From c21c49a4ae7cec8e8fea6c6f7259ae89e2aaa647 Mon Sep 17 00:00:00 2001 From: Guy Bedford Date: Sun, 11 Aug 2024 22:48:39 -0700 Subject: [PATCH] deps: upgrade to latest Node.js implementations --- chompfile.toml | 3 +- nodelibs/browser/_stream_duplex.js | 15 +- nodelibs/browser/_stream_passthrough.js | 15 +- nodelibs/browser/_stream_readable.js | 13 +- nodelibs/browser/_stream_transform.js | 15 +- nodelibs/browser/_stream_writable.js | 15 +- nodelibs/browser/assert.js | 2622 +- nodelibs/browser/assert/strict.js | 6 +- nodelibs/browser/buffer.js | 2302 +- .../{chunk-gkrMq4sQ.js => chunk-B6-G-Ftj.js} | 44 +- .../{chunk-CU2hd6BF.js => chunk-B738Er4n.js} | 16 +- nodelibs/browser/chunk-BZgdGiNw.js | 35 - .../{chunk-DppJZDIM.js => chunk-BlJi4mNy.js} | 215 +- nodelibs/browser/chunk-BsRZ0PEC.js | 74 + nodelibs/browser/chunk-C4rKjYLo.js | 20 + nodelibs/browser/chunk-C9hMJ5VR.js | 9 - nodelibs/browser/chunk-CKeAujU-.js | 3 - nodelibs/browser/chunk-CbQqNoLO.js | 32 + nodelibs/browser/chunk-CcCWfKp1.js | 360 + nodelibs/browser/chunk-CjPlbOtt.js | 47 + nodelibs/browser/chunk-CkFCi-G1.js | 36 + .../{chunk-D04hy_Cu.js => chunk-D3uu3VYh.js} | 32 +- nodelibs/browser/chunk-D5E0hY9V.js | 3 - nodelibs/browser/chunk-DEMDiNwt.js | 275 + nodelibs/browser/chunk-DEckhzyo.js | 3 - nodelibs/browser/chunk-DHWh-hmB.js | 1344 + nodelibs/browser/chunk-DtDiafJB.js | 96 + nodelibs/browser/chunk-DtcTpLWz.js | 826 + nodelibs/browser/chunk-DtuTasat.js | 1923 + nodelibs/browser/chunk-aBeyrThb.js | 20 - nodelibs/browser/console.js | 32 +- nodelibs/browser/crypto.js | 88474 +++++++++++----- nodelibs/browser/diagnostics_channel.js | 50 +- nodelibs/browser/domain.js | 23 +- nodelibs/browser/events.js | 395 +- nodelibs/browser/fs.js | 2012 +- nodelibs/browser/fs/promises.js | 30 +- nodelibs/browser/http.js | 3118 +- nodelibs/browser/https.js | 850 +- nodelibs/browser/os.js | 19 +- nodelibs/browser/path.js | 4 +- nodelibs/browser/path/posix.js | 4 +- nodelibs/browser/path/win32.js | 4 +- nodelibs/browser/process-production.js | 4 +- nodelibs/browser/process.js | 4 +- nodelibs/browser/punycode.js | 453 +- nodelibs/browser/querystring.js | 125 +- nodelibs/browser/stream.js | 6557 +- nodelibs/browser/stream/consumers.js | 61 + nodelibs/browser/stream/promises.js | 13 +- nodelibs/browser/string_decoder.js | 7 +- nodelibs/browser/sys.js | 10 +- nodelibs/browser/timers.js | 86 +- nodelibs/browser/timers/promises.js | 7 +- nodelibs/browser/url.js | 2738 +- nodelibs/browser/util.js | 1379 +- nodelibs/browser/util/types.js | 6 +- nodelibs/browser/vm.js | 31 +- nodelibs/browser/wasi.js | 30 +- nodelibs/browser/worker_threads.js | 1 - nodelibs/browser/zlib.js | 3898 +- package-lock.json | 4799 +- package.json | 6 +- rollup.config.mjs | 57 +- src-browser/_stream_duplex.js | 2 +- src-browser/_stream_passthrough.js | 2 +- src-browser/_stream_transform.js | 2 +- src-browser/_stream_writable.js | 2 +- src-browser/process-production.js | 2 + src-browser/process.js | 2 + src-browser/stream.js | 4 +- src-browser/sys.js | 4 +- test/test.html | 9 +- 73 files changed, 86894 insertions(+), 38841 deletions(-) rename nodelibs/browser/{chunk-gkrMq4sQ.js => chunk-B6-G-Ftj.js} (78%) rename nodelibs/browser/{chunk-CU2hd6BF.js => chunk-B738Er4n.js} (85%) delete mode 100644 nodelibs/browser/chunk-BZgdGiNw.js rename nodelibs/browser/{chunk-DppJZDIM.js => chunk-BlJi4mNy.js} (81%) create mode 100644 nodelibs/browser/chunk-BsRZ0PEC.js create mode 100644 nodelibs/browser/chunk-C4rKjYLo.js delete mode 100644 nodelibs/browser/chunk-C9hMJ5VR.js delete mode 100644 nodelibs/browser/chunk-CKeAujU-.js create mode 100644 nodelibs/browser/chunk-CbQqNoLO.js create mode 100644 nodelibs/browser/chunk-CcCWfKp1.js create mode 100644 nodelibs/browser/chunk-CjPlbOtt.js create mode 100644 nodelibs/browser/chunk-CkFCi-G1.js rename nodelibs/browser/{chunk-D04hy_Cu.js => chunk-D3uu3VYh.js} (82%) delete mode 100644 nodelibs/browser/chunk-D5E0hY9V.js create mode 100644 nodelibs/browser/chunk-DEMDiNwt.js delete mode 100644 nodelibs/browser/chunk-DEckhzyo.js create mode 100644 nodelibs/browser/chunk-DHWh-hmB.js create mode 100644 nodelibs/browser/chunk-DtDiafJB.js create mode 100644 nodelibs/browser/chunk-DtcTpLWz.js create mode 100644 nodelibs/browser/chunk-DtuTasat.js delete mode 100644 nodelibs/browser/chunk-aBeyrThb.js create mode 100644 nodelibs/browser/stream/consumers.js diff --git a/chompfile.toml b/chompfile.toml index c2dd17b..7853f6b 100644 --- a/chompfile.toml +++ b/chompfile.toml @@ -8,8 +8,9 @@ deps = ['nodelibs/node', 'nodelibs/browser'] [[task]] target = 'nodelibs/browser' -deps = ['src-browser/**/*'] +deps = ['src-browser/**/*', 'rollup.config.mjs'] run = 'rollup -c' +# env = { JSPM_GENERATOR_LOG = '1' } [[task]] target = 'nodelibs/node' diff --git a/nodelibs/browser/_stream_duplex.js b/nodelibs/browser/_stream_duplex.js index a908a6b..efba299 100644 --- a/nodelibs/browser/_stream_duplex.js +++ b/nodelibs/browser/_stream_duplex.js @@ -1,12 +1,11 @@ -import { e as exports } from './chunk-gkrMq4sQ.js'; +import exports from './stream.js'; +import './chunk-DtuTasat.js'; import './events.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-CU2hd6BF.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; +import './chunk-DEMDiNwt.js'; +import './chunk-CcCWfKp1.js'; +import './util.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; var _stream_duplex = exports.Duplex; var from = exports.Duplex.from; diff --git a/nodelibs/browser/_stream_passthrough.js b/nodelibs/browser/_stream_passthrough.js index d840cef..dec5f9a 100644 --- a/nodelibs/browser/_stream_passthrough.js +++ b/nodelibs/browser/_stream_passthrough.js @@ -1,12 +1,11 @@ -import { e as exports } from './chunk-gkrMq4sQ.js'; +import exports from './stream.js'; +import './chunk-DtuTasat.js'; import './events.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-CU2hd6BF.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; +import './chunk-DEMDiNwt.js'; +import './chunk-CcCWfKp1.js'; +import './util.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; var _stream_passthrough = exports.PassThrough; diff --git a/nodelibs/browser/_stream_readable.js b/nodelibs/browser/_stream_readable.js index 65122a4..2bcea9e 100644 --- a/nodelibs/browser/_stream_readable.js +++ b/nodelibs/browser/_stream_readable.js @@ -1,14 +1,11 @@ import { Readable } from './stream.js'; -import './chunk-gkrMq4sQ.js'; +import './chunk-DtuTasat.js'; import './events.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-CU2hd6BF.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; +import './chunk-DEMDiNwt.js'; +import './chunk-CcCWfKp1.js'; import './util.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; var ReadableState = Readable.ReadableState; var _fromList = Readable._fromList; diff --git a/nodelibs/browser/_stream_transform.js b/nodelibs/browser/_stream_transform.js index 639766a..4ceec9a 100644 --- a/nodelibs/browser/_stream_transform.js +++ b/nodelibs/browser/_stream_transform.js @@ -1,12 +1,11 @@ -import { e as exports } from './chunk-gkrMq4sQ.js'; +import exports from './stream.js'; +import './chunk-DtuTasat.js'; import './events.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-CU2hd6BF.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; +import './chunk-DEMDiNwt.js'; +import './chunk-CcCWfKp1.js'; +import './util.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; var _stream_transform = exports.Transform; diff --git a/nodelibs/browser/_stream_writable.js b/nodelibs/browser/_stream_writable.js index 59452af..fe310ce 100644 --- a/nodelibs/browser/_stream_writable.js +++ b/nodelibs/browser/_stream_writable.js @@ -1,12 +1,11 @@ -import { e as exports } from './chunk-gkrMq4sQ.js'; +import exports from './stream.js'; +import './chunk-DtuTasat.js'; import './events.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-CU2hd6BF.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; +import './chunk-DEMDiNwt.js'; +import './chunk-CcCWfKp1.js'; +import './util.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; var _stream_writable = exports.Writable; var WritableState = exports.Writable.WritableState; diff --git a/nodelibs/browser/assert.js b/nodelibs/browser/assert.js index 32e0969..063ab8f 100644 --- a/nodelibs/browser/assert.js +++ b/nodelibs/browser/assert.js @@ -1,48 +1,2574 @@ -import { X as X$1 } from './chunk-D04hy_Cu.js'; -import { T as T$1 } from './chunk-DEckhzyo.js'; - -function e(e,r){if(null==e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),n=1;n=0&&"[object Function]"===e$1.call(t.callee)),n};if(!Object.keys){var n=Object.prototype.hasOwnProperty,o=Object.prototype.toString,c=r$1,l=Object.prototype.propertyIsEnumerable,i=!l.call({toString:null},"toString"),a=l.call((function(){}),"prototype"),u=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(t){var e=t.constructor;return e&&e.prototype===t},p={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},s=function(){if("undefined"==typeof window)return !1;for(var t in window)try{if(!p["$"+t]&&n.call(window,t)&&null!==window[t]&&"object"==typeof window[t])try{f(window[t]);}catch(t){return !0}}catch(t){return !0}return !1}();t=function(t){var e=null!==t&&"object"==typeof t,r="[object Function]"===o.call(t),l=c(t),p=e&&"[object String]"===o.call(t),y=[];if(!e&&!r&&!l)throw new TypeError("Object.keys called on a non-object");var b=a&&r;if(p&&t.length>0&&!n.call(t,0))for(var g=0;g0)for(var h=0;h2?arguments[2]:{},c=r$2(o);e$2&&(c=n$1.call(c,Object.getOwnPropertySymbols(o)));for(var u=0;u1&&"boolean"!=typeof e)throw new TypeError('"allowMissing" argument must be a boolean');for(var n=v(r),y=P("%"+(n.length>0?n[0]:"")+"%",e),a=1;a=n.length){var i=t$3(y,n[a]);if(!(n[a]in y))throw new o$3("base intrinsic for "+r+" exists, but the property is not available.");y=i?i.get||i.value:y[n[a]];}else y=y[n[a]];return y};var t$4,p$1=e$4,o$4=c$2("%Function%"),i$2=o$4.apply,a$3=o$4.call;(t$4=function(){return p$1.apply(a$3,arguments)}).apply=function(){return p$1.apply(i$2,arguments)};var l$4=t$4;var r$4,n$4,i$3=function(t){return t!=t},o$5=(r$4=function(t,e){return 0===t&&0===e?1/t==1/e:t===e||!(!i$3(t)||!i$3(e))},r$4),c$3=(n$4=function(){return "function"==typeof Object.is?Object.is:o$5},n$4),f$4=f$1,u$3=f$1,s$1=r$4,a$4=n$4,l$5=function(){var t=c$3();return f$4(Object,{is:t},{is:function(){return Object.is!==t}}),t},p$2=l$4(a$4(),Object);u$3(p$2,{getPolyfill:a$4,implementation:s$1,shim:l$5});var m=p$2;N=function(r){return r!=r};var N,e$5,i$4=N,n$5=(e$5=function(){return Number.isNaN&&Number.isNaN(NaN)&&!Number.isNaN("a")?Number.isNaN:i$4},f$1),t$5=e$5,u$4=f$1,a$5=N,m$1=e$5,o$6=function(){var r=t$5();return n$5(Number,{isNaN:r},{isNaN:function(){return Number.isNaN!==r}}),r},s$2=m$1();u$4(s$2,{getPolyfill:m$1,implementation:a$5,shim:o$6});var f$5=s$2;var c$4={},a$6=!1;function i$5(){if(a$6)return c$4;function e(t){return (e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,n){return !n||"object"!==e(n)&&"function"!=typeof n?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):n}function r(t){return (r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return (o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}a$6=!0;var i,u,l={};function f(t,e,c){c||(c=Error);var a=function(c){function a(o,c,i){var u;return !function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(u=n(this,r(a).call(this,function(t,n,r){return "string"==typeof e?e:e(t,n,r)}(o,c,i)))).code=t,u}return !function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&o(t,e);}(a,c),a}(c);l[t]=a;}function s(t,e){if(Array.isArray(t)){var n=t.length;return t=t.map((function(t){return String(t)})),n>2?"one of ".concat(e," ").concat(t.slice(0,n-1).join(", "),", or ")+t[n-1]:2===n?"one of ".concat(e," ").concat(t[0]," or ").concat(t[1]):"of ".concat(e," ").concat(t[0])}return "of ".concat(e," ").concat(String(t))}return f("ERR_AMBIGUOUS_ARGUMENT",'The "%s" argument is ambiguous. %s',TypeError),f("ERR_INVALID_ARG_TYPE",(function(t,n,r){var o,c,u;if(void 0===i&&(i=tt()),i("string"==typeof t,"'name' must be a string"),"string"==typeof n&&(c="not ",n.substr(0,c.length)===c)?(o="must not be",n=n.replace(/^not /,"")):o="must be",function(t,e,n){return (void 0===n||n>t.length)&&(n=t.length),t.substring(n-e.length,n)===e}(t," argument"))u="The ".concat(t," ").concat(o," ").concat(s(n,"type"));else {var l=function(t,e,n){return "number"!=typeof n&&(n=0),!(n+e.length>t.length)&&-1!==t.indexOf(e,n)}(t,".")?"property":"argument";u='The "'.concat(t,'" ').concat(l," ").concat(o," ").concat(s(n,"type"));}return u+=". Received type ".concat(e(r))}),TypeError),f("ERR_INVALID_ARG_VALUE",(function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"is invalid";void 0===u&&(u=X$1);var o=u.inspect(n);return o.length>128&&(o="".concat(o.slice(0,128),"...")),"The argument '".concat(e,"' ").concat(r,". Received ").concat(o)}),TypeError),f("ERR_INVALID_RETURN_VALUE",(function(t,n,r){var o;return o=r&&r.constructor&&r.constructor.name?"instance of ".concat(r.constructor.name):"type ".concat(e(r)),"Expected ".concat(t,' to be returned from the "').concat(n,'"')+" function but got ".concat(o,".")}),TypeError),f("ERR_MISSING_ARGS",(function(){for(var t=arguments.length,e=new Array(t),n=0;n0,"At least one arg needs to be specified");var r="The ",o=e.length;switch(e=e.map((function(t){return '"'.concat(t,'"')})),o){case 1:r+="".concat(e[0]," argument");break;case 2:r+="".concat(e[0]," and ").concat(e[1]," arguments");break;default:r+=e.slice(0,o-1).join(", "),r+=", and ".concat(e[o-1]," arguments");}return "".concat(r," must be specified")}),TypeError),c$4.codes=l,c$4}var u$5={},l$6=!1;function f$6(){if(l$6)return u$5;l$6=!0;var n=T$1;function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){for(var n=0;nt.length)&&(n=t.length),t.substring(n-e.length,n)===e}var m="",E="",w="",S="",j={deepStrictEqual:"Expected values to be strictly deep-equal:",strictEqual:"Expected values to be strictly equal:",strictEqualObject:'Expected "actual" to be reference-equal to "expected":',deepEqual:"Expected values to be loosely deep-equal:",equal:"Expected values to be loosely equal:",notDeepStrictEqual:'Expected "actual" not to be strictly deep-equal to:',notStrictEqual:'Expected "actual" to be strictly unequal to:',notStrictEqualObject:'Expected "actual" not to be reference-equal to "expected":',notDeepEqual:'Expected "actual" not to be loosely deep-equal to:',notEqual:'Expected "actual" to be loosely unequal to:',notIdentical:"Values identical but not reference-equal:"};function O(t){var e=Object.keys(t),n=Object.create(Object.getPrototypeOf(t));return e.forEach((function(e){n[e]=t[e];})),Object.defineProperty(n,"message",{value:t.message}),n}function x(t){return b(t,{compact:!1,customInspect:!1,depth:1e3,maxArrayLength:1/0,showHidden:!1,breakLength:1/0,showProxy:!1,sorted:!0,getters:!0})}function q(t,e,r){var o="",c="",a=0,i="",u=!1,l=x(t),f=l.split("\n"),s=x(e).split("\n"),p=0,g="";if("strictEqual"===r&&"object"===y(t)&&"object"===y(e)&&null!==t&&null!==e&&(r="strictEqualObject"),1===f.length&&1===s.length&&f[0]!==s[0]){var h=f[0].length+s[0].length;if(h<=10){if(!("object"===y(t)&&null!==t||"object"===y(e)&&null!==e||0===t&&0===e))return "".concat(j[r],"\n\n")+"".concat(f[0]," !== ").concat(s[0],"\n")}else if("strictEqualObject"!==r){if(h<(n.stderr&&n.stderr.isTTY?n.stderr.columns:80)){for(;f[0][p]===s[0][p];)p++;p>2&&(g="\n ".concat(function(t,e){if(e=Math.floor(e),0==t.length||0==e)return "";var n=t.length*e;for(e=Math.floor(Math.log(e)/Math.log(2));e;)t+=t,e--;return t+=t.substring(0,n-t.length)}(" ",p),"^"),p=0);}}}for(var b=f[f.length-1],v=s[s.length-1];b===v&&(p++<2?i="\n ".concat(b).concat(i):o=b,f.pop(),s.pop(),0!==f.length&&0!==s.length);)b=f[f.length-1],v=s[s.length-1];var O=Math.max(f.length,s.length);if(0===O){var q=l.split("\n");if(q.length>30)for(q[26]="".concat(m,"...").concat(S);q.length>27;)q.pop();return "".concat(j.notIdentical,"\n\n").concat(q.join("\n"),"\n")}p>3&&(i="\n".concat(m,"...").concat(S).concat(i),u=!0),""!==o&&(i="\n ".concat(o).concat(i),o="");var R=0,A=j[r]+"\n".concat(E,"+ actual").concat(S," ").concat(w,"- expected").concat(S),k=" ".concat(m,"...").concat(S," Lines skipped");for(p=0;p1&&p>2&&(_>4?(c+="\n".concat(m,"...").concat(S),u=!0):_>3&&(c+="\n ".concat(s[p-2]),R++),c+="\n ".concat(s[p-1]),R++),a=p,o+="\n".concat(w,"-").concat(S," ").concat(s[p]),R++;else if(s.length1&&p>2&&(_>4?(c+="\n".concat(m,"...").concat(S),u=!0):_>3&&(c+="\n ".concat(f[p-2]),R++),c+="\n ".concat(f[p-1]),R++),a=p,c+="\n".concat(E,"+").concat(S," ").concat(f[p]),R++;else {var T=s[p],P=f[p],I=P!==T&&(!d(P,",")||P.slice(0,-1)!==T);I&&d(T,",")&&T.slice(0,-1)===P&&(I=!1,P+=","),I?(_>1&&p>2&&(_>4?(c+="\n".concat(m,"...").concat(S),u=!0):_>3&&(c+="\n ".concat(f[p-2]),R++),c+="\n ".concat(f[p-1]),R++),a=p,c+="\n".concat(E,"+").concat(S," ").concat(P),o+="\n".concat(w,"-").concat(S," ").concat(T),R+=2):(c+=o,o="",1!==_&&0!==p||(c+="\n ".concat(P),R++));}if(R>20&&p30)for(g[26]="".concat(m,"...").concat(S);g.length>27;)g.pop();r=1===g.length?c(this,h(e).call(this,"".concat(p," ").concat(g[0]))):c(this,h(e).call(this,"".concat(p,"\n\n").concat(g.join("\n"),"\n")));}else {var b=x(l),d="",R=j[i];"notDeepEqual"===i||"notEqual"===i?(b="".concat(j[i],"\n\n").concat(b)).length>1024&&(b="".concat(b.slice(0,1021),"...")):(d="".concat(x(f)),b.length>512&&(b="".concat(b.slice(0,509),"...")),d.length>512&&(d="".concat(d.slice(0,509),"...")),"deepEqual"===i||"equal"===i?b="".concat(R,"\n\n").concat(b,"\n\nshould equal\n\n"):d=" ".concat(i," ").concat(d)),r=c(this,h(e).call(this,"".concat(b).concat(d)));}return Error.stackTraceLimit=s,r.generatedMessage=!o,Object.defineProperty(a(r),"name",{value:"AssertionError [ERR_ASSERTION]",enumerable:!1,writable:!0,configurable:!0}),r.code="ERR_ASSERTION",r.actual=l,r.expected=f,r.operator=i,Error.captureStackTrace&&Error.captureStackTrace(a(r),u),r.stack,r.name="AssertionError",c(r)}var i,u;return !function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&g(t,e);}(e,t),i=e,(u=[{key:"toString",value:function(){return "".concat(this.name," [").concat(this.code,"]: ").concat(this.message)}},{key:b.custom,value:function(t,e){return b(this,function(t){for(var e=1;e10)return !0;for(var e=0;e57)return !0}return 10===t.length&&t>=Math.pow(2,32)}function G(t){return Object.keys(t).filter(U).concat(v$1(t).filter(Object.prototype.propertyIsEnumerable.bind(t)))} -/*! - * The buffer module from node.js, for the browser. - * - * @author Feross Aboukhadijeh - * @license MIT - */function V(t,e){if(t===e)return 0;for(var n=t.length,r=e.length,o=0,c=Math.min(n,r);o1?n-1:0),o=1;o1?n-1:0),o=1;o1?n-1:0),o=1;o1?n-1:0),o=1;o 2) { + return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(", "), ", or ") + expected[len - 1]; + } else if (len === 2) { + return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]); + } else { + return "of ".concat(thing, " ").concat(expected[0]); + } + } else { + return "of ".concat(thing, " ").concat(String(expected)); + } + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith + function startsWith(str, search, pos) { + return str.substr(0 , search.length) === search; + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith + function endsWith(str, search, this_len) { + if (this_len === undefined || this_len > str.length) { + this_len = str.length; + } + return str.substring(this_len - search.length, this_len) === search; + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes + function includes(str, search, start) { + if (typeof start !== "number") { + start = 0; + } + if (start + search.length > str.length) { + return false; + } else { + return str.indexOf(search, start) !== -1; + } + } + createErrorType("ERR_AMBIGUOUS_ARGUMENT", "The \"%s\" argument is ambiguous. %s", TypeError); + createErrorType("ERR_INVALID_ARG_TYPE", function (name, expected, actual) { + if (assert === undefined) assert = dew(); + assert(typeof name === "string", "'name' must be a string"); + + // determiner: 'must be' or 'must not be' + var determiner; + if (typeof expected === "string" && startsWith(expected, "not ")) { + determiner = "must not be"; + expected = expected.replace(/^not /, ""); + } else { + determiner = "must be"; + } + var msg; + if (endsWith(name, " argument")) { + // For cases like 'first argument' + msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, "type")); + } else { + var type = includes(name, ".") ? "property" : "argument"; + msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, "type")); + } + + // TODO(BridgeAR): Improve the output by showing `null` and similar. + msg += ". Received type ".concat(_typeof(actual)); + return msg; + }, TypeError); + createErrorType("ERR_INVALID_ARG_VALUE", function (name, value) { + var reason = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "is invalid"; + if (util === undefined) util = exports$j; + var inspected = util.inspect(value); + if (inspected.length > 128) { + inspected = "".concat(inspected.slice(0, 128), "..."); + } + return "The argument '".concat(name, "' ").concat(reason, ". Received ").concat(inspected); + }, TypeError); + createErrorType("ERR_INVALID_RETURN_VALUE", function (input, name, value) { + var type; + if (value && value.constructor && value.constructor.name) { + type = "instance of ".concat(value.constructor.name); + } else { + type = "type ".concat(_typeof(value)); + } + return "Expected ".concat(input, " to be returned from the \"").concat(name, "\"") + " function but got ".concat(type, "."); + }, TypeError); + createErrorType("ERR_MISSING_ARGS", function () { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + if (assert === undefined) assert = dew(); + assert(args.length > 0, "At least one arg needs to be specified"); + var msg = "The "; + var len = args.length; + args = args.map(function (a) { + return "\"".concat(a, "\""); + }); + switch (len) { + case 1: + msg += "".concat(args[0], " argument"); + break; + case 2: + msg += "".concat(args[0], " and ").concat(args[1], " arguments"); + break; + default: + msg += args.slice(0, len - 1).join(", "); + msg += ", and ".concat(args[len - 1], " arguments"); + break; + } + return "".concat(msg, " must be specified"); + }, TypeError); + exports$i.codes = codes; + return exports$i; +} + +var exports$h = {}, + _dewExec$g = false; +function dew$g() { + if (_dewExec$g) return exports$h; + _dewExec$g = true; + var process$1 = process; + function ownKeys(e, r) { + var t = Object.keys(e); + if (Object.getOwnPropertySymbols) { + var o = Object.getOwnPropertySymbols(e); + r && (o = o.filter(function (r) { + return Object.getOwnPropertyDescriptor(e, r).enumerable; + })), t.push.apply(t, o); + } + return t; + } + function _objectSpread(e) { + for (var r = 1; r < arguments.length; r++) { + var t = null != arguments[r] ? arguments[r] : {}; + r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { + _defineProperty(e, r, t[r]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { + Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); + }); + } + return e; + } + function _defineProperty(obj, key, value) { + key = _toPropertyKey(key); + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; + } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); + } + } + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + function _toPropertyKey(arg) { + var key = _toPrimitive(arg, "string"); + return _typeof(key) === "symbol" ? key : String(key); + } + function _toPrimitive(input, hint) { + if (_typeof(input) !== "object" || input === null) return input; + var prim = input[Symbol.toPrimitive]; + if (prim !== undefined) { + var res = prim.call(input, hint || "default"); + if (_typeof(res) !== "object") return res; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return (hint === "string" ? String : Number)(input); + } + function _inherits(subClass, superClass) { + if (typeof superClass !== "function" && superClass !== null) { + throw new TypeError("Super expression must either be null or a function"); + } + subClass.prototype = Object.create(superClass && superClass.prototype, { + constructor: { + value: subClass, + writable: true, + configurable: true + } + }); + Object.defineProperty(subClass, "prototype", { + writable: false + }); + if (superClass) _setPrototypeOf(subClass, superClass); + } + function _createSuper(Derived) { + var hasNativeReflectConstruct = _isNativeReflectConstruct(); + return function _createSuperInternal() { + var Super = _getPrototypeOf(Derived), + result; + if (hasNativeReflectConstruct) { + var NewTarget = _getPrototypeOf(this).constructor; + result = Reflect.construct(Super, arguments, NewTarget); + } else { + result = Super.apply(this, arguments); + } + return _possibleConstructorReturn(this, result); + }; + } + function _possibleConstructorReturn(self, call) { + if (call && (_typeof(call) === "object" || typeof call === "function")) { + return call; + } else if (call !== void 0) { + throw new TypeError("Derived constructors may only return object or undefined"); + } + return _assertThisInitialized(self); + } + function _assertThisInitialized(self) { + if (self === void 0) { + throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); + } + return self; + } + function _wrapNativeSuper(Class) { + var _cache = typeof Map === "function" ? new Map() : undefined; + _wrapNativeSuper = function _wrapNativeSuper(Class) { + if (Class === null || !_isNativeFunction(Class)) return Class; + if (typeof Class !== "function") { + throw new TypeError("Super expression must either be null or a function"); + } + if (typeof _cache !== "undefined") { + if (_cache.has(Class)) return _cache.get(Class); + _cache.set(Class, Wrapper); + } + function Wrapper() { + return _construct(Class, arguments, _getPrototypeOf(this).constructor); + } + Wrapper.prototype = Object.create(Class.prototype, { + constructor: { + value: Wrapper, + enumerable: false, + writable: true, + configurable: true + } + }); + return _setPrototypeOf(Wrapper, Class); + }; + return _wrapNativeSuper(Class); + } + function _construct(Parent, args, Class) { + if (_isNativeReflectConstruct()) { + _construct = Reflect.construct.bind(); + } else { + _construct = function _construct(Parent, args, Class) { + var a = [null]; + a.push.apply(a, args); + var Constructor = Function.bind.apply(Parent, a); + var instance = new Constructor(); + if (Class) _setPrototypeOf(instance, Class.prototype); + return instance; + }; + } + return _construct.apply(null, arguments); + } + function _isNativeReflectConstruct() { + if (typeof Reflect === "undefined" || !Reflect.construct) return false; + if (Reflect.construct.sham) return false; + if (typeof Proxy === "function") return true; + try { + Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); + return true; + } catch (e) { + return false; + } + } + function _isNativeFunction(fn) { + return Function.toString.call(fn).indexOf("[native code]") !== -1; + } + function _setPrototypeOf(o, p) { + _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { + o.__proto__ = p; + return o; + }; + return _setPrototypeOf(o, p); + } + function _getPrototypeOf(o) { + _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { + return o.__proto__ || Object.getPrototypeOf(o); + }; + return _getPrototypeOf(o); + } + function _typeof(o) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { + return typeof o; + } : function (o) { + return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; + }, _typeof(o); + } + var _require = exports$j, + inspect = _require.inspect; + var _require2 = dew$h(), + ERR_INVALID_ARG_TYPE = _require2.codes.ERR_INVALID_ARG_TYPE; + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith + function endsWith(str, search, this_len) { + if (this_len === undefined || this_len > str.length) { + this_len = str.length; + } + return str.substring(this_len - search.length, this_len) === search; + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/repeat + function repeat(str, count) { + count = Math.floor(count); + if (str.length == 0 || count == 0) return ""; + var maxCount = str.length * count; + count = Math.floor(Math.log(count) / Math.log(2)); + while (count) { + str += str; + count--; + } + str += str.substring(0, maxCount - str.length); + return str; + } + var blue = ""; + var green = ""; + var red = ""; + var white = ""; + var kReadableOperator = { + deepStrictEqual: "Expected values to be strictly deep-equal:", + strictEqual: "Expected values to be strictly equal:", + strictEqualObject: "Expected \"actual\" to be reference-equal to \"expected\":", + deepEqual: "Expected values to be loosely deep-equal:", + equal: "Expected values to be loosely equal:", + notDeepStrictEqual: "Expected \"actual\" not to be strictly deep-equal to:", + notStrictEqual: "Expected \"actual\" to be strictly unequal to:", + notStrictEqualObject: "Expected \"actual\" not to be reference-equal to \"expected\":", + notDeepEqual: "Expected \"actual\" not to be loosely deep-equal to:", + notEqual: "Expected \"actual\" to be loosely unequal to:", + notIdentical: "Values identical but not reference-equal:" + }; + + // Comparing short primitives should just show === / !== instead of using the + // diff. + var kMaxShortLength = 10; + function copyError(source) { + var keys = Object.keys(source); + var target = Object.create(Object.getPrototypeOf(source)); + keys.forEach(function (key) { + target[key] = source[key]; + }); + Object.defineProperty(target, "message", { + value: source.message + }); + return target; + } + function inspectValue(val) { + // The util.inspect default values could be changed. This makes sure the + // error messages contain the necessary information nevertheless. + return inspect(val, { + compact: false, + customInspect: false, + depth: 1000, + maxArrayLength: Infinity, + // Assert compares only enumerable properties (with a few exceptions). + showHidden: false, + // Having a long line as error is better than wrapping the line for + // comparison for now. + // TODO(BridgeAR): `breakLength` should be limited as soon as soon as we + // have meta information about the inspected properties (i.e., know where + // in what line the property starts and ends). + breakLength: Infinity, + // Assert does not detect proxies currently. + showProxy: false, + sorted: true, + // Inspect getters as we also check them when comparing entries. + getters: true + }); + } + function createErrDiff(actual, expected, operator) { + var other = ""; + var res = ""; + var lastPos = 0; + var end = ""; + var skipped = false; + var actualInspected = inspectValue(actual); + var actualLines = actualInspected.split("\n"); + var expectedLines = inspectValue(expected).split("\n"); + var i = 0; + var indicator = ""; + + // In case both values are objects explicitly mark them as not reference equal + // for the `strictEqual` operator. + if (operator === "strictEqual" && _typeof(actual) === "object" && _typeof(expected) === "object" && actual !== null && expected !== null) { + operator = "strictEqualObject"; + } + + // If "actual" and "expected" fit on a single line and they are not strictly + // equal, check further special handling. + if (actualLines.length === 1 && expectedLines.length === 1 && actualLines[0] !== expectedLines[0]) { + var inputLength = actualLines[0].length + expectedLines[0].length; + // If the character length of "actual" and "expected" together is less than + // kMaxShortLength and if neither is an object and at least one of them is + // not `zero`, use the strict equal comparison to visualize the output. + if (inputLength <= kMaxShortLength) { + if ((_typeof(actual) !== "object" || actual === null) && (_typeof(expected) !== "object" || expected === null) && (actual !== 0 || expected !== 0)) { + // -0 === +0 + return "".concat(kReadableOperator[operator], "\n\n") + "".concat(actualLines[0], " !== ").concat(expectedLines[0], "\n"); + } + } else if (operator !== "strictEqualObject") { + // If the stderr is a tty and the input length is lower than the current + // columns per line, add a mismatch indicator below the output. If it is + // not a tty, use a default value of 80 characters. + var maxLength = process$1.stderr && process$1.stderr.isTTY ? process$1.stderr.columns : 80; + if (inputLength < maxLength) { + while (actualLines[0][i] === expectedLines[0][i]) { + i++; + } + // Ignore the first characters. + if (i > 2) { + // Add position indicator for the first mismatch in case it is a + // single line and the input length is less than the column length. + indicator = "\n ".concat(repeat(" ", i), "^"); + i = 0; + } + } + } + } + + // Remove all ending lines that match (this optimizes the output for + // readability by reducing the number of total changed lines). + var a = actualLines[actualLines.length - 1]; + var b = expectedLines[expectedLines.length - 1]; + while (a === b) { + if (i++ < 2) { + end = "\n ".concat(a).concat(end); + } else { + other = a; + } + actualLines.pop(); + expectedLines.pop(); + if (actualLines.length === 0 || expectedLines.length === 0) break; + a = actualLines[actualLines.length - 1]; + b = expectedLines[expectedLines.length - 1]; + } + var maxLines = Math.max(actualLines.length, expectedLines.length); + // Strict equal with identical objects that are not identical by reference. + // E.g., assert.deepStrictEqual({ a: Symbol() }, { a: Symbol() }) + if (maxLines === 0) { + // We have to get the result again. The lines were all removed before. + var _actualLines = actualInspected.split("\n"); + + // Only remove lines in case it makes sense to collapse those. + // TODO: Accept env to always show the full error. + if (_actualLines.length > 30) { + _actualLines[26] = "".concat(blue, "...").concat(white); + while (_actualLines.length > 27) { + _actualLines.pop(); + } + } + return "".concat(kReadableOperator.notIdentical, "\n\n").concat(_actualLines.join("\n"), "\n"); + } + if (i > 3) { + end = "\n".concat(blue, "...").concat(white).concat(end); + skipped = true; + } + if (other !== "") { + end = "\n ".concat(other).concat(end); + other = ""; + } + var printedLines = 0; + var msg = kReadableOperator[operator] + "\n".concat(green, "+ actual").concat(white, " ").concat(red, "- expected").concat(white); + var skippedMsg = " ".concat(blue, "...").concat(white, " Lines skipped"); + for (i = 0; i < maxLines; i++) { + // Only extra expected lines exist + var cur = i - lastPos; + if (actualLines.length < i + 1) { + // If the last diverging line is more than one line above and the + // current line is at least line three, add some of the former lines and + // also add dots to indicate skipped entries. + if (cur > 1 && i > 2) { + if (cur > 4) { + res += "\n".concat(blue, "...").concat(white); + skipped = true; + } else if (cur > 3) { + res += "\n ".concat(expectedLines[i - 2]); + printedLines++; + } + res += "\n ".concat(expectedLines[i - 1]); + printedLines++; + } + // Mark the current line as the last diverging one. + lastPos = i; + // Add the expected line to the cache. + other += "\n".concat(red, "-").concat(white, " ").concat(expectedLines[i]); + printedLines++; + // Only extra actual lines exist + } else if (expectedLines.length < i + 1) { + // If the last diverging line is more than one line above and the + // current line is at least line three, add some of the former lines and + // also add dots to indicate skipped entries. + if (cur > 1 && i > 2) { + if (cur > 4) { + res += "\n".concat(blue, "...").concat(white); + skipped = true; + } else if (cur > 3) { + res += "\n ".concat(actualLines[i - 2]); + printedLines++; + } + res += "\n ".concat(actualLines[i - 1]); + printedLines++; + } + // Mark the current line as the last diverging one. + lastPos = i; + // Add the actual line to the result. + res += "\n".concat(green, "+").concat(white, " ").concat(actualLines[i]); + printedLines++; + // Lines diverge + } else { + var expectedLine = expectedLines[i]; + var actualLine = actualLines[i]; + // If the lines diverge, specifically check for lines that only diverge by + // a trailing comma. In that case it is actually identical and we should + // mark it as such. + var divergingLines = actualLine !== expectedLine && (!endsWith(actualLine, ",") || actualLine.slice(0, -1) !== expectedLine); + // If the expected line has a trailing comma but is otherwise identical, + // add a comma at the end of the actual line. Otherwise the output could + // look weird as in: + // + // [ + // 1 // No comma at the end! + // + 2 + // ] + // + if (divergingLines && endsWith(expectedLine, ",") && expectedLine.slice(0, -1) === actualLine) { + divergingLines = false; + actualLine += ","; + } + if (divergingLines) { + // If the last diverging line is more than one line above and the + // current line is at least line three, add some of the former lines and + // also add dots to indicate skipped entries. + if (cur > 1 && i > 2) { + if (cur > 4) { + res += "\n".concat(blue, "...").concat(white); + skipped = true; + } else if (cur > 3) { + res += "\n ".concat(actualLines[i - 2]); + printedLines++; + } + res += "\n ".concat(actualLines[i - 1]); + printedLines++; + } + // Mark the current line as the last diverging one. + lastPos = i; + // Add the actual line to the result and cache the expected diverging + // line so consecutive diverging lines show up as +++--- and not +-+-+-. + res += "\n".concat(green, "+").concat(white, " ").concat(actualLine); + other += "\n".concat(red, "-").concat(white, " ").concat(expectedLine); + printedLines += 2; + // Lines are identical + } else { + // Add all cached information to the result before adding other things + // and reset the cache. + res += other; + other = ""; + // If the last diverging line is exactly one line above or if it is the + // very first line, add the line to the result. + if (cur === 1 || i === 0) { + res += "\n ".concat(actualLine); + printedLines++; + } + } + } + // Inspected object to big (Show ~20 rows max) + if (printedLines > 20 && i < maxLines - 2) { + return "".concat(msg).concat(skippedMsg, "\n").concat(res, "\n").concat(blue, "...").concat(white).concat(other, "\n") + "".concat(blue, "...").concat(white); + } + } + return "".concat(msg).concat(skipped ? skippedMsg : "", "\n").concat(res).concat(other).concat(end).concat(indicator); + } + var AssertionError = /*#__PURE__*/function (_Error, _inspect$custom) { + _inherits(AssertionError, _Error); + var _super = _createSuper(AssertionError); + function AssertionError(options) { + var _this; + _classCallCheck(this, AssertionError); + if (_typeof(options) !== "object" || options === null) { + throw new ERR_INVALID_ARG_TYPE("options", "Object", options); + } + var message = options.message, + operator = options.operator, + stackStartFn = options.stackStartFn; + var actual = options.actual, + expected = options.expected; + var limit = Error.stackTraceLimit; + Error.stackTraceLimit = 0; + if (message != null) { + _this = _super.call(this, String(message)); + } else { + if (process$1.stderr && process$1.stderr.isTTY) { + // Reset on each call to make sure we handle dynamically set environment + // variables correct. + if (process$1.stderr && process$1.stderr.getColorDepth && process$1.stderr.getColorDepth() !== 1) { + blue = "\x1B[34m"; + green = "\x1B[32m"; + white = "\x1B[39m"; + red = "\x1B[31m"; + } else { + blue = ""; + green = ""; + white = ""; + red = ""; + } + } + // Prevent the error stack from being visible by duplicating the error + // in a very close way to the original in case both sides are actually + // instances of Error. + if (_typeof(actual) === "object" && actual !== null && _typeof(expected) === "object" && expected !== null && "stack" in actual && actual instanceof Error && "stack" in expected && expected instanceof Error) { + actual = copyError(actual); + expected = copyError(expected); + } + if (operator === "deepStrictEqual" || operator === "strictEqual") { + _this = _super.call(this, createErrDiff(actual, expected, operator)); + } else if (operator === "notDeepStrictEqual" || operator === "notStrictEqual") { + // In case the objects are equal but the operator requires unequal, show + // the first object and say A equals B + var base = kReadableOperator[operator]; + var res = inspectValue(actual).split("\n"); + + // In case "actual" is an object, it should not be reference equal. + if (operator === "notStrictEqual" && _typeof(actual) === "object" && actual !== null) { + base = kReadableOperator.notStrictEqualObject; + } + + // Only remove lines in case it makes sense to collapse those. + // TODO: Accept env to always show the full error. + if (res.length > 30) { + res[26] = "".concat(blue, "...").concat(white); + while (res.length > 27) { + res.pop(); + } + } + + // Only print a single input. + if (res.length === 1) { + _this = _super.call(this, "".concat(base, " ").concat(res[0])); + } else { + _this = _super.call(this, "".concat(base, "\n\n").concat(res.join("\n"), "\n")); + } + } else { + var _res = inspectValue(actual); + var other = ""; + var knownOperators = kReadableOperator[operator]; + if (operator === "notDeepEqual" || operator === "notEqual") { + _res = "".concat(kReadableOperator[operator], "\n\n").concat(_res); + if (_res.length > 1024) { + _res = "".concat(_res.slice(0, 1021), "..."); + } + } else { + other = "".concat(inspectValue(expected)); + if (_res.length > 512) { + _res = "".concat(_res.slice(0, 509), "..."); + } + if (other.length > 512) { + other = "".concat(other.slice(0, 509), "..."); + } + if (operator === "deepEqual" || operator === "equal") { + _res = "".concat(knownOperators, "\n\n").concat(_res, "\n\nshould equal\n\n"); + } else { + other = " ".concat(operator, " ").concat(other); + } + } + _this = _super.call(this, "".concat(_res).concat(other)); + } + } + Error.stackTraceLimit = limit; + _this.generatedMessage = !message; + Object.defineProperty(_assertThisInitialized(_this), "name", { + value: "AssertionError [ERR_ASSERTION]", + enumerable: false, + writable: true, + configurable: true + }); + _this.code = "ERR_ASSERTION"; + _this.actual = actual; + _this.expected = expected; + _this.operator = operator; + if (Error.captureStackTrace) { + // eslint-disable-next-line no-restricted-syntax + Error.captureStackTrace(_assertThisInitialized(_this), stackStartFn); + } + // Create error message including the error code in the name. + _this.stack; + // Reset the name. + _this.name = "AssertionError"; + return _possibleConstructorReturn(_this); + } + _createClass(AssertionError, [{ + key: "toString", + value: function toString() { + return "".concat(this.name, " [").concat(this.code, "]: ").concat(this.message); + } + }, { + key: _inspect$custom, + value: function value(recurseTimes, ctx) { + // This limits the `actual` and `expected` property default inspection to + // the minimum depth. Otherwise those values would be too verbose compared + // to the actual error message which contains a combined view of these two + // input values. + return inspect(this, _objectSpread(_objectSpread({}, ctx), {}, { + customInspect: false, + depth: 0 + })); + } + }]); + return AssertionError; + }(/*#__PURE__*/_wrapNativeSuper(Error), inspect.custom); + exports$h = AssertionError; + return exports$h; +} + +var exports$g = {}, + _dewExec$f = false; +function dew$f() { + if (_dewExec$f) return exports$g; + _dewExec$f = true; + var toStr = Object.prototype.toString; + exports$g = function isArguments(value) { + var str = toStr.call(value); + var isArgs = str === "[object Arguments]"; + if (!isArgs) { + isArgs = str !== "[object Array]" && value !== null && typeof value === "object" && typeof value.length === "number" && value.length >= 0 && toStr.call(value.callee) === "[object Function]"; + } + return isArgs; + }; + return exports$g; +} + +var exports$f = {}, + _dewExec$e = false; +function dew$e() { + if (_dewExec$e) return exports$f; + _dewExec$e = true; + var keysShim; + if (!Object.keys) { + // modified from https://github.com/es-shims/es5-shim + var has = Object.prototype.hasOwnProperty; + var toStr = Object.prototype.toString; + var isArgs = dew$f(); // eslint-disable-line global-require + var isEnumerable = Object.prototype.propertyIsEnumerable; + var hasDontEnumBug = !isEnumerable.call({ + toString: null + }, "toString"); + var hasProtoEnumBug = isEnumerable.call(function () {}, "prototype"); + var dontEnums = ["toString", "toLocaleString", "valueOf", "hasOwnProperty", "isPrototypeOf", "propertyIsEnumerable", "constructor"]; + var equalsConstructorPrototype = function (o) { + var ctor = o.constructor; + return ctor && ctor.prototype === o; + }; + var excludedKeys = { + $applicationCache: true, + $console: true, + $external: true, + $frame: true, + $frameElement: true, + $frames: true, + $innerHeight: true, + $innerWidth: true, + $onmozfullscreenchange: true, + $onmozfullscreenerror: true, + $outerHeight: true, + $outerWidth: true, + $pageXOffset: true, + $pageYOffset: true, + $parent: true, + $scrollLeft: true, + $scrollTop: true, + $scrollX: true, + $scrollY: true, + $self: true, + $webkitIndexedDB: true, + $webkitStorageInfo: true, + $window: true + }; + var hasAutomationEqualityBug = function () { + /* global window */ + if (typeof window === "undefined") { + return false; + } + for (var k in window) { + try { + if (!excludedKeys["$" + k] && has.call(window, k) && window[k] !== null && typeof window[k] === "object") { + try { + equalsConstructorPrototype(window[k]); + } catch (e) { + return true; + } + } + } catch (e) { + return true; + } + } + return false; + }(); + var equalsConstructorPrototypeIfNotBuggy = function (o) { + /* global window */ + if (typeof window === "undefined" || !hasAutomationEqualityBug) { + return equalsConstructorPrototype(o); + } + try { + return equalsConstructorPrototype(o); + } catch (e) { + return false; + } + }; + keysShim = function keys(object) { + var isObject = object !== null && typeof object === "object"; + var isFunction = toStr.call(object) === "[object Function]"; + var isArguments = isArgs(object); + var isString = isObject && toStr.call(object) === "[object String]"; + var theKeys = []; + if (!isObject && !isFunction && !isArguments) { + throw new TypeError("Object.keys called on a non-object"); + } + var skipProto = hasProtoEnumBug && isFunction; + if (isString && object.length > 0 && !has.call(object, 0)) { + for (var i = 0; i < object.length; ++i) { + theKeys.push(String(i)); + } + } + if (isArguments && object.length > 0) { + for (var j = 0; j < object.length; ++j) { + theKeys.push(String(j)); + } + } else { + for (var name in object) { + if (!(skipProto && name === "prototype") && has.call(object, name)) { + theKeys.push(String(name)); + } + } + } + if (hasDontEnumBug) { + var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object); + for (var k = 0; k < dontEnums.length; ++k) { + if (!(skipConstructor && dontEnums[k] === "constructor") && has.call(object, dontEnums[k])) { + theKeys.push(dontEnums[k]); + } + } + } + return theKeys; + }; + } + exports$f = keysShim; + return exports$f; +} + +var exports$e = {}, + _dewExec$d = false; +function dew$d() { + if (_dewExec$d) return exports$e; + _dewExec$d = true; + var slice = Array.prototype.slice; + var isArgs = dew$f(); + var origKeys = Object.keys; + var keysShim = origKeys ? function keys(o) { + return origKeys(o); + } : dew$e(); + var originalKeys = Object.keys; + keysShim.shim = function shimObjectKeys() { + if (Object.keys) { + var keysWorksWithArguments = function () { + // Safari 5.0 bug + var args = Object.keys(arguments); + return args && args.length === arguments.length; + }(1, 2); + if (!keysWorksWithArguments) { + Object.keys = function keys(object) { + // eslint-disable-line func-name-matching + if (isArgs(object)) { + return originalKeys(slice.call(object)); + } + return originalKeys(object); + }; + } + } else { + Object.keys = keysShim; + } + return Object.keys || keysShim; + }; + exports$e = keysShim; + return exports$e; +} + +var exports$d = {}, + _dewExec$c = false; +function dew$c() { + if (_dewExec$c) return exports$d; + _dewExec$c = true; + // modified from https://github.com/es-shims/es6-shim + var objectKeys = dew$d(); + var hasSymbols = dew$i()(); + var callBound = dew$j(); + var toObject = Object; + var $push = callBound("Array.prototype.push"); + var $propIsEnumerable = callBound("Object.prototype.propertyIsEnumerable"); + var originalGetSymbols = hasSymbols ? Object.getOwnPropertySymbols : null; + + // eslint-disable-next-line no-unused-vars + exports$d = function assign(target, source1) { + if (target == null) { + throw new TypeError("target must be an object"); + } + var to = toObject(target); // step 1 + if (arguments.length === 1) { + return to; // step 2 + } + for (var s = 1; s < arguments.length; ++s) { + var from = toObject(arguments[s]); // step 3.a.i + + // step 3.a.ii: + var keys = objectKeys(from); + var getSymbols = hasSymbols && (Object.getOwnPropertySymbols || originalGetSymbols); + if (getSymbols) { + var syms = getSymbols(from); + for (var j = 0; j < syms.length; ++j) { + var key = syms[j]; + if ($propIsEnumerable(from, key)) { + $push(keys, key); + } + } + } + + // step 3.a.iii: + for (var i = 0; i < keys.length; ++i) { + var nextKey = keys[i]; + if ($propIsEnumerable(from, nextKey)) { + // step 3.a.iii.2 + var propValue = from[nextKey]; // step 3.a.iii.2.a + to[nextKey] = propValue; // step 3.a.iii.2.b + } + } + } + return to; // step 4 + }; + return exports$d; +} + +var exports$c = {}, + _dewExec$b = false; +function dew$b() { + if (_dewExec$b) return exports$c; + _dewExec$b = true; + var implementation = dew$c(); + var lacksProperEnumerationOrder = function () { + if (!Object.assign) { + return false; + } + /* + * v8, specifically in node 4.x, has a bug with incorrect property enumeration order + * note: this does not detect the bug unless there's 20 characters + */ + var str = "abcdefghijklmnopqrst"; + var letters = str.split(""); + var map = {}; + for (var i = 0; i < letters.length; ++i) { + map[letters[i]] = letters[i]; + } + var obj = Object.assign({}, map); + var actual = ""; + for (var k in obj) { + actual += k; + } + return str !== actual; + }; + var assignHasPendingExceptions = function () { + if (!Object.assign || !Object.preventExtensions) { + return false; + } + /* + * Firefox 37 still has "pending exception" logic in its Object.assign implementation, + * which is 72% slower than our shim, and Firefox 40's native implementation. + */ + var thrower = Object.preventExtensions({ + 1: 2 + }); + try { + Object.assign(thrower, "xy"); + } catch (e) { + return thrower[1] === "y"; + } + return false; + }; + exports$c = function getPolyfill() { + if (!Object.assign) { + return implementation; + } + if (lacksProperEnumerationOrder()) { + return implementation; + } + if (assignHasPendingExceptions()) { + return implementation; + } + return Object.assign; + }; + return exports$c; +} + +var exports$b = {}, + _dewExec$a = false; +function dew$a() { + if (_dewExec$a) return exports$b; + _dewExec$a = true; + var numberIsNaN = function (value) { + return value !== value; + }; + exports$b = function is(a, b) { + if (a === 0 && b === 0) { + return 1 / a === 1 / b; + } + if (a === b) { + return true; + } + if (numberIsNaN(a) && numberIsNaN(b)) { + return true; + } + return false; + }; + return exports$b; +} + +var exports$a = {}, + _dewExec$9 = false; +function dew$9() { + if (_dewExec$9) return exports$a; + _dewExec$9 = true; + var implementation = dew$a(); + exports$a = function getPolyfill() { + return typeof Object.is === "function" ? Object.is : implementation; + }; + return exports$a; +} + +var exports$9 = {}, + _dewExec$8 = false; +function dew$8() { + if (_dewExec$8) return exports$9; + _dewExec$8 = true; + var keys = dew$d(); + var hasSymbols = typeof Symbol === "function" && typeof Symbol("foo") === "symbol"; + var toStr = Object.prototype.toString; + var concat = Array.prototype.concat; + var defineDataProperty = dew$k(); + var isFunction = function (fn) { + return typeof fn === "function" && toStr.call(fn) === "[object Function]"; + }; + var supportsDescriptors = dew$l()(); + var defineProperty = function (object, name, value, predicate) { + if (name in object) { + if (predicate === true) { + if (object[name] === value) { + return; + } + } else if (!isFunction(predicate) || !predicate()) { + return; + } + } + if (supportsDescriptors) { + defineDataProperty(object, name, value, true); + } else { + defineDataProperty(object, name, value); + } + }; + var defineProperties = function (object, map) { + var predicates = arguments.length > 2 ? arguments[2] : {}; + var props = keys(map); + if (hasSymbols) { + props = concat.call(props, Object.getOwnPropertySymbols(map)); + } + for (var i = 0; i < props.length; i += 1) { + defineProperty(object, props[i], map[props[i]], predicates[props[i]]); + } + }; + defineProperties.supportsDescriptors = !!supportsDescriptors; + exports$9 = defineProperties; + return exports$9; +} + +var exports$8 = {}, + _dewExec$7 = false; +function dew$7() { + if (_dewExec$7) return exports$8; + _dewExec$7 = true; + var getPolyfill = dew$9(); + var define = dew$8(); + exports$8 = function shimObjectIs() { + var polyfill = getPolyfill(); + define(Object, { + is: polyfill + }, { + is: function testObjectIs() { + return Object.is !== polyfill; + } + }); + return polyfill; + }; + return exports$8; +} + +var exports$7 = {}, + _dewExec$6 = false; +function dew$6() { + if (_dewExec$6) return exports$7; + _dewExec$6 = true; + var define = dew$8(); + var callBind = dew$m(); + var implementation = dew$a(); + var getPolyfill = dew$9(); + var shim = dew$7(); + var polyfill = callBind(getPolyfill(), Object); + define(polyfill, { + getPolyfill: getPolyfill, + implementation: implementation, + shim: shim + }); + exports$7 = polyfill; + return exports$7; +} + +var exports$6 = {}, + _dewExec$5 = false; +function dew$5() { + if (_dewExec$5) return exports$6; + _dewExec$5 = true; + /* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */ + + exports$6 = function isNaN(value) { + return value !== value; + }; + return exports$6; +} + +var exports$5 = {}, + _dewExec$4 = false; +function dew$4() { + if (_dewExec$4) return exports$5; + _dewExec$4 = true; + var implementation = dew$5(); + exports$5 = function getPolyfill() { + if (Number.isNaN && Number.isNaN(NaN) && !Number.isNaN("a")) { + return Number.isNaN; + } + return implementation; + }; + return exports$5; +} + +var exports$4 = {}, + _dewExec$3 = false; +function dew$3() { + if (_dewExec$3) return exports$4; + _dewExec$3 = true; + var define = dew$8(); + var getPolyfill = dew$4(); + + /* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */ + + exports$4 = function shimNumberIsNaN() { + var polyfill = getPolyfill(); + define(Number, { + isNaN: polyfill + }, { + isNaN: function testIsNaN() { + return Number.isNaN !== polyfill; + } + }); + return polyfill; + }; + return exports$4; +} + +var exports$3 = {}, + _dewExec$2 = false; +function dew$2() { + if (_dewExec$2) return exports$3; + _dewExec$2 = true; + var callBind = dew$m(); + var define = dew$8(); + var implementation = dew$5(); + var getPolyfill = dew$4(); + var shim = dew$3(); + var polyfill = callBind(getPolyfill(), Number); + + /* http://www.ecma-international.org/ecma-262/6.0/#sec-number.isnan */ + + define(polyfill, { + getPolyfill: getPolyfill, + implementation: implementation, + shim: shim + }); + exports$3 = polyfill; + return exports$3; +} + +var exports$2 = {}, + _dewExec$1 = false; +function dew$1() { + if (_dewExec$1) return exports$2; + _dewExec$1 = true; + function _slicedToArray(arr, i) { + return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); + } + function _nonIterableRest() { + throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); + } + function _unsupportedIterableToArray(o, minLen) { + if (!o) return; + if (typeof o === "string") return _arrayLikeToArray(o, minLen); + var n = Object.prototype.toString.call(o).slice(8, -1); + if (n === "Object" && o.constructor) n = o.constructor.name; + if (n === "Map" || n === "Set") return Array.from(o); + if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); + } + function _arrayLikeToArray(arr, len) { + if (len == null || len > arr.length) len = arr.length; + for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; + return arr2; + } + function _iterableToArrayLimit(r, l) { + var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; + if (null != t) { + var e, + n, + i, + u, + a = [], + f = !0, + o = !1; + try { + if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); + } catch (r) { + o = !0, n = r; + } finally { + try { + if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; + } finally { + if (o) throw n; + } + } + return a; + } + } + function _arrayWithHoles(arr) { + if (Array.isArray(arr)) return arr; + } + function _typeof(o) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { + return typeof o; + } : function (o) { + return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; + }, _typeof(o); + } + var regexFlagsSupported = /a/g.flags !== undefined; + var arrayFromSet = function arrayFromSet(set) { + var array = []; + set.forEach(function (value) { + return array.push(value); + }); + return array; + }; + var arrayFromMap = function arrayFromMap(map) { + var array = []; + map.forEach(function (value, key) { + return array.push([key, value]); + }); + return array; + }; + var objectIs = Object.is ? Object.is : dew$6(); + var objectGetOwnPropertySymbols = Object.getOwnPropertySymbols ? Object.getOwnPropertySymbols : function () { + return []; + }; + var numberIsNaN = Number.isNaN ? Number.isNaN : dew$2(); + function uncurryThis(f) { + return f.call.bind(f); + } + var hasOwnProperty = uncurryThis(Object.prototype.hasOwnProperty); + var propertyIsEnumerable = uncurryThis(Object.prototype.propertyIsEnumerable); + var objectToString = uncurryThis(Object.prototype.toString); + var _require$types = exports$j.types, + isAnyArrayBuffer = _require$types.isAnyArrayBuffer, + isArrayBufferView = _require$types.isArrayBufferView, + isDate = _require$types.isDate, + isMap = _require$types.isMap, + isRegExp = _require$types.isRegExp, + isSet = _require$types.isSet, + isNativeError = _require$types.isNativeError, + isBoxedPrimitive = _require$types.isBoxedPrimitive, + isNumberObject = _require$types.isNumberObject, + isStringObject = _require$types.isStringObject, + isBooleanObject = _require$types.isBooleanObject, + isBigIntObject = _require$types.isBigIntObject, + isSymbolObject = _require$types.isSymbolObject, + isFloat32Array = _require$types.isFloat32Array, + isFloat64Array = _require$types.isFloat64Array; + function isNonIndex(key) { + if (key.length === 0 || key.length > 10) return true; + for (var i = 0; i < key.length; i++) { + var code = key.charCodeAt(i); + if (code < 48 || code > 57) return true; + } + // The maximum size for an array is 2 ** 32 -1. + return key.length === 10 && key >= Math.pow(2, 32); + } + function getOwnNonIndexProperties(value) { + return Object.keys(value).filter(isNonIndex).concat(objectGetOwnPropertySymbols(value).filter(Object.prototype.propertyIsEnumerable.bind(value))); + } + + // Taken from https://github.com/feross/buffer/blob/680e9e5e488f22aac27599a57dc844a6315928dd/index.js + // original notice: + /*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */ + function compare(a, b) { + if (a === b) { + return 0; + } + var x = a.length; + var y = b.length; + for (var i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + } + if (x < y) { + return -1; + } + if (y < x) { + return 1; + } + return 0; + } + var kStrict = true; + var kLoose = false; + var kNoIterator = 0; + var kIsArray = 1; + var kIsSet = 2; + var kIsMap = 3; + + // Check if they have the same source and flags + function areSimilarRegExps(a, b) { + return regexFlagsSupported ? a.source === b.source && a.flags === b.flags : RegExp.prototype.toString.call(a) === RegExp.prototype.toString.call(b); + } + function areSimilarFloatArrays(a, b) { + if (a.byteLength !== b.byteLength) { + return false; + } + for (var offset = 0; offset < a.byteLength; offset++) { + if (a[offset] !== b[offset]) { + return false; + } + } + return true; + } + function areSimilarTypedArrays(a, b) { + if (a.byteLength !== b.byteLength) { + return false; + } + return compare(new Uint8Array(a.buffer, a.byteOffset, a.byteLength), new Uint8Array(b.buffer, b.byteOffset, b.byteLength)) === 0; + } + function areEqualArrayBuffers(buf1, buf2) { + return buf1.byteLength === buf2.byteLength && compare(new Uint8Array(buf1), new Uint8Array(buf2)) === 0; + } + function isEqualBoxedPrimitive(val1, val2) { + if (isNumberObject(val1)) { + return isNumberObject(val2) && objectIs(Number.prototype.valueOf.call(val1), Number.prototype.valueOf.call(val2)); + } + if (isStringObject(val1)) { + return isStringObject(val2) && String.prototype.valueOf.call(val1) === String.prototype.valueOf.call(val2); + } + if (isBooleanObject(val1)) { + return isBooleanObject(val2) && Boolean.prototype.valueOf.call(val1) === Boolean.prototype.valueOf.call(val2); + } + if (isBigIntObject(val1)) { + return isBigIntObject(val2) && BigInt.prototype.valueOf.call(val1) === BigInt.prototype.valueOf.call(val2); + } + return isSymbolObject(val2) && Symbol.prototype.valueOf.call(val1) === Symbol.prototype.valueOf.call(val2); + } + + // Notes: Type tags are historical [[Class]] properties that can be set by + // FunctionTemplate::SetClassName() in C++ or Symbol.toStringTag in JS + // and retrieved using Object.prototype.toString.call(obj) in JS + // See https://tc39.github.io/ecma262/#sec-object.prototype.tostring + // for a list of tags pre-defined in the spec. + // There are some unspecified tags in the wild too (e.g. typed array tags). + // Since tags can be altered, they only serve fast failures + // + // Typed arrays and buffers are checked by comparing the content in their + // underlying ArrayBuffer. This optimization requires that it's + // reasonable to interpret their underlying memory in the same way, + // which is checked by comparing their type tags. + // (e.g. a Uint8Array and a Uint16Array with the same memory content + // could still be different because they will be interpreted differently). + // + // For strict comparison, objects should have + // a) The same built-in type tags + // b) The same prototypes. + + function innerDeepEqual(val1, val2, strict, memos) { + // All identical values are equivalent, as determined by ===. + if (val1 === val2) { + if (val1 !== 0) return true; + return strict ? objectIs(val1, val2) : true; + } + + // Check more closely if val1 and val2 are equal. + if (strict) { + if (_typeof(val1) !== "object") { + return typeof val1 === "number" && numberIsNaN(val1) && numberIsNaN(val2); + } + if (_typeof(val2) !== "object" || val1 === null || val2 === null) { + return false; + } + if (Object.getPrototypeOf(val1) !== Object.getPrototypeOf(val2)) { + return false; + } + } else { + if (val1 === null || _typeof(val1) !== "object") { + if (val2 === null || _typeof(val2) !== "object") { + // eslint-disable-next-line eqeqeq + return val1 == val2; + } + return false; + } + if (val2 === null || _typeof(val2) !== "object") { + return false; + } + } + var val1Tag = objectToString(val1); + var val2Tag = objectToString(val2); + if (val1Tag !== val2Tag) { + return false; + } + if (Array.isArray(val1)) { + // Check for sparse arrays and general fast path + if (val1.length !== val2.length) { + return false; + } + var keys1 = getOwnNonIndexProperties(val1); + var keys2 = getOwnNonIndexProperties(val2); + if (keys1.length !== keys2.length) { + return false; + } + return keyCheck(val1, val2, strict, memos, kIsArray, keys1); + } + // [browserify] This triggers on certain types in IE (Map/Set) so we don't + // wan't to early return out of the rest of the checks. However we can check + // if the second value is one of these values and the first isn't. + if (val1Tag === "[object Object]") { + // return keyCheck(val1, val2, strict, memos, kNoIterator); + if (!isMap(val1) && isMap(val2) || !isSet(val1) && isSet(val2)) { + return false; + } + } + if (isDate(val1)) { + if (!isDate(val2) || Date.prototype.getTime.call(val1) !== Date.prototype.getTime.call(val2)) { + return false; + } + } else if (isRegExp(val1)) { + if (!isRegExp(val2) || !areSimilarRegExps(val1, val2)) { + return false; + } + } else if (isNativeError(val1) || val1 instanceof Error) { + // Do not compare the stack as it might differ even though the error itself + // is otherwise identical. + if (val1.message !== val2.message || val1.name !== val2.name) { + return false; + } + } else if (isArrayBufferView(val1)) { + if (!strict && (isFloat32Array(val1) || isFloat64Array(val1))) { + if (!areSimilarFloatArrays(val1, val2)) { + return false; + } + } else if (!areSimilarTypedArrays(val1, val2)) { + return false; + } + // Buffer.compare returns true, so val1.length === val2.length. If they both + // only contain numeric keys, we don't need to exam further than checking + // the symbols. + var _keys = getOwnNonIndexProperties(val1); + var _keys2 = getOwnNonIndexProperties(val2); + if (_keys.length !== _keys2.length) { + return false; + } + return keyCheck(val1, val2, strict, memos, kNoIterator, _keys); + } else if (isSet(val1)) { + if (!isSet(val2) || val1.size !== val2.size) { + return false; + } + return keyCheck(val1, val2, strict, memos, kIsSet); + } else if (isMap(val1)) { + if (!isMap(val2) || val1.size !== val2.size) { + return false; + } + return keyCheck(val1, val2, strict, memos, kIsMap); + } else if (isAnyArrayBuffer(val1)) { + if (!areEqualArrayBuffers(val1, val2)) { + return false; + } + } else if (isBoxedPrimitive(val1) && !isEqualBoxedPrimitive(val1, val2)) { + return false; + } + return keyCheck(val1, val2, strict, memos, kNoIterator); + } + function getEnumerables(val, keys) { + return keys.filter(function (k) { + return propertyIsEnumerable(val, k); + }); + } + function keyCheck(val1, val2, strict, memos, iterationType, aKeys) { + // For all remaining Object pairs, including Array, objects and Maps, + // equivalence is determined by having: + // a) The same number of owned enumerable properties + // b) The same set of keys/indexes (although not necessarily the same order) + // c) Equivalent values for every corresponding key/index + // d) For Sets and Maps, equal contents + // Note: this accounts for both named and indexed properties on Arrays. + if (arguments.length === 5) { + aKeys = Object.keys(val1); + var bKeys = Object.keys(val2); + + // The pair must have the same number of owned properties. + if (aKeys.length !== bKeys.length) { + return false; + } + } + + // Cheap key test + var i = 0; + for (; i < aKeys.length; i++) { + if (!hasOwnProperty(val2, aKeys[i])) { + return false; + } + } + if (strict && arguments.length === 5) { + var symbolKeysA = objectGetOwnPropertySymbols(val1); + if (symbolKeysA.length !== 0) { + var count = 0; + for (i = 0; i < symbolKeysA.length; i++) { + var key = symbolKeysA[i]; + if (propertyIsEnumerable(val1, key)) { + if (!propertyIsEnumerable(val2, key)) { + return false; + } + aKeys.push(key); + count++; + } else if (propertyIsEnumerable(val2, key)) { + return false; + } + } + var symbolKeysB = objectGetOwnPropertySymbols(val2); + if (symbolKeysA.length !== symbolKeysB.length && getEnumerables(val2, symbolKeysB).length !== count) { + return false; + } + } else { + var _symbolKeysB = objectGetOwnPropertySymbols(val2); + if (_symbolKeysB.length !== 0 && getEnumerables(val2, _symbolKeysB).length !== 0) { + return false; + } + } + } + if (aKeys.length === 0 && (iterationType === kNoIterator || iterationType === kIsArray && val1.length === 0 || val1.size === 0)) { + return true; + } + + // Use memos to handle cycles. + if (memos === undefined) { + memos = { + val1: new Map(), + val2: new Map(), + position: 0 + }; + } else { + // We prevent up to two map.has(x) calls by directly retrieving the value + // and checking for undefined. The map can only contain numbers, so it is + // safe to check for undefined only. + var val2MemoA = memos.val1.get(val1); + if (val2MemoA !== undefined) { + var val2MemoB = memos.val2.get(val2); + if (val2MemoB !== undefined) { + return val2MemoA === val2MemoB; + } + } + memos.position++; + } + memos.val1.set(val1, memos.position); + memos.val2.set(val2, memos.position); + var areEq = objEquiv(val1, val2, strict, aKeys, memos, iterationType); + memos.val1.delete(val1); + memos.val2.delete(val2); + return areEq; + } + function setHasEqualElement(set, val1, strict, memo) { + // Go looking. + var setValues = arrayFromSet(set); + for (var i = 0; i < setValues.length; i++) { + var val2 = setValues[i]; + if (innerDeepEqual(val1, val2, strict, memo)) { + // Remove the matching element to make sure we do not check that again. + set.delete(val2); + return true; + } + } + return false; + } + + // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Equality_comparisons_and_sameness#Loose_equality_using + // Sadly it is not possible to detect corresponding values properly in case the + // type is a string, number, bigint or boolean. The reason is that those values + // can match lots of different string values (e.g., 1n == '+00001'). + function findLooseMatchingPrimitives(prim) { + switch (_typeof(prim)) { + case "undefined": + return null; + case "object": + // Only pass in null as object! + return undefined; + case "symbol": + return false; + case "string": + prim = +prim; + // Loose equal entries exist only if the string is possible to convert to + // a regular number and not NaN. + // Fall through + case "number": + if (numberIsNaN(prim)) { + return false; + } + } + return true; + } + function setMightHaveLoosePrim(a, b, prim) { + var altValue = findLooseMatchingPrimitives(prim); + if (altValue != null) return altValue; + return b.has(altValue) && !a.has(altValue); + } + function mapMightHaveLoosePrim(a, b, prim, item, memo) { + var altValue = findLooseMatchingPrimitives(prim); + if (altValue != null) { + return altValue; + } + var curB = b.get(altValue); + if (curB === undefined && !b.has(altValue) || !innerDeepEqual(item, curB, false, memo)) { + return false; + } + return !a.has(altValue) && innerDeepEqual(item, curB, false, memo); + } + function setEquiv(a, b, strict, memo) { + // This is a lazily initiated Set of entries which have to be compared + // pairwise. + var set = null; + var aValues = arrayFromSet(a); + for (var i = 0; i < aValues.length; i++) { + var val = aValues[i]; + // Note: Checking for the objects first improves the performance for object + // heavy sets but it is a minor slow down for primitives. As they are fast + // to check this improves the worst case scenario instead. + if (_typeof(val) === "object" && val !== null) { + if (set === null) { + set = new Set(); + } + // If the specified value doesn't exist in the second set its an not null + // object (or non strict only: a not matching primitive) we'll need to go + // hunting for something thats deep-(strict-)equal to it. To make this + // O(n log n) complexity we have to copy these values in a new set first. + set.add(val); + } else if (!b.has(val)) { + if (strict) return false; + + // Fast path to detect missing string, symbol, undefined and null values. + if (!setMightHaveLoosePrim(a, b, val)) { + return false; + } + if (set === null) { + set = new Set(); + } + set.add(val); + } + } + if (set !== null) { + var bValues = arrayFromSet(b); + for (var _i = 0; _i < bValues.length; _i++) { + var _val = bValues[_i]; + // We have to check if a primitive value is already + // matching and only if it's not, go hunting for it. + if (_typeof(_val) === "object" && _val !== null) { + if (!setHasEqualElement(set, _val, strict, memo)) return false; + } else if (!strict && !a.has(_val) && !setHasEqualElement(set, _val, strict, memo)) { + return false; + } + } + return set.size === 0; + } + return true; + } + function mapHasEqualEntry(set, map, key1, item1, strict, memo) { + // To be able to handle cases like: + // Map([[{}, 'a'], [{}, 'b']]) vs Map([[{}, 'b'], [{}, 'a']]) + // ... we need to consider *all* matching keys, not just the first we find. + var setValues = arrayFromSet(set); + for (var i = 0; i < setValues.length; i++) { + var key2 = setValues[i]; + if (innerDeepEqual(key1, key2, strict, memo) && innerDeepEqual(item1, map.get(key2), strict, memo)) { + set.delete(key2); + return true; + } + } + return false; + } + function mapEquiv(a, b, strict, memo) { + var set = null; + var aEntries = arrayFromMap(a); + for (var i = 0; i < aEntries.length; i++) { + var _aEntries$i = _slicedToArray(aEntries[i], 2), + key = _aEntries$i[0], + item1 = _aEntries$i[1]; + if (_typeof(key) === "object" && key !== null) { + if (set === null) { + set = new Set(); + } + set.add(key); + } else { + // By directly retrieving the value we prevent another b.has(key) check in + // almost all possible cases. + var item2 = b.get(key); + if (item2 === undefined && !b.has(key) || !innerDeepEqual(item1, item2, strict, memo)) { + if (strict) return false; + // Fast path to detect missing string, symbol, undefined and null + // keys. + if (!mapMightHaveLoosePrim(a, b, key, item1, memo)) return false; + if (set === null) { + set = new Set(); + } + set.add(key); + } + } + } + if (set !== null) { + var bEntries = arrayFromMap(b); + for (var _i2 = 0; _i2 < bEntries.length; _i2++) { + var _bEntries$_i = _slicedToArray(bEntries[_i2], 2), + _key = _bEntries$_i[0], + item = _bEntries$_i[1]; + if (_typeof(_key) === "object" && _key !== null) { + if (!mapHasEqualEntry(set, a, _key, item, strict, memo)) return false; + } else if (!strict && (!a.has(_key) || !innerDeepEqual(a.get(_key), item, false, memo)) && !mapHasEqualEntry(set, a, _key, item, false, memo)) { + return false; + } + } + return set.size === 0; + } + return true; + } + function objEquiv(a, b, strict, keys, memos, iterationType) { + // Sets and maps don't have their entries accessible via normal object + // properties. + var i = 0; + if (iterationType === kIsSet) { + if (!setEquiv(a, b, strict, memos)) { + return false; + } + } else if (iterationType === kIsMap) { + if (!mapEquiv(a, b, strict, memos)) { + return false; + } + } else if (iterationType === kIsArray) { + for (; i < a.length; i++) { + if (hasOwnProperty(a, i)) { + if (!hasOwnProperty(b, i) || !innerDeepEqual(a[i], b[i], strict, memos)) { + return false; + } + } else if (hasOwnProperty(b, i)) { + return false; + } else { + // Array is sparse. + var keysA = Object.keys(a); + for (; i < keysA.length; i++) { + var key = keysA[i]; + if (!hasOwnProperty(b, key) || !innerDeepEqual(a[key], b[key], strict, memos)) { + return false; + } + } + if (keysA.length !== Object.keys(b).length) { + return false; + } + return true; + } + } + } + + // The pair must have equivalent values for every corresponding key. + // Possibly expensive deep test: + for (i = 0; i < keys.length; i++) { + var _key2 = keys[i]; + if (!innerDeepEqual(a[_key2], b[_key2], strict, memos)) { + return false; + } + } + return true; + } + function isDeepEqual(val1, val2) { + return innerDeepEqual(val1, val2, kLoose); + } + function isDeepStrictEqual(val1, val2) { + return innerDeepEqual(val1, val2, kStrict); + } + exports$2 = { + isDeepEqual: isDeepEqual, + isDeepStrictEqual: isDeepStrictEqual + }; + return exports$2; +} + +var exports$1 = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports$1; + _dewExec = true; + var process$1 = process; + function _typeof(o) { + "@babel/helpers - typeof"; + + return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { + return typeof o; + } : function (o) { + return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; + }, _typeof(o); + } + function _createClass(Constructor, protoProps, staticProps) { + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + var _require = dew$h(), + _require$codes = _require.codes, + ERR_AMBIGUOUS_ARGUMENT = _require$codes.ERR_AMBIGUOUS_ARGUMENT, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_INVALID_ARG_VALUE = _require$codes.ERR_INVALID_ARG_VALUE, + ERR_INVALID_RETURN_VALUE = _require$codes.ERR_INVALID_RETURN_VALUE, + ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS; + var AssertionError = dew$g(); + var _require2 = exports$j, + inspect = _require2.inspect; + var _require$types = exports$j.types, + isPromise = _require$types.isPromise, + isRegExp = _require$types.isRegExp; + var objectAssign = dew$b()(); + var objectIs = dew$9()(); + var RegExpPrototypeTest = dew$j()("RegExp.prototype.test"); + var isDeepEqual; + var isDeepStrictEqual; + function lazyLoadComparison() { + var comparison = dew$1(); + isDeepEqual = comparison.isDeepEqual; + isDeepStrictEqual = comparison.isDeepStrictEqual; + } + var warned = false; + + // The assert module provides functions that throw + // AssertionError's when particular conditions are not met. The + // assert module must conform to the following interface. + + var assert = exports$1 = ok; + var NO_EXCEPTION_SENTINEL = {}; + + // All of the following functions must throw an AssertionError + // when a corresponding condition is not met, with a message that + // may be undefined if not provided. All assertion methods provide + // both the actual and expected values to the assertion error for + // display purposes. + + function innerFail(obj) { + if (obj.message instanceof Error) throw obj.message; + throw new AssertionError(obj); + } + function fail(actual, expected, message, operator, stackStartFn) { + var argsLen = arguments.length; + var internalMessage; + if (argsLen === 0) { + internalMessage = "Failed"; + } else if (argsLen === 1) { + message = actual; + actual = undefined; + } else { + if (warned === false) { + warned = true; + var warn = process$1.emitWarning ? process$1.emitWarning : console.warn.bind(console); + warn("assert.fail() with more than one argument is deprecated. " + "Please use assert.strictEqual() instead or only pass a message.", "DeprecationWarning", "DEP0094"); + } + if (argsLen === 2) operator = "!="; + } + if (message instanceof Error) throw message; + var errArgs = { + actual: actual, + expected: expected, + operator: operator === undefined ? "fail" : operator, + stackStartFn: stackStartFn || fail + }; + if (message !== undefined) { + errArgs.message = message; + } + var err = new AssertionError(errArgs); + if (internalMessage) { + err.message = internalMessage; + err.generatedMessage = true; + } + throw err; + } + assert.fail = fail; + + // The AssertionError is defined in internal/error. + assert.AssertionError = AssertionError; + function innerOk(fn, argLen, value, message) { + if (!value) { + var generatedMessage = false; + if (argLen === 0) { + generatedMessage = true; + message = "No value argument passed to `assert.ok()`"; + } else if (message instanceof Error) { + throw message; + } + var err = new AssertionError({ + actual: value, + expected: true, + message: message, + operator: "==", + stackStartFn: fn + }); + err.generatedMessage = generatedMessage; + throw err; + } + } + + // Pure assertion tests whether a value is truthy, as determined + // by !!value. + function ok() { + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + innerOk.apply(void 0, [ok, args.length].concat(args)); + } + assert.ok = ok; + + // The equality assertion tests shallow, coercive equality with ==. + /* eslint-disable no-restricted-properties */ + assert.equal = function equal(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + // eslint-disable-next-line eqeqeq + if (actual != expected) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "==", + stackStartFn: equal + }); + } + }; + + // The non-equality assertion tests for whether two objects are not + // equal with !=. + assert.notEqual = function notEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + // eslint-disable-next-line eqeqeq + if (actual == expected) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "!=", + stackStartFn: notEqual + }); + } + }; + + // The equivalence assertion tests a deep equality relation. + assert.deepEqual = function deepEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + if (isDeepEqual === undefined) lazyLoadComparison(); + if (!isDeepEqual(actual, expected)) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "deepEqual", + stackStartFn: deepEqual + }); + } + }; + + // The non-equivalence assertion tests for any deep inequality. + assert.notDeepEqual = function notDeepEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + if (isDeepEqual === undefined) lazyLoadComparison(); + if (isDeepEqual(actual, expected)) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "notDeepEqual", + stackStartFn: notDeepEqual + }); + } + }; + /* eslint-enable */ + + assert.deepStrictEqual = function deepStrictEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + if (isDeepEqual === undefined) lazyLoadComparison(); + if (!isDeepStrictEqual(actual, expected)) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "deepStrictEqual", + stackStartFn: deepStrictEqual + }); + } + }; + assert.notDeepStrictEqual = notDeepStrictEqual; + function notDeepStrictEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + if (isDeepEqual === undefined) lazyLoadComparison(); + if (isDeepStrictEqual(actual, expected)) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "notDeepStrictEqual", + stackStartFn: notDeepStrictEqual + }); + } + } + assert.strictEqual = function strictEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + if (!objectIs(actual, expected)) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "strictEqual", + stackStartFn: strictEqual + }); + } + }; + assert.notStrictEqual = function notStrictEqual(actual, expected, message) { + if (arguments.length < 2) { + throw new ERR_MISSING_ARGS("actual", "expected"); + } + if (objectIs(actual, expected)) { + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: "notStrictEqual", + stackStartFn: notStrictEqual + }); + } + }; + var Comparison = /*#__PURE__*/_createClass(function Comparison(obj, keys, actual) { + var _this = this; + _classCallCheck(this, Comparison); + keys.forEach(function (key) { + if (key in obj) { + if (actual !== undefined && typeof actual[key] === "string" && isRegExp(obj[key]) && RegExpPrototypeTest(obj[key], actual[key])) { + _this[key] = actual[key]; + } else { + _this[key] = obj[key]; + } + } + }); + }); + function compareExceptionKey(actual, expected, key, message, keys, fn) { + if (!(key in actual) || !isDeepStrictEqual(actual[key], expected[key])) { + if (!message) { + // Create placeholder objects to create a nice output. + var a = new Comparison(actual, keys); + var b = new Comparison(expected, keys, actual); + var err = new AssertionError({ + actual: a, + expected: b, + operator: "deepStrictEqual", + stackStartFn: fn + }); + err.actual = actual; + err.expected = expected; + err.operator = fn.name; + throw err; + } + innerFail({ + actual: actual, + expected: expected, + message: message, + operator: fn.name, + stackStartFn: fn + }); + } + } + function expectedException(actual, expected, msg, fn) { + if (typeof expected !== "function") { + if (isRegExp(expected)) return RegExpPrototypeTest(expected, actual); + // assert.doesNotThrow does not accept objects. + if (arguments.length === 2) { + throw new ERR_INVALID_ARG_TYPE("expected", ["Function", "RegExp"], expected); + } + + // Handle primitives properly. + if (_typeof(actual) !== "object" || actual === null) { + var err = new AssertionError({ + actual: actual, + expected: expected, + message: msg, + operator: "deepStrictEqual", + stackStartFn: fn + }); + err.operator = fn.name; + throw err; + } + var keys = Object.keys(expected); + // Special handle errors to make sure the name and the message are compared + // as well. + if (expected instanceof Error) { + keys.push("name", "message"); + } else if (keys.length === 0) { + throw new ERR_INVALID_ARG_VALUE("error", expected, "may not be an empty object"); + } + if (isDeepEqual === undefined) lazyLoadComparison(); + keys.forEach(function (key) { + if (typeof actual[key] === "string" && isRegExp(expected[key]) && RegExpPrototypeTest(expected[key], actual[key])) { + return; + } + compareExceptionKey(actual, expected, key, msg, keys, fn); + }); + return true; + } + // Guard instanceof against arrow functions as they don't have a prototype. + if (expected.prototype !== undefined && actual instanceof expected) { + return true; + } + if (Error.isPrototypeOf(expected)) { + return false; + } + return expected.call({}, actual) === true; + } + function getActual(fn) { + if (typeof fn !== "function") { + throw new ERR_INVALID_ARG_TYPE("fn", "Function", fn); + } + try { + fn(); + } catch (e) { + return e; + } + return NO_EXCEPTION_SENTINEL; + } + function checkIsPromise(obj) { + // Accept native ES6 promises and promises that are implemented in a similar + // way. Do not accept thenables that use a function as `obj` and that have no + // `catch` handler. + + // TODO: thenables are checked up until they have the correct methods, + // but according to documentation, the `then` method should receive + // the `fulfill` and `reject` arguments as well or it may be never resolved. + + return isPromise(obj) || obj !== null && _typeof(obj) === "object" && typeof obj.then === "function" && typeof obj.catch === "function"; + } + function waitForActual(promiseFn) { + return Promise.resolve().then(function () { + var resultPromise; + if (typeof promiseFn === "function") { + // Return a rejected promise if `promiseFn` throws synchronously. + resultPromise = promiseFn(); + // Fail in case no promise is returned. + if (!checkIsPromise(resultPromise)) { + throw new ERR_INVALID_RETURN_VALUE("instance of Promise", "promiseFn", resultPromise); + } + } else if (checkIsPromise(promiseFn)) { + resultPromise = promiseFn; + } else { + throw new ERR_INVALID_ARG_TYPE("promiseFn", ["Function", "Promise"], promiseFn); + } + return Promise.resolve().then(function () { + return resultPromise; + }).then(function () { + return NO_EXCEPTION_SENTINEL; + }).catch(function (e) { + return e; + }); + }); + } + function expectsError(stackStartFn, actual, error, message) { + if (typeof error === "string") { + if (arguments.length === 4) { + throw new ERR_INVALID_ARG_TYPE("error", ["Object", "Error", "Function", "RegExp"], error); + } + if (_typeof(actual) === "object" && actual !== null) { + if (actual.message === error) { + throw new ERR_AMBIGUOUS_ARGUMENT("error/message", "The error message \"".concat(actual.message, "\" is identical to the message.")); + } + } else if (actual === error) { + throw new ERR_AMBIGUOUS_ARGUMENT("error/message", "The error \"".concat(actual, "\" is identical to the message.")); + } + message = error; + error = undefined; + } else if (error != null && _typeof(error) !== "object" && typeof error !== "function") { + throw new ERR_INVALID_ARG_TYPE("error", ["Object", "Error", "Function", "RegExp"], error); + } + if (actual === NO_EXCEPTION_SENTINEL) { + var details = ""; + if (error && error.name) { + details += " (".concat(error.name, ")"); + } + details += message ? ": ".concat(message) : "."; + var fnType = stackStartFn.name === "rejects" ? "rejection" : "exception"; + innerFail({ + actual: undefined, + expected: error, + operator: stackStartFn.name, + message: "Missing expected ".concat(fnType).concat(details), + stackStartFn: stackStartFn + }); + } + if (error && !expectedException(actual, error, message, stackStartFn)) { + throw actual; + } + } + function expectsNoError(stackStartFn, actual, error, message) { + if (actual === NO_EXCEPTION_SENTINEL) return; + if (typeof error === "string") { + message = error; + error = undefined; + } + if (!error || expectedException(actual, error)) { + var details = message ? ": ".concat(message) : "."; + var fnType = stackStartFn.name === "doesNotReject" ? "rejection" : "exception"; + innerFail({ + actual: actual, + expected: error, + operator: stackStartFn.name, + message: "Got unwanted ".concat(fnType).concat(details, "\n") + "Actual message: \"".concat(actual && actual.message, "\""), + stackStartFn: stackStartFn + }); + } + throw actual; + } + assert.throws = function throws(promiseFn) { + for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) { + args[_key2 - 1] = arguments[_key2]; + } + expectsError.apply(void 0, [throws, getActual(promiseFn)].concat(args)); + }; + assert.rejects = function rejects(promiseFn) { + for (var _len3 = arguments.length, args = new Array(_len3 > 1 ? _len3 - 1 : 0), _key3 = 1; _key3 < _len3; _key3++) { + args[_key3 - 1] = arguments[_key3]; + } + return waitForActual(promiseFn).then(function (result) { + return expectsError.apply(void 0, [rejects, result].concat(args)); + }); + }; + assert.doesNotThrow = function doesNotThrow(fn) { + for (var _len4 = arguments.length, args = new Array(_len4 > 1 ? _len4 - 1 : 0), _key4 = 1; _key4 < _len4; _key4++) { + args[_key4 - 1] = arguments[_key4]; + } + expectsNoError.apply(void 0, [doesNotThrow, getActual(fn)].concat(args)); + }; + assert.doesNotReject = function doesNotReject(fn) { + for (var _len5 = arguments.length, args = new Array(_len5 > 1 ? _len5 - 1 : 0), _key5 = 1; _key5 < _len5; _key5++) { + args[_key5 - 1] = arguments[_key5]; + } + return waitForActual(fn).then(function (result) { + return expectsNoError.apply(void 0, [doesNotReject, result].concat(args)); + }); + }; + assert.ifError = function ifError(err) { + if (err !== null && err !== undefined) { + var message = "ifError got unwanted exception: "; + if (_typeof(err) === "object" && typeof err.message === "string") { + if (err.message.length === 0 && err.constructor) { + message += err.constructor.name; + } else { + message += err.message; + } + } else { + message += inspect(err); + } + var newErr = new AssertionError({ + actual: err, + expected: null, + operator: "ifError", + message: message, + stackStartFn: ifError + }); + + // Make sure we actually have a stack trace! + var origStack = err.stack; + if (typeof origStack === "string") { + // This will remove any duplicated frames from the error frames taken + // from within `ifError` and add the original error frames to the newly + // created ones. + var tmp2 = origStack.split("\n"); + tmp2.shift(); + // Filter all frames existing in err.stack. + var tmp1 = newErr.stack.split("\n"); + for (var i = 0; i < tmp2.length; i++) { + // Find the first occurrence of the frame. + var pos = tmp1.indexOf(tmp2[i]); + if (pos !== -1) { + // Only keep new frames. + tmp1 = tmp1.slice(0, pos); + break; + } + } + newErr.stack = "".concat(tmp1.join("\n"), "\n").concat(tmp2.join("\n")); + } + throw newErr; + } + }; + + // Currently in sync with Node.js lib/assert.js + // https://github.com/nodejs/node/commit/2a871df3dfb8ea663ef5e1f8f62701ec51384ecb + function internalMatch(string, regexp, message, fn, fnName) { + if (!isRegExp(regexp)) { + throw new ERR_INVALID_ARG_TYPE("regexp", "RegExp", regexp); + } + var match = fnName === "match"; + if (typeof string !== "string" || RegExpPrototypeTest(regexp, string) !== match) { + if (message instanceof Error) { + throw message; + } + var generatedMessage = !message; + + // 'The input was expected to not match the regular expression ' + + message = message || (typeof string !== "string" ? "The \"string\" argument must be of type string. Received type " + "".concat(_typeof(string), " (").concat(inspect(string), ")") : (match ? "The input did not match the regular expression " : "The input was expected to not match the regular expression ") + "".concat(inspect(regexp), ". Input:\n\n").concat(inspect(string), "\n")); + var err = new AssertionError({ + actual: string, + expected: regexp, + message: message, + operator: fnName, + stackStartFn: fn + }); + err.generatedMessage = generatedMessage; + throw err; + } + } + assert.match = function match(string, regexp, message) { + internalMatch(string, regexp, message, match, "match"); + }; + assert.doesNotMatch = function doesNotMatch(string, regexp, message) { + internalMatch(string, regexp, message, doesNotMatch, "doesNotMatch"); + }; + + // Expose a strict only variant of assert + function strict() { + for (var _len6 = arguments.length, args = new Array(_len6), _key6 = 0; _key6 < _len6; _key6++) { + args[_key6] = arguments[_key6]; + } + innerOk.apply(void 0, [strict, args.length].concat(args)); + } + assert.strict = objectAssign(strict, assert, { + equal: assert.strictEqual, + deepEqual: assert.deepStrictEqual, + notEqual: assert.notStrictEqual, + notDeepEqual: assert.notDeepStrictEqual + }); + assert.strict.strict = assert.strict; + return exports$1; +} + +const exports = dew(); + +var AssertionError = exports.AssertionError; +var deepEqual = exports.deepEqual; +var deepStrictEqual = exports.deepStrictEqual; +var doesNotReject = exports.doesNotReject; +var doesNotThrow = exports.doesNotThrow; +var equal = exports.equal; +var fail = exports.fail; +var ifError = exports.ifError; +var notDeepEqual = exports.notDeepEqual; +var notDeepStrictEqual = exports.notDeepStrictEqual; +var notEqual = exports.notEqual; +var notStrictEqual = exports.notStrictEqual; +var ok = exports.ok; +var rejects = exports.rejects; +var strict = exports.strict; +var strictEqual = exports.strictEqual; +var throws = exports.throws; + +export { AssertionError, deepEqual, deepStrictEqual, exports as default, doesNotReject, doesNotThrow, equal, fail, ifError, notDeepEqual, notDeepStrictEqual, notEqual, notStrictEqual, ok, rejects, strict, strictEqual, throws }; diff --git a/nodelibs/browser/assert/strict.js b/nodelibs/browser/assert/strict.js index 9dd1983..3e930c0 100644 --- a/nodelibs/browser/assert/strict.js +++ b/nodelibs/browser/assert/strict.js @@ -1,6 +1,8 @@ import { strict } from '../assert.js'; -import '../chunk-D04hy_Cu.js'; -import '../chunk-DEckhzyo.js'; +import '../util.js'; +import '../chunk-DtcTpLWz.js'; +import '../chunk-CkFCi-G1.js'; +import '../chunk-DEMDiNwt.js'; const { fail, diff --git a/nodelibs/browser/buffer.js b/nodelibs/browser/buffer.js index c8b2db1..223490e 100644 --- a/nodelibs/browser/buffer.js +++ b/nodelibs/browser/buffer.js @@ -1,2304 +1,4 @@ -var exports$3 = {}, - _dewExec$2 = false; -function dew$2() { - if (_dewExec$2) return exports$3; - _dewExec$2 = true; - exports$3.byteLength = byteLength; - exports$3.toByteArray = toByteArray; - exports$3.fromByteArray = fromByteArray; - var lookup = []; - var revLookup = []; - var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array; - var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; - - for (var i = 0, len = code.length; i < len; ++i) { - lookup[i] = code[i]; - revLookup[code.charCodeAt(i)] = i; - } // Support decoding URL-safe base64 strings, as Node.js does. - // See: https://en.wikipedia.org/wiki/Base64#URL_applications - - - revLookup["-".charCodeAt(0)] = 62; - revLookup["_".charCodeAt(0)] = 63; - - function getLens(b64) { - var len = b64.length; - - if (len % 4 > 0) { - throw new Error("Invalid string. Length must be a multiple of 4"); - } // Trim off extra bytes after placeholder bytes are found - // See: https://github.com/beatgammit/base64-js/issues/42 - - - var validLen = b64.indexOf("="); - if (validLen === -1) validLen = len; - var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; - return [validLen, placeHoldersLen]; - } // base64 is 4/3 + up to two characters of the original data - - - function byteLength(b64) { - var lens = getLens(b64); - var validLen = lens[0]; - var placeHoldersLen = lens[1]; - return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; - } - - function _byteLength(b64, validLen, placeHoldersLen) { - return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; - } - - function toByteArray(b64) { - var tmp; - var lens = getLens(b64); - var validLen = lens[0]; - var placeHoldersLen = lens[1]; - var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); - var curByte = 0; // if there are placeholders, only get up to the last complete 4 chars - - var len = placeHoldersLen > 0 ? validLen - 4 : validLen; - var i; - - for (i = 0; i < len; i += 4) { - tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; - arr[curByte++] = tmp >> 16 & 255; - arr[curByte++] = tmp >> 8 & 255; - arr[curByte++] = tmp & 255; - } - - if (placeHoldersLen === 2) { - tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; - arr[curByte++] = tmp & 255; - } - - if (placeHoldersLen === 1) { - tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; - arr[curByte++] = tmp >> 8 & 255; - arr[curByte++] = tmp & 255; - } - - return arr; - } - - function tripletToBase64(num) { - return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63]; - } - - function encodeChunk(uint8, start, end) { - var tmp; - var output = []; - - for (var i = start; i < end; i += 3) { - tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255); - output.push(tripletToBase64(tmp)); - } - - return output.join(""); - } - - function fromByteArray(uint8) { - var tmp; - var len = uint8.length; - var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes - - var parts = []; - var maxChunkLength = 16383; // must be multiple of 3 - // go through the array every three bytes, we'll deal with trailing stuff later - - for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { - parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); - } // pad the end with zeros, but make sure to not forget the extra bytes - - - if (extraBytes === 1) { - tmp = uint8[len - 1]; - parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="); - } else if (extraBytes === 2) { - tmp = (uint8[len - 2] << 8) + uint8[len - 1]; - parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="); - } - - return parts.join(""); - } - - return exports$3; -} - -var exports$2 = {}, - _dewExec$1 = false; -function dew$1() { - if (_dewExec$1) return exports$2; - _dewExec$1 = true; - - /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ - exports$2.read = function (buffer, offset, isLE, mLen, nBytes) { - var e, m; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var nBits = -7; - var i = isLE ? nBytes - 1 : 0; - var d = isLE ? -1 : 1; - var s = buffer[offset + i]; - i += d; - e = s & (1 << -nBits) - 1; - s >>= -nBits; - nBits += eLen; - - for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} - - m = e & (1 << -nBits) - 1; - e >>= -nBits; - nBits += mLen; - - for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} - - if (e === 0) { - e = 1 - eBias; - } else if (e === eMax) { - return m ? NaN : (s ? -1 : 1) * Infinity; - } else { - m = m + Math.pow(2, mLen); - e = e - eBias; - } - - return (s ? -1 : 1) * m * Math.pow(2, e - mLen); - }; - - exports$2.write = function (buffer, value, offset, isLE, mLen, nBytes) { - var e, m, c; - var eLen = nBytes * 8 - mLen - 1; - var eMax = (1 << eLen) - 1; - var eBias = eMax >> 1; - var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; - var i = isLE ? 0 : nBytes - 1; - var d = isLE ? 1 : -1; - var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; - value = Math.abs(value); - - if (isNaN(value) || value === Infinity) { - m = isNaN(value) ? 1 : 0; - e = eMax; - } else { - e = Math.floor(Math.log(value) / Math.LN2); - - if (value * (c = Math.pow(2, -e)) < 1) { - e--; - c *= 2; - } - - if (e + eBias >= 1) { - value += rt / c; - } else { - value += rt * Math.pow(2, 1 - eBias); - } - - if (value * c >= 2) { - e++; - c /= 2; - } - - if (e + eBias >= eMax) { - m = 0; - e = eMax; - } else if (e + eBias >= 1) { - m = (value * c - 1) * Math.pow(2, mLen); - e = e + eBias; - } else { - m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); - e = 0; - } - } - - for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {} - - e = e << mLen | m; - eLen += mLen; - - for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {} - - buffer[offset + i - d] |= s * 128; - }; - - return exports$2; -} - -var exports$1 = {}, - _dewExec = false; -function dew() { - if (_dewExec) return exports$1; - _dewExec = true; - - const base64 = dew$2(); - - const ieee754 = dew$1(); - - const customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" ? Symbol["for"]("nodejs.util.inspect.custom") // eslint-disable-line dot-notation - : null; - exports$1.Buffer = Buffer; - exports$1.SlowBuffer = SlowBuffer; - exports$1.INSPECT_MAX_BYTES = 50; - const K_MAX_LENGTH = 2147483647; - exports$1.kMaxLength = K_MAX_LENGTH; - /** - * If `Buffer.TYPED_ARRAY_SUPPORT`: - * === true Use Uint8Array implementation (fastest) - * === false Print warning and recommend using `buffer` v4.x which has an Object - * implementation (most compatible, even IE6) - * - * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, - * Opera 11.6+, iOS 4.2+. - * - * We report that the browser does not support typed arrays if the are not subclassable - * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` - * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support - * for __proto__ and has a buggy typed array implementation. - */ - - Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); - - if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") { - console.error("This browser lacks typed array (Uint8Array) support which is required by " + "`buffer` v5.x. Use `buffer` v4.x if you require old browser support."); - } - - function typedArraySupport() { - // Can typed array instances can be augmented? - try { - const arr = new Uint8Array(1); - const proto = { - foo: function () { - return 42; - } - }; - Object.setPrototypeOf(proto, Uint8Array.prototype); - Object.setPrototypeOf(arr, proto); - return arr.foo() === 42; - } catch (e) { - return false; - } - } - - Object.defineProperty(Buffer.prototype, "parent", { - enumerable: true, - get: function () { - if (!Buffer.isBuffer(this)) return undefined; - return this.buffer; - } - }); - Object.defineProperty(Buffer.prototype, "offset", { - enumerable: true, - get: function () { - if (!Buffer.isBuffer(this)) return undefined; - return this.byteOffset; - } - }); - - function createBuffer(length) { - if (length > K_MAX_LENGTH) { - throw new RangeError("The value \"" + length + "\" is invalid for option \"size\""); - } // Return an augmented `Uint8Array` instance - - - const buf = new Uint8Array(length); - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; - } - /** - * The Buffer constructor returns instances of `Uint8Array` that have their - * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of - * `Uint8Array`, so the returned instances will have all the node `Buffer` methods - * and the `Uint8Array` methods. Square bracket notation works as expected -- it - * returns a single octet. - * - * The `Uint8Array` prototype remains unmodified. - */ - - - function Buffer(arg, encodingOrOffset, length) { - // Common case. - if (typeof arg === "number") { - if (typeof encodingOrOffset === "string") { - throw new TypeError("The \"string\" argument must be of type string. Received type number"); - } - - return allocUnsafe(arg); - } - - return from(arg, encodingOrOffset, length); - } - - Buffer.poolSize = 8192; // not used by this implementation - - function from(value, encodingOrOffset, length) { - if (typeof value === "string") { - return fromString(value, encodingOrOffset); - } - - if (ArrayBuffer.isView(value)) { - return fromArrayView(value); - } - - if (value == null) { - throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, " + "or Array-like Object. Received type " + typeof value); - } - - if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - - if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) { - return fromArrayBuffer(value, encodingOrOffset, length); - } - - if (typeof value === "number") { - throw new TypeError("The \"value\" argument must not be of type number. Received type number"); - } - - const valueOf = value.valueOf && value.valueOf(); - - if (valueOf != null && valueOf !== value) { - return Buffer.from(valueOf, encodingOrOffset, length); - } - - const b = fromObject(value); - if (b) return b; - - if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") { - return Buffer.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length); - } - - throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, " + "or Array-like Object. Received type " + typeof value); - } - /** - * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError - * if value is a number. - * Buffer.from(str[, encoding]) - * Buffer.from(array) - * Buffer.from(buffer) - * Buffer.from(arrayBuffer[, byteOffset[, length]]) - **/ - - - Buffer.from = function (value, encodingOrOffset, length) { - return from(value, encodingOrOffset, length); - }; // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: - // https://github.com/feross/buffer/pull/148 - - - Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); - Object.setPrototypeOf(Buffer, Uint8Array); - - function assertSize(size) { - if (typeof size !== "number") { - throw new TypeError("\"size\" argument must be of type number"); - } else if (size < 0) { - throw new RangeError("The value \"" + size + "\" is invalid for option \"size\""); - } - } - - function alloc(size, fill, encoding) { - assertSize(size); - - if (size <= 0) { - return createBuffer(size); - } - - if (fill !== undefined) { - // Only pay attention to encoding if it's a string. This - // prevents accidentally sending in a number that would - // be interpreted as a start offset. - return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); - } - - return createBuffer(size); - } - /** - * Creates a new filled Buffer instance. - * alloc(size[, fill[, encoding]]) - **/ - - - Buffer.alloc = function (size, fill, encoding) { - return alloc(size, fill, encoding); - }; - - function allocUnsafe(size) { - assertSize(size); - return createBuffer(size < 0 ? 0 : checked(size) | 0); - } - /** - * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. - * */ - - - Buffer.allocUnsafe = function (size) { - return allocUnsafe(size); - }; - /** - * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. - */ - - - Buffer.allocUnsafeSlow = function (size) { - return allocUnsafe(size); - }; - - function fromString(string, encoding) { - if (typeof encoding !== "string" || encoding === "") { - encoding = "utf8"; - } - - if (!Buffer.isEncoding(encoding)) { - throw new TypeError("Unknown encoding: " + encoding); - } - - const length = byteLength(string, encoding) | 0; - let buf = createBuffer(length); - const actual = buf.write(string, encoding); - - if (actual !== length) { - // Writing a hex string, for example, that contains invalid characters will - // cause everything after the first invalid character to be ignored. (e.g. - // 'abxxcd' will be treated as 'ab') - buf = buf.slice(0, actual); - } - - return buf; - } - - function fromArrayLike(array) { - const length = array.length < 0 ? 0 : checked(array.length) | 0; - const buf = createBuffer(length); - - for (let i = 0; i < length; i += 1) { - buf[i] = array[i] & 255; - } - - return buf; - } - - function fromArrayView(arrayView) { - if (isInstance(arrayView, Uint8Array)) { - const copy = new Uint8Array(arrayView); - return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); - } - - return fromArrayLike(arrayView); - } - - function fromArrayBuffer(array, byteOffset, length) { - if (byteOffset < 0 || array.byteLength < byteOffset) { - throw new RangeError("\"offset\" is outside of buffer bounds"); - } - - if (array.byteLength < byteOffset + (length || 0)) { - throw new RangeError("\"length\" is outside of buffer bounds"); - } - - let buf; - - if (byteOffset === undefined && length === undefined) { - buf = new Uint8Array(array); - } else if (length === undefined) { - buf = new Uint8Array(array, byteOffset); - } else { - buf = new Uint8Array(array, byteOffset, length); - } // Return an augmented `Uint8Array` instance - - - Object.setPrototypeOf(buf, Buffer.prototype); - return buf; - } - - function fromObject(obj) { - if (Buffer.isBuffer(obj)) { - const len = checked(obj.length) | 0; - const buf = createBuffer(len); - - if (buf.length === 0) { - return buf; - } - - obj.copy(buf, 0, 0, len); - return buf; - } - - if (obj.length !== undefined) { - if (typeof obj.length !== "number" || numberIsNaN(obj.length)) { - return createBuffer(0); - } - - return fromArrayLike(obj); - } - - if (obj.type === "Buffer" && Array.isArray(obj.data)) { - return fromArrayLike(obj.data); - } - } - - function checked(length) { - // Note: cannot use `length < K_MAX_LENGTH` here because that fails when - // length is NaN (which is otherwise coerced to zero.) - if (length >= K_MAX_LENGTH) { - throw new RangeError("Attempt to allocate Buffer larger than maximum " + "size: 0x" + K_MAX_LENGTH.toString(16) + " bytes"); - } - - return length | 0; - } - - function SlowBuffer(length) { - if (+length != length) { - // eslint-disable-line eqeqeq - length = 0; - } - - return Buffer.alloc(+length); - } - - Buffer.isBuffer = function isBuffer(b) { - return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false - }; - - Buffer.compare = function compare(a, b) { - if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); - if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); - - if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { - throw new TypeError("The \"buf1\", \"buf2\" arguments must be one of type Buffer or Uint8Array"); - } - - if (a === b) return 0; - let x = a.length; - let y = b.length; - - for (let i = 0, len = Math.min(x, y); i < len; ++i) { - if (a[i] !== b[i]) { - x = a[i]; - y = b[i]; - break; - } - } - - if (x < y) return -1; - if (y < x) return 1; - return 0; - }; - - Buffer.isEncoding = function isEncoding(encoding) { - switch (String(encoding).toLowerCase()) { - case "hex": - case "utf8": - case "utf-8": - case "ascii": - case "latin1": - case "binary": - case "base64": - case "ucs2": - case "ucs-2": - case "utf16le": - case "utf-16le": - return true; - - default: - return false; - } - }; - - Buffer.concat = function concat(list, length) { - if (!Array.isArray(list)) { - throw new TypeError("\"list\" argument must be an Array of Buffers"); - } - - if (list.length === 0) { - return Buffer.alloc(0); - } - - let i; - - if (length === undefined) { - length = 0; - - for (i = 0; i < list.length; ++i) { - length += list[i].length; - } - } - - const buffer = Buffer.allocUnsafe(length); - let pos = 0; - - for (i = 0; i < list.length; ++i) { - let buf = list[i]; - - if (isInstance(buf, Uint8Array)) { - if (pos + buf.length > buffer.length) { - if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); - buf.copy(buffer, pos); - } else { - Uint8Array.prototype.set.call(buffer, buf, pos); - } - } else if (!Buffer.isBuffer(buf)) { - throw new TypeError("\"list\" argument must be an Array of Buffers"); - } else { - buf.copy(buffer, pos); - } - - pos += buf.length; - } - - return buffer; - }; - - function byteLength(string, encoding) { - if (Buffer.isBuffer(string)) { - return string.length; - } - - if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { - return string.byteLength; - } - - if (typeof string !== "string") { - throw new TypeError("The \"string\" argument must be one of type string, Buffer, or ArrayBuffer. " + "Received type " + typeof string); - } - - const len = string.length; - const mustMatch = arguments.length > 2 && arguments[2] === true; - if (!mustMatch && len === 0) return 0; // Use a for loop to avoid recursion - - let loweredCase = false; - - for (;;) { - switch (encoding) { - case "ascii": - case "latin1": - case "binary": - return len; - - case "utf8": - case "utf-8": - return utf8ToBytes(string).length; - - case "ucs2": - case "ucs-2": - case "utf16le": - case "utf-16le": - return len * 2; - - case "hex": - return len >>> 1; - - case "base64": - return base64ToBytes(string).length; - - default: - if (loweredCase) { - return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 - } - - encoding = ("" + encoding).toLowerCase(); - loweredCase = true; - } - } - } - - Buffer.byteLength = byteLength; - - function slowToString(encoding, start, end) { - let loweredCase = false; // No need to verify that "this.length <= MAX_UINT32" since it's a read-only - // property of a typed array. - // This behaves neither like String nor Uint8Array in that we set start/end - // to their upper/lower bounds if the value passed is out of range. - // undefined is handled specially as per ECMA-262 6th Edition, - // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. - - if (start === undefined || start < 0) { - start = 0; - } // Return early if start > this.length. Done here to prevent potential uint32 - // coercion fail below. - - - if (start > this.length) { - return ""; - } - - if (end === undefined || end > this.length) { - end = this.length; - } - - if (end <= 0) { - return ""; - } // Force coercion to uint32. This will also coerce falsey/NaN values to 0. - - - end >>>= 0; - start >>>= 0; - - if (end <= start) { - return ""; - } - - if (!encoding) encoding = "utf8"; - - while (true) { - switch (encoding) { - case "hex": - return hexSlice(this, start, end); - - case "utf8": - case "utf-8": - return utf8Slice(this, start, end); - - case "ascii": - return asciiSlice(this, start, end); - - case "latin1": - case "binary": - return latin1Slice(this, start, end); - - case "base64": - return base64Slice(this, start, end); - - case "ucs2": - case "ucs-2": - case "utf16le": - case "utf-16le": - return utf16leSlice(this, start, end); - - default: - if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); - encoding = (encoding + "").toLowerCase(); - loweredCase = true; - } - } - } // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) - // to detect a Buffer instance. It's not possible to use `instanceof Buffer` - // reliably in a browserify context because there could be multiple different - // copies of the 'buffer' package in use. This method works even for Buffer - // instances that were created from another copy of the `buffer` package. - // See: https://github.com/feross/buffer/issues/154 - - - Buffer.prototype._isBuffer = true; - - function swap(b, n, m) { - const i = b[n]; - b[n] = b[m]; - b[m] = i; - } - - Buffer.prototype.swap16 = function swap16() { - const len = this.length; - - if (len % 2 !== 0) { - throw new RangeError("Buffer size must be a multiple of 16-bits"); - } - - for (let i = 0; i < len; i += 2) { - swap(this, i, i + 1); - } - - return this; - }; - - Buffer.prototype.swap32 = function swap32() { - const len = this.length; - - if (len % 4 !== 0) { - throw new RangeError("Buffer size must be a multiple of 32-bits"); - } - - for (let i = 0; i < len; i += 4) { - swap(this, i, i + 3); - swap(this, i + 1, i + 2); - } - - return this; - }; - - Buffer.prototype.swap64 = function swap64() { - const len = this.length; - - if (len % 8 !== 0) { - throw new RangeError("Buffer size must be a multiple of 64-bits"); - } - - for (let i = 0; i < len; i += 8) { - swap(this, i, i + 7); - swap(this, i + 1, i + 6); - swap(this, i + 2, i + 5); - swap(this, i + 3, i + 4); - } - - return this; - }; - - Buffer.prototype.toString = function toString() { - const length = this.length; - if (length === 0) return ""; - if (arguments.length === 0) return utf8Slice(this, 0, length); - return slowToString.apply(this, arguments); - }; - - Buffer.prototype.toLocaleString = Buffer.prototype.toString; - - Buffer.prototype.equals = function equals(b) { - if (!Buffer.isBuffer(b)) throw new TypeError("Argument must be a Buffer"); - if (this === b) return true; - return Buffer.compare(this, b) === 0; - }; - - Buffer.prototype.inspect = function inspect() { - let str = ""; - const max = exports$1.INSPECT_MAX_BYTES; - str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim(); - if (this.length > max) str += " ... "; - return ""; - }; - - if (customInspectSymbol) { - Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; - } - - Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { - if (isInstance(target, Uint8Array)) { - target = Buffer.from(target, target.offset, target.byteLength); - } - - if (!Buffer.isBuffer(target)) { - throw new TypeError("The \"target\" argument must be one of type Buffer or Uint8Array. " + "Received type " + typeof target); - } - - if (start === undefined) { - start = 0; - } - - if (end === undefined) { - end = target ? target.length : 0; - } - - if (thisStart === undefined) { - thisStart = 0; - } - - if (thisEnd === undefined) { - thisEnd = this.length; - } - - if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { - throw new RangeError("out of range index"); - } - - if (thisStart >= thisEnd && start >= end) { - return 0; - } - - if (thisStart >= thisEnd) { - return -1; - } - - if (start >= end) { - return 1; - } - - start >>>= 0; - end >>>= 0; - thisStart >>>= 0; - thisEnd >>>= 0; - if (this === target) return 0; - let x = thisEnd - thisStart; - let y = end - start; - const len = Math.min(x, y); - const thisCopy = this.slice(thisStart, thisEnd); - const targetCopy = target.slice(start, end); - - for (let i = 0; i < len; ++i) { - if (thisCopy[i] !== targetCopy[i]) { - x = thisCopy[i]; - y = targetCopy[i]; - break; - } - } - - if (x < y) return -1; - if (y < x) return 1; - return 0; - }; // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, - // OR the last index of `val` in `buffer` at offset <= `byteOffset`. - // - // Arguments: - // - buffer - a Buffer to search - // - val - a string, Buffer, or number - // - byteOffset - an index into `buffer`; will be clamped to an int32 - // - encoding - an optional encoding, relevant is val is a string - // - dir - true for indexOf, false for lastIndexOf - - - function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { - // Empty buffer means no match - if (buffer.length === 0) return -1; // Normalize byteOffset - - if (typeof byteOffset === "string") { - encoding = byteOffset; - byteOffset = 0; - } else if (byteOffset > 2147483647) { - byteOffset = 2147483647; - } else if (byteOffset < -2147483648) { - byteOffset = -2147483648; - } - - byteOffset = +byteOffset; // Coerce to Number. - - if (numberIsNaN(byteOffset)) { - // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer - byteOffset = dir ? 0 : buffer.length - 1; - } // Normalize byteOffset: negative offsets start from the end of the buffer - - - if (byteOffset < 0) byteOffset = buffer.length + byteOffset; - - if (byteOffset >= buffer.length) { - if (dir) return -1;else byteOffset = buffer.length - 1; - } else if (byteOffset < 0) { - if (dir) byteOffset = 0;else return -1; - } // Normalize val - - - if (typeof val === "string") { - val = Buffer.from(val, encoding); - } // Finally, search either indexOf (if dir is true) or lastIndexOf - - - if (Buffer.isBuffer(val)) { - // Special case: looking for empty string/buffer always fails - if (val.length === 0) { - return -1; - } - - return arrayIndexOf(buffer, val, byteOffset, encoding, dir); - } else if (typeof val === "number") { - val = val & 255; // Search for a byte value [0-255] - - if (typeof Uint8Array.prototype.indexOf === "function") { - if (dir) { - return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); - } else { - return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); - } - } - - return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); - } - - throw new TypeError("val must be string, number or Buffer"); - } - - function arrayIndexOf(arr, val, byteOffset, encoding, dir) { - let indexSize = 1; - let arrLength = arr.length; - let valLength = val.length; - - if (encoding !== undefined) { - encoding = String(encoding).toLowerCase(); - - if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") { - if (arr.length < 2 || val.length < 2) { - return -1; - } - - indexSize = 2; - arrLength /= 2; - valLength /= 2; - byteOffset /= 2; - } - } - - function read(buf, i) { - if (indexSize === 1) { - return buf[i]; - } else { - return buf.readUInt16BE(i * indexSize); - } - } - - let i; - - if (dir) { - let foundIndex = -1; - - for (i = byteOffset; i < arrLength; i++) { - if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { - if (foundIndex === -1) foundIndex = i; - if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; - } else { - if (foundIndex !== -1) i -= i - foundIndex; - foundIndex = -1; - } - } - } else { - if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; - - for (i = byteOffset; i >= 0; i--) { - let found = true; - - for (let j = 0; j < valLength; j++) { - if (read(arr, i + j) !== read(val, j)) { - found = false; - break; - } - } - - if (found) return i; - } - } - - return -1; - } - - Buffer.prototype.includes = function includes(val, byteOffset, encoding) { - return this.indexOf(val, byteOffset, encoding) !== -1; - }; - - Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, true); - }; - - Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { - return bidirectionalIndexOf(this, val, byteOffset, encoding, false); - }; - - function hexWrite(buf, string, offset, length) { - offset = Number(offset) || 0; - const remaining = buf.length - offset; - - if (!length) { - length = remaining; - } else { - length = Number(length); - - if (length > remaining) { - length = remaining; - } - } - - const strLen = string.length; - - if (length > strLen / 2) { - length = strLen / 2; - } - - let i; - - for (i = 0; i < length; ++i) { - const parsed = parseInt(string.substr(i * 2, 2), 16); - if (numberIsNaN(parsed)) return i; - buf[offset + i] = parsed; - } - - return i; - } - - function utf8Write(buf, string, offset, length) { - return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); - } - - function asciiWrite(buf, string, offset, length) { - return blitBuffer(asciiToBytes(string), buf, offset, length); - } - - function base64Write(buf, string, offset, length) { - return blitBuffer(base64ToBytes(string), buf, offset, length); - } - - function ucs2Write(buf, string, offset, length) { - return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); - } - - Buffer.prototype.write = function write(string, offset, length, encoding) { - // Buffer#write(string) - if (offset === undefined) { - encoding = "utf8"; - length = this.length; - offset = 0; // Buffer#write(string, encoding) - } else if (length === undefined && typeof offset === "string") { - encoding = offset; - length = this.length; - offset = 0; // Buffer#write(string, offset[, length][, encoding]) - } else if (isFinite(offset)) { - offset = offset >>> 0; - - if (isFinite(length)) { - length = length >>> 0; - if (encoding === undefined) encoding = "utf8"; - } else { - encoding = length; - length = undefined; - } - } else { - throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported"); - } - - const remaining = this.length - offset; - if (length === undefined || length > remaining) length = remaining; - - if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { - throw new RangeError("Attempt to write outside buffer bounds"); - } - - if (!encoding) encoding = "utf8"; - let loweredCase = false; - - for (;;) { - switch (encoding) { - case "hex": - return hexWrite(this, string, offset, length); - - case "utf8": - case "utf-8": - return utf8Write(this, string, offset, length); - - case "ascii": - case "latin1": - case "binary": - return asciiWrite(this, string, offset, length); - - case "base64": - // Warning: maxLength not taken into account in base64Write - return base64Write(this, string, offset, length); - - case "ucs2": - case "ucs-2": - case "utf16le": - case "utf-16le": - return ucs2Write(this, string, offset, length); - - default: - if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); - encoding = ("" + encoding).toLowerCase(); - loweredCase = true; - } - } - }; - - Buffer.prototype.toJSON = function toJSON() { - return { - type: "Buffer", - data: Array.prototype.slice.call(this._arr || this, 0) - }; - }; - - function base64Slice(buf, start, end) { - if (start === 0 && end === buf.length) { - return base64.fromByteArray(buf); - } else { - return base64.fromByteArray(buf.slice(start, end)); - } - } - - function utf8Slice(buf, start, end) { - end = Math.min(buf.length, end); - const res = []; - let i = start; - - while (i < end) { - const firstByte = buf[i]; - let codePoint = null; - let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; - - if (i + bytesPerSequence <= end) { - let secondByte, thirdByte, fourthByte, tempCodePoint; - - switch (bytesPerSequence) { - case 1: - if (firstByte < 128) { - codePoint = firstByte; - } - - break; - - case 2: - secondByte = buf[i + 1]; - - if ((secondByte & 192) === 128) { - tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; - - if (tempCodePoint > 127) { - codePoint = tempCodePoint; - } - } - - break; - - case 3: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - - if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { - tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; - - if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { - codePoint = tempCodePoint; - } - } - - break; - - case 4: - secondByte = buf[i + 1]; - thirdByte = buf[i + 2]; - fourthByte = buf[i + 3]; - - if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { - tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; - - if (tempCodePoint > 65535 && tempCodePoint < 1114112) { - codePoint = tempCodePoint; - } - } - - } - } - - if (codePoint === null) { - // we did not generate a valid codePoint so insert a - // replacement char (U+FFFD) and advance only 1 byte - codePoint = 65533; - bytesPerSequence = 1; - } else if (codePoint > 65535) { - // encode to utf16 (surrogate pair dance) - codePoint -= 65536; - res.push(codePoint >>> 10 & 1023 | 55296); - codePoint = 56320 | codePoint & 1023; - } - - res.push(codePoint); - i += bytesPerSequence; - } - - return decodeCodePointsArray(res); - } // Based on http://stackoverflow.com/a/22747272/680742, the browser with - // the lowest limit is Chrome, with 0x10000 args. - // We go 1 magnitude less, for safety - - - const MAX_ARGUMENTS_LENGTH = 4096; - - function decodeCodePointsArray(codePoints) { - const len = codePoints.length; - - if (len <= MAX_ARGUMENTS_LENGTH) { - return String.fromCharCode.apply(String, codePoints); // avoid extra slice() - } // Decode in chunks to avoid "call stack size exceeded". - - - let res = ""; - let i = 0; - - while (i < len) { - res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); - } - - return res; - } - - function asciiSlice(buf, start, end) { - let ret = ""; - end = Math.min(buf.length, end); - - for (let i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i] & 127); - } - - return ret; - } - - function latin1Slice(buf, start, end) { - let ret = ""; - end = Math.min(buf.length, end); - - for (let i = start; i < end; ++i) { - ret += String.fromCharCode(buf[i]); - } - - return ret; - } - - function hexSlice(buf, start, end) { - const len = buf.length; - if (!start || start < 0) start = 0; - if (!end || end < 0 || end > len) end = len; - let out = ""; - - for (let i = start; i < end; ++i) { - out += hexSliceLookupTable[buf[i]]; - } - - return out; - } - - function utf16leSlice(buf, start, end) { - const bytes = buf.slice(start, end); - let res = ""; // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) - - for (let i = 0; i < bytes.length - 1; i += 2) { - res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); - } - - return res; - } - - Buffer.prototype.slice = function slice(start, end) { - const len = this.length; - start = ~~start; - end = end === undefined ? len : ~~end; - - if (start < 0) { - start += len; - if (start < 0) start = 0; - } else if (start > len) { - start = len; - } - - if (end < 0) { - end += len; - if (end < 0) end = 0; - } else if (end > len) { - end = len; - } - - if (end < start) end = start; - const newBuf = this.subarray(start, end); // Return an augmented `Uint8Array` instance - - Object.setPrototypeOf(newBuf, Buffer.prototype); - return newBuf; - }; - /* - * Need to make sure that buffer isn't trying to write out of bounds. - */ - - - function checkOffset(offset, ext, length) { - if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint"); - if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length"); - } - - Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - let val = this[offset]; - let mul = 1; - let i = 0; - - while (++i < byteLength && (mul *= 256)) { - val += this[offset + i] * mul; - } - - return val; - }; - - Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - - if (!noAssert) { - checkOffset(offset, byteLength, this.length); - } - - let val = this[offset + --byteLength]; - let mul = 1; - - while (byteLength > 0 && (mul *= 256)) { - val += this[offset + --byteLength] * mul; - } - - return val; - }; - - Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 1, this.length); - return this[offset]; - }; - - Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] | this[offset + 1] << 8; - }; - - Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - return this[offset] << 8 | this[offset + 1]; - }; - - Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216; - }; - - Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); - }; - - Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) { - offset = offset >>> 0; - validateNumber(offset, "offset"); - const first = this[offset]; - const last = this[offset + 7]; - - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - - const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24; - const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24; - return BigInt(lo) + (BigInt(hi) << BigInt(32)); - }); - Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) { - offset = offset >>> 0; - validateNumber(offset, "offset"); - const first = this[offset]; - const last = this[offset + 7]; - - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - - const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset]; - const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last; - return (BigInt(hi) << BigInt(32)) + BigInt(lo); - }); - - Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - let val = this[offset]; - let mul = 1; - let i = 0; - - while (++i < byteLength && (mul *= 256)) { - val += this[offset + i] * mul; - } - - mul *= 128; - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - return val; - }; - - Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { - offset = offset >>> 0; - byteLength = byteLength >>> 0; - if (!noAssert) checkOffset(offset, byteLength, this.length); - let i = byteLength; - let mul = 1; - let val = this[offset + --i]; - - while (i > 0 && (mul *= 256)) { - val += this[offset + --i] * mul; - } - - mul *= 128; - if (val >= mul) val -= Math.pow(2, 8 * byteLength); - return val; - }; - - Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 1, this.length); - if (!(this[offset] & 128)) return this[offset]; - return (255 - this[offset] + 1) * -1; - }; - - Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - const val = this[offset] | this[offset + 1] << 8; - return val & 32768 ? val | 4294901760 : val; - }; - - Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 2, this.length); - const val = this[offset + 1] | this[offset] << 8; - return val & 32768 ? val | 4294901760 : val; - }; - - Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; - }; - - Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; - }; - - Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) { - offset = offset >>> 0; - validateNumber(offset, "offset"); - const first = this[offset]; - const last = this[offset + 7]; - - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - - const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24); // Overflow - - return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24); - }); - Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) { - offset = offset >>> 0; - validateNumber(offset, "offset"); - const first = this[offset]; - const last = this[offset + 7]; - - if (first === undefined || last === undefined) { - boundsError(offset, this.length - 8); - } - - const val = (first << 24) + // Overflow - this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset]; - return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last); - }); - - Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return ieee754.read(this, offset, true, 23, 4); - }; - - Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 4, this.length); - return ieee754.read(this, offset, false, 23, 4); - }; - - Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 8, this.length); - return ieee754.read(this, offset, true, 52, 8); - }; - - Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { - offset = offset >>> 0; - if (!noAssert) checkOffset(offset, 8, this.length); - return ieee754.read(this, offset, false, 52, 8); - }; - - function checkInt(buf, value, offset, ext, max, min) { - if (!Buffer.isBuffer(buf)) throw new TypeError("\"buffer\" argument must be a Buffer instance"); - if (value > max || value < min) throw new RangeError("\"value\" argument is out of bounds"); - if (offset + ext > buf.length) throw new RangeError("Index out of range"); - } - - Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - byteLength = byteLength >>> 0; - - if (!noAssert) { - const maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - - let mul = 1; - let i = 0; - this[offset] = value & 255; - - while (++i < byteLength && (mul *= 256)) { - this[offset + i] = value / mul & 255; - } - - return offset + byteLength; - }; - - Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - byteLength = byteLength >>> 0; - - if (!noAssert) { - const maxBytes = Math.pow(2, 8 * byteLength) - 1; - checkInt(this, value, offset, byteLength, maxBytes, 0); - } - - let i = byteLength - 1; - let mul = 1; - this[offset + i] = value & 255; - - while (--i >= 0 && (mul *= 256)) { - this[offset + i] = value / mul & 255; - } - - return offset + byteLength; - }; - - Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 1, 255, 0); - this[offset] = value & 255; - return offset + 1; - }; - - Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); - this[offset] = value & 255; - this[offset + 1] = value >>> 8; - return offset + 2; - }; - - Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); - this[offset] = value >>> 8; - this[offset + 1] = value & 255; - return offset + 2; - }; - - Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); - this[offset + 3] = value >>> 24; - this[offset + 2] = value >>> 16; - this[offset + 1] = value >>> 8; - this[offset] = value & 255; - return offset + 4; - }; - - Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); - this[offset] = value >>> 24; - this[offset + 1] = value >>> 16; - this[offset + 2] = value >>> 8; - this[offset + 3] = value & 255; - return offset + 4; - }; - - function wrtBigUInt64LE(buf, value, offset, min, max) { - checkIntBI(value, min, max, buf, offset, 7); - let lo = Number(value & BigInt(4294967295)); - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - lo = lo >> 8; - buf[offset++] = lo; - let hi = Number(value >> BigInt(32) & BigInt(4294967295)); - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - hi = hi >> 8; - buf[offset++] = hi; - return offset; - } - - function wrtBigUInt64BE(buf, value, offset, min, max) { - checkIntBI(value, min, max, buf, offset, 7); - let lo = Number(value & BigInt(4294967295)); - buf[offset + 7] = lo; - lo = lo >> 8; - buf[offset + 6] = lo; - lo = lo >> 8; - buf[offset + 5] = lo; - lo = lo >> 8; - buf[offset + 4] = lo; - let hi = Number(value >> BigInt(32) & BigInt(4294967295)); - buf[offset + 3] = hi; - hi = hi >> 8; - buf[offset + 2] = hi; - hi = hi >> 8; - buf[offset + 1] = hi; - hi = hi >> 8; - buf[offset] = hi; - return offset + 8; - } - - Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) { - return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff")); - }); - Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) { - return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff")); - }); - - Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - - if (!noAssert) { - const limit = Math.pow(2, 8 * byteLength - 1); - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - - let i = 0; - let mul = 1; - let sub = 0; - this[offset] = value & 255; - - while (++i < byteLength && (mul *= 256)) { - if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { - sub = 1; - } - - this[offset + i] = (value / mul >> 0) - sub & 255; - } - - return offset + byteLength; - }; - - Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { - value = +value; - offset = offset >>> 0; - - if (!noAssert) { - const limit = Math.pow(2, 8 * byteLength - 1); - checkInt(this, value, offset, byteLength, limit - 1, -limit); - } - - let i = byteLength - 1; - let mul = 1; - let sub = 0; - this[offset + i] = value & 255; - - while (--i >= 0 && (mul *= 256)) { - if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { - sub = 1; - } - - this[offset + i] = (value / mul >> 0) - sub & 255; - } - - return offset + byteLength; - }; - - Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 1, 127, -128); - if (value < 0) value = 255 + value + 1; - this[offset] = value & 255; - return offset + 1; - }; - - Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); - this[offset] = value & 255; - this[offset + 1] = value >>> 8; - return offset + 2; - }; - - Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); - this[offset] = value >>> 8; - this[offset + 1] = value & 255; - return offset + 2; - }; - - Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); - this[offset] = value & 255; - this[offset + 1] = value >>> 8; - this[offset + 2] = value >>> 16; - this[offset + 3] = value >>> 24; - return offset + 4; - }; - - Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { - value = +value; - offset = offset >>> 0; - if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); - if (value < 0) value = 4294967295 + value + 1; - this[offset] = value >>> 24; - this[offset + 1] = value >>> 16; - this[offset + 2] = value >>> 8; - this[offset + 3] = value & 255; - return offset + 4; - }; - - Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) { - return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); - }); - Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) { - return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); - }); - - function checkIEEE754(buf, value, offset, ext, max, min) { - if (offset + ext > buf.length) throw new RangeError("Index out of range"); - if (offset < 0) throw new RangeError("Index out of range"); - } - - function writeFloat(buf, value, offset, littleEndian, noAssert) { - value = +value; - offset = offset >>> 0; - - if (!noAssert) { - checkIEEE754(buf, value, offset, 4); - } - - ieee754.write(buf, value, offset, littleEndian, 23, 4); - return offset + 4; - } - - Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { - return writeFloat(this, value, offset, true, noAssert); - }; - - Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { - return writeFloat(this, value, offset, false, noAssert); - }; - - function writeDouble(buf, value, offset, littleEndian, noAssert) { - value = +value; - offset = offset >>> 0; - - if (!noAssert) { - checkIEEE754(buf, value, offset, 8); - } - - ieee754.write(buf, value, offset, littleEndian, 52, 8); - return offset + 8; - } - - Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { - return writeDouble(this, value, offset, true, noAssert); - }; - - Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { - return writeDouble(this, value, offset, false, noAssert); - }; // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) - - - Buffer.prototype.copy = function copy(target, targetStart, start, end) { - if (!Buffer.isBuffer(target)) throw new TypeError("argument should be a Buffer"); - if (!start) start = 0; - if (!end && end !== 0) end = this.length; - if (targetStart >= target.length) targetStart = target.length; - if (!targetStart) targetStart = 0; - if (end > 0 && end < start) end = start; // Copy 0 bytes; we're done - - if (end === start) return 0; - if (target.length === 0 || this.length === 0) return 0; // Fatal error conditions - - if (targetStart < 0) { - throw new RangeError("targetStart out of bounds"); - } - - if (start < 0 || start >= this.length) throw new RangeError("Index out of range"); - if (end < 0) throw new RangeError("sourceEnd out of bounds"); // Are we oob? - - if (end > this.length) end = this.length; - - if (target.length - targetStart < end - start) { - end = target.length - targetStart + start; - } - - const len = end - start; - - if (this === target && typeof Uint8Array.prototype.copyWithin === "function") { - // Use built-in when available, missing from IE11 - this.copyWithin(targetStart, start, end); - } else { - Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); - } - - return len; - }; // Usage: - // buffer.fill(number[, offset[, end]]) - // buffer.fill(buffer[, offset[, end]]) - // buffer.fill(string[, offset[, end]][, encoding]) - - - Buffer.prototype.fill = function fill(val, start, end, encoding) { - // Handle string cases: - if (typeof val === "string") { - if (typeof start === "string") { - encoding = start; - start = 0; - end = this.length; - } else if (typeof end === "string") { - encoding = end; - end = this.length; - } - - if (encoding !== undefined && typeof encoding !== "string") { - throw new TypeError("encoding must be a string"); - } - - if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) { - throw new TypeError("Unknown encoding: " + encoding); - } - - if (val.length === 1) { - const code = val.charCodeAt(0); - - if (encoding === "utf8" && code < 128 || encoding === "latin1") { - // Fast path: If `val` fits into a single byte, use that numeric value. - val = code; - } - } - } else if (typeof val === "number") { - val = val & 255; - } else if (typeof val === "boolean") { - val = Number(val); - } // Invalid ranges are not set to a default, so can range check early. - - - if (start < 0 || this.length < start || this.length < end) { - throw new RangeError("Out of range index"); - } - - if (end <= start) { - return this; - } - - start = start >>> 0; - end = end === undefined ? this.length : end >>> 0; - if (!val) val = 0; - let i; - - if (typeof val === "number") { - for (i = start; i < end; ++i) { - this[i] = val; - } - } else { - const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); - const len = bytes.length; - - if (len === 0) { - throw new TypeError("The value \"" + val + "\" is invalid for argument \"value\""); - } - - for (i = 0; i < end - start; ++i) { - this[i + start] = bytes[i % len]; - } - } - - return this; - }; // CUSTOM ERRORS - // ============= - // Simplified versions from Node, changed for Buffer-only usage - - - const errors = {}; - - function E(sym, getMessage, Base) { - errors[sym] = class NodeError extends Base { - constructor() { - super(); - Object.defineProperty(this, "message", { - value: getMessage.apply(this, arguments), - writable: true, - configurable: true - }); // Add the error code to the name to include it in the stack trace. - - this.name = `${this.name} [${sym}]`; // Access the stack to generate the error message including the error code - // from the name. - - this.stack; // eslint-disable-line no-unused-expressions - // Reset the name to the actual name. - - delete this.name; - } - - get code() { - return sym; - } - - set code(value) { - Object.defineProperty(this, "code", { - configurable: true, - enumerable: true, - value, - writable: true - }); - } - - toString() { - return `${this.name} [${sym}]: ${this.message}`; - } - - }; - } - - E("ERR_BUFFER_OUT_OF_BOUNDS", function (name) { - if (name) { - return `${name} is outside of buffer bounds`; - } - - return "Attempt to access memory outside buffer bounds"; - }, RangeError); - E("ERR_INVALID_ARG_TYPE", function (name, actual) { - return `The "${name}" argument must be of type number. Received type ${typeof actual}`; - }, TypeError); - E("ERR_OUT_OF_RANGE", function (str, range, input) { - let msg = `The value of "${str}" is out of range.`; - let received = input; - - if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) { - received = addNumericalSeparator(String(input)); - } else if (typeof input === "bigint") { - received = String(input); - - if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) { - received = addNumericalSeparator(received); - } - - received += "n"; - } - - msg += ` It must be ${range}. Received ${received}`; - return msg; - }, RangeError); - - function addNumericalSeparator(val) { - let res = ""; - let i = val.length; - const start = val[0] === "-" ? 1 : 0; - - for (; i >= start + 4; i -= 3) { - res = `_${val.slice(i - 3, i)}${res}`; - } - - return `${val.slice(0, i)}${res}`; - } // CHECK FUNCTIONS - // =============== - - - function checkBounds(buf, offset, byteLength) { - validateNumber(offset, "offset"); - - if (buf[offset] === undefined || buf[offset + byteLength] === undefined) { - boundsError(offset, buf.length - (byteLength + 1)); - } - } - - function checkIntBI(value, min, max, buf, offset, byteLength) { - if (value > max || value < min) { - const n = typeof min === "bigint" ? "n" : ""; - let range; - - { - if (min === 0 || min === BigInt(0)) { - range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`; - } else { - range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + `${(byteLength + 1) * 8 - 1}${n}`; - } - } - - throw new errors.ERR_OUT_OF_RANGE("value", range, value); - } - - checkBounds(buf, offset, byteLength); - } - - function validateNumber(value, name) { - if (typeof value !== "number") { - throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value); - } - } - - function boundsError(value, length, type) { - if (Math.floor(value) !== value) { - validateNumber(value, type); - throw new errors.ERR_OUT_OF_RANGE("offset", "an integer", value); - } - - if (length < 0) { - throw new errors.ERR_BUFFER_OUT_OF_BOUNDS(); - } - - throw new errors.ERR_OUT_OF_RANGE("offset", `>= ${0} and <= ${length}`, value); - } // HELPER FUNCTIONS - // ================ - - - const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; - - function base64clean(str) { - // Node takes equal signs as end of the Base64 encoding - str = str.split("=")[0]; // Node strips out invalid characters like \n and \t from the string, base64-js does not - - str = str.trim().replace(INVALID_BASE64_RE, ""); // Node converts strings with length < 2 to '' - - if (str.length < 2) return ""; // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not - - while (str.length % 4 !== 0) { - str = str + "="; - } - - return str; - } - - function utf8ToBytes(string, units) { - units = units || Infinity; - let codePoint; - const length = string.length; - let leadSurrogate = null; - const bytes = []; - - for (let i = 0; i < length; ++i) { - codePoint = string.charCodeAt(i); // is surrogate component - - if (codePoint > 55295 && codePoint < 57344) { - // last char was a lead - if (!leadSurrogate) { - // no lead yet - if (codePoint > 56319) { - // unexpected trail - if ((units -= 3) > -1) bytes.push(239, 191, 189); - continue; - } else if (i + 1 === length) { - // unpaired lead - if ((units -= 3) > -1) bytes.push(239, 191, 189); - continue; - } // valid lead - - - leadSurrogate = codePoint; - continue; - } // 2 leads in a row - - - if (codePoint < 56320) { - if ((units -= 3) > -1) bytes.push(239, 191, 189); - leadSurrogate = codePoint; - continue; - } // valid surrogate pair - - - codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536; - } else if (leadSurrogate) { - // valid bmp char, but last char was a lead - if ((units -= 3) > -1) bytes.push(239, 191, 189); - } - - leadSurrogate = null; // encode utf8 - - if (codePoint < 128) { - if ((units -= 1) < 0) break; - bytes.push(codePoint); - } else if (codePoint < 2048) { - if ((units -= 2) < 0) break; - bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128); - } else if (codePoint < 65536) { - if ((units -= 3) < 0) break; - bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); - } else if (codePoint < 1114112) { - if ((units -= 4) < 0) break; - bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); - } else { - throw new Error("Invalid code point"); - } - } - - return bytes; - } - - function asciiToBytes(str) { - const byteArray = []; - - for (let i = 0; i < str.length; ++i) { - // Node's code seems to be doing this and not & 0x7F.. - byteArray.push(str.charCodeAt(i) & 255); - } - - return byteArray; - } - - function utf16leToBytes(str, units) { - let c, hi, lo; - const byteArray = []; - - for (let i = 0; i < str.length; ++i) { - if ((units -= 2) < 0) break; - c = str.charCodeAt(i); - hi = c >> 8; - lo = c % 256; - byteArray.push(lo); - byteArray.push(hi); - } - - return byteArray; - } - - function base64ToBytes(str) { - return base64.toByteArray(base64clean(str)); - } - - function blitBuffer(src, dst, offset, length) { - let i; - - for (i = 0; i < length; ++i) { - if (i + offset >= dst.length || i >= src.length) break; - dst[i + offset] = src[i]; - } - - return i; - } // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass - // the `instanceof` check but they should be treated as of that type. - // See: https://github.com/feross/buffer/issues/166 - - - function isInstance(obj, type) { - return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name; - } - - function numberIsNaN(obj) { - // For IE11 support - return obj !== obj; // eslint-disable-line no-self-compare - } // Create lookup table for `toString('hex')` - // See: https://github.com/feross/buffer/issues/219 - - - const hexSliceLookupTable = function () { - const alphabet = "0123456789abcdef"; - const table = new Array(256); - - for (let i = 0; i < 16; ++i) { - const i16 = i * 16; - - for (let j = 0; j < 16; ++j) { - table[i16 + j] = alphabet[i] + alphabet[j]; - } - } - - return table; - }(); // Return not function with Error if BigInt not supported - - - function defineBigIntMethod(fn) { - return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn; - } - - function BufferBigIntNotDefined() { - throw new Error("BigInt not supported"); - } - - return exports$1; -} +import { d as dew } from './chunk-DtuTasat.js'; const exports = dew(); exports['Buffer']; exports['SlowBuffer']; exports['INSPECT_MAX_BYTES']; exports['kMaxLength']; diff --git a/nodelibs/browser/chunk-gkrMq4sQ.js b/nodelibs/browser/chunk-B6-G-Ftj.js similarity index 78% rename from nodelibs/browser/chunk-gkrMq4sQ.js rename to nodelibs/browser/chunk-B6-G-Ftj.js index 623d15b..fec8fe6 100644 --- a/nodelibs/browser/chunk-gkrMq4sQ.js +++ b/nodelibs/browser/chunk-B6-G-Ftj.js @@ -1,6 +1,9 @@ -import './events.js'; -import { a as dew$1, c as dew$2, e as dew$3, f as dew$4, g as dew$5, h as dew$6, i as dew$7, d as dew$8 } from './chunk-CU2hd6BF.js'; +import './chunk-DtDiafJB.js'; +import { c as dew$3, f as dew$8, g as dew$7, h as dew$2, i as dew$1, j as dew$6, k as dew$4, d as dew$f } from './chunk-B738Er4n.js'; import { y } from './chunk-tHuMsdT0.js'; +import { p as promisify } from './chunk-CbQqNoLO.js'; +import './chunk-D3uu3VYh.js'; +import './chunk-b0rmRow7.js'; var exports$1 = {}, _dewExec = false; @@ -33,16 +36,16 @@ function dew() { exports$1 = Stream; var EE = y.EventEmitter; - var inherits = dew$8(); + var inherits = dew$f(); inherits(Stream, EE); - Stream.Readable = dew$1(); - Stream.Writable = dew$2(); - Stream.Duplex = dew$3(); - Stream.Transform = dew$4(); - Stream.PassThrough = dew$5(); + Stream.Readable = dew$3(); + Stream.Writable = dew$8(); + Stream.Duplex = dew$7(); + Stream.Transform = dew$2(); + Stream.PassThrough = dew$1(); Stream.finished = dew$6(); - Stream.pipeline = dew$7(); // Backwards-compat with node 0.4.x + Stream.pipeline = dew$4(); // Backwards-compat with node 0.4.x Stream.Stream = Stream; // old-style streams. Note that the pipe method (the only relevant // part of this class) is overridden in the Readable class. @@ -129,4 +132,27 @@ function dew() { const exports = dew(); +var Readable = exports.Readable; +Readable.wrap = function(src, options) { + options = Object.assign({ objectMode: src.readableObjectMode != null || src.objectMode != null || true }, options); + options.destroy = function(err, callback) { + src.destroy(err); + callback(err); + }; + return new Readable(options).wrap(src); +}; + +exports.Writable; +exports.Duplex; +exports.Transform; +exports.PassThrough; +exports.finished; +exports.pipeline; +exports.Stream; + +({ + finished: promisify(exports.finished), + pipeline: promisify(exports.pipeline) +}); + export { exports as e }; diff --git a/nodelibs/browser/chunk-CU2hd6BF.js b/nodelibs/browser/chunk-B738Er4n.js similarity index 85% rename from nodelibs/browser/chunk-CU2hd6BF.js rename to nodelibs/browser/chunk-B738Er4n.js index 095771d..17a251d 100644 --- a/nodelibs/browser/chunk-CU2hd6BF.js +++ b/nodelibs/browser/chunk-B738Er4n.js @@ -1,8 +1,10 @@ -import { y } from './chunk-tHuMsdT0.js'; -import './chunk-BZgdGiNw.js'; -import { X } from './chunk-D04hy_Cu.js'; +import { y as y$1 } from './chunk-tHuMsdT0.js'; +import { X } from './chunk-D3uu3VYh.js'; import { p as process } from './chunk-b0rmRow7.js'; -import { a as e$1 } from './chunk-C9hMJ5VR.js'; + +for(var r$1={byteLength:function(r){var t=u$2(r),e=t[0],n=t[1];return 3*(e+n)/4-n},toByteArray:function(r){var t,o,a=u$2(r),h=a[0],c=a[1],d=new n$2(function(r,t,e){return 3*(t+e)/4-e}(0,h,c)),f=0,A=c>0?h-4:h;for(o=0;o>16&255,d[f++]=t>>8&255,d[f++]=255&t;2===c&&(t=e$2[r.charCodeAt(o)]<<2|e$2[r.charCodeAt(o+1)]>>4,d[f++]=255&t);1===c&&(t=e$2[r.charCodeAt(o)]<<10|e$2[r.charCodeAt(o+1)]<<4|e$2[r.charCodeAt(o+2)]>>2,d[f++]=t>>8&255,d[f++]=255&t);return d},fromByteArray:function(r){for(var e,n=r.length,o=n%3,a=[],h=0,u=n-o;hu?u:h+16383));1===o?(e=r[n-1],a.push(t$1[e>>2]+t$1[e<<4&63]+"==")):2===o&&(e=(r[n-2]<<8)+r[n-1],a.push(t$1[e>>10]+t$1[e>>4&63]+t$1[e<<2&63]+"="));return a.join("")}},t$1=[],e$2=[],n$2="undefined"!=typeof Uint8Array?Uint8Array:Array,o$2="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a$1=0,h$1=o$2.length;a$10)throw new Error("Invalid string. Length must be a multiple of 4");var e=r.indexOf("=");return -1===e&&(e=t),[e,e===t?0:4-e%4]}function c$1(r,e,n){for(var o,a,h=[],u=e;u>18&63]+t$1[a>>12&63]+t$1[a>>6&63]+t$1[63&a]);return h.join("")}e$2["-".charCodeAt(0)]=62,e$2["_".charCodeAt(0)]=63;var a$1$1={read:function(a,t,o,r,h){var M,f,p=8*h-r-1,w=(1<>1,i=-7,N=o?h-1:0,n=o?-1:1,u=a[t+N];for(N+=n,M=u&(1<<-i)-1,u>>=-i,i+=p;i>0;M=256*M+a[t+N],N+=n,i-=8);for(f=M&(1<<-i)-1,M>>=-i,i+=r;i>0;f=256*f+a[t+N],N+=n,i-=8);if(0===M)M=1-e;else {if(M===w)return f?NaN:1/0*(u?-1:1);f+=Math.pow(2,r),M-=e;}return (u?-1:1)*f*Math.pow(2,M-r)},write:function(a,t,o,r,h,M){var f,p,w,e=8*M-h-1,i=(1<>1,n=23===h?Math.pow(2,-24)-Math.pow(2,-77):0,u=r?0:M-1,l=r?1:-1,s=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(p=isNaN(t)?1:0,f=i):(f=Math.floor(Math.log(t)/Math.LN2),t*(w=Math.pow(2,-f))<1&&(f--,w*=2),(t+=f+N>=1?n/w:n*Math.pow(2,1-N))*w>=2&&(f++,w/=2),f+N>=i?(p=0,f=i):f+N>=1?(p=(t*w-1)*Math.pow(2,h),f+=N):(p=t*Math.pow(2,N-1)*Math.pow(2,h),f=0));h>=8;a[o+u]=255&p,u+=l,p/=256,h-=8);for(f=f<0;a[o+u]=255&f,u+=l,f/=256,e-=8);a[o+u-l]|=128*s;}};var e$1$1={},n$1$1=r$1,i$1=a$1$1,o$1$1="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e$1$1.Buffer=u$1$1,e$1$1.SlowBuffer=function(t){+t!=t&&(t=0);return u$1$1.alloc(+t)},e$1$1.INSPECT_MAX_BYTES=50;function f$2(t){if(t>2147483647)throw new RangeError('The value "'+t+'" is invalid for option "size"');var r=new Uint8Array(t);return Object.setPrototypeOf(r,u$1$1.prototype),r}function u$1$1(t,r,e){if("number"==typeof t){if("string"==typeof r)throw new TypeError('The "string" argument must be of type string. Received type number');return a$2(t)}return s$1(t,r,e)}function s$1(t,r,e){if("string"==typeof t)return function(t,r){"string"==typeof r&&""!==r||(r="utf8");if(!u$1$1.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var e=0|y(t,r),n=f$2(e),i=n.write(t,r);i!==e&&(n=n.slice(0,i));return n}(t,r);if(ArrayBuffer.isView(t))return p(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(F(t,ArrayBuffer)||t&&F(t.buffer,ArrayBuffer))return c$1$1(t,r,e);if("undefined"!=typeof SharedArrayBuffer&&(F(t,SharedArrayBuffer)||t&&F(t.buffer,SharedArrayBuffer)))return c$1$1(t,r,e);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return u$1$1.from(n,r,e);var i=function(t){if(u$1$1.isBuffer(t)){var r=0|l$1(t.length),e=f$2(r);return 0===e.length||t.copy(e,0,0,r),e}if(void 0!==t.length)return "number"!=typeof t.length||N(t.length)?f$2(0):p(t);if("Buffer"===t.type&&Array.isArray(t.data))return p(t.data)}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u$1$1.from(t[Symbol.toPrimitive]("string"),r,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h$1$1(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function a$2(t){return h$1$1(t),f$2(t<0?0:0|l$1(t))}function p(t){for(var r=t.length<0?0:0|l$1(t.length),e=f$2(r),n=0;n=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function y(t,r){if(u$1$1.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||F(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var e=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===e)return 0;for(var i=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return _(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return z(t).length;default:if(i)return n?-1:_(t).length;r=(""+r).toLowerCase(),i=!0;}}function g(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return "";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return "";if((e>>>=0)<=(r>>>=0))return "";for(t||(t="utf8");;)switch(t){case"hex":return O(this,r,e);case"utf8":case"utf-8":return I(this,r,e);case"ascii":return S(this,r,e);case"latin1":case"binary":return R(this,r,e);case"base64":return T(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0;}}function w(t,r,e){var n=t[r];t[r]=t[e],t[e]=n;}function d(t,r,e,n,i){if(0===t.length)return -1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),N(e=+e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return -1;e=t.length-1;}else if(e<0){if(!i)return -1;e=0;}if("string"==typeof r&&(r=u$1$1.from(r,n)),u$1$1.isBuffer(r))return 0===r.length?-1:v(t,r,e,n,i);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):v(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function v(t,r,e,n,i){var o,f=1,u=t.length,s=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return -1;f=2,u/=2,s/=2,e/=2;}function h(t,r){return 1===f?t[r]:t.readUInt16BE(r*f)}if(i){var a=-1;for(o=e;ou&&(e=u-s),o=e;o>=0;o--){for(var p=!0,c=0;ci&&(n=i):n=i;var o=r.length;n>o/2&&(n=o/2);for(var f=0;f>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function T(t,r,e){return 0===r&&e===t.length?n$1$1.fromByteArray(t):n$1$1.fromByteArray(t.slice(r,e))}function I(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:h>223?3:h>191?2:1;if(i+p<=e)switch(p){case 1:h<128&&(a=h);break;case 2:128==(192&(o=t[i+1]))&&(s=(31&h)<<6|63&o)>127&&(a=s);break;case 3:o=t[i+1],f=t[i+2],128==(192&o)&&128==(192&f)&&(s=(15&h)<<12|(63&o)<<6|63&f)>2047&&(s<55296||s>57343)&&(a=s);break;case 4:o=t[i+1],f=t[i+2],u=t[i+3],128==(192&o)&&128==(192&f)&&128==(192&u)&&(s=(15&h)<<18|(63&o)<<12|(63&f)<<6|63&u)>65535&&s<1114112&&(a=s);}null===a?(a=65533,p=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|1023&a),n.push(a),i+=p;}return function(t){var r=t.length;if(r<=4096)return String.fromCharCode.apply(String,t);var e="",n=0;for(;nr&&(t+=" ... "),""},o$1$1&&(u$1$1.prototype[o$1$1]=u$1$1.prototype.inspect),u$1$1.prototype.compare=function(t,r,e,n,i){if(F(t,Uint8Array)&&(t=u$1$1.from(t,t.offset,t.byteLength)),!u$1$1.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return -1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),f=(e>>>=0)-(r>>>=0),s=Math.min(o,f),h=this.slice(n,i),a=t.slice(r,e),p=0;p>>=0,isFinite(e)?(e>>>=0,void 0===n&&(n="utf8")):(n=e,e=void 0);}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return b(this,t,r,e);case"utf8":case"utf-8":return m(this,t,r,e);case"ascii":return E(this,t,r,e);case"latin1":case"binary":return B(this,t,r,e);case"base64":return A(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0;}},u$1$1.prototype.toJSON=function(){return {type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function S(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;in)&&(e=n);for(var i="",o=r;oe)throw new RangeError("Trying to access beyond buffer length")}function C(t,r,e,n,i,o){if(!u$1$1.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||rt.length)throw new RangeError("Index out of range")}function P(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function k(t,r,e,n,o){return r=+r,e>>>=0,o||P(t,0,e,4),i$1.write(t,r,e,n,23,4),e+4}function M(t,r,e,n,o){return r=+r,e>>>=0,o||P(t,0,e,8),i$1.write(t,r,e,n,52,8),e+8}u$1$1.prototype.slice=function(t,r){var e=this.length;(t=~~t)<0?(t+=e)<0&&(t=0):t>e&&(t=e),(r=void 0===r?e:~~r)<0?(r+=e)<0&&(r=0):r>e&&(r=e),r>>=0,r>>>=0,e||x(t,r,this.length);for(var n=this[t],i=1,o=0;++o>>=0,r>>>=0,e||x(t,r,this.length);for(var n=this[t+--r],i=1;r>0&&(i*=256);)n+=this[t+--r]*i;return n},u$1$1.prototype.readUInt8=function(t,r){return t>>>=0,r||x(t,1,this.length),this[t]},u$1$1.prototype.readUInt16LE=function(t,r){return t>>>=0,r||x(t,2,this.length),this[t]|this[t+1]<<8},u$1$1.prototype.readUInt16BE=function(t,r){return t>>>=0,r||x(t,2,this.length),this[t]<<8|this[t+1]},u$1$1.prototype.readUInt32LE=function(t,r){return t>>>=0,r||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u$1$1.prototype.readUInt32BE=function(t,r){return t>>>=0,r||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u$1$1.prototype.readIntLE=function(t,r,e){t>>>=0,r>>>=0,e||x(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},u$1$1.prototype.readIntBE=function(t,r,e){t>>>=0,r>>>=0,e||x(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},u$1$1.prototype.readInt8=function(t,r){return t>>>=0,r||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u$1$1.prototype.readInt16LE=function(t,r){t>>>=0,r||x(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},u$1$1.prototype.readInt16BE=function(t,r){t>>>=0,r||x(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},u$1$1.prototype.readInt32LE=function(t,r){return t>>>=0,r||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u$1$1.prototype.readInt32BE=function(t,r){return t>>>=0,r||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u$1$1.prototype.readFloatLE=function(t,r){return t>>>=0,r||x(t,4,this.length),i$1.read(this,t,!0,23,4)},u$1$1.prototype.readFloatBE=function(t,r){return t>>>=0,r||x(t,4,this.length),i$1.read(this,t,!1,23,4)},u$1$1.prototype.readDoubleLE=function(t,r){return t>>>=0,r||x(t,8,this.length),i$1.read(this,t,!0,52,8)},u$1$1.prototype.readDoubleBE=function(t,r){return t>>>=0,r||x(t,8,this.length),i$1.read(this,t,!1,52,8)},u$1$1.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r>>>=0,e>>>=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o>>=0,e>>>=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=e-1,o=1;for(this[r+i]=255&t;--i>=0&&(o*=256);)this[r+i]=t/o&255;return r+e},u$1$1.prototype.writeUInt8=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,1,255,0),this[r]=255&t,r+1},u$1$1.prototype.writeUInt16LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,65535,0),this[r]=255&t,this[r+1]=t>>>8,r+2},u$1$1.prototype.writeUInt16BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=255&t,r+2},u$1$1.prototype.writeUInt32LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t,r+4},u$1$1.prototype.writeUInt32BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t,r+4},u$1$1.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r>>>=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i);}var o=0,f=1,u=0;for(this[r]=255&t;++o>0)-u&255;return r+e},u$1$1.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r>>>=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i);}var o=e-1,f=1,u=0;for(this[r+o]=255&t;--o>=0&&(f*=256);)t<0&&0===u&&0!==this[r+o+1]&&(u=1),this[r+o]=(t/f>>0)-u&255;return r+e},u$1$1.prototype.writeInt8=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=255&t,r+1},u$1$1.prototype.writeInt16LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,32767,-32768),this[r]=255&t,this[r+1]=t>>>8,r+2},u$1$1.prototype.writeInt16BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=255&t,r+2},u$1$1.prototype.writeInt32LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,2147483647,-2147483648),this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},u$1$1.prototype.writeInt32BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t,r+4},u$1$1.prototype.writeFloatLE=function(t,r,e){return k(this,t,r,!0,e)},u$1$1.prototype.writeFloatBE=function(t,r,e){return k(this,t,r,!1,e)},u$1$1.prototype.writeDoubleLE=function(t,r,e){return M(this,t,r,!0,e)},u$1$1.prototype.writeDoubleBE=function(t,r,e){return M(this,t,r,!1,e)},u$1$1.prototype.copy=function(t,r,e,n){if(!u$1$1.isBuffer(t))throw new TypeError("argument should be a Buffer");if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else Uint8Array.prototype.set.call(t,this.subarray(e,n),r);return i},u$1$1.prototype.fill=function(t,r,e,n){if("string"==typeof t){if("string"==typeof r?(n=r,r=0,e=this.length):"string"==typeof e&&(n=e,e=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u$1$1.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){var i=t.charCodeAt(0);("utf8"===n&&i<128||"latin1"===n)&&(t=i);}}else "number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(r<0||this.length>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(f+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320);}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e);}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128);}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128);}else {if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128);}}return o}function z(t){return n$1$1.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(j,"")).length<2)return "";for(;t.length%4!=0;)t+="=";return t}(t))}function D(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}function F(t,r){return t instanceof r||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===r.name}function N(t){return t!=t}var Y=function(){for(var t=new Array(256),r=0;r<16;++r)for(var e=16*r,n=0;n<16;++n)t[e+n]="0123456789abcdef"[r]+"0123456789abcdef"[n];return t}();e$1$1.Buffer;e$1$1.INSPECT_MAX_BYTES;e$1$1.kMaxLength; + +var e={},n=e$1$1,o=n.Buffer;function t(r,e){for(var n in r)e[n]=r[n];}function f(r,e,n){return o(r,e,n)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?e=n:(t(n,e),e.Buffer=f),f.prototype=Object.create(o.prototype),t(o,f),f.from=function(r,e,n){if("number"==typeof r)throw new TypeError("Argument must not be a number");return o(r,e,n)},f.alloc=function(r,e,n){if("number"!=typeof r)throw new TypeError("Argument must be a number");var t=o(r);return void 0!==e?"string"==typeof n?t.fill(e,n):t.fill(e):t.fill(0),t},f.allocUnsafe=function(r){if("number"!=typeof r)throw new TypeError("Argument must be a number");return o(r)},f.allocUnsafeSlow=function(r){if("number"!=typeof r)throw new TypeError("Argument must be a number");return n.SlowBuffer(r)};var u=e;var e$1={},s=u.Buffer,i=s.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){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 !0;default:return !1}};function a(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return "utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return "utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return "utf16le";case"latin1":case"binary":return "latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0;}}(t);if("string"!=typeof e&&(s.isEncoding===i||!i(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=h,this.end=l,e=4;break;case"utf8":this.fillLast=n$1,e=4;break;case"base64":this.text=u$1,this.end=o$1,e=3;break;default:return this.write=f$1,this.end=c,void 0}this.lastNeed=0,this.lastTotal=0,this.lastChar=s.allocUnsafe(e);}function r(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function n$1(t){var e=this.lastTotal-this.lastNeed,s=function(t,e,s){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==s?s:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),this.lastNeed-=t.length,void 0)}function h(t,e){if((t.length-e)%2==0){var s=t.toString("utf16le",e);if(s){var i=s.charCodeAt(s.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],s.slice(0,-1)}return s}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function l(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var s=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,s)}return e}function u$1(t,e){var s=(t.length-e)%3;return 0===s?t.toString("base64",e):(this.lastNeed=3-s,this.lastTotal=3,1===s?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-s))}function o$1(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function f$1(t){return t.toString(this.encoding)}function c(t){return t&&t.length?this.write(t):""}e$1.StringDecoder=a,a.prototype.write=function(t){if(0===t.length)return "";var e,s;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return "";s=this.lastNeed,this.lastNeed=0;}else s=0;return s=0)return a>0&&(t.lastNeed=a-1),a;if(--i=0)return a>0&&(t.lastNeed=a-2),a;if(--i=0)return a>0&&(2===a?a=0:t.lastNeed=a-3),a;return 0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=s;var i=t.length-(s-this.lastNeed);return t.copy(this.lastChar,0,i),t.toString("utf8",e,i)},a.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length;}; var exports$2$1 = {}, _dewExec$2$1 = false; @@ -2356,7 +2358,7 @@ var exports$e = {}, function dew$e() { if (_dewExec$e) return exports$e; _dewExec$e = true; - exports$e = y.EventEmitter; + exports$e = y$1.EventEmitter; return exports$e; } @@ -4153,7 +4155,7 @@ function dew$3() { Readable.ReadableState = ReadableState; /**/ - y.EventEmitter; + y$1.EventEmitter; var EElistenerCount = function EElistenerCount(emitter, type) { return emitter.listeners(type).length; @@ -5519,4 +5521,4 @@ function dew() { return exports; } -export { dew$3 as a, buffer as b, dew$8 as c, dew$f as d, dew$7 as e, dew$2 as f, dew$1 as g, dew$6 as h, dew as i }; +export { e$1$1 as a, buffer as b, dew$3 as c, dew$f as d, e$1 as e, dew$8 as f, dew$7 as g, dew$2 as h, dew$1 as i, dew$6 as j, dew as k, u }; diff --git a/nodelibs/browser/chunk-BZgdGiNw.js b/nodelibs/browser/chunk-BZgdGiNw.js deleted file mode 100644 index 442fbaa..0000000 --- a/nodelibs/browser/chunk-BZgdGiNw.js +++ /dev/null @@ -1,35 +0,0 @@ -import { X } from './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; - -X._extend;X.callbackify;X.debuglog;X.deprecate;X.format;X.inherits;X.inspect;X.isArray;X.isBoolean;X.isBuffer;X.isDate;X.isError;X.isFunction;X.isNull;X.isNullOrUndefined;X.isNumber;X.isObject;X.isPrimitive;X.isRegExp;X.isString;X.isSymbol;X.isUndefined;X.log;X.promisify; - -var _extend = X._extend; -var callbackify = X.callbackify; -var debuglog = X.debuglog; -var deprecate = X.deprecate; -var format = X.format; -var inherits = X.inherits; -var inspect = X.inspect; -var isArray = X.isArray; -var isBoolean = X.isBoolean; -var isBuffer = X.isBuffer; -var isDate = X.isDate; -var isError = X.isError; -var isFunction = X.isFunction; -var isNull = X.isNull; -var isNullOrUndefined = X.isNullOrUndefined; -var isNumber = X.isNumber; -var isObject = X.isObject; -var isPrimitive = X.isPrimitive; -var isRegExp = X.isRegExp; -var isString = X.isString; -var isSymbol = X.isSymbol; -var isUndefined = X.isUndefined; -var log = X.log; -var promisify = X.promisify; -var types = X.types; - -const TextEncoder = self.TextEncoder; -const TextDecoder = self.TextDecoder; - -export { TextDecoder as T, _extend as _, TextEncoder as a, deprecate as b, callbackify as c, debuglog as d, inspect as e, format as f, isArray as g, isBoolean as h, inherits as i, isBuffer as j, isDate as k, isError as l, isFunction as m, isNull as n, isNullOrUndefined as o, promisify as p, isNumber as q, isObject as r, isPrimitive as s, isRegExp as t, isString as u, isSymbol as v, isUndefined as w, log as x, types as y }; diff --git a/nodelibs/browser/chunk-DppJZDIM.js b/nodelibs/browser/chunk-BlJi4mNy.js similarity index 81% rename from nodelibs/browser/chunk-DppJZDIM.js rename to nodelibs/browser/chunk-BlJi4mNy.js index 07990bd..5d68434 100644 --- a/nodelibs/browser/chunk-DppJZDIM.js +++ b/nodelibs/browser/chunk-BlJi4mNy.js @@ -1,45 +1,31 @@ -import { p as process } from './chunk-b0rmRow7.js'; +import { p as process } from './chunk-DEMDiNwt.js'; var exports$1 = {}, - _dewExec = false; + _dewExec = false; function dew() { if (_dewExec) return exports$1; _dewExec = true; var process$1 = process; - function assertPath(path) { if (typeof path !== "string") { throw new TypeError("Path must be a string. Received " + JSON.stringify(path)); } - } // Resolves . and .. elements in a path with directory names - + } + // Resolves . and .. elements in a path with directory names function normalizeStringPosix(path, allowAboveRoot) { var res = ""; var lastSegmentLength = 0; var lastSlash = -1; var dots = 0; var code; - for (var i = 0; i <= path.length; ++i) { - if (i < path.length) code = path.charCodeAt(i);else if (code === 47 - /*/*/ - ) break;else code = 47 - /*/*/ - ; - - if (code === 47 - /*/*/ - ) { + if (i < path.length) code = path.charCodeAt(i);else if (code === 47 /*/*/) break;else code = 47 /*/*/; + if (code === 47 /*/*/) { if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) { - if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 - /*.*/ - || res.charCodeAt(res.length - 2) !== 46 - /*.*/ - ) { + if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 /*.*/ || res.charCodeAt(res.length - 2) !== 46 /*.*/) { if (res.length > 2) { var lastSlashIndex = res.lastIndexOf("/"); - if (lastSlashIndex !== res.length - 1) { if (lastSlashIndex === -1) { res = ""; @@ -48,7 +34,6 @@ function dew() { res = res.slice(0, lastSlashIndex); lastSegmentLength = res.length - 1 - res.lastIndexOf("/"); } - lastSlash = i; dots = 0; continue; @@ -61,7 +46,6 @@ function dew() { continue; } } - if (allowAboveRoot) { if (res.length > 0) res += "/..";else res = ".."; lastSegmentLength = 2; @@ -70,66 +54,54 @@ function dew() { if (res.length > 0) res += "/" + path.slice(lastSlash + 1, i);else res = path.slice(lastSlash + 1, i); lastSegmentLength = i - lastSlash - 1; } - lastSlash = i; dots = 0; - } else if (code === 46 - /*.*/ - && dots !== -1) { + } else if (code === 46 /*.*/ && dots !== -1) { ++dots; } else { dots = -1; } } - return res; } - function _format(sep, pathObject) { var dir = pathObject.dir || pathObject.root; var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); - if (!dir) { return base; } - if (dir === pathObject.root) { return dir + base; } - return dir + sep + base; } - var posix = { // path.resolve([from ...], to) resolve: function resolve() { var resolvedPath = ""; var resolvedAbsolute = false; var cwd; - for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { var path; if (i >= 0) path = arguments[i];else { if (cwd === undefined) cwd = process$1.cwd(); path = cwd; } - assertPath(path); // Skip empty entries + assertPath(path); + // Skip empty entries if (path.length === 0) { continue; } - resolvedPath = path + "/" + resolvedPath; - resolvedAbsolute = path.charCodeAt(0) === 47 - /*/*/ - ; - } // At this point the path should be resolved to a full absolute path, but - // handle relative paths to be safe (might happen when process.cwd() fails) - // Normalize the path + resolvedAbsolute = path.charCodeAt(0) === 47 /*/*/; + } + // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) + // Normalize the path resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute); - if (resolvedAbsolute) { if (resolvedPath.length > 0) return "/" + resolvedPath;else return "/"; } else if (resolvedPath.length > 0) { @@ -141,13 +113,10 @@ function dew() { normalize: function normalize(path) { assertPath(path); if (path.length === 0) return "."; - var isAbsolute = path.charCodeAt(0) === 47 - /*/*/ - ; - var trailingSeparator = path.charCodeAt(path.length - 1) === 47 - /*/*/ - ; // Normalize the path + var isAbsolute = path.charCodeAt(0) === 47 /*/*/; + var trailingSeparator = path.charCodeAt(path.length - 1) === 47 /*/*/; + // Normalize the path path = normalizeStringPosix(path, !isAbsolute); if (path.length === 0 && !isAbsolute) path = "."; if (path.length > 0 && trailingSeparator) path += "/"; @@ -156,23 +125,18 @@ function dew() { }, isAbsolute: function isAbsolute(path) { assertPath(path); - return path.length > 0 && path.charCodeAt(0) === 47 - /*/*/ - ; + return path.length > 0 && path.charCodeAt(0) === 47 /*/*/; }, join: function join() { if (arguments.length === 0) return "."; var joined; - for (var i = 0; i < arguments.length; ++i) { var arg = arguments[i]; assertPath(arg); - if (arg.length > 0) { if (joined === undefined) joined = arg;else joined += "/" + arg; } } - if (joined === undefined) return "."; return posix.normalize(joined); }, @@ -182,40 +146,32 @@ function dew() { if (from === to) return ""; from = posix.resolve(from); to = posix.resolve(to); - if (from === to) return ""; // Trim any leading backslashes + if (from === to) return ""; + // Trim any leading backslashes var fromStart = 1; - for (; fromStart < from.length; ++fromStart) { - if (from.charCodeAt(fromStart) !== 47 - /*/*/ - ) break; + if (from.charCodeAt(fromStart) !== 47 /*/*/) break; } - var fromEnd = from.length; - var fromLen = fromEnd - fromStart; // Trim any leading backslashes + var fromLen = fromEnd - fromStart; + // Trim any leading backslashes var toStart = 1; - for (; toStart < to.length; ++toStart) { - if (to.charCodeAt(toStart) !== 47 - /*/*/ - ) break; + if (to.charCodeAt(toStart) !== 47 /*/*/) break; } - var toEnd = to.length; - var toLen = toEnd - toStart; // Compare paths to find the longest common path from root + var toLen = toEnd - toStart; + // Compare paths to find the longest common path from root var length = fromLen < toLen ? fromLen : toLen; var lastCommonSep = -1; var i = 0; - for (; i <= length; ++i) { if (i === length) { if (toLen > length) { - if (to.charCodeAt(toStart + i) === 47 - /*/*/ - ) { + if (to.charCodeAt(toStart + i) === 47 /*/*/) { // We get here if `from` is the exact base path for `to`. // For example: from='/foo/bar'; to='/foo/bar/baz' return to.slice(toStart + i + 1); @@ -225,9 +181,7 @@ function dew() { return to.slice(toStart + i); } } else if (fromLen > length) { - if (from.charCodeAt(fromStart + i) === 47 - /*/*/ - ) { + if (from.charCodeAt(fromStart + i) === 47 /*/*/) { // We get here if `to` is the exact base path for `from`. // For example: from='/foo/bar/baz'; to='/foo/bar' lastCommonSep = i; @@ -237,35 +191,26 @@ function dew() { lastCommonSep = 0; } } - break; } - var fromCode = from.charCodeAt(fromStart + i); var toCode = to.charCodeAt(toStart + i); - if (fromCode !== toCode) break;else if (fromCode === 47 - /*/*/ - ) lastCommonSep = i; + if (fromCode !== toCode) break;else if (fromCode === 47 /*/*/) lastCommonSep = i; } - - var out = ""; // Generate the relative path based on the path difference between `to` + var out = ""; + // Generate the relative path based on the path difference between `to` // and `from` - for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { - if (i === fromEnd || from.charCodeAt(i) === 47 - /*/*/ - ) { + if (i === fromEnd || from.charCodeAt(i) === 47 /*/*/) { if (out.length === 0) out += "..";else out += "/.."; } - } // Lastly, append the rest of the destination (`to`) path that comes after - // the common path parts - + } + // Lastly, append the rest of the destination (`to`) path that comes after + // the common path parts if (out.length > 0) return out + to.slice(toStart + lastCommonSep);else { toStart += lastCommonSep; - if (to.charCodeAt(toStart) === 47 - /*/*/ - ) ++toStart; + if (to.charCodeAt(toStart) === 47 /*/*/) ++toStart; return to.slice(toStart); } }, @@ -276,18 +221,12 @@ function dew() { assertPath(path); if (path.length === 0) return "."; var code = path.charCodeAt(0); - var hasRoot = code === 47 - /*/*/ - ; + var hasRoot = code === 47 /*/*/; var end = -1; var matchedSlash = true; - for (var i = path.length - 1; i >= 1; --i) { code = path.charCodeAt(i); - - if (code === 47 - /*/*/ - ) { + if (code === 47 /*/*/) { if (!matchedSlash) { end = i; break; @@ -297,7 +236,6 @@ function dew() { matchedSlash = false; } } - if (end === -1) return hasRoot ? "/" : "."; if (hasRoot && end === 1) return "//"; return path.slice(0, end); @@ -309,18 +247,13 @@ function dew() { var end = -1; var matchedSlash = true; var i; - if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { if (ext.length === path.length && ext === path) return ""; var extIdx = ext.length - 1; var firstNonSlashEnd = -1; - for (i = path.length - 1; i >= 0; --i) { var code = path.charCodeAt(i); - - if (code === 47 - /*/*/ - ) { + if (code === 47 /*/*/) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { @@ -334,7 +267,6 @@ function dew() { matchedSlash = false; firstNonSlashEnd = i + 1; } - if (extIdx >= 0) { // Try to match the explicit extension if (code === ext.charCodeAt(extIdx)) { @@ -352,14 +284,11 @@ function dew() { } } } - if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length; return path.slice(start, end); } else { for (i = path.length - 1; i >= 0; --i) { - if (path.charCodeAt(i) === 47 - /*/*/ - ) { + if (path.charCodeAt(i) === 47 /*/*/) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { @@ -373,7 +302,6 @@ function dew() { end = i + 1; } } - if (end === -1) return ""; return path.slice(start, end); } @@ -383,37 +311,28 @@ function dew() { var startDot = -1; var startPart = 0; var end = -1; - var matchedSlash = true; // Track the state of characters (if any) we see before our first dot and + var matchedSlash = true; + // Track the state of characters (if any) we see before our first dot and // after any path separator we find - var preDotState = 0; - for (var i = path.length - 1; i >= 0; --i) { var code = path.charCodeAt(i); - - if (code === 47 - /*/*/ - ) { + if (code === 47 /*/*/) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { startPart = i + 1; break; } - continue; } - if (end === -1) { // We saw the first non-path separator, mark this as the end of our // extension matchedSlash = false; end = i + 1; } - - if (code === 46 - /*.*/ - ) { + if (code === 46 /*.*/) { // If this is our first dot, mark it as the start of our extension if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1; } else if (startDot !== -1) { @@ -422,20 +341,19 @@ function dew() { preDotState = -1; } } - - if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot - preDotState === 0 || // The (right-most) trimmed path component is exactly '..' + if (startDot === -1 || end === -1 || + // We saw a non-dot character immediately before the dot + preDotState === 0 || + // The (right-most) trimmed path component is exactly '..' preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { return ""; } - return path.slice(startDot, end); }, format: function format(pathObject) { if (pathObject === null || typeof pathObject !== "object") { throw new TypeError("The \"pathObject\" argument must be of type Object. Received type " + typeof pathObject); } - return _format("/", pathObject); }, parse: function parse(path) { @@ -449,53 +367,43 @@ function dew() { }; if (path.length === 0) return ret; var code = path.charCodeAt(0); - var isAbsolute = code === 47 - /*/*/ - ; + var isAbsolute = code === 47 /*/*/; var start; - if (isAbsolute) { ret.root = "/"; start = 1; } else { start = 0; } - var startDot = -1; var startPart = 0; var end = -1; var matchedSlash = true; - var i = path.length - 1; // Track the state of characters (if any) we see before our first dot and - // after any path separator we find + var i = path.length - 1; - var preDotState = 0; // Get non-dir info + // Track the state of characters (if any) we see before our first dot and + // after any path separator we find + var preDotState = 0; + // Get non-dir info for (; i >= start; --i) { code = path.charCodeAt(i); - - if (code === 47 - /*/*/ - ) { + if (code === 47 /*/*/) { // If we reached a path separator that was not part of a set of path // separators at the end of the string, stop now if (!matchedSlash) { startPart = i + 1; break; } - continue; } - if (end === -1) { // We saw the first non-path separator, mark this as the end of our // extension matchedSlash = false; end = i + 1; } - - if (code === 46 - /*.*/ - ) { + if (code === 46 /*.*/) { // If this is our first dot, mark it as the start of our extension if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1; } else if (startDot !== -1) { @@ -504,9 +412,10 @@ function dew() { preDotState = -1; } } - - if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot - preDotState === 0 || // The (right-most) trimmed path component is exactly '..' + if (startDot === -1 || end === -1 || + // We saw a non-dot character immediately before the dot + preDotState === 0 || + // The (right-most) trimmed path component is exactly '..' preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { if (end !== -1) { if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end); @@ -519,10 +428,8 @@ function dew() { ret.name = path.slice(startPart, startDot); ret.base = path.slice(startPart, end); } - ret.ext = path.slice(startDot, end); } - if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = "/"; return ret; }, diff --git a/nodelibs/browser/chunk-BsRZ0PEC.js b/nodelibs/browser/chunk-BsRZ0PEC.js new file mode 100644 index 0000000..593a212 --- /dev/null +++ b/nodelibs/browser/chunk-BsRZ0PEC.js @@ -0,0 +1,74 @@ +var exports = {}, + _dewExec = false; +var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew() { + if (_dewExec) return exports; + _dewExec = true; + /** + * Module exports. + */ + + exports = deprecate; + + /** + * Mark that a method should not be used. + * Returns a modified function which warns once by default. + * + * If `localStorage.noDeprecation = true` is set, then it is a no-op. + * + * If `localStorage.throwDeprecation = true` is set, then deprecated functions + * will throw an Error when invoked. + * + * If `localStorage.traceDeprecation = true` is set, then deprecated functions + * will invoke `console.trace()` instead of `console.error()`. + * + * @param {Function} fn - the function to deprecate + * @param {String} msg - the string to print to the console when `fn` is invoked + * @returns {Function} a new "deprecated" version of `fn` + * @api public + */ + + function deprecate(fn, msg) { + if (config("noDeprecation")) { + return fn; + } + var warned = false; + function deprecated() { + if (!warned) { + if (config("throwDeprecation")) { + throw new Error(msg); + } else if (config("traceDeprecation")) { + console.trace(msg); + } else { + console.warn(msg); + } + warned = true; + } + return fn.apply(this || _global, arguments); + } + return deprecated; + } + + /** + * Checks `localStorage` for boolean values for the given `name`. + * + * @param {String} name + * @returns {Boolean} + * @api private + */ + + function config(name) { + // accessing global.localStorage can trigger a DOMException in sandboxed iframes + try { + if (!_global.localStorage) return false; + } catch (_) { + return false; + } + var val = _global.localStorage[name]; + if (null == val) return false; + return String(val).toLowerCase() === "true"; + } + return exports; +} + +export { dew as d }; diff --git a/nodelibs/browser/chunk-C4rKjYLo.js b/nodelibs/browser/chunk-C4rKjYLo.js new file mode 100644 index 0000000..3b53485 --- /dev/null +++ b/nodelibs/browser/chunk-C4rKjYLo.js @@ -0,0 +1,20 @@ +import { c as dew$3, f as dew$8, g as dew$7, h as dew$2, i as dew$1, j as dew$6, k as dew$4 } from './chunk-B738Er4n.js'; + +var exports = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports; + _dewExec = true; + exports = exports = dew$3(); + exports.Stream = exports; + exports.Readable = exports; + exports.Writable = dew$8(); + exports.Duplex = dew$7(); + exports.Transform = dew$2(); + exports.PassThrough = dew$1(); + exports.finished = dew$6(); + exports.pipeline = dew$4(); + return exports; +} + +export { dew as d }; diff --git a/nodelibs/browser/chunk-C9hMJ5VR.js b/nodelibs/browser/chunk-C9hMJ5VR.js deleted file mode 100644 index f3911eb..0000000 --- a/nodelibs/browser/chunk-C9hMJ5VR.js +++ /dev/null @@ -1,9 +0,0 @@ -for(var r$1={byteLength:function(r){var t=u$2(r),e=t[0],n=t[1];return 3*(e+n)/4-n},toByteArray:function(r){var t,o,a=u$2(r),h=a[0],c=a[1],d=new n$2(function(r,t,e){return 3*(t+e)/4-e}(0,h,c)),f=0,A=c>0?h-4:h;for(o=0;o>16&255,d[f++]=t>>8&255,d[f++]=255&t;2===c&&(t=e$2[r.charCodeAt(o)]<<2|e$2[r.charCodeAt(o+1)]>>4,d[f++]=255&t);1===c&&(t=e$2[r.charCodeAt(o)]<<10|e$2[r.charCodeAt(o+1)]<<4|e$2[r.charCodeAt(o+2)]>>2,d[f++]=t>>8&255,d[f++]=255&t);return d},fromByteArray:function(r){for(var e,n=r.length,o=n%3,a=[],h=0,u=n-o;hu?u:h+16383));1===o?(e=r[n-1],a.push(t$1[e>>2]+t$1[e<<4&63]+"==")):2===o&&(e=(r[n-2]<<8)+r[n-1],a.push(t$1[e>>10]+t$1[e>>4&63]+t$1[e<<2&63]+"="));return a.join("")}},t$1=[],e$2=[],n$2="undefined"!=typeof Uint8Array?Uint8Array:Array,o$2="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",a$1=0,h$1=o$2.length;a$10)throw new Error("Invalid string. Length must be a multiple of 4");var e=r.indexOf("=");return -1===e&&(e=t),[e,e===t?0:4-e%4]}function c$1(r,e,n){for(var o,a,h=[],u=e;u>18&63]+t$1[a>>12&63]+t$1[a>>6&63]+t$1[63&a]);return h.join("")}e$2["-".charCodeAt(0)]=62,e$2["_".charCodeAt(0)]=63;var a$1$1={read:function(a,t,o,r,h){var M,f,p=8*h-r-1,w=(1<>1,i=-7,N=o?h-1:0,n=o?-1:1,u=a[t+N];for(N+=n,M=u&(1<<-i)-1,u>>=-i,i+=p;i>0;M=256*M+a[t+N],N+=n,i-=8);for(f=M&(1<<-i)-1,M>>=-i,i+=r;i>0;f=256*f+a[t+N],N+=n,i-=8);if(0===M)M=1-e;else {if(M===w)return f?NaN:1/0*(u?-1:1);f+=Math.pow(2,r),M-=e;}return (u?-1:1)*f*Math.pow(2,M-r)},write:function(a,t,o,r,h,M){var f,p,w,e=8*M-h-1,i=(1<>1,n=23===h?Math.pow(2,-24)-Math.pow(2,-77):0,u=r?0:M-1,l=r?1:-1,s=t<0||0===t&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(p=isNaN(t)?1:0,f=i):(f=Math.floor(Math.log(t)/Math.LN2),t*(w=Math.pow(2,-f))<1&&(f--,w*=2),(t+=f+N>=1?n/w:n*Math.pow(2,1-N))*w>=2&&(f++,w/=2),f+N>=i?(p=0,f=i):f+N>=1?(p=(t*w-1)*Math.pow(2,h),f+=N):(p=t*Math.pow(2,N-1)*Math.pow(2,h),f=0));h>=8;a[o+u]=255&p,u+=l,p/=256,h-=8);for(f=f<0;a[o+u]=255&f,u+=l,f/=256,e-=8);a[o+u-l]|=128*s;}};var e$1$1={},n$1$1=r$1,i$1=a$1$1,o$1$1="function"==typeof Symbol&&"function"==typeof Symbol.for?Symbol.for("nodejs.util.inspect.custom"):null;e$1$1.Buffer=u$1$1,e$1$1.SlowBuffer=function(t){+t!=t&&(t=0);return u$1$1.alloc(+t)},e$1$1.INSPECT_MAX_BYTES=50;function f$2(t){if(t>2147483647)throw new RangeError('The value "'+t+'" is invalid for option "size"');var r=new Uint8Array(t);return Object.setPrototypeOf(r,u$1$1.prototype),r}function u$1$1(t,r,e){if("number"==typeof t){if("string"==typeof r)throw new TypeError('The "string" argument must be of type string. Received type number');return a$2(t)}return s$1(t,r,e)}function s$1(t,r,e){if("string"==typeof t)return function(t,r){"string"==typeof r&&""!==r||(r="utf8");if(!u$1$1.isEncoding(r))throw new TypeError("Unknown encoding: "+r);var e=0|y(t,r),n=f$2(e),i=n.write(t,r);i!==e&&(n=n.slice(0,i));return n}(t,r);if(ArrayBuffer.isView(t))return p(t);if(null==t)throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t);if(F(t,ArrayBuffer)||t&&F(t.buffer,ArrayBuffer))return c$1$1(t,r,e);if("undefined"!=typeof SharedArrayBuffer&&(F(t,SharedArrayBuffer)||t&&F(t.buffer,SharedArrayBuffer)))return c$1$1(t,r,e);if("number"==typeof t)throw new TypeError('The "value" argument must not be of type number. Received type number');var n=t.valueOf&&t.valueOf();if(null!=n&&n!==t)return u$1$1.from(n,r,e);var i=function(t){if(u$1$1.isBuffer(t)){var r=0|l$1(t.length),e=f$2(r);return 0===e.length||t.copy(e,0,0,r),e}if(void 0!==t.length)return "number"!=typeof t.length||N(t.length)?f$2(0):p(t);if("Buffer"===t.type&&Array.isArray(t.data))return p(t.data)}(t);if(i)return i;if("undefined"!=typeof Symbol&&null!=Symbol.toPrimitive&&"function"==typeof t[Symbol.toPrimitive])return u$1$1.from(t[Symbol.toPrimitive]("string"),r,e);throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type "+typeof t)}function h$1$1(t){if("number"!=typeof t)throw new TypeError('"size" argument must be of type number');if(t<0)throw new RangeError('The value "'+t+'" is invalid for option "size"')}function a$2(t){return h$1$1(t),f$2(t<0?0:0|l$1(t))}function p(t){for(var r=t.length<0?0:0|l$1(t.length),e=f$2(r),n=0;n=2147483647)throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+2147483647..toString(16)+" bytes");return 0|t}function y(t,r){if(u$1$1.isBuffer(t))return t.length;if(ArrayBuffer.isView(t)||F(t,ArrayBuffer))return t.byteLength;if("string"!=typeof t)throw new TypeError('The "string" argument must be one of type string, Buffer, or ArrayBuffer. Received type '+typeof t);var e=t.length,n=arguments.length>2&&!0===arguments[2];if(!n&&0===e)return 0;for(var i=!1;;)switch(r){case"ascii":case"latin1":case"binary":return e;case"utf8":case"utf-8":return _(t).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return 2*e;case"hex":return e>>>1;case"base64":return z(t).length;default:if(i)return n?-1:_(t).length;r=(""+r).toLowerCase(),i=!0;}}function g(t,r,e){var n=!1;if((void 0===r||r<0)&&(r=0),r>this.length)return "";if((void 0===e||e>this.length)&&(e=this.length),e<=0)return "";if((e>>>=0)<=(r>>>=0))return "";for(t||(t="utf8");;)switch(t){case"hex":return O(this,r,e);case"utf8":case"utf-8":return I(this,r,e);case"ascii":return S(this,r,e);case"latin1":case"binary":return R(this,r,e);case"base64":return T(this,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return L(this,r,e);default:if(n)throw new TypeError("Unknown encoding: "+t);t=(t+"").toLowerCase(),n=!0;}}function w(t,r,e){var n=t[r];t[r]=t[e],t[e]=n;}function d(t,r,e,n,i){if(0===t.length)return -1;if("string"==typeof e?(n=e,e=0):e>2147483647?e=2147483647:e<-2147483648&&(e=-2147483648),N(e=+e)&&(e=i?0:t.length-1),e<0&&(e=t.length+e),e>=t.length){if(i)return -1;e=t.length-1;}else if(e<0){if(!i)return -1;e=0;}if("string"==typeof r&&(r=u$1$1.from(r,n)),u$1$1.isBuffer(r))return 0===r.length?-1:v(t,r,e,n,i);if("number"==typeof r)return r&=255,"function"==typeof Uint8Array.prototype.indexOf?i?Uint8Array.prototype.indexOf.call(t,r,e):Uint8Array.prototype.lastIndexOf.call(t,r,e):v(t,[r],e,n,i);throw new TypeError("val must be string, number or Buffer")}function v(t,r,e,n,i){var o,f=1,u=t.length,s=r.length;if(void 0!==n&&("ucs2"===(n=String(n).toLowerCase())||"ucs-2"===n||"utf16le"===n||"utf-16le"===n)){if(t.length<2||r.length<2)return -1;f=2,u/=2,s/=2,e/=2;}function h(t,r){return 1===f?t[r]:t.readUInt16BE(r*f)}if(i){var a=-1;for(o=e;ou&&(e=u-s),o=e;o>=0;o--){for(var p=!0,c=0;ci&&(n=i):n=i;var o=r.length;n>o/2&&(n=o/2);for(var f=0;f>8,i=e%256,o.push(i),o.push(n);return o}(r,t.length-e),t,e,n)}function T(t,r,e){return 0===r&&e===t.length?n$1$1.fromByteArray(t):n$1$1.fromByteArray(t.slice(r,e))}function I(t,r,e){e=Math.min(t.length,e);for(var n=[],i=r;i239?4:h>223?3:h>191?2:1;if(i+p<=e)switch(p){case 1:h<128&&(a=h);break;case 2:128==(192&(o=t[i+1]))&&(s=(31&h)<<6|63&o)>127&&(a=s);break;case 3:o=t[i+1],f=t[i+2],128==(192&o)&&128==(192&f)&&(s=(15&h)<<12|(63&o)<<6|63&f)>2047&&(s<55296||s>57343)&&(a=s);break;case 4:o=t[i+1],f=t[i+2],u=t[i+3],128==(192&o)&&128==(192&f)&&128==(192&u)&&(s=(15&h)<<18|(63&o)<<12|(63&f)<<6|63&u)>65535&&s<1114112&&(a=s);}null===a?(a=65533,p=1):a>65535&&(a-=65536,n.push(a>>>10&1023|55296),a=56320|1023&a),n.push(a),i+=p;}return function(t){var r=t.length;if(r<=4096)return String.fromCharCode.apply(String,t);var e="",n=0;for(;nr&&(t+=" ... "),""},o$1$1&&(u$1$1.prototype[o$1$1]=u$1$1.prototype.inspect),u$1$1.prototype.compare=function(t,r,e,n,i){if(F(t,Uint8Array)&&(t=u$1$1.from(t,t.offset,t.byteLength)),!u$1$1.isBuffer(t))throw new TypeError('The "target" argument must be one of type Buffer or Uint8Array. Received type '+typeof t);if(void 0===r&&(r=0),void 0===e&&(e=t?t.length:0),void 0===n&&(n=0),void 0===i&&(i=this.length),r<0||e>t.length||n<0||i>this.length)throw new RangeError("out of range index");if(n>=i&&r>=e)return 0;if(n>=i)return -1;if(r>=e)return 1;if(this===t)return 0;for(var o=(i>>>=0)-(n>>>=0),f=(e>>>=0)-(r>>>=0),s=Math.min(o,f),h=this.slice(n,i),a=t.slice(r,e),p=0;p>>=0,isFinite(e)?(e>>>=0,void 0===n&&(n="utf8")):(n=e,e=void 0);}var i=this.length-r;if((void 0===e||e>i)&&(e=i),t.length>0&&(e<0||r<0)||r>this.length)throw new RangeError("Attempt to write outside buffer bounds");n||(n="utf8");for(var o=!1;;)switch(n){case"hex":return b(this,t,r,e);case"utf8":case"utf-8":return m(this,t,r,e);case"ascii":return E(this,t,r,e);case"latin1":case"binary":return B(this,t,r,e);case"base64":return A(this,t,r,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return U(this,t,r,e);default:if(o)throw new TypeError("Unknown encoding: "+n);n=(""+n).toLowerCase(),o=!0;}},u$1$1.prototype.toJSON=function(){return {type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function S(t,r,e){var n="";e=Math.min(t.length,e);for(var i=r;in)&&(e=n);for(var i="",o=r;oe)throw new RangeError("Trying to access beyond buffer length")}function C(t,r,e,n,i,o){if(!u$1$1.isBuffer(t))throw new TypeError('"buffer" argument must be a Buffer instance');if(r>i||rt.length)throw new RangeError("Index out of range")}function P(t,r,e,n,i,o){if(e+n>t.length)throw new RangeError("Index out of range");if(e<0)throw new RangeError("Index out of range")}function k(t,r,e,n,o){return r=+r,e>>>=0,o||P(t,0,e,4),i$1.write(t,r,e,n,23,4),e+4}function M(t,r,e,n,o){return r=+r,e>>>=0,o||P(t,0,e,8),i$1.write(t,r,e,n,52,8),e+8}u$1$1.prototype.slice=function(t,r){var e=this.length;(t=~~t)<0?(t+=e)<0&&(t=0):t>e&&(t=e),(r=void 0===r?e:~~r)<0?(r+=e)<0&&(r=0):r>e&&(r=e),r>>=0,r>>>=0,e||x(t,r,this.length);for(var n=this[t],i=1,o=0;++o>>=0,r>>>=0,e||x(t,r,this.length);for(var n=this[t+--r],i=1;r>0&&(i*=256);)n+=this[t+--r]*i;return n},u$1$1.prototype.readUInt8=function(t,r){return t>>>=0,r||x(t,1,this.length),this[t]},u$1$1.prototype.readUInt16LE=function(t,r){return t>>>=0,r||x(t,2,this.length),this[t]|this[t+1]<<8},u$1$1.prototype.readUInt16BE=function(t,r){return t>>>=0,r||x(t,2,this.length),this[t]<<8|this[t+1]},u$1$1.prototype.readUInt32LE=function(t,r){return t>>>=0,r||x(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+16777216*this[t+3]},u$1$1.prototype.readUInt32BE=function(t,r){return t>>>=0,r||x(t,4,this.length),16777216*this[t]+(this[t+1]<<16|this[t+2]<<8|this[t+3])},u$1$1.prototype.readIntLE=function(t,r,e){t>>>=0,r>>>=0,e||x(t,r,this.length);for(var n=this[t],i=1,o=0;++o=(i*=128)&&(n-=Math.pow(2,8*r)),n},u$1$1.prototype.readIntBE=function(t,r,e){t>>>=0,r>>>=0,e||x(t,r,this.length);for(var n=r,i=1,o=this[t+--n];n>0&&(i*=256);)o+=this[t+--n]*i;return o>=(i*=128)&&(o-=Math.pow(2,8*r)),o},u$1$1.prototype.readInt8=function(t,r){return t>>>=0,r||x(t,1,this.length),128&this[t]?-1*(255-this[t]+1):this[t]},u$1$1.prototype.readInt16LE=function(t,r){t>>>=0,r||x(t,2,this.length);var e=this[t]|this[t+1]<<8;return 32768&e?4294901760|e:e},u$1$1.prototype.readInt16BE=function(t,r){t>>>=0,r||x(t,2,this.length);var e=this[t+1]|this[t]<<8;return 32768&e?4294901760|e:e},u$1$1.prototype.readInt32LE=function(t,r){return t>>>=0,r||x(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24},u$1$1.prototype.readInt32BE=function(t,r){return t>>>=0,r||x(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]},u$1$1.prototype.readFloatLE=function(t,r){return t>>>=0,r||x(t,4,this.length),i$1.read(this,t,!0,23,4)},u$1$1.prototype.readFloatBE=function(t,r){return t>>>=0,r||x(t,4,this.length),i$1.read(this,t,!1,23,4)},u$1$1.prototype.readDoubleLE=function(t,r){return t>>>=0,r||x(t,8,this.length),i$1.read(this,t,!0,52,8)},u$1$1.prototype.readDoubleBE=function(t,r){return t>>>=0,r||x(t,8,this.length),i$1.read(this,t,!1,52,8)},u$1$1.prototype.writeUIntLE=function(t,r,e,n){(t=+t,r>>>=0,e>>>=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=1,o=0;for(this[r]=255&t;++o>>=0,e>>>=0,n)||C(this,t,r,e,Math.pow(2,8*e)-1,0);var i=e-1,o=1;for(this[r+i]=255&t;--i>=0&&(o*=256);)this[r+i]=t/o&255;return r+e},u$1$1.prototype.writeUInt8=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,1,255,0),this[r]=255&t,r+1},u$1$1.prototype.writeUInt16LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,65535,0),this[r]=255&t,this[r+1]=t>>>8,r+2},u$1$1.prototype.writeUInt16BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,65535,0),this[r]=t>>>8,this[r+1]=255&t,r+2},u$1$1.prototype.writeUInt32LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,4294967295,0),this[r+3]=t>>>24,this[r+2]=t>>>16,this[r+1]=t>>>8,this[r]=255&t,r+4},u$1$1.prototype.writeUInt32BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,4294967295,0),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t,r+4},u$1$1.prototype.writeIntLE=function(t,r,e,n){if(t=+t,r>>>=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i);}var o=0,f=1,u=0;for(this[r]=255&t;++o>0)-u&255;return r+e},u$1$1.prototype.writeIntBE=function(t,r,e,n){if(t=+t,r>>>=0,!n){var i=Math.pow(2,8*e-1);C(this,t,r,e,i-1,-i);}var o=e-1,f=1,u=0;for(this[r+o]=255&t;--o>=0&&(f*=256);)t<0&&0===u&&0!==this[r+o+1]&&(u=1),this[r+o]=(t/f>>0)-u&255;return r+e},u$1$1.prototype.writeInt8=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,1,127,-128),t<0&&(t=255+t+1),this[r]=255&t,r+1},u$1$1.prototype.writeInt16LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,32767,-32768),this[r]=255&t,this[r+1]=t>>>8,r+2},u$1$1.prototype.writeInt16BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,2,32767,-32768),this[r]=t>>>8,this[r+1]=255&t,r+2},u$1$1.prototype.writeInt32LE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,2147483647,-2147483648),this[r]=255&t,this[r+1]=t>>>8,this[r+2]=t>>>16,this[r+3]=t>>>24,r+4},u$1$1.prototype.writeInt32BE=function(t,r,e){return t=+t,r>>>=0,e||C(this,t,r,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),this[r]=t>>>24,this[r+1]=t>>>16,this[r+2]=t>>>8,this[r+3]=255&t,r+4},u$1$1.prototype.writeFloatLE=function(t,r,e){return k(this,t,r,!0,e)},u$1$1.prototype.writeFloatBE=function(t,r,e){return k(this,t,r,!1,e)},u$1$1.prototype.writeDoubleLE=function(t,r,e){return M(this,t,r,!0,e)},u$1$1.prototype.writeDoubleBE=function(t,r,e){return M(this,t,r,!1,e)},u$1$1.prototype.copy=function(t,r,e,n){if(!u$1$1.isBuffer(t))throw new TypeError("argument should be a Buffer");if(e||(e=0),n||0===n||(n=this.length),r>=t.length&&(r=t.length),r||(r=0),n>0&&n=this.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("sourceEnd out of bounds");n>this.length&&(n=this.length),t.length-r=0;--o)t[o+r]=this[o+e];else Uint8Array.prototype.set.call(t,this.subarray(e,n),r);return i},u$1$1.prototype.fill=function(t,r,e,n){if("string"==typeof t){if("string"==typeof r?(n=r,r=0,e=this.length):"string"==typeof e&&(n=e,e=this.length),void 0!==n&&"string"!=typeof n)throw new TypeError("encoding must be a string");if("string"==typeof n&&!u$1$1.isEncoding(n))throw new TypeError("Unknown encoding: "+n);if(1===t.length){var i=t.charCodeAt(0);("utf8"===n&&i<128||"latin1"===n)&&(t=i);}}else "number"==typeof t?t&=255:"boolean"==typeof t&&(t=Number(t));if(r<0||this.length>>=0,e=void 0===e?this.length:e>>>0,t||(t=0),"number"==typeof t)for(o=r;o55295&&e<57344){if(!i){if(e>56319){(r-=3)>-1&&o.push(239,191,189);continue}if(f+1===n){(r-=3)>-1&&o.push(239,191,189);continue}i=e;continue}if(e<56320){(r-=3)>-1&&o.push(239,191,189),i=e;continue}e=65536+(i-55296<<10|e-56320);}else i&&(r-=3)>-1&&o.push(239,191,189);if(i=null,e<128){if((r-=1)<0)break;o.push(e);}else if(e<2048){if((r-=2)<0)break;o.push(e>>6|192,63&e|128);}else if(e<65536){if((r-=3)<0)break;o.push(e>>12|224,e>>6&63|128,63&e|128);}else {if(!(e<1114112))throw new Error("Invalid code point");if((r-=4)<0)break;o.push(e>>18|240,e>>12&63|128,e>>6&63|128,63&e|128);}}return o}function z(t){return n$1$1.toByteArray(function(t){if((t=(t=t.split("=")[0]).trim().replace(j,"")).length<2)return "";for(;t.length%4!=0;)t+="=";return t}(t))}function D(t,r,e,n){for(var i=0;i=r.length||i>=t.length);++i)r[i+e]=t[i];return i}function F(t,r){return t instanceof r||null!=t&&null!=t.constructor&&null!=t.constructor.name&&t.constructor.name===r.name}function N(t){return t!=t}var Y=function(){for(var t=new Array(256),r=0;r<16;++r)for(var e=16*r,n=0;n<16;++n)t[e+n]="0123456789abcdef"[r]+"0123456789abcdef"[n];return t}();e$1$1.Buffer;e$1$1.INSPECT_MAX_BYTES;e$1$1.kMaxLength; - -var e={},n=e$1$1,o=n.Buffer;function t(r,e){for(var n in r)e[n]=r[n];}function f(r,e,n){return o(r,e,n)}o.from&&o.alloc&&o.allocUnsafe&&o.allocUnsafeSlow?e=n:(t(n,e),e.Buffer=f),f.prototype=Object.create(o.prototype),t(o,f),f.from=function(r,e,n){if("number"==typeof r)throw new TypeError("Argument must not be a number");return o(r,e,n)},f.alloc=function(r,e,n){if("number"!=typeof r)throw new TypeError("Argument must be a number");var t=o(r);return void 0!==e?"string"==typeof n?t.fill(e,n):t.fill(e):t.fill(0),t},f.allocUnsafe=function(r){if("number"!=typeof r)throw new TypeError("Argument must be a number");return o(r)},f.allocUnsafeSlow=function(r){if("number"!=typeof r)throw new TypeError("Argument must be a number");return n.SlowBuffer(r)};var u=e;var e$1={},s=u.Buffer,i=s.isEncoding||function(t){switch((t=""+t)&&t.toLowerCase()){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 !0;default:return !1}};function a(t){var e;switch(this.encoding=function(t){var e=function(t){if(!t)return "utf8";for(var e;;)switch(t){case"utf8":case"utf-8":return "utf8";case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return "utf16le";case"latin1":case"binary":return "latin1";case"base64":case"ascii":case"hex":return t;default:if(e)return;t=(""+t).toLowerCase(),e=!0;}}(t);if("string"!=typeof e&&(s.isEncoding===i||!i(t)))throw new Error("Unknown encoding: "+t);return e||t}(t),this.encoding){case"utf16le":this.text=h,this.end=l,e=4;break;case"utf8":this.fillLast=n$1,e=4;break;case"base64":this.text=u$1,this.end=o$1,e=3;break;default:return this.write=f$1,this.end=c,void 0}this.lastNeed=0,this.lastTotal=0,this.lastChar=s.allocUnsafe(e);}function r(t){return t<=127?0:t>>5==6?2:t>>4==14?3:t>>3==30?4:t>>6==2?-1:-2}function n$1(t){var e=this.lastTotal-this.lastNeed,s=function(t,e,s){if(128!=(192&e[0]))return t.lastNeed=0,"�";if(t.lastNeed>1&&e.length>1){if(128!=(192&e[1]))return t.lastNeed=1,"�";if(t.lastNeed>2&&e.length>2&&128!=(192&e[2]))return t.lastNeed=2,"�"}}(this,t);return void 0!==s?s:this.lastNeed<=t.length?(t.copy(this.lastChar,e,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal)):(t.copy(this.lastChar,e,0,t.length),this.lastNeed-=t.length,void 0)}function h(t,e){if((t.length-e)%2==0){var s=t.toString("utf16le",e);if(s){var i=s.charCodeAt(s.length-1);if(i>=55296&&i<=56319)return this.lastNeed=2,this.lastTotal=4,this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1],s.slice(0,-1)}return s}return this.lastNeed=1,this.lastTotal=2,this.lastChar[0]=t[t.length-1],t.toString("utf16le",e,t.length-1)}function l(t){var e=t&&t.length?this.write(t):"";if(this.lastNeed){var s=this.lastTotal-this.lastNeed;return e+this.lastChar.toString("utf16le",0,s)}return e}function u$1(t,e){var s=(t.length-e)%3;return 0===s?t.toString("base64",e):(this.lastNeed=3-s,this.lastTotal=3,1===s?this.lastChar[0]=t[t.length-1]:(this.lastChar[0]=t[t.length-2],this.lastChar[1]=t[t.length-1]),t.toString("base64",e,t.length-s))}function o$1(t){var e=t&&t.length?this.write(t):"";return this.lastNeed?e+this.lastChar.toString("base64",0,3-this.lastNeed):e}function f$1(t){return t.toString(this.encoding)}function c(t){return t&&t.length?this.write(t):""}e$1.StringDecoder=a,a.prototype.write=function(t){if(0===t.length)return "";var e,s;if(this.lastNeed){if(void 0===(e=this.fillLast(t)))return "";s=this.lastNeed,this.lastNeed=0;}else s=0;return s=0)return a>0&&(t.lastNeed=a-1),a;if(--i=0)return a>0&&(t.lastNeed=a-2),a;if(--i=0)return a>0&&(2===a?a=0:t.lastNeed=a-3),a;return 0}(this,t,e);if(!this.lastNeed)return t.toString("utf8",e);this.lastTotal=s;var i=t.length-(s-this.lastNeed);return t.copy(this.lastChar,0,i),t.toString("utf8",e,i)},a.prototype.fillLast=function(t){if(this.lastNeed<=t.length)return t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,this.lastNeed),this.lastChar.toString(this.encoding,0,this.lastTotal);t.copy(this.lastChar,this.lastTotal-this.lastNeed,0,t.length),this.lastNeed-=t.length;}; - -e$1.StringDecoder; - -e$1.StringDecoder; - -export { e$1 as a, e$1$1 as e, u }; diff --git a/nodelibs/browser/chunk-CKeAujU-.js b/nodelibs/browser/chunk-CKeAujU-.js deleted file mode 100644 index ba2507c..0000000 --- a/nodelibs/browser/chunk-CKeAujU-.js +++ /dev/null @@ -1,3 +0,0 @@ -const t=2147483647,o=/^xn--/,n=/[^\0-\x7E]/,e=/[\x2E\u3002\uFF0E\uFF61]/g,r={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},c=Math.floor,s=String.fromCharCode;function i(t){throw new RangeError(r[t])}function f(t,o){const n=t.split("@");let r="";n.length>1&&(r=n[0]+"@",t=n[1]);const c=function(t,o){const n=[];let e=t.length;for(;e--;)n[e]=o(t[e]);return n}((t=t.replace(e,".")).split("."),o).join(".");return r+c}function l(t){const o=[];let n=0;const e=t.length;for(;n=55296&&r<=56319&&n>1,t+=c(t/o);t>455;e+=36)t=c(t/35);return c(e+36*t/(t+38))},d=function(o){const n=[],e=o.length;let r=0,s=128,f=72,l=o.lastIndexOf("-");l<0&&(l=0);for(let t=0;t=128&&i("not-basic"),n.push(o.charCodeAt(t));for(let d=l>0?l+1:0;d=e&&i("invalid-input");const l=(u=o.charCodeAt(d++))-48<10?u-22:u-65<26?u-65:u-97<26?u-97:36;(l>=36||l>c((t-r)/n))&&i("overflow"),r+=l*n;const a=s<=f?1:s>=f+26?26:s-f;if(lc(t/h)&&i("overflow"),n*=h;}const h=n.length+1;f=a(r-l,h,0==l),c(r/h)>t-s&&i("overflow"),s+=c(r/h),r%=h,n.splice(r++,0,s);}var u;return String.fromCodePoint(...n)},h=function(o){const n=[];let e=(o=l(o)).length,r=128,f=0,d=72;for(const t of o)t<128&&n.push(s(t));let h=n.length,p=h;for(h&&n.push("-");p=r&&tc((t-f)/l)&&i("overflow"),f+=(e-r)*l,r=e;for(const e of o)if(et&&i("overflow"),e==r){let t=f;for(let o=36;;o+=36){const e=o<=d?1:o>=d+26?26:o-d;if(tString.fromCodePoint(...t)},decode:d,encode:h,toASCII:function(t){return f(t,(function(t){return n.test(t)?"xn--"+h(t):t}))},toUnicode:function(t){return f(t,(function(t){return o.test(t)?d(t.slice(4).toLowerCase()):t}))}};p.decode;p.encode;p.toASCII;p.toUnicode;p.ucs2;p.version; - -export { p }; diff --git a/nodelibs/browser/chunk-CbQqNoLO.js b/nodelibs/browser/chunk-CbQqNoLO.js new file mode 100644 index 0000000..048a5f4 --- /dev/null +++ b/nodelibs/browser/chunk-CbQqNoLO.js @@ -0,0 +1,32 @@ +import { X } from './chunk-D3uu3VYh.js'; + +X._extend; +X.callbackify; +X.debuglog; +X.deprecate; +X.format; +X.inherits; +X.inspect; +X.isArray; +X.isBoolean; +X.isBuffer; +X.isDate; +X.isError; +X.isFunction; +X.isNull; +X.isNullOrUndefined; +X.isNumber; +X.isObject; +X.isPrimitive; +X.isRegExp; +X.isString; +X.isSymbol; +X.isUndefined; +X.log; +var promisify = X.promisify; +X.types; + +X.TextEncoder = globalThis.TextEncoder; +X.TextDecoder = globalThis.TextDecoder; + +export { promisify as p }; diff --git a/nodelibs/browser/chunk-CcCWfKp1.js b/nodelibs/browser/chunk-CcCWfKp1.js new file mode 100644 index 0000000..3170edb --- /dev/null +++ b/nodelibs/browser/chunk-CcCWfKp1.js @@ -0,0 +1,360 @@ +import { d as dew$2 } from './chunk-DtuTasat.js'; + +var exports$2 = {}, + _dewExec$1 = false; +function dew$1() { + if (_dewExec$1) return exports$2; + _dewExec$1 = true; + /*! safe-buffer. MIT License. Feross Aboukhadijeh */ + /* eslint-disable node/no-deprecated-api */ + var buffer = dew$2(); + var Buffer = buffer.Buffer; + + // alternative to using Object.keys for old browsers + function copyProps(src, dst) { + for (var key in src) { + dst[key] = src[key]; + } + } + if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + exports$2 = buffer; + } else { + // Copy properties from require('buffer') + copyProps(buffer, exports$2); + exports$2.Buffer = SafeBuffer; + } + function SafeBuffer(arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length); + } + SafeBuffer.prototype = Object.create(Buffer.prototype); + + // Copy static methods from Buffer + copyProps(Buffer, SafeBuffer); + SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === "number") { + throw new TypeError("Argument must not be a number"); + } + return Buffer(arg, encodingOrOffset, length); + }; + SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + var buf = Buffer(size); + if (fill !== undefined) { + if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } + } else { + buf.fill(0); + } + return buf; + }; + SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + return Buffer(size); + }; + SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + return buffer.SlowBuffer(size); + }; + return exports$2; +} + +var exports$1 = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports$1; + _dewExec = true; + /**/ + + var Buffer = dew$1().Buffer; + /**/ + + var isEncoding = Buffer.isEncoding || function (encoding) { + encoding = "" + encoding; + switch (encoding && encoding.toLowerCase()) { + 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; + default: + return false; + } + }; + function _normalizeEncoding(enc) { + if (!enc) return "utf8"; + var retried; + while (true) { + switch (enc) { + case "utf8": + case "utf-8": + return "utf8"; + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return "utf16le"; + case "latin1": + case "binary": + return "latin1"; + case "base64": + case "ascii": + case "hex": + return enc; + default: + if (retried) return; // undefined + enc = ("" + enc).toLowerCase(); + retried = true; + } + } + } + + // Do not cache `Buffer.isEncoding` when checking encoding names as some + // modules monkey-patch it to support additional encodings + function normalizeEncoding(enc) { + var nenc = _normalizeEncoding(enc); + if (typeof nenc !== "string" && (Buffer.isEncoding === isEncoding || !isEncoding(enc))) throw new Error("Unknown encoding: " + enc); + return nenc || enc; + } + + // StringDecoder provides an interface for efficiently splitting a series of + // buffers into a series of JS strings without breaking apart multi-byte + // characters. + exports$1.StringDecoder = StringDecoder; + function StringDecoder(encoding) { + this.encoding = normalizeEncoding(encoding); + var nb; + switch (this.encoding) { + case "utf16le": + this.text = utf16Text; + this.end = utf16End; + nb = 4; + break; + case "utf8": + this.fillLast = utf8FillLast; + nb = 4; + break; + case "base64": + this.text = base64Text; + this.end = base64End; + nb = 3; + break; + default: + this.write = simpleWrite; + this.end = simpleEnd; + return; + } + this.lastNeed = 0; + this.lastTotal = 0; + this.lastChar = Buffer.allocUnsafe(nb); + } + StringDecoder.prototype.write = function (buf) { + if (buf.length === 0) return ""; + var r; + var i; + if (this.lastNeed) { + r = this.fillLast(buf); + if (r === undefined) return ""; + i = this.lastNeed; + this.lastNeed = 0; + } else { + i = 0; + } + if (i < buf.length) return r ? r + this.text(buf, i) : this.text(buf, i); + return r || ""; + }; + StringDecoder.prototype.end = utf8End; + + // Returns only complete characters in a Buffer + StringDecoder.prototype.text = utf8Text; + + // Attempts to complete a partial non-UTF-8 character using bytes from a Buffer + StringDecoder.prototype.fillLast = function (buf) { + if (this.lastNeed <= buf.length) { + buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, this.lastNeed); + return this.lastChar.toString(this.encoding, 0, this.lastTotal); + } + buf.copy(this.lastChar, this.lastTotal - this.lastNeed, 0, buf.length); + this.lastNeed -= buf.length; + }; + + // Checks the type of a UTF-8 byte, whether it's ASCII, a leading byte, or a + // continuation byte. If an invalid byte is detected, -2 is returned. + function utf8CheckByte(byte) { + if (byte <= 127) return 0;else if (byte >> 5 === 6) return 2;else if (byte >> 4 === 14) return 3;else if (byte >> 3 === 30) return 4; + return byte >> 6 === 2 ? -1 : -2; + } + + // Checks at most 3 bytes at the end of a Buffer in order to detect an + // incomplete multi-byte UTF-8 character. The total number of bytes (2, 3, or 4) + // needed to complete the UTF-8 character (if applicable) are returned. + function utf8CheckIncomplete(self, buf, i) { + var j = buf.length - 1; + if (j < i) return 0; + var nb = utf8CheckByte(buf[j]); + if (nb >= 0) { + if (nb > 0) self.lastNeed = nb - 1; + return nb; + } + if (--j < i || nb === -2) return 0; + nb = utf8CheckByte(buf[j]); + if (nb >= 0) { + if (nb > 0) self.lastNeed = nb - 2; + return nb; + } + if (--j < i || nb === -2) return 0; + nb = utf8CheckByte(buf[j]); + if (nb >= 0) { + if (nb > 0) { + if (nb === 2) nb = 0;else self.lastNeed = nb - 3; + } + return nb; + } + return 0; + } + + // Validates as many continuation bytes for a multi-byte UTF-8 character as + // needed or are available. If we see a non-continuation byte where we expect + // one, we "replace" the validated continuation bytes we've seen so far with + // a single UTF-8 replacement character ('\ufffd'), to match v8's UTF-8 decoding + // behavior. The continuation byte check is included three times in the case + // where all of the continuation bytes for a character exist in the same buffer. + // It is also done this way as a slight performance increase instead of using a + // loop. + function utf8CheckExtraBytes(self, buf, p) { + if ((buf[0] & 192) !== 128) { + self.lastNeed = 0; + return "\uFFFD"; + } + if (self.lastNeed > 1 && buf.length > 1) { + if ((buf[1] & 192) !== 128) { + self.lastNeed = 1; + return "\uFFFD"; + } + if (self.lastNeed > 2 && buf.length > 2) { + if ((buf[2] & 192) !== 128) { + self.lastNeed = 2; + return "\uFFFD"; + } + } + } + } + + // Attempts to complete a multi-byte UTF-8 character using bytes from a Buffer. + function utf8FillLast(buf) { + var p = this.lastTotal - this.lastNeed; + var r = utf8CheckExtraBytes(this, buf); + if (r !== undefined) return r; + if (this.lastNeed <= buf.length) { + buf.copy(this.lastChar, p, 0, this.lastNeed); + return this.lastChar.toString(this.encoding, 0, this.lastTotal); + } + buf.copy(this.lastChar, p, 0, buf.length); + this.lastNeed -= buf.length; + } + + // Returns all complete UTF-8 characters in a Buffer. If the Buffer ended on a + // partial character, the character's bytes are buffered until the required + // number of bytes are available. + function utf8Text(buf, i) { + var total = utf8CheckIncomplete(this, buf, i); + if (!this.lastNeed) return buf.toString("utf8", i); + this.lastTotal = total; + var end = buf.length - (total - this.lastNeed); + buf.copy(this.lastChar, 0, end); + return buf.toString("utf8", i, end); + } + + // For UTF-8, a replacement character is added when ending on a partial + // character. + function utf8End(buf) { + var r = buf && buf.length ? this.write(buf) : ""; + if (this.lastNeed) return r + "\uFFFD"; + return r; + } + + // UTF-16LE typically needs two bytes per character, but even if we have an even + // number of bytes available, we need to check if we end on a leading/high + // surrogate. In that case, we need to wait for the next two bytes in order to + // decode the last character properly. + function utf16Text(buf, i) { + if ((buf.length - i) % 2 === 0) { + var r = buf.toString("utf16le", i); + if (r) { + var c = r.charCodeAt(r.length - 1); + if (c >= 55296 && c <= 56319) { + this.lastNeed = 2; + this.lastTotal = 4; + this.lastChar[0] = buf[buf.length - 2]; + this.lastChar[1] = buf[buf.length - 1]; + return r.slice(0, -1); + } + } + return r; + } + this.lastNeed = 1; + this.lastTotal = 2; + this.lastChar[0] = buf[buf.length - 1]; + return buf.toString("utf16le", i, buf.length - 1); + } + + // For UTF-16LE we do not explicitly append special replacement characters if we + // end on a partial character, we simply let v8 handle that. + function utf16End(buf) { + var r = buf && buf.length ? this.write(buf) : ""; + if (this.lastNeed) { + var end = this.lastTotal - this.lastNeed; + return r + this.lastChar.toString("utf16le", 0, end); + } + return r; + } + function base64Text(buf, i) { + var n = (buf.length - i) % 3; + if (n === 0) return buf.toString("base64", i); + this.lastNeed = 3 - n; + this.lastTotal = 3; + if (n === 1) { + this.lastChar[0] = buf[buf.length - 1]; + } else { + this.lastChar[0] = buf[buf.length - 2]; + this.lastChar[1] = buf[buf.length - 1]; + } + return buf.toString("base64", i, buf.length - n); + } + function base64End(buf) { + var r = buf && buf.length ? this.write(buf) : ""; + if (this.lastNeed) return r + this.lastChar.toString("base64", 0, 3 - this.lastNeed); + return r; + } + + // Pass bytes on through for single-byte encodings (e.g. ascii, latin1, hex) + function simpleWrite(buf) { + return buf.toString(this.encoding); + } + function simpleEnd(buf) { + return buf && buf.length ? this.write(buf) : ""; + } + return exports$1; +} + +const exports = dew(); +exports['StringDecoder']; + +var StringDecoder = exports.StringDecoder; + +export { StringDecoder as S, dew$1 as d, exports as e }; diff --git a/nodelibs/browser/chunk-CjPlbOtt.js b/nodelibs/browser/chunk-CjPlbOtt.js new file mode 100644 index 0000000..dcfc0a3 --- /dev/null +++ b/nodelibs/browser/chunk-CjPlbOtt.js @@ -0,0 +1,47 @@ +import { X as X$1, T as T$1 } from './chunk-D3uu3VYh.js'; + +function e(e,r){if(null==e)throw new TypeError("Cannot convert first argument to object");for(var t=Object(e),n=1;n=0&&"[object Function]"===e$1.call(t.callee)),n};if(!Object.keys){var n=Object.prototype.hasOwnProperty,o=Object.prototype.toString,c=r$1,l=Object.prototype.propertyIsEnumerable,i=!l.call({toString:null},"toString"),a=l.call((function(){}),"prototype"),u=["toString","toLocaleString","valueOf","hasOwnProperty","isPrototypeOf","propertyIsEnumerable","constructor"],f=function(t){var e=t.constructor;return e&&e.prototype===t},p={$applicationCache:!0,$console:!0,$external:!0,$frame:!0,$frameElement:!0,$frames:!0,$innerHeight:!0,$innerWidth:!0,$onmozfullscreenchange:!0,$onmozfullscreenerror:!0,$outerHeight:!0,$outerWidth:!0,$pageXOffset:!0,$pageYOffset:!0,$parent:!0,$scrollLeft:!0,$scrollTop:!0,$scrollX:!0,$scrollY:!0,$self:!0,$webkitIndexedDB:!0,$webkitStorageInfo:!0,$window:!0},s=function(){if("undefined"==typeof window)return !1;for(var t in window)try{if(!p["$"+t]&&n.call(window,t)&&null!==window[t]&&"object"==typeof window[t])try{f(window[t]);}catch(t){return !0}}catch(t){return !0}return !1}();t=function(t){var e=null!==t&&"object"==typeof t,r="[object Function]"===o.call(t),l=c(t),p=e&&"[object String]"===o.call(t),y=[];if(!e&&!r&&!l)throw new TypeError("Object.keys called on a non-object");var b=a&&r;if(p&&t.length>0&&!n.call(t,0))for(var g=0;g0)for(var h=0;h2?arguments[2]:{},c=r$2(o);e$2&&(c=n$1.call(c,Object.getOwnPropertySymbols(o)));for(var u=0;u1&&"boolean"!=typeof e)throw new TypeError('"allowMissing" argument must be a boolean');for(var n=v(r),y=P("%"+(n.length>0?n[0]:"")+"%",e),a=1;a=n.length){var i=t$3(y,n[a]);if(!(n[a]in y))throw new o$3("base intrinsic for "+r+" exists, but the property is not available.");y=i?i.get||i.value:y[n[a]];}else y=y[n[a]];return y};var t$4,p$1=e$4,o$4=c$2("%Function%"),i$2=o$4.apply,a$3=o$4.call;(t$4=function(){return p$1.apply(a$3,arguments)}).apply=function(){return p$1.apply(i$2,arguments)};var l$4=t$4;var r$4,n$4,i$3=function(t){return t!=t},o$5=(r$4=function(t,e){return 0===t&&0===e?1/t==1/e:t===e||!(!i$3(t)||!i$3(e))},r$4),c$3=(n$4=function(){return "function"==typeof Object.is?Object.is:o$5},n$4),f$4=f$1,u$3=f$1,s$1=r$4,a$4=n$4,l$5=function(){var t=c$3();return f$4(Object,{is:t},{is:function(){return Object.is!==t}}),t},p$2=l$4(a$4(),Object);u$3(p$2,{getPolyfill:a$4,implementation:s$1,shim:l$5});var m=p$2;N=function(r){return r!=r};var N,e$5,i$4=N,n$5=(e$5=function(){return Number.isNaN&&Number.isNaN(NaN)&&!Number.isNaN("a")?Number.isNaN:i$4},f$1),t$5=e$5,u$4=f$1,a$5=N,m$1=e$5,o$6=function(){var r=t$5();return n$5(Number,{isNaN:r},{isNaN:function(){return Number.isNaN!==r}}),r},s$2=m$1();u$4(s$2,{getPolyfill:m$1,implementation:a$5,shim:o$6});var f$5=s$2;var c$4={},a$6=!1;function i$5(){if(a$6)return c$4;function e(t){return (e="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function n(t,n){return !n||"object"!==e(n)&&"function"!=typeof n?function(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}(t):n}function r(t){return (r=Object.setPrototypeOf?Object.getPrototypeOf:function(t){return t.__proto__||Object.getPrototypeOf(t)})(t)}function o(t,e){return (o=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}a$6=!0;var i,u,l={};function f(t,e,c){c||(c=Error);var a=function(c){function a(o,c,i){var u;return !function(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}(this,a),(u=n(this,r(a).call(this,function(t,n,r){return "string"==typeof e?e:e(t,n,r)}(o,c,i)))).code=t,u}return !function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&o(t,e);}(a,c),a}(c);l[t]=a;}function s(t,e){if(Array.isArray(t)){var n=t.length;return t=t.map((function(t){return String(t)})),n>2?"one of ".concat(e," ").concat(t.slice(0,n-1).join(", "),", or ")+t[n-1]:2===n?"one of ".concat(e," ").concat(t[0]," or ").concat(t[1]):"of ".concat(e," ").concat(t[0])}return "of ".concat(e," ").concat(String(t))}return f("ERR_AMBIGUOUS_ARGUMENT",'The "%s" argument is ambiguous. %s',TypeError),f("ERR_INVALID_ARG_TYPE",(function(t,n,r){var o,c,u;if(void 0===i&&(i=tt()),i("string"==typeof t,"'name' must be a string"),"string"==typeof n&&(c="not ",n.substr(0,c.length)===c)?(o="must not be",n=n.replace(/^not /,"")):o="must be",function(t,e,n){return (void 0===n||n>t.length)&&(n=t.length),t.substring(n-e.length,n)===e}(t," argument"))u="The ".concat(t," ").concat(o," ").concat(s(n,"type"));else {var l=function(t,e,n){return "number"!=typeof n&&(n=0),!(n+e.length>t.length)&&-1!==t.indexOf(e,n)}(t,".")?"property":"argument";u='The "'.concat(t,'" ').concat(l," ").concat(o," ").concat(s(n,"type"));}return u+=". Received type ".concat(e(r))}),TypeError),f("ERR_INVALID_ARG_VALUE",(function(e,n){var r=arguments.length>2&&void 0!==arguments[2]?arguments[2]:"is invalid";void 0===u&&(u=X$1);var o=u.inspect(n);return o.length>128&&(o="".concat(o.slice(0,128),"...")),"The argument '".concat(e,"' ").concat(r,". Received ").concat(o)}),TypeError),f("ERR_INVALID_RETURN_VALUE",(function(t,n,r){var o;return o=r&&r.constructor&&r.constructor.name?"instance of ".concat(r.constructor.name):"type ".concat(e(r)),"Expected ".concat(t,' to be returned from the "').concat(n,'"')+" function but got ".concat(o,".")}),TypeError),f("ERR_MISSING_ARGS",(function(){for(var t=arguments.length,e=new Array(t),n=0;n0,"At least one arg needs to be specified");var r="The ",o=e.length;switch(e=e.map((function(t){return '"'.concat(t,'"')})),o){case 1:r+="".concat(e[0]," argument");break;case 2:r+="".concat(e[0]," and ").concat(e[1]," arguments");break;default:r+=e.slice(0,o-1).join(", "),r+=", and ".concat(e[o-1]," arguments");}return "".concat(r," must be specified")}),TypeError),c$4.codes=l,c$4}var u$5={},l$6=!1;function f$6(){if(l$6)return u$5;l$6=!0;var n=T$1;function r(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function o(t,e){for(var n=0;nt.length)&&(n=t.length),t.substring(n-e.length,n)===e}var m="",E="",w="",S="",j={deepStrictEqual:"Expected values to be strictly deep-equal:",strictEqual:"Expected values to be strictly equal:",strictEqualObject:'Expected "actual" to be reference-equal to "expected":',deepEqual:"Expected values to be loosely deep-equal:",equal:"Expected values to be loosely equal:",notDeepStrictEqual:'Expected "actual" not to be strictly deep-equal to:',notStrictEqual:'Expected "actual" to be strictly unequal to:',notStrictEqualObject:'Expected "actual" not to be reference-equal to "expected":',notDeepEqual:'Expected "actual" not to be loosely deep-equal to:',notEqual:'Expected "actual" to be loosely unequal to:',notIdentical:"Values identical but not reference-equal:"};function O(t){var e=Object.keys(t),n=Object.create(Object.getPrototypeOf(t));return e.forEach((function(e){n[e]=t[e];})),Object.defineProperty(n,"message",{value:t.message}),n}function x(t){return b(t,{compact:!1,customInspect:!1,depth:1e3,maxArrayLength:1/0,showHidden:!1,breakLength:1/0,showProxy:!1,sorted:!0,getters:!0})}function q(t,e,r){var o="",c="",a=0,i="",u=!1,l=x(t),f=l.split("\n"),s=x(e).split("\n"),p=0,g="";if("strictEqual"===r&&"object"===y(t)&&"object"===y(e)&&null!==t&&null!==e&&(r="strictEqualObject"),1===f.length&&1===s.length&&f[0]!==s[0]){var h=f[0].length+s[0].length;if(h<=10){if(!("object"===y(t)&&null!==t||"object"===y(e)&&null!==e||0===t&&0===e))return "".concat(j[r],"\n\n")+"".concat(f[0]," !== ").concat(s[0],"\n")}else if("strictEqualObject"!==r){if(h<(n.stderr&&n.stderr.isTTY?n.stderr.columns:80)){for(;f[0][p]===s[0][p];)p++;p>2&&(g="\n ".concat(function(t,e){if(e=Math.floor(e),0==t.length||0==e)return "";var n=t.length*e;for(e=Math.floor(Math.log(e)/Math.log(2));e;)t+=t,e--;return t+=t.substring(0,n-t.length)}(" ",p),"^"),p=0);}}}for(var b=f[f.length-1],v=s[s.length-1];b===v&&(p++<2?i="\n ".concat(b).concat(i):o=b,f.pop(),s.pop(),0!==f.length&&0!==s.length);)b=f[f.length-1],v=s[s.length-1];var O=Math.max(f.length,s.length);if(0===O){var q=l.split("\n");if(q.length>30)for(q[26]="".concat(m,"...").concat(S);q.length>27;)q.pop();return "".concat(j.notIdentical,"\n\n").concat(q.join("\n"),"\n")}p>3&&(i="\n".concat(m,"...").concat(S).concat(i),u=!0),""!==o&&(i="\n ".concat(o).concat(i),o="");var R=0,A=j[r]+"\n".concat(E,"+ actual").concat(S," ").concat(w,"- expected").concat(S),k=" ".concat(m,"...").concat(S," Lines skipped");for(p=0;p1&&p>2&&(_>4?(c+="\n".concat(m,"...").concat(S),u=!0):_>3&&(c+="\n ".concat(s[p-2]),R++),c+="\n ".concat(s[p-1]),R++),a=p,o+="\n".concat(w,"-").concat(S," ").concat(s[p]),R++;else if(s.length1&&p>2&&(_>4?(c+="\n".concat(m,"...").concat(S),u=!0):_>3&&(c+="\n ".concat(f[p-2]),R++),c+="\n ".concat(f[p-1]),R++),a=p,c+="\n".concat(E,"+").concat(S," ").concat(f[p]),R++;else {var T=s[p],P=f[p],I=P!==T&&(!d(P,",")||P.slice(0,-1)!==T);I&&d(T,",")&&T.slice(0,-1)===P&&(I=!1,P+=","),I?(_>1&&p>2&&(_>4?(c+="\n".concat(m,"...").concat(S),u=!0):_>3&&(c+="\n ".concat(f[p-2]),R++),c+="\n ".concat(f[p-1]),R++),a=p,c+="\n".concat(E,"+").concat(S," ").concat(P),o+="\n".concat(w,"-").concat(S," ").concat(T),R+=2):(c+=o,o="",1!==_&&0!==p||(c+="\n ".concat(P),R++));}if(R>20&&p30)for(g[26]="".concat(m,"...").concat(S);g.length>27;)g.pop();r=1===g.length?c(this,h(e).call(this,"".concat(p," ").concat(g[0]))):c(this,h(e).call(this,"".concat(p,"\n\n").concat(g.join("\n"),"\n")));}else {var b=x(l),d="",R=j[i];"notDeepEqual"===i||"notEqual"===i?(b="".concat(j[i],"\n\n").concat(b)).length>1024&&(b="".concat(b.slice(0,1021),"...")):(d="".concat(x(f)),b.length>512&&(b="".concat(b.slice(0,509),"...")),d.length>512&&(d="".concat(d.slice(0,509),"...")),"deepEqual"===i||"equal"===i?b="".concat(R,"\n\n").concat(b,"\n\nshould equal\n\n"):d=" ".concat(i," ").concat(d)),r=c(this,h(e).call(this,"".concat(b).concat(d)));}return Error.stackTraceLimit=s,r.generatedMessage=!o,Object.defineProperty(a(r),"name",{value:"AssertionError [ERR_ASSERTION]",enumerable:!1,writable:!0,configurable:!0}),r.code="ERR_ASSERTION",r.actual=l,r.expected=f,r.operator=i,Error.captureStackTrace&&Error.captureStackTrace(a(r),u),r.stack,r.name="AssertionError",c(r)}var i,u;return !function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Super expression must either be null or a function");t.prototype=Object.create(e&&e.prototype,{constructor:{value:t,writable:!0,configurable:!0}}),e&&g(t,e);}(e,t),i=e,(u=[{key:"toString",value:function(){return "".concat(this.name," [").concat(this.code,"]: ").concat(this.message)}},{key:b.custom,value:function(t,e){return b(this,function(t){for(var e=1;e10)return !0;for(var e=0;e57)return !0}return 10===t.length&&t>=Math.pow(2,32)}function G(t){return Object.keys(t).filter(U).concat(v$1(t).filter(Object.prototype.propertyIsEnumerable.bind(t)))} +/*! + * The buffer module from node.js, for the browser. + * + * @author Feross Aboukhadijeh + * @license MIT + */function V(t,e){if(t===e)return 0;for(var n=t.length,r=e.length,o=0,c=Math.min(n,r);o1?n-1:0),o=1;o1?n-1:0),o=1;o1?n-1:0),o=1;o1?n-1:0),o=1;o1)for(var n=1;n=0&&"[object Array]"!==e.call(t)&&"[object Function]"===e.call(t.callee)},r=function(){return o(arguments)}();o.isLegacyArguments=n;var l=r?o:n;var t$1=Object.prototype.toString,o$1=Function.prototype.toString,n$1=/^\s*(?:function)?\*/,e$1="function"==typeof Symbol&&"symbol"==typeof Symbol.toStringTag,r$1=Object.getPrototypeOf,c=function(){if(!e$1)return !1;try{return Function("return function*() {}")()}catch(t){}}(),u=c?r$1(c):{},i=function(c){return "function"==typeof c&&(!!n$1.test(o$1.call(c))||(e$1?r$1(c)===u:"[object GeneratorFunction]"===t$1.call(c)))};var t$2="function"==typeof Object.create?function(t,e){e&&(t.super_=e,t.prototype=Object.create(e.prototype,{constructor:{value:t,enumerable:!1,writable:!0,configurable:!0}}));}:function(t,e){if(e){t.super_=e;var o=function(){};o.prototype=e.prototype,t.prototype=new o,t.prototype.constructor=t;}};var i$1=function(e){return e&&"object"==typeof e&&"function"==typeof e.copy&&"function"==typeof e.fill&&"function"==typeof e.readUInt8},o$2={},u$1=i$1,f=l,a=i;function c$1(e){return e.call.bind(e)}var s="undefined"!=typeof BigInt,p="undefined"!=typeof Symbol,y=p&&void 0!==Symbol.toStringTag,l$1="undefined"!=typeof Uint8Array,d="undefined"!=typeof ArrayBuffer;if(l$1&&y)var g=Object.getPrototypeOf(Uint8Array.prototype),b=c$1(Object.getOwnPropertyDescriptor(g,Symbol.toStringTag).get);var m=c$1(Object.prototype.toString),h=c$1(Number.prototype.valueOf),j=c$1(String.prototype.valueOf),A=c$1(Boolean.prototype.valueOf);if(s)var w=c$1(BigInt.prototype.valueOf);if(p)var v=c$1(Symbol.prototype.valueOf);function O(e,t){if("object"!=typeof e)return !1;try{return t(e),!0}catch(e){return !1}}function S(e){return l$1&&y?void 0!==b(e):B(e)||k(e)||E(e)||D(e)||U(e)||P(e)||x(e)||I(e)||M(e)||z(e)||F(e)}function B(e){return l$1&&y?"Uint8Array"===b(e):"[object Uint8Array]"===m(e)||u$1(e)&&void 0!==e.buffer}function k(e){return l$1&&y?"Uint8ClampedArray"===b(e):"[object Uint8ClampedArray]"===m(e)}function E(e){return l$1&&y?"Uint16Array"===b(e):"[object Uint16Array]"===m(e)}function D(e){return l$1&&y?"Uint32Array"===b(e):"[object Uint32Array]"===m(e)}function U(e){return l$1&&y?"Int8Array"===b(e):"[object Int8Array]"===m(e)}function P(e){return l$1&&y?"Int16Array"===b(e):"[object Int16Array]"===m(e)}function x(e){return l$1&&y?"Int32Array"===b(e):"[object Int32Array]"===m(e)}function I(e){return l$1&&y?"Float32Array"===b(e):"[object Float32Array]"===m(e)}function M(e){return l$1&&y?"Float64Array"===b(e):"[object Float64Array]"===m(e)}function z(e){return l$1&&y?"BigInt64Array"===b(e):"[object BigInt64Array]"===m(e)}function F(e){return l$1&&y?"BigUint64Array"===b(e):"[object BigUint64Array]"===m(e)}function T(e){return "[object Map]"===m(e)}function N(e){return "[object Set]"===m(e)}function W(e){return "[object WeakMap]"===m(e)}function $(e){return "[object WeakSet]"===m(e)}function C(e){return "[object ArrayBuffer]"===m(e)}function V(e){return "undefined"!=typeof ArrayBuffer&&(C.working?C(e):e instanceof ArrayBuffer)}function G(e){return "[object DataView]"===m(e)}function R(e){return "undefined"!=typeof DataView&&(G.working?G(e):e instanceof DataView)}function J(e){return "[object SharedArrayBuffer]"===m(e)}function _(e){return "undefined"!=typeof SharedArrayBuffer&&(J.working?J(e):e instanceof SharedArrayBuffer)}function H(e){return O(e,h)}function Z(e){return O(e,j)}function q(e){return O(e,A)}function K(e){return s&&O(e,w)}function L(e){return p&&O(e,v)}o$2.isArgumentsObject=f,o$2.isGeneratorFunction=a,o$2.isPromise=function(e){return "undefined"!=typeof Promise&&e instanceof Promise||null!==e&&"object"==typeof e&&"function"==typeof e.then&&"function"==typeof e.catch},o$2.isArrayBufferView=function(e){return d&&ArrayBuffer.isView?ArrayBuffer.isView(e):S(e)||R(e)},o$2.isTypedArray=S,o$2.isUint8Array=B,o$2.isUint8ClampedArray=k,o$2.isUint16Array=E,o$2.isUint32Array=D,o$2.isInt8Array=U,o$2.isInt16Array=P,o$2.isInt32Array=x,o$2.isFloat32Array=I,o$2.isFloat64Array=M,o$2.isBigInt64Array=z,o$2.isBigUint64Array=F,T.working="undefined"!=typeof Map&&T(new Map),o$2.isMap=function(e){return "undefined"!=typeof Map&&(T.working?T(e):e instanceof Map)},N.working="undefined"!=typeof Set&&N(new Set),o$2.isSet=function(e){return "undefined"!=typeof Set&&(N.working?N(e):e instanceof Set)},W.working="undefined"!=typeof WeakMap&&W(new WeakMap),o$2.isWeakMap=function(e){return "undefined"!=typeof WeakMap&&(W.working?W(e):e instanceof WeakMap)},$.working="undefined"!=typeof WeakSet&&$(new WeakSet),o$2.isWeakSet=function(e){return $(e)},C.working="undefined"!=typeof ArrayBuffer&&C(new ArrayBuffer),o$2.isArrayBuffer=V,G.working="undefined"!=typeof ArrayBuffer&&"undefined"!=typeof DataView&&G(new DataView(new ArrayBuffer(1),0,1)),o$2.isDataView=R,J.working="undefined"!=typeof SharedArrayBuffer&&J(new SharedArrayBuffer),o$2.isSharedArrayBuffer=_,o$2.isAsyncFunction=function(e){return "[object AsyncFunction]"===m(e)},o$2.isMapIterator=function(e){return "[object Map Iterator]"===m(e)},o$2.isSetIterator=function(e){return "[object Set Iterator]"===m(e)},o$2.isGeneratorObject=function(e){return "[object Generator]"===m(e)},o$2.isWebAssemblyCompiledModule=function(e){return "[object WebAssembly.Module]"===m(e)},o$2.isNumberObject=H,o$2.isStringObject=Z,o$2.isBooleanObject=q,o$2.isBigIntObject=K,o$2.isSymbolObject=L,o$2.isBoxedPrimitive=function(e){return H(e)||Z(e)||q(e)||K(e)||L(e)},o$2.isAnyArrayBuffer=function(e){return l$1&&(V(e)||_(e))},["isProxy","isExternal","isModuleNamespaceObject"].forEach((function(e){Object.defineProperty(o$2,e,{enumerable:!1,value:function(){throw new Error(e+" is not supported in userland")}});}));var Q="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,X={},Y=T$1,ee=Object.getOwnPropertyDescriptors||function(e){for(var t=Object.keys(e),r={},n=0;n=i)return e;switch(e){case"%s":return String(n[r++]);case"%d":return Number(n[r++]);case"%j":try{return JSON.stringify(n[r++])}catch(e){return "[Circular]"}default:return e}})),u=n[r];r=3&&(r.depth=arguments[2]),arguments.length>=4&&(r.colors=arguments[3]),ye(t)?r.showHidden=t:t&&X._extend(r,t),be(r.showHidden)&&(r.showHidden=!1),be(r.depth)&&(r.depth=2),be(r.colors)&&(r.colors=!1),be(r.customInspect)&&(r.customInspect=!0),r.colors&&(r.stylize=ue),ae(r,e,r.depth)}function ue(e,t){var r=oe.styles[t];return r?"["+oe.colors[r][0]+"m"+e+"["+oe.colors[r][1]+"m":e}function fe(e,t){return e}function ae(e,t,r){if(e.customInspect&&t&&we(t.inspect)&&t.inspect!==X.inspect&&(!t.constructor||t.constructor.prototype!==t)){var n=t.inspect(r,e);return ge(n)||(n=ae(e,n,r)),n}var i=function(e,t){if(be(t))return e.stylize("undefined","undefined");if(ge(t)){var r="'"+JSON.stringify(t).replace(/^"|"$/g,"").replace(/'/g,"\\'").replace(/\\"/g,'"')+"'";return e.stylize(r,"string")}if(de(t))return e.stylize(""+t,"number");if(ye(t))return e.stylize(""+t,"boolean");if(le(t))return e.stylize("null","null")}(e,t);if(i)return i;var o=Object.keys(t),u=function(e){var t={};return e.forEach((function(e,r){t[e]=!0;})),t}(o);if(e.showHidden&&(o=Object.getOwnPropertyNames(t)),Ae(t)&&(o.indexOf("message")>=0||o.indexOf("description")>=0))return ce(t);if(0===o.length){if(we(t)){var f=t.name?": "+t.name:"";return e.stylize("[Function"+f+"]","special")}if(me(t))return e.stylize(RegExp.prototype.toString.call(t),"regexp");if(je(t))return e.stylize(Date.prototype.toString.call(t),"date");if(Ae(t))return ce(t)}var a,c="",s=!1,p=["{","}"];(pe(t)&&(s=!0,p=["[","]"]),we(t))&&(c=" [Function"+(t.name?": "+t.name:"")+"]");return me(t)&&(c=" "+RegExp.prototype.toString.call(t)),je(t)&&(c=" "+Date.prototype.toUTCString.call(t)),Ae(t)&&(c=" "+ce(t)),0!==o.length||s&&0!=t.length?r<0?me(t)?e.stylize(RegExp.prototype.toString.call(t),"regexp"):e.stylize("[Object]","special"):(e.seen.push(t),a=s?function(e,t,r,n,i){for(var o=[],u=0,f=t.length;u=0&&n++,e+t.replace(/\u001b\[\d\d?m/g,"").length+1}),0)>60)return r[0]+(""===t?"":t+"\n ")+" "+e.join(",\n ")+" "+r[1];return r[0]+t+" "+e.join(", ")+" "+r[1]}(a,c,p)):p[0]+c+p[1]}function ce(e){return "["+Error.prototype.toString.call(e)+"]"}function se(e,t,r,n,i,o){var u,f,a;if((a=Object.getOwnPropertyDescriptor(t,i)||{value:t[i]}).get?f=a.set?e.stylize("[Getter/Setter]","special"):e.stylize("[Getter]","special"):a.set&&(f=e.stylize("[Setter]","special")),ke(n,i)||(u="["+i+"]"),f||(e.seen.indexOf(a.value)<0?(f=le(r)?ae(e,a.value,null):ae(e,a.value,r-1)).indexOf("\n")>-1&&(f=o?f.split("\n").map((function(e){return " "+e})).join("\n").substr(2):"\n"+f.split("\n").map((function(e){return " "+e})).join("\n")):f=e.stylize("[Circular]","special")),be(u)){if(o&&i.match(/^\d+$/))return f;(u=JSON.stringify(""+i)).match(/^"([a-zA-Z_][a-zA-Z_0-9]*)"$/)?(u=u.substr(1,u.length-2),u=e.stylize(u,"name")):(u=u.replace(/'/g,"\\'").replace(/\\"/g,'"').replace(/(^"|"$)/g,"'"),u=e.stylize(u,"string"));}return u+": "+f}function pe(e){return Array.isArray(e)}function ye(e){return "boolean"==typeof e}function le(e){return null===e}function de(e){return "number"==typeof e}function ge(e){return "string"==typeof e}function be(e){return void 0===e}function me(e){return he(e)&&"[object RegExp]"===ve(e)}function he(e){return "object"==typeof e&&null!==e}function je(e){return he(e)&&"[object Date]"===ve(e)}function Ae(e){return he(e)&&("[object Error]"===ve(e)||e instanceof Error)}function we(e){return "function"==typeof e}function ve(e){return Object.prototype.toString.call(e)}function Oe(e){return e<10?"0"+e.toString(10):e.toString(10)}X.debuglog=function(e){if(e=e.toUpperCase(),!re[e])if(ne.test(e)){var t=Y.pid;re[e]=function(){var r=X.format.apply(X,arguments);console.error("%s %d: %s",e,t,r);};}else re[e]=function(){};return re[e]},X.inspect=oe,oe.colors={bold:[1,22],italic:[3,23],underline:[4,24],inverse:[7,27],white:[37,39],grey:[90,39],black:[30,39],blue:[34,39],cyan:[36,39],green:[32,39],magenta:[35,39],red:[31,39],yellow:[33,39]},oe.styles={special:"cyan",number:"yellow",boolean:"yellow",undefined:"grey",null:"bold",string:"green",date:"magenta",regexp:"red"},X.types=o$2,X.isArray=pe,X.isBoolean=ye,X.isNull=le,X.isNullOrUndefined=function(e){return null==e},X.isNumber=de,X.isString=ge,X.isSymbol=function(e){return "symbol"==typeof e},X.isUndefined=be,X.isRegExp=me,X.types.isRegExp=me,X.isObject=he,X.isDate=je,X.types.isDate=je,X.isError=Ae,X.types.isNativeError=Ae,X.isFunction=we,X.isPrimitive=function(e){return null===e||"boolean"==typeof e||"number"==typeof e||"string"==typeof e||"symbol"==typeof e||void 0===e},X.isBuffer=i$1;var Se=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"];function Be(){var e=new Date,t=[Oe(e.getHours()),Oe(e.getMinutes()),Oe(e.getSeconds())].join(":");return [e.getDate(),Se[e.getMonth()],t].join(" ")}function ke(e,t){return Object.prototype.hasOwnProperty.call(e,t)}X.log=function(){console.log("%s - %s",Be(),X.format.apply(X,arguments));},X.inherits=t$2,X._extend=function(e,t){if(!t||!he(t))return e;for(var r=Object.keys(t),n=r.length;n--;)e[r[n]]=t[r[n]];return e};var Ee="undefined"!=typeof Symbol?Symbol("util.promisify.custom"):void 0;function De(e,t){if(!e){var r=new Error("Promise was rejected with a falsy value");r.reason=e,e=r;}return t(e)}X.promisify=function(e){if("function"!=typeof e)throw new TypeError('The "original" argument must be of type Function');if(Ee&&e[Ee]){var t;if("function"!=typeof(t=e[Ee]))throw new TypeError('The "util.promisify.custom" argument must be of type Function');return Object.defineProperty(t,Ee,{value:t,enumerable:!1,writable:!1,configurable:!0}),t}function t(){for(var t,r,n=new Promise((function(e,n){t=e,r=n;})),i=[],o=0;o0&&i>c&&(i=c);for(var s=0;s=0?(p=m.substr(0,l),f=m.substr(l+1)):(p=m,f=""),d=decodeURIComponent(p),y=decodeURIComponent(f),e(a,d)?Array.isArray(a[d])?a[d].push(y):a[d]=[a[d],y]:a[d]=y;}return a},r=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return ""}},t=function(e,n,t,o){return n=n||"&",t=t||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map((function(o){var a=encodeURIComponent(r(o))+t;return Array.isArray(e[o])?e[o].map((function(e){return a+encodeURIComponent(r(e))})).join(n):a+encodeURIComponent(r(e[o]))})).join(n):o?encodeURIComponent(r(o))+t+encodeURIComponent(r(e)):""},o={};o.decode=o.parse=n,o.encode=o.stringify=t;o.decode;o.encode;o.parse;o.stringify; - -export { o }; diff --git a/nodelibs/browser/chunk-DEMDiNwt.js b/nodelibs/browser/chunk-DEMDiNwt.js new file mode 100644 index 0000000..26d6970 --- /dev/null +++ b/nodelibs/browser/chunk-DEMDiNwt.js @@ -0,0 +1,275 @@ +function unimplemented(name) { + throw new Error('Node.js process ' + name + ' is not supported by JSPM core outside of Node.js'); +} + +var queue = []; +var draining = false; +var currentQueue; +var queueIndex = -1; + +function cleanUpNextTick() { + if (!draining || !currentQueue) + return; + draining = false; + if (currentQueue.length) { + queue = currentQueue.concat(queue); + } + else { + queueIndex = -1; + } + if (queue.length) + drainQueue(); +} + +function drainQueue() { + if (draining) + return; + var timeout = setTimeout(cleanUpNextTick, 0); + draining = true; + + var len = queue.length; + while(len) { + currentQueue = queue; + queue = []; + while (++queueIndex < len) { + if (currentQueue) + currentQueue[queueIndex].run(); + } + queueIndex = -1; + len = queue.length; + } + currentQueue = null; + draining = false; + clearTimeout(timeout); +} + +function nextTick (fun) { + var args = new Array(arguments.length - 1); + if (arguments.length > 1) { + for (var i = 1; i < arguments.length; i++) + args[i - 1] = arguments[i]; + } + queue.push(new Item(fun, args)); + if (queue.length === 1 && !draining) + setTimeout(drainQueue, 0); +} +// v8 likes predictible objects +function Item(fun, array) { + this.fun = fun; + this.array = array; +} +Item.prototype.run = function () { + this.fun.apply(null, this.array); +}; + +var title = 'browser'; +var arch = 'x64'; +var platform = 'browser'; +var env = { + PATH: '/usr/bin', + LANG: navigator.language + '.UTF-8', + PWD: '/', + HOME: '/home', + TMP: '/tmp', +}; +var argv = ['/usr/bin/node']; +var execArgv = []; +var version = 'v16.8.0'; +var versions = {}; + +var emitWarning = function(message, type) { + console.warn((type ? (type + ': ') : '') + message); +}; + +var binding = function(name) { unimplemented('binding'); }; + +var umask = function(mask) { return 0; }; + +var cwd = function() { return '/'; }; +var chdir = function(dir) {}; + +var release = { + name: 'node', + sourceUrl: '', + headersUrl: '', + libUrl: '', +}; + +function noop() {} + +var _rawDebug = noop; +var moduleLoadList = []; +function _linkedBinding(name) { unimplemented('_linkedBinding'); } +var domain = {}; +var _exiting = false; +var config = {}; +function dlopen(name) { unimplemented('dlopen'); } +function _getActiveRequests() { return []; } +function _getActiveHandles() { return []; } +var reallyExit = noop; +var _kill = noop; +var cpuUsage = function() { return {}; }; +var resourceUsage = cpuUsage; +var memoryUsage = cpuUsage; +var kill = noop; +var exit = noop; +var openStdin = noop; +var allowedNodeEnvironmentFlags = {}; +function assert(condition, message) { + if (!condition) throw new Error(message || 'assertion error'); +} +var features = { + inspector: false, + debug: false, + uv: false, + ipv6: false, + tls_alpn: false, + tls_sni: false, + tls_ocsp: false, + tls: false, + cached_builtins: true, +}; +var _fatalExceptions = noop; +var setUncaughtExceptionCaptureCallback = noop; +function hasUncaughtExceptionCaptureCallback() { return false; }var _tickCallback = noop; +var _debugProcess = noop; +var _debugEnd = noop; +var _startProfilerIdleNotifier = noop; +var _stopProfilerIdleNotifier = noop; +var stdout = undefined; +var stderr = undefined; +var stdin = undefined; +var abort = noop; +var pid = 2; +var ppid = 1; +var execPath = '/bin/usr/node'; +var debugPort = 9229; +var argv0 = 'node'; +var _preload_modules = []; +var setSourceMapsEnabled = noop; + +var _performance = { + now: typeof performance !== 'undefined' ? performance.now.bind(performance) : undefined, + timing: typeof performance !== 'undefined' ? performance.timing : undefined, +}; +if (_performance.now === undefined) { + var nowOffset = Date.now(); + + if (_performance.timing && _performance.timing.navigationStart) { + nowOffset = _performance.timing.navigationStart; + } + _performance.now = () => Date.now() - nowOffset; +} + +function uptime() { + return _performance.now() / 1000; +} + +var nanoPerSec = 1000000000; +function hrtime(previousTimestamp) { + var baseNow = Math.floor((Date.now() - _performance.now()) * 1e-3); + var clocktime = _performance.now() * 1e-3; + var seconds = Math.floor(clocktime) + baseNow; + var nanoseconds = Math.floor((clocktime % 1) * 1e9); + if (previousTimestamp) { + seconds = seconds - previousTimestamp[0]; + nanoseconds = nanoseconds - previousTimestamp[1]; + if (nanoseconds < 0) { + seconds--; + nanoseconds += nanoPerSec; + } + } + return [seconds, nanoseconds]; +}hrtime.bigint = function(time) { + var diff = hrtime(time); + if (typeof BigInt === 'undefined') { + return diff[0] * nanoPerSec + diff[1]; + } + return BigInt(diff[0] * nanoPerSec) + BigInt(diff[1]); +}; + +var _maxListeners = 10; +var _events = {}; +var _eventsCount = 0; +function on () { return process }var addListener = on; +var once = on; +var off = on; +var removeListener = on; +var removeAllListeners = on; +var emit = noop; +var prependListener = on; +var prependOnceListener = on; +function listeners (name) { return []; } +var process = { + version, + versions, + arch, + platform, + release, + _rawDebug, + moduleLoadList, + binding, + _linkedBinding, + _events, + _eventsCount, + _maxListeners, + on, + addListener, + once, + off, + removeListener, + removeAllListeners, + emit, + prependListener, + prependOnceListener, + listeners, + domain, + _exiting, + config, + dlopen, + uptime, + _getActiveRequests, + _getActiveHandles, + reallyExit, + _kill, + cpuUsage, + resourceUsage, + memoryUsage, + kill, + exit, + openStdin, + allowedNodeEnvironmentFlags, + assert, + features, + _fatalExceptions, + setUncaughtExceptionCaptureCallback, + hasUncaughtExceptionCaptureCallback, + emitWarning, + nextTick, + _tickCallback, + _debugProcess, + _debugEnd, + _startProfilerIdleNotifier, + _stopProfilerIdleNotifier, + stdout, + stdin, + stderr, + abort, + umask, + chdir, + cwd, + env, + title, + argv, + execArgv, + pid, + ppid, + execPath, + debugPort, + hrtime, + argv0, + _preload_modules, + setSourceMapsEnabled, +}; + +export { process as p }; diff --git a/nodelibs/browser/chunk-DEckhzyo.js b/nodelibs/browser/chunk-DEckhzyo.js deleted file mode 100644 index f4f00a6..0000000 --- a/nodelibs/browser/chunk-DEckhzyo.js +++ /dev/null @@ -1,3 +0,0 @@ -var e,t,n,r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,o=e={};function i(){throw new Error("setTimeout has not been defined")}function u(){throw new Error("clearTimeout has not been defined")}function c(e){if(t===setTimeout)return setTimeout(e,0);if((t===i||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this||r,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:i;}catch(e){t=i;}try{n="function"==typeof clearTimeout?clearTimeout:u;}catch(e){n=u;}}();var l,s=[],f=!1,a=-1;function h(){f&&l&&(f=!1,l.length?s=l.concat(s):a=-1,s.length&&d());}function d(){if(!f){var e=c(h);f=!0;for(var t=s.length;t;){for(l=s,s=[];++a1)for(var n=1;n 2) { + var lastSlashIndex = res.lastIndexOf("/"); + + if (lastSlashIndex !== res.length - 1) { + if (lastSlashIndex === -1) { + res = ""; + lastSegmentLength = 0; + } else { + res = res.slice(0, lastSlashIndex); + lastSegmentLength = res.length - 1 - res.lastIndexOf("/"); + } + + lastSlash = i; + dots = 0; + continue; + } + } else if (res.length === 2 || res.length === 1) { + res = ""; + lastSegmentLength = 0; + lastSlash = i; + dots = 0; + continue; + } + } + + if (allowAboveRoot) { + if (res.length > 0) res += "/..";else res = ".."; + lastSegmentLength = 2; + } + } else { + if (res.length > 0) res += "/" + path.slice(lastSlash + 1, i);else res = path.slice(lastSlash + 1, i); + lastSegmentLength = i - lastSlash - 1; + } + + lastSlash = i; + dots = 0; + } else if (code === 46 + /*.*/ + && dots !== -1) { + ++dots; + } else { + dots = -1; + } + } + + return res; + } + + function _format(sep, pathObject) { + var dir = pathObject.dir || pathObject.root; + var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); + + if (!dir) { + return base; + } + + if (dir === pathObject.root) { + return dir + base; + } + + return dir + sep + base; + } + + var posix = { + // path.resolve([from ...], to) + resolve: function resolve() { + var resolvedPath = ""; + var resolvedAbsolute = false; + var cwd; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path; + if (i >= 0) path = arguments[i];else { + if (cwd === undefined) cwd = process$1.cwd(); + path = cwd; + } + assertPath(path); // Skip empty entries + + if (path.length === 0) { + continue; + } + + resolvedPath = path + "/" + resolvedPath; + resolvedAbsolute = path.charCodeAt(0) === 47 + /*/*/ + ; + } // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) + // Normalize the path + + + resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute); + + if (resolvedAbsolute) { + if (resolvedPath.length > 0) return "/" + resolvedPath;else return "/"; + } else if (resolvedPath.length > 0) { + return resolvedPath; + } else { + return "."; + } + }, + normalize: function normalize(path) { + assertPath(path); + if (path.length === 0) return "."; + var isAbsolute = path.charCodeAt(0) === 47 + /*/*/ + ; + var trailingSeparator = path.charCodeAt(path.length - 1) === 47 + /*/*/ + ; // Normalize the path + + path = normalizeStringPosix(path, !isAbsolute); + if (path.length === 0 && !isAbsolute) path = "."; + if (path.length > 0 && trailingSeparator) path += "/"; + if (isAbsolute) return "/" + path; + return path; + }, + isAbsolute: function isAbsolute(path) { + assertPath(path); + return path.length > 0 && path.charCodeAt(0) === 47 + /*/*/ + ; + }, + join: function join() { + if (arguments.length === 0) return "."; + var joined; + + for (var i = 0; i < arguments.length; ++i) { + var arg = arguments[i]; + assertPath(arg); + + if (arg.length > 0) { + if (joined === undefined) joined = arg;else joined += "/" + arg; + } + } + + if (joined === undefined) return "."; + return posix.normalize(joined); + }, + relative: function relative(from, to) { + assertPath(from); + assertPath(to); + if (from === to) return ""; + from = posix.resolve(from); + to = posix.resolve(to); + if (from === to) return ""; // Trim any leading backslashes + + var fromStart = 1; + + for (; fromStart < from.length; ++fromStart) { + if (from.charCodeAt(fromStart) !== 47 + /*/*/ + ) break; + } + + var fromEnd = from.length; + var fromLen = fromEnd - fromStart; // Trim any leading backslashes + + var toStart = 1; + + for (; toStart < to.length; ++toStart) { + if (to.charCodeAt(toStart) !== 47 + /*/*/ + ) break; + } + + var toEnd = to.length; + var toLen = toEnd - toStart; // Compare paths to find the longest common path from root + + var length = fromLen < toLen ? fromLen : toLen; + var lastCommonSep = -1; + var i = 0; + + for (; i <= length; ++i) { + if (i === length) { + if (toLen > length) { + if (to.charCodeAt(toStart + i) === 47 + /*/*/ + ) { + // We get here if `from` is the exact base path for `to`. + // For example: from='/foo/bar'; to='/foo/bar/baz' + return to.slice(toStart + i + 1); + } else if (i === 0) { + // We get here if `from` is the root + // For example: from='/'; to='/foo' + return to.slice(toStart + i); + } + } else if (fromLen > length) { + if (from.charCodeAt(fromStart + i) === 47 + /*/*/ + ) { + // We get here if `to` is the exact base path for `from`. + // For example: from='/foo/bar/baz'; to='/foo/bar' + lastCommonSep = i; + } else if (i === 0) { + // We get here if `to` is the root. + // For example: from='/foo'; to='/' + lastCommonSep = 0; + } + } + + break; + } + + var fromCode = from.charCodeAt(fromStart + i); + var toCode = to.charCodeAt(toStart + i); + if (fromCode !== toCode) break;else if (fromCode === 47 + /*/*/ + ) lastCommonSep = i; + } + + var out = ""; // Generate the relative path based on the path difference between `to` + // and `from` + + for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { + if (i === fromEnd || from.charCodeAt(i) === 47 + /*/*/ + ) { + if (out.length === 0) out += "..";else out += "/.."; + } + } // Lastly, append the rest of the destination (`to`) path that comes after + // the common path parts + + + if (out.length > 0) return out + to.slice(toStart + lastCommonSep);else { + toStart += lastCommonSep; + if (to.charCodeAt(toStart) === 47 + /*/*/ + ) ++toStart; + return to.slice(toStart); + } + }, + _makeLong: function _makeLong(path) { + return path; + }, + dirname: function dirname(path) { + assertPath(path); + if (path.length === 0) return "."; + var code = path.charCodeAt(0); + var hasRoot = code === 47 + /*/*/ + ; + var end = -1; + var matchedSlash = true; + + for (var i = path.length - 1; i >= 1; --i) { + code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + if (!matchedSlash) { + end = i; + break; + } + } else { + // We saw the first non-path separator + matchedSlash = false; + } + } + + if (end === -1) return hasRoot ? "/" : "."; + if (hasRoot && end === 1) return "//"; + return path.slice(0, end); + }, + basename: function basename(path, ext) { + if (ext !== undefined && typeof ext !== "string") throw new TypeError("\"ext\" argument must be a string"); + assertPath(path); + var start = 0; + var end = -1; + var matchedSlash = true; + var i; + + if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { + if (ext.length === path.length && ext === path) return ""; + var extIdx = ext.length - 1; + var firstNonSlashEnd = -1; + + for (i = path.length - 1; i >= 0; --i) { + var code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + start = i + 1; + break; + } + } else { + if (firstNonSlashEnd === -1) { + // We saw the first non-path separator, remember this index in case + // we need it if the extension ends up not matching + matchedSlash = false; + firstNonSlashEnd = i + 1; + } + + if (extIdx >= 0) { + // Try to match the explicit extension + if (code === ext.charCodeAt(extIdx)) { + if (--extIdx === -1) { + // We matched the extension, so mark this as the end of our path + // component + end = i; + } + } else { + // Extension does not match, so our result is the entire path + // component + extIdx = -1; + end = firstNonSlashEnd; + } + } + } + } + + if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length; + return path.slice(start, end); + } else { + for (i = path.length - 1; i >= 0; --i) { + if (path.charCodeAt(i) === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // path component + matchedSlash = false; + end = i + 1; + } + } + + if (end === -1) return ""; + return path.slice(start, end); + } + }, + extname: function extname(path) { + assertPath(path); + var startDot = -1; + var startPart = 0; + var end = -1; + var matchedSlash = true; // Track the state of characters (if any) we see before our first dot and + // after any path separator we find + + var preDotState = 0; + + for (var i = path.length - 1; i >= 0; --i) { + var code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + startPart = i + 1; + break; + } + + continue; + } + + if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // extension + matchedSlash = false; + end = i + 1; + } + + if (code === 46 + /*.*/ + ) { + // If this is our first dot, mark it as the start of our extension + if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1; + } else if (startDot !== -1) { + // We saw a non-dot and non-path separator before our dot, so we should + // have a good chance at having a non-empty extension + preDotState = -1; + } + } + + if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot + preDotState === 0 || // The (right-most) trimmed path component is exactly '..' + preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ""; + } + + return path.slice(startDot, end); + }, + format: function format(pathObject) { + if (pathObject === null || typeof pathObject !== "object") { + throw new TypeError("The \"pathObject\" argument must be of type Object. Received type " + typeof pathObject); + } + + return _format("/", pathObject); + }, + parse: function parse(path) { + assertPath(path); + var ret = { + root: "", + dir: "", + base: "", + ext: "", + name: "" + }; + if (path.length === 0) return ret; + var code = path.charCodeAt(0); + var isAbsolute = code === 47 + /*/*/ + ; + var start; + + if (isAbsolute) { + ret.root = "/"; + start = 1; + } else { + start = 0; + } + + var startDot = -1; + var startPart = 0; + var end = -1; + var matchedSlash = true; + var i = path.length - 1; // Track the state of characters (if any) we see before our first dot and + // after any path separator we find + + var preDotState = 0; // Get non-dir info + + for (; i >= start; --i) { + code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + startPart = i + 1; + break; + } + + continue; + } + + if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // extension + matchedSlash = false; + end = i + 1; + } + + if (code === 46 + /*.*/ + ) { + // If this is our first dot, mark it as the start of our extension + if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1; + } else if (startDot !== -1) { + // We saw a non-dot and non-path separator before our dot, so we should + // have a good chance at having a non-empty extension + preDotState = -1; + } + } + + if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot + preDotState === 0 || // The (right-most) trimmed path component is exactly '..' + preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if (end !== -1) { + if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end); + } + } else { + if (startPart === 0 && isAbsolute) { + ret.name = path.slice(1, startDot); + ret.base = path.slice(1, end); + } else { + ret.name = path.slice(startPart, startDot); + ret.base = path.slice(startPart, end); + } + + ret.ext = path.slice(startDot, end); + } + + if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = "/"; + return ret; + }, + sep: "/", + delimiter: ":", + win32: null, + posix: null + }; + posix.posix = posix; + exports$1 = posix; + return exports$1; +} + +const exports$2 = dew$1(); + +const t$1=2147483647,o$2=/^xn--/,n$2=/[^\0-\x7E]/,e$2=/[\x2E\u3002\uFF0E\uFF61]/g,r$2={overflow:"Overflow: input needs wider integers to process","not-basic":"Illegal input >= 0x80 (not a basic code point)","invalid-input":"Invalid input"},c$1=Math.floor,s=String.fromCharCode;function i$1(t){throw new RangeError(r$2[t])}function f$1(t,o){const n=t.split("@");let r="";n.length>1&&(r=n[0]+"@",t=n[1]);const c=function(t,o){const n=[];let e=t.length;for(;e--;)n[e]=o(t[e]);return n}((t=t.replace(e$2,".")).split("."),o).join(".");return r+c}function l$1(t){const o=[];let n=0;const e=t.length;for(;n=55296&&r<=56319&&n>1,t+=c$1(t/o);t>455;e+=36)t=c$1(t/35);return c$1(e+36*t/(t+38))},d=function(o){const n=[],e=o.length;let r=0,s=128,f=72,l=o.lastIndexOf("-");l<0&&(l=0);for(let t=0;t=128&&i$1("not-basic"),n.push(o.charCodeAt(t));for(let d=l>0?l+1:0;d=e&&i$1("invalid-input");const l=(u=o.charCodeAt(d++))-48<10?u-22:u-65<26?u-65:u-97<26?u-97:36;(l>=36||l>c$1((t$1-r)/n))&&i$1("overflow"),r+=l*n;const a=s<=f?1:s>=f+26?26:s-f;if(lc$1(t$1/h)&&i$1("overflow"),n*=h;}const h=n.length+1;f=a$1(r-l,h,0==l),c$1(r/h)>t$1-s&&i$1("overflow"),s+=c$1(r/h),r%=h,n.splice(r++,0,s);}var u;return String.fromCodePoint(...n)},h$1=function(o){const n=[];let e=(o=l$1(o)).length,r=128,f=0,d=72;for(const t of o)t<128&&n.push(s(t));let h=n.length,p=h;for(h&&n.push("-");p=r&&tc$1((t$1-f)/l)&&i$1("overflow"),f+=(e-r)*l,r=e;for(const e of o)if(et$1&&i$1("overflow"),e==r){let t=f;for(let o=36;;o+=36){const e=o<=d?1:o>=d+26?26:o-d;if(tString.fromCodePoint(...t)},decode:d,encode:h$1,toASCII:function(t){return f$1(t,(function(t){return n$2.test(t)?"xn--"+h$1(t):t}))},toUnicode:function(t){return f$1(t,(function(t){return o$2.test(t)?d(t.slice(4).toLowerCase()):t}))}}; + +function e$1(e,n){return Object.prototype.hasOwnProperty.call(e,n)}var n$1=function(n,r,t,o){r=r||"&",t=t||"=";var a={};if("string"!=typeof n||0===n.length)return a;var u=/\+/g;n=n.split(r);var c=1e3;o&&"number"==typeof o.maxKeys&&(c=o.maxKeys);var i=n.length;c>0&&i>c&&(i=c);for(var s=0;s=0?(p=m.substr(0,l),f=m.substr(l+1)):(p=m,f=""),d=decodeURIComponent(p),y=decodeURIComponent(f),e$1(a,d)?Array.isArray(a[d])?a[d].push(y):a[d]=[a[d],y]:a[d]=y;}return a},r$1=function(e){switch(typeof e){case"string":return e;case"boolean":return e?"true":"false";case"number":return isFinite(e)?e:"";default:return ""}},t=function(e,n,t,o){return n=n||"&",t=t||"=",null===e&&(e=void 0),"object"==typeof e?Object.keys(e).map((function(o){var a=encodeURIComponent(r$1(o))+t;return Array.isArray(e[o])?e[o].map((function(e){return a+encodeURIComponent(r$1(e))})).join(n):a+encodeURIComponent(r$1(e[o]))})).join(n):o?encodeURIComponent(r$1(o))+t+encodeURIComponent(r$1(e)):""},o$1={};o$1.decode=o$1.parse=n$1,o$1.encode=o$1.stringify=t;o$1.decode;o$1.encode;o$1.parse;o$1.stringify; + +var h={},e=p$1,a={isString:function(t){return "string"==typeof t},isObject:function(t){return "object"==typeof t&&null!==t},isNull:function(t){return null===t},isNullOrUndefined:function(t){return null==t}};function r(){this.protocol=null,this.slashes=null,this.auth=null,this.host=null,this.port=null,this.hostname=null,this.hash=null,this.search=null,this.query=null,this.pathname=null,this.path=null,this.href=null;}h.parse=O,h.resolve=function(t,s){return O(t,!1,!0).resolve(s)},h.resolveObject=function(t,s){return t?O(t,!1,!0).resolveObject(s):s},h.format=function(t){a.isString(t)&&(t=O(t));return t instanceof r?t.format():r.prototype.format.call(t)},h.Url=r;var o=/^([a-z0-9.+-]+:)/i,n=/:[0-9]*$/,i=/^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/,l=["{","}","|","\\","^","`"].concat(["<",">",'"',"`"," ","\r","\n","\t"]),p=["'"].concat(l),c=["%","/","?",";","#"].concat(p),u=["/","?","#"],f=/^[+a-z0-9A-Z_-]{0,63}$/,m=/^([+a-z0-9A-Z_-]{0,63})(.*)$/,v={javascript:!0,"javascript:":!0},g={javascript:!0,"javascript:":!0},y={http:!0,https:!0,ftp:!0,gopher:!0,file:!0,"http:":!0,"https:":!0,"ftp:":!0,"gopher:":!0,"file:":!0},b=o$1;function O(t,s,h){if(t&&a.isObject(t)&&t instanceof r)return t;var e=new r;return e.parse(t,s,h),e}r.prototype.parse=function(t,s,h){if(!a.isString(t))throw new TypeError("Parameter 'url' must be a string, not "+typeof t);var r=t.indexOf("?"),n=-1!==r&&r127?$+="x":$+=R[z];if(!$.match(f)){var L=k.slice(0,w),Z=k.slice(w+1),_=R.match(m);_&&(L.push(_[1]),Z.unshift(_[2])),Z.length&&(O="/"+Z.join(".")+O),this.hostname=L.join(".");break}}}this.hostname.length>255?this.hostname="":this.hostname=this.hostname.toLowerCase(),U||(this.hostname=e.toASCII(this.hostname));var E=this.port?":"+this.port:"",P=this.hostname||"";this.host=P+E,this.href+=this.host,U&&(this.hostname=this.hostname.substr(1,this.hostname.length-2),"/"!==O[0]&&(O="/"+O));}if(!v[q])for(w=0,S=p.length;w0)&&h.host.split("@"))&&(h.auth=U.shift(),h.host=h.hostname=U.shift());return h.search=t.search,h.query=t.query,a.isNull(h.pathname)&&a.isNull(h.search)||(h.path=(h.pathname?h.pathname:"")+(h.search?h.search:"")),h.href=h.format(),h}if(!x.length)return h.pathname=null,h.search?h.path="/"+h.search:h.path=null,h.href=h.format(),h;for(var C=x.slice(-1)[0],I=(h.host||t.host||x.length>1)&&("."===C||".."===C)||""===C,w=0,N=x.length;N>=0;N--)"."===(C=x[N])?x.splice(N,1):".."===C?(x.splice(N,1),w++):w&&(x.splice(N,1),w--);if(!j&&!q)for(;w--;w)x.unshift("..");!j||""===x[0]||x[0]&&"/"===x[0].charAt(0)||x.unshift(""),I&&"/"!==x.join("/").substr(-1)&&x.push("");var U,k=""===x[0]||x[0]&&"/"===x[0].charAt(0);A&&(h.hostname=h.host=k?"":x.length?x.shift():"",(U=!!(h.host&&h.host.indexOf("@")>0)&&h.host.split("@"))&&(h.auth=U.shift(),h.host=h.hostname=U.shift()));return (j=j||h.host&&x.length)&&!k&&x.unshift(""),x.length?h.pathname=x.join("/"):(h.pathname=null,h.path=null),a.isNull(h.pathname)&&a.isNull(h.search)||(h.path=(h.pathname?h.pathname:"")+(h.search?h.search:"")),h.auth=t.auth||h.auth,h.slashes=h.slashes||t.slashes,h.href=h.format(),h},r.prototype.parseHost=function(){var t=this.host,s=n.exec(t);s&&(":"!==(s=s[0])&&(this.port=s.substr(1)),t=t.substr(0,t.length-s.length)),t&&(this.hostname=t);}; +h.Url;h.format;h.resolve;h.resolveObject; + +var exports = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports; + _dewExec = true; + var process = T; + + function assertPath(path) { + if (typeof path !== "string") { + throw new TypeError("Path must be a string. Received " + JSON.stringify(path)); + } + } // Resolves . and .. elements in a path with directory names + + + function normalizeStringPosix(path, allowAboveRoot) { + var res = ""; + var lastSegmentLength = 0; + var lastSlash = -1; + var dots = 0; + var code; + + for (var i = 0; i <= path.length; ++i) { + if (i < path.length) code = path.charCodeAt(i);else if (code === 47 + /*/*/ + ) break;else code = 47 + /*/*/ + ; + + if (code === 47 + /*/*/ + ) { + if (lastSlash === i - 1 || dots === 1) ; else if (lastSlash !== i - 1 && dots === 2) { + if (res.length < 2 || lastSegmentLength !== 2 || res.charCodeAt(res.length - 1) !== 46 + /*.*/ + || res.charCodeAt(res.length - 2) !== 46 + /*.*/ + ) { + if (res.length > 2) { + var lastSlashIndex = res.lastIndexOf("/"); + + if (lastSlashIndex !== res.length - 1) { + if (lastSlashIndex === -1) { + res = ""; + lastSegmentLength = 0; + } else { + res = res.slice(0, lastSlashIndex); + lastSegmentLength = res.length - 1 - res.lastIndexOf("/"); + } + + lastSlash = i; + dots = 0; + continue; + } + } else if (res.length === 2 || res.length === 1) { + res = ""; + lastSegmentLength = 0; + lastSlash = i; + dots = 0; + continue; + } + } + + if (allowAboveRoot) { + if (res.length > 0) res += "/..";else res = ".."; + lastSegmentLength = 2; + } + } else { + if (res.length > 0) res += "/" + path.slice(lastSlash + 1, i);else res = path.slice(lastSlash + 1, i); + lastSegmentLength = i - lastSlash - 1; + } + + lastSlash = i; + dots = 0; + } else if (code === 46 + /*.*/ + && dots !== -1) { + ++dots; + } else { + dots = -1; + } + } + + return res; + } + + function _format(sep, pathObject) { + var dir = pathObject.dir || pathObject.root; + var base = pathObject.base || (pathObject.name || "") + (pathObject.ext || ""); + + if (!dir) { + return base; + } + + if (dir === pathObject.root) { + return dir + base; + } + + return dir + sep + base; + } + + var posix = { + // path.resolve([from ...], to) + resolve: function resolve() { + var resolvedPath = ""; + var resolvedAbsolute = false; + var cwd; + + for (var i = arguments.length - 1; i >= -1 && !resolvedAbsolute; i--) { + var path; + if (i >= 0) path = arguments[i];else { + if (cwd === undefined) cwd = process.cwd(); + path = cwd; + } + assertPath(path); // Skip empty entries + + if (path.length === 0) { + continue; + } + + resolvedPath = path + "/" + resolvedPath; + resolvedAbsolute = path.charCodeAt(0) === 47 + /*/*/ + ; + } // At this point the path should be resolved to a full absolute path, but + // handle relative paths to be safe (might happen when process.cwd() fails) + // Normalize the path + + + resolvedPath = normalizeStringPosix(resolvedPath, !resolvedAbsolute); + + if (resolvedAbsolute) { + if (resolvedPath.length > 0) return "/" + resolvedPath;else return "/"; + } else if (resolvedPath.length > 0) { + return resolvedPath; + } else { + return "."; + } + }, + normalize: function normalize(path) { + assertPath(path); + if (path.length === 0) return "."; + var isAbsolute = path.charCodeAt(0) === 47 + /*/*/ + ; + var trailingSeparator = path.charCodeAt(path.length - 1) === 47 + /*/*/ + ; // Normalize the path + + path = normalizeStringPosix(path, !isAbsolute); + if (path.length === 0 && !isAbsolute) path = "."; + if (path.length > 0 && trailingSeparator) path += "/"; + if (isAbsolute) return "/" + path; + return path; + }, + isAbsolute: function isAbsolute(path) { + assertPath(path); + return path.length > 0 && path.charCodeAt(0) === 47 + /*/*/ + ; + }, + join: function join() { + if (arguments.length === 0) return "."; + var joined; + + for (var i = 0; i < arguments.length; ++i) { + var arg = arguments[i]; + assertPath(arg); + + if (arg.length > 0) { + if (joined === undefined) joined = arg;else joined += "/" + arg; + } + } + + if (joined === undefined) return "."; + return posix.normalize(joined); + }, + relative: function relative(from, to) { + assertPath(from); + assertPath(to); + if (from === to) return ""; + from = posix.resolve(from); + to = posix.resolve(to); + if (from === to) return ""; // Trim any leading backslashes + + var fromStart = 1; + + for (; fromStart < from.length; ++fromStart) { + if (from.charCodeAt(fromStart) !== 47 + /*/*/ + ) break; + } + + var fromEnd = from.length; + var fromLen = fromEnd - fromStart; // Trim any leading backslashes + + var toStart = 1; + + for (; toStart < to.length; ++toStart) { + if (to.charCodeAt(toStart) !== 47 + /*/*/ + ) break; + } + + var toEnd = to.length; + var toLen = toEnd - toStart; // Compare paths to find the longest common path from root + + var length = fromLen < toLen ? fromLen : toLen; + var lastCommonSep = -1; + var i = 0; + + for (; i <= length; ++i) { + if (i === length) { + if (toLen > length) { + if (to.charCodeAt(toStart + i) === 47 + /*/*/ + ) { + // We get here if `from` is the exact base path for `to`. + // For example: from='/foo/bar'; to='/foo/bar/baz' + return to.slice(toStart + i + 1); + } else if (i === 0) { + // We get here if `from` is the root + // For example: from='/'; to='/foo' + return to.slice(toStart + i); + } + } else if (fromLen > length) { + if (from.charCodeAt(fromStart + i) === 47 + /*/*/ + ) { + // We get here if `to` is the exact base path for `from`. + // For example: from='/foo/bar/baz'; to='/foo/bar' + lastCommonSep = i; + } else if (i === 0) { + // We get here if `to` is the root. + // For example: from='/foo'; to='/' + lastCommonSep = 0; + } + } + + break; + } + + var fromCode = from.charCodeAt(fromStart + i); + var toCode = to.charCodeAt(toStart + i); + if (fromCode !== toCode) break;else if (fromCode === 47 + /*/*/ + ) lastCommonSep = i; + } + + var out = ""; // Generate the relative path based on the path difference between `to` + // and `from` + + for (i = fromStart + lastCommonSep + 1; i <= fromEnd; ++i) { + if (i === fromEnd || from.charCodeAt(i) === 47 + /*/*/ + ) { + if (out.length === 0) out += "..";else out += "/.."; + } + } // Lastly, append the rest of the destination (`to`) path that comes after + // the common path parts + + + if (out.length > 0) return out + to.slice(toStart + lastCommonSep);else { + toStart += lastCommonSep; + if (to.charCodeAt(toStart) === 47 + /*/*/ + ) ++toStart; + return to.slice(toStart); + } + }, + _makeLong: function _makeLong(path) { + return path; + }, + dirname: function dirname(path) { + assertPath(path); + if (path.length === 0) return "."; + var code = path.charCodeAt(0); + var hasRoot = code === 47 + /*/*/ + ; + var end = -1; + var matchedSlash = true; + + for (var i = path.length - 1; i >= 1; --i) { + code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + if (!matchedSlash) { + end = i; + break; + } + } else { + // We saw the first non-path separator + matchedSlash = false; + } + } + + if (end === -1) return hasRoot ? "/" : "."; + if (hasRoot && end === 1) return "//"; + return path.slice(0, end); + }, + basename: function basename(path, ext) { + if (ext !== undefined && typeof ext !== "string") throw new TypeError("\"ext\" argument must be a string"); + assertPath(path); + var start = 0; + var end = -1; + var matchedSlash = true; + var i; + + if (ext !== undefined && ext.length > 0 && ext.length <= path.length) { + if (ext.length === path.length && ext === path) return ""; + var extIdx = ext.length - 1; + var firstNonSlashEnd = -1; + + for (i = path.length - 1; i >= 0; --i) { + var code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + start = i + 1; + break; + } + } else { + if (firstNonSlashEnd === -1) { + // We saw the first non-path separator, remember this index in case + // we need it if the extension ends up not matching + matchedSlash = false; + firstNonSlashEnd = i + 1; + } + + if (extIdx >= 0) { + // Try to match the explicit extension + if (code === ext.charCodeAt(extIdx)) { + if (--extIdx === -1) { + // We matched the extension, so mark this as the end of our path + // component + end = i; + } + } else { + // Extension does not match, so our result is the entire path + // component + extIdx = -1; + end = firstNonSlashEnd; + } + } + } + } + + if (start === end) end = firstNonSlashEnd;else if (end === -1) end = path.length; + return path.slice(start, end); + } else { + for (i = path.length - 1; i >= 0; --i) { + if (path.charCodeAt(i) === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + start = i + 1; + break; + } + } else if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // path component + matchedSlash = false; + end = i + 1; + } + } + + if (end === -1) return ""; + return path.slice(start, end); + } + }, + extname: function extname(path) { + assertPath(path); + var startDot = -1; + var startPart = 0; + var end = -1; + var matchedSlash = true; // Track the state of characters (if any) we see before our first dot and + // after any path separator we find + + var preDotState = 0; + + for (var i = path.length - 1; i >= 0; --i) { + var code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + startPart = i + 1; + break; + } + + continue; + } + + if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // extension + matchedSlash = false; + end = i + 1; + } + + if (code === 46 + /*.*/ + ) { + // If this is our first dot, mark it as the start of our extension + if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1; + } else if (startDot !== -1) { + // We saw a non-dot and non-path separator before our dot, so we should + // have a good chance at having a non-empty extension + preDotState = -1; + } + } + + if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot + preDotState === 0 || // The (right-most) trimmed path component is exactly '..' + preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + return ""; + } + + return path.slice(startDot, end); + }, + format: function format(pathObject) { + if (pathObject === null || typeof pathObject !== "object") { + throw new TypeError("The \"pathObject\" argument must be of type Object. Received type " + typeof pathObject); + } + + return _format("/", pathObject); + }, + parse: function parse(path) { + assertPath(path); + var ret = { + root: "", + dir: "", + base: "", + ext: "", + name: "" + }; + if (path.length === 0) return ret; + var code = path.charCodeAt(0); + var isAbsolute = code === 47 + /*/*/ + ; + var start; + + if (isAbsolute) { + ret.root = "/"; + start = 1; + } else { + start = 0; + } + + var startDot = -1; + var startPart = 0; + var end = -1; + var matchedSlash = true; + var i = path.length - 1; // Track the state of characters (if any) we see before our first dot and + // after any path separator we find + + var preDotState = 0; // Get non-dir info + + for (; i >= start; --i) { + code = path.charCodeAt(i); + + if (code === 47 + /*/*/ + ) { + // If we reached a path separator that was not part of a set of path + // separators at the end of the string, stop now + if (!matchedSlash) { + startPart = i + 1; + break; + } + + continue; + } + + if (end === -1) { + // We saw the first non-path separator, mark this as the end of our + // extension + matchedSlash = false; + end = i + 1; + } + + if (code === 46 + /*.*/ + ) { + // If this is our first dot, mark it as the start of our extension + if (startDot === -1) startDot = i;else if (preDotState !== 1) preDotState = 1; + } else if (startDot !== -1) { + // We saw a non-dot and non-path separator before our dot, so we should + // have a good chance at having a non-empty extension + preDotState = -1; + } + } + + if (startDot === -1 || end === -1 || // We saw a non-dot character immediately before the dot + preDotState === 0 || // The (right-most) trimmed path component is exactly '..' + preDotState === 1 && startDot === end - 1 && startDot === startPart + 1) { + if (end !== -1) { + if (startPart === 0 && isAbsolute) ret.base = ret.name = path.slice(1, end);else ret.base = ret.name = path.slice(startPart, end); + } + } else { + if (startPart === 0 && isAbsolute) { + ret.name = path.slice(1, startDot); + ret.base = path.slice(1, end); + } else { + ret.name = path.slice(startPart, startDot); + ret.base = path.slice(startPart, end); + } + + ret.ext = path.slice(startDot, end); + } + + if (startPart > 0) ret.dir = path.slice(0, startPart - 1);else if (isAbsolute) ret.dir = "/"; + return ret; + }, + sep: "/", + delimiter: ":", + win32: null, + posix: null + }; + posix.posix = posix; + exports = posix; + return exports; +} + +var path = dew(); + +// Copyright Joyent, Inc. and other Node contributors. + +const processPlatform$1 = typeof Deno !== 'undefined' ? (Deno.build.os === "windows" ? "win32" : Deno.build.os) : undefined; + +h.URL = typeof URL !== 'undefined' ? URL : null; +h.pathToFileURL = pathToFileURL$1; +h.fileURLToPath = fileURLToPath$1; + +h.Url; +h.format; +h.resolve; +h.resolveObject; + +h.URL; + +const CHAR_BACKWARD_SLASH$1 = 92; +const CHAR_FORWARD_SLASH$1 = 47; +const CHAR_LOWERCASE_A$1 = 97; +const CHAR_LOWERCASE_Z$1 = 122; + +const isWindows$1 = processPlatform$1 === 'win32'; + +const forwardSlashRegEx$1 = /\//g; +const percentRegEx$1 = /%/g; +const backslashRegEx$1 = /\\/g; +const newlineRegEx$1 = /\n/g; +const carriageReturnRegEx$1 = /\r/g; +const tabRegEx$1 = /\t/g; + +/** + * Get fully resolved platform-specific file path from the given URL string/ object + * @param path The file URL string or URL object to convert to a path + */ +function fileURLToPath$1(path) { + if (typeof path === "string") path = new URL(path); + else if (!(path instanceof URL)) { + throw new Deno.errors.InvalidData( + "invalid argument path , must be a string or URL", + ); + } + if (path.protocol !== "file:") { + throw new Deno.errors.InvalidData("invalid url scheme"); + } + return isWindows$1 ? getPathFromURLWin$1(path) : getPathFromURLPosix$1(path); +} + +function getPathFromURLWin$1(url) { + const hostname = url.hostname; + let pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { + if (pathname[n] === "%") { + const third = pathname.codePointAt(n + 2) || 0x20; + if ( + (pathname[n + 1] === "2" && third === 102) || // 2f 2F / + (pathname[n + 1] === "5" && third === 99) + ) { + // 5c 5C \ + throw new Deno.errors.InvalidData( + "must not include encoded \\ or / characters", + ); + } + } + } + + pathname = pathname.replace(forwardSlashRegEx$1, "\\"); + pathname = decodeURIComponent(pathname); + if (hostname !== "") { + //TODO add support for punycode encodings + return `\\\\${hostname}${pathname}`; + } else { + // Otherwise, it's a local path that requires a drive letter + const letter = pathname.codePointAt(1) | 0x20; + const sep = pathname[2]; + if ( + letter < CHAR_LOWERCASE_A$1 || + letter > CHAR_LOWERCASE_Z$1 || // a..z A..Z + sep !== ":" + ) { + throw new Deno.errors.InvalidData("file url path must be absolute"); + } + return pathname.slice(1); + } +} +function getPathFromURLPosix$1(url) { + if (url.hostname !== "") { + throw new Deno.errors.InvalidData("invalid file url hostname"); + } + const pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { + if (pathname[n] === "%") { + const third = pathname.codePointAt(n + 2) || 0x20; + if (pathname[n + 1] === "2" && third === 102) { + throw new Deno.errors.InvalidData( + "must not include encoded / characters", + ); + } + } + } + return decodeURIComponent(pathname); +} + +/** Get fully resolved platform-specific File URL from the given file path */ +function pathToFileURL$1(filepath) { + let resolved = path.resolve(filepath); + // path.resolve strips trailing slashes so we must add them back + const filePathLast = filepath.charCodeAt(filepath.length - 1); + if ( + (filePathLast === CHAR_FORWARD_SLASH$1 || + (isWindows$1 && filePathLast === CHAR_BACKWARD_SLASH$1)) && + resolved[resolved.length - 1] !== path.sep + ) { + resolved += "/"; + } + const outURL = new URL("file://"); + if (resolved.includes("%")) resolved = resolved.replace(percentRegEx$1, "%25"); + // In posix, "/" is a valid character in paths + if (!isWindows$1 && resolved.includes("\\")) { + resolved = resolved.replace(backslashRegEx$1, "%5C"); + } + if (resolved.includes("\n")) resolved = resolved.replace(newlineRegEx$1, "%0A"); + if (resolved.includes("\r")) { + resolved = resolved.replace(carriageReturnRegEx$1, "%0D"); + } + if (resolved.includes("\t")) resolved = resolved.replace(tabRegEx$1, "%09"); + outURL.pathname = resolved; + return outURL; +} + +// Copyright Joyent, Inc. and other Node contributors. + +const processPlatform = typeof Deno !== 'undefined' ? (Deno.build.os === "windows" ? "win32" : Deno.build.os) : undefined; + +h.URL = typeof URL !== 'undefined' ? URL : null; +h.pathToFileURL = pathToFileURL; +h.fileURLToPath = fileURLToPath; + +h.Url; +h.format; +h.resolve; +h.resolveObject; +h.parse; + +h.URL; + +const CHAR_BACKWARD_SLASH = 92; +const CHAR_FORWARD_SLASH = 47; +const CHAR_LOWERCASE_A = 97; +const CHAR_LOWERCASE_Z = 122; + +const isWindows = processPlatform === 'win32'; + +const forwardSlashRegEx = /\//g; +const percentRegEx = /%/g; +const backslashRegEx = /\\/g; +const newlineRegEx = /\n/g; +const carriageReturnRegEx = /\r/g; +const tabRegEx = /\t/g; + +/** + * Get fully resolved platform-specific file path from the given URL string/ object + * @param path The file URL string or URL object to convert to a path + */ +function fileURLToPath(path) { + if (typeof path === "string") path = new URL(path); + else if (!(path instanceof URL)) { + throw new Deno.errors.InvalidData( + "invalid argument path , must be a string or URL", + ); + } + if (path.protocol !== "file:") { + throw new Deno.errors.InvalidData("invalid url scheme"); + } + return isWindows ? getPathFromURLWin(path) : getPathFromURLPosix(path); +} + +function getPathFromURLWin(url) { + const hostname = url.hostname; + let pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { + if (pathname[n] === "%") { + const third = pathname.codePointAt(n + 2) || 0x20; + if ( + (pathname[n + 1] === "2" && third === 102) || // 2f 2F / + (pathname[n + 1] === "5" && third === 99) + ) { + // 5c 5C \ + throw new Deno.errors.InvalidData( + "must not include encoded \\ or / characters", + ); + } + } + } + + pathname = pathname.replace(forwardSlashRegEx, "\\"); + pathname = decodeURIComponent(pathname); + if (hostname !== "") { + //TODO add support for punycode encodings + return `\\\\${hostname}${pathname}`; + } else { + // Otherwise, it's a local path that requires a drive letter + const letter = pathname.codePointAt(1) | 0x20; + const sep = pathname[2]; + if ( + letter < CHAR_LOWERCASE_A || + letter > CHAR_LOWERCASE_Z || // a..z A..Z + sep !== ":" + ) { + throw new Deno.errors.InvalidData("file url path must be absolute"); + } + return pathname.slice(1); + } +} +function getPathFromURLPosix(url) { + if (url.hostname !== "") { + throw new Deno.errors.InvalidData("invalid file url hostname"); + } + const pathname = url.pathname; + for (let n = 0; n < pathname.length; n++) { + if (pathname[n] === "%") { + const third = pathname.codePointAt(n + 2) || 0x20; + if (pathname[n + 1] === "2" && third === 102) { + throw new Deno.errors.InvalidData( + "must not include encoded / characters", + ); + } + } + } + return decodeURIComponent(pathname); +} + +/** Get fully resolved platform-specific File URL from the given file path */ +function pathToFileURL(filepath) { + let resolved = exports$2.resolve(filepath); + // path.resolve strips trailing slashes so we must add them back + const filePathLast = filepath.charCodeAt(filepath.length - 1); + if ( + (filePathLast === CHAR_FORWARD_SLASH || + (isWindows && filePathLast === CHAR_BACKWARD_SLASH)) && + resolved[resolved.length - 1] !== exports$2.sep + ) { + resolved += "/"; + } + const outURL = new URL("file://"); + if (resolved.includes("%")) resolved = resolved.replace(percentRegEx, "%25"); + // In posix, "/" is a valid character in paths + if (!isWindows && resolved.includes("\\")) { + resolved = resolved.replace(backslashRegEx, "%5C"); + } + if (resolved.includes("\n")) resolved = resolved.replace(newlineRegEx, "%0A"); + if (resolved.includes("\r")) { + resolved = resolved.replace(carriageReturnRegEx, "%0D"); + } + if (resolved.includes("\t")) resolved = resolved.replace(tabRegEx, "%09"); + outURL.pathname = resolved; + return outURL; +} + +export { exports$2 as e, h }; diff --git a/nodelibs/browser/chunk-DtDiafJB.js b/nodelibs/browser/chunk-DtDiafJB.js new file mode 100644 index 0000000..8b5cac7 --- /dev/null +++ b/nodelibs/browser/chunk-DtDiafJB.js @@ -0,0 +1,96 @@ +import { y } from './chunk-tHuMsdT0.js'; + +// https://github.com/denoland/deno_std/blob/d005433c709054af87aca54f57a446b4f7966f11/node/events.ts#L501-L638 +y.once = function (emitter, event) { + return new Promise((resolve, reject) => { + function eventListener(...args) { + if (errorListener !== undefined) { + emitter.removeListener('error', errorListener); + } + resolve(args); + } + let errorListener; + if (event !== 'error') { + // deno-lint-ignore no-explicit-any + errorListener = (err) => { + emitter.removeListener(name, eventListener); + reject(err); + }; + + emitter.once('error', errorListener); + } + + emitter.once(event, eventListener); + }); +}; +y.on = function (emitter, event) { + const unconsumedEventValues = []; + const unconsumedPromises = []; + let error = null; + let finished = false; + + const iterator = { + async next() { + const value = unconsumedEventValues.shift(); + if (value) { + return createIterResult(value, false); + } + + if (error) { + const p = Promise.reject(error); + error = null; + return p; + } + + if (finished) { + return createIterResult(undefined, true); + } + + return new Promise((resolve, reject) => unconsumedPromises.push({ resolve, reject })); + }, + async return() { + emitter.removeListener(event, eventHandler); + emitter.removeListener('error', errorHandler); + finished = true; + + for (const promise of unconsumedPromises) { + promise.resolve(createIterResult(undefined, true)); + } + + return createIterResult(undefined, true); + }, + throw(err) { + error = err; + emitter.removeListener(event, eventHandler); + emitter.removeListener('error', errorHandler); + }, + [Symbol.asyncIterator]() { + return this; + }, + }; + + emitter.on(event, eventHandler); + emitter.on('error', errorHandler); + + return iterator; + + function eventHandler(...args) { + const promise = unconsumedPromises.shift(); + if (promise) { + promise.resolve(createIterResult(args, false)); + } else { + unconsumedEventValues.push(args); + } + } + + function errorHandler(err) { + finished = true; + const toError = unconsumedPromises.shift(); + if (toError) { + toError.reject(err); + } else { + error = err; + } + iterator.return(); + } +}; diff --git a/nodelibs/browser/chunk-DtcTpLWz.js b/nodelibs/browser/chunk-DtcTpLWz.js new file mode 100644 index 0000000..8658bb5 --- /dev/null +++ b/nodelibs/browser/chunk-DtcTpLWz.js @@ -0,0 +1,826 @@ +var exports$k = {}, + _dewExec$k = false; +function dew$k() { + if (_dewExec$k) return exports$k; + _dewExec$k = true; + /* eslint complexity: [2, 18], max-statements: [2, 33] */ + exports$k = function hasSymbols() { + if (typeof Symbol !== "function" || typeof Object.getOwnPropertySymbols !== "function") { + return false; + } + if (typeof Symbol.iterator === "symbol") { + return true; + } + var obj = {}; + var sym = Symbol("test"); + var symObj = Object(sym); + if (typeof sym === "string") { + return false; + } + if (Object.prototype.toString.call(sym) !== "[object Symbol]") { + return false; + } + if (Object.prototype.toString.call(symObj) !== "[object Symbol]") { + return false; + } + + // temp disabled per https://github.com/ljharb/object.assign/issues/17 + // if (sym instanceof Symbol) { return false; } + // temp disabled per https://github.com/WebReflection/get-own-property-symbols/issues/4 + // if (!(symObj instanceof Symbol)) { return false; } + + // if (typeof Symbol.prototype.toString !== 'function') { return false; } + // if (String(sym) !== Symbol.prototype.toString.call(sym)) { return false; } + + var symVal = 42; + obj[sym] = symVal; + for (sym in obj) { + return false; + } // eslint-disable-line no-restricted-syntax, no-unreachable-loop + if (typeof Object.keys === "function" && Object.keys(obj).length !== 0) { + return false; + } + if (typeof Object.getOwnPropertyNames === "function" && Object.getOwnPropertyNames(obj).length !== 0) { + return false; + } + var syms = Object.getOwnPropertySymbols(obj); + if (syms.length !== 1 || syms[0] !== sym) { + return false; + } + if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { + return false; + } + if (typeof Object.getOwnPropertyDescriptor === "function") { + var descriptor = Object.getOwnPropertyDescriptor(obj, sym); + if (descriptor.value !== symVal || descriptor.enumerable !== true) { + return false; + } + } + return true; + }; + return exports$k; +} + +var exports$j = {}, + _dewExec$j = false; +function dew$j() { + if (_dewExec$j) return exports$j; + _dewExec$j = true; + /** @type {import('.')} */ + exports$j = Error; + return exports$j; +} + +var exports$i = {}, + _dewExec$i = false; +function dew$i() { + if (_dewExec$i) return exports$i; + _dewExec$i = true; + /** @type {import('./eval')} */ + exports$i = EvalError; + return exports$i; +} + +var exports$h = {}, + _dewExec$h = false; +function dew$h() { + if (_dewExec$h) return exports$h; + _dewExec$h = true; + /** @type {import('./range')} */ + exports$h = RangeError; + return exports$h; +} + +var exports$g = {}, + _dewExec$g = false; +function dew$g() { + if (_dewExec$g) return exports$g; + _dewExec$g = true; + /** @type {import('./ref')} */ + exports$g = ReferenceError; + return exports$g; +} + +var exports$f = {}, + _dewExec$f = false; +function dew$f() { + if (_dewExec$f) return exports$f; + _dewExec$f = true; + /** @type {import('./syntax')} */ + exports$f = SyntaxError; + return exports$f; +} + +var exports$e = {}, + _dewExec$e = false; +function dew$e() { + if (_dewExec$e) return exports$e; + _dewExec$e = true; + /** @type {import('./type')} */ + exports$e = TypeError; + return exports$e; +} + +var exports$d = {}, + _dewExec$d = false; +function dew$d() { + if (_dewExec$d) return exports$d; + _dewExec$d = true; + /** @type {import('./uri')} */ + exports$d = URIError; + return exports$d; +} + +var exports$c = {}, + _dewExec$c = false; +function dew$c() { + if (_dewExec$c) return exports$c; + _dewExec$c = true; + var origSymbol = typeof Symbol !== "undefined" && Symbol; + var hasSymbolSham = dew$k(); + exports$c = function hasNativeSymbols() { + if (typeof origSymbol !== "function") { + return false; + } + if (typeof Symbol !== "function") { + return false; + } + if (typeof origSymbol("foo") !== "symbol") { + return false; + } + if (typeof Symbol("bar") !== "symbol") { + return false; + } + return hasSymbolSham(); + }; + return exports$c; +} + +var exports$b = {}, + _dewExec$b = false; +function dew$b() { + if (_dewExec$b) return exports$b; + _dewExec$b = true; + var test = { + __proto__: null, + foo: {} + }; + var $Object = Object; + + /** @type {import('.')} */ + exports$b = function hasProto() { + // @ts-expect-error: TS errors on an inherited property for some reason + return { + __proto__: test + }.foo === test.foo && !(test instanceof $Object); + }; + return exports$b; +} + +var exports$a = {}, + _dewExec$a = false; +function dew$a() { + if (_dewExec$a) return exports$a; + _dewExec$a = true; + /* eslint no-invalid-this: 1 */ + + var ERROR_MESSAGE = "Function.prototype.bind called on incompatible "; + var toStr = Object.prototype.toString; + var max = Math.max; + var funcType = "[object Function]"; + var concatty = function concatty(a, b) { + var arr = []; + for (var i = 0; i < a.length; i += 1) { + arr[i] = a[i]; + } + for (var j = 0; j < b.length; j += 1) { + arr[j + a.length] = b[j]; + } + return arr; + }; + var slicy = function slicy(arrLike, offset) { + var arr = []; + for (var i = offset, j = 0; i < arrLike.length; i += 1, j += 1) { + arr[j] = arrLike[i]; + } + return arr; + }; + var joiny = function (arr, joiner) { + var str = ""; + for (var i = 0; i < arr.length; i += 1) { + str += arr[i]; + if (i + 1 < arr.length) { + str += joiner; + } + } + return str; + }; + exports$a = function bind(that) { + var target = this; + if (typeof target !== "function" || toStr.apply(target) !== funcType) { + throw new TypeError(ERROR_MESSAGE + target); + } + var args = slicy(arguments, 1); + var bound; + var binder = function () { + if (this instanceof bound) { + var result = target.apply(this, concatty(args, arguments)); + if (Object(result) === result) { + return result; + } + return this; + } + return target.apply(that, concatty(args, arguments)); + }; + var boundLength = max(0, target.length - args.length); + var boundArgs = []; + for (var i = 0; i < boundLength; i++) { + boundArgs[i] = "$" + i; + } + bound = Function("binder", "return function (" + joiny(boundArgs, ",") + "){ return binder.apply(this,arguments); }")(binder); + if (target.prototype) { + var Empty = function Empty() {}; + Empty.prototype = target.prototype; + bound.prototype = new Empty(); + Empty.prototype = null; + } + return bound; + }; + return exports$a; +} + +var exports$9 = {}, + _dewExec$9 = false; +function dew$9() { + if (_dewExec$9) return exports$9; + _dewExec$9 = true; + var implementation = dew$a(); + exports$9 = Function.prototype.bind || implementation; + return exports$9; +} + +var exports$8 = {}, + _dewExec$8 = false; +function dew$8() { + if (_dewExec$8) return exports$8; + _dewExec$8 = true; + var call = Function.prototype.call; + var $hasOwn = Object.prototype.hasOwnProperty; + var bind = dew$9(); + + /** @type {import('.')} */ + exports$8 = bind.call(call, $hasOwn); + return exports$8; +} + +var exports$7 = {}, + _dewExec$7 = false; +function dew$7() { + if (_dewExec$7) return exports$7; + _dewExec$7 = true; + var undefined$1; + var $Error = dew$j(); + var $EvalError = dew$i(); + var $RangeError = dew$h(); + var $ReferenceError = dew$g(); + var $SyntaxError = dew$f(); + var $TypeError = dew$e(); + var $URIError = dew$d(); + var $Function = Function; + + // eslint-disable-next-line consistent-return + var getEvalledConstructor = function (expressionSyntax) { + try { + return $Function("\"use strict\"; return (" + expressionSyntax + ").constructor;")(); + } catch (e) {} + }; + var $gOPD = Object.getOwnPropertyDescriptor; + if ($gOPD) { + try { + $gOPD({}, ""); + } catch (e) { + $gOPD = null; // this is IE 8, which has a broken gOPD + } + } + var throwTypeError = function () { + throw new $TypeError(); + }; + var ThrowTypeError = $gOPD ? function () { + try { + // eslint-disable-next-line no-unused-expressions, no-caller, no-restricted-properties + arguments.callee; // IE 8 does not throw here + return throwTypeError; + } catch (calleeThrows) { + try { + // IE 8 throws on Object.getOwnPropertyDescriptor(arguments, '') + return $gOPD(arguments, "callee").get; + } catch (gOPDthrows) { + return throwTypeError; + } + } + }() : throwTypeError; + var hasSymbols = dew$c()(); + var hasProto = dew$b()(); + var getProto = Object.getPrototypeOf || (hasProto ? function (x) { + return x.__proto__; + } // eslint-disable-line no-proto + : null); + var needsEval = {}; + var TypedArray = typeof Uint8Array === "undefined" || !getProto ? undefined$1 : getProto(Uint8Array); + var INTRINSICS = { + __proto__: null, + "%AggregateError%": typeof AggregateError === "undefined" ? undefined$1 : AggregateError, + "%Array%": Array, + "%ArrayBuffer%": typeof ArrayBuffer === "undefined" ? undefined$1 : ArrayBuffer, + "%ArrayIteratorPrototype%": hasSymbols && getProto ? getProto([][Symbol.iterator]()) : undefined$1, + "%AsyncFromSyncIteratorPrototype%": undefined$1, + "%AsyncFunction%": needsEval, + "%AsyncGenerator%": needsEval, + "%AsyncGeneratorFunction%": needsEval, + "%AsyncIteratorPrototype%": needsEval, + "%Atomics%": typeof Atomics === "undefined" ? undefined$1 : Atomics, + "%BigInt%": typeof BigInt === "undefined" ? undefined$1 : BigInt, + "%BigInt64Array%": typeof BigInt64Array === "undefined" ? undefined$1 : BigInt64Array, + "%BigUint64Array%": typeof BigUint64Array === "undefined" ? undefined$1 : BigUint64Array, + "%Boolean%": Boolean, + "%DataView%": typeof DataView === "undefined" ? undefined$1 : DataView, + "%Date%": Date, + "%decodeURI%": decodeURI, + "%decodeURIComponent%": decodeURIComponent, + "%encodeURI%": encodeURI, + "%encodeURIComponent%": encodeURIComponent, + "%Error%": $Error, + "%eval%": eval, + // eslint-disable-line no-eval + "%EvalError%": $EvalError, + "%Float32Array%": typeof Float32Array === "undefined" ? undefined$1 : Float32Array, + "%Float64Array%": typeof Float64Array === "undefined" ? undefined$1 : Float64Array, + "%FinalizationRegistry%": typeof FinalizationRegistry === "undefined" ? undefined$1 : FinalizationRegistry, + "%Function%": $Function, + "%GeneratorFunction%": needsEval, + "%Int8Array%": typeof Int8Array === "undefined" ? undefined$1 : Int8Array, + "%Int16Array%": typeof Int16Array === "undefined" ? undefined$1 : Int16Array, + "%Int32Array%": typeof Int32Array === "undefined" ? undefined$1 : Int32Array, + "%isFinite%": isFinite, + "%isNaN%": isNaN, + "%IteratorPrototype%": hasSymbols && getProto ? getProto(getProto([][Symbol.iterator]())) : undefined$1, + "%JSON%": typeof JSON === "object" ? JSON : undefined$1, + "%Map%": typeof Map === "undefined" ? undefined$1 : Map, + "%MapIteratorPrototype%": typeof Map === "undefined" || !hasSymbols || !getProto ? undefined$1 : getProto(new Map()[Symbol.iterator]()), + "%Math%": Math, + "%Number%": Number, + "%Object%": Object, + "%parseFloat%": parseFloat, + "%parseInt%": parseInt, + "%Promise%": typeof Promise === "undefined" ? undefined$1 : Promise, + "%Proxy%": typeof Proxy === "undefined" ? undefined$1 : Proxy, + "%RangeError%": $RangeError, + "%ReferenceError%": $ReferenceError, + "%Reflect%": typeof Reflect === "undefined" ? undefined$1 : Reflect, + "%RegExp%": RegExp, + "%Set%": typeof Set === "undefined" ? undefined$1 : Set, + "%SetIteratorPrototype%": typeof Set === "undefined" || !hasSymbols || !getProto ? undefined$1 : getProto(new Set()[Symbol.iterator]()), + "%SharedArrayBuffer%": typeof SharedArrayBuffer === "undefined" ? undefined$1 : SharedArrayBuffer, + "%String%": String, + "%StringIteratorPrototype%": hasSymbols && getProto ? getProto(""[Symbol.iterator]()) : undefined$1, + "%Symbol%": hasSymbols ? Symbol : undefined$1, + "%SyntaxError%": $SyntaxError, + "%ThrowTypeError%": ThrowTypeError, + "%TypedArray%": TypedArray, + "%TypeError%": $TypeError, + "%Uint8Array%": typeof Uint8Array === "undefined" ? undefined$1 : Uint8Array, + "%Uint8ClampedArray%": typeof Uint8ClampedArray === "undefined" ? undefined$1 : Uint8ClampedArray, + "%Uint16Array%": typeof Uint16Array === "undefined" ? undefined$1 : Uint16Array, + "%Uint32Array%": typeof Uint32Array === "undefined" ? undefined$1 : Uint32Array, + "%URIError%": $URIError, + "%WeakMap%": typeof WeakMap === "undefined" ? undefined$1 : WeakMap, + "%WeakRef%": typeof WeakRef === "undefined" ? undefined$1 : WeakRef, + "%WeakSet%": typeof WeakSet === "undefined" ? undefined$1 : WeakSet + }; + if (getProto) { + try { + null.error; // eslint-disable-line no-unused-expressions + } catch (e) { + // https://github.com/tc39/proposal-shadowrealm/pull/384#issuecomment-1364264229 + var errorProto = getProto(getProto(e)); + INTRINSICS["%Error.prototype%"] = errorProto; + } + } + var doEval = function doEval(name) { + var value; + if (name === "%AsyncFunction%") { + value = getEvalledConstructor("async function () {}"); + } else if (name === "%GeneratorFunction%") { + value = getEvalledConstructor("function* () {}"); + } else if (name === "%AsyncGeneratorFunction%") { + value = getEvalledConstructor("async function* () {}"); + } else if (name === "%AsyncGenerator%") { + var fn = doEval("%AsyncGeneratorFunction%"); + if (fn) { + value = fn.prototype; + } + } else if (name === "%AsyncIteratorPrototype%") { + var gen = doEval("%AsyncGenerator%"); + if (gen && getProto) { + value = getProto(gen.prototype); + } + } + INTRINSICS[name] = value; + return value; + }; + var LEGACY_ALIASES = { + __proto__: null, + "%ArrayBufferPrototype%": ["ArrayBuffer", "prototype"], + "%ArrayPrototype%": ["Array", "prototype"], + "%ArrayProto_entries%": ["Array", "prototype", "entries"], + "%ArrayProto_forEach%": ["Array", "prototype", "forEach"], + "%ArrayProto_keys%": ["Array", "prototype", "keys"], + "%ArrayProto_values%": ["Array", "prototype", "values"], + "%AsyncFunctionPrototype%": ["AsyncFunction", "prototype"], + "%AsyncGenerator%": ["AsyncGeneratorFunction", "prototype"], + "%AsyncGeneratorPrototype%": ["AsyncGeneratorFunction", "prototype", "prototype"], + "%BooleanPrototype%": ["Boolean", "prototype"], + "%DataViewPrototype%": ["DataView", "prototype"], + "%DatePrototype%": ["Date", "prototype"], + "%ErrorPrototype%": ["Error", "prototype"], + "%EvalErrorPrototype%": ["EvalError", "prototype"], + "%Float32ArrayPrototype%": ["Float32Array", "prototype"], + "%Float64ArrayPrototype%": ["Float64Array", "prototype"], + "%FunctionPrototype%": ["Function", "prototype"], + "%Generator%": ["GeneratorFunction", "prototype"], + "%GeneratorPrototype%": ["GeneratorFunction", "prototype", "prototype"], + "%Int8ArrayPrototype%": ["Int8Array", "prototype"], + "%Int16ArrayPrototype%": ["Int16Array", "prototype"], + "%Int32ArrayPrototype%": ["Int32Array", "prototype"], + "%JSONParse%": ["JSON", "parse"], + "%JSONStringify%": ["JSON", "stringify"], + "%MapPrototype%": ["Map", "prototype"], + "%NumberPrototype%": ["Number", "prototype"], + "%ObjectPrototype%": ["Object", "prototype"], + "%ObjProto_toString%": ["Object", "prototype", "toString"], + "%ObjProto_valueOf%": ["Object", "prototype", "valueOf"], + "%PromisePrototype%": ["Promise", "prototype"], + "%PromiseProto_then%": ["Promise", "prototype", "then"], + "%Promise_all%": ["Promise", "all"], + "%Promise_reject%": ["Promise", "reject"], + "%Promise_resolve%": ["Promise", "resolve"], + "%RangeErrorPrototype%": ["RangeError", "prototype"], + "%ReferenceErrorPrototype%": ["ReferenceError", "prototype"], + "%RegExpPrototype%": ["RegExp", "prototype"], + "%SetPrototype%": ["Set", "prototype"], + "%SharedArrayBufferPrototype%": ["SharedArrayBuffer", "prototype"], + "%StringPrototype%": ["String", "prototype"], + "%SymbolPrototype%": ["Symbol", "prototype"], + "%SyntaxErrorPrototype%": ["SyntaxError", "prototype"], + "%TypedArrayPrototype%": ["TypedArray", "prototype"], + "%TypeErrorPrototype%": ["TypeError", "prototype"], + "%Uint8ArrayPrototype%": ["Uint8Array", "prototype"], + "%Uint8ClampedArrayPrototype%": ["Uint8ClampedArray", "prototype"], + "%Uint16ArrayPrototype%": ["Uint16Array", "prototype"], + "%Uint32ArrayPrototype%": ["Uint32Array", "prototype"], + "%URIErrorPrototype%": ["URIError", "prototype"], + "%WeakMapPrototype%": ["WeakMap", "prototype"], + "%WeakSetPrototype%": ["WeakSet", "prototype"] + }; + var bind = dew$9(); + var hasOwn = dew$8(); + var $concat = bind.call(Function.call, Array.prototype.concat); + var $spliceApply = bind.call(Function.apply, Array.prototype.splice); + var $replace = bind.call(Function.call, String.prototype.replace); + var $strSlice = bind.call(Function.call, String.prototype.slice); + var $exec = bind.call(Function.call, RegExp.prototype.exec); + + /* adapted from https://github.com/lodash/lodash/blob/4.17.15/dist/lodash.js#L6735-L6744 */ + var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g; + var reEscapeChar = /\\(\\)?/g; /** Used to match backslashes in property paths. */ + var stringToPath = function stringToPath(string) { + var first = $strSlice(string, 0, 1); + var last = $strSlice(string, -1); + if (first === "%" && last !== "%") { + throw new $SyntaxError("invalid intrinsic syntax, expected closing `%`"); + } else if (last === "%" && first !== "%") { + throw new $SyntaxError("invalid intrinsic syntax, expected opening `%`"); + } + var result = []; + $replace(string, rePropName, function (match, number, quote, subString) { + result[result.length] = quote ? $replace(subString, reEscapeChar, "$1") : number || match; + }); + return result; + }; + /* end adaptation */ + + var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) { + var intrinsicName = name; + var alias; + if (hasOwn(LEGACY_ALIASES, intrinsicName)) { + alias = LEGACY_ALIASES[intrinsicName]; + intrinsicName = "%" + alias[0] + "%"; + } + if (hasOwn(INTRINSICS, intrinsicName)) { + var value = INTRINSICS[intrinsicName]; + if (value === needsEval) { + value = doEval(intrinsicName); + } + if (typeof value === "undefined" && !allowMissing) { + throw new $TypeError("intrinsic " + name + " exists, but is not available. Please file an issue!"); + } + return { + alias: alias, + name: intrinsicName, + value: value + }; + } + throw new $SyntaxError("intrinsic " + name + " does not exist!"); + }; + exports$7 = function GetIntrinsic(name, allowMissing) { + if (typeof name !== "string" || name.length === 0) { + throw new $TypeError("intrinsic name must be a non-empty string"); + } + if (arguments.length > 1 && typeof allowMissing !== "boolean") { + throw new $TypeError("\"allowMissing\" argument must be a boolean"); + } + if ($exec(/^%?[^%]*%?$/, name) === null) { + throw new $SyntaxError("`%` may not be present anywhere but at the beginning and end of the intrinsic name"); + } + var parts = stringToPath(name); + var intrinsicBaseName = parts.length > 0 ? parts[0] : ""; + var intrinsic = getBaseIntrinsic("%" + intrinsicBaseName + "%", allowMissing); + var intrinsicRealName = intrinsic.name; + var value = intrinsic.value; + var skipFurtherCaching = false; + var alias = intrinsic.alias; + if (alias) { + intrinsicBaseName = alias[0]; + $spliceApply(parts, $concat([0, 1], alias)); + } + for (var i = 1, isOwn = true; i < parts.length; i += 1) { + var part = parts[i]; + var first = $strSlice(part, 0, 1); + var last = $strSlice(part, -1); + if ((first === "\"" || first === "'" || first === "`" || last === "\"" || last === "'" || last === "`") && first !== last) { + throw new $SyntaxError("property names with quotes must have matching quotes"); + } + if (part === "constructor" || !isOwn) { + skipFurtherCaching = true; + } + intrinsicBaseName += "." + part; + intrinsicRealName = "%" + intrinsicBaseName + "%"; + if (hasOwn(INTRINSICS, intrinsicRealName)) { + value = INTRINSICS[intrinsicRealName]; + } else if (value != null) { + if (!(part in value)) { + if (!allowMissing) { + throw new $TypeError("base intrinsic for " + name + " exists, but the property is not available."); + } + return void undefined$1; + } + if ($gOPD && i + 1 >= parts.length) { + var desc = $gOPD(value, part); + isOwn = !!desc; + + // By convention, when a data property is converted to an accessor + // property to emulate a data property that does not suffer from + // the override mistake, that accessor's getter is marked with + // an `originalValue` property. Here, when we detect this, we + // uphold the illusion by pretending to see that original data + // property, i.e., returning the value rather than the getter + // itself. + if (isOwn && "get" in desc && !("originalValue" in desc.get)) { + value = desc.get; + } else { + value = value[part]; + } + } else { + isOwn = hasOwn(value, part); + value = value[part]; + } + if (isOwn && !skipFurtherCaching) { + INTRINSICS[intrinsicRealName] = value; + } + } + } + return value; + }; + return exports$7; +} + +var exports$6 = {}, + _dewExec$6 = false; +function dew$6() { + if (_dewExec$6) return exports$6; + _dewExec$6 = true; + var GetIntrinsic = dew$7(); + + /** @type {import('.')} */ + var $defineProperty = GetIntrinsic("%Object.defineProperty%", true) || false; + if ($defineProperty) { + try { + $defineProperty({}, "a", { + value: 1 + }); + } catch (e) { + // IE 8 has a broken defineProperty + $defineProperty = false; + } + } + exports$6 = $defineProperty; + return exports$6; +} + +var exports$5 = {}, + _dewExec$5 = false; +function dew$5() { + if (_dewExec$5) return exports$5; + _dewExec$5 = true; + var GetIntrinsic = dew$7(); + var $gOPD = GetIntrinsic("%Object.getOwnPropertyDescriptor%", true); + if ($gOPD) { + try { + $gOPD([], "length"); + } catch (e) { + // IE 8 has a broken gOPD + $gOPD = null; + } + } + exports$5 = $gOPD; + return exports$5; +} + +var exports$4 = {}, + _dewExec$4 = false; +function dew$4() { + if (_dewExec$4) return exports$4; + _dewExec$4 = true; + var $defineProperty = dew$6(); + var $SyntaxError = dew$f(); + var $TypeError = dew$e(); + var gopd = dew$5(); + + /** @type {import('.')} */ + exports$4 = function defineDataProperty(obj, property, value) { + if (!obj || typeof obj !== "object" && typeof obj !== "function") { + throw new $TypeError("`obj` must be an object or a function`"); + } + if (typeof property !== "string" && typeof property !== "symbol") { + throw new $TypeError("`property` must be a string or a symbol`"); + } + if (arguments.length > 3 && typeof arguments[3] !== "boolean" && arguments[3] !== null) { + throw new $TypeError("`nonEnumerable`, if provided, must be a boolean or null"); + } + if (arguments.length > 4 && typeof arguments[4] !== "boolean" && arguments[4] !== null) { + throw new $TypeError("`nonWritable`, if provided, must be a boolean or null"); + } + if (arguments.length > 5 && typeof arguments[5] !== "boolean" && arguments[5] !== null) { + throw new $TypeError("`nonConfigurable`, if provided, must be a boolean or null"); + } + if (arguments.length > 6 && typeof arguments[6] !== "boolean") { + throw new $TypeError("`loose`, if provided, must be a boolean"); + } + var nonEnumerable = arguments.length > 3 ? arguments[3] : null; + var nonWritable = arguments.length > 4 ? arguments[4] : null; + var nonConfigurable = arguments.length > 5 ? arguments[5] : null; + var loose = arguments.length > 6 ? arguments[6] : false; + + /* @type {false | TypedPropertyDescriptor} */ + var desc = !!gopd && gopd(obj, property); + if ($defineProperty) { + $defineProperty(obj, property, { + configurable: nonConfigurable === null && desc ? desc.configurable : !nonConfigurable, + enumerable: nonEnumerable === null && desc ? desc.enumerable : !nonEnumerable, + value: value, + writable: nonWritable === null && desc ? desc.writable : !nonWritable + }); + } else if (loose || !nonEnumerable && !nonWritable && !nonConfigurable) { + // must fall back to [[Set]], and was not explicitly asked to make non-enumerable, non-writable, or non-configurable + obj[property] = value; // eslint-disable-line no-param-reassign + } else { + throw new $SyntaxError("This environment does not support defining a property as non-configurable, non-writable, or non-enumerable."); + } + }; + return exports$4; +} + +var exports$3 = {}, + _dewExec$3 = false; +function dew$3() { + if (_dewExec$3) return exports$3; + _dewExec$3 = true; + var $defineProperty = dew$6(); + var hasPropertyDescriptors = function hasPropertyDescriptors() { + return !!$defineProperty; + }; + hasPropertyDescriptors.hasArrayLengthDefineBug = function hasArrayLengthDefineBug() { + // node v0.6 has a bug where array lengths can be Set but not Defined + if (!$defineProperty) { + return null; + } + try { + return $defineProperty([], "length", { + value: 1 + }).length !== 1; + } catch (e) { + // In Firefox 4-22, defining length on an array throws an exception. + return true; + } + }; + exports$3 = hasPropertyDescriptors; + return exports$3; +} + +var exports$2 = {}, + _dewExec$2 = false; +function dew$2() { + if (_dewExec$2) return exports$2; + _dewExec$2 = true; + var GetIntrinsic = dew$7(); + var define = dew$4(); + var hasDescriptors = dew$3()(); + var gOPD = dew$5(); + var $TypeError = dew$e(); + var $floor = GetIntrinsic("%Math.floor%"); + + /** @type {import('.')} */ + exports$2 = function setFunctionLength(fn, length) { + if (typeof fn !== "function") { + throw new $TypeError("`fn` is not a function"); + } + if (typeof length !== "number" || length < 0 || length > 4294967295 || $floor(length) !== length) { + throw new $TypeError("`length` must be a positive 32-bit integer"); + } + var loose = arguments.length > 2 && !!arguments[2]; + var functionLengthIsConfigurable = true; + var functionLengthIsWritable = true; + if ("length" in fn && gOPD) { + var desc = gOPD(fn, "length"); + if (desc && !desc.configurable) { + functionLengthIsConfigurable = false; + } + if (desc && !desc.writable) { + functionLengthIsWritable = false; + } + } + if (functionLengthIsConfigurable || functionLengthIsWritable || !loose) { + if (hasDescriptors) { + define(/** @type {Parameters[0]} */fn, "length", length, true, true); + } else { + define(/** @type {Parameters[0]} */fn, "length", length); + } + } + return fn; + }; + return exports$2; +} + +var exports$1 = {}, + _dewExec$1 = false; +function dew$1() { + if (_dewExec$1) return exports$1; + _dewExec$1 = true; + var bind = dew$9(); + var GetIntrinsic = dew$7(); + var setFunctionLength = dew$2(); + var $TypeError = dew$e(); + var $apply = GetIntrinsic("%Function.prototype.apply%"); + var $call = GetIntrinsic("%Function.prototype.call%"); + var $reflectApply = GetIntrinsic("%Reflect.apply%", true) || bind.call($call, $apply); + var $defineProperty = dew$6(); + var $max = GetIntrinsic("%Math.max%"); + exports$1 = function callBind(originalFunction) { + if (typeof originalFunction !== "function") { + throw new $TypeError("a function is required"); + } + var func = $reflectApply(bind, $call, arguments); + return setFunctionLength(func, 1 + $max(0, originalFunction.length - (arguments.length - 1)), true); + }; + var applyBind = function applyBind() { + return $reflectApply(bind, $apply, arguments); + }; + if ($defineProperty) { + $defineProperty(exports$1, "apply", { + value: applyBind + }); + } else { + exports$1.apply = applyBind; + } + return exports$1; +} + +var exports = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports; + _dewExec = true; + var GetIntrinsic = dew$7(); + var callBind = dew$1(); + var $indexOf = callBind(GetIntrinsic("String.prototype.indexOf")); + exports = function callBoundIntrinsic(name, allowMissing) { + var intrinsic = GetIntrinsic(name, !!allowMissing); + if (typeof intrinsic === "function" && $indexOf(name, ".prototype.") > -1) { + return callBind(intrinsic); + } + return intrinsic; + }; + return exports; +} + +export { dew as a, dew$4 as b, dew$3 as c, dew$k as d, dew$1 as e, dew$5 as f, dew$7 as g, dew$e as h }; diff --git a/nodelibs/browser/chunk-DtuTasat.js b/nodelibs/browser/chunk-DtuTasat.js new file mode 100644 index 0000000..a9e7a61 --- /dev/null +++ b/nodelibs/browser/chunk-DtuTasat.js @@ -0,0 +1,1923 @@ +var exports$2 = {}, + _dewExec$2 = false; +function dew$2() { + if (_dewExec$2) return exports$2; + _dewExec$2 = true; + exports$2.byteLength = byteLength; + exports$2.toByteArray = toByteArray; + exports$2.fromByteArray = fromByteArray; + var lookup = []; + var revLookup = []; + var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array; + var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; + for (var i = 0, len = code.length; i < len; ++i) { + lookup[i] = code[i]; + revLookup[code.charCodeAt(i)] = i; + } + + // Support decoding URL-safe base64 strings, as Node.js does. + // See: https://en.wikipedia.org/wiki/Base64#URL_applications + revLookup["-".charCodeAt(0)] = 62; + revLookup["_".charCodeAt(0)] = 63; + function getLens(b64) { + var len = b64.length; + if (len % 4 > 0) { + throw new Error("Invalid string. Length must be a multiple of 4"); + } + + // Trim off extra bytes after placeholder bytes are found + // See: https://github.com/beatgammit/base64-js/issues/42 + var validLen = b64.indexOf("="); + if (validLen === -1) validLen = len; + var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4; + return [validLen, placeHoldersLen]; + } + + // base64 is 4/3 + up to two characters of the original data + function byteLength(b64) { + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + function _byteLength(b64, validLen, placeHoldersLen) { + return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen; + } + function toByteArray(b64) { + var tmp; + var lens = getLens(b64); + var validLen = lens[0]; + var placeHoldersLen = lens[1]; + var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen)); + var curByte = 0; + + // if there are placeholders, only get up to the last complete 4 chars + var len = placeHoldersLen > 0 ? validLen - 4 : validLen; + var i; + for (i = 0; i < len; i += 4) { + tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)]; + arr[curByte++] = tmp >> 16 & 255; + arr[curByte++] = tmp >> 8 & 255; + arr[curByte++] = tmp & 255; + } + if (placeHoldersLen === 2) { + tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4; + arr[curByte++] = tmp & 255; + } + if (placeHoldersLen === 1) { + tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2; + arr[curByte++] = tmp >> 8 & 255; + arr[curByte++] = tmp & 255; + } + return arr; + } + function tripletToBase64(num) { + return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63]; + } + function encodeChunk(uint8, start, end) { + var tmp; + var output = []; + for (var i = start; i < end; i += 3) { + tmp = (uint8[i] << 16 & 16711680) + (uint8[i + 1] << 8 & 65280) + (uint8[i + 2] & 255); + output.push(tripletToBase64(tmp)); + } + return output.join(""); + } + function fromByteArray(uint8) { + var tmp; + var len = uint8.length; + var extraBytes = len % 3; // if we have 1 byte left, pad 2 bytes + var parts = []; + var maxChunkLength = 16383; // must be multiple of 3 + + // go through the array every three bytes, we'll deal with trailing stuff later + for (var i = 0, len2 = len - extraBytes; i < len2; i += maxChunkLength) { + parts.push(encodeChunk(uint8, i, i + maxChunkLength > len2 ? len2 : i + maxChunkLength)); + } + + // pad the end with zeros, but make sure to not forget the extra bytes + if (extraBytes === 1) { + tmp = uint8[len - 1]; + parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "=="); + } else if (extraBytes === 2) { + tmp = (uint8[len - 2] << 8) + uint8[len - 1]; + parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "="); + } + return parts.join(""); + } + return exports$2; +} + +var exports$1 = {}, + _dewExec$1 = false; +function dew$1() { + if (_dewExec$1) return exports$1; + _dewExec$1 = true; + /*! ieee754. BSD-3-Clause License. Feross Aboukhadijeh */ + exports$1.read = function (buffer, offset, isLE, mLen, nBytes) { + var e, m; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var nBits = -7; + var i = isLE ? nBytes - 1 : 0; + var d = isLE ? -1 : 1; + var s = buffer[offset + i]; + i += d; + e = s & (1 << -nBits) - 1; + s >>= -nBits; + nBits += eLen; + for (; nBits > 0; e = e * 256 + buffer[offset + i], i += d, nBits -= 8) {} + m = e & (1 << -nBits) - 1; + e >>= -nBits; + nBits += mLen; + for (; nBits > 0; m = m * 256 + buffer[offset + i], i += d, nBits -= 8) {} + if (e === 0) { + e = 1 - eBias; + } else if (e === eMax) { + return m ? NaN : (s ? -1 : 1) * Infinity; + } else { + m = m + Math.pow(2, mLen); + e = e - eBias; + } + return (s ? -1 : 1) * m * Math.pow(2, e - mLen); + }; + exports$1.write = function (buffer, value, offset, isLE, mLen, nBytes) { + var e, m, c; + var eLen = nBytes * 8 - mLen - 1; + var eMax = (1 << eLen) - 1; + var eBias = eMax >> 1; + var rt = mLen === 23 ? Math.pow(2, -24) - Math.pow(2, -77) : 0; + var i = isLE ? 0 : nBytes - 1; + var d = isLE ? 1 : -1; + var s = value < 0 || value === 0 && 1 / value < 0 ? 1 : 0; + value = Math.abs(value); + if (isNaN(value) || value === Infinity) { + m = isNaN(value) ? 1 : 0; + e = eMax; + } else { + e = Math.floor(Math.log(value) / Math.LN2); + if (value * (c = Math.pow(2, -e)) < 1) { + e--; + c *= 2; + } + if (e + eBias >= 1) { + value += rt / c; + } else { + value += rt * Math.pow(2, 1 - eBias); + } + if (value * c >= 2) { + e++; + c /= 2; + } + if (e + eBias >= eMax) { + m = 0; + e = eMax; + } else if (e + eBias >= 1) { + m = (value * c - 1) * Math.pow(2, mLen); + e = e + eBias; + } else { + m = value * Math.pow(2, eBias - 1) * Math.pow(2, mLen); + e = 0; + } + } + for (; mLen >= 8; buffer[offset + i] = m & 255, i += d, m /= 256, mLen -= 8) {} + e = e << mLen | m; + eLen += mLen; + for (; eLen > 0; buffer[offset + i] = e & 255, i += d, e /= 256, eLen -= 8) {} + buffer[offset + i - d] |= s * 128; + }; + return exports$1; +} + +var exports = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports; + _dewExec = true; + const base64 = dew$2(); + const ieee754 = dew$1(); + const customInspectSymbol = typeof Symbol === "function" && typeof Symbol["for"] === "function" // eslint-disable-line dot-notation + ? Symbol["for"]("nodejs.util.inspect.custom") // eslint-disable-line dot-notation + : null; + exports.Buffer = Buffer; + exports.SlowBuffer = SlowBuffer; + exports.INSPECT_MAX_BYTES = 50; + const K_MAX_LENGTH = 2147483647; + exports.kMaxLength = K_MAX_LENGTH; + + /** + * If `Buffer.TYPED_ARRAY_SUPPORT`: + * === true Use Uint8Array implementation (fastest) + * === false Print warning and recommend using `buffer` v4.x which has an Object + * implementation (most compatible, even IE6) + * + * Browsers that support typed arrays are IE 10+, Firefox 4+, Chrome 7+, Safari 5.1+, + * Opera 11.6+, iOS 4.2+. + * + * We report that the browser does not support typed arrays if the are not subclassable + * using __proto__. Firefox 4-29 lacks support for adding new properties to `Uint8Array` + * (See: https://bugzilla.mozilla.org/show_bug.cgi?id=695438). IE 10 lacks support + * for __proto__ and has a buggy typed array implementation. + */ + Buffer.TYPED_ARRAY_SUPPORT = typedArraySupport(); + if (!Buffer.TYPED_ARRAY_SUPPORT && typeof console !== "undefined" && typeof console.error === "function") { + console.error("This browser lacks typed array (Uint8Array) support which is required by " + "`buffer` v5.x. Use `buffer` v4.x if you require old browser support."); + } + function typedArraySupport() { + // Can typed array instances can be augmented? + try { + const arr = new Uint8Array(1); + const proto = { + foo: function () { + return 42; + } + }; + Object.setPrototypeOf(proto, Uint8Array.prototype); + Object.setPrototypeOf(arr, proto); + return arr.foo() === 42; + } catch (e) { + return false; + } + } + Object.defineProperty(Buffer.prototype, "parent", { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined; + return this.buffer; + } + }); + Object.defineProperty(Buffer.prototype, "offset", { + enumerable: true, + get: function () { + if (!Buffer.isBuffer(this)) return undefined; + return this.byteOffset; + } + }); + function createBuffer(length) { + if (length > K_MAX_LENGTH) { + throw new RangeError("The value \"" + length + "\" is invalid for option \"size\""); + } + // Return an augmented `Uint8Array` instance + const buf = new Uint8Array(length); + Object.setPrototypeOf(buf, Buffer.prototype); + return buf; + } + + /** + * The Buffer constructor returns instances of `Uint8Array` that have their + * prototype changed to `Buffer.prototype`. Furthermore, `Buffer` is a subclass of + * `Uint8Array`, so the returned instances will have all the node `Buffer` methods + * and the `Uint8Array` methods. Square bracket notation works as expected -- it + * returns a single octet. + * + * The `Uint8Array` prototype remains unmodified. + */ + + function Buffer(arg, encodingOrOffset, length) { + // Common case. + if (typeof arg === "number") { + if (typeof encodingOrOffset === "string") { + throw new TypeError("The \"string\" argument must be of type string. Received type number"); + } + return allocUnsafe(arg); + } + return from(arg, encodingOrOffset, length); + } + Buffer.poolSize = 8192; // not used by this implementation + + function from(value, encodingOrOffset, length) { + if (typeof value === "string") { + return fromString(value, encodingOrOffset); + } + if (ArrayBuffer.isView(value)) { + return fromArrayView(value); + } + if (value == null) { + throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, " + "or Array-like Object. Received type " + typeof value); + } + if (isInstance(value, ArrayBuffer) || value && isInstance(value.buffer, ArrayBuffer)) { + return fromArrayBuffer(value, encodingOrOffset, length); + } + if (typeof SharedArrayBuffer !== "undefined" && (isInstance(value, SharedArrayBuffer) || value && isInstance(value.buffer, SharedArrayBuffer))) { + return fromArrayBuffer(value, encodingOrOffset, length); + } + if (typeof value === "number") { + throw new TypeError("The \"value\" argument must not be of type number. Received type number"); + } + const valueOf = value.valueOf && value.valueOf(); + if (valueOf != null && valueOf !== value) { + return Buffer.from(valueOf, encodingOrOffset, length); + } + const b = fromObject(value); + if (b) return b; + if (typeof Symbol !== "undefined" && Symbol.toPrimitive != null && typeof value[Symbol.toPrimitive] === "function") { + return Buffer.from(value[Symbol.toPrimitive]("string"), encodingOrOffset, length); + } + throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, " + "or Array-like Object. Received type " + typeof value); + } + + /** + * Functionally equivalent to Buffer(arg, encoding) but throws a TypeError + * if value is a number. + * Buffer.from(str[, encoding]) + * Buffer.from(array) + * Buffer.from(buffer) + * Buffer.from(arrayBuffer[, byteOffset[, length]]) + **/ + Buffer.from = function (value, encodingOrOffset, length) { + return from(value, encodingOrOffset, length); + }; + + // Note: Change prototype *after* Buffer.from is defined to workaround Chrome bug: + // https://github.com/feross/buffer/pull/148 + Object.setPrototypeOf(Buffer.prototype, Uint8Array.prototype); + Object.setPrototypeOf(Buffer, Uint8Array); + function assertSize(size) { + if (typeof size !== "number") { + throw new TypeError("\"size\" argument must be of type number"); + } else if (size < 0) { + throw new RangeError("The value \"" + size + "\" is invalid for option \"size\""); + } + } + function alloc(size, fill, encoding) { + assertSize(size); + if (size <= 0) { + return createBuffer(size); + } + if (fill !== undefined) { + // Only pay attention to encoding if it's a string. This + // prevents accidentally sending in a number that would + // be interpreted as a start offset. + return typeof encoding === "string" ? createBuffer(size).fill(fill, encoding) : createBuffer(size).fill(fill); + } + return createBuffer(size); + } + + /** + * Creates a new filled Buffer instance. + * alloc(size[, fill[, encoding]]) + **/ + Buffer.alloc = function (size, fill, encoding) { + return alloc(size, fill, encoding); + }; + function allocUnsafe(size) { + assertSize(size); + return createBuffer(size < 0 ? 0 : checked(size) | 0); + } + + /** + * Equivalent to Buffer(num), by default creates a non-zero-filled Buffer instance. + * */ + Buffer.allocUnsafe = function (size) { + return allocUnsafe(size); + }; + /** + * Equivalent to SlowBuffer(num), by default creates a non-zero-filled Buffer instance. + */ + Buffer.allocUnsafeSlow = function (size) { + return allocUnsafe(size); + }; + function fromString(string, encoding) { + if (typeof encoding !== "string" || encoding === "") { + encoding = "utf8"; + } + if (!Buffer.isEncoding(encoding)) { + throw new TypeError("Unknown encoding: " + encoding); + } + const length = byteLength(string, encoding) | 0; + let buf = createBuffer(length); + const actual = buf.write(string, encoding); + if (actual !== length) { + // Writing a hex string, for example, that contains invalid characters will + // cause everything after the first invalid character to be ignored. (e.g. + // 'abxxcd' will be treated as 'ab') + buf = buf.slice(0, actual); + } + return buf; + } + function fromArrayLike(array) { + const length = array.length < 0 ? 0 : checked(array.length) | 0; + const buf = createBuffer(length); + for (let i = 0; i < length; i += 1) { + buf[i] = array[i] & 255; + } + return buf; + } + function fromArrayView(arrayView) { + if (isInstance(arrayView, Uint8Array)) { + const copy = new Uint8Array(arrayView); + return fromArrayBuffer(copy.buffer, copy.byteOffset, copy.byteLength); + } + return fromArrayLike(arrayView); + } + function fromArrayBuffer(array, byteOffset, length) { + if (byteOffset < 0 || array.byteLength < byteOffset) { + throw new RangeError("\"offset\" is outside of buffer bounds"); + } + if (array.byteLength < byteOffset + (length || 0)) { + throw new RangeError("\"length\" is outside of buffer bounds"); + } + let buf; + if (byteOffset === undefined && length === undefined) { + buf = new Uint8Array(array); + } else if (length === undefined) { + buf = new Uint8Array(array, byteOffset); + } else { + buf = new Uint8Array(array, byteOffset, length); + } + + // Return an augmented `Uint8Array` instance + Object.setPrototypeOf(buf, Buffer.prototype); + return buf; + } + function fromObject(obj) { + if (Buffer.isBuffer(obj)) { + const len = checked(obj.length) | 0; + const buf = createBuffer(len); + if (buf.length === 0) { + return buf; + } + obj.copy(buf, 0, 0, len); + return buf; + } + if (obj.length !== undefined) { + if (typeof obj.length !== "number" || numberIsNaN(obj.length)) { + return createBuffer(0); + } + return fromArrayLike(obj); + } + if (obj.type === "Buffer" && Array.isArray(obj.data)) { + return fromArrayLike(obj.data); + } + } + function checked(length) { + // Note: cannot use `length < K_MAX_LENGTH` here because that fails when + // length is NaN (which is otherwise coerced to zero.) + if (length >= K_MAX_LENGTH) { + throw new RangeError("Attempt to allocate Buffer larger than maximum " + "size: 0x" + K_MAX_LENGTH.toString(16) + " bytes"); + } + return length | 0; + } + function SlowBuffer(length) { + if (+length != length) { + // eslint-disable-line eqeqeq + length = 0; + } + return Buffer.alloc(+length); + } + Buffer.isBuffer = function isBuffer(b) { + return b != null && b._isBuffer === true && b !== Buffer.prototype; // so Buffer.isBuffer(Buffer.prototype) will be false + }; + Buffer.compare = function compare(a, b) { + if (isInstance(a, Uint8Array)) a = Buffer.from(a, a.offset, a.byteLength); + if (isInstance(b, Uint8Array)) b = Buffer.from(b, b.offset, b.byteLength); + if (!Buffer.isBuffer(a) || !Buffer.isBuffer(b)) { + throw new TypeError("The \"buf1\", \"buf2\" arguments must be one of type Buffer or Uint8Array"); + } + if (a === b) return 0; + let x = a.length; + let y = b.length; + for (let i = 0, len = Math.min(x, y); i < len; ++i) { + if (a[i] !== b[i]) { + x = a[i]; + y = b[i]; + break; + } + } + if (x < y) return -1; + if (y < x) return 1; + return 0; + }; + Buffer.isEncoding = function isEncoding(encoding) { + switch (String(encoding).toLowerCase()) { + case "hex": + case "utf8": + case "utf-8": + case "ascii": + case "latin1": + case "binary": + case "base64": + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return true; + default: + return false; + } + }; + Buffer.concat = function concat(list, length) { + if (!Array.isArray(list)) { + throw new TypeError("\"list\" argument must be an Array of Buffers"); + } + if (list.length === 0) { + return Buffer.alloc(0); + } + let i; + if (length === undefined) { + length = 0; + for (i = 0; i < list.length; ++i) { + length += list[i].length; + } + } + const buffer = Buffer.allocUnsafe(length); + let pos = 0; + for (i = 0; i < list.length; ++i) { + let buf = list[i]; + if (isInstance(buf, Uint8Array)) { + if (pos + buf.length > buffer.length) { + if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); + buf.copy(buffer, pos); + } else { + Uint8Array.prototype.set.call(buffer, buf, pos); + } + } else if (!Buffer.isBuffer(buf)) { + throw new TypeError("\"list\" argument must be an Array of Buffers"); + } else { + buf.copy(buffer, pos); + } + pos += buf.length; + } + return buffer; + }; + function byteLength(string, encoding) { + if (Buffer.isBuffer(string)) { + return string.length; + } + if (ArrayBuffer.isView(string) || isInstance(string, ArrayBuffer)) { + return string.byteLength; + } + if (typeof string !== "string") { + throw new TypeError("The \"string\" argument must be one of type string, Buffer, or ArrayBuffer. " + "Received type " + typeof string); + } + const len = string.length; + const mustMatch = arguments.length > 2 && arguments[2] === true; + if (!mustMatch && len === 0) return 0; + + // Use a for loop to avoid recursion + let loweredCase = false; + for (;;) { + switch (encoding) { + case "ascii": + case "latin1": + case "binary": + return len; + case "utf8": + case "utf-8": + return utf8ToBytes(string).length; + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return len * 2; + case "hex": + return len >>> 1; + case "base64": + return base64ToBytes(string).length; + default: + if (loweredCase) { + return mustMatch ? -1 : utf8ToBytes(string).length; // assume utf8 + } + encoding = ("" + encoding).toLowerCase(); + loweredCase = true; + } + } + } + Buffer.byteLength = byteLength; + function slowToString(encoding, start, end) { + let loweredCase = false; + + // No need to verify that "this.length <= MAX_UINT32" since it's a read-only + // property of a typed array. + + // This behaves neither like String nor Uint8Array in that we set start/end + // to their upper/lower bounds if the value passed is out of range. + // undefined is handled specially as per ECMA-262 6th Edition, + // Section 13.3.3.7 Runtime Semantics: KeyedBindingInitialization. + if (start === undefined || start < 0) { + start = 0; + } + // Return early if start > this.length. Done here to prevent potential uint32 + // coercion fail below. + if (start > this.length) { + return ""; + } + if (end === undefined || end > this.length) { + end = this.length; + } + if (end <= 0) { + return ""; + } + + // Force coercion to uint32. This will also coerce falsey/NaN values to 0. + end >>>= 0; + start >>>= 0; + if (end <= start) { + return ""; + } + if (!encoding) encoding = "utf8"; + while (true) { + switch (encoding) { + case "hex": + return hexSlice(this, start, end); + case "utf8": + case "utf-8": + return utf8Slice(this, start, end); + case "ascii": + return asciiSlice(this, start, end); + case "latin1": + case "binary": + return latin1Slice(this, start, end); + case "base64": + return base64Slice(this, start, end); + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return utf16leSlice(this, start, end); + default: + if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); + encoding = (encoding + "").toLowerCase(); + loweredCase = true; + } + } + } + + // This property is used by `Buffer.isBuffer` (and the `is-buffer` npm package) + // to detect a Buffer instance. It's not possible to use `instanceof Buffer` + // reliably in a browserify context because there could be multiple different + // copies of the 'buffer' package in use. This method works even for Buffer + // instances that were created from another copy of the `buffer` package. + // See: https://github.com/feross/buffer/issues/154 + Buffer.prototype._isBuffer = true; + function swap(b, n, m) { + const i = b[n]; + b[n] = b[m]; + b[m] = i; + } + Buffer.prototype.swap16 = function swap16() { + const len = this.length; + if (len % 2 !== 0) { + throw new RangeError("Buffer size must be a multiple of 16-bits"); + } + for (let i = 0; i < len; i += 2) { + swap(this, i, i + 1); + } + return this; + }; + Buffer.prototype.swap32 = function swap32() { + const len = this.length; + if (len % 4 !== 0) { + throw new RangeError("Buffer size must be a multiple of 32-bits"); + } + for (let i = 0; i < len; i += 4) { + swap(this, i, i + 3); + swap(this, i + 1, i + 2); + } + return this; + }; + Buffer.prototype.swap64 = function swap64() { + const len = this.length; + if (len % 8 !== 0) { + throw new RangeError("Buffer size must be a multiple of 64-bits"); + } + for (let i = 0; i < len; i += 8) { + swap(this, i, i + 7); + swap(this, i + 1, i + 6); + swap(this, i + 2, i + 5); + swap(this, i + 3, i + 4); + } + return this; + }; + Buffer.prototype.toString = function toString() { + const length = this.length; + if (length === 0) return ""; + if (arguments.length === 0) return utf8Slice(this, 0, length); + return slowToString.apply(this, arguments); + }; + Buffer.prototype.toLocaleString = Buffer.prototype.toString; + Buffer.prototype.equals = function equals(b) { + if (!Buffer.isBuffer(b)) throw new TypeError("Argument must be a Buffer"); + if (this === b) return true; + return Buffer.compare(this, b) === 0; + }; + Buffer.prototype.inspect = function inspect() { + let str = ""; + const max = exports.INSPECT_MAX_BYTES; + str = this.toString("hex", 0, max).replace(/(.{2})/g, "$1 ").trim(); + if (this.length > max) str += " ... "; + return ""; + }; + if (customInspectSymbol) { + Buffer.prototype[customInspectSymbol] = Buffer.prototype.inspect; + } + Buffer.prototype.compare = function compare(target, start, end, thisStart, thisEnd) { + if (isInstance(target, Uint8Array)) { + target = Buffer.from(target, target.offset, target.byteLength); + } + if (!Buffer.isBuffer(target)) { + throw new TypeError("The \"target\" argument must be one of type Buffer or Uint8Array. " + "Received type " + typeof target); + } + if (start === undefined) { + start = 0; + } + if (end === undefined) { + end = target ? target.length : 0; + } + if (thisStart === undefined) { + thisStart = 0; + } + if (thisEnd === undefined) { + thisEnd = this.length; + } + if (start < 0 || end > target.length || thisStart < 0 || thisEnd > this.length) { + throw new RangeError("out of range index"); + } + if (thisStart >= thisEnd && start >= end) { + return 0; + } + if (thisStart >= thisEnd) { + return -1; + } + if (start >= end) { + return 1; + } + start >>>= 0; + end >>>= 0; + thisStart >>>= 0; + thisEnd >>>= 0; + if (this === target) return 0; + let x = thisEnd - thisStart; + let y = end - start; + const len = Math.min(x, y); + const thisCopy = this.slice(thisStart, thisEnd); + const targetCopy = target.slice(start, end); + for (let i = 0; i < len; ++i) { + if (thisCopy[i] !== targetCopy[i]) { + x = thisCopy[i]; + y = targetCopy[i]; + break; + } + } + if (x < y) return -1; + if (y < x) return 1; + return 0; + }; + + // Finds either the first index of `val` in `buffer` at offset >= `byteOffset`, + // OR the last index of `val` in `buffer` at offset <= `byteOffset`. + // + // Arguments: + // - buffer - a Buffer to search + // - val - a string, Buffer, or number + // - byteOffset - an index into `buffer`; will be clamped to an int32 + // - encoding - an optional encoding, relevant is val is a string + // - dir - true for indexOf, false for lastIndexOf + function bidirectionalIndexOf(buffer, val, byteOffset, encoding, dir) { + // Empty buffer means no match + if (buffer.length === 0) return -1; + + // Normalize byteOffset + if (typeof byteOffset === "string") { + encoding = byteOffset; + byteOffset = 0; + } else if (byteOffset > 2147483647) { + byteOffset = 2147483647; + } else if (byteOffset < -2147483648) { + byteOffset = -2147483648; + } + byteOffset = +byteOffset; // Coerce to Number. + if (numberIsNaN(byteOffset)) { + // byteOffset: it it's undefined, null, NaN, "foo", etc, search whole buffer + byteOffset = dir ? 0 : buffer.length - 1; + } + + // Normalize byteOffset: negative offsets start from the end of the buffer + if (byteOffset < 0) byteOffset = buffer.length + byteOffset; + if (byteOffset >= buffer.length) { + if (dir) return -1;else byteOffset = buffer.length - 1; + } else if (byteOffset < 0) { + if (dir) byteOffset = 0;else return -1; + } + + // Normalize val + if (typeof val === "string") { + val = Buffer.from(val, encoding); + } + + // Finally, search either indexOf (if dir is true) or lastIndexOf + if (Buffer.isBuffer(val)) { + // Special case: looking for empty string/buffer always fails + if (val.length === 0) { + return -1; + } + return arrayIndexOf(buffer, val, byteOffset, encoding, dir); + } else if (typeof val === "number") { + val = val & 255; // Search for a byte value [0-255] + if (typeof Uint8Array.prototype.indexOf === "function") { + if (dir) { + return Uint8Array.prototype.indexOf.call(buffer, val, byteOffset); + } else { + return Uint8Array.prototype.lastIndexOf.call(buffer, val, byteOffset); + } + } + return arrayIndexOf(buffer, [val], byteOffset, encoding, dir); + } + throw new TypeError("val must be string, number or Buffer"); + } + function arrayIndexOf(arr, val, byteOffset, encoding, dir) { + let indexSize = 1; + let arrLength = arr.length; + let valLength = val.length; + if (encoding !== undefined) { + encoding = String(encoding).toLowerCase(); + if (encoding === "ucs2" || encoding === "ucs-2" || encoding === "utf16le" || encoding === "utf-16le") { + if (arr.length < 2 || val.length < 2) { + return -1; + } + indexSize = 2; + arrLength /= 2; + valLength /= 2; + byteOffset /= 2; + } + } + function read(buf, i) { + if (indexSize === 1) { + return buf[i]; + } else { + return buf.readUInt16BE(i * indexSize); + } + } + let i; + if (dir) { + let foundIndex = -1; + for (i = byteOffset; i < arrLength; i++) { + if (read(arr, i) === read(val, foundIndex === -1 ? 0 : i - foundIndex)) { + if (foundIndex === -1) foundIndex = i; + if (i - foundIndex + 1 === valLength) return foundIndex * indexSize; + } else { + if (foundIndex !== -1) i -= i - foundIndex; + foundIndex = -1; + } + } + } else { + if (byteOffset + valLength > arrLength) byteOffset = arrLength - valLength; + for (i = byteOffset; i >= 0; i--) { + let found = true; + for (let j = 0; j < valLength; j++) { + if (read(arr, i + j) !== read(val, j)) { + found = false; + break; + } + } + if (found) return i; + } + } + return -1; + } + Buffer.prototype.includes = function includes(val, byteOffset, encoding) { + return this.indexOf(val, byteOffset, encoding) !== -1; + }; + Buffer.prototype.indexOf = function indexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, true); + }; + Buffer.prototype.lastIndexOf = function lastIndexOf(val, byteOffset, encoding) { + return bidirectionalIndexOf(this, val, byteOffset, encoding, false); + }; + function hexWrite(buf, string, offset, length) { + offset = Number(offset) || 0; + const remaining = buf.length - offset; + if (!length) { + length = remaining; + } else { + length = Number(length); + if (length > remaining) { + length = remaining; + } + } + const strLen = string.length; + if (length > strLen / 2) { + length = strLen / 2; + } + let i; + for (i = 0; i < length; ++i) { + const parsed = parseInt(string.substr(i * 2, 2), 16); + if (numberIsNaN(parsed)) return i; + buf[offset + i] = parsed; + } + return i; + } + function utf8Write(buf, string, offset, length) { + return blitBuffer(utf8ToBytes(string, buf.length - offset), buf, offset, length); + } + function asciiWrite(buf, string, offset, length) { + return blitBuffer(asciiToBytes(string), buf, offset, length); + } + function base64Write(buf, string, offset, length) { + return blitBuffer(base64ToBytes(string), buf, offset, length); + } + function ucs2Write(buf, string, offset, length) { + return blitBuffer(utf16leToBytes(string, buf.length - offset), buf, offset, length); + } + Buffer.prototype.write = function write(string, offset, length, encoding) { + // Buffer#write(string) + if (offset === undefined) { + encoding = "utf8"; + length = this.length; + offset = 0; + // Buffer#write(string, encoding) + } else if (length === undefined && typeof offset === "string") { + encoding = offset; + length = this.length; + offset = 0; + // Buffer#write(string, offset[, length][, encoding]) + } else if (isFinite(offset)) { + offset = offset >>> 0; + if (isFinite(length)) { + length = length >>> 0; + if (encoding === undefined) encoding = "utf8"; + } else { + encoding = length; + length = undefined; + } + } else { + throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported"); + } + const remaining = this.length - offset; + if (length === undefined || length > remaining) length = remaining; + if (string.length > 0 && (length < 0 || offset < 0) || offset > this.length) { + throw new RangeError("Attempt to write outside buffer bounds"); + } + if (!encoding) encoding = "utf8"; + let loweredCase = false; + for (;;) { + switch (encoding) { + case "hex": + return hexWrite(this, string, offset, length); + case "utf8": + case "utf-8": + return utf8Write(this, string, offset, length); + case "ascii": + case "latin1": + case "binary": + return asciiWrite(this, string, offset, length); + case "base64": + // Warning: maxLength not taken into account in base64Write + return base64Write(this, string, offset, length); + case "ucs2": + case "ucs-2": + case "utf16le": + case "utf-16le": + return ucs2Write(this, string, offset, length); + default: + if (loweredCase) throw new TypeError("Unknown encoding: " + encoding); + encoding = ("" + encoding).toLowerCase(); + loweredCase = true; + } + } + }; + Buffer.prototype.toJSON = function toJSON() { + return { + type: "Buffer", + data: Array.prototype.slice.call(this._arr || this, 0) + }; + }; + function base64Slice(buf, start, end) { + if (start === 0 && end === buf.length) { + return base64.fromByteArray(buf); + } else { + return base64.fromByteArray(buf.slice(start, end)); + } + } + function utf8Slice(buf, start, end) { + end = Math.min(buf.length, end); + const res = []; + let i = start; + while (i < end) { + const firstByte = buf[i]; + let codePoint = null; + let bytesPerSequence = firstByte > 239 ? 4 : firstByte > 223 ? 3 : firstByte > 191 ? 2 : 1; + if (i + bytesPerSequence <= end) { + let secondByte, thirdByte, fourthByte, tempCodePoint; + switch (bytesPerSequence) { + case 1: + if (firstByte < 128) { + codePoint = firstByte; + } + break; + case 2: + secondByte = buf[i + 1]; + if ((secondByte & 192) === 128) { + tempCodePoint = (firstByte & 31) << 6 | secondByte & 63; + if (tempCodePoint > 127) { + codePoint = tempCodePoint; + } + } + break; + case 3: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + if ((secondByte & 192) === 128 && (thirdByte & 192) === 128) { + tempCodePoint = (firstByte & 15) << 12 | (secondByte & 63) << 6 | thirdByte & 63; + if (tempCodePoint > 2047 && (tempCodePoint < 55296 || tempCodePoint > 57343)) { + codePoint = tempCodePoint; + } + } + break; + case 4: + secondByte = buf[i + 1]; + thirdByte = buf[i + 2]; + fourthByte = buf[i + 3]; + if ((secondByte & 192) === 128 && (thirdByte & 192) === 128 && (fourthByte & 192) === 128) { + tempCodePoint = (firstByte & 15) << 18 | (secondByte & 63) << 12 | (thirdByte & 63) << 6 | fourthByte & 63; + if (tempCodePoint > 65535 && tempCodePoint < 1114112) { + codePoint = tempCodePoint; + } + } + } + } + if (codePoint === null) { + // we did not generate a valid codePoint so insert a + // replacement char (U+FFFD) and advance only 1 byte + codePoint = 65533; + bytesPerSequence = 1; + } else if (codePoint > 65535) { + // encode to utf16 (surrogate pair dance) + codePoint -= 65536; + res.push(codePoint >>> 10 & 1023 | 55296); + codePoint = 56320 | codePoint & 1023; + } + res.push(codePoint); + i += bytesPerSequence; + } + return decodeCodePointsArray(res); + } + + // Based on http://stackoverflow.com/a/22747272/680742, the browser with + // the lowest limit is Chrome, with 0x10000 args. + // We go 1 magnitude less, for safety + const MAX_ARGUMENTS_LENGTH = 4096; + function decodeCodePointsArray(codePoints) { + const len = codePoints.length; + if (len <= MAX_ARGUMENTS_LENGTH) { + return String.fromCharCode.apply(String, codePoints); // avoid extra slice() + } + + // Decode in chunks to avoid "call stack size exceeded". + let res = ""; + let i = 0; + while (i < len) { + res += String.fromCharCode.apply(String, codePoints.slice(i, i += MAX_ARGUMENTS_LENGTH)); + } + return res; + } + function asciiSlice(buf, start, end) { + let ret = ""; + end = Math.min(buf.length, end); + for (let i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i] & 127); + } + return ret; + } + function latin1Slice(buf, start, end) { + let ret = ""; + end = Math.min(buf.length, end); + for (let i = start; i < end; ++i) { + ret += String.fromCharCode(buf[i]); + } + return ret; + } + function hexSlice(buf, start, end) { + const len = buf.length; + if (!start || start < 0) start = 0; + if (!end || end < 0 || end > len) end = len; + let out = ""; + for (let i = start; i < end; ++i) { + out += hexSliceLookupTable[buf[i]]; + } + return out; + } + function utf16leSlice(buf, start, end) { + const bytes = buf.slice(start, end); + let res = ""; + // If bytes.length is odd, the last 8 bits must be ignored (same as node.js) + for (let i = 0; i < bytes.length - 1; i += 2) { + res += String.fromCharCode(bytes[i] + bytes[i + 1] * 256); + } + return res; + } + Buffer.prototype.slice = function slice(start, end) { + const len = this.length; + start = ~~start; + end = end === undefined ? len : ~~end; + if (start < 0) { + start += len; + if (start < 0) start = 0; + } else if (start > len) { + start = len; + } + if (end < 0) { + end += len; + if (end < 0) end = 0; + } else if (end > len) { + end = len; + } + if (end < start) end = start; + const newBuf = this.subarray(start, end); + // Return an augmented `Uint8Array` instance + Object.setPrototypeOf(newBuf, Buffer.prototype); + return newBuf; + }; + + /* + * Need to make sure that buffer isn't trying to write out of bounds. + */ + function checkOffset(offset, ext, length) { + if (offset % 1 !== 0 || offset < 0) throw new RangeError("offset is not uint"); + if (offset + ext > length) throw new RangeError("Trying to access beyond buffer length"); + } + Buffer.prototype.readUintLE = Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let val = this[offset]; + let mul = 1; + let i = 0; + while (++i < byteLength && (mul *= 256)) { + val += this[offset + i] * mul; + } + return val; + }; + Buffer.prototype.readUintBE = Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + checkOffset(offset, byteLength, this.length); + } + let val = this[offset + --byteLength]; + let mul = 1; + while (byteLength > 0 && (mul *= 256)) { + val += this[offset + --byteLength] * mul; + } + return val; + }; + Buffer.prototype.readUint8 = Buffer.prototype.readUInt8 = function readUInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 1, this.length); + return this[offset]; + }; + Buffer.prototype.readUint16LE = Buffer.prototype.readUInt16LE = function readUInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + return this[offset] | this[offset + 1] << 8; + }; + Buffer.prototype.readUint16BE = Buffer.prototype.readUInt16BE = function readUInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + return this[offset] << 8 | this[offset + 1]; + }; + Buffer.prototype.readUint32LE = Buffer.prototype.readUInt32LE = function readUInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return (this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16) + this[offset + 3] * 16777216; + }; + Buffer.prototype.readUint32BE = Buffer.prototype.readUInt32BE = function readUInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return this[offset] * 16777216 + (this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]); + }; + Buffer.prototype.readBigUInt64LE = defineBigIntMethod(function readBigUInt64LE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) { + boundsError(offset, this.length - 8); + } + const lo = first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24; + const hi = this[++offset] + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + last * 2 ** 24; + return BigInt(lo) + (BigInt(hi) << BigInt(32)); + }); + Buffer.prototype.readBigUInt64BE = defineBigIntMethod(function readBigUInt64BE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) { + boundsError(offset, this.length - 8); + } + const hi = first * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset]; + const lo = this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last; + return (BigInt(hi) << BigInt(32)) + BigInt(lo); + }); + Buffer.prototype.readIntLE = function readIntLE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let val = this[offset]; + let mul = 1; + let i = 0; + while (++i < byteLength && (mul *= 256)) { + val += this[offset + i] * mul; + } + mul *= 128; + if (val >= mul) val -= Math.pow(2, 8 * byteLength); + return val; + }; + Buffer.prototype.readIntBE = function readIntBE(offset, byteLength, noAssert) { + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) checkOffset(offset, byteLength, this.length); + let i = byteLength; + let mul = 1; + let val = this[offset + --i]; + while (i > 0 && (mul *= 256)) { + val += this[offset + --i] * mul; + } + mul *= 128; + if (val >= mul) val -= Math.pow(2, 8 * byteLength); + return val; + }; + Buffer.prototype.readInt8 = function readInt8(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 1, this.length); + if (!(this[offset] & 128)) return this[offset]; + return (255 - this[offset] + 1) * -1; + }; + Buffer.prototype.readInt16LE = function readInt16LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + const val = this[offset] | this[offset + 1] << 8; + return val & 32768 ? val | 4294901760 : val; + }; + Buffer.prototype.readInt16BE = function readInt16BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 2, this.length); + const val = this[offset + 1] | this[offset] << 8; + return val & 32768 ? val | 4294901760 : val; + }; + Buffer.prototype.readInt32LE = function readInt32LE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return this[offset] | this[offset + 1] << 8 | this[offset + 2] << 16 | this[offset + 3] << 24; + }; + Buffer.prototype.readInt32BE = function readInt32BE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return this[offset] << 24 | this[offset + 1] << 16 | this[offset + 2] << 8 | this[offset + 3]; + }; + Buffer.prototype.readBigInt64LE = defineBigIntMethod(function readBigInt64LE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) { + boundsError(offset, this.length - 8); + } + const val = this[offset + 4] + this[offset + 5] * 2 ** 8 + this[offset + 6] * 2 ** 16 + (last << 24); // Overflow + + return (BigInt(val) << BigInt(32)) + BigInt(first + this[++offset] * 2 ** 8 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 24); + }); + Buffer.prototype.readBigInt64BE = defineBigIntMethod(function readBigInt64BE(offset) { + offset = offset >>> 0; + validateNumber(offset, "offset"); + const first = this[offset]; + const last = this[offset + 7]; + if (first === undefined || last === undefined) { + boundsError(offset, this.length - 8); + } + const val = (first << 24) + + // Overflow + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + this[++offset]; + return (BigInt(val) << BigInt(32)) + BigInt(this[++offset] * 2 ** 24 + this[++offset] * 2 ** 16 + this[++offset] * 2 ** 8 + last); + }); + Buffer.prototype.readFloatLE = function readFloatLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, true, 23, 4); + }; + Buffer.prototype.readFloatBE = function readFloatBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 4, this.length); + return ieee754.read(this, offset, false, 23, 4); + }; + Buffer.prototype.readDoubleLE = function readDoubleLE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, true, 52, 8); + }; + Buffer.prototype.readDoubleBE = function readDoubleBE(offset, noAssert) { + offset = offset >>> 0; + if (!noAssert) checkOffset(offset, 8, this.length); + return ieee754.read(this, offset, false, 52, 8); + }; + function checkInt(buf, value, offset, ext, max, min) { + if (!Buffer.isBuffer(buf)) throw new TypeError("\"buffer\" argument must be a Buffer instance"); + if (value > max || value < min) throw new RangeError("\"value\" argument is out of bounds"); + if (offset + ext > buf.length) throw new RangeError("Index out of range"); + } + Buffer.prototype.writeUintLE = Buffer.prototype.writeUIntLE = function writeUIntLE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + const maxBytes = Math.pow(2, 8 * byteLength) - 1; + checkInt(this, value, offset, byteLength, maxBytes, 0); + } + let mul = 1; + let i = 0; + this[offset] = value & 255; + while (++i < byteLength && (mul *= 256)) { + this[offset + i] = value / mul & 255; + } + return offset + byteLength; + }; + Buffer.prototype.writeUintBE = Buffer.prototype.writeUIntBE = function writeUIntBE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + byteLength = byteLength >>> 0; + if (!noAssert) { + const maxBytes = Math.pow(2, 8 * byteLength) - 1; + checkInt(this, value, offset, byteLength, maxBytes, 0); + } + let i = byteLength - 1; + let mul = 1; + this[offset + i] = value & 255; + while (--i >= 0 && (mul *= 256)) { + this[offset + i] = value / mul & 255; + } + return offset + byteLength; + }; + Buffer.prototype.writeUint8 = Buffer.prototype.writeUInt8 = function writeUInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 1, 255, 0); + this[offset] = value & 255; + return offset + 1; + }; + Buffer.prototype.writeUint16LE = Buffer.prototype.writeUInt16LE = function writeUInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); + this[offset] = value & 255; + this[offset + 1] = value >>> 8; + return offset + 2; + }; + Buffer.prototype.writeUint16BE = Buffer.prototype.writeUInt16BE = function writeUInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 65535, 0); + this[offset] = value >>> 8; + this[offset + 1] = value & 255; + return offset + 2; + }; + Buffer.prototype.writeUint32LE = Buffer.prototype.writeUInt32LE = function writeUInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); + this[offset + 3] = value >>> 24; + this[offset + 2] = value >>> 16; + this[offset + 1] = value >>> 8; + this[offset] = value & 255; + return offset + 4; + }; + Buffer.prototype.writeUint32BE = Buffer.prototype.writeUInt32BE = function writeUInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 4294967295, 0); + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 255; + return offset + 4; + }; + function wrtBigUInt64LE(buf, value, offset, min, max) { + checkIntBI(value, min, max, buf, offset, 7); + let lo = Number(value & BigInt(4294967295)); + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + lo = lo >> 8; + buf[offset++] = lo; + let hi = Number(value >> BigInt(32) & BigInt(4294967295)); + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + hi = hi >> 8; + buf[offset++] = hi; + return offset; + } + function wrtBigUInt64BE(buf, value, offset, min, max) { + checkIntBI(value, min, max, buf, offset, 7); + let lo = Number(value & BigInt(4294967295)); + buf[offset + 7] = lo; + lo = lo >> 8; + buf[offset + 6] = lo; + lo = lo >> 8; + buf[offset + 5] = lo; + lo = lo >> 8; + buf[offset + 4] = lo; + let hi = Number(value >> BigInt(32) & BigInt(4294967295)); + buf[offset + 3] = hi; + hi = hi >> 8; + buf[offset + 2] = hi; + hi = hi >> 8; + buf[offset + 1] = hi; + hi = hi >> 8; + buf[offset] = hi; + return offset + 8; + } + Buffer.prototype.writeBigUInt64LE = defineBigIntMethod(function writeBigUInt64LE(value, offset = 0) { + return wrtBigUInt64LE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff")); + }); + Buffer.prototype.writeBigUInt64BE = defineBigIntMethod(function writeBigUInt64BE(value, offset = 0) { + return wrtBigUInt64BE(this, value, offset, BigInt(0), BigInt("0xffffffffffffffff")); + }); + Buffer.prototype.writeIntLE = function writeIntLE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + const limit = Math.pow(2, 8 * byteLength - 1); + checkInt(this, value, offset, byteLength, limit - 1, -limit); + } + let i = 0; + let mul = 1; + let sub = 0; + this[offset] = value & 255; + while (++i < byteLength && (mul *= 256)) { + if (value < 0 && sub === 0 && this[offset + i - 1] !== 0) { + sub = 1; + } + this[offset + i] = (value / mul >> 0) - sub & 255; + } + return offset + byteLength; + }; + Buffer.prototype.writeIntBE = function writeIntBE(value, offset, byteLength, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + const limit = Math.pow(2, 8 * byteLength - 1); + checkInt(this, value, offset, byteLength, limit - 1, -limit); + } + let i = byteLength - 1; + let mul = 1; + let sub = 0; + this[offset + i] = value & 255; + while (--i >= 0 && (mul *= 256)) { + if (value < 0 && sub === 0 && this[offset + i + 1] !== 0) { + sub = 1; + } + this[offset + i] = (value / mul >> 0) - sub & 255; + } + return offset + byteLength; + }; + Buffer.prototype.writeInt8 = function writeInt8(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 1, 127, -128); + if (value < 0) value = 255 + value + 1; + this[offset] = value & 255; + return offset + 1; + }; + Buffer.prototype.writeInt16LE = function writeInt16LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); + this[offset] = value & 255; + this[offset + 1] = value >>> 8; + return offset + 2; + }; + Buffer.prototype.writeInt16BE = function writeInt16BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 2, 32767, -32768); + this[offset] = value >>> 8; + this[offset + 1] = value & 255; + return offset + 2; + }; + Buffer.prototype.writeInt32LE = function writeInt32LE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); + this[offset] = value & 255; + this[offset + 1] = value >>> 8; + this[offset + 2] = value >>> 16; + this[offset + 3] = value >>> 24; + return offset + 4; + }; + Buffer.prototype.writeInt32BE = function writeInt32BE(value, offset, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) checkInt(this, value, offset, 4, 2147483647, -2147483648); + if (value < 0) value = 4294967295 + value + 1; + this[offset] = value >>> 24; + this[offset + 1] = value >>> 16; + this[offset + 2] = value >>> 8; + this[offset + 3] = value & 255; + return offset + 4; + }; + Buffer.prototype.writeBigInt64LE = defineBigIntMethod(function writeBigInt64LE(value, offset = 0) { + return wrtBigUInt64LE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); + }); + Buffer.prototype.writeBigInt64BE = defineBigIntMethod(function writeBigInt64BE(value, offset = 0) { + return wrtBigUInt64BE(this, value, offset, -BigInt("0x8000000000000000"), BigInt("0x7fffffffffffffff")); + }); + function checkIEEE754(buf, value, offset, ext, max, min) { + if (offset + ext > buf.length) throw new RangeError("Index out of range"); + if (offset < 0) throw new RangeError("Index out of range"); + } + function writeFloat(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + checkIEEE754(buf, value, offset, 4); + } + ieee754.write(buf, value, offset, littleEndian, 23, 4); + return offset + 4; + } + Buffer.prototype.writeFloatLE = function writeFloatLE(value, offset, noAssert) { + return writeFloat(this, value, offset, true, noAssert); + }; + Buffer.prototype.writeFloatBE = function writeFloatBE(value, offset, noAssert) { + return writeFloat(this, value, offset, false, noAssert); + }; + function writeDouble(buf, value, offset, littleEndian, noAssert) { + value = +value; + offset = offset >>> 0; + if (!noAssert) { + checkIEEE754(buf, value, offset, 8); + } + ieee754.write(buf, value, offset, littleEndian, 52, 8); + return offset + 8; + } + Buffer.prototype.writeDoubleLE = function writeDoubleLE(value, offset, noAssert) { + return writeDouble(this, value, offset, true, noAssert); + }; + Buffer.prototype.writeDoubleBE = function writeDoubleBE(value, offset, noAssert) { + return writeDouble(this, value, offset, false, noAssert); + }; + + // copy(targetBuffer, targetStart=0, sourceStart=0, sourceEnd=buffer.length) + Buffer.prototype.copy = function copy(target, targetStart, start, end) { + if (!Buffer.isBuffer(target)) throw new TypeError("argument should be a Buffer"); + if (!start) start = 0; + if (!end && end !== 0) end = this.length; + if (targetStart >= target.length) targetStart = target.length; + if (!targetStart) targetStart = 0; + if (end > 0 && end < start) end = start; + + // Copy 0 bytes; we're done + if (end === start) return 0; + if (target.length === 0 || this.length === 0) return 0; + + // Fatal error conditions + if (targetStart < 0) { + throw new RangeError("targetStart out of bounds"); + } + if (start < 0 || start >= this.length) throw new RangeError("Index out of range"); + if (end < 0) throw new RangeError("sourceEnd out of bounds"); + + // Are we oob? + if (end > this.length) end = this.length; + if (target.length - targetStart < end - start) { + end = target.length - targetStart + start; + } + const len = end - start; + if (this === target && typeof Uint8Array.prototype.copyWithin === "function") { + // Use built-in when available, missing from IE11 + this.copyWithin(targetStart, start, end); + } else { + Uint8Array.prototype.set.call(target, this.subarray(start, end), targetStart); + } + return len; + }; + + // Usage: + // buffer.fill(number[, offset[, end]]) + // buffer.fill(buffer[, offset[, end]]) + // buffer.fill(string[, offset[, end]][, encoding]) + Buffer.prototype.fill = function fill(val, start, end, encoding) { + // Handle string cases: + if (typeof val === "string") { + if (typeof start === "string") { + encoding = start; + start = 0; + end = this.length; + } else if (typeof end === "string") { + encoding = end; + end = this.length; + } + if (encoding !== undefined && typeof encoding !== "string") { + throw new TypeError("encoding must be a string"); + } + if (typeof encoding === "string" && !Buffer.isEncoding(encoding)) { + throw new TypeError("Unknown encoding: " + encoding); + } + if (val.length === 1) { + const code = val.charCodeAt(0); + if (encoding === "utf8" && code < 128 || encoding === "latin1") { + // Fast path: If `val` fits into a single byte, use that numeric value. + val = code; + } + } + } else if (typeof val === "number") { + val = val & 255; + } else if (typeof val === "boolean") { + val = Number(val); + } + + // Invalid ranges are not set to a default, so can range check early. + if (start < 0 || this.length < start || this.length < end) { + throw new RangeError("Out of range index"); + } + if (end <= start) { + return this; + } + start = start >>> 0; + end = end === undefined ? this.length : end >>> 0; + if (!val) val = 0; + let i; + if (typeof val === "number") { + for (i = start; i < end; ++i) { + this[i] = val; + } + } else { + const bytes = Buffer.isBuffer(val) ? val : Buffer.from(val, encoding); + const len = bytes.length; + if (len === 0) { + throw new TypeError("The value \"" + val + "\" is invalid for argument \"value\""); + } + for (i = 0; i < end - start; ++i) { + this[i + start] = bytes[i % len]; + } + } + return this; + }; + + // CUSTOM ERRORS + // ============= + + // Simplified versions from Node, changed for Buffer-only usage + const errors = {}; + function E(sym, getMessage, Base) { + errors[sym] = class NodeError extends Base { + constructor() { + super(); + Object.defineProperty(this, "message", { + value: getMessage.apply(this, arguments), + writable: true, + configurable: true + }); + + // Add the error code to the name to include it in the stack trace. + this.name = `${this.name} [${sym}]`; + // Access the stack to generate the error message including the error code + // from the name. + this.stack; // eslint-disable-line no-unused-expressions + // Reset the name to the actual name. + delete this.name; + } + get code() { + return sym; + } + set code(value) { + Object.defineProperty(this, "code", { + configurable: true, + enumerable: true, + value, + writable: true + }); + } + toString() { + return `${this.name} [${sym}]: ${this.message}`; + } + }; + } + E("ERR_BUFFER_OUT_OF_BOUNDS", function (name) { + if (name) { + return `${name} is outside of buffer bounds`; + } + return "Attempt to access memory outside buffer bounds"; + }, RangeError); + E("ERR_INVALID_ARG_TYPE", function (name, actual) { + return `The "${name}" argument must be of type number. Received type ${typeof actual}`; + }, TypeError); + E("ERR_OUT_OF_RANGE", function (str, range, input) { + let msg = `The value of "${str}" is out of range.`; + let received = input; + if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) { + received = addNumericalSeparator(String(input)); + } else if (typeof input === "bigint") { + received = String(input); + if (input > BigInt(2) ** BigInt(32) || input < -(BigInt(2) ** BigInt(32))) { + received = addNumericalSeparator(received); + } + received += "n"; + } + msg += ` It must be ${range}. Received ${received}`; + return msg; + }, RangeError); + function addNumericalSeparator(val) { + let res = ""; + let i = val.length; + const start = val[0] === "-" ? 1 : 0; + for (; i >= start + 4; i -= 3) { + res = `_${val.slice(i - 3, i)}${res}`; + } + return `${val.slice(0, i)}${res}`; + } + + // CHECK FUNCTIONS + // =============== + + function checkBounds(buf, offset, byteLength) { + validateNumber(offset, "offset"); + if (buf[offset] === undefined || buf[offset + byteLength] === undefined) { + boundsError(offset, buf.length - (byteLength + 1)); + } + } + function checkIntBI(value, min, max, buf, offset, byteLength) { + if (value > max || value < min) { + const n = typeof min === "bigint" ? "n" : ""; + let range; + { + if (min === 0 || min === BigInt(0)) { + range = `>= 0${n} and < 2${n} ** ${(byteLength + 1) * 8}${n}`; + } else { + range = `>= -(2${n} ** ${(byteLength + 1) * 8 - 1}${n}) and < 2 ** ` + `${(byteLength + 1) * 8 - 1}${n}`; + } + } + throw new errors.ERR_OUT_OF_RANGE("value", range, value); + } + checkBounds(buf, offset, byteLength); + } + function validateNumber(value, name) { + if (typeof value !== "number") { + throw new errors.ERR_INVALID_ARG_TYPE(name, "number", value); + } + } + function boundsError(value, length, type) { + if (Math.floor(value) !== value) { + validateNumber(value, type); + throw new errors.ERR_OUT_OF_RANGE("offset", "an integer", value); + } + if (length < 0) { + throw new errors.ERR_BUFFER_OUT_OF_BOUNDS(); + } + throw new errors.ERR_OUT_OF_RANGE("offset", `>= ${0} and <= ${length}`, value); + } + + // HELPER FUNCTIONS + // ================ + + const INVALID_BASE64_RE = /[^+/0-9A-Za-z-_]/g; + function base64clean(str) { + // Node takes equal signs as end of the Base64 encoding + str = str.split("=")[0]; + // Node strips out invalid characters like \n and \t from the string, base64-js does not + str = str.trim().replace(INVALID_BASE64_RE, ""); + // Node converts strings with length < 2 to '' + if (str.length < 2) return ""; + // Node allows for non-padded base64 strings (missing trailing ===), base64-js does not + while (str.length % 4 !== 0) { + str = str + "="; + } + return str; + } + function utf8ToBytes(string, units) { + units = units || Infinity; + let codePoint; + const length = string.length; + let leadSurrogate = null; + const bytes = []; + for (let i = 0; i < length; ++i) { + codePoint = string.charCodeAt(i); + + // is surrogate component + if (codePoint > 55295 && codePoint < 57344) { + // last char was a lead + if (!leadSurrogate) { + // no lead yet + if (codePoint > 56319) { + // unexpected trail + if ((units -= 3) > -1) bytes.push(239, 191, 189); + continue; + } else if (i + 1 === length) { + // unpaired lead + if ((units -= 3) > -1) bytes.push(239, 191, 189); + continue; + } + + // valid lead + leadSurrogate = codePoint; + continue; + } + + // 2 leads in a row + if (codePoint < 56320) { + if ((units -= 3) > -1) bytes.push(239, 191, 189); + leadSurrogate = codePoint; + continue; + } + + // valid surrogate pair + codePoint = (leadSurrogate - 55296 << 10 | codePoint - 56320) + 65536; + } else if (leadSurrogate) { + // valid bmp char, but last char was a lead + if ((units -= 3) > -1) bytes.push(239, 191, 189); + } + leadSurrogate = null; + + // encode utf8 + if (codePoint < 128) { + if ((units -= 1) < 0) break; + bytes.push(codePoint); + } else if (codePoint < 2048) { + if ((units -= 2) < 0) break; + bytes.push(codePoint >> 6 | 192, codePoint & 63 | 128); + } else if (codePoint < 65536) { + if ((units -= 3) < 0) break; + bytes.push(codePoint >> 12 | 224, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); + } else if (codePoint < 1114112) { + if ((units -= 4) < 0) break; + bytes.push(codePoint >> 18 | 240, codePoint >> 12 & 63 | 128, codePoint >> 6 & 63 | 128, codePoint & 63 | 128); + } else { + throw new Error("Invalid code point"); + } + } + return bytes; + } + function asciiToBytes(str) { + const byteArray = []; + for (let i = 0; i < str.length; ++i) { + // Node's code seems to be doing this and not & 0x7F.. + byteArray.push(str.charCodeAt(i) & 255); + } + return byteArray; + } + function utf16leToBytes(str, units) { + let c, hi, lo; + const byteArray = []; + for (let i = 0; i < str.length; ++i) { + if ((units -= 2) < 0) break; + c = str.charCodeAt(i); + hi = c >> 8; + lo = c % 256; + byteArray.push(lo); + byteArray.push(hi); + } + return byteArray; + } + function base64ToBytes(str) { + return base64.toByteArray(base64clean(str)); + } + function blitBuffer(src, dst, offset, length) { + let i; + for (i = 0; i < length; ++i) { + if (i + offset >= dst.length || i >= src.length) break; + dst[i + offset] = src[i]; + } + return i; + } + + // ArrayBuffer or Uint8Array objects from other contexts (i.e. iframes) do not pass + // the `instanceof` check but they should be treated as of that type. + // See: https://github.com/feross/buffer/issues/166 + function isInstance(obj, type) { + return obj instanceof type || obj != null && obj.constructor != null && obj.constructor.name != null && obj.constructor.name === type.name; + } + function numberIsNaN(obj) { + // For IE11 support + return obj !== obj; // eslint-disable-line no-self-compare + } + + // Create lookup table for `toString('hex')` + // See: https://github.com/feross/buffer/issues/219 + const hexSliceLookupTable = function () { + const alphabet = "0123456789abcdef"; + const table = new Array(256); + for (let i = 0; i < 16; ++i) { + const i16 = i * 16; + for (let j = 0; j < 16; ++j) { + table[i16 + j] = alphabet[i] + alphabet[j]; + } + } + return table; + }(); + + // Return not function with Error if BigInt not supported + function defineBigIntMethod(fn) { + return typeof BigInt === "undefined" ? BufferBigIntNotDefined : fn; + } + function BufferBigIntNotDefined() { + throw new Error("BigInt not supported"); + } + return exports; +} + +export { dew as d }; diff --git a/nodelibs/browser/chunk-aBeyrThb.js b/nodelibs/browser/chunk-aBeyrThb.js deleted file mode 100644 index 264b084..0000000 --- a/nodelibs/browser/chunk-aBeyrThb.js +++ /dev/null @@ -1,20 +0,0 @@ -import { a as dew$1, c as dew$2, e as dew$3, f as dew$4, g as dew$5, h as dew$6, i as dew$7 } from './chunk-CU2hd6BF.js'; - -var exports = {}, - _dewExec = false; -function dew() { - if (_dewExec) return exports; - _dewExec = true; - exports = exports = dew$1(); - exports.Stream = exports; - exports.Readable = exports; - exports.Writable = dew$2(); - exports.Duplex = dew$3(); - exports.Transform = dew$4(); - exports.PassThrough = dew$5(); - exports.finished = dew$6(); - exports.pipeline = dew$7(); - return exports; -} - -export { dew as d }; diff --git a/nodelibs/browser/console.js b/nodelibs/browser/console.js index db18fb6..bad254f 100644 --- a/nodelibs/browser/console.js +++ b/nodelibs/browser/console.js @@ -1,30 +1,22 @@ -import './util.js'; -import et from './assert.js'; -import { X } from './chunk-D04hy_Cu.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-DEckhzyo.js'; +import './chunk-CbQqNoLO.js'; +import { e as et } from './chunk-CjPlbOtt.js'; +import { X } from './chunk-D3uu3VYh.js'; var exports$1 = {}, - _dewExec = false; - + _dewExec = false; var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew() { if (_dewExec) return exports$1; _dewExec = true; - /*global window, global*/ var util = X; var assert = et; - function now() { return new Date().getTime(); } - var slice = Array.prototype.slice; var console; var times = {}; - if (typeof _global !== "undefined" && _global.console) { console = _global.console; } else if (typeof window !== "undefined" && window.console) { @@ -32,69 +24,53 @@ function dew() { } else { console = {}; } - var functions = [[log, "log"], [info, "info"], [warn, "warn"], [error, "error"], [time, "time"], [timeEnd, "timeEnd"], [trace, "trace"], [dir, "dir"], [consoleAssert, "assert"]]; - for (var i = 0; i < functions.length; i++) { var tuple = functions[i]; var f = tuple[0]; var name = tuple[1]; - if (!console[name]) { console[name] = f; } } - exports$1 = console; - function log() {} - function info() { console.log.apply(console, arguments); } - function warn() { console.log.apply(console, arguments); } - function error() { console.warn.apply(console, arguments); } - function time(label) { times[label] = now(); } - function timeEnd(label) { var time = times[label]; - if (!time) { throw new Error("No such label: " + label); } - delete times[label]; var duration = now() - time; console.log(label + ": " + duration + "ms"); } - function trace() { var err = new Error(); err.name = "Trace"; err.message = util.format.apply(null, arguments); console.error(err.stack); } - function dir(object) { console.log(util.inspect(object) + "\n"); } - function consoleAssert(expression) { if (!expression) { var arr = slice.call(arguments, 1); assert.ok(false, util.format.apply(null, arr)); } } - return exports$1; } diff --git a/nodelibs/browser/crypto.js b/nodelibs/browser/crypto.js index 0fcde09..d9242ad 100644 --- a/nodelibs/browser/crypto.js +++ b/nodelibs/browser/crypto.js @@ -1,125 +1,46 @@ -import { b as buffer, d as dew$2R } from './chunk-CU2hd6BF.js'; -import { p as process } from './chunk-b0rmRow7.js'; -import { d as dew$2Q } from './chunk-aBeyrThb.js'; +import { d as dew$3H, e as exports$3J } from './chunk-CcCWfKp1.js'; +import { p as process } from './chunk-DEMDiNwt.js'; +import { d as dew$3I } from './chunk-CkFCi-G1.js'; +import { e as exports$3I } from './chunk-B6-G-Ftj.js'; +import { d as dew$3J } from './chunk-DtuTasat.js'; +import { e as e$1$2, a as e$1$1$1, u as u$q, b as buffer, d as dew$f$4 } from './chunk-B738Er4n.js'; +import { p as process$1 } from './chunk-b0rmRow7.js'; +import { d as dew$3K } from './chunk-C4rKjYLo.js'; import { y as y$o } from './chunk-tHuMsdT0.js'; -import { e as e$1$1$1, a as e$1$2, u as u$q } from './chunk-C9hMJ5VR.js'; -import { p as promisify } from './chunk-BZgdGiNw.js'; -import { X as X$5, t as t$2$2 } from './chunk-D04hy_Cu.js'; -import { T as T$9 } from './chunk-DEckhzyo.js'; - -var exports$2Q = {}, - _dewExec$2P = false; -function dew$2P() { - if (_dewExec$2P) return exports$2Q; - _dewExec$2P = true; - - /* eslint-disable node/no-deprecated-api */ - var buffer$1 = buffer; - var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers - - function copyProps(src, dst) { - for (var key in src) { - dst[key] = src[key]; - } - } - - if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - exports$2Q = buffer$1; - } else { - // Copy properties from require('buffer') - copyProps(buffer$1, exports$2Q); - exports$2Q.Buffer = SafeBuffer; - } - - function SafeBuffer(arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length); - } // Copy static methods from Buffer - - - copyProps(Buffer, SafeBuffer); - - SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === "number") { - throw new TypeError("Argument must not be a number"); - } - - return Buffer(arg, encodingOrOffset, length); - }; - - SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } - - var buf = Buffer(size); - - if (fill !== undefined) { - if (typeof encoding === "string") { - buf.fill(fill, encoding); - } else { - buf.fill(fill); - } - } else { - buf.fill(0); - } - - return buf; - }; - - SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } - - return Buffer(size); - }; - - SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } - - return buffer$1.SlowBuffer(size); - }; - - return exports$2Q; -} - -var exports$2P = {}, - _dewExec$2O = false; - -var _global$U = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2O() { - if (_dewExec$2O) return exports$2P; - _dewExec$2O = true; +import { p as promisify, X as X$5, t as t$2$2, T as T$9 } from './chunk-D3uu3VYh.js'; +import './chunk-DtDiafJB.js'; +import './chunk-CbQqNoLO.js'; +import { d as dew$3L } from './chunk-BsRZ0PEC.js'; +import exports$3K from './vm.js'; + +var exports$3H = {}, + _dewExec$3G = false; +var _global$1e = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3G() { + if (_dewExec$3G) return exports$3H; + _dewExec$3G = true; var process$1 = process; // limit of Crypto.getRandomValues() // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues - var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes - // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 + var MAX_BYTES = 65536; + // Node supports requesting up to this number of bytes + // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 var MAX_UINT32 = 4294967295; - function oldBrowser() { throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11"); } - - var Buffer = dew$2P().Buffer; - - var crypto = _global$U.crypto || _global$U.msCrypto; - + var Buffer = dew$3H().Buffer; + var crypto = _global$1e.crypto || _global$1e.msCrypto; if (crypto && crypto.getRandomValues) { - exports$2P = randomBytes; + exports$3H = randomBytes; } else { - exports$2P = oldBrowser; + exports$3H = oldBrowser; } - function randomBytes(size, cb) { // phantomjs needs to throw if (size > MAX_UINT32) throw new RangeError("requested too many random bytes"); var bytes = Buffer.allocUnsafe(size); - if (size > 0) { // getRandomValues fails on IE if size == 0 if (size > MAX_BYTES) { @@ -134,118 +55,29 @@ function dew$2O() { crypto.getRandomValues(bytes); } } - if (typeof cb === "function") { return process$1.nextTick(function () { cb(null, bytes); }); } - return bytes; } - - return exports$2P; -} - -var exports$2O = {}, - _dewExec$2N = false; -function dew$2N() { - if (_dewExec$2N) return exports$2O; - _dewExec$2N = true; - - /*! safe-buffer. MIT License. Feross Aboukhadijeh */ - - /* eslint-disable node/no-deprecated-api */ - var buffer$1 = buffer; - var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers - - function copyProps(src, dst) { - for (var key in src) { - dst[key] = src[key]; - } - } - - if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - exports$2O = buffer$1; - } else { - // Copy properties from require('buffer') - copyProps(buffer$1, exports$2O); - exports$2O.Buffer = SafeBuffer; - } - - function SafeBuffer(arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length); - } - - SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer - - copyProps(Buffer, SafeBuffer); - - SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === "number") { - throw new TypeError("Argument must not be a number"); - } - - return Buffer(arg, encodingOrOffset, length); - }; - - SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } - - var buf = Buffer(size); - - if (fill !== undefined) { - if (typeof encoding === "string") { - buf.fill(fill, encoding); - } else { - buf.fill(fill); - } - } else { - buf.fill(0); - } - - return buf; - }; - - SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } - - return Buffer(size); - }; - - SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } - - return buffer$1.SlowBuffer(size); - }; - - return exports$2O; + return exports$3H; } -var exports$2N = {}, - _dewExec$2M = false; -function dew$2M() { - if (_dewExec$2M) return exports$2N; - _dewExec$2M = true; - - var Buffer = dew$2N().Buffer; - - var Transform = dew$2Q().Transform; - - var inherits = dew$2R(); - +var exports$3G = {}, + _dewExec$3F = false; +function dew$3F() { + if (_dewExec$3F) return exports$3G; + _dewExec$3F = true; + var Buffer = dew$3H().Buffer; + var Transform = exports$3I.Transform; + var inherits = dew$3I(); function throwIfNotStringOrBuffer(val, prefix) { if (!Buffer.isBuffer(val) && typeof val !== "string") { throw new TypeError(prefix + " must be a string or a buffer"); } } - function HashBase(blockSize) { Transform.call(this); this._block = Buffer.allocUnsafe(blockSize); @@ -254,120 +86,92 @@ function dew$2M() { this._length = [0, 0, 0, 0]; this._finalized = false; } - inherits(HashBase, Transform); - HashBase.prototype._transform = function (chunk, encoding, callback) { var error = null; - try { this.update(chunk, encoding); } catch (err) { error = err; } - callback(error); }; - HashBase.prototype._flush = function (callback) { var error = null; - try { this.push(this.digest()); } catch (err) { error = err; } - callback(error); }; - HashBase.prototype.update = function (data, encoding) { throwIfNotStringOrBuffer(data, "Data"); if (this._finalized) throw new Error("Digest already called"); - if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data + if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); + // consume data var block = this._block; var offset = 0; - while (this._blockOffset + data.length - offset >= this._blockSize) { for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]; - this._update(); - this._blockOffset = 0; } + while (offset < data.length) block[this._blockOffset++] = data[offset++]; - while (offset < data.length) block[this._blockOffset++] = data[offset++]; // update length - - + // update length for (var j = 0, carry = data.length * 8; carry > 0; ++j) { this._length[j] += carry; carry = this._length[j] / 4294967296 | 0; if (carry > 0) this._length[j] -= 4294967296 * carry; } - return this; }; - HashBase.prototype._update = function () { throw new Error("_update is not implemented"); }; - HashBase.prototype.digest = function (encoding) { if (this._finalized) throw new Error("Digest already called"); this._finalized = true; - var digest = this._digest(); + if (encoding !== undefined) digest = digest.toString(encoding); - if (encoding !== undefined) digest = digest.toString(encoding); // reset state - + // reset state this._block.fill(0); - this._blockOffset = 0; - for (var i = 0; i < 4; ++i) this._length[i] = 0; - return digest; }; - HashBase.prototype._digest = function () { throw new Error("_digest is not implemented"); }; - - exports$2N = HashBase; - return exports$2N; + exports$3G = HashBase; + return exports$3G; } -var exports$2M = {}, - _dewExec$2L = false; -function dew$2L() { - if (_dewExec$2L) return exports$2M; - _dewExec$2L = true; - - var inherits = dew$2R(); - - var HashBase = dew$2M(); - - var Buffer = dew$2P().Buffer; - +var exports$3F = {}, + _dewExec$3E = false; +function dew$3E() { + if (_dewExec$3E) return exports$3F; + _dewExec$3E = true; + var inherits = dew$3I(); + var HashBase = dew$3F(); + var Buffer = dew$3H().Buffer; var ARRAY16 = new Array(16); - function MD5() { - HashBase.call(this, 64); // state + HashBase.call(this, 64); + // state this._a = 1732584193; this._b = 4023233417; this._c = 2562383102; this._d = 271733878; } - inherits(MD5, HashBase); - MD5.prototype._update = function () { var M = ARRAY16; - for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4); - var a = this._a; var b = this._b; var c = this._c; @@ -441,28 +245,20 @@ function dew$2L() { this._c = this._c + c | 0; this._d = this._d + d | 0; }; - MD5.prototype._digest = function () { // create padding and handle blocks this._block[this._blockOffset++] = 128; - if (this._blockOffset > 56) { this._block.fill(0, this._blockOffset, 64); - this._update(); - this._blockOffset = 0; } - this._block.fill(0, this._blockOffset, 56); - this._block.writeUInt32LE(this._length[0], 56); - this._block.writeUInt32LE(this._length[1], 60); + this._update(); - this._update(); // produce result - - + // produce result var buffer = Buffer.allocUnsafe(16); buffer.writeInt32LE(this._a, 0); buffer.writeInt32LE(this._b, 4); @@ -470,42 +266,33 @@ function dew$2L() { buffer.writeInt32LE(this._d, 12); return buffer; }; - function rotl(x, n) { return x << n | x >>> 32 - n; } - function fnF(a, b, c, d, m, k, s) { return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0; } - function fnG(a, b, c, d, m, k, s) { return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0; } - function fnH(a, b, c, d, m, k, s) { return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0; } - function fnI(a, b, c, d, m, k, s) { return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0; } - - exports$2M = MD5; - return exports$2M; + exports$3F = MD5; + return exports$3F; } -var exports$2L = {}, - _dewExec$2K = false; -function dew$2K() { - if (_dewExec$2K) return exports$2L; - _dewExec$2K = true; - var Buffer = buffer.Buffer; - - var inherits = dew$2R(); - - var HashBase = dew$2M(); - +var exports$3E = {}, + _dewExec$3D = false; +function dew$3D() { + if (_dewExec$3D) return exports$3E; + _dewExec$3D = true; + var Buffer = dew$3J().Buffer; + var inherits = dew$3I(); + var HashBase = dew$3F(); var ARRAY16 = new Array(16); var zl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]; var zr = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; @@ -513,24 +300,20 @@ function dew$2K() { var sr = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; var hl = [0, 1518500249, 1859775393, 2400959708, 2840853838]; var hr = [1352829926, 1548603684, 1836072691, 2053994217, 0]; - function RIPEMD160() { - HashBase.call(this, 64); // state + HashBase.call(this, 64); + // state this._a = 1732584193; this._b = 4023233417; this._c = 2562383102; this._d = 271733878; this._e = 3285377520; } - inherits(RIPEMD160, HashBase); - RIPEMD160.prototype._update = function () { var words = ARRAY16; - for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4); - var al = this._a | 0; var bl = this._b | 0; var cl = this._c | 0; @@ -540,12 +323,12 @@ function dew$2K() { var br = this._b | 0; var cr = this._c | 0; var dr = this._d | 0; - var er = this._e | 0; // computation + var er = this._e | 0; + // computation for (var i = 0; i < 80; i += 1) { var tl; var tr; - if (i < 16) { tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]); tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]); @@ -563,7 +346,6 @@ function dew$2K() { tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]); tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]); } - al = el; el = dl; dl = rotl(cl, 10); @@ -574,9 +356,9 @@ function dew$2K() { dr = rotl(cr, 10); cr = br; br = tr; - } // update state - + } + // update state var t = this._b + cl + dr | 0; this._b = this._c + dl + er | 0; this._c = this._d + el + ar | 0; @@ -584,28 +366,20 @@ function dew$2K() { this._e = this._a + bl + cr | 0; this._a = t; }; - RIPEMD160.prototype._digest = function () { // create padding and handle blocks this._block[this._blockOffset++] = 128; - if (this._blockOffset > 56) { this._block.fill(0, this._blockOffset, 64); - this._update(); - this._blockOffset = 0; } - this._block.fill(0, this._blockOffset, 56); - this._block.writeUInt32LE(this._length[0], 56); - this._block.writeUInt32LE(this._length[1], 60); + this._update(); - this._update(); // produce result - - + // produce result var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20); buffer.writeInt32LE(this._a, 0); buffer.writeInt32LE(this._b, 4); @@ -614,136 +388,108 @@ function dew$2K() { buffer.writeInt32LE(this._e, 16); return buffer; }; - function rotl(x, n) { return x << n | x >>> 32 - n; } - function fn1(a, b, c, d, e, m, k, s) { return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0; } - function fn2(a, b, c, d, e, m, k, s) { return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0; } - function fn3(a, b, c, d, e, m, k, s) { return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0; } - function fn4(a, b, c, d, e, m, k, s) { return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0; } - function fn5(a, b, c, d, e, m, k, s) { return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0; } - - exports$2L = RIPEMD160; - return exports$2L; + exports$3E = RIPEMD160; + return exports$3E; } -var exports$2K = {}, - _dewExec$2J = false; - -var _global$T = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2J() { - if (_dewExec$2J) return exports$2K; - _dewExec$2J = true; - - var Buffer = dew$2P().Buffer; // prototype class for hash functions - +var exports$3D = {}, + _dewExec$3C = false; +var _global$1d = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3C() { + if (_dewExec$3C) return exports$3D; + _dewExec$3C = true; + var Buffer = dew$3H().Buffer; + // prototype class for hash functions function Hash(blockSize, finalSize) { - (this || _global$T)._block = Buffer.alloc(blockSize); - (this || _global$T)._finalSize = finalSize; - (this || _global$T)._blockSize = blockSize; - (this || _global$T)._len = 0; + (this || _global$1d)._block = Buffer.alloc(blockSize); + (this || _global$1d)._finalSize = finalSize; + (this || _global$1d)._blockSize = blockSize; + (this || _global$1d)._len = 0; } - Hash.prototype.update = function (data, enc) { if (typeof data === "string") { enc = enc || "utf8"; data = Buffer.from(data, enc); } - - var block = (this || _global$T)._block; - var blockSize = (this || _global$T)._blockSize; + var block = (this || _global$1d)._block; + var blockSize = (this || _global$1d)._blockSize; var length = data.length; - var accum = (this || _global$T)._len; - + var accum = (this || _global$1d)._len; for (var offset = 0; offset < length;) { var assigned = accum % blockSize; var remainder = Math.min(length - offset, blockSize - assigned); - for (var i = 0; i < remainder; i++) { block[assigned + i] = data[offset + i]; } - accum += remainder; offset += remainder; - if (accum % blockSize === 0) { this._update(block); } } - - (this || _global$T)._len += length; - return this || _global$T; + (this || _global$1d)._len += length; + return this || _global$1d; }; - Hash.prototype.digest = function (enc) { - var rem = (this || _global$T)._len % (this || _global$T)._blockSize; - (this || _global$T)._block[rem] = 128; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest - // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize - - (this || _global$T)._block.fill(0, rem + 1); - - if (rem >= (this || _global$T)._finalSize) { - this._update((this || _global$T)._block); + var rem = (this || _global$1d)._len % (this || _global$1d)._blockSize; + (this || _global$1d)._block[rem] = 128; - (this || _global$T)._block.fill(0); + // zero (rem + 1) trailing bits, where (rem + 1) is the smallest + // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize + (this || _global$1d)._block.fill(0, rem + 1); + if (rem >= (this || _global$1d)._finalSize) { + this._update((this || _global$1d)._block); + (this || _global$1d)._block.fill(0); } + var bits = (this || _global$1d)._len * 8; - var bits = (this || _global$T)._len * 8; // uint32 - + // uint32 if (bits <= 4294967295) { - (this || _global$T)._block.writeUInt32BE(bits, (this || _global$T)._blockSize - 4); // uint64 + (this || _global$1d)._block.writeUInt32BE(bits, (this || _global$1d)._blockSize - 4); + // uint64 } else { var lowBits = (bits & 4294967295) >>> 0; var highBits = (bits - lowBits) / 4294967296; - - (this || _global$T)._block.writeUInt32BE(highBits, (this || _global$T)._blockSize - 8); - - (this || _global$T)._block.writeUInt32BE(lowBits, (this || _global$T)._blockSize - 4); + (this || _global$1d)._block.writeUInt32BE(highBits, (this || _global$1d)._blockSize - 8); + (this || _global$1d)._block.writeUInt32BE(lowBits, (this || _global$1d)._blockSize - 4); } - - this._update((this || _global$T)._block); - + this._update((this || _global$1d)._block); var hash = this._hash(); - return enc ? hash.toString(enc) : hash; }; - Hash.prototype._update = function () { throw new Error("_update must be implemented by subclass"); }; - - exports$2K = Hash; - return exports$2K; + exports$3D = Hash; + return exports$3D; } -var exports$2J = {}, - _dewExec$2I = false; - -var _global$S = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2I() { - if (_dewExec$2I) return exports$2J; - _dewExec$2I = true; - +var exports$3C = {}, + _dewExec$3B = false; +var _global$1c = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3B() { + if (_dewExec$3B) return exports$3C; + _dewExec$3B = true; /* * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined * in FIPS PUB 180-1 @@ -751,58 +497,46 @@ function dew$2I() { * The difference between SHA-0 and SHA-1 is just a bitwise rotate left * operation was added. */ - var inherits = dew$2R(); - - var Hash = dew$2J(); - - var Buffer = dew$2P().Buffer; + var inherits = dew$3I(); + var Hash = dew$3C(); + var Buffer = dew$3H().Buffer; var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; var W = new Array(80); - function Sha() { this.init(); - (this || _global$S)._w = W; - Hash.call(this || _global$S, 64, 56); + (this || _global$1c)._w = W; + Hash.call(this || _global$1c, 64, 56); } - inherits(Sha, Hash); - Sha.prototype.init = function () { - (this || _global$S)._a = 1732584193; - (this || _global$S)._b = 4023233417; - (this || _global$S)._c = 2562383102; - (this || _global$S)._d = 271733878; - (this || _global$S)._e = 3285377520; - return this || _global$S; + (this || _global$1c)._a = 1732584193; + (this || _global$1c)._b = 4023233417; + (this || _global$1c)._c = 2562383102; + (this || _global$1c)._d = 271733878; + (this || _global$1c)._e = 3285377520; + return this || _global$1c; }; - function rotl5(num) { return num << 5 | num >>> 27; } - function rotl30(num) { return num << 30 | num >>> 2; } - function ft(s, b, c, d) { if (s === 0) return b & c | ~b & d; if (s === 2) return b & c | b & d | c & d; return b ^ c ^ d; } - Sha.prototype._update = function (M) { - var W = (this || _global$S)._w; - var a = (this || _global$S)._a | 0; - var b = (this || _global$S)._b | 0; - var c = (this || _global$S)._c | 0; - var d = (this || _global$S)._d | 0; - var e = (this || _global$S)._e | 0; - + var W = (this || _global$1c)._w; + var a = (this || _global$1c)._a | 0; + var b = (this || _global$1c)._b | 0; + var c = (this || _global$1c)._c | 0; + var d = (this || _global$1c)._d | 0; + var e = (this || _global$1c)._e | 0; for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); - for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; - for (var j = 0; j < 80; ++j) { var s = ~~(j / 20); var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; @@ -812,37 +546,31 @@ function dew$2I() { b = a; a = t; } - - (this || _global$S)._a = a + (this || _global$S)._a | 0; - (this || _global$S)._b = b + (this || _global$S)._b | 0; - (this || _global$S)._c = c + (this || _global$S)._c | 0; - (this || _global$S)._d = d + (this || _global$S)._d | 0; - (this || _global$S)._e = e + (this || _global$S)._e | 0; + (this || _global$1c)._a = a + (this || _global$1c)._a | 0; + (this || _global$1c)._b = b + (this || _global$1c)._b | 0; + (this || _global$1c)._c = c + (this || _global$1c)._c | 0; + (this || _global$1c)._d = d + (this || _global$1c)._d | 0; + (this || _global$1c)._e = e + (this || _global$1c)._e | 0; }; - Sha.prototype._hash = function () { var H = Buffer.allocUnsafe(20); - H.writeInt32BE((this || _global$S)._a | 0, 0); - H.writeInt32BE((this || _global$S)._b | 0, 4); - H.writeInt32BE((this || _global$S)._c | 0, 8); - H.writeInt32BE((this || _global$S)._d | 0, 12); - H.writeInt32BE((this || _global$S)._e | 0, 16); + H.writeInt32BE((this || _global$1c)._a | 0, 0); + H.writeInt32BE((this || _global$1c)._b | 0, 4); + H.writeInt32BE((this || _global$1c)._c | 0, 8); + H.writeInt32BE((this || _global$1c)._d | 0, 12); + H.writeInt32BE((this || _global$1c)._e | 0, 16); return H; }; - - exports$2J = Sha; - return exports$2J; + exports$3C = Sha; + return exports$3C; } -var exports$2I = {}, - _dewExec$2H = false; - -var _global$R = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2H() { - if (_dewExec$2H) return exports$2I; - _dewExec$2H = true; - +var exports$3B = {}, + _dewExec$3A = false; +var _global$1b = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3A() { + if (_dewExec$3A) return exports$3B; + _dewExec$3A = true; /* * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined * in FIPS PUB 180-1 @@ -851,62 +579,49 @@ function dew$2H() { * Distributed under the BSD License * See http://pajhome.org.uk/crypt/md5 for details. */ - var inherits = dew$2R(); - - var Hash = dew$2J(); - - var Buffer = dew$2P().Buffer; + var inherits = dew$3I(); + var Hash = dew$3C(); + var Buffer = dew$3H().Buffer; var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; var W = new Array(80); - function Sha1() { this.init(); - (this || _global$R)._w = W; - Hash.call(this || _global$R, 64, 56); + (this || _global$1b)._w = W; + Hash.call(this || _global$1b, 64, 56); } - inherits(Sha1, Hash); - Sha1.prototype.init = function () { - (this || _global$R)._a = 1732584193; - (this || _global$R)._b = 4023233417; - (this || _global$R)._c = 2562383102; - (this || _global$R)._d = 271733878; - (this || _global$R)._e = 3285377520; - return this || _global$R; + (this || _global$1b)._a = 1732584193; + (this || _global$1b)._b = 4023233417; + (this || _global$1b)._c = 2562383102; + (this || _global$1b)._d = 271733878; + (this || _global$1b)._e = 3285377520; + return this || _global$1b; }; - function rotl1(num) { return num << 1 | num >>> 31; } - function rotl5(num) { return num << 5 | num >>> 27; } - function rotl30(num) { return num << 30 | num >>> 2; } - function ft(s, b, c, d) { if (s === 0) return b & c | ~b & d; if (s === 2) return b & c | b & d | c & d; return b ^ c ^ d; } - Sha1.prototype._update = function (M) { - var W = (this || _global$R)._w; - var a = (this || _global$R)._a | 0; - var b = (this || _global$R)._b | 0; - var c = (this || _global$R)._c | 0; - var d = (this || _global$R)._d | 0; - var e = (this || _global$R)._e | 0; - + var W = (this || _global$1b)._w; + var a = (this || _global$1b)._a | 0; + var b = (this || _global$1b)._b | 0; + var c = (this || _global$1b)._c | 0; + var d = (this || _global$1b)._d | 0; + var e = (this || _global$1b)._e | 0; for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); - for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]); - for (var j = 0; j < 80; ++j) { var s = ~~(j / 20); var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; @@ -916,37 +631,31 @@ function dew$2H() { b = a; a = t; } - - (this || _global$R)._a = a + (this || _global$R)._a | 0; - (this || _global$R)._b = b + (this || _global$R)._b | 0; - (this || _global$R)._c = c + (this || _global$R)._c | 0; - (this || _global$R)._d = d + (this || _global$R)._d | 0; - (this || _global$R)._e = e + (this || _global$R)._e | 0; + (this || _global$1b)._a = a + (this || _global$1b)._a | 0; + (this || _global$1b)._b = b + (this || _global$1b)._b | 0; + (this || _global$1b)._c = c + (this || _global$1b)._c | 0; + (this || _global$1b)._d = d + (this || _global$1b)._d | 0; + (this || _global$1b)._e = e + (this || _global$1b)._e | 0; }; - Sha1.prototype._hash = function () { var H = Buffer.allocUnsafe(20); - H.writeInt32BE((this || _global$R)._a | 0, 0); - H.writeInt32BE((this || _global$R)._b | 0, 4); - H.writeInt32BE((this || _global$R)._c | 0, 8); - H.writeInt32BE((this || _global$R)._d | 0, 12); - H.writeInt32BE((this || _global$R)._e | 0, 16); + H.writeInt32BE((this || _global$1b)._a | 0, 0); + H.writeInt32BE((this || _global$1b)._b | 0, 4); + H.writeInt32BE((this || _global$1b)._c | 0, 8); + H.writeInt32BE((this || _global$1b)._d | 0, 12); + H.writeInt32BE((this || _global$1b)._e | 0, 16); return H; }; - - exports$2I = Sha1; - return exports$2I; + exports$3B = Sha1; + return exports$3B; } -var exports$2H = {}, - _dewExec$2G = false; - -var _global$Q = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2G() { - if (_dewExec$2G) return exports$2H; - _dewExec$2G = true; - +var exports$3A = {}, + _dewExec$3z = false; +var _global$1a = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3z() { + if (_dewExec$3z) return exports$3A; + _dewExec$3z = true; /** * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined * in FIPS 180-2 @@ -954,75 +663,60 @@ function dew$2G() { * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * */ - var inherits = dew$2R(); - - var Hash = dew$2J(); - - var Buffer = dew$2P().Buffer; + var inherits = dew$3I(); + var Hash = dew$3C(); + var Buffer = dew$3H().Buffer; var K = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298]; var W = new Array(64); - function Sha256() { this.init(); - (this || _global$Q)._w = W; // new Array(64) + (this || _global$1a)._w = W; // new Array(64) - Hash.call(this || _global$Q, 64, 56); + Hash.call(this || _global$1a, 64, 56); } - inherits(Sha256, Hash); - Sha256.prototype.init = function () { - (this || _global$Q)._a = 1779033703; - (this || _global$Q)._b = 3144134277; - (this || _global$Q)._c = 1013904242; - (this || _global$Q)._d = 2773480762; - (this || _global$Q)._e = 1359893119; - (this || _global$Q)._f = 2600822924; - (this || _global$Q)._g = 528734635; - (this || _global$Q)._h = 1541459225; - return this || _global$Q; + (this || _global$1a)._a = 1779033703; + (this || _global$1a)._b = 3144134277; + (this || _global$1a)._c = 1013904242; + (this || _global$1a)._d = 2773480762; + (this || _global$1a)._e = 1359893119; + (this || _global$1a)._f = 2600822924; + (this || _global$1a)._g = 528734635; + (this || _global$1a)._h = 1541459225; + return this || _global$1a; }; - function ch(x, y, z) { return z ^ x & (y ^ z); } - function maj(x, y, z) { return x & y | z & (x | y); } - function sigma0(x) { return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10); } - function sigma1(x) { return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7); } - function gamma0(x) { return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3; } - function gamma1(x) { return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10; } - Sha256.prototype._update = function (M) { - var W = (this || _global$Q)._w; - var a = (this || _global$Q)._a | 0; - var b = (this || _global$Q)._b | 0; - var c = (this || _global$Q)._c | 0; - var d = (this || _global$Q)._d | 0; - var e = (this || _global$Q)._e | 0; - var f = (this || _global$Q)._f | 0; - var g = (this || _global$Q)._g | 0; - var h = (this || _global$Q)._h | 0; - + var W = (this || _global$1a)._w; + var a = (this || _global$1a)._a | 0; + var b = (this || _global$1a)._b | 0; + var c = (this || _global$1a)._c | 0; + var d = (this || _global$1a)._d | 0; + var e = (this || _global$1a)._e | 0; + var f = (this || _global$1a)._f | 0; + var g = (this || _global$1a)._g | 0; + var h = (this || _global$1a)._h | 0; for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); - for (; i < 64; ++i) W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0; - for (var j = 0; j < 64; ++j) { var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0; var T2 = sigma0(a) + maj(a, b, c) | 0; @@ -1035,43 +729,37 @@ function dew$2G() { b = a; a = T1 + T2 | 0; } + (this || _global$1a)._a = a + (this || _global$1a)._a | 0; + (this || _global$1a)._b = b + (this || _global$1a)._b | 0; + (this || _global$1a)._c = c + (this || _global$1a)._c | 0; + (this || _global$1a)._d = d + (this || _global$1a)._d | 0; + (this || _global$1a)._e = e + (this || _global$1a)._e | 0; + (this || _global$1a)._f = f + (this || _global$1a)._f | 0; + (this || _global$1a)._g = g + (this || _global$1a)._g | 0; + (this || _global$1a)._h = h + (this || _global$1a)._h | 0; + }; + Sha256.prototype._hash = function () { + var H = Buffer.allocUnsafe(32); + H.writeInt32BE((this || _global$1a)._a, 0); + H.writeInt32BE((this || _global$1a)._b, 4); + H.writeInt32BE((this || _global$1a)._c, 8); + H.writeInt32BE((this || _global$1a)._d, 12); + H.writeInt32BE((this || _global$1a)._e, 16); + H.writeInt32BE((this || _global$1a)._f, 20); + H.writeInt32BE((this || _global$1a)._g, 24); + H.writeInt32BE((this || _global$1a)._h, 28); + return H; + }; + exports$3A = Sha256; + return exports$3A; +} - (this || _global$Q)._a = a + (this || _global$Q)._a | 0; - (this || _global$Q)._b = b + (this || _global$Q)._b | 0; - (this || _global$Q)._c = c + (this || _global$Q)._c | 0; - (this || _global$Q)._d = d + (this || _global$Q)._d | 0; - (this || _global$Q)._e = e + (this || _global$Q)._e | 0; - (this || _global$Q)._f = f + (this || _global$Q)._f | 0; - (this || _global$Q)._g = g + (this || _global$Q)._g | 0; - (this || _global$Q)._h = h + (this || _global$Q)._h | 0; - }; - - Sha256.prototype._hash = function () { - var H = Buffer.allocUnsafe(32); - H.writeInt32BE((this || _global$Q)._a, 0); - H.writeInt32BE((this || _global$Q)._b, 4); - H.writeInt32BE((this || _global$Q)._c, 8); - H.writeInt32BE((this || _global$Q)._d, 12); - H.writeInt32BE((this || _global$Q)._e, 16); - H.writeInt32BE((this || _global$Q)._f, 20); - H.writeInt32BE((this || _global$Q)._g, 24); - H.writeInt32BE((this || _global$Q)._h, 28); - return H; - }; - - exports$2H = Sha256; - return exports$2H; -} - -var exports$2G = {}, - _dewExec$2F = false; - -var _global$P = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2F() { - if (_dewExec$2F) return exports$2G; - _dewExec$2F = true; - +var exports$3z = {}, + _dewExec$3y = false; +var _global$19 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3y() { + if (_dewExec$3y) return exports$3z; + _dewExec$3y = true; /** * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined * in FIPS 180-2 @@ -1079,159 +767,130 @@ function dew$2F() { * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet * */ - var inherits = dew$2R(); - - var Sha256 = dew$2G(); - - var Hash = dew$2J(); - - var Buffer = dew$2P().Buffer; + var inherits = dew$3I(); + var Sha256 = dew$3z(); + var Hash = dew$3C(); + var Buffer = dew$3H().Buffer; var W = new Array(64); - function Sha224() { this.init(); - (this || _global$P)._w = W; // new Array(64) + (this || _global$19)._w = W; // new Array(64) - Hash.call(this || _global$P, 64, 56); + Hash.call(this || _global$19, 64, 56); } - inherits(Sha224, Sha256); - Sha224.prototype.init = function () { - (this || _global$P)._a = 3238371032; - (this || _global$P)._b = 914150663; - (this || _global$P)._c = 812702999; - (this || _global$P)._d = 4144912697; - (this || _global$P)._e = 4290775857; - (this || _global$P)._f = 1750603025; - (this || _global$P)._g = 1694076839; - (this || _global$P)._h = 3204075428; - return this || _global$P; + (this || _global$19)._a = 3238371032; + (this || _global$19)._b = 914150663; + (this || _global$19)._c = 812702999; + (this || _global$19)._d = 4144912697; + (this || _global$19)._e = 4290775857; + (this || _global$19)._f = 1750603025; + (this || _global$19)._g = 1694076839; + (this || _global$19)._h = 3204075428; + return this || _global$19; }; - Sha224.prototype._hash = function () { var H = Buffer.allocUnsafe(28); - H.writeInt32BE((this || _global$P)._a, 0); - H.writeInt32BE((this || _global$P)._b, 4); - H.writeInt32BE((this || _global$P)._c, 8); - H.writeInt32BE((this || _global$P)._d, 12); - H.writeInt32BE((this || _global$P)._e, 16); - H.writeInt32BE((this || _global$P)._f, 20); - H.writeInt32BE((this || _global$P)._g, 24); + H.writeInt32BE((this || _global$19)._a, 0); + H.writeInt32BE((this || _global$19)._b, 4); + H.writeInt32BE((this || _global$19)._c, 8); + H.writeInt32BE((this || _global$19)._d, 12); + H.writeInt32BE((this || _global$19)._e, 16); + H.writeInt32BE((this || _global$19)._f, 20); + H.writeInt32BE((this || _global$19)._g, 24); return H; }; - - exports$2G = Sha224; - return exports$2G; + exports$3z = Sha224; + return exports$3z; } -var exports$2F = {}, - _dewExec$2E = false; - -var _global$O = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2E() { - if (_dewExec$2E) return exports$2F; - _dewExec$2E = true; - - var inherits = dew$2R(); - - var Hash = dew$2J(); - - var Buffer = dew$2P().Buffer; - +var exports$3y = {}, + _dewExec$3x = false; +var _global$18 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3x() { + if (_dewExec$3x) return exports$3y; + _dewExec$3x = true; + var inherits = dew$3I(); + var Hash = dew$3C(); + var Buffer = dew$3H().Buffer; var K = [1116352408, 3609767458, 1899447441, 602891725, 3049323471, 3964484399, 3921009573, 2173295548, 961987163, 4081628472, 1508970993, 3053834265, 2453635748, 2937671579, 2870763221, 3664609560, 3624381080, 2734883394, 310598401, 1164996542, 607225278, 1323610764, 1426881987, 3590304994, 1925078388, 4068182383, 2162078206, 991336113, 2614888103, 633803317, 3248222580, 3479774868, 3835390401, 2666613458, 4022224774, 944711139, 264347078, 2341262773, 604807628, 2007800933, 770255983, 1495990901, 1249150122, 1856431235, 1555081692, 3175218132, 1996064986, 2198950837, 2554220882, 3999719339, 2821834349, 766784016, 2952996808, 2566594879, 3210313671, 3203337956, 3336571891, 1034457026, 3584528711, 2466948901, 113926993, 3758326383, 338241895, 168717936, 666307205, 1188179964, 773529912, 1546045734, 1294757372, 1522805485, 1396182291, 2643833823, 1695183700, 2343527390, 1986661051, 1014477480, 2177026350, 1206759142, 2456956037, 344077627, 2730485921, 1290863460, 2820302411, 3158454273, 3259730800, 3505952657, 3345764771, 106217008, 3516065817, 3606008344, 3600352804, 1432725776, 4094571909, 1467031594, 275423344, 851169720, 430227734, 3100823752, 506948616, 1363258195, 659060556, 3750685593, 883997877, 3785050280, 958139571, 3318307427, 1322822218, 3812723403, 1537002063, 2003034995, 1747873779, 3602036899, 1955562222, 1575990012, 2024104815, 1125592928, 2227730452, 2716904306, 2361852424, 442776044, 2428436474, 593698344, 2756734187, 3733110249, 3204031479, 2999351573, 3329325298, 3815920427, 3391569614, 3928383900, 3515267271, 566280711, 3940187606, 3454069534, 4118630271, 4000239992, 116418474, 1914138554, 174292421, 2731055270, 289380356, 3203993006, 460393269, 320620315, 685471733, 587496836, 852142971, 1086792851, 1017036298, 365543100, 1126000580, 2618297676, 1288033470, 3409855158, 1501505948, 4234509866, 1607167915, 987167468, 1816402316, 1246189591]; var W = new Array(160); - function Sha512() { this.init(); - (this || _global$O)._w = W; - Hash.call(this || _global$O, 128, 112); + (this || _global$18)._w = W; + Hash.call(this || _global$18, 128, 112); } - inherits(Sha512, Hash); - Sha512.prototype.init = function () { - (this || _global$O)._ah = 1779033703; - (this || _global$O)._bh = 3144134277; - (this || _global$O)._ch = 1013904242; - (this || _global$O)._dh = 2773480762; - (this || _global$O)._eh = 1359893119; - (this || _global$O)._fh = 2600822924; - (this || _global$O)._gh = 528734635; - (this || _global$O)._hh = 1541459225; - (this || _global$O)._al = 4089235720; - (this || _global$O)._bl = 2227873595; - (this || _global$O)._cl = 4271175723; - (this || _global$O)._dl = 1595750129; - (this || _global$O)._el = 2917565137; - (this || _global$O)._fl = 725511199; - (this || _global$O)._gl = 4215389547; - (this || _global$O)._hl = 327033209; - return this || _global$O; + (this || _global$18)._ah = 1779033703; + (this || _global$18)._bh = 3144134277; + (this || _global$18)._ch = 1013904242; + (this || _global$18)._dh = 2773480762; + (this || _global$18)._eh = 1359893119; + (this || _global$18)._fh = 2600822924; + (this || _global$18)._gh = 528734635; + (this || _global$18)._hh = 1541459225; + (this || _global$18)._al = 4089235720; + (this || _global$18)._bl = 2227873595; + (this || _global$18)._cl = 4271175723; + (this || _global$18)._dl = 1595750129; + (this || _global$18)._el = 2917565137; + (this || _global$18)._fl = 725511199; + (this || _global$18)._gl = 4215389547; + (this || _global$18)._hl = 327033209; + return this || _global$18; }; - function Ch(x, y, z) { return z ^ x & (y ^ z); } - function maj(x, y, z) { return x & y | z & (x | y); } - function sigma0(x, xl) { return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25); } - function sigma1(x, xl) { return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23); } - function Gamma0(x, xl) { return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7; } - function Gamma0l(x, xl) { return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25); } - function Gamma1(x, xl) { return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6; } - function Gamma1l(x, xl) { return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26); } - function getCarry(a, b) { return a >>> 0 < b >>> 0 ? 1 : 0; } - Sha512.prototype._update = function (M) { - var W = (this || _global$O)._w; - var ah = (this || _global$O)._ah | 0; - var bh = (this || _global$O)._bh | 0; - var ch = (this || _global$O)._ch | 0; - var dh = (this || _global$O)._dh | 0; - var eh = (this || _global$O)._eh | 0; - var fh = (this || _global$O)._fh | 0; - var gh = (this || _global$O)._gh | 0; - var hh = (this || _global$O)._hh | 0; - var al = (this || _global$O)._al | 0; - var bl = (this || _global$O)._bl | 0; - var cl = (this || _global$O)._cl | 0; - var dl = (this || _global$O)._dl | 0; - var el = (this || _global$O)._el | 0; - var fl = (this || _global$O)._fl | 0; - var gl = (this || _global$O)._gl | 0; - var hl = (this || _global$O)._hl | 0; - + var W = (this || _global$18)._w; + var ah = (this || _global$18)._ah | 0; + var bh = (this || _global$18)._bh | 0; + var ch = (this || _global$18)._ch | 0; + var dh = (this || _global$18)._dh | 0; + var eh = (this || _global$18)._eh | 0; + var fh = (this || _global$18)._fh | 0; + var gh = (this || _global$18)._gh | 0; + var hh = (this || _global$18)._hh | 0; + var al = (this || _global$18)._al | 0; + var bl = (this || _global$18)._bl | 0; + var cl = (this || _global$18)._cl | 0; + var dl = (this || _global$18)._dl | 0; + var el = (this || _global$18)._el | 0; + var fl = (this || _global$18)._fl | 0; + var gl = (this || _global$18)._gl | 0; + var hl = (this || _global$18)._hl | 0; for (var i = 0; i < 32; i += 2) { W[i] = M.readInt32BE(i * 4); W[i + 1] = M.readInt32BE(i * 4 + 4); } - for (; i < 160; i += 2) { var xh = W[i - 15 * 2]; var xl = W[i - 15 * 2 + 1]; @@ -1240,8 +899,9 @@ function dew$2E() { xh = W[i - 2 * 2]; xl = W[i - 2 * 2 + 1]; var gamma1 = Gamma1(xh, xl); - var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + var gamma1l = Gamma1l(xl, xh); + // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] var Wi7h = W[i - 7 * 2]; var Wi7l = W[i - 7 * 2 + 1]; var Wi16h = W[i - 16 * 2]; @@ -1255,7 +915,6 @@ function dew$2E() { W[i] = Wih; W[i + 1] = Wil; } - for (var j = 0; j < 160; j += 2) { Wih = W[j]; Wil = W[j + 1]; @@ -1264,8 +923,9 @@ function dew$2E() { var sigma0h = sigma0(ah, al); var sigma0l = sigma0(al, ah); var sigma1h = sigma1(eh, el); - var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j] + var sigma1l = sigma1(el, eh); + // t1 = h + sigma1 + ch + K[j] + W[j] var Kih = K[j]; var Kil = K[j + 1]; var chh = Ch(eh, fh, gh); @@ -1277,8 +937,9 @@ function dew$2E() { t1l = t1l + Kil | 0; t1h = t1h + Kih + getCarry(t1l, Kil) | 0; t1l = t1l + Wil | 0; - t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj + t1h = t1h + Wih + getCarry(t1l, Wil) | 0; + // t2 = sigma0 + maj var t2l = sigma0l + majl | 0; var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0; hh = gh; @@ -1298,17997 +959,52081 @@ function dew$2E() { al = t1l + t2l | 0; ah = t1h + t2h + getCarry(al, t1l) | 0; } - - (this || _global$O)._al = (this || _global$O)._al + al | 0; - (this || _global$O)._bl = (this || _global$O)._bl + bl | 0; - (this || _global$O)._cl = (this || _global$O)._cl + cl | 0; - (this || _global$O)._dl = (this || _global$O)._dl + dl | 0; - (this || _global$O)._el = (this || _global$O)._el + el | 0; - (this || _global$O)._fl = (this || _global$O)._fl + fl | 0; - (this || _global$O)._gl = (this || _global$O)._gl + gl | 0; - (this || _global$O)._hl = (this || _global$O)._hl + hl | 0; - (this || _global$O)._ah = (this || _global$O)._ah + ah + getCarry((this || _global$O)._al, al) | 0; - (this || _global$O)._bh = (this || _global$O)._bh + bh + getCarry((this || _global$O)._bl, bl) | 0; - (this || _global$O)._ch = (this || _global$O)._ch + ch + getCarry((this || _global$O)._cl, cl) | 0; - (this || _global$O)._dh = (this || _global$O)._dh + dh + getCarry((this || _global$O)._dl, dl) | 0; - (this || _global$O)._eh = (this || _global$O)._eh + eh + getCarry((this || _global$O)._el, el) | 0; - (this || _global$O)._fh = (this || _global$O)._fh + fh + getCarry((this || _global$O)._fl, fl) | 0; - (this || _global$O)._gh = (this || _global$O)._gh + gh + getCarry((this || _global$O)._gl, gl) | 0; - (this || _global$O)._hh = (this || _global$O)._hh + hh + getCarry((this || _global$O)._hl, hl) | 0; + (this || _global$18)._al = (this || _global$18)._al + al | 0; + (this || _global$18)._bl = (this || _global$18)._bl + bl | 0; + (this || _global$18)._cl = (this || _global$18)._cl + cl | 0; + (this || _global$18)._dl = (this || _global$18)._dl + dl | 0; + (this || _global$18)._el = (this || _global$18)._el + el | 0; + (this || _global$18)._fl = (this || _global$18)._fl + fl | 0; + (this || _global$18)._gl = (this || _global$18)._gl + gl | 0; + (this || _global$18)._hl = (this || _global$18)._hl + hl | 0; + (this || _global$18)._ah = (this || _global$18)._ah + ah + getCarry((this || _global$18)._al, al) | 0; + (this || _global$18)._bh = (this || _global$18)._bh + bh + getCarry((this || _global$18)._bl, bl) | 0; + (this || _global$18)._ch = (this || _global$18)._ch + ch + getCarry((this || _global$18)._cl, cl) | 0; + (this || _global$18)._dh = (this || _global$18)._dh + dh + getCarry((this || _global$18)._dl, dl) | 0; + (this || _global$18)._eh = (this || _global$18)._eh + eh + getCarry((this || _global$18)._el, el) | 0; + (this || _global$18)._fh = (this || _global$18)._fh + fh + getCarry((this || _global$18)._fl, fl) | 0; + (this || _global$18)._gh = (this || _global$18)._gh + gh + getCarry((this || _global$18)._gl, gl) | 0; + (this || _global$18)._hh = (this || _global$18)._hh + hh + getCarry((this || _global$18)._hl, hl) | 0; }; - Sha512.prototype._hash = function () { var H = Buffer.allocUnsafe(64); - function writeInt64BE(h, l, offset) { H.writeInt32BE(h, offset); H.writeInt32BE(l, offset + 4); } - - writeInt64BE((this || _global$O)._ah, (this || _global$O)._al, 0); - writeInt64BE((this || _global$O)._bh, (this || _global$O)._bl, 8); - writeInt64BE((this || _global$O)._ch, (this || _global$O)._cl, 16); - writeInt64BE((this || _global$O)._dh, (this || _global$O)._dl, 24); - writeInt64BE((this || _global$O)._eh, (this || _global$O)._el, 32); - writeInt64BE((this || _global$O)._fh, (this || _global$O)._fl, 40); - writeInt64BE((this || _global$O)._gh, (this || _global$O)._gl, 48); - writeInt64BE((this || _global$O)._hh, (this || _global$O)._hl, 56); + writeInt64BE((this || _global$18)._ah, (this || _global$18)._al, 0); + writeInt64BE((this || _global$18)._bh, (this || _global$18)._bl, 8); + writeInt64BE((this || _global$18)._ch, (this || _global$18)._cl, 16); + writeInt64BE((this || _global$18)._dh, (this || _global$18)._dl, 24); + writeInt64BE((this || _global$18)._eh, (this || _global$18)._el, 32); + writeInt64BE((this || _global$18)._fh, (this || _global$18)._fl, 40); + writeInt64BE((this || _global$18)._gh, (this || _global$18)._gl, 48); + writeInt64BE((this || _global$18)._hh, (this || _global$18)._hl, 56); return H; }; - - exports$2F = Sha512; - return exports$2F; + exports$3y = Sha512; + return exports$3y; } -var exports$2E = {}, - _dewExec$2D = false; - -var _global$N = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$2D() { - if (_dewExec$2D) return exports$2E; - _dewExec$2D = true; - - var inherits = dew$2R(); - - var SHA512 = dew$2E(); - - var Hash = dew$2J(); - - var Buffer = dew$2P().Buffer; - +var exports$3x = {}, + _dewExec$3w = false; +var _global$17 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3w() { + if (_dewExec$3w) return exports$3x; + _dewExec$3w = true; + var inherits = dew$3I(); + var SHA512 = dew$3x(); + var Hash = dew$3C(); + var Buffer = dew$3H().Buffer; var W = new Array(160); - function Sha384() { this.init(); - (this || _global$N)._w = W; - Hash.call(this || _global$N, 128, 112); + (this || _global$17)._w = W; + Hash.call(this || _global$17, 128, 112); } - inherits(Sha384, SHA512); - Sha384.prototype.init = function () { - (this || _global$N)._ah = 3418070365; - (this || _global$N)._bh = 1654270250; - (this || _global$N)._ch = 2438529370; - (this || _global$N)._dh = 355462360; - (this || _global$N)._eh = 1731405415; - (this || _global$N)._fh = 2394180231; - (this || _global$N)._gh = 3675008525; - (this || _global$N)._hh = 1203062813; - (this || _global$N)._al = 3238371032; - (this || _global$N)._bl = 914150663; - (this || _global$N)._cl = 812702999; - (this || _global$N)._dl = 4144912697; - (this || _global$N)._el = 4290775857; - (this || _global$N)._fl = 1750603025; - (this || _global$N)._gl = 1694076839; - (this || _global$N)._hl = 3204075428; - return this || _global$N; + (this || _global$17)._ah = 3418070365; + (this || _global$17)._bh = 1654270250; + (this || _global$17)._ch = 2438529370; + (this || _global$17)._dh = 355462360; + (this || _global$17)._eh = 1731405415; + (this || _global$17)._fh = 2394180231; + (this || _global$17)._gh = 3675008525; + (this || _global$17)._hh = 1203062813; + (this || _global$17)._al = 3238371032; + (this || _global$17)._bl = 914150663; + (this || _global$17)._cl = 812702999; + (this || _global$17)._dl = 4144912697; + (this || _global$17)._el = 4290775857; + (this || _global$17)._fl = 1750603025; + (this || _global$17)._gl = 1694076839; + (this || _global$17)._hl = 3204075428; + return this || _global$17; }; - Sha384.prototype._hash = function () { var H = Buffer.allocUnsafe(48); - function writeInt64BE(h, l, offset) { H.writeInt32BE(h, offset); H.writeInt32BE(l, offset + 4); } - - writeInt64BE((this || _global$N)._ah, (this || _global$N)._al, 0); - writeInt64BE((this || _global$N)._bh, (this || _global$N)._bl, 8); - writeInt64BE((this || _global$N)._ch, (this || _global$N)._cl, 16); - writeInt64BE((this || _global$N)._dh, (this || _global$N)._dl, 24); - writeInt64BE((this || _global$N)._eh, (this || _global$N)._el, 32); - writeInt64BE((this || _global$N)._fh, (this || _global$N)._fl, 40); + writeInt64BE((this || _global$17)._ah, (this || _global$17)._al, 0); + writeInt64BE((this || _global$17)._bh, (this || _global$17)._bl, 8); + writeInt64BE((this || _global$17)._ch, (this || _global$17)._cl, 16); + writeInt64BE((this || _global$17)._dh, (this || _global$17)._dl, 24); + writeInt64BE((this || _global$17)._eh, (this || _global$17)._el, 32); + writeInt64BE((this || _global$17)._fh, (this || _global$17)._fl, 40); return H; }; - - exports$2E = Sha384; - return exports$2E; + exports$3x = Sha384; + return exports$3x; } -var exports$2D = {}, - _dewExec$2C = false; -var module$b = { - exports: exports$2D +var exports$3w = {}, + _dewExec$3v = false; +var module$f = { + exports: exports$3w }; -function dew$2C() { - if (_dewExec$2C) return module$b.exports; - _dewExec$2C = true; - - var exports = module$b.exports = function SHA(algorithm) { +function dew$3v() { + if (_dewExec$3v) return module$f.exports; + _dewExec$3v = true; + var exports = module$f.exports = function SHA(algorithm) { algorithm = algorithm.toLowerCase(); var Algorithm = exports[algorithm]; if (!Algorithm) throw new Error(algorithm + " is not supported (we accept pull requests)"); return new Algorithm(); }; - - exports.sha = dew$2I(); - exports.sha1 = dew$2H(); - exports.sha224 = dew$2F(); - exports.sha256 = dew$2G(); - exports.sha384 = dew$2D(); - exports.sha512 = dew$2E(); - return module$b.exports; -} - -var exports$f$2 = {}, - _dewExec$f$2 = false; -function dew$f$2() { - if (_dewExec$f$2) return exports$f$2; - _dewExec$f$2 = true; - - if (typeof Object.create === "function") { - // implementation from standard node.js 'util' module - exports$f$2 = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor; - ctor.prototype = Object.create(superCtor.prototype, { - constructor: { - value: ctor, - enumerable: false, - writable: true, - configurable: true - } - }); - } - }; - } else { - // old school shim for old browsers - exports$f$2 = function inherits(ctor, superCtor) { - if (superCtor) { - ctor.super_ = superCtor; - - var TempCtor = function () {}; - - TempCtor.prototype = superCtor.prototype; - ctor.prototype = new TempCtor(); - ctor.prototype.constructor = ctor; - } - }; - } - - return exports$f$2; -} - -var exports$e$2 = {}, - _dewExec$e$2 = false; -function dew$e$2() { - if (_dewExec$e$2) return exports$e$2; - _dewExec$e$2 = true; - exports$e$2 = y$o.EventEmitter; - return exports$e$2; + exports.sha = dew$3B(); + exports.sha1 = dew$3A(); + exports.sha224 = dew$3y(); + exports.sha256 = dew$3z(); + exports.sha384 = dew$3w(); + exports.sha512 = dew$3x(); + return module$f.exports; } -var exports$d$2 = {}, - _dewExec$d$2 = false; -function dew$d$2() { - if (_dewExec$d$2) return exports$d$2; - _dewExec$d$2 = true; - - function ownKeys(object, enumerableOnly) { - var keys = Object.keys(object); - - if (Object.getOwnPropertySymbols) { - var symbols = Object.getOwnPropertySymbols(object); - if (enumerableOnly) symbols = symbols.filter(function (sym) { - return Object.getOwnPropertyDescriptor(object, sym).enumerable; - }); - keys.push.apply(keys, symbols); +var exports$3v = {}, + _dewExec$3u = false; +var _global$16 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3u() { + if (_dewExec$3u) return exports$3v; + _dewExec$3u = true; + var Buffer = dew$3H().Buffer; + var Transform = exports$3I.Transform; + var StringDecoder = e$1$2.StringDecoder; + var inherits = dew$3I(); + function CipherBase(hashMode) { + Transform.call(this || _global$16); + (this || _global$16).hashMode = typeof hashMode === "string"; + if ((this || _global$16).hashMode) { + (this || _global$16)[hashMode] = (this || _global$16)._finalOrDigest; + } else { + (this || _global$16).final = (this || _global$16)._finalOrDigest; } - - return keys; + if ((this || _global$16)._final) { + (this || _global$16).__final = (this || _global$16)._final; + (this || _global$16)._final = null; + } + (this || _global$16)._decoder = null; + (this || _global$16)._encoding = null; } - - function _objectSpread(target) { - for (var i = 1; i < arguments.length; i++) { - var source = arguments[i] != null ? arguments[i] : {}; - - if (i % 2) { - ownKeys(Object(source), true).forEach(function (key) { - _defineProperty(target, key, source[key]); - }); - } else if (Object.getOwnPropertyDescriptors) { - Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + inherits(CipherBase, Transform); + CipherBase.prototype.update = function (data, inputEnc, outputEnc) { + if (typeof data === "string") { + data = Buffer.from(data, inputEnc); + } + var outData = this._update(data); + if ((this || _global$16).hashMode) return this || _global$16; + if (outputEnc) { + outData = this._toString(outData, outputEnc); + } + return outData; + }; + CipherBase.prototype.setAutoPadding = function () {}; + CipherBase.prototype.getAuthTag = function () { + throw new Error("trying to get auth tag in unsupported state"); + }; + CipherBase.prototype.setAuthTag = function () { + throw new Error("trying to set auth tag in unsupported state"); + }; + CipherBase.prototype.setAAD = function () { + throw new Error("trying to set aad in unsupported state"); + }; + CipherBase.prototype._transform = function (data, _, next) { + var err; + try { + if ((this || _global$16).hashMode) { + this._update(data); } else { - ownKeys(Object(source)).forEach(function (key) { - Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); - }); + this.push(this._update(data)); } + } catch (e) { + err = e; + } finally { + next(err); } - - return target; - } - - function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); - } else { - obj[key] = value; + }; + CipherBase.prototype._flush = function (done) { + var err; + try { + this.push(this.__final()); + } catch (e) { + err = e; + } + done(err); + }; + CipherBase.prototype._finalOrDigest = function (outputEnc) { + var outData = this.__final() || Buffer.alloc(0); + if (outputEnc) { + outData = this._toString(outData, outputEnc, true); + } + return outData; + }; + CipherBase.prototype._toString = function (value, enc, fin) { + if (!(this || _global$16)._decoder) { + (this || _global$16)._decoder = new StringDecoder(enc); + (this || _global$16)._encoding = enc; + } + if ((this || _global$16)._encoding !== enc) throw new Error("can't switch encodings"); + var out = (this || _global$16)._decoder.write(value); + if (fin) { + out += (this || _global$16)._decoder.end(); } + return out; + }; + exports$3v = CipherBase; + return exports$3v; +} - return obj; +var exports$3u = {}, + _dewExec$3t = false; +function dew$3t() { + if (_dewExec$3t) return exports$3u; + _dewExec$3t = true; + var inherits = dew$3I(); + var MD5 = dew$3E(); + var RIPEMD160 = dew$3D(); + var sha = dew$3v(); + var Base = dew$3u(); + function Hash(hash) { + Base.call(this, "digest"); + this._hash = hash; } + inherits(Hash, Base); + Hash.prototype._update = function (data) { + this._hash.update(data); + }; + Hash.prototype._final = function () { + return this._hash.digest(); + }; + exports$3u = function createHash(alg) { + alg = alg.toLowerCase(); + if (alg === "md5") return new MD5(); + if (alg === "rmd160" || alg === "ripemd160") return new RIPEMD160(); + return new Hash(sha(alg)); + }; + return exports$3u; +} - function _classCallCheck(instance, Constructor) { - if (!(instance instanceof Constructor)) { - throw new TypeError("Cannot call a class as a function"); +var exports$3t = {}, + _dewExec$3s = false; +function dew$3s() { + if (_dewExec$3s) return exports$3t; + _dewExec$3s = true; + var inherits = dew$3I(); + var Buffer = dew$3H().Buffer; + var Base = dew$3u(); + var ZEROS = Buffer.alloc(128); + var blocksize = 64; + function Hmac(alg, key) { + Base.call(this, "digest"); + if (typeof key === "string") { + key = Buffer.from(key); } - } - - function _defineProperties(target, props) { - for (var i = 0; i < props.length; i++) { - var descriptor = props[i]; - descriptor.enumerable = descriptor.enumerable || false; - descriptor.configurable = true; - if ("value" in descriptor) descriptor.writable = true; - Object.defineProperty(target, descriptor.key, descriptor); + this._alg = alg; + this._key = key; + if (key.length > blocksize) { + key = alg(key); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); } + var ipad = this._ipad = Buffer.allocUnsafe(blocksize); + var opad = this._opad = Buffer.allocUnsafe(blocksize); + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + this._hash = [ipad]; } + inherits(Hmac, Base); + Hmac.prototype._update = function (data) { + this._hash.push(data); + }; + Hmac.prototype._final = function () { + var h = this._alg(Buffer.concat(this._hash)); + return this._alg(Buffer.concat([this._opad, h])); + }; + exports$3t = Hmac; + return exports$3t; +} - function _createClass(Constructor, protoProps, staticProps) { - if (protoProps) _defineProperties(Constructor.prototype, protoProps); - return Constructor; - } - - var _require = e$1$1$1, - Buffer = _require.Buffer; - var _require2 = X$5, - inspect = _require2.inspect; - var custom = inspect && inspect.custom || "inspect"; +var exports$3s = {}, + _dewExec$3r = false; +function dew$3r() { + if (_dewExec$3r) return exports$3s; + _dewExec$3r = true; + var MD5 = dew$3E(); + exports$3s = function (buffer) { + return new MD5().update(buffer).digest(); + }; + return exports$3s; +} - function copyBuffer(src, target, offset) { - Buffer.prototype.copy.call(src, target, offset); +var exports$3r = {}, + _dewExec$3q = false; +function dew$3q() { + if (_dewExec$3q) return exports$3r; + _dewExec$3q = true; + var inherits = dew$3I(); + var Legacy = dew$3s(); + var Base = dew$3u(); + var Buffer = dew$3H().Buffer; + var md5 = dew$3r(); + var RIPEMD160 = dew$3D(); + var sha = dew$3v(); + var ZEROS = Buffer.alloc(128); + function Hmac(alg, key) { + Base.call(this, "digest"); + if (typeof key === "string") { + key = Buffer.from(key); + } + var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + this._alg = alg; + this._key = key; + if (key.length > blocksize) { + var hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + key = hash.update(key).digest(); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + var ipad = this._ipad = Buffer.allocUnsafe(blocksize); + var opad = this._opad = Buffer.allocUnsafe(blocksize); + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + this._hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + this._hash.update(ipad); } - - exports$d$2 = /*#__PURE__*/function () { - function BufferList() { - _classCallCheck(this, BufferList); - - this.head = null; - this.tail = null; - this.length = 0; + inherits(Hmac, Base); + Hmac.prototype._update = function (data) { + this._hash.update(data); + }; + Hmac.prototype._final = function () { + var h = this._hash.digest(); + var hash = this._alg === "rmd160" ? new RIPEMD160() : sha(this._alg); + return hash.update(this._opad).update(h).digest(); + }; + exports$3r = function createHmac(alg, key) { + alg = alg.toLowerCase(); + if (alg === "rmd160" || alg === "ripemd160") { + return new Hmac("rmd160", key); + } + if (alg === "md5") { + return new Legacy(md5, key); } + return new Hmac(alg, key); + }; + return exports$3r; +} - _createClass(BufferList, [{ - key: "push", - value: function push(v) { - var entry = { - data: v, - next: null - }; - if (this.length > 0) this.tail.next = entry;else this.head = entry; - this.tail = entry; - ++this.length; - } - }, { - key: "unshift", - value: function unshift(v) { - var entry = { - data: v, - next: this.head - }; - if (this.length === 0) this.tail = entry; - this.head = entry; - ++this.length; - } - }, { - key: "shift", - value: function shift() { - if (this.length === 0) return; - var ret = this.head.data; - if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; - --this.length; - return ret; - } - }, { - key: "clear", - value: function clear() { - this.head = this.tail = null; - this.length = 0; - } - }, { - key: "join", - value: function join(s) { - if (this.length === 0) return ""; - var p = this.head; - var ret = "" + p.data; - - while (p = p.next) { - ret += s + p.data; - } - - return ret; - } - }, { - key: "concat", - value: function concat(n) { - if (this.length === 0) return Buffer.alloc(0); - var ret = Buffer.allocUnsafe(n >>> 0); - var p = this.head; - var i = 0; - - while (p) { - copyBuffer(p.data, ret, i); - i += p.data.length; - p = p.next; - } - - return ret; - } // Consumes a specified amount of bytes or characters from the buffered data. - - }, { - key: "consume", - value: function consume(n, hasStrings) { - var ret; - - if (n < this.head.data.length) { - // `slice` is the same for buffers and strings. - ret = this.head.data.slice(0, n); - this.head.data = this.head.data.slice(n); - } else if (n === this.head.data.length) { - // First chunk is a perfect match. - ret = this.shift(); - } else { - // Result spans more than one buffer. - ret = hasStrings ? this._getString(n) : this._getBuffer(n); - } - - return ret; - } - }, { - key: "first", - value: function first() { - return this.head.data; - } // Consumes a specified amount of characters from the buffered data. - - }, { - key: "_getString", - value: function _getString(n) { - var p = this.head; - var c = 1; - var ret = p.data; - n -= ret.length; - - while (p = p.next) { - var str = p.data; - var nb = n > str.length ? str.length : n; - if (nb === str.length) ret += str;else ret += str.slice(0, n); - n -= nb; - - if (n === 0) { - if (nb === str.length) { - ++c; - if (p.next) this.head = p.next;else this.head = this.tail = null; - } else { - this.head = p; - p.data = str.slice(nb); - } - - break; - } - - ++c; - } - - this.length -= c; - return ret; - } // Consumes a specified amount of bytes from the buffered data. - - }, { - key: "_getBuffer", - value: function _getBuffer(n) { - var ret = Buffer.allocUnsafe(n); - var p = this.head; - var c = 1; - p.data.copy(ret); - n -= p.data.length; - - while (p = p.next) { - var buf = p.data; - var nb = n > buf.length ? buf.length : n; - buf.copy(ret, ret.length - n, 0, nb); - n -= nb; - - if (n === 0) { - if (nb === buf.length) { - ++c; - if (p.next) this.head = p.next;else this.head = this.tail = null; - } else { - this.head = p; - p.data = buf.slice(nb); - } - - break; - } - - ++c; - } - - this.length -= c; - return ret; - } // Make sure the linked list only shows the minimal necessary information. - - }, { - key: custom, - value: function value(_, options) { - return inspect(this, _objectSpread({}, options, { - // Only inspect one level. - depth: 0, - // It should not recurse. - customInspect: false - })); - } - }]); - - return BufferList; - }(); +var _algorithms$2 = { + "sha224WithRSAEncryption": { + "sign": "rsa", + "hash": "sha224", + "id": "302d300d06096086480165030402040500041c" + }, + "RSA-SHA224": { + "sign": "ecdsa/rsa", + "hash": "sha224", + "id": "302d300d06096086480165030402040500041c" + }, + "sha256WithRSAEncryption": { + "sign": "rsa", + "hash": "sha256", + "id": "3031300d060960864801650304020105000420" + }, + "RSA-SHA256": { + "sign": "ecdsa/rsa", + "hash": "sha256", + "id": "3031300d060960864801650304020105000420" + }, + "sha384WithRSAEncryption": { + "sign": "rsa", + "hash": "sha384", + "id": "3041300d060960864801650304020205000430" + }, + "RSA-SHA384": { + "sign": "ecdsa/rsa", + "hash": "sha384", + "id": "3041300d060960864801650304020205000430" + }, + "sha512WithRSAEncryption": { + "sign": "rsa", + "hash": "sha512", + "id": "3051300d060960864801650304020305000440" + }, + "RSA-SHA512": { + "sign": "ecdsa/rsa", + "hash": "sha512", + "id": "3051300d060960864801650304020305000440" + }, + "RSA-SHA1": { + "sign": "rsa", + "hash": "sha1", + "id": "3021300906052b0e03021a05000414" + }, + "ecdsa-with-SHA1": { + "sign": "ecdsa", + "hash": "sha1", + "id": "" + }, + "sha256": { + "sign": "ecdsa", + "hash": "sha256", + "id": "" + }, + "sha224": { + "sign": "ecdsa", + "hash": "sha224", + "id": "" + }, + "sha384": { + "sign": "ecdsa", + "hash": "sha384", + "id": "" + }, + "sha512": { + "sign": "ecdsa", + "hash": "sha512", + "id": "" + }, + "DSA-SHA": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA-SHA1": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA-WITH-SHA224": { + "sign": "dsa", + "hash": "sha224", + "id": "" + }, + "DSA-SHA224": { + "sign": "dsa", + "hash": "sha224", + "id": "" + }, + "DSA-WITH-SHA256": { + "sign": "dsa", + "hash": "sha256", + "id": "" + }, + "DSA-SHA256": { + "sign": "dsa", + "hash": "sha256", + "id": "" + }, + "DSA-WITH-SHA384": { + "sign": "dsa", + "hash": "sha384", + "id": "" + }, + "DSA-SHA384": { + "sign": "dsa", + "hash": "sha384", + "id": "" + }, + "DSA-WITH-SHA512": { + "sign": "dsa", + "hash": "sha512", + "id": "" + }, + "DSA-SHA512": { + "sign": "dsa", + "hash": "sha512", + "id": "" + }, + "DSA-RIPEMD160": { + "sign": "dsa", + "hash": "rmd160", + "id": "" + }, + "ripemd160WithRSA": { + "sign": "rsa", + "hash": "rmd160", + "id": "3021300906052b2403020105000414" + }, + "RSA-RIPEMD160": { + "sign": "rsa", + "hash": "rmd160", + "id": "3021300906052b2403020105000414" + }, + "md5WithRSAEncryption": { + "sign": "rsa", + "hash": "md5", + "id": "3020300c06082a864886f70d020505000410" + }, + "RSA-MD5": { + "sign": "rsa", + "hash": "md5", + "id": "3020300c06082a864886f70d020505000410" + } +}; - return exports$d$2; +var exports$3q = {}, + _dewExec$3p = false; +function dew$3p() { + if (_dewExec$3p) return exports$3q; + _dewExec$3p = true; + exports$3q = _algorithms$2; + return exports$3q; } -var exports$c$2 = {}, - _dewExec$c$2 = false; -function dew$c$2() { - if (_dewExec$c$2) return exports$c$2; - _dewExec$c$2 = true; - var process = T$9; - - // undocumented cb() API, needed for core, not for public API - function destroy(err, cb) { - var _this = this; - - var readableDestroyed = this._readableState && this._readableState.destroyed; - var writableDestroyed = this._writableState && this._writableState.destroyed; - - if (readableDestroyed || writableDestroyed) { - if (cb) { - cb(err); - } else if (err) { - if (!this._writableState) { - process.nextTick(emitErrorNT, this, err); - } else if (!this._writableState.errorEmitted) { - this._writableState.errorEmitted = true; - process.nextTick(emitErrorNT, this, err); - } - } - - return this; - } // we set destroyed to true before firing error callbacks in order - // to make it re-entrance safe in case destroy() is called within callbacks - - - if (this._readableState) { - this._readableState.destroyed = true; - } // if this is a duplex stream mark the writable part as destroyed as well - +var exports$3p = {}, + _dewExec$3o = false; +function dew$3o() { + if (_dewExec$3o) return exports$3p; + _dewExec$3o = true; + var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs - if (this._writableState) { - this._writableState.destroyed = true; + exports$3p = function (iterations, keylen) { + if (typeof iterations !== "number") { + throw new TypeError("Iterations not a number"); } - - this._destroy(err || null, function (err) { - if (!cb && err) { - if (!_this._writableState) { - process.nextTick(emitErrorAndCloseNT, _this, err); - } else if (!_this._writableState.errorEmitted) { - _this._writableState.errorEmitted = true; - process.nextTick(emitErrorAndCloseNT, _this, err); - } else { - process.nextTick(emitCloseNT, _this); - } - } else if (cb) { - process.nextTick(emitCloseNT, _this); - cb(err); - } else { - process.nextTick(emitCloseNT, _this); - } - }); - - return this; - } - - function emitErrorAndCloseNT(self, err) { - emitErrorNT(self, err); - emitCloseNT(self); - } - - function emitCloseNT(self) { - if (self._writableState && !self._writableState.emitClose) return; - if (self._readableState && !self._readableState.emitClose) return; - self.emit("close"); - } - - function undestroy() { - if (this._readableState) { - this._readableState.destroyed = false; - this._readableState.reading = false; - this._readableState.ended = false; - this._readableState.endEmitted = false; + if (iterations < 0) { + throw new TypeError("Bad iterations"); } - - if (this._writableState) { - this._writableState.destroyed = false; - this._writableState.ended = false; - this._writableState.ending = false; - this._writableState.finalCalled = false; - this._writableState.prefinished = false; - this._writableState.finished = false; - this._writableState.errorEmitted = false; + if (typeof keylen !== "number") { + throw new TypeError("Key length not a number"); } - } - - function emitErrorNT(self, err) { - self.emit("error", err); - } + if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { + /* eslint no-self-compare: 0 */ + throw new TypeError("Bad key length"); + } + }; + return exports$3p; +} - function errorOrDestroy(stream, err) { - // We have tests that rely on errors being emitted - // in the same tick, so changing this is semver major. - // For now when you opt-in to autoDestroy we allow - // the error to be emitted nextTick. In a future - // semver major update we should change the default to this. - var rState = stream._readableState; - var wState = stream._writableState; - if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit("error", err); +var exports$3o = {}, + _dewExec$3n = false; +var _global$15 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3n() { + if (_dewExec$3n) return exports$3o; + _dewExec$3n = true; + var process$1 = process; + var defaultEncoding; + /* istanbul ignore next */ + if (_global$15.process && _global$15.process.browser) { + defaultEncoding = "utf-8"; + } else if (_global$15.process && _global$15.process.version) { + var pVersionMajor = parseInt(process$1.version.split(".")[0].slice(1), 10); + defaultEncoding = pVersionMajor >= 6 ? "utf-8" : "binary"; + } else { + defaultEncoding = "utf-8"; } + exports$3o = defaultEncoding; + return exports$3o; +} - exports$c$2 = { - destroy: destroy, - undestroy: undestroy, - errorOrDestroy: errorOrDestroy +var exports$3n = {}, + _dewExec$3m = false; +function dew$3m() { + if (_dewExec$3m) return exports$3n; + _dewExec$3m = true; + var Buffer = dew$3H().Buffer; + exports$3n = function (thing, encoding, name) { + if (Buffer.isBuffer(thing)) { + return thing; + } else if (typeof thing === "string") { + return Buffer.from(thing, encoding); + } else if (ArrayBuffer.isView(thing)) { + return Buffer.from(thing.buffer); + } else { + throw new TypeError(name + " must be a string, a Buffer, a typed array or a DataView"); + } }; - return exports$c$2; + return exports$3n; } -var exports$b$2 = {}, - _dewExec$b$2 = false; -function dew$b$2() { - if (_dewExec$b$2) return exports$b$2; - _dewExec$b$2 = true; - const codes = {}; - - function createErrorType(code, message, Base) { - if (!Base) { - Base = Error; +var exports$3m = {}, + _dewExec$3l = false; +var _global$14 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3l() { + if (_dewExec$3l) return exports$3m; + _dewExec$3l = true; + var md5 = dew$3r(); + var RIPEMD160 = dew$3D(); + var sha = dew$3v(); + var Buffer = dew$3H().Buffer; + var checkParameters = dew$3o(); + var defaultEncoding = dew$3n(); + var toBuffer = dew$3m(); + var ZEROS = Buffer.alloc(128); + var sizes = { + md5: 16, + sha1: 20, + sha224: 28, + sha256: 32, + sha384: 48, + sha512: 64, + rmd160: 20, + ripemd160: 20 + }; + function Hmac(alg, key, saltLen) { + var hash = getDigest(alg); + var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + if (key.length > blocksize) { + key = hash(key); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); } - - function getMessage(arg1, arg2, arg3) { - if (typeof message === "string") { - return message; - } else { - return message(arg1, arg2, arg3); - } + var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]); + var opad = Buffer.allocUnsafe(blocksize + sizes[alg]); + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; } - - class NodeError extends Base { - constructor(arg1, arg2, arg3) { - super(getMessage(arg1, arg2, arg3)); - } - + var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4); + ipad.copy(ipad1, 0, 0, blocksize); + (this || _global$14).ipad1 = ipad1; + (this || _global$14).ipad2 = ipad; + (this || _global$14).opad = opad; + (this || _global$14).alg = alg; + (this || _global$14).blocksize = blocksize; + (this || _global$14).hash = hash; + (this || _global$14).size = sizes[alg]; + } + Hmac.prototype.run = function (data, ipad) { + data.copy(ipad, (this || _global$14).blocksize); + var h = this.hash(ipad); + h.copy((this || _global$14).opad, (this || _global$14).blocksize); + return this.hash((this || _global$14).opad); + }; + function getDigest(alg) { + function shaFunc(data) { + return sha(alg).update(data).digest(); } - - NodeError.prototype.name = Base.name; - NodeError.prototype.code = code; - codes[code] = NodeError; - } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js - - - function oneOf(expected, thing) { - if (Array.isArray(expected)) { - const len = expected.length; - expected = expected.map(i => String(i)); - - if (len > 2) { - return `one of ${thing} ${expected.slice(0, len - 1).join(", ")}, or ` + expected[len - 1]; - } else if (len === 2) { - return `one of ${thing} ${expected[0]} or ${expected[1]}`; - } else { - return `of ${thing} ${expected[0]}`; + function rmd160Func(data) { + return new RIPEMD160().update(data).digest(); + } + if (alg === "rmd160" || alg === "ripemd160") return rmd160Func; + if (alg === "md5") return md5; + return shaFunc; + } + function pbkdf2(password, salt, iterations, keylen, digest) { + checkParameters(iterations, keylen); + password = toBuffer(password, defaultEncoding, "Password"); + salt = toBuffer(salt, defaultEncoding, "Salt"); + digest = digest || "sha1"; + var hmac = new Hmac(digest, password, salt.length); + var DK = Buffer.allocUnsafe(keylen); + var block1 = Buffer.allocUnsafe(salt.length + 4); + salt.copy(block1, 0, 0, salt.length); + var destPos = 0; + var hLen = sizes[digest]; + var l = Math.ceil(keylen / hLen); + for (var i = 1; i <= l; i++) { + block1.writeUInt32BE(i, salt.length); + var T = hmac.run(block1, hmac.ipad1); + var U = T; + for (var j = 1; j < iterations; j++) { + U = hmac.run(U, hmac.ipad2); + for (var k = 0; k < hLen; k++) T[k] ^= U[k]; } - } else { - return `of ${thing} ${String(expected)}`; + T.copy(DK, destPos); + destPos += hLen; } - } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith - - - function startsWith(str, search, pos) { - return str.substr(0 , search.length) === search; - } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith - + return DK; + } + exports$3m = pbkdf2; + return exports$3m; +} - function endsWith(str, search, this_len) { - if (this_len === undefined || this_len > str.length) { - this_len = str.length; +var exports$3l = {}, + _dewExec$3k = false; +var _global$13 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3k() { + if (_dewExec$3k) return exports$3l; + _dewExec$3k = true; + var Buffer = dew$3H().Buffer; + var checkParameters = dew$3o(); + var defaultEncoding = dew$3n(); + var sync = dew$3l(); + var toBuffer = dew$3m(); + var ZERO_BUF; + var subtle = _global$13.crypto && _global$13.crypto.subtle; + var toBrowser = { + sha: "SHA-1", + "sha-1": "SHA-1", + sha1: "SHA-1", + sha256: "SHA-256", + "sha-256": "SHA-256", + sha384: "SHA-384", + "sha-384": "SHA-384", + "sha-512": "SHA-512", + sha512: "SHA-512" + }; + var checks = []; + function checkNative(algo) { + if (_global$13.process && !_global$13.process.browser) { + return Promise.resolve(false); } - - return str.substring(this_len - search.length, this_len) === search; - } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes - - - function includes(str, search, start) { - if (typeof start !== "number") { - start = 0; + if (!subtle || !subtle.importKey || !subtle.deriveBits) { + return Promise.resolve(false); } - - if (start + search.length > str.length) { - return false; - } else { - return str.indexOf(search, start) !== -1; + if (checks[algo] !== undefined) { + return checks[algo]; } + ZERO_BUF = ZERO_BUF || Buffer.alloc(8); + var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () { + return true; + }).catch(function () { + return false; + }); + checks[algo] = prom; + return prom; } - - createErrorType("ERR_INVALID_OPT_VALUE", function (name, value) { - return "The value \"" + value + "\" is invalid for option \"" + name + "\""; - }, TypeError); - createErrorType("ERR_INVALID_ARG_TYPE", function (name, expected, actual) { - // determiner: 'must be' or 'must not be' - let determiner; - - if (typeof expected === "string" && startsWith(expected, "not ")) { - determiner = "must not be"; - expected = expected.replace(/^not /, ""); - } else { - determiner = "must be"; + var nextTick; + function getNextTick() { + if (nextTick) { + return nextTick; } - - let msg; - - if (endsWith(name, " argument")) { - // For cases like 'first argument' - msg = `The ${name} ${determiner} ${oneOf(expected, "type")}`; + if (_global$13.process && _global$13.process.nextTick) { + nextTick = _global$13.process.nextTick; + } else if (_global$13.queueMicrotask) { + nextTick = _global$13.queueMicrotask; + } else if (_global$13.setImmediate) { + nextTick = _global$13.setImmediate; } else { - const type = includes(name, ".") ? "property" : "argument"; - msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, "type")}`; + nextTick = _global$13.setTimeout; } - - msg += `. Received type ${typeof actual}`; - return msg; - }, TypeError); - createErrorType("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF"); - createErrorType("ERR_METHOD_NOT_IMPLEMENTED", function (name) { - return "The " + name + " method is not implemented"; - }); - createErrorType("ERR_STREAM_PREMATURE_CLOSE", "Premature close"); - createErrorType("ERR_STREAM_DESTROYED", function (name) { - return "Cannot call " + name + " after a stream was destroyed"; - }); - createErrorType("ERR_MULTIPLE_CALLBACK", "Callback called multiple times"); - createErrorType("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable"); - createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end"); - createErrorType("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError); - createErrorType("ERR_UNKNOWN_ENCODING", function (arg) { - return "Unknown encoding: " + arg; - }, TypeError); - createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event"); - exports$b$2.codes = codes; - return exports$b$2; -} - -var exports$a$2 = {}, - _dewExec$a$2 = false; -function dew$a$2() { - if (_dewExec$a$2) return exports$a$2; - _dewExec$a$2 = true; - - var ERR_INVALID_OPT_VALUE = dew$b$2().codes.ERR_INVALID_OPT_VALUE; - - function highWaterMarkFrom(options, isDuplex, duplexKey) { - return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; + return nextTick; } - - function getHighWaterMark(state, options, duplexKey, isDuplex) { - var hwm = highWaterMarkFrom(options, isDuplex, duplexKey); - - if (hwm != null) { - if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) { - var name = isDuplex ? duplexKey : "highWaterMark"; - throw new ERR_INVALID_OPT_VALUE(name, hwm); - } - - return Math.floor(hwm); - } // Default value - - - return state.objectMode ? 16 : 16 * 1024; + function browserPbkdf2(password, salt, iterations, length, algo) { + return subtle.importKey("raw", password, { + name: "PBKDF2" + }, false, ["deriveBits"]).then(function (key) { + return subtle.deriveBits({ + name: "PBKDF2", + salt: salt, + iterations: iterations, + hash: { + name: algo + } + }, key, length << 3); + }).then(function (res) { + return Buffer.from(res); + }); } - - exports$a$2 = { - getHighWaterMark: getHighWaterMark + function resolvePromise(promise, callback) { + promise.then(function (out) { + getNextTick()(function () { + callback(null, out); + }); + }, function (e) { + getNextTick()(function () { + callback(e); + }); + }); + } + exports$3l = function (password, salt, iterations, keylen, digest, callback) { + if (typeof digest === "function") { + callback = digest; + digest = undefined; + } + digest = digest || "sha1"; + var algo = toBrowser[digest.toLowerCase()]; + if (!algo || typeof _global$13.Promise !== "function") { + getNextTick()(function () { + var out; + try { + out = sync(password, salt, iterations, keylen, digest); + } catch (e) { + return callback(e); + } + callback(null, out); + }); + return; + } + checkParameters(iterations, keylen); + password = toBuffer(password, defaultEncoding, "Password"); + salt = toBuffer(salt, defaultEncoding, "Salt"); + if (typeof callback !== "function") throw new Error("No callback provided to pbkdf2"); + resolvePromise(checkNative(algo).then(function (resp) { + if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo); + return sync(password, salt, iterations, keylen, digest); + }), callback); }; - return exports$a$2; + return exports$3l; } -var exports$9$2 = {}, - _dewExec$9$2 = false; - -var _global$2$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$9$2() { - if (_dewExec$9$2) return exports$9$2; - _dewExec$9$2 = true; - - /** - * Module exports. - */ - exports$9$2 = deprecate; - /** - * Mark that a method should not be used. - * Returns a modified function which warns once by default. - * - * If `localStorage.noDeprecation = true` is set, then it is a no-op. - * - * If `localStorage.throwDeprecation = true` is set, then deprecated functions - * will throw an Error when invoked. - * - * If `localStorage.traceDeprecation = true` is set, then deprecated functions - * will invoke `console.trace()` instead of `console.error()`. - * - * @param {Function} fn - the function to deprecate - * @param {String} msg - the string to print to the console when `fn` is invoked - * @returns {Function} a new "deprecated" version of `fn` - * @api public - */ +var exports$3k = {}, + _dewExec$3j = false; +function dew$3j() { + if (_dewExec$3j) return exports$3k; + _dewExec$3j = true; + exports$3k.pbkdf2 = dew$3k(); + exports$3k.pbkdf2Sync = dew$3l(); + return exports$3k; +} - function deprecate(fn, msg) { - if (config("noDeprecation")) { - return fn; +var exports$3j = {}, + _dewExec$3i = false; +function dew$3i() { + if (_dewExec$3i) return exports$3j; + _dewExec$3i = true; + exports$3j.readUInt32BE = function readUInt32BE(bytes, off) { + var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off]; + return res >>> 0; + }; + exports$3j.writeUInt32BE = function writeUInt32BE(bytes, value, off) { + bytes[0 + off] = value >>> 24; + bytes[1 + off] = value >>> 16 & 255; + bytes[2 + off] = value >>> 8 & 255; + bytes[3 + off] = value & 255; + }; + exports$3j.ip = function ip(inL, inR, out, off) { + var outL = 0; + var outR = 0; + for (var i = 6; i >= 0; i -= 2) { + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >>> j + i & 1; + } + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inL >>> j + i & 1; + } } - - var warned = false; - - function deprecated() { - if (!warned) { - if (config("throwDeprecation")) { - throw new Error(msg); - } else if (config("traceDeprecation")) { - console.trace(msg); - } else { - console.warn(msg); - } - - warned = true; + for (var i = 6; i >= 0; i -= 2) { + for (var j = 1; j <= 25; j += 8) { + outR <<= 1; + outR |= inR >>> j + i & 1; + } + for (var j = 1; j <= 25; j += 8) { + outR <<= 1; + outR |= inL >>> j + i & 1; } - - return fn.apply(this || _global$2$2, arguments); } + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + exports$3j.rip = function rip(inL, inR, out, off) { + var outL = 0; + var outR = 0; + for (var i = 0; i < 4; i++) { + for (var j = 24; j >= 0; j -= 8) { + outL <<= 1; + outL |= inR >>> j + i & 1; + outL <<= 1; + outL |= inL >>> j + i & 1; + } + } + for (var i = 4; i < 8; i++) { + for (var j = 24; j >= 0; j -= 8) { + outR <<= 1; + outR |= inR >>> j + i & 1; + outR <<= 1; + outR |= inL >>> j + i & 1; + } + } + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + exports$3j.pc1 = function pc1(inL, inR, out, off) { + var outL = 0; + var outR = 0; - return deprecated; - } - /** - * Checks `localStorage` for boolean values for the given `name`. - * - * @param {String} name - * @returns {Boolean} - * @api private - */ - + // 7, 15, 23, 31, 39, 47, 55, 63 + // 6, 14, 22, 30, 39, 47, 55, 63 + // 5, 13, 21, 29, 39, 47, 55, 63 + // 4, 12, 20, 28 + for (var i = 7; i >= 5; i--) { + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >> j + i & 1; + } + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inL >> j + i & 1; + } + } + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >> j + i & 1; + } - function config(name) { - // accessing global.localStorage can trigger a DOMException in sandboxed iframes - try { - if (!_global$2$2.localStorage) return false; - } catch (_) { - return false; + // 1, 9, 17, 25, 33, 41, 49, 57 + // 2, 10, 18, 26, 34, 42, 50, 58 + // 3, 11, 19, 27, 35, 43, 51, 59 + // 36, 44, 52, 60 + for (var i = 1; i <= 3; i++) { + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inR >> j + i & 1; + } + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inL >> j + i & 1; + } + } + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inL >> j + i & 1; + } + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + exports$3j.r28shl = function r28shl(num, shift) { + return num << shift & 268435455 | num >>> 28 - shift; + }; + var pc2table = [ + // inL => outL + 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, + // inR => outR + 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24]; + exports$3j.pc2 = function pc2(inL, inR, out, off) { + var outL = 0; + var outR = 0; + var len = pc2table.length >>> 1; + for (var i = 0; i < len; i++) { + outL <<= 1; + outL |= inL >>> pc2table[i] & 1; + } + for (var i = len; i < pc2table.length; i++) { + outR <<= 1; + outR |= inR >>> pc2table[i] & 1; + } + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + exports$3j.expand = function expand(r, out, off) { + var outL = 0; + var outR = 0; + outL = (r & 1) << 5 | r >>> 27; + for (var i = 23; i >= 15; i -= 4) { + outL <<= 6; + outL |= r >>> i & 63; + } + for (var i = 11; i >= 3; i -= 4) { + outR |= r >>> i & 63; + outR <<= 6; + } + outR |= (r & 31) << 1 | r >>> 31; + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11]; + exports$3j.substitute = function substitute(inL, inR) { + var out = 0; + for (var i = 0; i < 4; i++) { + var b = inL >>> 18 - i * 6 & 63; + var sb = sTable[i * 64 + b]; + out <<= 4; + out |= sb; + } + for (var i = 0; i < 4; i++) { + var b = inR >>> 18 - i * 6 & 63; + var sb = sTable[4 * 64 + i * 64 + b]; + out <<= 4; + out |= sb; + } + return out >>> 0; + }; + var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7]; + exports$3j.permute = function permute(num) { + var out = 0; + for (var i = 0; i < permuteTable.length; i++) { + out <<= 1; + out |= num >>> permuteTable[i] & 1; } + return out >>> 0; + }; + exports$3j.padSplit = function padSplit(num, size, group) { + var str = num.toString(2); + while (str.length < size) str = "0" + str; + var out = []; + for (var i = 0; i < size; i += group) out.push(str.slice(i, i + group)); + return out.join(" "); + }; + return exports$3j; +} - var val = _global$2$2.localStorage[name]; - if (null == val) return false; - return String(val).toLowerCase() === "true"; +var exports$3i = {}, + _dewExec$3h = false; +function dew$3h() { + if (_dewExec$3h) return exports$3i; + _dewExec$3h = true; + exports$3i = assert; + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); } - - return exports$9$2; + assert.equal = function assertEqual(l, r, msg) { + if (l != r) throw new Error(msg || "Assertion failed: " + l + " != " + r); + }; + return exports$3i; } -var exports$8$2 = {}, - _dewExec$8$2 = false; - -var _global$1$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var exports$3h = {}, + _dewExec$3g = false; +function dew$3g() { + if (_dewExec$3g) return exports$3h; + _dewExec$3g = true; + var assert = dew$3h(); + function Cipher(options) { + this.options = options; + this.type = this.options.type; + this.blockSize = 8; + this._init(); + this.buffer = new Array(this.blockSize); + this.bufferOff = 0; + this.padding = options.padding !== false; + } + exports$3h = Cipher; + Cipher.prototype._init = function _init() { + // Might be overrided + }; + Cipher.prototype.update = function update(data) { + if (data.length === 0) return []; + if (this.type === "decrypt") return this._updateDecrypt(data);else return this._updateEncrypt(data); + }; + Cipher.prototype._buffer = function _buffer(data, off) { + // Append data to buffer + var min = Math.min(this.buffer.length - this.bufferOff, data.length - off); + for (var i = 0; i < min; i++) this.buffer[this.bufferOff + i] = data[off + i]; + this.bufferOff += min; -function dew$8$2() { - if (_dewExec$8$2) return exports$8$2; - _dewExec$8$2 = true; - var process = T$9; - exports$8$2 = Writable; - // there will be only 2 of these for each stream + // Shift next + return min; + }; + Cipher.prototype._flushBuffer = function _flushBuffer(out, off) { + this._update(this.buffer, 0, out, off); + this.bufferOff = 0; + return this.blockSize; + }; + Cipher.prototype._updateEncrypt = function _updateEncrypt(data) { + var inputOff = 0; + var outputOff = 0; + var count = (this.bufferOff + data.length) / this.blockSize | 0; + var out = new Array(count * this.blockSize); + if (this.bufferOff !== 0) { + inputOff += this._buffer(data, inputOff); + if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff); + } + // Write blocks + var max = data.length - (data.length - inputOff) % this.blockSize; + for (; inputOff < max; inputOff += this.blockSize) { + this._update(data, inputOff, out, outputOff); + outputOff += this.blockSize; + } - function CorkedRequest(state) { - var _this = this; + // Queue rest + for (; inputOff < data.length; inputOff++, this.bufferOff++) this.buffer[this.bufferOff] = data[inputOff]; + return out; + }; + Cipher.prototype._updateDecrypt = function _updateDecrypt(data) { + var inputOff = 0; + var outputOff = 0; + var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1; + var out = new Array(count * this.blockSize); - this.next = null; - this.entry = null; - - this.finish = function () { - onCorkedFinish(_this, state); - }; - } - /* */ - - /**/ - - - var Duplex; - /**/ - - Writable.WritableState = WritableState; - /**/ + // TODO(indutny): optimize it, this is far from optimal + for (; count > 0; count--) { + inputOff += this._buffer(data, inputOff); + outputOff += this._flushBuffer(out, outputOff); + } - var internalUtil = { - deprecate: dew$9$2() + // Buffer rest of the input + inputOff += this._buffer(data, inputOff); + return out; }; - /**/ - - /**/ - - var Stream = dew$e$2(); - /**/ - - - var Buffer = e$1$1$1.Buffer; - - var OurUint8Array = _global$1$2.Uint8Array || function () {}; + Cipher.prototype.final = function final(buffer) { + var first; + if (buffer) first = this.update(buffer); + var last; + if (this.type === "encrypt") last = this._finalEncrypt();else last = this._finalDecrypt(); + if (first) return first.concat(last);else return last; + }; + Cipher.prototype._pad = function _pad(buffer, off) { + if (off === 0) return false; + while (off < buffer.length) buffer[off++] = 0; + return true; + }; + Cipher.prototype._finalEncrypt = function _finalEncrypt() { + if (!this._pad(this.buffer, this.bufferOff)) return []; + var out = new Array(this.blockSize); + this._update(this.buffer, 0, out, 0); + return out; + }; + Cipher.prototype._unpad = function _unpad(buffer) { + return buffer; + }; + Cipher.prototype._finalDecrypt = function _finalDecrypt() { + assert.equal(this.bufferOff, this.blockSize, "Not enough data to decrypt"); + var out = new Array(this.blockSize); + this._flushBuffer(out, 0); + return this._unpad(out); + }; + return exports$3h; +} - function _uint8ArrayToBuffer(chunk) { - return Buffer.from(chunk); +var exports$3g = {}, + _dewExec$3f = false; +function dew$3f() { + if (_dewExec$3f) return exports$3g; + _dewExec$3f = true; + var assert = dew$3h(); + var inherits = dew$3I(); + var utils = dew$3i(); + var Cipher = dew$3g(); + function DESState() { + this.tmp = new Array(2); + this.keys = null; } - - function _isUint8Array(obj) { - return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + function DES(options) { + Cipher.call(this, options); + var state = new DESState(); + this._desState = state; + this.deriveKeys(state, options.key); } + inherits(DES, Cipher); + exports$3g = DES; + DES.create = function create(options) { + return new DES(options); + }; + var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]; + DES.prototype.deriveKeys = function deriveKeys(state, key) { + state.keys = new Array(16 * 2); + assert.equal(key.length, this.blockSize, "Invalid key length"); + var kL = utils.readUInt32BE(key, 0); + var kR = utils.readUInt32BE(key, 4); + utils.pc1(kL, kR, state.tmp, 0); + kL = state.tmp[0]; + kR = state.tmp[1]; + for (var i = 0; i < state.keys.length; i += 2) { + var shift = shiftTable[i >>> 1]; + kL = utils.r28shl(kL, shift); + kR = utils.r28shl(kR, shift); + utils.pc2(kL, kR, state.keys, i); + } + }; + DES.prototype._update = function _update(inp, inOff, out, outOff) { + var state = this._desState; + var l = utils.readUInt32BE(inp, inOff); + var r = utils.readUInt32BE(inp, inOff + 4); - var destroyImpl = dew$c$2(); - - var _require = dew$a$2(), - getHighWaterMark = _require.getHighWaterMark; - - var _require$codes = dew$b$2().codes, - ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, - ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, - ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, - ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE, - ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED, - ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, - ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, - ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING; - - var errorOrDestroy = destroyImpl.errorOrDestroy; - - dew$f$2()(Writable, Stream); - - function nop() {} - - function WritableState(options, stream, isDuplex) { - Duplex = Duplex || dew$7$2(); - options = options || {}; // Duplex streams are both readable and writable, but share - // the same options object. - // However, some cases require setting options to different - // values for the readable and the writable sides of the duplex stream, - // e.g. options.readableObjectMode vs. options.writableObjectMode, etc. - - if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream - // contains buffers or objects. - - this.objectMode = !!options.objectMode; - if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false - // Note: 0 is a valid value, means that we always return false if - // the entire buffer is not flushed immediately on write() - - this.highWaterMark = getHighWaterMark(this, options, "writableHighWaterMark", isDuplex); // if _final has been called - - this.finalCalled = false; // drain event flag. - - this.needDrain = false; // at the start of calling end() - - this.ending = false; // when end() has been called, and returned - - this.ended = false; // when 'finish' is emitted - - this.finished = false; // has it been destroyed - - this.destroyed = false; // should we decode strings into buffers before passing to _write? - // this is here so that some node-core streams can optimize string - // handling at a lower level. - - var noDecode = options.decodeStrings === false; - this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string - // encoding is 'binary' so we have to make this configurable. - // Everything else in the universe uses 'utf8', though. - - this.defaultEncoding = options.defaultEncoding || "utf8"; // not an actual buffer we keep track of, but a measurement - // of how much we're waiting to get pushed to some underlying - // socket or file. - - this.length = 0; // a flag to see when we're in the middle of a write. - - this.writing = false; // when true all writes will be buffered until .uncork() call - - this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately, - // or on a later tick. We set this to true at first, because any - // actions that shouldn't happen until "later" should generally also - // not happen before the first write call. - - this.sync = true; // a flag to know if we're processing previously buffered items, which - // may call the _write() callback in the same tick, so that we don't - // end up in an overlapped onwrite situation. - - this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb) - - this.onwrite = function (er) { - onwrite(stream, er); - }; // the callback that the user supplies to write(chunk,encoding,cb) - - - this.writecb = null; // the amount that is being written when _write is called. - - this.writelen = 0; - this.bufferedRequest = null; - this.lastBufferedRequest = null; // number of pending user-supplied write callbacks - // this must be 0 before 'finish' can be emitted - - this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs - // This is relevant for synchronous Transform streams - - this.prefinished = false; // True if the error was already emitted and should not be thrown again - - this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true. - - this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end') - - this.autoDestroy = !!options.autoDestroy; // count buffered requests - - this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always - // one allocated and free to use, and we maintain at most two - - this.corkedRequestsFree = new CorkedRequest(this); - } + // Initial Permutation + utils.ip(l, r, state.tmp, 0); + l = state.tmp[0]; + r = state.tmp[1]; + if (this.type === "encrypt") this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0); + l = state.tmp[0]; + r = state.tmp[1]; + utils.writeUInt32BE(out, l, outOff); + utils.writeUInt32BE(out, r, outOff + 4); + }; + DES.prototype._pad = function _pad(buffer, off) { + if (this.padding === false) { + return false; + } + var value = buffer.length - off; + for (var i = off; i < buffer.length; i++) buffer[i] = value; + return true; + }; + DES.prototype._unpad = function _unpad(buffer) { + if (this.padding === false) { + return buffer; + } + var pad = buffer[buffer.length - 1]; + for (var i = buffer.length - pad; i < buffer.length; i++) assert.equal(buffer[i], pad); + return buffer.slice(0, buffer.length - pad); + }; + DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) { + var l = lStart; + var r = rStart; - WritableState.prototype.getBuffer = function getBuffer() { - var current = this.bufferedRequest; - var out = []; + // Apply f() x16 times + for (var i = 0; i < state.keys.length; i += 2) { + var keyL = state.keys[i]; + var keyR = state.keys[i + 1]; - while (current) { - out.push(current); - current = current.next; + // f(r, k) + utils.expand(r, state.tmp, 0); + keyL ^= state.tmp[0]; + keyR ^= state.tmp[1]; + var s = utils.substitute(keyL, keyR); + var f = utils.permute(s); + var t = r; + r = (l ^ f) >>> 0; + l = t; } - return out; + // Reverse Initial Permutation + utils.rip(r, l, out, off); }; + DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) { + var l = rStart; + var r = lStart; - (function () { - try { - Object.defineProperty(WritableState.prototype, "buffer", { - get: internalUtil.deprecate(function writableStateBufferGetter() { - return this.getBuffer(); - }, "_writableState.buffer is deprecated. Use _writableState.getBuffer " + "instead.", "DEP0003") - }); - } catch (_) {} - })(); // Test _writableState for inheritance to account for Duplex streams, - // whose prototype chain only points to Readable. + // Apply f() x16 times + for (var i = state.keys.length - 2; i >= 0; i -= 2) { + var keyL = state.keys[i]; + var keyR = state.keys[i + 1]; + // f(r, k) + utils.expand(l, state.tmp, 0); + keyL ^= state.tmp[0]; + keyR ^= state.tmp[1]; + var s = utils.substitute(keyL, keyR); + var f = utils.permute(s); + var t = l; + l = (r ^ f) >>> 0; + r = t; + } - var realHasInstance; + // Reverse Initial Permutation + utils.rip(l, r, out, off); + }; + return exports$3g; +} - if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") { - realHasInstance = Function.prototype[Symbol.hasInstance]; - Object.defineProperty(Writable, Symbol.hasInstance, { - value: function value(object) { - if (realHasInstance.call(this, object)) return true; - if (this !== Writable) return false; - return object && object._writableState instanceof WritableState; - } - }); - } else { - realHasInstance = function realHasInstance(object) { - return object instanceof this; - }; +var exports$3f = {}, + _dewExec$3e = false; +function dew$3e() { + if (_dewExec$3e) return exports$3f; + _dewExec$3e = true; + var assert = dew$3h(); + var inherits = dew$3I(); + var proto = {}; + function CBCState(iv) { + assert.equal(iv.length, 8, "Invalid IV length"); + this.iv = new Array(8); + for (var i = 0; i < this.iv.length; i++) this.iv[i] = iv[i]; } - - function Writable(options) { - Duplex = Duplex || dew$7$2(); // Writable ctor is applied to Duplexes, too. - // `realHasInstance` is necessary because using plain `instanceof` - // would return false, as no `_writableState` property is attached. - // Trying to use the custom `instanceof` for Writable here will also break the - // Node.js LazyTransform implementation, which has a non-trivial getter for - // `_writableState` that would lead to infinite recursion. - // Checking for a Stream.Duplex instance is faster here instead of inside - // the WritableState constructor, at least with V8 6.5 - - var isDuplex = this instanceof Duplex; - if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options); - this._writableState = new WritableState(options, this, isDuplex); // legacy. - - this.writable = true; - - if (options) { - if (typeof options.write === "function") this._write = options.write; - if (typeof options.writev === "function") this._writev = options.writev; - if (typeof options.destroy === "function") this._destroy = options.destroy; - if (typeof options.final === "function") this._final = options.final; + function instantiate(Base) { + function CBC(options) { + Base.call(this, options); + this._cbcInit(); } - - Stream.call(this); - } // Otherwise people can pipe Writable streams, which is just wrong. - - - Writable.prototype.pipe = function () { - errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE()); + inherits(CBC, Base); + var keys = Object.keys(proto); + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + CBC.prototype[key] = proto[key]; + } + CBC.create = function create(options) { + return new CBC(options); + }; + return CBC; + } + exports$3f.instantiate = instantiate; + proto._cbcInit = function _cbcInit() { + var state = new CBCState(this.options.iv); + this._cbcState = state; }; - - function writeAfterEnd(stream, cb) { - var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb - - errorOrDestroy(stream, er); - process.nextTick(cb, er); - } // Checks that a user-supplied chunk is valid, especially for the particular - // mode the stream is in. Currently this means that `null` is never accepted - // and undefined/non-string values are only allowed in object mode. - - - function validChunk(stream, state, chunk, cb) { - var er; - - if (chunk === null) { - er = new ERR_STREAM_NULL_VALUES(); - } else if (typeof chunk !== "string" && !state.objectMode) { - er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk); + proto._update = function _update(inp, inOff, out, outOff) { + var state = this._cbcState; + var superProto = this.constructor.super_.prototype; + var iv = state.iv; + if (this.type === "encrypt") { + for (var i = 0; i < this.blockSize; i++) iv[i] ^= inp[inOff + i]; + superProto._update.call(this, iv, 0, out, outOff); + for (var i = 0; i < this.blockSize; i++) iv[i] = out[outOff + i]; + } else { + superProto._update.call(this, inp, inOff, out, outOff); + for (var i = 0; i < this.blockSize; i++) out[outOff + i] ^= iv[i]; + for (var i = 0; i < this.blockSize; i++) iv[i] = inp[inOff + i]; } + }; + return exports$3f; +} - if (er) { - errorOrDestroy(stream, er); - process.nextTick(cb, er); - return false; +var exports$3e = {}, + _dewExec$3d = false; +function dew$3d() { + if (_dewExec$3d) return exports$3e; + _dewExec$3d = true; + var assert = dew$3h(); + var inherits = dew$3I(); + var Cipher = dew$3g(); + var DES = dew$3f(); + function EDEState(type, key) { + assert.equal(key.length, 24, "Invalid key length"); + var k1 = key.slice(0, 8); + var k2 = key.slice(8, 16); + var k3 = key.slice(16, 24); + if (type === "encrypt") { + this.ciphers = [DES.create({ + type: "encrypt", + key: k1 + }), DES.create({ + type: "decrypt", + key: k2 + }), DES.create({ + type: "encrypt", + key: k3 + })]; + } else { + this.ciphers = [DES.create({ + type: "decrypt", + key: k3 + }), DES.create({ + type: "encrypt", + key: k2 + }), DES.create({ + type: "decrypt", + key: k1 + })]; } - - return true; } + function EDE(options) { + Cipher.call(this, options); + var state = new EDEState(this.type, this.options.key); + this._edeState = state; + } + inherits(EDE, Cipher); + exports$3e = EDE; + EDE.create = function create(options) { + return new EDE(options); + }; + EDE.prototype._update = function _update(inp, inOff, out, outOff) { + var state = this._edeState; + state.ciphers[0]._update(inp, inOff, out, outOff); + state.ciphers[1]._update(out, outOff, out, outOff); + state.ciphers[2]._update(out, outOff, out, outOff); + }; + EDE.prototype._pad = DES.prototype._pad; + EDE.prototype._unpad = DES.prototype._unpad; + return exports$3e; +} - Writable.prototype.write = function (chunk, encoding, cb) { - var state = this._writableState; - var ret = false; - - var isBuf = !state.objectMode && _isUint8Array(chunk); +var exports$3d = {}, + _dewExec$3c = false; +function dew$3c() { + if (_dewExec$3c) return exports$3d; + _dewExec$3c = true; + exports$3d.utils = dew$3i(); + exports$3d.Cipher = dew$3g(); + exports$3d.DES = dew$3f(); + exports$3d.CBC = dew$3e(); + exports$3d.EDE = dew$3d(); + return exports$3d; +} - if (isBuf && !Buffer.isBuffer(chunk)) { - chunk = _uint8ArrayToBuffer(chunk); +var exports$3c = {}, + _dewExec$3b = false; +var _global$12 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$3b() { + if (_dewExec$3b) return exports$3c; + _dewExec$3b = true; + var CipherBase = dew$3u(); + var des = dew$3c(); + var inherits = dew$3I(); + var Buffer = dew$3H().Buffer; + var modes = { + "des-ede3-cbc": des.CBC.instantiate(des.EDE), + "des-ede3": des.EDE, + "des-ede-cbc": des.CBC.instantiate(des.EDE), + "des-ede": des.EDE, + "des-cbc": des.CBC.instantiate(des.DES), + "des-ecb": des.DES + }; + modes.des = modes["des-cbc"]; + modes.des3 = modes["des-ede3-cbc"]; + exports$3c = DES; + inherits(DES, CipherBase); + function DES(opts) { + CipherBase.call(this || _global$12); + var modeName = opts.mode.toLowerCase(); + var mode = modes[modeName]; + var type; + if (opts.decrypt) { + type = "decrypt"; + } else { + type = "encrypt"; } - - if (typeof encoding === "function") { - cb = encoding; - encoding = null; + var key = opts.key; + if (!Buffer.isBuffer(key)) { + key = Buffer.from(key); } - - if (isBuf) encoding = "buffer";else if (!encoding) encoding = state.defaultEncoding; - if (typeof cb !== "function") cb = nop; - if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { - state.pendingcb++; - ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); + if (modeName === "des-ede" || modeName === "des-ede-cbc") { + key = Buffer.concat([key, key.slice(0, 8)]); } - return ret; + var iv = opts.iv; + if (!Buffer.isBuffer(iv)) { + iv = Buffer.from(iv); + } + (this || _global$12)._des = mode.create({ + key: key, + iv: iv, + type: type + }); + } + DES.prototype._update = function (data) { + return Buffer.from((this || _global$12)._des.update(data)); }; - - Writable.prototype.cork = function () { - this._writableState.corked++; + DES.prototype._final = function () { + return Buffer.from((this || _global$12)._des.final()); }; + return exports$3c; +} - Writable.prototype.uncork = function () { - var state = this._writableState; +var exports$3b = {}, + _dewExec$3a = false; +function dew$3a() { + if (_dewExec$3a) return exports$3b; + _dewExec$3a = true; + exports$3b.encrypt = function (self, block) { + return self._cipher.encryptBlock(block); + }; + exports$3b.decrypt = function (self, block) { + return self._cipher.decryptBlock(block); + }; + return exports$3b; +} - if (state.corked) { - state.corked--; - if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); +var exports$3a = {}, + _dewExec$39 = false; +function dew$39() { + if (_dewExec$39) return exports$3a; + _dewExec$39 = true; + var Buffer = dew$3J().Buffer; + exports$3a = function xor(a, b) { + var length = Math.min(a.length, b.length); + var buffer = new Buffer(length); + for (var i = 0; i < length; ++i) { + buffer[i] = a[i] ^ b[i]; } + return buffer; }; + return exports$3a; +} - Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { - // node::ParseEncoding() requires lower case. - if (typeof encoding === "string") encoding = encoding.toLowerCase(); - if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding); - this._writableState.defaultEncoding = encoding; - return this; +var exports$39 = {}, + _dewExec$38 = false; +function dew$38() { + if (_dewExec$38) return exports$39; + _dewExec$38 = true; + var xor = dew$39(); + exports$39.encrypt = function (self, block) { + var data = xor(block, self._prev); + self._prev = self._cipher.encryptBlock(data); + return self._prev; }; + exports$39.decrypt = function (self, block) { + var pad = self._prev; + self._prev = block; + var out = self._cipher.decryptBlock(block); + return xor(out, pad); + }; + return exports$39; +} - Object.defineProperty(Writable.prototype, "writableBuffer", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._writableState && this._writableState.getBuffer(); +var exports$38 = {}, + _dewExec$37 = false; +function dew$37() { + if (_dewExec$37) return exports$38; + _dewExec$37 = true; + var Buffer = dew$3H().Buffer; + var xor = dew$39(); + function encryptStart(self, data, decrypt) { + var len = data.length; + var out = xor(data, self._cache); + self._cache = self._cache.slice(len); + self._prev = Buffer.concat([self._prev, decrypt ? data : out]); + return out; + } + exports$38.encrypt = function (self, data, decrypt) { + var out = Buffer.allocUnsafe(0); + var len; + while (data.length) { + if (self._cache.length === 0) { + self._cache = self._cipher.encryptBlock(self._prev); + self._prev = Buffer.allocUnsafe(0); + } + if (self._cache.length <= data.length) { + len = self._cache.length; + out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]); + data = data.slice(len); + } else { + out = Buffer.concat([out, encryptStart(self, data, decrypt)]); + break; + } } - }); + return out; + }; + return exports$38; +} - function decodeChunk(state, chunk, encoding) { - if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") { - chunk = Buffer.from(chunk, encoding); +var exports$37 = {}, + _dewExec$36 = false; +function dew$36() { + if (_dewExec$36) return exports$37; + _dewExec$36 = true; + var Buffer = dew$3H().Buffer; + function encryptByte(self, byteParam, decrypt) { + var pad = self._cipher.encryptBlock(self._prev); + var out = pad[0] ^ byteParam; + self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]); + return out; + } + exports$37.encrypt = function (self, chunk, decrypt) { + var len = chunk.length; + var out = Buffer.allocUnsafe(len); + var i = -1; + while (++i < len) { + out[i] = encryptByte(self, chunk[i], decrypt); } + return out; + }; + return exports$37; +} - return chunk; +var exports$36 = {}, + _dewExec$35 = false; +function dew$35() { + if (_dewExec$35) return exports$36; + _dewExec$35 = true; + var Buffer = dew$3H().Buffer; + function encryptByte(self, byteParam, decrypt) { + var pad; + var i = -1; + var len = 8; + var out = 0; + var bit, value; + while (++i < len) { + pad = self._cipher.encryptBlock(self._prev); + bit = byteParam & 1 << 7 - i ? 128 : 0; + value = pad[0] ^ bit; + out += (value & 128) >> i % 8; + self._prev = shiftIn(self._prev, decrypt ? bit : value); + } + return out; } - - Object.defineProperty(Writable.prototype, "writableHighWaterMark", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._writableState.highWaterMark; + function shiftIn(buffer, value) { + var len = buffer.length; + var i = -1; + var out = Buffer.allocUnsafe(buffer.length); + buffer = Buffer.concat([buffer, Buffer.from([value])]); + while (++i < len) { + out[i] = buffer[i] << 1 | buffer[i + 1] >> 7; } - }); // if we're already writing something, then just put this - // in the queue, and wait our turn. Otherwise, call _write - // If we return false, then we need a drain event, so set that flag. - - function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { - if (!isBuf) { - var newChunk = decodeChunk(state, chunk, encoding); - - if (chunk !== newChunk) { - isBuf = true; - encoding = "buffer"; - chunk = newChunk; - } + return out; + } + exports$36.encrypt = function (self, chunk, decrypt) { + var len = chunk.length; + var out = Buffer.allocUnsafe(len); + var i = -1; + while (++i < len) { + out[i] = encryptByte(self, chunk[i], decrypt); } + return out; + }; + return exports$36; +} - var len = state.objectMode ? 1 : chunk.length; - state.length += len; - var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false. - - if (!ret) state.needDrain = true; - - if (state.writing || state.corked) { - var last = state.lastBufferedRequest; - state.lastBufferedRequest = { - chunk: chunk, - encoding: encoding, - isBuf: isBuf, - callback: cb, - next: null - }; +var exports$35 = {}, + _dewExec$34 = false; +function dew$34() { + if (_dewExec$34) return exports$35; + _dewExec$34 = true; + var Buffer = dew$3J().Buffer; + var xor = dew$39(); + function getBlock(self) { + self._prev = self._cipher.encryptBlock(self._prev); + return self._prev; + } + exports$35.encrypt = function (self, chunk) { + while (self._cache.length < chunk.length) { + self._cache = Buffer.concat([self._cache, getBlock(self)]); + } + var pad = self._cache.slice(0, chunk.length); + self._cache = self._cache.slice(chunk.length); + return xor(chunk, pad); + }; + return exports$35; +} - if (last) { - last.next = state.lastBufferedRequest; +var exports$34 = {}, + _dewExec$33 = false; +function dew$33() { + if (_dewExec$33) return exports$34; + _dewExec$33 = true; + function incr32(iv) { + var len = iv.length; + var item; + while (len--) { + item = iv.readUInt8(len); + if (item === 255) { + iv.writeUInt8(0, len); } else { - state.bufferedRequest = state.lastBufferedRequest; + item++; + iv.writeUInt8(item, len); + break; } - - state.bufferedRequestCount += 1; - } else { - doWrite(stream, state, false, len, chunk, encoding, cb); } - - return ret; } + exports$34 = incr32; + return exports$34; +} - function doWrite(stream, state, writev, len, chunk, encoding, cb) { - state.writelen = len; - state.writecb = cb; - state.writing = true; - state.sync = true; - if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED("write"));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); - state.sync = false; +var exports$33 = {}, + _dewExec$32 = false; +function dew$32() { + if (_dewExec$32) return exports$33; + _dewExec$32 = true; + var xor = dew$39(); + var Buffer = dew$3H().Buffer; + var incr32 = dew$33(); + function getBlock(self) { + var out = self._cipher.encryptBlockRaw(self._prev); + incr32(self._prev); + return out; } + var blockSize = 16; + exports$33.encrypt = function (self, chunk) { + var chunkNum = Math.ceil(chunk.length / blockSize); + var start = self._cache.length; + self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]); + for (var i = 0; i < chunkNum; i++) { + var out = getBlock(self); + var offset = start + i * blockSize; + self._cache.writeUInt32BE(out[0], offset + 0); + self._cache.writeUInt32BE(out[1], offset + 4); + self._cache.writeUInt32BE(out[2], offset + 8); + self._cache.writeUInt32BE(out[3], offset + 12); + } + var pad = self._cache.slice(0, chunk.length); + self._cache = self._cache.slice(chunk.length); + return xor(chunk, pad); + }; + return exports$33; +} - function onwriteError(stream, state, sync, er, cb) { - --state.pendingcb; +var _list$2 = { + "aes-128-ecb": { + "cipher": "AES", + "key": 128, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-192-ecb": { + "cipher": "AES", + "key": 192, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-256-ecb": { + "cipher": "AES", + "key": 256, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-128-cbc": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-192-cbc": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-256-cbc": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes128": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes192": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes256": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-128-cfb": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-192-cfb": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-256-cfb": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-128-cfb8": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-192-cfb8": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-256-cfb8": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-128-cfb1": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-192-cfb1": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-256-cfb1": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-128-ofb": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-192-ofb": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-256-ofb": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-128-ctr": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-192-ctr": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-256-ctr": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-128-gcm": { + "cipher": "AES", + "key": 128, + "iv": 12, + "mode": "GCM", + "type": "auth" + }, + "aes-192-gcm": { + "cipher": "AES", + "key": 192, + "iv": 12, + "mode": "GCM", + "type": "auth" + }, + "aes-256-gcm": { + "cipher": "AES", + "key": 256, + "iv": 12, + "mode": "GCM", + "type": "auth" + } +}; - if (sync) { - // defer the callback if we are being called synchronously - // to avoid piling up things on the stack - process.nextTick(cb, er); // this can emit finish, and it will always happen - // after error +var exports$32 = {}, + _dewExec$31 = false; +function dew$31() { + if (_dewExec$31) return exports$32; + _dewExec$31 = true; + var modeModules = { + ECB: dew$3a(), + CBC: dew$38(), + CFB: dew$37(), + CFB8: dew$36(), + CFB1: dew$35(), + OFB: dew$34(), + CTR: dew$32(), + GCM: dew$32() + }; + var modes = _list$2; + for (var key in modes) { + modes[key].module = modeModules[modes[key].mode]; + } + exports$32 = modes; + return exports$32; +} - process.nextTick(finishMaybe, stream, state); - stream._writableState.errorEmitted = true; - errorOrDestroy(stream, er); - } else { - // the caller expect this to happen before if - // it is async - cb(er); - stream._writableState.errorEmitted = true; - errorOrDestroy(stream, er); // this can emit finish, but finish must - // always follow error +var exports$31 = {}, + _dewExec$30 = false; +var _global$11 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$30() { + if (_dewExec$30) return exports$31; + _dewExec$30 = true; + // based on the aes implimentation in triple sec + // https://github.com/keybase/triplesec + // which is in turn based on the one from crypto-js + // https://code.google.com/p/crypto-js/ - finishMaybe(stream, state); + var Buffer = dew$3H().Buffer; + function asUInt32Array(buf) { + if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); + var len = buf.length / 4 | 0; + var out = new Array(len); + for (var i = 0; i < len; i++) { + out[i] = buf.readUInt32BE(i * 4); } + return out; } - - function onwriteStateUpdate(state) { - state.writing = false; - state.writecb = null; - state.length -= state.writelen; - state.writelen = 0; + function scrubVec(v) { + for (var i = 0; i < v.length; v++) { + v[i] = 0; + } } - - function onwrite(stream, er) { - var state = stream._writableState; - var sync = state.sync; - var cb = state.writecb; - if (typeof cb !== "function") throw new ERR_MULTIPLE_CALLBACK(); - onwriteStateUpdate(state); - if (er) onwriteError(stream, state, sync, er, cb);else { - // Check if we're actually ready to finish, but don't emit yet - var finished = needFinish(state) || stream.destroyed; - - if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { - clearBuffer(stream, state); - } - - if (sync) { - process.nextTick(afterWrite, stream, state, finished, cb); - } else { - afterWrite(stream, state, finished, cb); - } + function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) { + var SUB_MIX0 = SUB_MIX[0]; + var SUB_MIX1 = SUB_MIX[1]; + var SUB_MIX2 = SUB_MIX[2]; + var SUB_MIX3 = SUB_MIX[3]; + var s0 = M[0] ^ keySchedule[0]; + var s1 = M[1] ^ keySchedule[1]; + var s2 = M[2] ^ keySchedule[2]; + var s3 = M[3] ^ keySchedule[3]; + var t0, t1, t2, t3; + var ksRow = 4; + for (var round = 1; round < nRounds; round++) { + t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 255] ^ SUB_MIX2[s2 >>> 8 & 255] ^ SUB_MIX3[s3 & 255] ^ keySchedule[ksRow++]; + t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 255] ^ SUB_MIX2[s3 >>> 8 & 255] ^ SUB_MIX3[s0 & 255] ^ keySchedule[ksRow++]; + t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 255] ^ SUB_MIX2[s0 >>> 8 & 255] ^ SUB_MIX3[s1 & 255] ^ keySchedule[ksRow++]; + t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 255] ^ SUB_MIX2[s1 >>> 8 & 255] ^ SUB_MIX3[s2 & 255] ^ keySchedule[ksRow++]; + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; } + t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 255] << 16 | SBOX[s2 >>> 8 & 255] << 8 | SBOX[s3 & 255]) ^ keySchedule[ksRow++]; + t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 255] << 16 | SBOX[s3 >>> 8 & 255] << 8 | SBOX[s0 & 255]) ^ keySchedule[ksRow++]; + t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 255] << 16 | SBOX[s0 >>> 8 & 255] << 8 | SBOX[s1 & 255]) ^ keySchedule[ksRow++]; + t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 255] << 16 | SBOX[s1 >>> 8 & 255] << 8 | SBOX[s2 & 255]) ^ keySchedule[ksRow++]; + t0 = t0 >>> 0; + t1 = t1 >>> 0; + t2 = t2 >>> 0; + t3 = t3 >>> 0; + return [t0, t1, t2, t3]; } - function afterWrite(stream, state, finished, cb) { - if (!finished) onwriteDrain(stream, state); - state.pendingcb--; - cb(); - finishMaybe(stream, state); - } // Must force callback to be called on nextTick, so that we don't - // emit 'drain' before the write() consumer gets the 'false' return - // value, and has a chance to attach a 'drain' listener. - - - function onwriteDrain(stream, state) { - if (state.length === 0 && state.needDrain) { - state.needDrain = false; - stream.emit("drain"); + // AES constants + var RCON = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]; + var G = function () { + // Compute double table + var d = new Array(256); + for (var j = 0; j < 256; j++) { + if (j < 128) { + d[j] = j << 1; + } else { + d[j] = j << 1 ^ 283; + } } - } // if there's something in the buffer waiting, then process it + var SBOX = []; + var INV_SBOX = []; + var SUB_MIX = [[], [], [], []]; + var INV_SUB_MIX = [[], [], [], []]; + // Walk GF(2^8) + var x = 0; + var xi = 0; + for (var i = 0; i < 256; ++i) { + // Compute sbox + var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4; + sx = sx >>> 8 ^ sx & 255 ^ 99; + SBOX[x] = sx; + INV_SBOX[sx] = x; - function clearBuffer(stream, state) { - state.bufferProcessing = true; - var entry = state.bufferedRequest; + // Compute multiplication + var x2 = d[x]; + var x4 = d[x2]; + var x8 = d[x4]; - if (stream._writev && entry && entry.next) { - // Fast case, write everything using _writev() - var l = state.bufferedRequestCount; - var buffer = new Array(l); - var holder = state.corkedRequestsFree; - holder.entry = entry; - var count = 0; - var allBuffers = true; + // Compute sub bytes, mix columns tables + var t = d[sx] * 257 ^ sx * 16843008; + SUB_MIX[0][x] = t << 24 | t >>> 8; + SUB_MIX[1][x] = t << 16 | t >>> 16; + SUB_MIX[2][x] = t << 8 | t >>> 24; + SUB_MIX[3][x] = t; - while (entry) { - buffer[count] = entry; - if (!entry.isBuf) allBuffers = false; - entry = entry.next; - count += 1; - } - - buffer.allBuffers = allBuffers; - doWrite(stream, state, true, state.length, buffer, "", holder.finish); // doWrite is almost always async, defer these to save a bit of time - // as the hot path ends with doWrite - - state.pendingcb++; - state.lastBufferedRequest = null; - - if (holder.next) { - state.corkedRequestsFree = holder.next; - holder.next = null; + // Compute inv sub bytes, inv mix columns tables + t = x8 * 16843009 ^ x4 * 65537 ^ x2 * 257 ^ x * 16843008; + INV_SUB_MIX[0][sx] = t << 24 | t >>> 8; + INV_SUB_MIX[1][sx] = t << 16 | t >>> 16; + INV_SUB_MIX[2][sx] = t << 8 | t >>> 24; + INV_SUB_MIX[3][sx] = t; + if (x === 0) { + x = xi = 1; } else { - state.corkedRequestsFree = new CorkedRequest(state); - } - - state.bufferedRequestCount = 0; - } else { - // Slow case, write chunks one-by-one - while (entry) { - var chunk = entry.chunk; - var encoding = entry.encoding; - var cb = entry.callback; - var len = state.objectMode ? 1 : chunk.length; - doWrite(stream, state, false, len, chunk, encoding, cb); - entry = entry.next; - state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then - // it means that we need to wait until it does. - // also, that means that the chunk and cb are currently - // being processed, so move the buffer counter past them. - - if (state.writing) { - break; - } + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; } - - if (entry === null) state.lastBufferedRequest = null; } - - state.bufferedRequest = entry; - state.bufferProcessing = false; + return { + SBOX: SBOX, + INV_SBOX: INV_SBOX, + SUB_MIX: SUB_MIX, + INV_SUB_MIX: INV_SUB_MIX + }; + }(); + function AES(key) { + (this || _global$11)._key = asUInt32Array(key); + this._reset(); } - - Writable.prototype._write = function (chunk, encoding, cb) { - cb(new ERR_METHOD_NOT_IMPLEMENTED("_write()")); - }; - - Writable.prototype._writev = null; - - Writable.prototype.end = function (chunk, encoding, cb) { - var state = this._writableState; - - if (typeof chunk === "function") { - cb = chunk; - chunk = null; - encoding = null; - } else if (typeof encoding === "function") { - cb = encoding; - encoding = null; - } - - if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks - - if (state.corked) { - state.corked = 1; - this.uncork(); - } // ignore unnecessary end() calls. - - - if (!state.ending) endWritable(this, state, cb); - return this; - }; - - Object.defineProperty(Writable.prototype, "writableLength", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._writableState.length; + AES.blockSize = 4 * 4; + AES.keySize = 256 / 8; + AES.prototype.blockSize = AES.blockSize; + AES.prototype.keySize = AES.keySize; + AES.prototype._reset = function () { + var keyWords = (this || _global$11)._key; + var keySize = keyWords.length; + var nRounds = keySize + 6; + var ksRows = (nRounds + 1) * 4; + var keySchedule = []; + for (var k = 0; k < keySize; k++) { + keySchedule[k] = keyWords[k]; } - }); - - function needFinish(state) { - return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; - } - - function callFinal(stream, state) { - stream._final(function (err) { - state.pendingcb--; - - if (err) { - errorOrDestroy(stream, err); + for (k = keySize; k < ksRows; k++) { + var t = keySchedule[k - 1]; + if (k % keySize === 0) { + t = t << 8 | t >>> 24; + t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; + t ^= RCON[k / keySize | 0] << 24; + } else if (keySize > 6 && k % keySize === 4) { + t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; } - - state.prefinished = true; - stream.emit("prefinish"); - finishMaybe(stream, state); - }); - } - - function prefinish(stream, state) { - if (!state.prefinished && !state.finalCalled) { - if (typeof stream._final === "function" && !state.destroyed) { - state.pendingcb++; - state.finalCalled = true; - process.nextTick(callFinal, stream, state); + keySchedule[k] = keySchedule[k - keySize] ^ t; + } + var invKeySchedule = []; + for (var ik = 0; ik < ksRows; ik++) { + var ksR = ksRows - ik; + var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]; + if (ik < 4 || ksR <= 4) { + invKeySchedule[ik] = tt; } else { - state.prefinished = true; - stream.emit("prefinish"); + invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 255]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 255]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 255]]; } } - } - - function finishMaybe(stream, state) { - var need = needFinish(state); - - if (need) { - prefinish(stream, state); - - if (state.pendingcb === 0) { - state.finished = true; - stream.emit("finish"); - - if (state.autoDestroy) { - // In case of duplex streams we need a way to detect - // if the readable side is ready for autoDestroy as well - var rState = stream._readableState; + (this || _global$11)._nRounds = nRounds; + (this || _global$11)._keySchedule = keySchedule; + (this || _global$11)._invKeySchedule = invKeySchedule; + }; + AES.prototype.encryptBlockRaw = function (M) { + M = asUInt32Array(M); + return cryptBlock(M, (this || _global$11)._keySchedule, G.SUB_MIX, G.SBOX, (this || _global$11)._nRounds); + }; + AES.prototype.encryptBlock = function (M) { + var out = this.encryptBlockRaw(M); + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[1], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[3], 12); + return buf; + }; + AES.prototype.decryptBlock = function (M) { + M = asUInt32Array(M); - if (!rState || rState.autoDestroy && rState.endEmitted) { - stream.destroy(); - } - } - } - } + // swap + var m1 = M[1]; + M[1] = M[3]; + M[3] = m1; + var out = cryptBlock(M, (this || _global$11)._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, (this || _global$11)._nRounds); + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[3], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[1], 12); + return buf; + }; + AES.prototype.scrub = function () { + scrubVec((this || _global$11)._keySchedule); + scrubVec((this || _global$11)._invKeySchedule); + scrubVec((this || _global$11)._key); + }; + exports$31.AES = AES; + return exports$31; +} - return need; +var exports$30 = {}, + _dewExec$2$ = false; +var _global$10 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2$() { + if (_dewExec$2$) return exports$30; + _dewExec$2$ = true; + var Buffer = dew$3H().Buffer; + var ZEROES = Buffer.alloc(16, 0); + function toArray(buf) { + return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)]; } - - function endWritable(stream, state, cb) { - state.ending = true; - finishMaybe(stream, state); - - if (cb) { - if (state.finished) process.nextTick(cb);else stream.once("finish", cb); - } - - state.ended = true; - stream.writable = false; + function fromArray(out) { + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0] >>> 0, 0); + buf.writeUInt32BE(out[1] >>> 0, 4); + buf.writeUInt32BE(out[2] >>> 0, 8); + buf.writeUInt32BE(out[3] >>> 0, 12); + return buf; } - - function onCorkedFinish(corkReq, state, err) { - var entry = corkReq.entry; - corkReq.entry = null; - - while (entry) { - var cb = entry.callback; - state.pendingcb--; - cb(err); - entry = entry.next; - } // reuse the free corkReq. - - - state.corkedRequestsFree.next = corkReq; + function GHASH(key) { + (this || _global$10).h = key; + (this || _global$10).state = Buffer.alloc(16, 0); + (this || _global$10).cache = Buffer.allocUnsafe(0); } - Object.defineProperty(Writable.prototype, "destroyed", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - if (this._writableState === undefined) { - return false; + // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html + // by Juho Vähä-Herttua + GHASH.prototype.ghash = function (block) { + var i = -1; + while (++i < block.length) { + (this || _global$10).state[i] ^= block[i]; + } + this._multiply(); + }; + GHASH.prototype._multiply = function () { + var Vi = toArray((this || _global$10).h); + var Zi = [0, 0, 0, 0]; + var j, xi, lsbVi; + var i = -1; + while (++i < 128) { + xi = ((this || _global$10).state[~~(i / 8)] & 1 << 7 - i % 8) !== 0; + if (xi) { + // Z_i+1 = Z_i ^ V_i + Zi[0] ^= Vi[0]; + Zi[1] ^= Vi[1]; + Zi[2] ^= Vi[2]; + Zi[3] ^= Vi[3]; } - return this._writableState.destroyed; - }, - set: function set(value) { - // we ignore the value if the stream - // has not been initialized yet - if (!this._writableState) { - return; - } // backward compatibility, the user is explicitly - // managing destroyed + // Store the value of LSB(V_i) + lsbVi = (Vi[3] & 1) !== 0; + // V_i+1 = V_i >> 1 + for (j = 3; j > 0; j--) { + Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31; + } + Vi[0] = Vi[0] >>> 1; - this._writableState.destroyed = value; + // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R + if (lsbVi) { + Vi[0] = Vi[0] ^ 225 << 24; + } } - }); - Writable.prototype.destroy = destroyImpl.destroy; - Writable.prototype._undestroy = destroyImpl.undestroy; - - Writable.prototype._destroy = function (err, cb) { - cb(err); + (this || _global$10).state = fromArray(Zi); }; - - return exports$8$2; -} - -var exports$7$2 = {}, - _dewExec$7$2 = false; -function dew$7$2() { - if (_dewExec$7$2) return exports$7$2; - _dewExec$7$2 = true; - var process = T$9; - - /**/ - var objectKeys = Object.keys || function (obj) { - var keys = []; - - for (var key in obj) { - keys.push(key); + GHASH.prototype.update = function (buf) { + (this || _global$10).cache = Buffer.concat([(this || _global$10).cache, buf]); + var chunk; + while ((this || _global$10).cache.length >= 16) { + chunk = (this || _global$10).cache.slice(0, 16); + (this || _global$10).cache = (this || _global$10).cache.slice(16); + this.ghash(chunk); } - - return keys; }; - /**/ - - - exports$7$2 = Duplex; - - var Readable = dew$3$2(); - - var Writable = dew$8$2(); - - dew$f$2()(Duplex, Readable); - - { - // Allow the keys array to be GC'ed. - var keys = objectKeys(Writable.prototype); - - for (var v = 0; v < keys.length; v++) { - var method = keys[v]; - if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + GHASH.prototype.final = function (abl, bl) { + if ((this || _global$10).cache.length) { + this.ghash(Buffer.concat([(this || _global$10).cache, ZEROES], 16)); } - } - - function Duplex(options) { - if (!(this instanceof Duplex)) return new Duplex(options); - Readable.call(this, options); - Writable.call(this, options); - this.allowHalfOpen = true; - - if (options) { - if (options.readable === false) this.readable = false; - if (options.writable === false) this.writable = false; + this.ghash(fromArray([0, abl, 0, bl])); + return (this || _global$10).state; + }; + exports$30 = GHASH; + return exports$30; +} - if (options.allowHalfOpen === false) { - this.allowHalfOpen = false; - this.once("end", onend); - } +var exports$2$ = {}, + _dewExec$2_ = false; +var _global$$ = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2_() { + if (_dewExec$2_) return exports$2$; + _dewExec$2_ = true; + var aes = dew$30(); + var Buffer = dew$3H().Buffer; + var Transform = dew$3u(); + var inherits = dew$3I(); + var GHASH = dew$2$(); + var xor = dew$39(); + var incr32 = dew$33(); + function xorTest(a, b) { + var out = 0; + if (a.length !== b.length) out++; + var len = Math.min(a.length, b.length); + for (var i = 0; i < len; ++i) { + out += a[i] ^ b[i]; } + return out; } - - Object.defineProperty(Duplex.prototype, "writableHighWaterMark", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._writableState.highWaterMark; - } - }); - Object.defineProperty(Duplex.prototype, "writableBuffer", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._writableState && this._writableState.getBuffer(); + function calcIv(self, iv, ck) { + if (iv.length === 12) { + self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]); + return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]); } - }); - Object.defineProperty(Duplex.prototype, "writableLength", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._writableState.length; + var ghash = new GHASH(ck); + var len = iv.length; + var toPad = len % 16; + ghash.update(iv); + if (toPad) { + toPad = 16 - toPad; + ghash.update(Buffer.alloc(toPad, 0)); } - }); // the no-half-open enforcer - - function onend() { - // If the writable side ended, then we're ok. - if (this._writableState.ended) return; // no more data can be written. - // But allow more writes to happen in this tick. - - process.nextTick(onEndNT, this); + ghash.update(Buffer.alloc(8, 0)); + var ivBits = len * 8; + var tail = Buffer.alloc(8); + tail.writeUIntBE(ivBits, 0, 8); + ghash.update(tail); + self._finID = ghash.state; + var out = Buffer.from(self._finID); + incr32(out); + return out; } - - function onEndNT(self) { - self.end(); + function StreamCipher(mode, key, iv, decrypt) { + Transform.call(this || _global$$); + var h = Buffer.alloc(4, 0); + (this || _global$$)._cipher = new aes.AES(key); + var ck = (this || _global$$)._cipher.encryptBlock(h); + (this || _global$$)._ghash = new GHASH(ck); + iv = calcIv(this || _global$$, iv, ck); + (this || _global$$)._prev = Buffer.from(iv); + (this || _global$$)._cache = Buffer.allocUnsafe(0); + (this || _global$$)._secCache = Buffer.allocUnsafe(0); + (this || _global$$)._decrypt = decrypt; + (this || _global$$)._alen = 0; + (this || _global$$)._len = 0; + (this || _global$$)._mode = mode; + (this || _global$$)._authTag = null; + (this || _global$$)._called = false; } - - Object.defineProperty(Duplex.prototype, "destroyed", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - if (this._readableState === undefined || this._writableState === undefined) { - return false; + inherits(StreamCipher, Transform); + StreamCipher.prototype._update = function (chunk) { + if (!(this || _global$$)._called && (this || _global$$)._alen) { + var rump = 16 - (this || _global$$)._alen % 16; + if (rump < 16) { + rump = Buffer.alloc(rump, 0); + (this || _global$$)._ghash.update(rump); } - - return this._readableState.destroyed && this._writableState.destroyed; - }, - set: function set(value) { - // we ignore the value if the stream - // has not been initialized yet - if (this._readableState === undefined || this._writableState === undefined) { - return; - } // backward compatibility, the user is explicitly - // managing destroyed - - - this._readableState.destroyed = value; - this._writableState.destroyed = value; } - }); - return exports$7$2; + (this || _global$$)._called = true; + var out = (this || _global$$)._mode.encrypt(this || _global$$, chunk); + if ((this || _global$$)._decrypt) { + (this || _global$$)._ghash.update(chunk); + } else { + (this || _global$$)._ghash.update(out); + } + (this || _global$$)._len += chunk.length; + return out; + }; + StreamCipher.prototype._final = function () { + if ((this || _global$$)._decrypt && !(this || _global$$)._authTag) throw new Error("Unsupported state or unable to authenticate data"); + var tag = xor((this || _global$$)._ghash.final((this || _global$$)._alen * 8, (this || _global$$)._len * 8), (this || _global$$)._cipher.encryptBlock((this || _global$$)._finID)); + if ((this || _global$$)._decrypt && xorTest(tag, (this || _global$$)._authTag)) throw new Error("Unsupported state or unable to authenticate data"); + (this || _global$$)._authTag = tag; + (this || _global$$)._cipher.scrub(); + }; + StreamCipher.prototype.getAuthTag = function getAuthTag() { + if ((this || _global$$)._decrypt || !Buffer.isBuffer((this || _global$$)._authTag)) throw new Error("Attempting to get auth tag in unsupported state"); + return (this || _global$$)._authTag; + }; + StreamCipher.prototype.setAuthTag = function setAuthTag(tag) { + if (!(this || _global$$)._decrypt) throw new Error("Attempting to set auth tag in unsupported state"); + (this || _global$$)._authTag = tag; + }; + StreamCipher.prototype.setAAD = function setAAD(buf) { + if ((this || _global$$)._called) throw new Error("Attempting to set AAD in unsupported state"); + (this || _global$$)._ghash.update(buf); + (this || _global$$)._alen += buf.length; + }; + exports$2$ = StreamCipher; + return exports$2$; } -var exports$6$2 = {}, - _dewExec$6$2 = false; -function dew$6$2() { - if (_dewExec$6$2) return exports$6$2; - _dewExec$6$2 = true; - - var ERR_STREAM_PREMATURE_CLOSE = dew$b$2().codes.ERR_STREAM_PREMATURE_CLOSE; +var exports$2_ = {}, + _dewExec$2Z = false; +var _global$_ = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2Z() { + if (_dewExec$2Z) return exports$2_; + _dewExec$2Z = true; + var aes = dew$30(); + var Buffer = dew$3H().Buffer; + var Transform = dew$3u(); + var inherits = dew$3I(); + function StreamCipher(mode, key, iv, decrypt) { + Transform.call(this || _global$_); + (this || _global$_)._cipher = new aes.AES(key); + (this || _global$_)._prev = Buffer.from(iv); + (this || _global$_)._cache = Buffer.allocUnsafe(0); + (this || _global$_)._secCache = Buffer.allocUnsafe(0); + (this || _global$_)._decrypt = decrypt; + (this || _global$_)._mode = mode; + } + inherits(StreamCipher, Transform); + StreamCipher.prototype._update = function (chunk) { + return (this || _global$_)._mode.encrypt(this || _global$_, chunk, (this || _global$_)._decrypt); + }; + StreamCipher.prototype._final = function () { + (this || _global$_)._cipher.scrub(); + }; + exports$2_ = StreamCipher; + return exports$2_; +} - function once(callback) { - var called = false; - return function () { - if (called) return; - called = true; +var exports$2Z = {}, + _dewExec$2Y = false; +function dew$2Y() { + if (_dewExec$2Y) return exports$2Z; + _dewExec$2Y = true; + var Buffer = dew$3H().Buffer; + var MD5 = dew$3E(); - for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { - args[_key] = arguments[_key]; + /* eslint-disable camelcase */ + function EVP_BytesToKey(password, salt, keyBits, ivLen) { + if (!Buffer.isBuffer(password)) password = Buffer.from(password, "binary"); + if (salt) { + if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, "binary"); + if (salt.length !== 8) throw new RangeError("salt should be Buffer with 8 byte length"); + } + var keyLen = keyBits / 8; + var key = Buffer.alloc(keyLen); + var iv = Buffer.alloc(ivLen || 0); + var tmp = Buffer.alloc(0); + while (keyLen > 0 || ivLen > 0) { + var hash = new MD5(); + hash.update(tmp); + hash.update(password); + if (salt) hash.update(salt); + tmp = hash.digest(); + var used = 0; + if (keyLen > 0) { + var keyStart = key.length - keyLen; + used = Math.min(keyLen, tmp.length); + tmp.copy(key, keyStart, 0, used); + keyLen -= used; } - - callback.apply(this, args); + if (used < tmp.length && ivLen > 0) { + var ivStart = iv.length - ivLen; + var length = Math.min(ivLen, tmp.length - used); + tmp.copy(iv, ivStart, used, used + length); + ivLen -= length; + } + } + tmp.fill(0); + return { + key: key, + iv: iv }; } + exports$2Z = EVP_BytesToKey; + return exports$2Z; +} - function noop() {} - - function isRequest(stream) { - return stream.setHeader && typeof stream.abort === "function"; +var exports$2Y = {}, + _dewExec$2X = false; +var _global$Z = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2X() { + if (_dewExec$2X) return exports$2Y; + _dewExec$2X = true; + var MODES = dew$31(); + var AuthCipher = dew$2_(); + var Buffer = dew$3H().Buffer; + var StreamCipher = dew$2Z(); + var Transform = dew$3u(); + var aes = dew$30(); + var ebtk = dew$2Y(); + var inherits = dew$3I(); + function Cipher(mode, key, iv) { + Transform.call(this || _global$Z); + (this || _global$Z)._cache = new Splitter(); + (this || _global$Z)._cipher = new aes.AES(key); + (this || _global$Z)._prev = Buffer.from(iv); + (this || _global$Z)._mode = mode; + (this || _global$Z)._autopadding = true; } + inherits(Cipher, Transform); + Cipher.prototype._update = function (data) { + (this || _global$Z)._cache.add(data); + var chunk; + var thing; + var out = []; + while (chunk = (this || _global$Z)._cache.get()) { + thing = (this || _global$Z)._mode.encrypt(this || _global$Z, chunk); + out.push(thing); + } + return Buffer.concat(out); + }; + var PADDING = Buffer.alloc(16, 16); + Cipher.prototype._final = function () { + var chunk = (this || _global$Z)._cache.flush(); + if ((this || _global$Z)._autopadding) { + chunk = (this || _global$Z)._mode.encrypt(this || _global$Z, chunk); + (this || _global$Z)._cipher.scrub(); + return chunk; + } + if (!chunk.equals(PADDING)) { + (this || _global$Z)._cipher.scrub(); + throw new Error("data not multiple of block length"); + } + }; + Cipher.prototype.setAutoPadding = function (setTo) { + (this || _global$Z)._autopadding = !!setTo; + return this || _global$Z; + }; + function Splitter() { + (this || _global$Z).cache = Buffer.allocUnsafe(0); + } + Splitter.prototype.add = function (data) { + (this || _global$Z).cache = Buffer.concat([(this || _global$Z).cache, data]); + }; + Splitter.prototype.get = function () { + if ((this || _global$Z).cache.length > 15) { + var out = (this || _global$Z).cache.slice(0, 16); + (this || _global$Z).cache = (this || _global$Z).cache.slice(16); + return out; + } + return null; + }; + Splitter.prototype.flush = function () { + var len = 16 - (this || _global$Z).cache.length; + var padBuff = Buffer.allocUnsafe(len); + var i = -1; + while (++i < len) { + padBuff.writeUInt8(len, i); + } + return Buffer.concat([(this || _global$Z).cache, padBuff]); + }; + function createCipheriv(suite, password, iv) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + if (typeof password === "string") password = Buffer.from(password); + if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + if (typeof iv === "string") iv = Buffer.from(iv); + if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + if (config.type === "stream") { + return new StreamCipher(config.module, password, iv); + } else if (config.type === "auth") { + return new AuthCipher(config.module, password, iv); + } + return new Cipher(config.module, password, iv); + } + function createCipher(suite, password) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + var keys = ebtk(password, false, config.key, config.iv); + return createCipheriv(suite, keys.key, keys.iv); + } + exports$2Y.createCipheriv = createCipheriv; + exports$2Y.createCipher = createCipher; + return exports$2Y; +} - function eos(stream, opts, callback) { - if (typeof opts === "function") return eos(stream, null, opts); - if (!opts) opts = {}; - callback = once(callback || noop); - var readable = opts.readable || opts.readable !== false && stream.readable; - var writable = opts.writable || opts.writable !== false && stream.writable; - - var onlegacyfinish = function onlegacyfinish() { - if (!stream.writable) onfinish(); - }; - - var writableEnded = stream._writableState && stream._writableState.finished; - - var onfinish = function onfinish() { - writable = false; - writableEnded = true; - if (!readable) callback.call(stream); - }; - - var readableEnded = stream._readableState && stream._readableState.endEmitted; - - var onend = function onend() { - readable = false; - readableEnded = true; - if (!writable) callback.call(stream); - }; - - var onerror = function onerror(err) { - callback.call(stream, err); - }; - - var onclose = function onclose() { - var err; - - if (readable && !readableEnded) { - if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); - return callback.call(stream, err); +var exports$2X = {}, + _dewExec$2W = false; +var _global$Y = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2W() { + if (_dewExec$2W) return exports$2X; + _dewExec$2W = true; + var AuthCipher = dew$2_(); + var Buffer = dew$3H().Buffer; + var MODES = dew$31(); + var StreamCipher = dew$2Z(); + var Transform = dew$3u(); + var aes = dew$30(); + var ebtk = dew$2Y(); + var inherits = dew$3I(); + function Decipher(mode, key, iv) { + Transform.call(this || _global$Y); + (this || _global$Y)._cache = new Splitter(); + (this || _global$Y)._last = void 0; + (this || _global$Y)._cipher = new aes.AES(key); + (this || _global$Y)._prev = Buffer.from(iv); + (this || _global$Y)._mode = mode; + (this || _global$Y)._autopadding = true; + } + inherits(Decipher, Transform); + Decipher.prototype._update = function (data) { + (this || _global$Y)._cache.add(data); + var chunk; + var thing; + var out = []; + while (chunk = (this || _global$Y)._cache.get((this || _global$Y)._autopadding)) { + thing = (this || _global$Y)._mode.decrypt(this || _global$Y, chunk); + out.push(thing); + } + return Buffer.concat(out); + }; + Decipher.prototype._final = function () { + var chunk = (this || _global$Y)._cache.flush(); + if ((this || _global$Y)._autopadding) { + return unpad((this || _global$Y)._mode.decrypt(this || _global$Y, chunk)); + } else if (chunk) { + throw new Error("data not multiple of block length"); + } + }; + Decipher.prototype.setAutoPadding = function (setTo) { + (this || _global$Y)._autopadding = !!setTo; + return this || _global$Y; + }; + function Splitter() { + (this || _global$Y).cache = Buffer.allocUnsafe(0); + } + Splitter.prototype.add = function (data) { + (this || _global$Y).cache = Buffer.concat([(this || _global$Y).cache, data]); + }; + Splitter.prototype.get = function (autoPadding) { + var out; + if (autoPadding) { + if ((this || _global$Y).cache.length > 16) { + out = (this || _global$Y).cache.slice(0, 16); + (this || _global$Y).cache = (this || _global$Y).cache.slice(16); + return out; } - - if (writable && !writableEnded) { - if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); - return callback.call(stream, err); + } else { + if ((this || _global$Y).cache.length >= 16) { + out = (this || _global$Y).cache.slice(0, 16); + (this || _global$Y).cache = (this || _global$Y).cache.slice(16); + return out; } - }; - - var onrequest = function onrequest() { - stream.req.on("finish", onfinish); - }; - - if (isRequest(stream)) { - stream.on("complete", onfinish); - stream.on("abort", onclose); - if (stream.req) onrequest();else stream.on("request", onrequest); - } else if (writable && !stream._writableState) { - // legacy streams - stream.on("end", onlegacyfinish); - stream.on("close", onlegacyfinish); } - - stream.on("end", onend); - stream.on("finish", onfinish); - if (opts.error !== false) stream.on("error", onerror); - stream.on("close", onclose); - return function () { - stream.removeListener("complete", onfinish); - stream.removeListener("abort", onclose); - stream.removeListener("request", onrequest); - if (stream.req) stream.req.removeListener("finish", onfinish); - stream.removeListener("end", onlegacyfinish); - stream.removeListener("close", onlegacyfinish); - stream.removeListener("finish", onfinish); - stream.removeListener("end", onend); - stream.removeListener("error", onerror); - stream.removeListener("close", onclose); - }; + return null; + }; + Splitter.prototype.flush = function () { + if ((this || _global$Y).cache.length) return (this || _global$Y).cache; + }; + function unpad(last) { + var padded = last[15]; + if (padded < 1 || padded > 16) { + throw new Error("unable to decrypt data"); + } + var i = -1; + while (++i < padded) { + if (last[i + (16 - padded)] !== padded) { + throw new Error("unable to decrypt data"); + } + } + if (padded === 16) return; + return last.slice(0, 16 - padded); } - - exports$6$2 = eos; - return exports$6$2; + function createDecipheriv(suite, password, iv) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + if (typeof iv === "string") iv = Buffer.from(iv); + if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + if (typeof password === "string") password = Buffer.from(password); + if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + if (config.type === "stream") { + return new StreamCipher(config.module, password, iv, true); + } else if (config.type === "auth") { + return new AuthCipher(config.module, password, iv, true); + } + return new Decipher(config.module, password, iv); + } + function createDecipher(suite, password) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + var keys = ebtk(password, false, config.key, config.iv); + return createDecipheriv(suite, keys.key, keys.iv); + } + exports$2X.createDecipher = createDecipher; + exports$2X.createDecipheriv = createDecipheriv; + return exports$2X; } -var exports$5$2 = {}, - _dewExec$5$2 = false; -function dew$5$2() { - if (_dewExec$5$2) return exports$5$2; - _dewExec$5$2 = true; - var process = T$9; +var exports$2W = {}, + _dewExec$2V = false; +function dew$2V() { + if (_dewExec$2V) return exports$2W; + _dewExec$2V = true; + var ciphers = dew$2X(); + var deciphers = dew$2W(); + var modes = _list$2; + function getCiphers() { + return Object.keys(modes); + } + exports$2W.createCipher = exports$2W.Cipher = ciphers.createCipher; + exports$2W.createCipheriv = exports$2W.Cipheriv = ciphers.createCipheriv; + exports$2W.createDecipher = exports$2W.Decipher = deciphers.createDecipher; + exports$2W.createDecipheriv = exports$2W.Decipheriv = deciphers.createDecipheriv; + exports$2W.listCiphers = exports$2W.getCiphers = getCiphers; + return exports$2W; +} - var _Object$setPrototypeO; +var exports$2V = {}, + _dewExec$2U = false; +function dew$2U() { + if (_dewExec$2U) return exports$2V; + _dewExec$2U = true; + exports$2V["des-ecb"] = { + key: 8, + iv: 0 + }; + exports$2V["des-cbc"] = exports$2V.des = { + key: 8, + iv: 8 + }; + exports$2V["des-ede3-cbc"] = exports$2V.des3 = { + key: 24, + iv: 8 + }; + exports$2V["des-ede3"] = { + key: 24, + iv: 0 + }; + exports$2V["des-ede-cbc"] = { + key: 16, + iv: 8 + }; + exports$2V["des-ede"] = { + key: 16, + iv: 0 + }; + return exports$2V; +} - function _defineProperty(obj, key, value) { - if (key in obj) { - Object.defineProperty(obj, key, { - value: value, - enumerable: true, - configurable: true, - writable: true - }); +var exports$2U = {}, + _dewExec$2T = false; +function dew$2T() { + if (_dewExec$2T) return exports$2U; + _dewExec$2T = true; + var DES = dew$3b(); + var aes = dew$2V(); + var aesModes = dew$31(); + var desModes = dew$2U(); + var ebtk = dew$2Y(); + function createCipher(suite, password) { + suite = suite.toLowerCase(); + var keyLen, ivLen; + if (aesModes[suite]) { + keyLen = aesModes[suite].key; + ivLen = aesModes[suite].iv; + } else if (desModes[suite]) { + keyLen = desModes[suite].key * 8; + ivLen = desModes[suite].iv; } else { - obj[key] = value; + throw new TypeError("invalid suite type"); } - - return obj; - } - - var finished = dew$6$2(); - - var kLastResolve = Symbol("lastResolve"); - var kLastReject = Symbol("lastReject"); - var kError = Symbol("error"); - var kEnded = Symbol("ended"); - var kLastPromise = Symbol("lastPromise"); - var kHandlePromise = Symbol("handlePromise"); - var kStream = Symbol("stream"); - - function createIterResult(value, done) { - return { - value: value, - done: done - }; + var keys = ebtk(password, false, keyLen, ivLen); + return createCipheriv(suite, keys.key, keys.iv); } - - function readAndResolve(iter) { - var resolve = iter[kLastResolve]; - - if (resolve !== null) { - var data = iter[kStream].read(); // we defer if data is null - // we can be expecting either 'end' or - // 'error' - - if (data !== null) { - iter[kLastPromise] = null; - iter[kLastResolve] = null; - iter[kLastReject] = null; - resolve(createIterResult(data, false)); - } + function createDecipher(suite, password) { + suite = suite.toLowerCase(); + var keyLen, ivLen; + if (aesModes[suite]) { + keyLen = aesModes[suite].key; + ivLen = aesModes[suite].iv; + } else if (desModes[suite]) { + keyLen = desModes[suite].key * 8; + ivLen = desModes[suite].iv; + } else { + throw new TypeError("invalid suite type"); } + var keys = ebtk(password, false, keyLen, ivLen); + return createDecipheriv(suite, keys.key, keys.iv); } - - function onReadable(iter) { - // we wait for the next tick, because it might - // emit an error with process.nextTick - process.nextTick(readAndResolve, iter); + function createCipheriv(suite, key, iv) { + suite = suite.toLowerCase(); + if (aesModes[suite]) return aes.createCipheriv(suite, key, iv); + if (desModes[suite]) return new DES({ + key: key, + iv: iv, + mode: suite + }); + throw new TypeError("invalid suite type"); } - - function wrapForNext(lastPromise, iter) { - return function (resolve, reject) { - lastPromise.then(function () { - if (iter[kEnded]) { - resolve(createIterResult(undefined, true)); - return; - } - - iter[kHandlePromise](resolve, reject); - }, reject); - }; + function createDecipheriv(suite, key, iv) { + suite = suite.toLowerCase(); + if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv); + if (desModes[suite]) return new DES({ + key: key, + iv: iv, + mode: suite, + decrypt: true + }); + throw new TypeError("invalid suite type"); + } + function getCiphers() { + return Object.keys(desModes).concat(aes.getCiphers()); } + exports$2U.createCipher = exports$2U.Cipher = createCipher; + exports$2U.createCipheriv = exports$2U.Cipheriv = createCipheriv; + exports$2U.createDecipher = exports$2U.Decipher = createDecipher; + exports$2U.createDecipheriv = exports$2U.Decipheriv = createDecipheriv; + exports$2U.listCiphers = exports$2U.getCiphers = getCiphers; + return exports$2U; +} - var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); - var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = { - get stream() { - return this[kStream]; - }, +var exports$2T = {}, + _dewExec$2S = false; +var module$e = { + exports: exports$2T +}; +var _global$X = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2S() { + if (_dewExec$2S) return module$e.exports; + _dewExec$2S = true; + (function (module, exports) { - next: function next() { - var _this = this; // if we have detected an error in the meanwhile - // reject straight away + // Utils + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } + // Could use `inherits` module, but don't want to move from single file + // architecture yet. + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + var TempCtor = function () {}; + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } - var error = this[kError]; + // BN - if (error !== null) { - return Promise.reject(error); + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; } + (this || _global$X).negative = 0; + (this || _global$X).words = null; + (this || _global$X).length = 0; - if (this[kEnded]) { - return Promise.resolve(createIterResult(undefined, true)); + // Reduction context + (this || _global$X).red = null; + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + this._init(number || 0, base || 10, endian || "be"); } - - if (this[kStream].destroyed) { - // We need to defer via nextTick because if .destroy(err) is - // called, the error will be emitted via nextTick, and - // we cannot guarantee that there is no error lingering around - // waiting to be emitted. - return new Promise(function (resolve, reject) { - process.nextTick(function () { - if (_this[kError]) { - reject(_this[kError]); - } else { - resolve(createIterResult(undefined, true)); - } - }); - }); - } // if we have multiple next() calls - // we will wait for the previous Promise to finish - // this logic is optimized to support for await loops, - // where next() is only called once at a time - - - var lastPromise = this[kLastPromise]; - var promise; - - if (lastPromise) { - promise = new Promise(wrapForNext(lastPromise, this)); + } + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; } else { - // fast path needed to support multiple this.push() - // without triggering the next() queue - var data = this[kStream].read(); - - if (data !== null) { - return Promise.resolve(createIterResult(data, false)); + Buffer = dew$3J().Buffer; + } + } catch (e) {} + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + if (base === "hex") { + base = 16; + } + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + if (number[0] === "-") { + start++; + (this || _global$X).negative = 1; + } + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } } - - promise = new Promise(this[kHandlePromise]); } + }; + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$X).negative = 1; + number = -number; + } + if (number < 67108864) { + (this || _global$X).words = [number & 67108863]; + (this || _global$X).length = 1; + } else if (number < 4503599627370496) { + (this || _global$X).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$X).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + (this || _global$X).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$X).length = 3; + } + if (endian !== "le") return; - this[kLastPromise] = promise; - return promise; - } - }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () { - return this; - }), _defineProperty(_Object$setPrototypeO, "return", function _return() { - var _this2 = this; // destroy(err, cb) is a private API - // we can guarantee we have that here, because we control the - // Readable class this is attached to - - - return new Promise(function (resolve, reject) { - _this2[kStream].destroy(null, function (err) { - if (err) { - reject(err); - return; + // Reverse the bytes + this._initArray(this.toArray(), base, endian); + }; + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + if (number.length <= 0) { + (this || _global$X).words = [0]; + (this || _global$X).length = 1; + return this || _global$X; + } + (this || _global$X).length = Math.ceil(number.length / 3); + (this || _global$X).words = new Array((this || _global$X).length); + for (var i = 0; i < (this || _global$X).length; i++) { + (this || _global$X).words[i] = 0; + } + var j, w; + var off = 0; + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$X).words[j] |= w << off & 67108863; + (this || _global$X).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + if (off >= 26) { + off -= 26; + j++; + } } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$X).words[j] |= w << off & 67108863; + (this || _global$X).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + if (off >= 26) { + off -= 26; + j++; + } + } + } + return this.strip(); + }; + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); + // 'A' - 'F' + if (c >= 65 && c <= 70) { + return c - 55; + // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; + // '0' - '9' + } else { + return c - 48 & 15; + } + } + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } + return r; + } + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$X).length = Math.ceil((number.length - start) / 6); + (this || _global$X).words = new Array((this || _global$X).length); + for (var i = 0; i < (this || _global$X).length; i++) { + (this || _global$X).words[i] = 0; + } - resolve(createIterResult(undefined, true)); - }); - }); - }), _Object$setPrototypeO), AsyncIteratorPrototype); - - var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) { - var _Object$create; - - var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, { - value: stream, - writable: true - }), _defineProperty(_Object$create, kLastResolve, { - value: null, - writable: true - }), _defineProperty(_Object$create, kLastReject, { - value: null, - writable: true - }), _defineProperty(_Object$create, kError, { - value: null, - writable: true - }), _defineProperty(_Object$create, kEnded, { - value: stream._readableState.endEmitted, - writable: true - }), _defineProperty(_Object$create, kHandlePromise, { - value: function value(resolve, reject) { - var data = iterator[kStream].read(); + // 24-bits chunks + var off = 0; + var j = 0; + var w; + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$X).words[j] |= w & 67108863; + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$X).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$X).words[j] |= w & 67108863; + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$X).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + this.strip(); + }; + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; - if (data) { - iterator[kLastPromise] = null; - iterator[kLastResolve] = null; - iterator[kLastReject] = null; - resolve(createIterResult(data, false)); + // 'a' + if (c >= 49) { + r += c - 49 + 10; + + // 'A' + } else if (c >= 17) { + r += c - 17 + 10; + + // '0' - '9' } else { - iterator[kLastResolve] = resolve; - iterator[kLastReject] = reject; + r += c; } - }, - writable: true - }), _Object$create)); - iterator[kLastPromise] = null; - finished(stream, function (err) { - if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") { - var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise - // returned by next() and store the error + } + return r; + } + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$X).words = [0]; + (this || _global$X).length = 1; - if (reject !== null) { - iterator[kLastPromise] = null; - iterator[kLastResolve] = null; - iterator[kLastReject] = null; - reject(err); + // Find length of limb in base + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + if ((this || _global$X).words[0] + word < 67108864) { + (this || _global$X).words[0] += word; + } else { + this._iaddn(word); + } + } + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + for (i = 0; i < mod; i++) { + pow *= base; + } + this.imuln(pow); + if ((this || _global$X).words[0] + word < 67108864) { + (this || _global$X).words[0] += word; + } else { + this._iaddn(word); } + } + this.strip(); + }; + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$X).length); + for (var i = 0; i < (this || _global$X).length; i++) { + dest.words[i] = (this || _global$X).words[i]; + } + dest.length = (this || _global$X).length; + dest.negative = (this || _global$X).negative; + dest.red = (this || _global$X).red; + }; + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + BN.prototype._expand = function _expand(size) { + while ((this || _global$X).length < size) { + (this || _global$X).words[(this || _global$X).length++] = 0; + } + return this || _global$X; + }; - iterator[kError] = err; - return; + // Remove leading `0` from `this` + BN.prototype.strip = function strip() { + while ((this || _global$X).length > 1 && (this || _global$X).words[(this || _global$X).length - 1] === 0) { + (this || _global$X).length--; } + return this._normSign(); + }; + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$X).length === 1 && (this || _global$X).words[0] === 0) { + (this || _global$X).negative = 0; + } + return this || _global$X; + }; + BN.prototype.inspect = function inspect() { + return ((this || _global$X).red ? ""; + }; - var resolve = iterator[kLastResolve]; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ - if (resolve !== null) { - iterator[kLastPromise] = null; - iterator[kLastResolve] = null; - iterator[kLastReject] = null; - resolve(createIterResult(undefined, true)); + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + for (var i = 0; i < (this || _global$X).length; i++) { + var w = (this || _global$X).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + if (carry !== 0 || i !== (this || _global$X).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + off += 2; + if (off >= 26) { + off -= 26; + i--; + } + } + if (carry !== 0) { + out = carry.toString(16) + out; + } + while (out.length % padding !== 0) { + out = "0" + out; + } + if ((this || _global$X).negative !== 0) { + out = "-" + out; + } + return out; + } + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + if (this.isZero()) { + out = "0" + out; + } + while (out.length % padding !== 0) { + out = "0" + out; + } + if ((this || _global$X).negative !== 0) { + out = "-" + out; + } + return out; + } + assert(false, "Base should be between 2 and 36"); + }; + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$X).words[0]; + if ((this || _global$X).length === 2) { + ret += (this || _global$X).words[1] * 67108864; + } else if ((this || _global$X).length === 3 && (this || _global$X).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$X).words[1] * 67108864; + } else if ((this || _global$X).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + return (this || _global$X).negative !== 0 ? -ret : ret; + }; + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } + } else { + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + for (; i < reqLength; i++) { + res[i] = 0; + } + } + return res; + }; + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + if (t >= 4096) { + r += 13; + t >>>= 13; + } + if (t >= 64) { + r += 7; + t >>>= 7; + } + if (t >= 8) { + r += 4; + t >>>= 4; + } + if (t >= 2) { + r += 2; + t >>>= 2; + } + return r + t; + }; + } + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } + if ((t & 1) === 0) { + r++; } + return r; + }; - iterator[kEnded] = true; - }); - stream.on("readable", onReadable.bind(null, iterator)); - return iterator; - }; + // Return number of used bits in a BN + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$X).words[(this || _global$X).length - 1]; + var hi = this._countBits(w); + return ((this || _global$X).length - 1) * 26 + hi; + }; + function toBitArray(num) { + var w = new Array(num.bitLength()); + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + return w; + } - exports$5$2 = createReadableStreamAsyncIterator; - return exports$5$2; -} + // Number of trailing zero bits + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; + for (var i = 0; i < (this || _global$X).length; i++) { + var b = this._zeroBits((this || _global$X).words[i]); + r += b; + if (b !== 26) break; + } + return r; + }; + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$X).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + return this.clone(); + }; + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } + return this.clone(); + }; + BN.prototype.isNeg = function isNeg() { + return (this || _global$X).negative !== 0; + }; -var exports$4$2 = {}, - _dewExec$4$2 = false; -function dew$4$2() { - if (_dewExec$4$2) return exports$4$2; - _dewExec$4$2 = true; + // Return negative clone of `this` + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$X).negative ^= 1; + } + return this || _global$X; + }; - exports$4$2 = function () { - throw new Error("Readable.from is not available in the browser"); - }; + // Or `num` with `this` in-place + BN.prototype.iuor = function iuor(num) { + while ((this || _global$X).length < num.length) { + (this || _global$X).words[(this || _global$X).length++] = 0; + } + for (var i = 0; i < num.length; i++) { + (this || _global$X).words[i] = (this || _global$X).words[i] | num.words[i]; + } + return this.strip(); + }; + BN.prototype.ior = function ior(num) { + assert(((this || _global$X).negative | num.negative) === 0); + return this.iuor(num); + }; - return exports$4$2; -} + // Or `num` with `this` + BN.prototype.or = function or(num) { + if ((this || _global$X).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$X); + }; + BN.prototype.uor = function uor(num) { + if ((this || _global$X).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$X); + }; -var exports$3$2 = {}, - _dewExec$3$2 = false; + // And `num` with `this` in-place + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + if ((this || _global$X).length > num.length) { + b = num; + } else { + b = this || _global$X; + } + for (var i = 0; i < b.length; i++) { + (this || _global$X).words[i] = (this || _global$X).words[i] & num.words[i]; + } + (this || _global$X).length = b.length; + return this.strip(); + }; + BN.prototype.iand = function iand(num) { + assert(((this || _global$X).negative | num.negative) === 0); + return this.iuand(num); + }; -var _global$M = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + // And `num` with `this` + BN.prototype.and = function and(num) { + if ((this || _global$X).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$X); + }; + BN.prototype.uand = function uand(num) { + if ((this || _global$X).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$X); + }; -function dew$3$2() { - if (_dewExec$3$2) return exports$3$2; - _dewExec$3$2 = true; - var process = T$9; - exports$3$2 = Readable; - /**/ + // Xor `num` with `this` in-place + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + if ((this || _global$X).length > num.length) { + a = this || _global$X; + b = num; + } else { + a = num; + b = this || _global$X; + } + for (var i = 0; i < b.length; i++) { + (this || _global$X).words[i] = a.words[i] ^ b.words[i]; + } + if ((this || _global$X) !== a) { + for (; i < a.length; i++) { + (this || _global$X).words[i] = a.words[i]; + } + } + (this || _global$X).length = a.length; + return this.strip(); + }; + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$X).negative | num.negative) === 0); + return this.iuxor(num); + }; - var Duplex; - /**/ + // Xor `num` with `this` + BN.prototype.xor = function xor(num) { + if ((this || _global$X).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$X); + }; + BN.prototype.uxor = function uxor(num) { + if ((this || _global$X).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$X); + }; - Readable.ReadableState = ReadableState; - /**/ + // Not ``this`` with ``width`` bitwidth + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; - y$o.EventEmitter; + // Extend the buffer with leading zeroes + this._expand(bytesNeeded); + if (bitsLeft > 0) { + bytesNeeded--; + } - var EElistenerCount = function EElistenerCount(emitter, type) { - return emitter.listeners(type).length; - }; - /**/ + // Handle complete words + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$X).words[i] = ~(this || _global$X).words[i] & 67108863; + } - /**/ + // Handle the residue + if (bitsLeft > 0) { + (this || _global$X).words[i] = ~(this || _global$X).words[i] & 67108863 >> 26 - bitsLeft; + } + // And remove leading zeroes + return this.strip(); + }; + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; - var Stream = dew$e$2(); - /**/ + // Set `bit` of `this` + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + this._expand(off + 1); + if (val) { + (this || _global$X).words[off] = (this || _global$X).words[off] | 1 << wbit; + } else { + (this || _global$X).words[off] = (this || _global$X).words[off] & ~(1 << wbit); + } + return this.strip(); + }; + // Add `num` to `this` in-place + BN.prototype.iadd = function iadd(num) { + var r; - var Buffer = e$1$1$1.Buffer; - - var OurUint8Array = _global$M.Uint8Array || function () {}; - - function _uint8ArrayToBuffer(chunk) { - return Buffer.from(chunk); - } - - function _isUint8Array(obj) { - return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; - } - /**/ - - - var debugUtil = X$5; - var debug; - - if (debugUtil && debugUtil.debuglog) { - debug = debugUtil.debuglog("stream"); - } else { - debug = function debug() {}; - } - /**/ - - - var BufferList = dew$d$2(); - - var destroyImpl = dew$c$2(); - - var _require = dew$a$2(), - getHighWaterMark = _require.getHighWaterMark; - - var _require$codes = dew$b$2().codes, - ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, - ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, - ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, - ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance. - - - var StringDecoder; - var createReadableStreamAsyncIterator; - var from; - - dew$f$2()(Readable, Stream); - - var errorOrDestroy = destroyImpl.errorOrDestroy; - var kProxyEvents = ["error", "close", "destroy", "pause", "resume"]; - - function prependListener(emitter, event, fn) { - // Sadly this is not cacheable as some libraries bundle their own - // event emitter implementation with them. - if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any - // userland ones. NEVER DO THIS. This is here only because this code needs - // to continue to work with older versions of Node.js that do not include - // the prependListener() method. The goal is to eventually remove this hack. - - if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; - } - - function ReadableState(options, stream, isDuplex) { - Duplex = Duplex || dew$7$2(); - options = options || {}; // Duplex streams are both readable and writable, but share - // the same options object. - // However, some cases require setting options to different - // values for the readable and the writable sides of the duplex stream. - // These options can be provided separately as readableXXX and writableXXX. - - if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to - // make all the buffer merging and length checks go away - - this.objectMode = !!options.objectMode; - if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer - // Note: 0 is a valid value, means "don't call _read preemptively ever" - - this.highWaterMark = getHighWaterMark(this, options, "readableHighWaterMark", isDuplex); // A linked list is used to store data chunks instead of an array because the - // linked list can remove elements from the beginning faster than - // array.shift() - - this.buffer = new BufferList(); - this.length = 0; - this.pipes = null; - this.pipesCount = 0; - this.flowing = null; - this.ended = false; - this.endEmitted = false; - this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted - // immediately, or on a later tick. We set this to true at first, because - // any actions that shouldn't happen until "later" should generally also - // not happen before the first read call. - - this.sync = true; // whenever we return null, then we set a flag to say - // that we're awaiting a 'readable' event emission. - - this.needReadable = false; - this.emittedReadable = false; - this.readableListening = false; - this.resumeScheduled = false; - this.paused = true; // Should close be emitted on destroy. Defaults to true. - - this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish') - - this.autoDestroy = !!options.autoDestroy; // has it been destroyed - - this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string - // encoding is 'binary' so we have to make this configurable. - // Everything else in the universe uses 'utf8', though. - - this.defaultEncoding = options.defaultEncoding || "utf8"; // the number of writers that are awaiting a drain event in .pipe()s - - this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled - - this.readingMore = false; - this.decoder = null; - this.encoding = null; - - if (options.encoding) { - if (!StringDecoder) StringDecoder = e$1$2.StringDecoder; - this.decoder = new StringDecoder(options.encoding); - this.encoding = options.encoding; - } - } - - function Readable(options) { - Duplex = Duplex || dew$7$2(); - if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside - // the ReadableState constructor, at least with V8 6.5 - - var isDuplex = this instanceof Duplex; - this._readableState = new ReadableState(options, this, isDuplex); // legacy - - this.readable = true; - - if (options) { - if (typeof options.read === "function") this._read = options.read; - if (typeof options.destroy === "function") this._destroy = options.destroy; - } - - Stream.call(this); - } + // negative + positive + if ((this || _global$X).negative !== 0 && num.negative === 0) { + (this || _global$X).negative = 0; + r = this.isub(num); + (this || _global$X).negative ^= 1; + return this._normSign(); - Object.defineProperty(Readable.prototype, "destroyed", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - if (this._readableState === undefined) { - return false; + // positive + negative + } else if ((this || _global$X).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); } - return this._readableState.destroyed; - }, - set: function set(value) { - // we ignore the value if the stream - // has not been initialized yet - if (!this._readableState) { - return; - } // backward compatibility, the user is explicitly - // managing destroyed - - - this._readableState.destroyed = value; - } - }); - Readable.prototype.destroy = destroyImpl.destroy; - Readable.prototype._undestroy = destroyImpl.undestroy; - - Readable.prototype._destroy = function (err, cb) { - cb(err); - }; // Manually shove something into the read() buffer. - // This returns true if the highWaterMark has not been hit yet, - // similar to how Writable.write() returns true if you should - // write() some more. - - - Readable.prototype.push = function (chunk, encoding) { - var state = this._readableState; - var skipChunkCheck; - - if (!state.objectMode) { - if (typeof chunk === "string") { - encoding = encoding || state.defaultEncoding; - - if (encoding !== state.encoding) { - chunk = Buffer.from(chunk, encoding); - encoding = ""; + // a.length > b.length + var a, b; + if ((this || _global$X).length > num.length) { + a = this || _global$X; + b = num; + } else { + a = num; + b = this || _global$X; + } + var carry = 0; + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$X).words[i] = r & 67108863; + carry = r >>> 26; + } + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$X).words[i] = r & 67108863; + carry = r >>> 26; + } + (this || _global$X).length = a.length; + if (carry !== 0) { + (this || _global$X).words[(this || _global$X).length] = carry; + (this || _global$X).length++; + // Copy the rest of the words + } else if (a !== (this || _global$X)) { + for (; i < a.length; i++) { + (this || _global$X).words[i] = a.words[i]; } + } + return this || _global$X; + }; - skipChunkCheck = true; + // Add `num` to `this` + BN.prototype.add = function add(num) { + var res; + if (num.negative !== 0 && (this || _global$X).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$X).negative !== 0) { + (this || _global$X).negative = 0; + res = num.sub(this || _global$X); + (this || _global$X).negative = 1; + return res; } - } else { - skipChunkCheck = true; - } + if ((this || _global$X).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$X); + }; - return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); - }; // Unshift should *always* be something directly out of read() + // Subtract `num` from `this` in-place + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); + // -this - num = -(this + num) + } else if ((this || _global$X).negative !== 0) { + (this || _global$X).negative = 0; + this.iadd(num); + (this || _global$X).negative = 1; + return this._normSign(); + } - Readable.prototype.unshift = function (chunk) { - return readableAddChunk(this, chunk, null, true, false); - }; + // At this point both numbers are positive + var cmp = this.cmp(num); - function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { - debug("readableAddChunk", chunk); - var state = stream._readableState; + // Optimization - zeroify + if (cmp === 0) { + (this || _global$X).negative = 0; + (this || _global$X).length = 1; + (this || _global$X).words[0] = 0; + return this || _global$X; + } - if (chunk === null) { - state.reading = false; - onEofChunk(stream, state); - } else { - var er; - if (!skipChunkCheck) er = chunkInvalid(state, chunk); + // a > b + var a, b; + if (cmp > 0) { + a = this || _global$X; + b = num; + } else { + a = num; + b = this || _global$X; + } + var carry = 0; + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$X).words[i] = r & 67108863; + } + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$X).words[i] = r & 67108863; + } - if (er) { - errorOrDestroy(stream, er); - } else if (state.objectMode || chunk && chunk.length > 0) { - if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { - chunk = _uint8ArrayToBuffer(chunk); + // Copy rest of the words + if (carry === 0 && i < a.length && a !== (this || _global$X)) { + for (; i < a.length; i++) { + (this || _global$X).words[i] = a.words[i]; } + } + (this || _global$X).length = Math.max((this || _global$X).length, i); + if (a !== (this || _global$X)) { + (this || _global$X).negative = 1; + } + return this.strip(); + }; - if (addToFront) { - if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true); - } else if (state.ended) { - errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF()); - } else if (state.destroyed) { - return false; - } else { - state.reading = false; + // Subtract `num` from `this` + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; - if (state.decoder && !encoding) { - chunk = state.decoder.write(chunk); - if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); - } else { - addChunk(stream, state, chunk, false); - } + // Peel one iteration (compiler can't do it, because of code complexity) + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; } - } else if (!addToFront) { - state.reading = false; - maybeReadMore(stream, state); + out.words[k] = rword | 0; + carry = ncarry | 0; } - } // We can push more data if we are below the highWaterMark. - // Also, if we have no data yet, we can stand some more bytes. - // This is to work around cases where hwm=0, such as the repl. - - - return !state.ended && (state.length < state.highWaterMark || state.length === 0); - } - - function addChunk(stream, state, chunk, addToFront) { - if (state.flowing && state.length === 0 && !state.sync) { - state.awaitDrain = 0; - stream.emit("data", chunk); - } else { - // update the buffer info. - state.length += state.objectMode ? 1 : chunk.length; - if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); - if (state.needReadable) emitReadable(stream); - } - - maybeReadMore(stream, state); - } - - function chunkInvalid(state, chunk) { - var er; - - if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== undefined && !state.objectMode) { - er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk); - } - - return er; - } - - Readable.prototype.isPaused = function () { - return this._readableState.flowing === false; - }; // backwards compatibility. - - - Readable.prototype.setEncoding = function (enc) { - if (!StringDecoder) StringDecoder = e$1$2.StringDecoder; - var decoder = new StringDecoder(enc); - this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8 - - this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers: - - var p = this._readableState.buffer.head; - var content = ""; - - while (p !== null) { - content += decoder.write(p.data); - p = p.next; - } - - this._readableState.buffer.clear(); - - if (content !== "") this._readableState.buffer.push(content); - this._readableState.length = content.length; - return this; - }; // Don't raise the hwm > 1GB - - - var MAX_HWM = 1073741824; - - function computeNewHighWaterMark(n) { - if (n >= MAX_HWM) { - // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE. - n = MAX_HWM; - } else { - // Get the next highest power of 2 to prevent increasing hwm excessively in - // tiny amounts - n--; - n |= n >>> 1; - n |= n >>> 2; - n |= n >>> 4; - n |= n >>> 8; - n |= n >>> 16; - n++; - } - - return n; - } // This function is designed to be inlinable, so please take care when making - // changes to the function body. - - - function howMuchToRead(n, state) { - if (n <= 0 || state.length === 0 && state.ended) return 0; - if (state.objectMode) return 1; - - if (n !== n) { - // Only flow one buffer at a time - if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; - } // If we're asking for more than the current hwm, then raise the hwm. - - - if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); - if (n <= state.length) return n; // Don't have enough - - if (!state.ended) { - state.needReadable = true; - return 0; - } - - return state.length; - } // you can override either this method, or the async _read(n) below. - - - Readable.prototype.read = function (n) { - debug("read", n); - n = parseInt(n, 10); - var state = this._readableState; - var nOrig = n; - if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we - // already have a bunch of data in the buffer, then just trigger - // the 'readable' event and move on. - - if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) { - debug("read: emitReadable", state.length, state.ended); - if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); - return null; - } - - n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up. - - if (n === 0 && state.ended) { - if (state.length === 0) endReadable(this); - return null; - } // All the actual chunk generation logic needs to be - // *below* the call to _read. The reason is that in certain - // synthetic stream cases, such as passthrough streams, _read - // may be a completely synchronous operation which may change - // the state of the read buffer, providing enough data when - // before there was *not* enough. - // - // So, the steps are: - // 1. Figure out what the state of things will be after we do - // a read from the buffer. - // - // 2. If that resulting state will trigger a _read, then call _read. - // Note that this may be asynchronous, or synchronous. Yes, it is - // deeply ugly to write APIs this way, but that still doesn't mean - // that the Readable class should behave improperly, as streams are - // designed to be sync/async agnostic. - // Take note if the _read call is sync or async (ie, if the read call - // has returned yet), so that we know whether or not it's safe to emit - // 'readable' etc. - // - // 3. Actually pull the requested chunks out of the buffer and return. - // if we need a readable event, then we need to do some reading. - - - var doRead = state.needReadable; - debug("need readable", doRead); // if we currently have less than the highWaterMark, then also read some - - if (state.length === 0 || state.length - n < state.highWaterMark) { - doRead = true; - debug("length less than watermark", doRead); - } // however, if we've ended, then there's no point, and if we're already - // reading, then it's unnecessary. - - - if (state.ended || state.reading) { - doRead = false; - debug("reading or ended", doRead); - } else if (doRead) { - debug("do read"); - state.reading = true; - state.sync = true; // if the length is currently zero, then we *need* a readable event. - - if (state.length === 0) state.needReadable = true; // call internal read method - - this._read(state.highWaterMark); - - state.sync = false; // If _read pushed data synchronously, then `reading` will be false, - // and we need to re-evaluate how much data we can return to the user. - - if (!state.reading) n = howMuchToRead(nOrig, state); - } - - var ret; - if (n > 0) ret = fromList(n, state);else ret = null; - - if (ret === null) { - state.needReadable = state.length <= state.highWaterMark; - n = 0; - } else { - state.length -= n; - state.awaitDrain = 0; + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } + return out.strip(); } - if (state.length === 0) { - // If we have nothing in the buffer, then we want to know - // as soon as we *do* get something into the buffer. - if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick. + // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + if (c !== 0) { + o[19] = c; + out.length++; + } + return out; + }; + + // Polyfill comb + if (!Math.imul) { + comb10MulTo = smallMulTo; + } + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } + return out.strip(); + } + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$X).length + num.length; + if ((this || _global$X).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$X, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$X, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$X, num, out); + } else { + res = jumboMulTo(this || _global$X, num, out); + } + return res; + }; + + // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion + + function FFTM(x, y) { + (this || _global$X).x = x; + (this || _global$X).y = y; + } + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } + return t; + }; + + // Returns binary-reversed representation of `x` + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } + return rb; + }; + + // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + + /* jshint maxdepth : false */ + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } + } + }; + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } + return 1 << i + 1 + odd; + }; + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; + } + }; + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } + return ws; + }; + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } + + // Pad with zeroes + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } + assert(carry === 0); + assert((carry & ~8191) === 0); + }; + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); + for (var i = 0; i < N; i++) { + ph[i] = 0; + } + return ph; + }; + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); + var _ = this.stub(N); + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; + + // Multiply `this` by `num` + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$X).length + num.length); + return this.mulTo(num, out); + }; + + // Multiply employing FFT + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$X).length + num.length); + return jumboMulTo(this || _global$X, num, out); + }; + + // In-place Multiplication + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$X); + }; + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); + + // Carry + var carry = 0; + for (var i = 0; i < (this || _global$X).length; i++) { + var w = ((this || _global$X).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum + carry += lo >>> 26; + (this || _global$X).words[i] = lo & 67108863; + } + if (carry !== 0) { + (this || _global$X).words[i] = carry; + (this || _global$X).length++; + } + return this || _global$X; + }; + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; + + // `this` * `this` + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$X); + }; + + // `this` * `this` in-place + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; + + // Math.pow(`this`, `num`) + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); + + // Skip leading zeroes + var res = this || _global$X; + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } + return res; + }; + + // Shift-left in-place + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; + if (r !== 0) { + var carry = 0; + for (i = 0; i < (this || _global$X).length; i++) { + var newCarry = (this || _global$X).words[i] & carryMask; + var c = ((this || _global$X).words[i] | 0) - newCarry << r; + (this || _global$X).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } + if (carry) { + (this || _global$X).words[i] = carry; + (this || _global$X).length++; + } + } + if (s !== 0) { + for (i = (this || _global$X).length - 1; i >= 0; i--) { + (this || _global$X).words[i + s] = (this || _global$X).words[i]; + } + for (i = 0; i < s; i++) { + (this || _global$X).words[i] = 0; + } + (this || _global$X).length += s; + } + return this.strip(); + }; + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$X).negative === 0); + return this.iushln(bits); + }; + + // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$X).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); + + // Extended mode, copy masked part + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$X).words[i]; + } + maskedWords.length = s; + } + if (s === 0) ; else if ((this || _global$X).length > s) { + (this || _global$X).length -= s; + for (i = 0; i < (this || _global$X).length; i++) { + (this || _global$X).words[i] = (this || _global$X).words[i + s]; + } + } else { + (this || _global$X).words[0] = 0; + (this || _global$X).length = 1; + } + var carry = 0; + for (i = (this || _global$X).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$X).words[i] | 0; + (this || _global$X).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } + + // Push carried bits as a mask + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } + if ((this || _global$X).length === 0) { + (this || _global$X).words[0] = 0; + (this || _global$X).length = 1; + } + return this.strip(); + }; + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$X).negative === 0); + return this.iushrn(bits, hint, extended); + }; + + // Shift-left + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; + + // Shift-right + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; + + // Test if n bit is set + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; + + // Fast case: bit is much higher than all existing words + if ((this || _global$X).length <= s) return false; + + // Check bit and return + var w = (this || _global$X).words[s]; + return !!(w & q); + }; + + // Return only lowers bits of number (in-place) + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$X).negative === 0, "imaskn works only with positive numbers"); + if ((this || _global$X).length <= s) { + return this || _global$X; + } + if (r !== 0) { + s++; + } + (this || _global$X).length = Math.min(s, (this || _global$X).length); + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$X).words[(this || _global$X).length - 1] &= mask; + } + return this.strip(); + }; + + // Return only lowers bits of number + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; + + // Add plain number `num` to `this` + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); + + // Possible sign change + if ((this || _global$X).negative !== 0) { + if ((this || _global$X).length === 1 && ((this || _global$X).words[0] | 0) < num) { + (this || _global$X).words[0] = num - ((this || _global$X).words[0] | 0); + (this || _global$X).negative = 0; + return this || _global$X; + } + (this || _global$X).negative = 0; + this.isubn(num); + (this || _global$X).negative = 1; + return this || _global$X; + } + + // Add without checks + return this._iaddn(num); + }; + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$X).words[0] += num; + + // Carry + for (var i = 0; i < (this || _global$X).length && (this || _global$X).words[i] >= 67108864; i++) { + (this || _global$X).words[i] -= 67108864; + if (i === (this || _global$X).length - 1) { + (this || _global$X).words[i + 1] = 1; + } else { + (this || _global$X).words[i + 1]++; + } + } + (this || _global$X).length = Math.max((this || _global$X).length, i + 1); + return this || _global$X; + }; + + // Subtract plain number `num` from `this` + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); + if ((this || _global$X).negative !== 0) { + (this || _global$X).negative = 0; + this.iaddn(num); + (this || _global$X).negative = 1; + return this || _global$X; + } + (this || _global$X).words[0] -= num; + if ((this || _global$X).length === 1 && (this || _global$X).words[0] < 0) { + (this || _global$X).words[0] = -(this || _global$X).words[0]; + (this || _global$X).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$X).length && (this || _global$X).words[i] < 0; i++) { + (this || _global$X).words[i] += 67108864; + (this || _global$X).words[i + 1] -= 1; + } + } + return this.strip(); + }; + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; + BN.prototype.iabs = function iabs() { + (this || _global$X).negative = 0; + return this || _global$X; + }; + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + this._expand(len); + var w; + var carry = 0; + for (i = 0; i < num.length; i++) { + w = ((this || _global$X).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$X).words[i + shift] = w & 67108863; + } + for (; i < (this || _global$X).length - shift; i++) { + w = ((this || _global$X).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$X).words[i + shift] = w & 67108863; + } + if (carry === 0) return this.strip(); + + // Subtraction overflow + assert(carry === -1); + carry = 0; + for (i = 0; i < (this || _global$X).length; i++) { + w = -((this || _global$X).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$X).words[i] = w & 67108863; + } + (this || _global$X).negative = 1; + return this.strip(); + }; + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$X).length - num.length; + var a = this.clone(); + var b = num; + + // Normalize + var bhi = b.words[b.length - 1] | 0; + var bhiBits = this._countBits(bhi); + shift = 26 - bhiBits; + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } + + // Initialize quotient + var m = a.length - b.length; + var q; + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } + var diff = a.clone()._ishlnsubmul(b, 1, m); + if (diff.negative === 0) { + a = diff; + if (q) { + q.words[m] = 1; + } + } + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) + qj = Math.min(qj / bhi | 0, 67108863); + a._ishlnsubmul(b, qj, j); + while (a.negative !== 0) { + qj--; + a.negative = 0; + a._ishlnsubmul(b, 1, j); + if (!a.isZero()) { + a.negative ^= 1; + } + } + if (q) { + q.words[j] = qj; + } + } + if (q) { + q.strip(); + } + a.strip(); + + // Denormalize + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } + return { + div: q || null, + mod: a + }; + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } + var div, mod, res; + if ((this || _global$X).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); + if (mode !== "mod") { + div = res.div.neg(); + } + if (mode !== "div") { + mod = res.mod.neg(); + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } + return { + div: div, + mod: mod + }; + } + if ((this || _global$X).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); + if (mode !== "mod") { + div = res.div.neg(); + } + return { + div: div, + mod: res.mod + }; + } + if (((this || _global$X).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); + if (mode !== "div") { + mod = res.mod.neg(); + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } + return { + div: res.div, + mod: mod + }; + } + + // Both numbers are positive at this point + + // Strip both numbers to approximate shift value + if (num.length > (this || _global$X).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$X + }; + } + + // Very short reduction + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } + return this._wordDiv(num, mode); + }; + + // Find `this` / `num` + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; + + // Find `this` % `num` + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; + + // Find Round(`this` / `num`) + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); + + // Fast case - exact division + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); + + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + + // Round up + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + for (var i = (this || _global$X).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$X).words[i] | 0)) % num; + } + return acc; + }; + + // In-place division by number + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + for (var i = (this || _global$X).length - 1; i >= 0; i--) { + var w = ((this || _global$X).words[i] | 0) + carry * 67108864; + (this || _global$X).words[i] = w / num | 0; + carry = w % num; + } + return this.strip(); + }; + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$X; + var y = p.clone(); + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } + + // A * x + B * y = x + var A = new BN(1); + var B = new BN(0); + + // C * x + D * y = y + var C = new BN(0); + var D = new BN(1); + var g = 0; + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } + var yp = y.clone(); + var xp = x.clone(); + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + if (i > 0) { + x.iushrn(i); + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + A.iushrn(1); + B.iushrn(1); + } + } + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + if (j > 0) { + y.iushrn(j); + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + C.iushrn(1); + D.iushrn(1); + } + } + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; + + // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$X; + var b = p.clone(); + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + if (i > 0) { + a.iushrn(i); + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } + x1.iushrn(1); + } + } + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + if (j > 0) { + b.iushrn(j); + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } + x2.iushrn(1); + } + } + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + var res; + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + if (res.cmpn(0) < 0) { + res.iadd(p); + } + return res; + }; + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; + + // Remove common factor of two + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + do { + while (a.isEven()) { + a.iushrn(1); + } + while (b.isEven()) { + b.iushrn(1); + } + var r = a.cmp(b); + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + a.isub(b); + } while (true); + return b.iushln(shift); + }; + + // Invert number in the field F(num) + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + BN.prototype.isEven = function isEven() { + return ((this || _global$X).words[0] & 1) === 0; + }; + BN.prototype.isOdd = function isOdd() { + return ((this || _global$X).words[0] & 1) === 1; + }; + + // And first word and num + BN.prototype.andln = function andln(num) { + return (this || _global$X).words[0] & num; + }; + + // Increment at the bit position in-line + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; + + // Fast case: bit is much higher than all existing words + if ((this || _global$X).length <= s) { + this._expand(s + 1); + (this || _global$X).words[s] |= q; + return this || _global$X; + } + + // Add bit and propagate, if needed + var carry = q; + for (var i = s; carry !== 0 && i < (this || _global$X).length; i++) { + var w = (this || _global$X).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$X).words[i] = w; + } + if (carry !== 0) { + (this || _global$X).words[i] = carry; + (this || _global$X).length++; + } + return this || _global$X; + }; + BN.prototype.isZero = function isZero() { + return (this || _global$X).length === 1 && (this || _global$X).words[0] === 0; + }; + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$X).negative !== 0 && !negative) return -1; + if ((this || _global$X).negative === 0 && negative) return 1; + this.strip(); + var res; + if ((this || _global$X).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$X).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + if ((this || _global$X).negative !== 0) return -res | 0; + return res; + }; + + // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + BN.prototype.cmp = function cmp(num) { + if ((this || _global$X).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$X).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$X).negative !== 0) return -res | 0; + return res; + }; + + // Unsigned comparison + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$X).length > num.length) return 1; + if ((this || _global$X).length < num.length) return -1; + var res = 0; + for (var i = (this || _global$X).length - 1; i >= 0; i--) { + var a = (this || _global$X).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + break; + } + return res; + }; + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; + + // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + BN.red = function red(num) { + return new Red(num); + }; + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$X).red, "Already a number in reduction context"); + assert((this || _global$X).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$X)._forceRed(ctx); + }; + BN.prototype.fromRed = function fromRed() { + assert((this || _global$X).red, "fromRed works only with numbers in reduction context"); + return (this || _global$X).red.convertFrom(this || _global$X); + }; + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$X).red = ctx; + return this || _global$X; + }; + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$X).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$X).red, "redAdd works only with red numbers"); + return (this || _global$X).red.add(this || _global$X, num); + }; + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$X).red, "redIAdd works only with red numbers"); + return (this || _global$X).red.iadd(this || _global$X, num); + }; + BN.prototype.redSub = function redSub(num) { + assert((this || _global$X).red, "redSub works only with red numbers"); + return (this || _global$X).red.sub(this || _global$X, num); + }; + BN.prototype.redISub = function redISub(num) { + assert((this || _global$X).red, "redISub works only with red numbers"); + return (this || _global$X).red.isub(this || _global$X, num); + }; + BN.prototype.redShl = function redShl(num) { + assert((this || _global$X).red, "redShl works only with red numbers"); + return (this || _global$X).red.shl(this || _global$X, num); + }; + BN.prototype.redMul = function redMul(num) { + assert((this || _global$X).red, "redMul works only with red numbers"); + (this || _global$X).red._verify2(this || _global$X, num); + return (this || _global$X).red.mul(this || _global$X, num); + }; + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$X).red, "redMul works only with red numbers"); + (this || _global$X).red._verify2(this || _global$X, num); + return (this || _global$X).red.imul(this || _global$X, num); + }; + BN.prototype.redSqr = function redSqr() { + assert((this || _global$X).red, "redSqr works only with red numbers"); + (this || _global$X).red._verify1(this || _global$X); + return (this || _global$X).red.sqr(this || _global$X); + }; + BN.prototype.redISqr = function redISqr() { + assert((this || _global$X).red, "redISqr works only with red numbers"); + (this || _global$X).red._verify1(this || _global$X); + return (this || _global$X).red.isqr(this || _global$X); + }; + + // Square root over p + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$X).red, "redSqrt works only with red numbers"); + (this || _global$X).red._verify1(this || _global$X); + return (this || _global$X).red.sqrt(this || _global$X); + }; + BN.prototype.redInvm = function redInvm() { + assert((this || _global$X).red, "redInvm works only with red numbers"); + (this || _global$X).red._verify1(this || _global$X); + return (this || _global$X).red.invm(this || _global$X); + }; + + // Return negative clone of `this` % `red modulo` + BN.prototype.redNeg = function redNeg() { + assert((this || _global$X).red, "redNeg works only with red numbers"); + (this || _global$X).red._verify1(this || _global$X); + return (this || _global$X).red.neg(this || _global$X); + }; + BN.prototype.redPow = function redPow(num) { + assert((this || _global$X).red && !num.red, "redPow(normalNum)"); + (this || _global$X).red._verify1(this || _global$X); + return (this || _global$X).red.pow(this || _global$X, num); + }; + + // Prime numbers with efficient reduction + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; + + // Pseudo-Mersenne prime + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$X).name = name; + (this || _global$X).p = new BN(p, 16); + (this || _global$X).n = (this || _global$X).p.bitLength(); + (this || _global$X).k = new BN(1).iushln((this || _global$X).n).isub((this || _global$X).p); + (this || _global$X).tmp = this._tmp(); + } + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$X).n / 13)); + return tmp; + }; + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + do { + this.split(r, (this || _global$X).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$X).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$X).n); + var cmp = rlen < (this || _global$X).n ? -1 : r.ucmp((this || _global$X).p); + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$X).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + return r; + }; + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$X).n, 0, out); + }; + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$X).k); + }; + function K256() { + MPrime.call(this || _global$X, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + inherits(K256, MPrime); + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + output.length = outLen; + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } + + // Shift by 9 limbs + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + prev >>>= 22; + input.words[i - 10] = prev; + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; + + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + var lo = 0; + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } + + // Fast length reduction + if (num.words[num.length - 1] === 0) { + num.length--; + if (num.words[num.length - 1] === 0) { + num.length--; + } + } + return num; + }; + function P224() { + MPrime.call(this || _global$X, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } + inherits(P224, MPrime); + function P192() { + MPrime.call(this || _global$X, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } + inherits(P192, MPrime); + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$X, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } + inherits(P25519, MPrime); + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } + if (carry !== 0) { + num.words[num.length++] = carry; + } + return num; + }; + + // Exported mostly for testing purposes, use plain name instead + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + primes[name] = prime; + return prime; + }; + + // + // Base reduction engine + // + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + (this || _global$X).m = prime.p; + (this || _global$X).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$X).m = m; + (this || _global$X).prime = null; + } + } + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; + Red.prototype.imod = function imod(a) { + if ((this || _global$X).prime) return (this || _global$X).prime.ireduce(a)._forceRed(this || _global$X); + return a.umod((this || _global$X).m)._forceRed(this || _global$X); + }; + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } + return (this || _global$X).m.sub(a)._forceRed(this || _global$X); + }; + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + var res = a.add(b); + if (res.cmp((this || _global$X).m) >= 0) { + res.isub((this || _global$X).m); + } + return res._forceRed(this || _global$X); + }; + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + var res = a.iadd(b); + if (res.cmp((this || _global$X).m) >= 0) { + res.isub((this || _global$X).m); + } + return res; + }; + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); + var res = a.sub(b); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$X).m); + } + return res._forceRed(this || _global$X); + }; + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); + var res = a.isub(b); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$X).m); + } + return res; + }; + Red.prototype.shl = function shl(a, num) { + this._verify1(a); + return this.imod(a.ushln(num)); + }; + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); + return this.imod(a.imul(b)); + }; + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); + return this.imod(a.mul(b)); + }; + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + var mod3 = (this || _global$X).m.andln(3); + assert(mod3 % 2 === 1); + + // Fast case + if (mod3 === 3) { + var pow = (this || _global$X).m.add(new BN(1)).iushrn(2); + return this.pow(a, pow); + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) + var q = (this || _global$X).m.subn(1); + var s = 0; + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$X); + var nOne = one.redNeg(); + + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + var lpow = (this || _global$X).m.subn(1).iushrn(1); + var z = (this || _global$X).m.bitLength(); + z = new BN(2 * z * z).toRed(this || _global$X); + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; + while (t.cmp(one) !== 0) { + var tmp = t; + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } + return r; + }; + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$X).m); + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$X); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$X); + wnd[1] = a; + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + if (start === 0) { + start = 26; + } + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + if (res !== wnd[0]) { + res = this.sqr(res); + } + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + start = 26; + } + return res; + }; + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$X).m); + return r === num ? r.clone() : r; + }; + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; + + // + // Montgomery method engine + // + + BN.mont = function mont(num) { + return new Mont(num); + }; + function Mont(m) { + Red.call(this || _global$X, m); + (this || _global$X).shift = (this || _global$X).m.bitLength(); + if ((this || _global$X).shift % 26 !== 0) { + (this || _global$X).shift += 26 - (this || _global$X).shift % 26; + } + (this || _global$X).r = new BN(1).iushln((this || _global$X).shift); + (this || _global$X).r2 = this.imod((this || _global$X).r.sqr()); + (this || _global$X).rinv = (this || _global$X).r._invmp((this || _global$X).m); + (this || _global$X).minv = (this || _global$X).rinv.mul((this || _global$X).r).isubn(1).div((this || _global$X).m); + (this || _global$X).minv = (this || _global$X).minv.umod((this || _global$X).r); + (this || _global$X).minv = (this || _global$X).r.sub((this || _global$X).minv); + } + inherits(Mont, Red); + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$X).shift)); + }; + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$X).rinv)); + r.red = null; + return r; + }; + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + var t = a.imul(b); + var c = t.maskn((this || _global$X).shift).mul((this || _global$X).minv).imaskn((this || _global$X).shift).mul((this || _global$X).m); + var u = t.isub(c).iushrn((this || _global$X).shift); + var res = u; + if (u.cmp((this || _global$X).m) >= 0) { + res = u.isub((this || _global$X).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$X).m); + } + return res._forceRed(this || _global$X); + }; + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$X); + var t = a.mul(b); + var c = t.maskn((this || _global$X).shift).mul((this || _global$X).minv).imaskn((this || _global$X).shift).mul((this || _global$X).m); + var u = t.isub(c).iushrn((this || _global$X).shift); + var res = u; + if (u.cmp((this || _global$X).m) >= 0) { + res = u.isub((this || _global$X).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$X).m); + } + return res._forceRed(this || _global$X); + }; + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$X).m).mul((this || _global$X).r2)); + return res._forceRed(this || _global$X); + }; + })(module$e, exports$2T); + return module$e.exports; +} + +var exports$2S = {}, + _dewExec$2R = false; +var module$d = { + exports: exports$2S +}; +var _global$W = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$2R() { + if (_dewExec$2R) return module$d.exports; + _dewExec$2R = true; + (function (module, exports) { + + // Utils + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } + + // Could use `inherits` module, but don't want to move from single file + // architecture yet. + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + var TempCtor = function () {}; + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } + + // BN + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } + (this || _global$W).negative = 0; + (this || _global$W).words = null; + (this || _global$W).length = 0; + + // Reduction context + (this || _global$W).red = null; + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + this._init(number || 0, base || 10, endian || "be"); + } + } + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = dew$3J().Buffer; + } + } catch (e) {} + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + if (base === "hex") { + base = 16; + } + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + if (number[0] === "-") { + start++; + (this || _global$W).negative = 1; + } + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } + }; + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$W).negative = 1; + number = -number; + } + if (number < 67108864) { + (this || _global$W).words = [number & 67108863]; + (this || _global$W).length = 1; + } else if (number < 4503599627370496) { + (this || _global$W).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$W).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + (this || _global$W).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$W).length = 3; + } + if (endian !== "le") return; + + // Reverse the bytes + this._initArray(this.toArray(), base, endian); + }; + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + if (number.length <= 0) { + (this || _global$W).words = [0]; + (this || _global$W).length = 1; + return this || _global$W; + } + (this || _global$W).length = Math.ceil(number.length / 3); + (this || _global$W).words = new Array((this || _global$W).length); + for (var i = 0; i < (this || _global$W).length; i++) { + (this || _global$W).words[i] = 0; + } + var j, w; + var off = 0; + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$W).words[j] |= w << off & 67108863; + (this || _global$W).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$W).words[j] |= w << off & 67108863; + (this || _global$W).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + if (off >= 26) { + off -= 26; + j++; + } + } + } + return this.strip(); + }; + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); + // 'A' - 'F' + if (c >= 65 && c <= 70) { + return c - 55; + // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; + // '0' - '9' + } else { + return c - 48 & 15; + } + } + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } + return r; + } + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$W).length = Math.ceil((number.length - start) / 6); + (this || _global$W).words = new Array((this || _global$W).length); + for (var i = 0; i < (this || _global$W).length; i++) { + (this || _global$W).words[i] = 0; + } + + // 24-bits chunks + var off = 0; + var j = 0; + var w; + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$W).words[j] |= w & 67108863; + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$W).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$W).words[j] |= w & 67108863; + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$W).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + this.strip(); + }; + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; + + // 'a' + if (c >= 49) { + r += c - 49 + 10; + + // 'A' + } else if (c >= 17) { + r += c - 17 + 10; + + // '0' - '9' + } else { + r += c; + } + } + return r; + } + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$W).words = [0]; + (this || _global$W).length = 1; + + // Find length of limb in base + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + if ((this || _global$W).words[0] + word < 67108864) { + (this || _global$W).words[0] += word; + } else { + this._iaddn(word); + } + } + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + for (i = 0; i < mod; i++) { + pow *= base; + } + this.imuln(pow); + if ((this || _global$W).words[0] + word < 67108864) { + (this || _global$W).words[0] += word; + } else { + this._iaddn(word); + } + } + this.strip(); + }; + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$W).length); + for (var i = 0; i < (this || _global$W).length; i++) { + dest.words[i] = (this || _global$W).words[i]; + } + dest.length = (this || _global$W).length; + dest.negative = (this || _global$W).negative; + dest.red = (this || _global$W).red; + }; + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + BN.prototype._expand = function _expand(size) { + while ((this || _global$W).length < size) { + (this || _global$W).words[(this || _global$W).length++] = 0; + } + return this || _global$W; + }; + + // Remove leading `0` from `this` + BN.prototype.strip = function strip() { + while ((this || _global$W).length > 1 && (this || _global$W).words[(this || _global$W).length - 1] === 0) { + (this || _global$W).length--; + } + return this._normSign(); + }; + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$W).length === 1 && (this || _global$W).words[0] === 0) { + (this || _global$W).negative = 0; + } + return this || _global$W; + }; + BN.prototype.inspect = function inspect() { + return ((this || _global$W).red ? ""; + }; + + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ + + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + for (var i = 0; i < (this || _global$W).length; i++) { + var w = (this || _global$W).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + if (carry !== 0 || i !== (this || _global$W).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + off += 2; + if (off >= 26) { + off -= 26; + i--; + } + } + if (carry !== 0) { + out = carry.toString(16) + out; + } + while (out.length % padding !== 0) { + out = "0" + out; + } + if ((this || _global$W).negative !== 0) { + out = "-" + out; + } + return out; + } + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + if (this.isZero()) { + out = "0" + out; + } + while (out.length % padding !== 0) { + out = "0" + out; + } + if ((this || _global$W).negative !== 0) { + out = "-" + out; + } + return out; + } + assert(false, "Base should be between 2 and 36"); + }; + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$W).words[0]; + if ((this || _global$W).length === 2) { + ret += (this || _global$W).words[1] * 67108864; + } else if ((this || _global$W).length === 3 && (this || _global$W).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$W).words[1] * 67108864; + } else if ((this || _global$W).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + return (this || _global$W).negative !== 0 ? -ret : ret; + }; + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } + } else { + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + for (; i < reqLength; i++) { + res[i] = 0; + } + } + return res; + }; + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + if (t >= 4096) { + r += 13; + t >>>= 13; + } + if (t >= 64) { + r += 7; + t >>>= 7; + } + if (t >= 8) { + r += 4; + t >>>= 4; + } + if (t >= 2) { + r += 2; + t >>>= 2; + } + return r + t; + }; + } + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } + if ((t & 1) === 0) { + r++; + } + return r; + }; + + // Return number of used bits in a BN + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$W).words[(this || _global$W).length - 1]; + var hi = this._countBits(w); + return ((this || _global$W).length - 1) * 26 + hi; + }; + function toBitArray(num) { + var w = new Array(num.bitLength()); + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + return w; + } + + // Number of trailing zero bits + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; + for (var i = 0; i < (this || _global$W).length; i++) { + var b = this._zeroBits((this || _global$W).words[i]); + r += b; + if (b !== 26) break; + } + return r; + }; + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$W).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + return this.clone(); + }; + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } + return this.clone(); + }; + BN.prototype.isNeg = function isNeg() { + return (this || _global$W).negative !== 0; + }; + + // Return negative clone of `this` + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$W).negative ^= 1; + } + return this || _global$W; + }; + + // Or `num` with `this` in-place + BN.prototype.iuor = function iuor(num) { + while ((this || _global$W).length < num.length) { + (this || _global$W).words[(this || _global$W).length++] = 0; + } + for (var i = 0; i < num.length; i++) { + (this || _global$W).words[i] = (this || _global$W).words[i] | num.words[i]; + } + return this.strip(); + }; + BN.prototype.ior = function ior(num) { + assert(((this || _global$W).negative | num.negative) === 0); + return this.iuor(num); + }; + + // Or `num` with `this` + BN.prototype.or = function or(num) { + if ((this || _global$W).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$W); + }; + BN.prototype.uor = function uor(num) { + if ((this || _global$W).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$W); + }; + + // And `num` with `this` in-place + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + if ((this || _global$W).length > num.length) { + b = num; + } else { + b = this || _global$W; + } + for (var i = 0; i < b.length; i++) { + (this || _global$W).words[i] = (this || _global$W).words[i] & num.words[i]; + } + (this || _global$W).length = b.length; + return this.strip(); + }; + BN.prototype.iand = function iand(num) { + assert(((this || _global$W).negative | num.negative) === 0); + return this.iuand(num); + }; + + // And `num` with `this` + BN.prototype.and = function and(num) { + if ((this || _global$W).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$W); + }; + BN.prototype.uand = function uand(num) { + if ((this || _global$W).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$W); + }; + + // Xor `num` with `this` in-place + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + if ((this || _global$W).length > num.length) { + a = this || _global$W; + b = num; + } else { + a = num; + b = this || _global$W; + } + for (var i = 0; i < b.length; i++) { + (this || _global$W).words[i] = a.words[i] ^ b.words[i]; + } + if ((this || _global$W) !== a) { + for (; i < a.length; i++) { + (this || _global$W).words[i] = a.words[i]; + } + } + (this || _global$W).length = a.length; + return this.strip(); + }; + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$W).negative | num.negative) === 0); + return this.iuxor(num); + }; + + // Xor `num` with `this` + BN.prototype.xor = function xor(num) { + if ((this || _global$W).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$W); + }; + BN.prototype.uxor = function uxor(num) { + if ((this || _global$W).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$W); + }; + + // Not ``this`` with ``width`` bitwidth + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; + + // Extend the buffer with leading zeroes + this._expand(bytesNeeded); + if (bitsLeft > 0) { + bytesNeeded--; + } + + // Handle complete words + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$W).words[i] = ~(this || _global$W).words[i] & 67108863; + } + + // Handle the residue + if (bitsLeft > 0) { + (this || _global$W).words[i] = ~(this || _global$W).words[i] & 67108863 >> 26 - bitsLeft; + } + + // And remove leading zeroes + return this.strip(); + }; + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; + + // Set `bit` of `this` + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + this._expand(off + 1); + if (val) { + (this || _global$W).words[off] = (this || _global$W).words[off] | 1 << wbit; + } else { + (this || _global$W).words[off] = (this || _global$W).words[off] & ~(1 << wbit); + } + return this.strip(); + }; + + // Add `num` to `this` in-place + BN.prototype.iadd = function iadd(num) { + var r; + + // negative + positive + if ((this || _global$W).negative !== 0 && num.negative === 0) { + (this || _global$W).negative = 0; + r = this.isub(num); + (this || _global$W).negative ^= 1; + return this._normSign(); + + // positive + negative + } else if ((this || _global$W).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } + + // a.length > b.length + var a, b; + if ((this || _global$W).length > num.length) { + a = this || _global$W; + b = num; + } else { + a = num; + b = this || _global$W; + } + var carry = 0; + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$W).words[i] = r & 67108863; + carry = r >>> 26; + } + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$W).words[i] = r & 67108863; + carry = r >>> 26; + } + (this || _global$W).length = a.length; + if (carry !== 0) { + (this || _global$W).words[(this || _global$W).length] = carry; + (this || _global$W).length++; + // Copy the rest of the words + } else if (a !== (this || _global$W)) { + for (; i < a.length; i++) { + (this || _global$W).words[i] = a.words[i]; + } + } + return this || _global$W; + }; + + // Add `num` to `this` + BN.prototype.add = function add(num) { + var res; + if (num.negative !== 0 && (this || _global$W).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$W).negative !== 0) { + (this || _global$W).negative = 0; + res = num.sub(this || _global$W); + (this || _global$W).negative = 1; + return res; + } + if ((this || _global$W).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$W); + }; + + // Subtract `num` from `this` in-place + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); + + // -this - num = -(this + num) + } else if ((this || _global$W).negative !== 0) { + (this || _global$W).negative = 0; + this.iadd(num); + (this || _global$W).negative = 1; + return this._normSign(); + } + + // At this point both numbers are positive + var cmp = this.cmp(num); + + // Optimization - zeroify + if (cmp === 0) { + (this || _global$W).negative = 0; + (this || _global$W).length = 1; + (this || _global$W).words[0] = 0; + return this || _global$W; + } + + // a > b + var a, b; + if (cmp > 0) { + a = this || _global$W; + b = num; + } else { + a = num; + b = this || _global$W; + } + var carry = 0; + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$W).words[i] = r & 67108863; + } + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$W).words[i] = r & 67108863; + } + + // Copy rest of the words + if (carry === 0 && i < a.length && a !== (this || _global$W)) { + for (; i < a.length; i++) { + (this || _global$W).words[i] = a.words[i]; + } + } + (this || _global$W).length = Math.max((this || _global$W).length, i); + if (a !== (this || _global$W)) { + (this || _global$W).negative = 1; + } + return this.strip(); + }; + + // Subtract `num` from `this` + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; + + // Peel one iteration (compiler can't do it, because of code complexity) + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } + out.words[k] = rword | 0; + carry = ncarry | 0; + } + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } + return out.strip(); + } + + // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + if (c !== 0) { + o[19] = c; + out.length++; + } + return out; + }; + + // Polyfill comb + if (!Math.imul) { + comb10MulTo = smallMulTo; + } + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } + return out.strip(); + } + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$W).length + num.length; + if ((this || _global$W).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$W, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$W, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$W, num, out); + } else { + res = jumboMulTo(this || _global$W, num, out); + } + return res; + }; + + // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion + + function FFTM(x, y) { + (this || _global$W).x = x; + (this || _global$W).y = y; + } + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } + return t; + }; + + // Returns binary-reversed representation of `x` + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } + return rb; + }; + + // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + + /* jshint maxdepth : false */ + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } + } + }; + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } + return 1 << i + 1 + odd; + }; + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; + } + }; + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } + return ws; + }; + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } + + // Pad with zeroes + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } + assert(carry === 0); + assert((carry & ~8191) === 0); + }; + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); + for (var i = 0; i < N; i++) { + ph[i] = 0; + } + return ph; + }; + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); + var _ = this.stub(N); + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; + + // Multiply `this` by `num` + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$W).length + num.length); + return this.mulTo(num, out); + }; + + // Multiply employing FFT + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$W).length + num.length); + return jumboMulTo(this || _global$W, num, out); + }; + + // In-place Multiplication + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$W); + }; + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); + + // Carry + var carry = 0; + for (var i = 0; i < (this || _global$W).length; i++) { + var w = ((this || _global$W).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum + carry += lo >>> 26; + (this || _global$W).words[i] = lo & 67108863; + } + if (carry !== 0) { + (this || _global$W).words[i] = carry; + (this || _global$W).length++; + } + return this || _global$W; + }; + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; + + // `this` * `this` + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$W); + }; + + // `this` * `this` in-place + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; + + // Math.pow(`this`, `num`) + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); + + // Skip leading zeroes + var res = this || _global$W; + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } + return res; + }; + + // Shift-left in-place + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; + if (r !== 0) { + var carry = 0; + for (i = 0; i < (this || _global$W).length; i++) { + var newCarry = (this || _global$W).words[i] & carryMask; + var c = ((this || _global$W).words[i] | 0) - newCarry << r; + (this || _global$W).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } + if (carry) { + (this || _global$W).words[i] = carry; + (this || _global$W).length++; + } + } + if (s !== 0) { + for (i = (this || _global$W).length - 1; i >= 0; i--) { + (this || _global$W).words[i + s] = (this || _global$W).words[i]; + } + for (i = 0; i < s; i++) { + (this || _global$W).words[i] = 0; + } + (this || _global$W).length += s; + } + return this.strip(); + }; + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$W).negative === 0); + return this.iushln(bits); + }; + + // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$W).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); + + // Extended mode, copy masked part + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$W).words[i]; + } + maskedWords.length = s; + } + if (s === 0) ; else if ((this || _global$W).length > s) { + (this || _global$W).length -= s; + for (i = 0; i < (this || _global$W).length; i++) { + (this || _global$W).words[i] = (this || _global$W).words[i + s]; + } + } else { + (this || _global$W).words[0] = 0; + (this || _global$W).length = 1; + } + var carry = 0; + for (i = (this || _global$W).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$W).words[i] | 0; + (this || _global$W).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } + + // Push carried bits as a mask + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } + if ((this || _global$W).length === 0) { + (this || _global$W).words[0] = 0; + (this || _global$W).length = 1; + } + return this.strip(); + }; + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$W).negative === 0); + return this.iushrn(bits, hint, extended); + }; + + // Shift-left + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; + + // Shift-right + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; + + // Test if n bit is set + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; + + // Fast case: bit is much higher than all existing words + if ((this || _global$W).length <= s) return false; + + // Check bit and return + var w = (this || _global$W).words[s]; + return !!(w & q); + }; + + // Return only lowers bits of number (in-place) + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$W).negative === 0, "imaskn works only with positive numbers"); + if ((this || _global$W).length <= s) { + return this || _global$W; + } + if (r !== 0) { + s++; + } + (this || _global$W).length = Math.min(s, (this || _global$W).length); + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$W).words[(this || _global$W).length - 1] &= mask; + } + return this.strip(); + }; + + // Return only lowers bits of number + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; + + // Add plain number `num` to `this` + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); + + // Possible sign change + if ((this || _global$W).negative !== 0) { + if ((this || _global$W).length === 1 && ((this || _global$W).words[0] | 0) < num) { + (this || _global$W).words[0] = num - ((this || _global$W).words[0] | 0); + (this || _global$W).negative = 0; + return this || _global$W; + } + (this || _global$W).negative = 0; + this.isubn(num); + (this || _global$W).negative = 1; + return this || _global$W; + } + + // Add without checks + return this._iaddn(num); + }; + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$W).words[0] += num; + + // Carry + for (var i = 0; i < (this || _global$W).length && (this || _global$W).words[i] >= 67108864; i++) { + (this || _global$W).words[i] -= 67108864; + if (i === (this || _global$W).length - 1) { + (this || _global$W).words[i + 1] = 1; + } else { + (this || _global$W).words[i + 1]++; + } + } + (this || _global$W).length = Math.max((this || _global$W).length, i + 1); + return this || _global$W; + }; + + // Subtract plain number `num` from `this` + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); + if ((this || _global$W).negative !== 0) { + (this || _global$W).negative = 0; + this.iaddn(num); + (this || _global$W).negative = 1; + return this || _global$W; + } + (this || _global$W).words[0] -= num; + if ((this || _global$W).length === 1 && (this || _global$W).words[0] < 0) { + (this || _global$W).words[0] = -(this || _global$W).words[0]; + (this || _global$W).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$W).length && (this || _global$W).words[i] < 0; i++) { + (this || _global$W).words[i] += 67108864; + (this || _global$W).words[i + 1] -= 1; + } + } + return this.strip(); + }; + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; + BN.prototype.iabs = function iabs() { + (this || _global$W).negative = 0; + return this || _global$W; + }; + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + this._expand(len); + var w; + var carry = 0; + for (i = 0; i < num.length; i++) { + w = ((this || _global$W).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$W).words[i + shift] = w & 67108863; + } + for (; i < (this || _global$W).length - shift; i++) { + w = ((this || _global$W).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$W).words[i + shift] = w & 67108863; + } + if (carry === 0) return this.strip(); + + // Subtraction overflow + assert(carry === -1); + carry = 0; + for (i = 0; i < (this || _global$W).length; i++) { + w = -((this || _global$W).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$W).words[i] = w & 67108863; + } + (this || _global$W).negative = 1; + return this.strip(); + }; + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$W).length - num.length; + var a = this.clone(); + var b = num; + + // Normalize + var bhi = b.words[b.length - 1] | 0; + var bhiBits = this._countBits(bhi); + shift = 26 - bhiBits; + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } + + // Initialize quotient + var m = a.length - b.length; + var q; + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } + var diff = a.clone()._ishlnsubmul(b, 1, m); + if (diff.negative === 0) { + a = diff; + if (q) { + q.words[m] = 1; + } + } + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) + qj = Math.min(qj / bhi | 0, 67108863); + a._ishlnsubmul(b, qj, j); + while (a.negative !== 0) { + qj--; + a.negative = 0; + a._ishlnsubmul(b, 1, j); + if (!a.isZero()) { + a.negative ^= 1; + } + } + if (q) { + q.words[j] = qj; + } + } + if (q) { + q.strip(); + } + a.strip(); + + // Denormalize + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } + return { + div: q || null, + mod: a + }; + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } + var div, mod, res; + if ((this || _global$W).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); + if (mode !== "mod") { + div = res.div.neg(); + } + if (mode !== "div") { + mod = res.mod.neg(); + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } + return { + div: div, + mod: mod + }; + } + if ((this || _global$W).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); + if (mode !== "mod") { + div = res.div.neg(); + } + return { + div: div, + mod: res.mod + }; + } + if (((this || _global$W).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); + if (mode !== "div") { + mod = res.mod.neg(); + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } + return { + div: res.div, + mod: mod + }; + } + + // Both numbers are positive at this point + + // Strip both numbers to approximate shift value + if (num.length > (this || _global$W).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$W + }; + } + + // Very short reduction + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } + return this._wordDiv(num, mode); + }; + + // Find `this` / `num` + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; + + // Find `this` % `num` + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; + + // Find Round(`this` / `num`) + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); + + // Fast case - exact division + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); + + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + + // Round up + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + for (var i = (this || _global$W).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$W).words[i] | 0)) % num; + } + return acc; + }; + + // In-place division by number + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + for (var i = (this || _global$W).length - 1; i >= 0; i--) { + var w = ((this || _global$W).words[i] | 0) + carry * 67108864; + (this || _global$W).words[i] = w / num | 0; + carry = w % num; + } + return this.strip(); + }; + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$W; + var y = p.clone(); + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } + + // A * x + B * y = x + var A = new BN(1); + var B = new BN(0); + + // C * x + D * y = y + var C = new BN(0); + var D = new BN(1); + var g = 0; + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } + var yp = y.clone(); + var xp = x.clone(); + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + if (i > 0) { + x.iushrn(i); + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + A.iushrn(1); + B.iushrn(1); + } + } + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + if (j > 0) { + y.iushrn(j); + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + C.iushrn(1); + D.iushrn(1); + } + } + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; + + // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$W; + var b = p.clone(); + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + if (i > 0) { + a.iushrn(i); + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } + x1.iushrn(1); + } + } + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + if (j > 0) { + b.iushrn(j); + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } + x2.iushrn(1); + } + } + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + var res; + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + if (res.cmpn(0) < 0) { + res.iadd(p); + } + return res; + }; + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; + + // Remove common factor of two + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + do { + while (a.isEven()) { + a.iushrn(1); + } + while (b.isEven()) { + b.iushrn(1); + } + var r = a.cmp(b); + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + a.isub(b); + } while (true); + return b.iushln(shift); + }; + + // Invert number in the field F(num) + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + BN.prototype.isEven = function isEven() { + return ((this || _global$W).words[0] & 1) === 0; + }; + BN.prototype.isOdd = function isOdd() { + return ((this || _global$W).words[0] & 1) === 1; + }; + + // And first word and num + BN.prototype.andln = function andln(num) { + return (this || _global$W).words[0] & num; + }; + + // Increment at the bit position in-line + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; + + // Fast case: bit is much higher than all existing words + if ((this || _global$W).length <= s) { + this._expand(s + 1); + (this || _global$W).words[s] |= q; + return this || _global$W; + } + + // Add bit and propagate, if needed + var carry = q; + for (var i = s; carry !== 0 && i < (this || _global$W).length; i++) { + var w = (this || _global$W).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$W).words[i] = w; + } + if (carry !== 0) { + (this || _global$W).words[i] = carry; + (this || _global$W).length++; + } + return this || _global$W; + }; + BN.prototype.isZero = function isZero() { + return (this || _global$W).length === 1 && (this || _global$W).words[0] === 0; + }; + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$W).negative !== 0 && !negative) return -1; + if ((this || _global$W).negative === 0 && negative) return 1; + this.strip(); + var res; + if ((this || _global$W).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$W).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + if ((this || _global$W).negative !== 0) return -res | 0; + return res; + }; + + // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + BN.prototype.cmp = function cmp(num) { + if ((this || _global$W).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$W).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$W).negative !== 0) return -res | 0; + return res; + }; + + // Unsigned comparison + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$W).length > num.length) return 1; + if ((this || _global$W).length < num.length) return -1; + var res = 0; + for (var i = (this || _global$W).length - 1; i >= 0; i--) { + var a = (this || _global$W).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + break; + } + return res; + }; + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; + + // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + BN.red = function red(num) { + return new Red(num); + }; + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$W).red, "Already a number in reduction context"); + assert((this || _global$W).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$W)._forceRed(ctx); + }; + BN.prototype.fromRed = function fromRed() { + assert((this || _global$W).red, "fromRed works only with numbers in reduction context"); + return (this || _global$W).red.convertFrom(this || _global$W); + }; + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$W).red = ctx; + return this || _global$W; + }; + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$W).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$W).red, "redAdd works only with red numbers"); + return (this || _global$W).red.add(this || _global$W, num); + }; + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$W).red, "redIAdd works only with red numbers"); + return (this || _global$W).red.iadd(this || _global$W, num); + }; + BN.prototype.redSub = function redSub(num) { + assert((this || _global$W).red, "redSub works only with red numbers"); + return (this || _global$W).red.sub(this || _global$W, num); + }; + BN.prototype.redISub = function redISub(num) { + assert((this || _global$W).red, "redISub works only with red numbers"); + return (this || _global$W).red.isub(this || _global$W, num); + }; + BN.prototype.redShl = function redShl(num) { + assert((this || _global$W).red, "redShl works only with red numbers"); + return (this || _global$W).red.shl(this || _global$W, num); + }; + BN.prototype.redMul = function redMul(num) { + assert((this || _global$W).red, "redMul works only with red numbers"); + (this || _global$W).red._verify2(this || _global$W, num); + return (this || _global$W).red.mul(this || _global$W, num); + }; + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$W).red, "redMul works only with red numbers"); + (this || _global$W).red._verify2(this || _global$W, num); + return (this || _global$W).red.imul(this || _global$W, num); + }; + BN.prototype.redSqr = function redSqr() { + assert((this || _global$W).red, "redSqr works only with red numbers"); + (this || _global$W).red._verify1(this || _global$W); + return (this || _global$W).red.sqr(this || _global$W); + }; + BN.prototype.redISqr = function redISqr() { + assert((this || _global$W).red, "redISqr works only with red numbers"); + (this || _global$W).red._verify1(this || _global$W); + return (this || _global$W).red.isqr(this || _global$W); + }; + + // Square root over p + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$W).red, "redSqrt works only with red numbers"); + (this || _global$W).red._verify1(this || _global$W); + return (this || _global$W).red.sqrt(this || _global$W); + }; + BN.prototype.redInvm = function redInvm() { + assert((this || _global$W).red, "redInvm works only with red numbers"); + (this || _global$W).red._verify1(this || _global$W); + return (this || _global$W).red.invm(this || _global$W); + }; + + // Return negative clone of `this` % `red modulo` + BN.prototype.redNeg = function redNeg() { + assert((this || _global$W).red, "redNeg works only with red numbers"); + (this || _global$W).red._verify1(this || _global$W); + return (this || _global$W).red.neg(this || _global$W); + }; + BN.prototype.redPow = function redPow(num) { + assert((this || _global$W).red && !num.red, "redPow(normalNum)"); + (this || _global$W).red._verify1(this || _global$W); + return (this || _global$W).red.pow(this || _global$W, num); + }; + + // Prime numbers with efficient reduction + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; + + // Pseudo-Mersenne prime + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$W).name = name; + (this || _global$W).p = new BN(p, 16); + (this || _global$W).n = (this || _global$W).p.bitLength(); + (this || _global$W).k = new BN(1).iushln((this || _global$W).n).isub((this || _global$W).p); + (this || _global$W).tmp = this._tmp(); + } + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$W).n / 13)); + return tmp; + }; + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + do { + this.split(r, (this || _global$W).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$W).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$W).n); + var cmp = rlen < (this || _global$W).n ? -1 : r.ucmp((this || _global$W).p); + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$W).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + return r; + }; + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$W).n, 0, out); + }; + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$W).k); + }; + function K256() { + MPrime.call(this || _global$W, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + inherits(K256, MPrime); + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + output.length = outLen; + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } + + // Shift by 9 limbs + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + prev >>>= 22; + input.words[i - 10] = prev; + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; + + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + var lo = 0; + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } + + // Fast length reduction + if (num.words[num.length - 1] === 0) { + num.length--; + if (num.words[num.length - 1] === 0) { + num.length--; + } + } + return num; + }; + function P224() { + MPrime.call(this || _global$W, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } + inherits(P224, MPrime); + function P192() { + MPrime.call(this || _global$W, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } + inherits(P192, MPrime); + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$W, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } + inherits(P25519, MPrime); + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } + if (carry !== 0) { + num.words[num.length++] = carry; + } + return num; + }; + + // Exported mostly for testing purposes, use plain name instead + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + primes[name] = prime; + return prime; + }; + + // + // Base reduction engine + // + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + (this || _global$W).m = prime.p; + (this || _global$W).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$W).m = m; + (this || _global$W).prime = null; + } + } + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; + Red.prototype.imod = function imod(a) { + if ((this || _global$W).prime) return (this || _global$W).prime.ireduce(a)._forceRed(this || _global$W); + return a.umod((this || _global$W).m)._forceRed(this || _global$W); + }; + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } + return (this || _global$W).m.sub(a)._forceRed(this || _global$W); + }; + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + var res = a.add(b); + if (res.cmp((this || _global$W).m) >= 0) { + res.isub((this || _global$W).m); + } + return res._forceRed(this || _global$W); + }; + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + var res = a.iadd(b); + if (res.cmp((this || _global$W).m) >= 0) { + res.isub((this || _global$W).m); + } + return res; + }; + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); + var res = a.sub(b); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$W).m); + } + return res._forceRed(this || _global$W); + }; + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); + var res = a.isub(b); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$W).m); + } + return res; + }; + Red.prototype.shl = function shl(a, num) { + this._verify1(a); + return this.imod(a.ushln(num)); + }; + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); + return this.imod(a.imul(b)); + }; + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); + return this.imod(a.mul(b)); + }; + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + var mod3 = (this || _global$W).m.andln(3); + assert(mod3 % 2 === 1); + + // Fast case + if (mod3 === 3) { + var pow = (this || _global$W).m.add(new BN(1)).iushrn(2); + return this.pow(a, pow); + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) + var q = (this || _global$W).m.subn(1); + var s = 0; + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$W); + var nOne = one.redNeg(); + + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + var lpow = (this || _global$W).m.subn(1).iushrn(1); + var z = (this || _global$W).m.bitLength(); + z = new BN(2 * z * z).toRed(this || _global$W); + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; + while (t.cmp(one) !== 0) { + var tmp = t; + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } + return r; + }; + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$W).m); + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$W); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$W); + wnd[1] = a; + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + if (start === 0) { + start = 26; + } + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + if (res !== wnd[0]) { + res = this.sqr(res); + } + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + start = 26; + } + return res; + }; + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$W).m); + return r === num ? r.clone() : r; + }; + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; + + // + // Montgomery method engine + // + + BN.mont = function mont(num) { + return new Mont(num); + }; + function Mont(m) { + Red.call(this || _global$W, m); + (this || _global$W).shift = (this || _global$W).m.bitLength(); + if ((this || _global$W).shift % 26 !== 0) { + (this || _global$W).shift += 26 - (this || _global$W).shift % 26; + } + (this || _global$W).r = new BN(1).iushln((this || _global$W).shift); + (this || _global$W).r2 = this.imod((this || _global$W).r.sqr()); + (this || _global$W).rinv = (this || _global$W).r._invmp((this || _global$W).m); + (this || _global$W).minv = (this || _global$W).rinv.mul((this || _global$W).r).isubn(1).div((this || _global$W).m); + (this || _global$W).minv = (this || _global$W).minv.umod((this || _global$W).r); + (this || _global$W).minv = (this || _global$W).r.sub((this || _global$W).minv); + } + inherits(Mont, Red); + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$W).shift)); + }; + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$W).rinv)); + r.red = null; + return r; + }; + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + var t = a.imul(b); + var c = t.maskn((this || _global$W).shift).mul((this || _global$W).minv).imaskn((this || _global$W).shift).mul((this || _global$W).m); + var u = t.isub(c).iushrn((this || _global$W).shift); + var res = u; + if (u.cmp((this || _global$W).m) >= 0) { + res = u.isub((this || _global$W).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$W).m); + } + return res._forceRed(this || _global$W); + }; + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$W); + var t = a.mul(b); + var c = t.maskn((this || _global$W).shift).mul((this || _global$W).minv).imaskn((this || _global$W).shift).mul((this || _global$W).m); + var u = t.isub(c).iushrn((this || _global$W).shift); + var res = u; + if (u.cmp((this || _global$W).m) >= 0) { + res = u.isub((this || _global$W).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$W).m); + } + return res._forceRed(this || _global$W); + }; + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$W).m).mul((this || _global$W).r2)); + return res._forceRed(this || _global$W); + }; + })(module$d, exports$2S); + return module$d.exports; +} + +var exports$2Q = {}, + _dewExec$2P = false; +function dew$2P() { + if (_dewExec$2P) return exports$2Q; + _dewExec$2P = true; + + /* eslint-disable node/no-deprecated-api */ + var buffer$1 = buffer; + var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers + + function copyProps(src, dst) { + for (var key in src) { + dst[key] = src[key]; + } + } + + if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + exports$2Q = buffer$1; + } else { + // Copy properties from require('buffer') + copyProps(buffer$1, exports$2Q); + exports$2Q.Buffer = SafeBuffer; + } + + function SafeBuffer(arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length); + } // Copy static methods from Buffer + + + copyProps(Buffer, SafeBuffer); + + SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === "number") { + throw new TypeError("Argument must not be a number"); + } + + return Buffer(arg, encodingOrOffset, length); + }; + + SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + var buf = Buffer(size); + + if (fill !== undefined) { + if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } + } else { + buf.fill(0); + } + + return buf; + }; + + SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return Buffer(size); + }; + + SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return buffer$1.SlowBuffer(size); + }; + + return exports$2Q; +} + +var exports$2P = {}, + _dewExec$2O = false; + +var _global$U = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2O() { + if (_dewExec$2O) return exports$2P; + _dewExec$2O = true; + var process$1$1 = process$1; + // limit of Crypto.getRandomValues() + // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues + var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes + // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 + + var MAX_UINT32 = 4294967295; + + function oldBrowser() { + throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11"); + } + + var Buffer = dew$2P().Buffer; + + var crypto = _global$U.crypto || _global$U.msCrypto; + + if (crypto && crypto.getRandomValues) { + exports$2P = randomBytes; + } else { + exports$2P = oldBrowser; + } + + function randomBytes(size, cb) { + // phantomjs needs to throw + if (size > MAX_UINT32) throw new RangeError("requested too many random bytes"); + var bytes = Buffer.allocUnsafe(size); + + if (size > 0) { + // getRandomValues fails on IE if size == 0 + if (size > MAX_BYTES) { + // this is the max bytes crypto.getRandomValues + // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues + for (var generated = 0; generated < size; generated += MAX_BYTES) { + // buffer.slice automatically checks if the end is past the end of + // the buffer so we don't have to here + crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES)); + } + } else { + crypto.getRandomValues(bytes); + } + } + + if (typeof cb === "function") { + return process$1$1.nextTick(function () { + cb(null, bytes); + }); + } + + return bytes; + } + + return exports$2P; +} + +var exports$2O = {}, + _dewExec$2N = false; +function dew$2N() { + if (_dewExec$2N) return exports$2O; + _dewExec$2N = true; + + /*! safe-buffer. MIT License. Feross Aboukhadijeh */ + + /* eslint-disable node/no-deprecated-api */ + var buffer$1 = buffer; + var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers + + function copyProps(src, dst) { + for (var key in src) { + dst[key] = src[key]; + } + } + + if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + exports$2O = buffer$1; + } else { + // Copy properties from require('buffer') + copyProps(buffer$1, exports$2O); + exports$2O.Buffer = SafeBuffer; + } + + function SafeBuffer(arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length); + } + + SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer + + copyProps(Buffer, SafeBuffer); + + SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === "number") { + throw new TypeError("Argument must not be a number"); + } + + return Buffer(arg, encodingOrOffset, length); + }; + + SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + var buf = Buffer(size); + + if (fill !== undefined) { + if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } + } else { + buf.fill(0); + } + + return buf; + }; + + SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return Buffer(size); + }; + + SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return buffer$1.SlowBuffer(size); + }; + + return exports$2O; +} + +var exports$2N = {}, + _dewExec$2M = false; +function dew$2M() { + if (_dewExec$2M) return exports$2N; + _dewExec$2M = true; + + var Buffer = dew$2N().Buffer; + + var Transform = dew$3K().Transform; + + var inherits = dew$f$4(); + + function throwIfNotStringOrBuffer(val, prefix) { + if (!Buffer.isBuffer(val) && typeof val !== "string") { + throw new TypeError(prefix + " must be a string or a buffer"); + } + } + + function HashBase(blockSize) { + Transform.call(this); + this._block = Buffer.allocUnsafe(blockSize); + this._blockSize = blockSize; + this._blockOffset = 0; + this._length = [0, 0, 0, 0]; + this._finalized = false; + } + + inherits(HashBase, Transform); + + HashBase.prototype._transform = function (chunk, encoding, callback) { + var error = null; + + try { + this.update(chunk, encoding); + } catch (err) { + error = err; + } + + callback(error); + }; + + HashBase.prototype._flush = function (callback) { + var error = null; + + try { + this.push(this.digest()); + } catch (err) { + error = err; + } + + callback(error); + }; + + HashBase.prototype.update = function (data, encoding) { + throwIfNotStringOrBuffer(data, "Data"); + if (this._finalized) throw new Error("Digest already called"); + if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data + + var block = this._block; + var offset = 0; + + while (this._blockOffset + data.length - offset >= this._blockSize) { + for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]; + + this._update(); + + this._blockOffset = 0; + } + + while (offset < data.length) block[this._blockOffset++] = data[offset++]; // update length + + + for (var j = 0, carry = data.length * 8; carry > 0; ++j) { + this._length[j] += carry; + carry = this._length[j] / 4294967296 | 0; + if (carry > 0) this._length[j] -= 4294967296 * carry; + } + + return this; + }; + + HashBase.prototype._update = function () { + throw new Error("_update is not implemented"); + }; + + HashBase.prototype.digest = function (encoding) { + if (this._finalized) throw new Error("Digest already called"); + this._finalized = true; + + var digest = this._digest(); + + if (encoding !== undefined) digest = digest.toString(encoding); // reset state + + this._block.fill(0); + + this._blockOffset = 0; + + for (var i = 0; i < 4; ++i) this._length[i] = 0; + + return digest; + }; + + HashBase.prototype._digest = function () { + throw new Error("_digest is not implemented"); + }; + + exports$2N = HashBase; + return exports$2N; +} + +var exports$2M = {}, + _dewExec$2L = false; +function dew$2L() { + if (_dewExec$2L) return exports$2M; + _dewExec$2L = true; + + var inherits = dew$f$4(); + + var HashBase = dew$2M(); + + var Buffer = dew$2P().Buffer; + + var ARRAY16 = new Array(16); + + function MD5() { + HashBase.call(this, 64); // state + + this._a = 1732584193; + this._b = 4023233417; + this._c = 2562383102; + this._d = 271733878; + } + + inherits(MD5, HashBase); + + MD5.prototype._update = function () { + var M = ARRAY16; + + for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4); + + var a = this._a; + var b = this._b; + var c = this._c; + var d = this._d; + a = fnF(a, b, c, d, M[0], 3614090360, 7); + d = fnF(d, a, b, c, M[1], 3905402710, 12); + c = fnF(c, d, a, b, M[2], 606105819, 17); + b = fnF(b, c, d, a, M[3], 3250441966, 22); + a = fnF(a, b, c, d, M[4], 4118548399, 7); + d = fnF(d, a, b, c, M[5], 1200080426, 12); + c = fnF(c, d, a, b, M[6], 2821735955, 17); + b = fnF(b, c, d, a, M[7], 4249261313, 22); + a = fnF(a, b, c, d, M[8], 1770035416, 7); + d = fnF(d, a, b, c, M[9], 2336552879, 12); + c = fnF(c, d, a, b, M[10], 4294925233, 17); + b = fnF(b, c, d, a, M[11], 2304563134, 22); + a = fnF(a, b, c, d, M[12], 1804603682, 7); + d = fnF(d, a, b, c, M[13], 4254626195, 12); + c = fnF(c, d, a, b, M[14], 2792965006, 17); + b = fnF(b, c, d, a, M[15], 1236535329, 22); + a = fnG(a, b, c, d, M[1], 4129170786, 5); + d = fnG(d, a, b, c, M[6], 3225465664, 9); + c = fnG(c, d, a, b, M[11], 643717713, 14); + b = fnG(b, c, d, a, M[0], 3921069994, 20); + a = fnG(a, b, c, d, M[5], 3593408605, 5); + d = fnG(d, a, b, c, M[10], 38016083, 9); + c = fnG(c, d, a, b, M[15], 3634488961, 14); + b = fnG(b, c, d, a, M[4], 3889429448, 20); + a = fnG(a, b, c, d, M[9], 568446438, 5); + d = fnG(d, a, b, c, M[14], 3275163606, 9); + c = fnG(c, d, a, b, M[3], 4107603335, 14); + b = fnG(b, c, d, a, M[8], 1163531501, 20); + a = fnG(a, b, c, d, M[13], 2850285829, 5); + d = fnG(d, a, b, c, M[2], 4243563512, 9); + c = fnG(c, d, a, b, M[7], 1735328473, 14); + b = fnG(b, c, d, a, M[12], 2368359562, 20); + a = fnH(a, b, c, d, M[5], 4294588738, 4); + d = fnH(d, a, b, c, M[8], 2272392833, 11); + c = fnH(c, d, a, b, M[11], 1839030562, 16); + b = fnH(b, c, d, a, M[14], 4259657740, 23); + a = fnH(a, b, c, d, M[1], 2763975236, 4); + d = fnH(d, a, b, c, M[4], 1272893353, 11); + c = fnH(c, d, a, b, M[7], 4139469664, 16); + b = fnH(b, c, d, a, M[10], 3200236656, 23); + a = fnH(a, b, c, d, M[13], 681279174, 4); + d = fnH(d, a, b, c, M[0], 3936430074, 11); + c = fnH(c, d, a, b, M[3], 3572445317, 16); + b = fnH(b, c, d, a, M[6], 76029189, 23); + a = fnH(a, b, c, d, M[9], 3654602809, 4); + d = fnH(d, a, b, c, M[12], 3873151461, 11); + c = fnH(c, d, a, b, M[15], 530742520, 16); + b = fnH(b, c, d, a, M[2], 3299628645, 23); + a = fnI(a, b, c, d, M[0], 4096336452, 6); + d = fnI(d, a, b, c, M[7], 1126891415, 10); + c = fnI(c, d, a, b, M[14], 2878612391, 15); + b = fnI(b, c, d, a, M[5], 4237533241, 21); + a = fnI(a, b, c, d, M[12], 1700485571, 6); + d = fnI(d, a, b, c, M[3], 2399980690, 10); + c = fnI(c, d, a, b, M[10], 4293915773, 15); + b = fnI(b, c, d, a, M[1], 2240044497, 21); + a = fnI(a, b, c, d, M[8], 1873313359, 6); + d = fnI(d, a, b, c, M[15], 4264355552, 10); + c = fnI(c, d, a, b, M[6], 2734768916, 15); + b = fnI(b, c, d, a, M[13], 1309151649, 21); + a = fnI(a, b, c, d, M[4], 4149444226, 6); + d = fnI(d, a, b, c, M[11], 3174756917, 10); + c = fnI(c, d, a, b, M[2], 718787259, 15); + b = fnI(b, c, d, a, M[9], 3951481745, 21); + this._a = this._a + a | 0; + this._b = this._b + b | 0; + this._c = this._c + c | 0; + this._d = this._d + d | 0; + }; + + MD5.prototype._digest = function () { + // create padding and handle blocks + this._block[this._blockOffset++] = 128; + + if (this._blockOffset > 56) { + this._block.fill(0, this._blockOffset, 64); + + this._update(); + + this._blockOffset = 0; + } + + this._block.fill(0, this._blockOffset, 56); + + this._block.writeUInt32LE(this._length[0], 56); + + this._block.writeUInt32LE(this._length[1], 60); + + this._update(); // produce result + + + var buffer = Buffer.allocUnsafe(16); + buffer.writeInt32LE(this._a, 0); + buffer.writeInt32LE(this._b, 4); + buffer.writeInt32LE(this._c, 8); + buffer.writeInt32LE(this._d, 12); + return buffer; + }; + + function rotl(x, n) { + return x << n | x >>> 32 - n; + } + + function fnF(a, b, c, d, m, k, s) { + return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0; + } + + function fnG(a, b, c, d, m, k, s) { + return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0; + } + + function fnH(a, b, c, d, m, k, s) { + return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0; + } + + function fnI(a, b, c, d, m, k, s) { + return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0; + } + + exports$2M = MD5; + return exports$2M; +} + +var exports$2L = {}, + _dewExec$2K = false; +function dew$2K() { + if (_dewExec$2K) return exports$2L; + _dewExec$2K = true; + var Buffer = buffer.Buffer; + + var inherits = dew$f$4(); + + var HashBase = dew$2M(); + + var ARRAY16 = new Array(16); + var zl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]; + var zr = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; + var sl = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]; + var sr = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; + var hl = [0, 1518500249, 1859775393, 2400959708, 2840853838]; + var hr = [1352829926, 1548603684, 1836072691, 2053994217, 0]; + + function RIPEMD160() { + HashBase.call(this, 64); // state + + this._a = 1732584193; + this._b = 4023233417; + this._c = 2562383102; + this._d = 271733878; + this._e = 3285377520; + } + + inherits(RIPEMD160, HashBase); + + RIPEMD160.prototype._update = function () { + var words = ARRAY16; + + for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4); + + var al = this._a | 0; + var bl = this._b | 0; + var cl = this._c | 0; + var dl = this._d | 0; + var el = this._e | 0; + var ar = this._a | 0; + var br = this._b | 0; + var cr = this._c | 0; + var dr = this._d | 0; + var er = this._e | 0; // computation + + for (var i = 0; i < 80; i += 1) { + var tl; + var tr; + + if (i < 16) { + tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]); + tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]); + } else if (i < 32) { + tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]); + tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]); + } else if (i < 48) { + tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]); + tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]); + } else if (i < 64) { + tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]); + tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]); + } else { + // if (i<80) { + tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]); + tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]); + } + + al = el; + el = dl; + dl = rotl(cl, 10); + cl = bl; + bl = tl; + ar = er; + er = dr; + dr = rotl(cr, 10); + cr = br; + br = tr; + } // update state + + + var t = this._b + cl + dr | 0; + this._b = this._c + dl + er | 0; + this._c = this._d + el + ar | 0; + this._d = this._e + al + br | 0; + this._e = this._a + bl + cr | 0; + this._a = t; + }; + + RIPEMD160.prototype._digest = function () { + // create padding and handle blocks + this._block[this._blockOffset++] = 128; + + if (this._blockOffset > 56) { + this._block.fill(0, this._blockOffset, 64); + + this._update(); + + this._blockOffset = 0; + } + + this._block.fill(0, this._blockOffset, 56); + + this._block.writeUInt32LE(this._length[0], 56); + + this._block.writeUInt32LE(this._length[1], 60); + + this._update(); // produce result + + + var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20); + buffer.writeInt32LE(this._a, 0); + buffer.writeInt32LE(this._b, 4); + buffer.writeInt32LE(this._c, 8); + buffer.writeInt32LE(this._d, 12); + buffer.writeInt32LE(this._e, 16); + return buffer; + }; + + function rotl(x, n) { + return x << n | x >>> 32 - n; + } + + function fn1(a, b, c, d, e, m, k, s) { + return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0; + } + + function fn2(a, b, c, d, e, m, k, s) { + return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0; + } + + function fn3(a, b, c, d, e, m, k, s) { + return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0; + } + + function fn4(a, b, c, d, e, m, k, s) { + return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0; + } + + function fn5(a, b, c, d, e, m, k, s) { + return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0; + } + + exports$2L = RIPEMD160; + return exports$2L; +} + +var exports$2K = {}, + _dewExec$2J = false; + +var _global$T = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2J() { + if (_dewExec$2J) return exports$2K; + _dewExec$2J = true; + + var Buffer = dew$2P().Buffer; // prototype class for hash functions + + + function Hash(blockSize, finalSize) { + (this || _global$T)._block = Buffer.alloc(blockSize); + (this || _global$T)._finalSize = finalSize; + (this || _global$T)._blockSize = blockSize; + (this || _global$T)._len = 0; + } + + Hash.prototype.update = function (data, enc) { + if (typeof data === "string") { + enc = enc || "utf8"; + data = Buffer.from(data, enc); + } + + var block = (this || _global$T)._block; + var blockSize = (this || _global$T)._blockSize; + var length = data.length; + var accum = (this || _global$T)._len; + + for (var offset = 0; offset < length;) { + var assigned = accum % blockSize; + var remainder = Math.min(length - offset, blockSize - assigned); + + for (var i = 0; i < remainder; i++) { + block[assigned + i] = data[offset + i]; + } + + accum += remainder; + offset += remainder; + + if (accum % blockSize === 0) { + this._update(block); + } + } + + (this || _global$T)._len += length; + return this || _global$T; + }; + + Hash.prototype.digest = function (enc) { + var rem = (this || _global$T)._len % (this || _global$T)._blockSize; + (this || _global$T)._block[rem] = 128; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest + // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize + + (this || _global$T)._block.fill(0, rem + 1); + + if (rem >= (this || _global$T)._finalSize) { + this._update((this || _global$T)._block); + + (this || _global$T)._block.fill(0); + } + + var bits = (this || _global$T)._len * 8; // uint32 + + if (bits <= 4294967295) { + (this || _global$T)._block.writeUInt32BE(bits, (this || _global$T)._blockSize - 4); // uint64 + + } else { + var lowBits = (bits & 4294967295) >>> 0; + var highBits = (bits - lowBits) / 4294967296; + + (this || _global$T)._block.writeUInt32BE(highBits, (this || _global$T)._blockSize - 8); + + (this || _global$T)._block.writeUInt32BE(lowBits, (this || _global$T)._blockSize - 4); + } + + this._update((this || _global$T)._block); + + var hash = this._hash(); + + return enc ? hash.toString(enc) : hash; + }; + + Hash.prototype._update = function () { + throw new Error("_update must be implemented by subclass"); + }; + + exports$2K = Hash; + return exports$2K; +} + +var exports$2J = {}, + _dewExec$2I = false; + +var _global$S = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2I() { + if (_dewExec$2I) return exports$2J; + _dewExec$2I = true; + + /* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined + * in FIPS PUB 180-1 + * This source code is derived from sha1.js of the same repository. + * The difference between SHA-0 and SHA-1 is just a bitwise rotate left + * operation was added. + */ + var inherits = dew$f$4(); + + var Hash = dew$2J(); + + var Buffer = dew$2P().Buffer; + + var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; + var W = new Array(80); + + function Sha() { + this.init(); + (this || _global$S)._w = W; + Hash.call(this || _global$S, 64, 56); + } + + inherits(Sha, Hash); + + Sha.prototype.init = function () { + (this || _global$S)._a = 1732584193; + (this || _global$S)._b = 4023233417; + (this || _global$S)._c = 2562383102; + (this || _global$S)._d = 271733878; + (this || _global$S)._e = 3285377520; + return this || _global$S; + }; + + function rotl5(num) { + return num << 5 | num >>> 27; + } + + function rotl30(num) { + return num << 30 | num >>> 2; + } + + function ft(s, b, c, d) { + if (s === 0) return b & c | ~b & d; + if (s === 2) return b & c | b & d | c & d; + return b ^ c ^ d; + } + + Sha.prototype._update = function (M) { + var W = (this || _global$S)._w; + var a = (this || _global$S)._a | 0; + var b = (this || _global$S)._b | 0; + var c = (this || _global$S)._c | 0; + var d = (this || _global$S)._d | 0; + var e = (this || _global$S)._e | 0; + + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + + for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + + for (var j = 0; j < 80; ++j) { + var s = ~~(j / 20); + var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; + e = d; + d = c; + c = rotl30(b); + b = a; + a = t; + } + + (this || _global$S)._a = a + (this || _global$S)._a | 0; + (this || _global$S)._b = b + (this || _global$S)._b | 0; + (this || _global$S)._c = c + (this || _global$S)._c | 0; + (this || _global$S)._d = d + (this || _global$S)._d | 0; + (this || _global$S)._e = e + (this || _global$S)._e | 0; + }; + + Sha.prototype._hash = function () { + var H = Buffer.allocUnsafe(20); + H.writeInt32BE((this || _global$S)._a | 0, 0); + H.writeInt32BE((this || _global$S)._b | 0, 4); + H.writeInt32BE((this || _global$S)._c | 0, 8); + H.writeInt32BE((this || _global$S)._d | 0, 12); + H.writeInt32BE((this || _global$S)._e | 0, 16); + return H; + }; + + exports$2J = Sha; + return exports$2J; +} + +var exports$2I = {}, + _dewExec$2H = false; + +var _global$R = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2H() { + if (_dewExec$2H) return exports$2I; + _dewExec$2H = true; + + /* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Version 2.1a Copyright Paul Johnston 2000 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for details. + */ + var inherits = dew$f$4(); + + var Hash = dew$2J(); + + var Buffer = dew$2P().Buffer; + + var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; + var W = new Array(80); + + function Sha1() { + this.init(); + (this || _global$R)._w = W; + Hash.call(this || _global$R, 64, 56); + } + + inherits(Sha1, Hash); + + Sha1.prototype.init = function () { + (this || _global$R)._a = 1732584193; + (this || _global$R)._b = 4023233417; + (this || _global$R)._c = 2562383102; + (this || _global$R)._d = 271733878; + (this || _global$R)._e = 3285377520; + return this || _global$R; + }; + + function rotl1(num) { + return num << 1 | num >>> 31; + } + + function rotl5(num) { + return num << 5 | num >>> 27; + } + + function rotl30(num) { + return num << 30 | num >>> 2; + } + + function ft(s, b, c, d) { + if (s === 0) return b & c | ~b & d; + if (s === 2) return b & c | b & d | c & d; + return b ^ c ^ d; + } + + Sha1.prototype._update = function (M) { + var W = (this || _global$R)._w; + var a = (this || _global$R)._a | 0; + var b = (this || _global$R)._b | 0; + var c = (this || _global$R)._c | 0; + var d = (this || _global$R)._d | 0; + var e = (this || _global$R)._e | 0; + + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + + for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]); + + for (var j = 0; j < 80; ++j) { + var s = ~~(j / 20); + var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; + e = d; + d = c; + c = rotl30(b); + b = a; + a = t; + } + + (this || _global$R)._a = a + (this || _global$R)._a | 0; + (this || _global$R)._b = b + (this || _global$R)._b | 0; + (this || _global$R)._c = c + (this || _global$R)._c | 0; + (this || _global$R)._d = d + (this || _global$R)._d | 0; + (this || _global$R)._e = e + (this || _global$R)._e | 0; + }; + + Sha1.prototype._hash = function () { + var H = Buffer.allocUnsafe(20); + H.writeInt32BE((this || _global$R)._a | 0, 0); + H.writeInt32BE((this || _global$R)._b | 0, 4); + H.writeInt32BE((this || _global$R)._c | 0, 8); + H.writeInt32BE((this || _global$R)._d | 0, 12); + H.writeInt32BE((this || _global$R)._e | 0, 16); + return H; + }; + + exports$2I = Sha1; + return exports$2I; +} + +var exports$2H = {}, + _dewExec$2G = false; + +var _global$Q = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2G() { + if (_dewExec$2G) return exports$2H; + _dewExec$2G = true; + + /** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ + var inherits = dew$f$4(); + + var Hash = dew$2J(); + + var Buffer = dew$2P().Buffer; + + var K = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298]; + var W = new Array(64); + + function Sha256() { + this.init(); + (this || _global$Q)._w = W; // new Array(64) + + Hash.call(this || _global$Q, 64, 56); + } + + inherits(Sha256, Hash); + + Sha256.prototype.init = function () { + (this || _global$Q)._a = 1779033703; + (this || _global$Q)._b = 3144134277; + (this || _global$Q)._c = 1013904242; + (this || _global$Q)._d = 2773480762; + (this || _global$Q)._e = 1359893119; + (this || _global$Q)._f = 2600822924; + (this || _global$Q)._g = 528734635; + (this || _global$Q)._h = 1541459225; + return this || _global$Q; + }; + + function ch(x, y, z) { + return z ^ x & (y ^ z); + } + + function maj(x, y, z) { + return x & y | z & (x | y); + } + + function sigma0(x) { + return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10); + } + + function sigma1(x) { + return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7); + } + + function gamma0(x) { + return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3; + } + + function gamma1(x) { + return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10; + } + + Sha256.prototype._update = function (M) { + var W = (this || _global$Q)._w; + var a = (this || _global$Q)._a | 0; + var b = (this || _global$Q)._b | 0; + var c = (this || _global$Q)._c | 0; + var d = (this || _global$Q)._d | 0; + var e = (this || _global$Q)._e | 0; + var f = (this || _global$Q)._f | 0; + var g = (this || _global$Q)._g | 0; + var h = (this || _global$Q)._h | 0; + + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + + for (; i < 64; ++i) W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0; + + for (var j = 0; j < 64; ++j) { + var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0; + var T2 = sigma0(a) + maj(a, b, c) | 0; + h = g; + g = f; + f = e; + e = d + T1 | 0; + d = c; + c = b; + b = a; + a = T1 + T2 | 0; + } + + (this || _global$Q)._a = a + (this || _global$Q)._a | 0; + (this || _global$Q)._b = b + (this || _global$Q)._b | 0; + (this || _global$Q)._c = c + (this || _global$Q)._c | 0; + (this || _global$Q)._d = d + (this || _global$Q)._d | 0; + (this || _global$Q)._e = e + (this || _global$Q)._e | 0; + (this || _global$Q)._f = f + (this || _global$Q)._f | 0; + (this || _global$Q)._g = g + (this || _global$Q)._g | 0; + (this || _global$Q)._h = h + (this || _global$Q)._h | 0; + }; + + Sha256.prototype._hash = function () { + var H = Buffer.allocUnsafe(32); + H.writeInt32BE((this || _global$Q)._a, 0); + H.writeInt32BE((this || _global$Q)._b, 4); + H.writeInt32BE((this || _global$Q)._c, 8); + H.writeInt32BE((this || _global$Q)._d, 12); + H.writeInt32BE((this || _global$Q)._e, 16); + H.writeInt32BE((this || _global$Q)._f, 20); + H.writeInt32BE((this || _global$Q)._g, 24); + H.writeInt32BE((this || _global$Q)._h, 28); + return H; + }; + + exports$2H = Sha256; + return exports$2H; +} + +var exports$2G = {}, + _dewExec$2F = false; + +var _global$P = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2F() { + if (_dewExec$2F) return exports$2G; + _dewExec$2F = true; + + /** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ + var inherits = dew$f$4(); + + var Sha256 = dew$2G(); + + var Hash = dew$2J(); + + var Buffer = dew$2P().Buffer; + + var W = new Array(64); + + function Sha224() { + this.init(); + (this || _global$P)._w = W; // new Array(64) + + Hash.call(this || _global$P, 64, 56); + } + + inherits(Sha224, Sha256); + + Sha224.prototype.init = function () { + (this || _global$P)._a = 3238371032; + (this || _global$P)._b = 914150663; + (this || _global$P)._c = 812702999; + (this || _global$P)._d = 4144912697; + (this || _global$P)._e = 4290775857; + (this || _global$P)._f = 1750603025; + (this || _global$P)._g = 1694076839; + (this || _global$P)._h = 3204075428; + return this || _global$P; + }; + + Sha224.prototype._hash = function () { + var H = Buffer.allocUnsafe(28); + H.writeInt32BE((this || _global$P)._a, 0); + H.writeInt32BE((this || _global$P)._b, 4); + H.writeInt32BE((this || _global$P)._c, 8); + H.writeInt32BE((this || _global$P)._d, 12); + H.writeInt32BE((this || _global$P)._e, 16); + H.writeInt32BE((this || _global$P)._f, 20); + H.writeInt32BE((this || _global$P)._g, 24); + return H; + }; + + exports$2G = Sha224; + return exports$2G; +} + +var exports$2F = {}, + _dewExec$2E = false; + +var _global$O = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2E() { + if (_dewExec$2E) return exports$2F; + _dewExec$2E = true; + + var inherits = dew$f$4(); + + var Hash = dew$2J(); + + var Buffer = dew$2P().Buffer; + + var K = [1116352408, 3609767458, 1899447441, 602891725, 3049323471, 3964484399, 3921009573, 2173295548, 961987163, 4081628472, 1508970993, 3053834265, 2453635748, 2937671579, 2870763221, 3664609560, 3624381080, 2734883394, 310598401, 1164996542, 607225278, 1323610764, 1426881987, 3590304994, 1925078388, 4068182383, 2162078206, 991336113, 2614888103, 633803317, 3248222580, 3479774868, 3835390401, 2666613458, 4022224774, 944711139, 264347078, 2341262773, 604807628, 2007800933, 770255983, 1495990901, 1249150122, 1856431235, 1555081692, 3175218132, 1996064986, 2198950837, 2554220882, 3999719339, 2821834349, 766784016, 2952996808, 2566594879, 3210313671, 3203337956, 3336571891, 1034457026, 3584528711, 2466948901, 113926993, 3758326383, 338241895, 168717936, 666307205, 1188179964, 773529912, 1546045734, 1294757372, 1522805485, 1396182291, 2643833823, 1695183700, 2343527390, 1986661051, 1014477480, 2177026350, 1206759142, 2456956037, 344077627, 2730485921, 1290863460, 2820302411, 3158454273, 3259730800, 3505952657, 3345764771, 106217008, 3516065817, 3606008344, 3600352804, 1432725776, 4094571909, 1467031594, 275423344, 851169720, 430227734, 3100823752, 506948616, 1363258195, 659060556, 3750685593, 883997877, 3785050280, 958139571, 3318307427, 1322822218, 3812723403, 1537002063, 2003034995, 1747873779, 3602036899, 1955562222, 1575990012, 2024104815, 1125592928, 2227730452, 2716904306, 2361852424, 442776044, 2428436474, 593698344, 2756734187, 3733110249, 3204031479, 2999351573, 3329325298, 3815920427, 3391569614, 3928383900, 3515267271, 566280711, 3940187606, 3454069534, 4118630271, 4000239992, 116418474, 1914138554, 174292421, 2731055270, 289380356, 3203993006, 460393269, 320620315, 685471733, 587496836, 852142971, 1086792851, 1017036298, 365543100, 1126000580, 2618297676, 1288033470, 3409855158, 1501505948, 4234509866, 1607167915, 987167468, 1816402316, 1246189591]; + var W = new Array(160); + + function Sha512() { + this.init(); + (this || _global$O)._w = W; + Hash.call(this || _global$O, 128, 112); + } + + inherits(Sha512, Hash); + + Sha512.prototype.init = function () { + (this || _global$O)._ah = 1779033703; + (this || _global$O)._bh = 3144134277; + (this || _global$O)._ch = 1013904242; + (this || _global$O)._dh = 2773480762; + (this || _global$O)._eh = 1359893119; + (this || _global$O)._fh = 2600822924; + (this || _global$O)._gh = 528734635; + (this || _global$O)._hh = 1541459225; + (this || _global$O)._al = 4089235720; + (this || _global$O)._bl = 2227873595; + (this || _global$O)._cl = 4271175723; + (this || _global$O)._dl = 1595750129; + (this || _global$O)._el = 2917565137; + (this || _global$O)._fl = 725511199; + (this || _global$O)._gl = 4215389547; + (this || _global$O)._hl = 327033209; + return this || _global$O; + }; + + function Ch(x, y, z) { + return z ^ x & (y ^ z); + } + + function maj(x, y, z) { + return x & y | z & (x | y); + } + + function sigma0(x, xl) { + return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25); + } + + function sigma1(x, xl) { + return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23); + } + + function Gamma0(x, xl) { + return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7; + } + + function Gamma0l(x, xl) { + return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25); + } + + function Gamma1(x, xl) { + return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6; + } + + function Gamma1l(x, xl) { + return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26); + } + + function getCarry(a, b) { + return a >>> 0 < b >>> 0 ? 1 : 0; + } + + Sha512.prototype._update = function (M) { + var W = (this || _global$O)._w; + var ah = (this || _global$O)._ah | 0; + var bh = (this || _global$O)._bh | 0; + var ch = (this || _global$O)._ch | 0; + var dh = (this || _global$O)._dh | 0; + var eh = (this || _global$O)._eh | 0; + var fh = (this || _global$O)._fh | 0; + var gh = (this || _global$O)._gh | 0; + var hh = (this || _global$O)._hh | 0; + var al = (this || _global$O)._al | 0; + var bl = (this || _global$O)._bl | 0; + var cl = (this || _global$O)._cl | 0; + var dl = (this || _global$O)._dl | 0; + var el = (this || _global$O)._el | 0; + var fl = (this || _global$O)._fl | 0; + var gl = (this || _global$O)._gl | 0; + var hl = (this || _global$O)._hl | 0; + + for (var i = 0; i < 32; i += 2) { + W[i] = M.readInt32BE(i * 4); + W[i + 1] = M.readInt32BE(i * 4 + 4); + } + + for (; i < 160; i += 2) { + var xh = W[i - 15 * 2]; + var xl = W[i - 15 * 2 + 1]; + var gamma0 = Gamma0(xh, xl); + var gamma0l = Gamma0l(xl, xh); + xh = W[i - 2 * 2]; + xl = W[i - 2 * 2 + 1]; + var gamma1 = Gamma1(xh, xl); + var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + + var Wi7h = W[i - 7 * 2]; + var Wi7l = W[i - 7 * 2 + 1]; + var Wi16h = W[i - 16 * 2]; + var Wi16l = W[i - 16 * 2 + 1]; + var Wil = gamma0l + Wi7l | 0; + var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0; + Wil = Wil + gamma1l | 0; + Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0; + Wil = Wil + Wi16l | 0; + Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0; + W[i] = Wih; + W[i + 1] = Wil; + } + + for (var j = 0; j < 160; j += 2) { + Wih = W[j]; + Wil = W[j + 1]; + var majh = maj(ah, bh, ch); + var majl = maj(al, bl, cl); + var sigma0h = sigma0(ah, al); + var sigma0l = sigma0(al, ah); + var sigma1h = sigma1(eh, el); + var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j] + + var Kih = K[j]; + var Kil = K[j + 1]; + var chh = Ch(eh, fh, gh); + var chl = Ch(el, fl, gl); + var t1l = hl + sigma1l | 0; + var t1h = hh + sigma1h + getCarry(t1l, hl) | 0; + t1l = t1l + chl | 0; + t1h = t1h + chh + getCarry(t1l, chl) | 0; + t1l = t1l + Kil | 0; + t1h = t1h + Kih + getCarry(t1l, Kil) | 0; + t1l = t1l + Wil | 0; + t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj + + var t2l = sigma0l + majl | 0; + var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0; + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = dl + t1l | 0; + eh = dh + t1h + getCarry(el, dl) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = t1l + t2l | 0; + ah = t1h + t2h + getCarry(al, t1l) | 0; + } + + (this || _global$O)._al = (this || _global$O)._al + al | 0; + (this || _global$O)._bl = (this || _global$O)._bl + bl | 0; + (this || _global$O)._cl = (this || _global$O)._cl + cl | 0; + (this || _global$O)._dl = (this || _global$O)._dl + dl | 0; + (this || _global$O)._el = (this || _global$O)._el + el | 0; + (this || _global$O)._fl = (this || _global$O)._fl + fl | 0; + (this || _global$O)._gl = (this || _global$O)._gl + gl | 0; + (this || _global$O)._hl = (this || _global$O)._hl + hl | 0; + (this || _global$O)._ah = (this || _global$O)._ah + ah + getCarry((this || _global$O)._al, al) | 0; + (this || _global$O)._bh = (this || _global$O)._bh + bh + getCarry((this || _global$O)._bl, bl) | 0; + (this || _global$O)._ch = (this || _global$O)._ch + ch + getCarry((this || _global$O)._cl, cl) | 0; + (this || _global$O)._dh = (this || _global$O)._dh + dh + getCarry((this || _global$O)._dl, dl) | 0; + (this || _global$O)._eh = (this || _global$O)._eh + eh + getCarry((this || _global$O)._el, el) | 0; + (this || _global$O)._fh = (this || _global$O)._fh + fh + getCarry((this || _global$O)._fl, fl) | 0; + (this || _global$O)._gh = (this || _global$O)._gh + gh + getCarry((this || _global$O)._gl, gl) | 0; + (this || _global$O)._hh = (this || _global$O)._hh + hh + getCarry((this || _global$O)._hl, hl) | 0; + }; + + Sha512.prototype._hash = function () { + var H = Buffer.allocUnsafe(64); + + function writeInt64BE(h, l, offset) { + H.writeInt32BE(h, offset); + H.writeInt32BE(l, offset + 4); + } + + writeInt64BE((this || _global$O)._ah, (this || _global$O)._al, 0); + writeInt64BE((this || _global$O)._bh, (this || _global$O)._bl, 8); + writeInt64BE((this || _global$O)._ch, (this || _global$O)._cl, 16); + writeInt64BE((this || _global$O)._dh, (this || _global$O)._dl, 24); + writeInt64BE((this || _global$O)._eh, (this || _global$O)._el, 32); + writeInt64BE((this || _global$O)._fh, (this || _global$O)._fl, 40); + writeInt64BE((this || _global$O)._gh, (this || _global$O)._gl, 48); + writeInt64BE((this || _global$O)._hh, (this || _global$O)._hl, 56); + return H; + }; + + exports$2F = Sha512; + return exports$2F; +} + +var exports$2E = {}, + _dewExec$2D = false; + +var _global$N = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2D() { + if (_dewExec$2D) return exports$2E; + _dewExec$2D = true; + + var inherits = dew$f$4(); + + var SHA512 = dew$2E(); + + var Hash = dew$2J(); + + var Buffer = dew$2P().Buffer; + + var W = new Array(160); + + function Sha384() { + this.init(); + (this || _global$N)._w = W; + Hash.call(this || _global$N, 128, 112); + } + + inherits(Sha384, SHA512); + + Sha384.prototype.init = function () { + (this || _global$N)._ah = 3418070365; + (this || _global$N)._bh = 1654270250; + (this || _global$N)._ch = 2438529370; + (this || _global$N)._dh = 355462360; + (this || _global$N)._eh = 1731405415; + (this || _global$N)._fh = 2394180231; + (this || _global$N)._gh = 3675008525; + (this || _global$N)._hh = 1203062813; + (this || _global$N)._al = 3238371032; + (this || _global$N)._bl = 914150663; + (this || _global$N)._cl = 812702999; + (this || _global$N)._dl = 4144912697; + (this || _global$N)._el = 4290775857; + (this || _global$N)._fl = 1750603025; + (this || _global$N)._gl = 1694076839; + (this || _global$N)._hl = 3204075428; + return this || _global$N; + }; + + Sha384.prototype._hash = function () { + var H = Buffer.allocUnsafe(48); + + function writeInt64BE(h, l, offset) { + H.writeInt32BE(h, offset); + H.writeInt32BE(l, offset + 4); + } + + writeInt64BE((this || _global$N)._ah, (this || _global$N)._al, 0); + writeInt64BE((this || _global$N)._bh, (this || _global$N)._bl, 8); + writeInt64BE((this || _global$N)._ch, (this || _global$N)._cl, 16); + writeInt64BE((this || _global$N)._dh, (this || _global$N)._dl, 24); + writeInt64BE((this || _global$N)._eh, (this || _global$N)._el, 32); + writeInt64BE((this || _global$N)._fh, (this || _global$N)._fl, 40); + return H; + }; + + exports$2E = Sha384; + return exports$2E; +} + +var exports$2D = {}, + _dewExec$2C = false; +var module$b = { + exports: exports$2D +}; +function dew$2C() { + if (_dewExec$2C) return module$b.exports; + _dewExec$2C = true; + + var exports = module$b.exports = function SHA(algorithm) { + algorithm = algorithm.toLowerCase(); + var Algorithm = exports[algorithm]; + if (!Algorithm) throw new Error(algorithm + " is not supported (we accept pull requests)"); + return new Algorithm(); + }; + + exports.sha = dew$2I(); + exports.sha1 = dew$2H(); + exports.sha224 = dew$2F(); + exports.sha256 = dew$2G(); + exports.sha384 = dew$2D(); + exports.sha512 = dew$2E(); + return module$b.exports; +} + +var exports$f$2 = {}, + _dewExec$f$2 = false; +function dew$f$2() { + if (_dewExec$f$2) return exports$f$2; + _dewExec$f$2 = true; + + if (typeof Object.create === "function") { + // implementation from standard node.js 'util' module + exports$f$2 = function inherits(ctor, superCtor) { + if (superCtor) { + ctor.super_ = superCtor; + ctor.prototype = Object.create(superCtor.prototype, { + constructor: { + value: ctor, + enumerable: false, + writable: true, + configurable: true + } + }); + } + }; + } else { + // old school shim for old browsers + exports$f$2 = function inherits(ctor, superCtor) { + if (superCtor) { + ctor.super_ = superCtor; + + var TempCtor = function () {}; + + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } + }; + } + + return exports$f$2; +} + +var exports$e$2 = {}, + _dewExec$e$2 = false; +function dew$e$2() { + if (_dewExec$e$2) return exports$e$2; + _dewExec$e$2 = true; + exports$e$2 = y$o.EventEmitter; + return exports$e$2; +} + +var exports$d$2 = {}, + _dewExec$d$2 = false; +function dew$d$2() { + if (_dewExec$d$2) return exports$d$2; + _dewExec$d$2 = true; + + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + if (enumerableOnly) symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + }); + keys.push.apply(keys, symbols); + } + + return keys; + } + + function _objectSpread(target) { + for (var i = 1; i < arguments.length; i++) { + var source = arguments[i] != null ? arguments[i] : {}; + + if (i % 2) { + ownKeys(Object(source), true).forEach(function (key) { + _defineProperty(target, key, source[key]); + }); + } else if (Object.getOwnPropertyDescriptors) { + Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); + } else { + ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + } + + return target; + } + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, descriptor.key, descriptor); + } + } + + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + return Constructor; + } + + var _require = e$1$1$1, + Buffer = _require.Buffer; + var _require2 = X$5, + inspect = _require2.inspect; + var custom = inspect && inspect.custom || "inspect"; + + function copyBuffer(src, target, offset) { + Buffer.prototype.copy.call(src, target, offset); + } + + exports$d$2 = /*#__PURE__*/function () { + function BufferList() { + _classCallCheck(this, BufferList); + + this.head = null; + this.tail = null; + this.length = 0; + } + + _createClass(BufferList, [{ + key: "push", + value: function push(v) { + var entry = { + data: v, + next: null + }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + } + }, { + key: "unshift", + value: function unshift(v) { + var entry = { + data: v, + next: this.head + }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + } + }, { + key: "shift", + value: function shift() { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + } + }, { + key: "clear", + value: function clear() { + this.head = this.tail = null; + this.length = 0; + } + }, { + key: "join", + value: function join(s) { + if (this.length === 0) return ""; + var p = this.head; + var ret = "" + p.data; + + while (p = p.next) { + ret += s + p.data; + } + + return ret; + } + }, { + key: "concat", + value: function concat(n) { + if (this.length === 0) return Buffer.alloc(0); + var ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + + while (p) { + copyBuffer(p.data, ret, i); + i += p.data.length; + p = p.next; + } + + return ret; + } // Consumes a specified amount of bytes or characters from the buffered data. + + }, { + key: "consume", + value: function consume(n, hasStrings) { + var ret; + + if (n < this.head.data.length) { + // `slice` is the same for buffers and strings. + ret = this.head.data.slice(0, n); + this.head.data = this.head.data.slice(n); + } else if (n === this.head.data.length) { + // First chunk is a perfect match. + ret = this.shift(); + } else { + // Result spans more than one buffer. + ret = hasStrings ? this._getString(n) : this._getBuffer(n); + } + + return ret; + } + }, { + key: "first", + value: function first() { + return this.head.data; + } // Consumes a specified amount of characters from the buffered data. + + }, { + key: "_getString", + value: function _getString(n) { + var p = this.head; + var c = 1; + var ret = p.data; + n -= ret.length; + + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = str.slice(nb); + } + + break; + } + + ++c; + } + + this.length -= c; + return ret; + } // Consumes a specified amount of bytes from the buffered data. + + }, { + key: "_getBuffer", + value: function _getBuffer(n) { + var ret = Buffer.allocUnsafe(n); + var p = this.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = buf.slice(nb); + } + + break; + } + + ++c; + } + + this.length -= c; + return ret; + } // Make sure the linked list only shows the minimal necessary information. + + }, { + key: custom, + value: function value(_, options) { + return inspect(this, _objectSpread({}, options, { + // Only inspect one level. + depth: 0, + // It should not recurse. + customInspect: false + })); + } + }]); + + return BufferList; + }(); + + return exports$d$2; +} + +var exports$c$2 = {}, + _dewExec$c$2 = false; +function dew$c$2() { + if (_dewExec$c$2) return exports$c$2; + _dewExec$c$2 = true; + var process = T$9; + + // undocumented cb() API, needed for core, not for public API + function destroy(err, cb) { + var _this = this; + + var readableDestroyed = this._readableState && this._readableState.destroyed; + var writableDestroyed = this._writableState && this._writableState.destroyed; + + if (readableDestroyed || writableDestroyed) { + if (cb) { + cb(err); + } else if (err) { + if (!this._writableState) { + process.nextTick(emitErrorNT, this, err); + } else if (!this._writableState.errorEmitted) { + this._writableState.errorEmitted = true; + process.nextTick(emitErrorNT, this, err); + } + } + + return this; + } // we set destroyed to true before firing error callbacks in order + // to make it re-entrance safe in case destroy() is called within callbacks + + + if (this._readableState) { + this._readableState.destroyed = true; + } // if this is a duplex stream mark the writable part as destroyed as well + + + if (this._writableState) { + this._writableState.destroyed = true; + } + + this._destroy(err || null, function (err) { + if (!cb && err) { + if (!_this._writableState) { + process.nextTick(emitErrorAndCloseNT, _this, err); + } else if (!_this._writableState.errorEmitted) { + _this._writableState.errorEmitted = true; + process.nextTick(emitErrorAndCloseNT, _this, err); + } else { + process.nextTick(emitCloseNT, _this); + } + } else if (cb) { + process.nextTick(emitCloseNT, _this); + cb(err); + } else { + process.nextTick(emitCloseNT, _this); + } + }); + + return this; + } + + function emitErrorAndCloseNT(self, err) { + emitErrorNT(self, err); + emitCloseNT(self); + } + + function emitCloseNT(self) { + if (self._writableState && !self._writableState.emitClose) return; + if (self._readableState && !self._readableState.emitClose) return; + self.emit("close"); + } + + function undestroy() { + if (this._readableState) { + this._readableState.destroyed = false; + this._readableState.reading = false; + this._readableState.ended = false; + this._readableState.endEmitted = false; + } + + if (this._writableState) { + this._writableState.destroyed = false; + this._writableState.ended = false; + this._writableState.ending = false; + this._writableState.finalCalled = false; + this._writableState.prefinished = false; + this._writableState.finished = false; + this._writableState.errorEmitted = false; + } + } + + function emitErrorNT(self, err) { + self.emit("error", err); + } + + function errorOrDestroy(stream, err) { + // We have tests that rely on errors being emitted + // in the same tick, so changing this is semver major. + // For now when you opt-in to autoDestroy we allow + // the error to be emitted nextTick. In a future + // semver major update we should change the default to this. + var rState = stream._readableState; + var wState = stream._writableState; + if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit("error", err); + } + + exports$c$2 = { + destroy: destroy, + undestroy: undestroy, + errorOrDestroy: errorOrDestroy + }; + return exports$c$2; +} + +var exports$b$2 = {}, + _dewExec$b$2 = false; +function dew$b$2() { + if (_dewExec$b$2) return exports$b$2; + _dewExec$b$2 = true; + const codes = {}; + + function createErrorType(code, message, Base) { + if (!Base) { + Base = Error; + } + + function getMessage(arg1, arg2, arg3) { + if (typeof message === "string") { + return message; + } else { + return message(arg1, arg2, arg3); + } + } + + class NodeError extends Base { + constructor(arg1, arg2, arg3) { + super(getMessage(arg1, arg2, arg3)); + } + + } + + NodeError.prototype.name = Base.name; + NodeError.prototype.code = code; + codes[code] = NodeError; + } // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js + + + function oneOf(expected, thing) { + if (Array.isArray(expected)) { + const len = expected.length; + expected = expected.map(i => String(i)); + + if (len > 2) { + return `one of ${thing} ${expected.slice(0, len - 1).join(", ")}, or ` + expected[len - 1]; + } else if (len === 2) { + return `one of ${thing} ${expected[0]} or ${expected[1]}`; + } else { + return `of ${thing} ${expected[0]}`; + } + } else { + return `of ${thing} ${String(expected)}`; + } + } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith + + + function startsWith(str, search, pos) { + return str.substr(0 , search.length) === search; + } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith + + + function endsWith(str, search, this_len) { + if (this_len === undefined || this_len > str.length) { + this_len = str.length; + } + + return str.substring(this_len - search.length, this_len) === search; + } // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes + + + function includes(str, search, start) { + if (typeof start !== "number") { + start = 0; + } + + if (start + search.length > str.length) { + return false; + } else { + return str.indexOf(search, start) !== -1; + } + } + + createErrorType("ERR_INVALID_OPT_VALUE", function (name, value) { + return "The value \"" + value + "\" is invalid for option \"" + name + "\""; + }, TypeError); + createErrorType("ERR_INVALID_ARG_TYPE", function (name, expected, actual) { + // determiner: 'must be' or 'must not be' + let determiner; + + if (typeof expected === "string" && startsWith(expected, "not ")) { + determiner = "must not be"; + expected = expected.replace(/^not /, ""); + } else { + determiner = "must be"; + } + + let msg; + + if (endsWith(name, " argument")) { + // For cases like 'first argument' + msg = `The ${name} ${determiner} ${oneOf(expected, "type")}`; + } else { + const type = includes(name, ".") ? "property" : "argument"; + msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, "type")}`; + } + + msg += `. Received type ${typeof actual}`; + return msg; + }, TypeError); + createErrorType("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF"); + createErrorType("ERR_METHOD_NOT_IMPLEMENTED", function (name) { + return "The " + name + " method is not implemented"; + }); + createErrorType("ERR_STREAM_PREMATURE_CLOSE", "Premature close"); + createErrorType("ERR_STREAM_DESTROYED", function (name) { + return "Cannot call " + name + " after a stream was destroyed"; + }); + createErrorType("ERR_MULTIPLE_CALLBACK", "Callback called multiple times"); + createErrorType("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable"); + createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end"); + createErrorType("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError); + createErrorType("ERR_UNKNOWN_ENCODING", function (arg) { + return "Unknown encoding: " + arg; + }, TypeError); + createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event"); + exports$b$2.codes = codes; + return exports$b$2; +} + +var exports$a$2 = {}, + _dewExec$a$2 = false; +function dew$a$2() { + if (_dewExec$a$2) return exports$a$2; + _dewExec$a$2 = true; + + var ERR_INVALID_OPT_VALUE = dew$b$2().codes.ERR_INVALID_OPT_VALUE; + + function highWaterMarkFrom(options, isDuplex, duplexKey) { + return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; + } + + function getHighWaterMark(state, options, duplexKey, isDuplex) { + var hwm = highWaterMarkFrom(options, isDuplex, duplexKey); + + if (hwm != null) { + if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) { + var name = isDuplex ? duplexKey : "highWaterMark"; + throw new ERR_INVALID_OPT_VALUE(name, hwm); + } + + return Math.floor(hwm); + } // Default value + + + return state.objectMode ? 16 : 16 * 1024; + } + + exports$a$2 = { + getHighWaterMark: getHighWaterMark + }; + return exports$a$2; +} + +var exports$9$2 = {}, + _dewExec$9$2 = false; + +var _global$2$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$9$2() { + if (_dewExec$9$2) return exports$9$2; + _dewExec$9$2 = true; + + /** + * Module exports. + */ + exports$9$2 = deprecate; + /** + * Mark that a method should not be used. + * Returns a modified function which warns once by default. + * + * If `localStorage.noDeprecation = true` is set, then it is a no-op. + * + * If `localStorage.throwDeprecation = true` is set, then deprecated functions + * will throw an Error when invoked. + * + * If `localStorage.traceDeprecation = true` is set, then deprecated functions + * will invoke `console.trace()` instead of `console.error()`. + * + * @param {Function} fn - the function to deprecate + * @param {String} msg - the string to print to the console when `fn` is invoked + * @returns {Function} a new "deprecated" version of `fn` + * @api public + */ + + function deprecate(fn, msg) { + if (config("noDeprecation")) { + return fn; + } + + var warned = false; + + function deprecated() { + if (!warned) { + if (config("throwDeprecation")) { + throw new Error(msg); + } else if (config("traceDeprecation")) { + console.trace(msg); + } else { + console.warn(msg); + } + + warned = true; + } + + return fn.apply(this || _global$2$2, arguments); + } + + return deprecated; + } + /** + * Checks `localStorage` for boolean values for the given `name`. + * + * @param {String} name + * @returns {Boolean} + * @api private + */ + + + function config(name) { + // accessing global.localStorage can trigger a DOMException in sandboxed iframes + try { + if (!_global$2$2.localStorage) return false; + } catch (_) { + return false; + } + + var val = _global$2$2.localStorage[name]; + if (null == val) return false; + return String(val).toLowerCase() === "true"; + } + + return exports$9$2; +} + +var exports$8$2 = {}, + _dewExec$8$2 = false; + +var _global$1$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$8$2() { + if (_dewExec$8$2) return exports$8$2; + _dewExec$8$2 = true; + var process = T$9; + exports$8$2 = Writable; + // there will be only 2 of these for each stream + + + function CorkedRequest(state) { + var _this = this; + + this.next = null; + this.entry = null; + + this.finish = function () { + onCorkedFinish(_this, state); + }; + } + /* */ + + /**/ + + + var Duplex; + /**/ + + Writable.WritableState = WritableState; + /**/ + + var internalUtil = { + deprecate: dew$9$2() + }; + /**/ + + /**/ + + var Stream = dew$e$2(); + /**/ + + + var Buffer = e$1$1$1.Buffer; + + var OurUint8Array = _global$1$2.Uint8Array || function () {}; + + function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); + } + + function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + } + + var destroyImpl = dew$c$2(); + + var _require = dew$a$2(), + getHighWaterMark = _require.getHighWaterMark; + + var _require$codes = dew$b$2().codes, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, + ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE, + ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED, + ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, + ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, + ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING; + + var errorOrDestroy = destroyImpl.errorOrDestroy; + + dew$f$2()(Writable, Stream); + + function nop() {} + + function WritableState(options, stream, isDuplex) { + Duplex = Duplex || dew$7$2(); + options = options || {}; // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream, + // e.g. options.readableObjectMode vs. options.writableObjectMode, etc. + + if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex; // object stream flag to indicate whether or not this stream + // contains buffers or objects. + + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + + this.highWaterMark = getHighWaterMark(this, options, "writableHighWaterMark", isDuplex); // if _final has been called + + this.finalCalled = false; // drain event flag. + + this.needDrain = false; // at the start of calling end() + + this.ending = false; // when end() has been called, and returned + + this.ended = false; // when 'finish' is emitted + + this.finished = false; // has it been destroyed + + this.destroyed = false; // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + + this.defaultEncoding = options.defaultEncoding || "utf8"; // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + + this.length = 0; // a flag to see when we're in the middle of a write. + + this.writing = false; // when true all writes will be buffered until .uncork() call + + this.corked = 0; // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + + this.sync = true; // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + + this.bufferProcessing = false; // the callback that's passed to _write(chunk,cb) + + this.onwrite = function (er) { + onwrite(stream, er); + }; // the callback that the user supplies to write(chunk,encoding,cb) + + + this.writecb = null; // the amount that is being written when _write is called. + + this.writelen = 0; + this.bufferedRequest = null; + this.lastBufferedRequest = null; // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + + this.pendingcb = 0; // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + + this.prefinished = false; // True if the error was already emitted and should not be thrown again + + this.errorEmitted = false; // Should close be emitted on destroy. Defaults to true. + + this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'finish' (and potentially 'end') + + this.autoDestroy = !!options.autoDestroy; // count buffered requests + + this.bufferedRequestCount = 0; // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two + + this.corkedRequestsFree = new CorkedRequest(this); + } + + WritableState.prototype.getBuffer = function getBuffer() { + var current = this.bufferedRequest; + var out = []; + + while (current) { + out.push(current); + current = current.next; + } + + return out; + }; + + (function () { + try { + Object.defineProperty(WritableState.prototype, "buffer", { + get: internalUtil.deprecate(function writableStateBufferGetter() { + return this.getBuffer(); + }, "_writableState.buffer is deprecated. Use _writableState.getBuffer " + "instead.", "DEP0003") + }); + } catch (_) {} + })(); // Test _writableState for inheritance to account for Duplex streams, + // whose prototype chain only points to Readable. + + + var realHasInstance; + + if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") { + realHasInstance = Function.prototype[Symbol.hasInstance]; + Object.defineProperty(Writable, Symbol.hasInstance, { + value: function value(object) { + if (realHasInstance.call(this, object)) return true; + if (this !== Writable) return false; + return object && object._writableState instanceof WritableState; + } + }); + } else { + realHasInstance = function realHasInstance(object) { + return object instanceof this; + }; + } + + function Writable(options) { + Duplex = Duplex || dew$7$2(); // Writable ctor is applied to Duplexes, too. + // `realHasInstance` is necessary because using plain `instanceof` + // would return false, as no `_writableState` property is attached. + // Trying to use the custom `instanceof` for Writable here will also break the + // Node.js LazyTransform implementation, which has a non-trivial getter for + // `_writableState` that would lead to infinite recursion. + // Checking for a Stream.Duplex instance is faster here instead of inside + // the WritableState constructor, at least with V8 6.5 + + var isDuplex = this instanceof Duplex; + if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options); + this._writableState = new WritableState(options, this, isDuplex); // legacy. + + this.writable = true; + + if (options) { + if (typeof options.write === "function") this._write = options.write; + if (typeof options.writev === "function") this._writev = options.writev; + if (typeof options.destroy === "function") this._destroy = options.destroy; + if (typeof options.final === "function") this._final = options.final; + } + + Stream.call(this); + } // Otherwise people can pipe Writable streams, which is just wrong. + + + Writable.prototype.pipe = function () { + errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE()); + }; + + function writeAfterEnd(stream, cb) { + var er = new ERR_STREAM_WRITE_AFTER_END(); // TODO: defer error events consistently everywhere, not just the cb + + errorOrDestroy(stream, er); + process.nextTick(cb, er); + } // Checks that a user-supplied chunk is valid, especially for the particular + // mode the stream is in. Currently this means that `null` is never accepted + // and undefined/non-string values are only allowed in object mode. + + + function validChunk(stream, state, chunk, cb) { + var er; + + if (chunk === null) { + er = new ERR_STREAM_NULL_VALUES(); + } else if (typeof chunk !== "string" && !state.objectMode) { + er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk); + } + + if (er) { + errorOrDestroy(stream, er); + process.nextTick(cb, er); + return false; + } + + return true; + } + + Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + + var isBuf = !state.objectMode && _isUint8Array(chunk); + + if (isBuf && !Buffer.isBuffer(chunk)) { + chunk = _uint8ArrayToBuffer(chunk); + } + + if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + + if (isBuf) encoding = "buffer";else if (!encoding) encoding = state.defaultEncoding; + if (typeof cb !== "function") cb = nop; + if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); + } + return ret; + }; + + Writable.prototype.cork = function () { + this._writableState.corked++; + }; + + Writable.prototype.uncork = function () { + var state = this._writableState; + + if (state.corked) { + state.corked--; + if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } + }; + + Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === "string") encoding = encoding.toLowerCase(); + if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding); + this._writableState.defaultEncoding = encoding; + return this; + }; + + Object.defineProperty(Writable.prototype, "writableBuffer", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState && this._writableState.getBuffer(); + } + }); + + function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") { + chunk = Buffer.from(chunk, encoding); + } + + return chunk; + } + + Object.defineProperty(Writable.prototype, "writableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.highWaterMark; + } + }); // if we're already writing something, then just put this + // in the queue, and wait our turn. Otherwise, call _write + // If we return false, then we need a drain event, so set that flag. + + function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { + if (!isBuf) { + var newChunk = decodeChunk(state, chunk, encoding); + + if (chunk !== newChunk) { + isBuf = true; + encoding = "buffer"; + chunk = newChunk; + } + } + + var len = state.objectMode ? 1 : chunk.length; + state.length += len; + var ret = state.length < state.highWaterMark; // we must ensure that previous needDrain will not be reset to false. + + if (!ret) state.needDrain = true; + + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = { + chunk: chunk, + encoding: encoding, + isBuf: isBuf, + callback: cb, + next: null + }; + + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + + return ret; + } + + function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED("write"));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } + + function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + + if (sync) { + // defer the callback if we are being called synchronously + // to avoid piling up things on the stack + process.nextTick(cb, er); // this can emit finish, and it will always happen + // after error + + process.nextTick(finishMaybe, stream, state); + stream._writableState.errorEmitted = true; + errorOrDestroy(stream, er); + } else { + // the caller expect this to happen before if + // it is async + cb(er); + stream._writableState.errorEmitted = true; + errorOrDestroy(stream, er); // this can emit finish, but finish must + // always follow error + + finishMaybe(stream, state); + } + } + + function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; + } + + function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + if (typeof cb !== "function") throw new ERR_MULTIPLE_CALLBACK(); + onwriteStateUpdate(state); + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state) || stream.destroyed; + + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); + } + + if (sync) { + process.nextTick(afterWrite, stream, state, finished, cb); + } else { + afterWrite(stream, state, finished, cb); + } + } + } + + function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); + } // Must force callback to be called on nextTick, so that we don't + // emit 'drain' before the write() consumer gets the 'false' return + // value, and has a chance to attach a 'drain' listener. + + + function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit("drain"); + } + } // if there's something in the buffer waiting, then process it + + + function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + var count = 0; + var allBuffers = true; + + while (entry) { + buffer[count] = entry; + if (!entry.isBuf) allBuffers = false; + entry = entry.next; + count += 1; + } + + buffer.allBuffers = allBuffers; + doWrite(stream, state, true, state.length, buffer, "", holder.finish); // doWrite is almost always async, defer these to save a bit of time + // as the hot path ends with doWrite + + state.pendingcb++; + state.lastBufferedRequest = null; + + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); + } + + state.bufferedRequestCount = 0; + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + state.bufferedRequestCount--; // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + + if (state.writing) { + break; + } + } + + if (entry === null) state.lastBufferedRequest = null; + } + + state.bufferedRequest = entry; + state.bufferProcessing = false; + } + + Writable.prototype._write = function (chunk, encoding, cb) { + cb(new ERR_METHOD_NOT_IMPLEMENTED("_write()")); + }; + + Writable.prototype._writev = null; + + Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; + + if (typeof chunk === "function") { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); // .end() fully uncorks + + if (state.corked) { + state.corked = 1; + this.uncork(); + } // ignore unnecessary end() calls. + + + if (!state.ending) endWritable(this, state, cb); + return this; + }; + + Object.defineProperty(Writable.prototype, "writableLength", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.length; + } + }); + + function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; + } + + function callFinal(stream, state) { + stream._final(function (err) { + state.pendingcb--; + + if (err) { + errorOrDestroy(stream, err); + } + + state.prefinished = true; + stream.emit("prefinish"); + finishMaybe(stream, state); + }); + } + + function prefinish(stream, state) { + if (!state.prefinished && !state.finalCalled) { + if (typeof stream._final === "function" && !state.destroyed) { + state.pendingcb++; + state.finalCalled = true; + process.nextTick(callFinal, stream, state); + } else { + state.prefinished = true; + stream.emit("prefinish"); + } + } + } + + function finishMaybe(stream, state) { + var need = needFinish(state); + + if (need) { + prefinish(stream, state); + + if (state.pendingcb === 0) { + state.finished = true; + stream.emit("finish"); + + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the readable side is ready for autoDestroy as well + var rState = stream._readableState; + + if (!rState || rState.autoDestroy && rState.endEmitted) { + stream.destroy(); + } + } + } + } + + return need; + } + + function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + + if (cb) { + if (state.finished) process.nextTick(cb);else stream.once("finish", cb); + } + + state.ended = true; + stream.writable = false; + } + + function onCorkedFinish(corkReq, state, err) { + var entry = corkReq.entry; + corkReq.entry = null; + + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } // reuse the free corkReq. + + + state.corkedRequestsFree.next = corkReq; + } + + Object.defineProperty(Writable.prototype, "destroyed", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._writableState === undefined) { + return false; + } + + return this._writableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._writableState) { + return; + } // backward compatibility, the user is explicitly + // managing destroyed + + + this._writableState.destroyed = value; + } + }); + Writable.prototype.destroy = destroyImpl.destroy; + Writable.prototype._undestroy = destroyImpl.undestroy; + + Writable.prototype._destroy = function (err, cb) { + cb(err); + }; + + return exports$8$2; +} + +var exports$7$2 = {}, + _dewExec$7$2 = false; +function dew$7$2() { + if (_dewExec$7$2) return exports$7$2; + _dewExec$7$2 = true; + var process = T$9; + + /**/ + var objectKeys = Object.keys || function (obj) { + var keys = []; + + for (var key in obj) { + keys.push(key); + } + + return keys; + }; + /**/ + + + exports$7$2 = Duplex; + + var Readable = dew$3$2(); + + var Writable = dew$8$2(); + + dew$f$2()(Duplex, Readable); + + { + // Allow the keys array to be GC'ed. + var keys = objectKeys(Writable.prototype); + + for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + } + } + + function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + Readable.call(this, options); + Writable.call(this, options); + this.allowHalfOpen = true; + + if (options) { + if (options.readable === false) this.readable = false; + if (options.writable === false) this.writable = false; + + if (options.allowHalfOpen === false) { + this.allowHalfOpen = false; + this.once("end", onend); + } + } + } + + Object.defineProperty(Duplex.prototype, "writableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.highWaterMark; + } + }); + Object.defineProperty(Duplex.prototype, "writableBuffer", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState && this._writableState.getBuffer(); + } + }); + Object.defineProperty(Duplex.prototype, "writableLength", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.length; + } + }); // the no-half-open enforcer + + function onend() { + // If the writable side ended, then we're ok. + if (this._writableState.ended) return; // no more data can be written. + // But allow more writes to happen in this tick. + + process.nextTick(onEndNT, this); + } + + function onEndNT(self) { + self.end(); + } + + Object.defineProperty(Duplex.prototype, "destroyed", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._readableState === undefined || this._writableState === undefined) { + return false; + } + + return this._readableState.destroyed && this._writableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (this._readableState === undefined || this._writableState === undefined) { + return; + } // backward compatibility, the user is explicitly + // managing destroyed + + + this._readableState.destroyed = value; + this._writableState.destroyed = value; + } + }); + return exports$7$2; +} + +var exports$6$2 = {}, + _dewExec$6$2 = false; +function dew$6$2() { + if (_dewExec$6$2) return exports$6$2; + _dewExec$6$2 = true; + + var ERR_STREAM_PREMATURE_CLOSE = dew$b$2().codes.ERR_STREAM_PREMATURE_CLOSE; + + function once(callback) { + var called = false; + return function () { + if (called) return; + called = true; + + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + callback.apply(this, args); + }; + } + + function noop() {} + + function isRequest(stream) { + return stream.setHeader && typeof stream.abort === "function"; + } + + function eos(stream, opts, callback) { + if (typeof opts === "function") return eos(stream, null, opts); + if (!opts) opts = {}; + callback = once(callback || noop); + var readable = opts.readable || opts.readable !== false && stream.readable; + var writable = opts.writable || opts.writable !== false && stream.writable; + + var onlegacyfinish = function onlegacyfinish() { + if (!stream.writable) onfinish(); + }; + + var writableEnded = stream._writableState && stream._writableState.finished; + + var onfinish = function onfinish() { + writable = false; + writableEnded = true; + if (!readable) callback.call(stream); + }; + + var readableEnded = stream._readableState && stream._readableState.endEmitted; + + var onend = function onend() { + readable = false; + readableEnded = true; + if (!writable) callback.call(stream); + }; + + var onerror = function onerror(err) { + callback.call(stream, err); + }; + + var onclose = function onclose() { + var err; + + if (readable && !readableEnded) { + if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); + return callback.call(stream, err); + } + + if (writable && !writableEnded) { + if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); + return callback.call(stream, err); + } + }; + + var onrequest = function onrequest() { + stream.req.on("finish", onfinish); + }; + + if (isRequest(stream)) { + stream.on("complete", onfinish); + stream.on("abort", onclose); + if (stream.req) onrequest();else stream.on("request", onrequest); + } else if (writable && !stream._writableState) { + // legacy streams + stream.on("end", onlegacyfinish); + stream.on("close", onlegacyfinish); + } + + stream.on("end", onend); + stream.on("finish", onfinish); + if (opts.error !== false) stream.on("error", onerror); + stream.on("close", onclose); + return function () { + stream.removeListener("complete", onfinish); + stream.removeListener("abort", onclose); + stream.removeListener("request", onrequest); + if (stream.req) stream.req.removeListener("finish", onfinish); + stream.removeListener("end", onlegacyfinish); + stream.removeListener("close", onlegacyfinish); + stream.removeListener("finish", onfinish); + stream.removeListener("end", onend); + stream.removeListener("error", onerror); + stream.removeListener("close", onclose); + }; + } + + exports$6$2 = eos; + return exports$6$2; +} + +var exports$5$2 = {}, + _dewExec$5$2 = false; +function dew$5$2() { + if (_dewExec$5$2) return exports$5$2; + _dewExec$5$2 = true; + var process = T$9; + + var _Object$setPrototypeO; + + function _defineProperty(obj, key, value) { + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + + return obj; + } + + var finished = dew$6$2(); + + var kLastResolve = Symbol("lastResolve"); + var kLastReject = Symbol("lastReject"); + var kError = Symbol("error"); + var kEnded = Symbol("ended"); + var kLastPromise = Symbol("lastPromise"); + var kHandlePromise = Symbol("handlePromise"); + var kStream = Symbol("stream"); + + function createIterResult(value, done) { + return { + value: value, + done: done + }; + } + + function readAndResolve(iter) { + var resolve = iter[kLastResolve]; + + if (resolve !== null) { + var data = iter[kStream].read(); // we defer if data is null + // we can be expecting either 'end' or + // 'error' + + if (data !== null) { + iter[kLastPromise] = null; + iter[kLastResolve] = null; + iter[kLastReject] = null; + resolve(createIterResult(data, false)); + } + } + } + + function onReadable(iter) { + // we wait for the next tick, because it might + // emit an error with process.nextTick + process.nextTick(readAndResolve, iter); + } + + function wrapForNext(lastPromise, iter) { + return function (resolve, reject) { + lastPromise.then(function () { + if (iter[kEnded]) { + resolve(createIterResult(undefined, true)); + return; + } + + iter[kHandlePromise](resolve, reject); + }, reject); + }; + } + + var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); + var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = { + get stream() { + return this[kStream]; + }, + + next: function next() { + var _this = this; // if we have detected an error in the meanwhile + // reject straight away + + + var error = this[kError]; + + if (error !== null) { + return Promise.reject(error); + } + + if (this[kEnded]) { + return Promise.resolve(createIterResult(undefined, true)); + } + + if (this[kStream].destroyed) { + // We need to defer via nextTick because if .destroy(err) is + // called, the error will be emitted via nextTick, and + // we cannot guarantee that there is no error lingering around + // waiting to be emitted. + return new Promise(function (resolve, reject) { + process.nextTick(function () { + if (_this[kError]) { + reject(_this[kError]); + } else { + resolve(createIterResult(undefined, true)); + } + }); + }); + } // if we have multiple next() calls + // we will wait for the previous Promise to finish + // this logic is optimized to support for await loops, + // where next() is only called once at a time + + + var lastPromise = this[kLastPromise]; + var promise; + + if (lastPromise) { + promise = new Promise(wrapForNext(lastPromise, this)); + } else { + // fast path needed to support multiple this.push() + // without triggering the next() queue + var data = this[kStream].read(); + + if (data !== null) { + return Promise.resolve(createIterResult(data, false)); + } + + promise = new Promise(this[kHandlePromise]); + } + + this[kLastPromise] = promise; + return promise; + } + }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () { + return this; + }), _defineProperty(_Object$setPrototypeO, "return", function _return() { + var _this2 = this; // destroy(err, cb) is a private API + // we can guarantee we have that here, because we control the + // Readable class this is attached to + + + return new Promise(function (resolve, reject) { + _this2[kStream].destroy(null, function (err) { + if (err) { + reject(err); + return; + } + + resolve(createIterResult(undefined, true)); + }); + }); + }), _Object$setPrototypeO), AsyncIteratorPrototype); + + var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) { + var _Object$create; + + var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, { + value: stream, + writable: true + }), _defineProperty(_Object$create, kLastResolve, { + value: null, + writable: true + }), _defineProperty(_Object$create, kLastReject, { + value: null, + writable: true + }), _defineProperty(_Object$create, kError, { + value: null, + writable: true + }), _defineProperty(_Object$create, kEnded, { + value: stream._readableState.endEmitted, + writable: true + }), _defineProperty(_Object$create, kHandlePromise, { + value: function value(resolve, reject) { + var data = iterator[kStream].read(); + + if (data) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(data, false)); + } else { + iterator[kLastResolve] = resolve; + iterator[kLastReject] = reject; + } + }, + writable: true + }), _Object$create)); + iterator[kLastPromise] = null; + finished(stream, function (err) { + if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") { + var reject = iterator[kLastReject]; // reject if we are waiting for data in the Promise + // returned by next() and store the error + + if (reject !== null) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + reject(err); + } + + iterator[kError] = err; + return; + } + + var resolve = iterator[kLastResolve]; + + if (resolve !== null) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(undefined, true)); + } + + iterator[kEnded] = true; + }); + stream.on("readable", onReadable.bind(null, iterator)); + return iterator; + }; + + exports$5$2 = createReadableStreamAsyncIterator; + return exports$5$2; +} + +var exports$4$2 = {}, + _dewExec$4$2 = false; +function dew$4$2() { + if (_dewExec$4$2) return exports$4$2; + _dewExec$4$2 = true; + + exports$4$2 = function () { + throw new Error("Readable.from is not available in the browser"); + }; + + return exports$4$2; +} + +var exports$3$2 = {}, + _dewExec$3$2 = false; + +var _global$M = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$3$2() { + if (_dewExec$3$2) return exports$3$2; + _dewExec$3$2 = true; + var process = T$9; + exports$3$2 = Readable; + /**/ + + var Duplex; + /**/ + + Readable.ReadableState = ReadableState; + /**/ + + y$o.EventEmitter; + + var EElistenerCount = function EElistenerCount(emitter, type) { + return emitter.listeners(type).length; + }; + /**/ + + /**/ + + + var Stream = dew$e$2(); + /**/ + + + var Buffer = e$1$1$1.Buffer; + + var OurUint8Array = _global$M.Uint8Array || function () {}; + + function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); + } + + function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + } + /**/ + + + var debugUtil = X$5; + var debug; + + if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog("stream"); + } else { + debug = function debug() {}; + } + /**/ + + + var BufferList = dew$d$2(); + + var destroyImpl = dew$c$2(); + + var _require = dew$a$2(), + getHighWaterMark = _require.getHighWaterMark; + + var _require$codes = dew$b$2().codes, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; // Lazy loaded to improve the startup performance. + + + var StringDecoder; + var createReadableStreamAsyncIterator; + var from; + + dew$f$2()(Readable, Stream); + + var errorOrDestroy = destroyImpl.errorOrDestroy; + var kProxyEvents = ["error", "close", "destroy", "pause", "resume"]; + + function prependListener(emitter, event, fn) { + // Sadly this is not cacheable as some libraries bundle their own + // event emitter implementation with them. + if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn); // This is a hack to make sure that our error handler is attached before any + // userland ones. NEVER DO THIS. This is here only because this code needs + // to continue to work with older versions of Node.js that do not include + // the prependListener() method. The goal is to eventually remove this hack. + + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; + } + + function ReadableState(options, stream, isDuplex) { + Duplex = Duplex || dew$7$2(); + options = options || {}; // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream. + // These options can be provided separately as readableXXX and writableXXX. + + if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex; // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + + this.highWaterMark = getHighWaterMark(this, options, "readableHighWaterMark", isDuplex); // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift() + + this.buffer = new BufferList(); + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; // a flag to be able to tell if the event 'readable'/'data' is emitted + // immediately, or on a later tick. We set this to true at first, because + // any actions that shouldn't happen until "later" should generally also + // not happen before the first read call. + + this.sync = true; // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + this.resumeScheduled = false; + this.paused = true; // Should close be emitted on destroy. Defaults to true. + + this.emitClose = options.emitClose !== false; // Should .destroy() be called after 'end' (and potentially 'finish') + + this.autoDestroy = !!options.autoDestroy; // has it been destroyed + + this.destroyed = false; // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + + this.defaultEncoding = options.defaultEncoding || "utf8"; // the number of writers that are awaiting a drain event in .pipe()s + + this.awaitDrain = 0; // if true, a maybeReadMore has been scheduled + + this.readingMore = false; + this.decoder = null; + this.encoding = null; + + if (options.encoding) { + if (!StringDecoder) StringDecoder = e$1$2.StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } + } + + function Readable(options) { + Duplex = Duplex || dew$7$2(); + if (!(this instanceof Readable)) return new Readable(options); // Checking for a Stream.Duplex instance is faster here instead of inside + // the ReadableState constructor, at least with V8 6.5 + + var isDuplex = this instanceof Duplex; + this._readableState = new ReadableState(options, this, isDuplex); // legacy + + this.readable = true; + + if (options) { + if (typeof options.read === "function") this._read = options.read; + if (typeof options.destroy === "function") this._destroy = options.destroy; + } + + Stream.call(this); + } + + Object.defineProperty(Readable.prototype, "destroyed", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._readableState === undefined) { + return false; + } + + return this._readableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._readableState) { + return; + } // backward compatibility, the user is explicitly + // managing destroyed + + + this._readableState.destroyed = value; + } + }); + Readable.prototype.destroy = destroyImpl.destroy; + Readable.prototype._undestroy = destroyImpl.undestroy; + + Readable.prototype._destroy = function (err, cb) { + cb(err); + }; // Manually shove something into the read() buffer. + // This returns true if the highWaterMark has not been hit yet, + // similar to how Writable.write() returns true if you should + // write() some more. + + + Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; + var skipChunkCheck; + + if (!state.objectMode) { + if (typeof chunk === "string") { + encoding = encoding || state.defaultEncoding; + + if (encoding !== state.encoding) { + chunk = Buffer.from(chunk, encoding); + encoding = ""; + } + + skipChunkCheck = true; + } + } else { + skipChunkCheck = true; + } + + return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); + }; // Unshift should *always* be something directly out of read() + + + Readable.prototype.unshift = function (chunk) { + return readableAddChunk(this, chunk, null, true, false); + }; + + function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { + debug("readableAddChunk", chunk); + var state = stream._readableState; + + if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else { + var er; + if (!skipChunkCheck) er = chunkInvalid(state, chunk); + + if (er) { + errorOrDestroy(stream, er); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { + chunk = _uint8ArrayToBuffer(chunk); + } + + if (addToFront) { + if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true); + } else if (state.ended) { + errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF()); + } else if (state.destroyed) { + return false; + } else { + state.reading = false; + + if (state.decoder && !encoding) { + chunk = state.decoder.write(chunk); + if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); + } else { + addChunk(stream, state, chunk, false); + } + } + } else if (!addToFront) { + state.reading = false; + maybeReadMore(stream, state); + } + } // We can push more data if we are below the highWaterMark. + // Also, if we have no data yet, we can stand some more bytes. + // This is to work around cases where hwm=0, such as the repl. + + + return !state.ended && (state.length < state.highWaterMark || state.length === 0); + } + + function addChunk(stream, state, chunk, addToFront) { + if (state.flowing && state.length === 0 && !state.sync) { + state.awaitDrain = 0; + stream.emit("data", chunk); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + if (state.needReadable) emitReadable(stream); + } + + maybeReadMore(stream, state); + } + + function chunkInvalid(state, chunk) { + var er; + + if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== undefined && !state.objectMode) { + er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk); + } + + return er; + } + + Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; + }; // backwards compatibility. + + + Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = e$1$2.StringDecoder; + var decoder = new StringDecoder(enc); + this._readableState.decoder = decoder; // If setEncoding(null), decoder.encoding equals utf8 + + this._readableState.encoding = this._readableState.decoder.encoding; // Iterate over current buffer to convert already stored Buffers: + + var p = this._readableState.buffer.head; + var content = ""; + + while (p !== null) { + content += decoder.write(p.data); + p = p.next; + } + + this._readableState.buffer.clear(); + + if (content !== "") this._readableState.buffer.push(content); + this._readableState.length = content.length; + return this; + }; // Don't raise the hwm > 1GB + + + var MAX_HWM = 1073741824; + + function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE. + n = MAX_HWM; + } else { + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + + return n; + } // This function is designed to be inlinable, so please take care when making + // changes to the function body. + + + function howMuchToRead(n, state) { + if (n <= 0 || state.length === 0 && state.ended) return 0; + if (state.objectMode) return 1; + + if (n !== n) { + // Only flow one buffer at a time + if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; + } // If we're asking for more than the current hwm, then raise the hwm. + + + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + if (n <= state.length) return n; // Don't have enough + + if (!state.ended) { + state.needReadable = true; + return 0; + } + + return state.length; + } // you can override either this method, or the async _read(n) below. + + + Readable.prototype.read = function (n) { + debug("read", n); + n = parseInt(n, 10); + var state = this._readableState; + var nOrig = n; + if (n !== 0) state.emittedReadable = false; // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + + if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) { + debug("read: emitReadable", state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; + } + + n = howMuchToRead(n, state); // if we've ended, and we're now clear, then finish it up. + + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; + } // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. + // if we need a readable event, then we need to do some reading. + + + var doRead = state.needReadable; + debug("need readable", doRead); // if we currently have less than the highWaterMark, then also read some + + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug("length less than watermark", doRead); + } // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + + + if (state.ended || state.reading) { + doRead = false; + debug("reading or ended", doRead); + } else if (doRead) { + debug("do read"); + state.reading = true; + state.sync = true; // if the length is currently zero, then we *need* a readable event. + + if (state.length === 0) state.needReadable = true; // call internal read method + + this._read(state.highWaterMark); + + state.sync = false; // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + + if (!state.reading) n = howMuchToRead(nOrig, state); + } + + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; + + if (ret === null) { + state.needReadable = state.length <= state.highWaterMark; + n = 0; + } else { + state.length -= n; + state.awaitDrain = 0; + } + + if (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!state.ended) state.needReadable = true; // If we tried to read() past the EOF, then emit end on the next tick. + + if (nOrig !== n && state.ended) endReadable(this); + } + + if (ret !== null) this.emit("data", ret); + return ret; + }; + + function onEofChunk(stream, state) { + debug("onEofChunk"); + if (state.ended) return; + + if (state.decoder) { + var chunk = state.decoder.end(); + + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + + state.ended = true; + + if (state.sync) { + // if we are sync, wait until next tick to emit the data. + // Otherwise we risk emitting data in the flow() + // the readable code triggers during a read() call + emitReadable(stream); + } else { + // emit 'readable' now to make sure it gets picked up. + state.needReadable = false; + + if (!state.emittedReadable) { + state.emittedReadable = true; + emitReadable_(stream); + } + } + } // Don't emit readable right away in sync mode, because this can trigger + // another read() call => stack overflow. This way, it might trigger + // a nextTick recursion warning, but that's not so bad. + + + function emitReadable(stream) { + var state = stream._readableState; + debug("emitReadable", state.needReadable, state.emittedReadable); + state.needReadable = false; + + if (!state.emittedReadable) { + debug("emitReadable", state.flowing); + state.emittedReadable = true; + process.nextTick(emitReadable_, stream); + } + } + + function emitReadable_(stream) { + var state = stream._readableState; + debug("emitReadable_", state.destroyed, state.length, state.ended); + + if (!state.destroyed && (state.length || state.ended)) { + stream.emit("readable"); + state.emittedReadable = false; + } // The stream needs another readable event if + // 1. It is not flowing, as the flow mechanism will take + // care of it. + // 2. It is not ended. + // 3. It is below the highWaterMark, so we can schedule + // another readable later. + + + state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark; + flow(stream); + } // at this point, the user has presumably seen the 'readable' event, + // and called read() to consume some data. that may have triggered + // in turn another _read(n) call, in which case reading = true if + // it's in progress. + // However, if we're not ended, or reading, and the length < hwm, + // then go ahead and try to read some more preemptively. + + + function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + process.nextTick(maybeReadMore_, stream, state); + } + } + + function maybeReadMore_(stream, state) { + // Attempt to read more data if we should. + // + // The conditions for reading more data are (one of): + // - Not enough data buffered (state.length < state.highWaterMark). The loop + // is responsible for filling the buffer with enough data if such data + // is available. If highWaterMark is 0 and we are not in the flowing mode + // we should _not_ attempt to buffer any extra data. We'll get more data + // when the stream consumer calls read() instead. + // - No data in the buffer, and the stream is in flowing mode. In this mode + // the loop below is responsible for ensuring read() is called. Failing to + // call read here would abort the flow and there's no other mechanism for + // continuing the flow if the stream consumer has just subscribed to the + // 'data' event. + // + // In addition to the above conditions to keep reading data, the following + // conditions prevent the data from being read: + // - The stream has ended (state.ended). + // - There is already a pending 'read' operation (state.reading). This is a + // case where the the stream has called the implementation defined _read() + // method, but they are processing the call asynchronously and have _not_ + // called push() with new data. In this case we skip performing more + // read()s. The execution ends in this method again after the _read() ends + // up calling push() with more data. + while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { + var len = state.length; + debug("maybeReadMore read 0"); + stream.read(0); + if (len === state.length) // didn't get any data, stop spinning. + break; + } + + state.readingMore = false; + } // abstract method. to be overridden in specific implementation classes. + // call cb(er, data) where data is <= n in length. + // for virtual (non-string, non-buffer) streams, "length" is somewhat + // arbitrary, and perhaps not very meaningful. + + + Readable.prototype._read = function (n) { + errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED("_read()")); + }; + + Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; + + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + + case 1: + state.pipes = [state.pipes, dest]; + break; + + default: + state.pipes.push(dest); + break; + } + + state.pipesCount += 1; + debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts); + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; + var endFn = doEnd ? onend : unpipe; + if (state.endEmitted) process.nextTick(endFn);else src.once("end", endFn); + dest.on("unpipe", onunpipe); + + function onunpipe(readable, unpipeInfo) { + debug("onunpipe"); + + if (readable === src) { + if (unpipeInfo && unpipeInfo.hasUnpiped === false) { + unpipeInfo.hasUnpiped = true; + cleanup(); + } + } + } + + function onend() { + debug("onend"); + dest.end(); + } // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + + + var ondrain = pipeOnDrain(src); + dest.on("drain", ondrain); + var cleanedUp = false; + + function cleanup() { + debug("cleanup"); // cleanup event handlers once the pipe is broken + + dest.removeListener("close", onclose); + dest.removeListener("finish", onfinish); + dest.removeListener("drain", ondrain); + dest.removeListener("error", onerror); + dest.removeListener("unpipe", onunpipe); + src.removeListener("end", onend); + src.removeListener("end", unpipe); + src.removeListener("data", ondata); + cleanedUp = true; // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + + src.on("data", ondata); + + function ondata(chunk) { + debug("ondata"); + var ret = dest.write(chunk); + debug("dest.write", ret); + + if (ret === false) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { + debug("false write response, pause", state.awaitDrain); + state.awaitDrain++; + } + + src.pause(); + } + } // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + + + function onerror(er) { + debug("onerror", er); + unpipe(); + dest.removeListener("error", onerror); + if (EElistenerCount(dest, "error") === 0) errorOrDestroy(dest, er); + } // Make sure our error handler is attached before userland ones. + + + prependListener(dest, "error", onerror); // Both close and finish should trigger unpipe, but only once. + + function onclose() { + dest.removeListener("finish", onfinish); + unpipe(); + } + + dest.once("close", onclose); + + function onfinish() { + debug("onfinish"); + dest.removeListener("close", onclose); + unpipe(); + } + + dest.once("finish", onfinish); + + function unpipe() { + debug("unpipe"); + src.unpipe(dest); + } // tell the dest that it's being piped to + + + dest.emit("pipe", src); // start the flow if it hasn't been started already. + + if (!state.flowing) { + debug("pipe resume"); + src.resume(); + } + + return dest; + }; + + function pipeOnDrain(src) { + return function pipeOnDrainFunctionResult() { + var state = src._readableState; + debug("pipeOnDrain", state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + + if (state.awaitDrain === 0 && EElistenerCount(src, "data")) { + state.flowing = true; + flow(src); + } + }; + } + + Readable.prototype.unpipe = function (dest) { + var state = this._readableState; + var unpipeInfo = { + hasUnpiped: false + }; // if we're not piping anywhere, then do nothing. + + if (state.pipesCount === 0) return this; // just one destination. most common case. + + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; + if (!dest) dest = state.pipes; // got a match. + + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit("unpipe", this, unpipeInfo); + return this; + } // slow case. multiple pipe destinations. + + + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + + for (var i = 0; i < len; i++) { + dests[i].emit("unpipe", this, { + hasUnpiped: false + }); + } + + return this; + } // try to find the right one. + + + var index = indexOf(state.pipes, dest); + if (index === -1) return this; + state.pipes.splice(index, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; + dest.emit("unpipe", this, unpipeInfo); + return this; + }; // set up data events if they are asked for + // Ensure readable listeners eventually get something + + + Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + var state = this._readableState; + + if (ev === "data") { + // update readableListening so that resume() may be a no-op + // a few lines down. This is needed to support once('readable'). + state.readableListening = this.listenerCount("readable") > 0; // Try start flowing on next tick if stream isn't explicitly paused + + if (state.flowing !== false) this.resume(); + } else if (ev === "readable") { + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; + state.flowing = false; + state.emittedReadable = false; + debug("on readable", state.length, state.reading); + + if (state.length) { + emitReadable(this); + } else if (!state.reading) { + process.nextTick(nReadingNextTick, this); + } + } + } + + return res; + }; + + Readable.prototype.addListener = Readable.prototype.on; + + Readable.prototype.removeListener = function (ev, fn) { + var res = Stream.prototype.removeListener.call(this, ev, fn); + + if (ev === "readable") { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process.nextTick(updateReadableListening, this); + } + + return res; + }; + + Readable.prototype.removeAllListeners = function (ev) { + var res = Stream.prototype.removeAllListeners.apply(this, arguments); + + if (ev === "readable" || ev === undefined) { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process.nextTick(updateReadableListening, this); + } + + return res; + }; + + function updateReadableListening(self) { + var state = self._readableState; + state.readableListening = self.listenerCount("readable") > 0; + + if (state.resumeScheduled && !state.paused) { + // flowing needs to be set to true now, otherwise + // the upcoming resume will not flow. + state.flowing = true; // crude way to check if we should resume + } else if (self.listenerCount("data") > 0) { + self.resume(); + } + } + + function nReadingNextTick(self) { + debug("readable nexttick read 0"); + self.read(0); + } // pause() and resume() are remnants of the legacy readable stream API + // If the user uses them, then switch into old mode. + + + Readable.prototype.resume = function () { + var state = this._readableState; + + if (!state.flowing) { + debug("resume"); // we flow only if there is no one listening + // for readable, but we still have to call + // resume() + + state.flowing = !state.readableListening; + resume(this, state); + } + + state.paused = false; + return this; + }; + + function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + process.nextTick(resume_, stream, state); + } + } + + function resume_(stream, state) { + debug("resume", state.reading); + + if (!state.reading) { + stream.read(0); + } + + state.resumeScheduled = false; + stream.emit("resume"); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); + } + + Readable.prototype.pause = function () { + debug("call pause flowing=%j", this._readableState.flowing); + + if (this._readableState.flowing !== false) { + debug("pause"); + this._readableState.flowing = false; + this.emit("pause"); + } + + this._readableState.paused = true; + return this; + }; + + function flow(stream) { + var state = stream._readableState; + debug("flow", state.flowing); + + while (state.flowing && stream.read() !== null) { + } + } // wrap an old-style stream as the async data source. + // This is *not* part of the readable stream interface. + // It is an ugly unfortunate mess of history. + + + Readable.prototype.wrap = function (stream) { + var _this = this; + + var state = this._readableState; + var paused = false; + stream.on("end", function () { + debug("wrapped end"); + + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) _this.push(chunk); + } + + _this.push(null); + }); + stream.on("data", function (chunk) { + debug("wrapped data"); + if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode + + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + + var ret = _this.push(chunk); + + if (!ret) { + paused = true; + stream.pause(); + } + }); // proxy all the other methods. + // important when wrapping filters and duplexes. + + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === "function") { + this[i] = function methodWrap(method) { + return function methodWrapReturnFunction() { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } // proxy certain important events. + + + for (var n = 0; n < kProxyEvents.length; n++) { + stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n])); + } // when we try to consume some more bytes, simply unpause the + // underlying stream. + + + this._read = function (n) { + debug("wrapped _read", n); + + if (paused) { + paused = false; + stream.resume(); + } + }; + + return this; + }; + + if (typeof Symbol === "function") { + Readable.prototype[Symbol.asyncIterator] = function () { + if (createReadableStreamAsyncIterator === undefined) { + createReadableStreamAsyncIterator = dew$5$2(); + } + + return createReadableStreamAsyncIterator(this); + }; + } + + Object.defineProperty(Readable.prototype, "readableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.highWaterMark; + } + }); + Object.defineProperty(Readable.prototype, "readableBuffer", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState && this._readableState.buffer; + } + }); + Object.defineProperty(Readable.prototype, "readableFlowing", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.flowing; + }, + set: function set(state) { + if (this._readableState) { + this._readableState.flowing = state; + } + } + }); // exposed for testing purposes only. + + Readable._fromList = fromList; + Object.defineProperty(Readable.prototype, "readableLength", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.length; + } + }); // Pluck off n bytes from an array of buffers. + // Length is the combined lengths of all the buffers in the list. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + + function fromList(n, state) { + // nothing buffered + if (state.length === 0) return null; + var ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // read it all, truncate the list + if (state.decoder) ret = state.buffer.join("");else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length); + state.buffer.clear(); + } else { + // read part of list + ret = state.buffer.consume(n, state.decoder); + } + return ret; + } + + function endReadable(stream) { + var state = stream._readableState; + debug("endReadable", state.endEmitted); + + if (!state.endEmitted) { + state.ended = true; + process.nextTick(endReadableNT, state, stream); + } + } + + function endReadableNT(state, stream) { + debug("endReadableNT", state.endEmitted, state.length); // Check that we didn't get one last unshift. + + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit("end"); + + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the writable side is ready for autoDestroy as well + var wState = stream._writableState; + + if (!wState || wState.autoDestroy && wState.finished) { + stream.destroy(); + } + } + } + } + + if (typeof Symbol === "function") { + Readable.from = function (iterable, opts) { + if (from === undefined) { + from = dew$4$2(); + } + + return from(Readable, iterable, opts); + }; + } + + function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + + return -1; + } + + return exports$3$2; +} + +var exports$2$2 = {}, + _dewExec$2$2 = false; +function dew$2$2() { + if (_dewExec$2$2) return exports$2$2; + _dewExec$2$2 = true; + exports$2$2 = Transform; + + var _require$codes = dew$b$2().codes, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, + ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING, + ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0; + + var Duplex = dew$7$2(); + + dew$f$2()(Transform, Duplex); + + function afterTransform(er, data) { + var ts = this._transformState; + ts.transforming = false; + var cb = ts.writecb; + + if (cb === null) { + return this.emit("error", new ERR_MULTIPLE_CALLBACK()); + } + + ts.writechunk = null; + ts.writecb = null; + if (data != null) // single equals check for both `null` and `undefined` + this.push(data); + cb(er); + var rs = this._readableState; + rs.reading = false; + + if (rs.needReadable || rs.length < rs.highWaterMark) { + this._read(rs.highWaterMark); + } + } + + function Transform(options) { + if (!(this instanceof Transform)) return new Transform(options); + Duplex.call(this, options); + this._transformState = { + afterTransform: afterTransform.bind(this), + needTransform: false, + transforming: false, + writecb: null, + writechunk: null, + writeencoding: null + }; // start out asking for a readable event once data is transformed. + + this._readableState.needReadable = true; // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + + this._readableState.sync = false; + + if (options) { + if (typeof options.transform === "function") this._transform = options.transform; + if (typeof options.flush === "function") this._flush = options.flush; + } // When the writable side finishes, then flush out anything remaining. + + + this.on("prefinish", prefinish); + } + + function prefinish() { + var _this = this; + + if (typeof this._flush === "function" && !this._readableState.destroyed) { + this._flush(function (er, data) { + done(_this, er, data); + }); + } else { + done(this, null, null); + } + } + + Transform.prototype.push = function (chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); + }; // This is the part where you do stuff! + // override this function in implementation classes. + // 'chunk' is an input chunk. + // + // Call `push(newChunk)` to pass along transformed output + // to the readable side. You may call 'push' zero or more times. + // + // Call `cb(err)` when you are done with this chunk. If you pass + // an error, then that'll put the hurt on the whole operation. If you + // never call cb(), then you'll never get another chunk. + + + Transform.prototype._transform = function (chunk, encoding, cb) { + cb(new ERR_METHOD_NOT_IMPLEMENTED("_transform()")); + }; + + Transform.prototype._write = function (chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); + } + }; // Doesn't matter what the args are here. + // _transform does all the work. + // That we got here means that the readable side wants more data. + + + Transform.prototype._read = function (n) { + var ts = this._transformState; + + if (ts.writechunk !== null && !ts.transforming) { + ts.transforming = true; + + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; + } + }; + + Transform.prototype._destroy = function (err, cb) { + Duplex.prototype._destroy.call(this, err, function (err2) { + cb(err2); + }); + }; + + function done(stream, er, data) { + if (er) return stream.emit("error", er); + if (data != null) // single equals check for both `null` and `undefined` + stream.push(data); // TODO(BridgeAR): Write a test for these two error cases + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + + if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0(); + if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING(); + return stream.push(null); + } + + return exports$2$2; +} + +var exports$1$2 = {}, + _dewExec$1$2 = false; +function dew$1$2() { + if (_dewExec$1$2) return exports$1$2; + _dewExec$1$2 = true; + exports$1$2 = PassThrough; + + var Transform = dew$2$2(); + + dew$f$2()(PassThrough, Transform); + + function PassThrough(options) { + if (!(this instanceof PassThrough)) return new PassThrough(options); + Transform.call(this, options); + } + + PassThrough.prototype._transform = function (chunk, encoding, cb) { + cb(null, chunk); + }; + + return exports$1$2; +} + +var exports$2C = {}, + _dewExec$2B = false; +function dew$2B() { + if (_dewExec$2B) return exports$2C; + _dewExec$2B = true; + var eos; + + function once(callback) { + var called = false; + return function () { + if (called) return; + called = true; + callback.apply(void 0, arguments); + }; + } + + var _require$codes = dew$b$2().codes, + ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, + ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED; + + function noop(err) { + // Rethrow the error if it exists to avoid swallowing it + if (err) throw err; + } + + function isRequest(stream) { + return stream.setHeader && typeof stream.abort === "function"; + } + + function destroyer(stream, reading, writing, callback) { + callback = once(callback); + var closed = false; + stream.on("close", function () { + closed = true; + }); + if (eos === undefined) eos = dew$6$2(); + eos(stream, { + readable: reading, + writable: writing + }, function (err) { + if (err) return callback(err); + closed = true; + callback(); + }); + var destroyed = false; + return function (err) { + if (closed) return; + if (destroyed) return; + destroyed = true; // request.destroy just do .end - .abort is what we want + + if (isRequest(stream)) return stream.abort(); + if (typeof stream.destroy === "function") return stream.destroy(); + callback(err || new ERR_STREAM_DESTROYED("pipe")); + }; + } + + function call(fn) { + fn(); + } + + function pipe(from, to) { + return from.pipe(to); + } + + function popCallback(streams) { + if (!streams.length) return noop; + if (typeof streams[streams.length - 1] !== "function") return noop; + return streams.pop(); + } + + function pipeline() { + for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) { + streams[_key] = arguments[_key]; + } + + var callback = popCallback(streams); + if (Array.isArray(streams[0])) streams = streams[0]; + + if (streams.length < 2) { + throw new ERR_MISSING_ARGS("streams"); + } + + var error; + var destroys = streams.map(function (stream, i) { + var reading = i < streams.length - 1; + var writing = i > 0; + return destroyer(stream, reading, writing, function (err) { + if (!error) error = err; + if (err) destroys.forEach(call); + if (reading) return; + destroys.forEach(call); + callback(error); + }); + }); + return streams.reduce(pipe); + } + + exports$2C = pipeline; + return exports$2C; +} + +var exports$2B = {}, + _dewExec$2A = false; + +var _global$L = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2A() { + if (_dewExec$2A) return exports$2B; + _dewExec$2A = true; + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + exports$2B = Stream; + var EE = y$o.EventEmitter; + + var inherits = dew$f$2(); + + inherits(Stream, EE); + Stream.Readable = dew$3$2(); + Stream.Writable = dew$8$2(); + Stream.Duplex = dew$7$2(); + Stream.Transform = dew$2$2(); + Stream.PassThrough = dew$1$2(); + Stream.finished = dew$6$2(); + Stream.pipeline = dew$2B(); // Backwards-compat with node 0.4.x + + Stream.Stream = Stream; // old-style streams. Note that the pipe method (the only relevant + // part of this class) is overridden in the Readable class. + + function Stream() { + EE.call(this || _global$L); + } + + Stream.prototype.pipe = function (dest, options) { + var source = this || _global$L; + + function ondata(chunk) { + if (dest.writable) { + if (false === dest.write(chunk) && source.pause) { + source.pause(); + } + } + } + + source.on("data", ondata); + + function ondrain() { + if (source.readable && source.resume) { + source.resume(); + } + } + + dest.on("drain", ondrain); // If the 'end' option is not supplied, dest.end() will be called when + // source gets the 'end' or 'close' events. Only dest.end() once. + + if (!dest._isStdio && (!options || options.end !== false)) { + source.on("end", onend); + source.on("close", onclose); + } + + var didOnEnd = false; + + function onend() { + if (didOnEnd) return; + didOnEnd = true; + dest.end(); + } + + function onclose() { + if (didOnEnd) return; + didOnEnd = true; + if (typeof dest.destroy === "function") dest.destroy(); + } // don't leave dangling pipes when there are errors. + + + function onerror(er) { + cleanup(); + + if (EE.listenerCount(this || _global$L, "error") === 0) { + throw er; // Unhandled stream error in pipe. + } + } + + source.on("error", onerror); + dest.on("error", onerror); // remove all the event listeners that were added. + + function cleanup() { + source.removeListener("data", ondata); + dest.removeListener("drain", ondrain); + source.removeListener("end", onend); + source.removeListener("close", onclose); + source.removeListener("error", onerror); + dest.removeListener("error", onerror); + source.removeListener("end", cleanup); + source.removeListener("close", cleanup); + dest.removeListener("close", cleanup); + } + + source.on("end", cleanup); + source.on("close", cleanup); + dest.on("close", cleanup); + dest.emit("pipe", source); // Allow for unix-like usage: A.pipe(B).pipe(C) + + return dest; + }; + + return exports$2B; +} + +var stream = dew$2A(); + +stream.Readable; +stream.Writable; +stream.Duplex; +stream.Transform; +stream.PassThrough; +stream.finished; +stream.pipeline; +stream.Stream; + +({ + finished: promisify(stream.finished), + pipeline: promisify(stream.pipeline) +}); + +var exports$2A = {}, + _dewExec$2z = false; + +var _global$K = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2z() { + if (_dewExec$2z) return exports$2A; + _dewExec$2z = true; + + var Buffer = dew$2P().Buffer; + + var Transform = stream.Transform; + var StringDecoder = e$1$2.StringDecoder; + + var inherits = dew$f$4(); + + function CipherBase(hashMode) { + Transform.call(this || _global$K); + (this || _global$K).hashMode = typeof hashMode === "string"; + + if ((this || _global$K).hashMode) { + (this || _global$K)[hashMode] = (this || _global$K)._finalOrDigest; + } else { + (this || _global$K).final = (this || _global$K)._finalOrDigest; + } + + if ((this || _global$K)._final) { + (this || _global$K).__final = (this || _global$K)._final; + (this || _global$K)._final = null; + } + + (this || _global$K)._decoder = null; + (this || _global$K)._encoding = null; + } + + inherits(CipherBase, Transform); + + CipherBase.prototype.update = function (data, inputEnc, outputEnc) { + if (typeof data === "string") { + data = Buffer.from(data, inputEnc); + } + + var outData = this._update(data); + + if ((this || _global$K).hashMode) return this || _global$K; + + if (outputEnc) { + outData = this._toString(outData, outputEnc); + } + + return outData; + }; + + CipherBase.prototype.setAutoPadding = function () {}; + + CipherBase.prototype.getAuthTag = function () { + throw new Error("trying to get auth tag in unsupported state"); + }; + + CipherBase.prototype.setAuthTag = function () { + throw new Error("trying to set auth tag in unsupported state"); + }; + + CipherBase.prototype.setAAD = function () { + throw new Error("trying to set aad in unsupported state"); + }; + + CipherBase.prototype._transform = function (data, _, next) { + var err; + + try { + if ((this || _global$K).hashMode) { + this._update(data); + } else { + this.push(this._update(data)); + } + } catch (e) { + err = e; + } finally { + next(err); + } + }; + + CipherBase.prototype._flush = function (done) { + var err; + + try { + this.push(this.__final()); + } catch (e) { + err = e; + } + + done(err); + }; + + CipherBase.prototype._finalOrDigest = function (outputEnc) { + var outData = this.__final() || Buffer.alloc(0); + + if (outputEnc) { + outData = this._toString(outData, outputEnc, true); + } + + return outData; + }; + + CipherBase.prototype._toString = function (value, enc, fin) { + if (!(this || _global$K)._decoder) { + (this || _global$K)._decoder = new StringDecoder(enc); + (this || _global$K)._encoding = enc; + } + + if ((this || _global$K)._encoding !== enc) throw new Error("can't switch encodings"); + + var out = (this || _global$K)._decoder.write(value); + + if (fin) { + out += (this || _global$K)._decoder.end(); + } + + return out; + }; + + exports$2A = CipherBase; + return exports$2A; +} + +var exports$2z = {}, + _dewExec$2y = false; +function dew$2y() { + if (_dewExec$2y) return exports$2z; + _dewExec$2y = true; + + var inherits = dew$f$4(); + + var MD5 = dew$2L(); + + var RIPEMD160 = dew$2K(); + + var sha = dew$2C(); + + var Base = dew$2z(); + + function Hash(hash) { + Base.call(this, "digest"); + this._hash = hash; + } + + inherits(Hash, Base); + + Hash.prototype._update = function (data) { + this._hash.update(data); + }; + + Hash.prototype._final = function () { + return this._hash.digest(); + }; + + exports$2z = function createHash(alg) { + alg = alg.toLowerCase(); + if (alg === "md5") return new MD5(); + if (alg === "rmd160" || alg === "ripemd160") return new RIPEMD160(); + return new Hash(sha(alg)); + }; + + return exports$2z; +} + +var exports$2y = {}, + _dewExec$2x = false; +function dew$2x() { + if (_dewExec$2x) return exports$2y; + _dewExec$2x = true; + + var inherits = dew$f$4(); + + var Buffer = dew$2P().Buffer; + + var Base = dew$2z(); + + var ZEROS = Buffer.alloc(128); + var blocksize = 64; + + function Hmac(alg, key) { + Base.call(this, "digest"); + + if (typeof key === "string") { + key = Buffer.from(key); + } + + this._alg = alg; + this._key = key; + + if (key.length > blocksize) { + key = alg(key); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + + var ipad = this._ipad = Buffer.allocUnsafe(blocksize); + var opad = this._opad = Buffer.allocUnsafe(blocksize); + + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + + this._hash = [ipad]; + } + + inherits(Hmac, Base); + + Hmac.prototype._update = function (data) { + this._hash.push(data); + }; + + Hmac.prototype._final = function () { + var h = this._alg(Buffer.concat(this._hash)); + + return this._alg(Buffer.concat([this._opad, h])); + }; + + exports$2y = Hmac; + return exports$2y; +} + +var exports$2x = {}, + _dewExec$2w = false; +function dew$2w() { + if (_dewExec$2w) return exports$2x; + _dewExec$2w = true; + + var MD5 = dew$2L(); + + exports$2x = function (buffer) { + return new MD5().update(buffer).digest(); + }; + + return exports$2x; +} + +var exports$2w = {}, + _dewExec$2v = false; +function dew$2v() { + if (_dewExec$2v) return exports$2w; + _dewExec$2v = true; + + var inherits = dew$f$4(); + + var Legacy = dew$2x(); + + var Base = dew$2z(); + + var Buffer = dew$2P().Buffer; + + var md5 = dew$2w(); + + var RIPEMD160 = dew$2K(); + + var sha = dew$2C(); + + var ZEROS = Buffer.alloc(128); + + function Hmac(alg, key) { + Base.call(this, "digest"); + + if (typeof key === "string") { + key = Buffer.from(key); + } + + var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + this._alg = alg; + this._key = key; + + if (key.length > blocksize) { + var hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + key = hash.update(key).digest(); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + + var ipad = this._ipad = Buffer.allocUnsafe(blocksize); + var opad = this._opad = Buffer.allocUnsafe(blocksize); + + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + + this._hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + + this._hash.update(ipad); + } + + inherits(Hmac, Base); + + Hmac.prototype._update = function (data) { + this._hash.update(data); + }; + + Hmac.prototype._final = function () { + var h = this._hash.digest(); + + var hash = this._alg === "rmd160" ? new RIPEMD160() : sha(this._alg); + return hash.update(this._opad).update(h).digest(); + }; + + exports$2w = function createHmac(alg, key) { + alg = alg.toLowerCase(); + + if (alg === "rmd160" || alg === "ripemd160") { + return new Hmac("rmd160", key); + } + + if (alg === "md5") { + return new Legacy(md5, key); + } + + return new Hmac(alg, key); + }; + + return exports$2w; +} + +var _algorithms$1 = { + "sha224WithRSAEncryption": { + "sign": "rsa", + "hash": "sha224", + "id": "302d300d06096086480165030402040500041c" + }, + "RSA-SHA224": { + "sign": "ecdsa/rsa", + "hash": "sha224", + "id": "302d300d06096086480165030402040500041c" + }, + "sha256WithRSAEncryption": { + "sign": "rsa", + "hash": "sha256", + "id": "3031300d060960864801650304020105000420" + }, + "RSA-SHA256": { + "sign": "ecdsa/rsa", + "hash": "sha256", + "id": "3031300d060960864801650304020105000420" + }, + "sha384WithRSAEncryption": { + "sign": "rsa", + "hash": "sha384", + "id": "3041300d060960864801650304020205000430" + }, + "RSA-SHA384": { + "sign": "ecdsa/rsa", + "hash": "sha384", + "id": "3041300d060960864801650304020205000430" + }, + "sha512WithRSAEncryption": { + "sign": "rsa", + "hash": "sha512", + "id": "3051300d060960864801650304020305000440" + }, + "RSA-SHA512": { + "sign": "ecdsa/rsa", + "hash": "sha512", + "id": "3051300d060960864801650304020305000440" + }, + "RSA-SHA1": { + "sign": "rsa", + "hash": "sha1", + "id": "3021300906052b0e03021a05000414" + }, + "ecdsa-with-SHA1": { + "sign": "ecdsa", + "hash": "sha1", + "id": "" + }, + "sha256": { + "sign": "ecdsa", + "hash": "sha256", + "id": "" + }, + "sha224": { + "sign": "ecdsa", + "hash": "sha224", + "id": "" + }, + "sha384": { + "sign": "ecdsa", + "hash": "sha384", + "id": "" + }, + "sha512": { + "sign": "ecdsa", + "hash": "sha512", + "id": "" + }, + "DSA-SHA": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA-SHA1": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA-WITH-SHA224": { + "sign": "dsa", + "hash": "sha224", + "id": "" + }, + "DSA-SHA224": { + "sign": "dsa", + "hash": "sha224", + "id": "" + }, + "DSA-WITH-SHA256": { + "sign": "dsa", + "hash": "sha256", + "id": "" + }, + "DSA-SHA256": { + "sign": "dsa", + "hash": "sha256", + "id": "" + }, + "DSA-WITH-SHA384": { + "sign": "dsa", + "hash": "sha384", + "id": "" + }, + "DSA-SHA384": { + "sign": "dsa", + "hash": "sha384", + "id": "" + }, + "DSA-WITH-SHA512": { + "sign": "dsa", + "hash": "sha512", + "id": "" + }, + "DSA-SHA512": { + "sign": "dsa", + "hash": "sha512", + "id": "" + }, + "DSA-RIPEMD160": { + "sign": "dsa", + "hash": "rmd160", + "id": "" + }, + "ripemd160WithRSA": { + "sign": "rsa", + "hash": "rmd160", + "id": "3021300906052b2403020105000414" + }, + "RSA-RIPEMD160": { + "sign": "rsa", + "hash": "rmd160", + "id": "3021300906052b2403020105000414" + }, + "md5WithRSAEncryption": { + "sign": "rsa", + "hash": "md5", + "id": "3020300c06082a864886f70d020505000410" + }, + "RSA-MD5": { + "sign": "rsa", + "hash": "md5", + "id": "3020300c06082a864886f70d020505000410" + } +}; + +var exports$2v = {}, + _dewExec$2u = false; +function dew$2u() { + if (_dewExec$2u) return exports$2v; + _dewExec$2u = true; + exports$2v = _algorithms$1; + return exports$2v; +} + +var exports$2u = {}, + _dewExec$2t = false; +function dew$2t() { + if (_dewExec$2t) return exports$2u; + _dewExec$2t = true; + var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs + + exports$2u = function (iterations, keylen) { + if (typeof iterations !== "number") { + throw new TypeError("Iterations not a number"); + } + + if (iterations < 0) { + throw new TypeError("Bad iterations"); + } + + if (typeof keylen !== "number") { + throw new TypeError("Key length not a number"); + } + + if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { + /* eslint no-self-compare: 0 */ + throw new TypeError("Bad key length"); + } + }; + + return exports$2u; +} + +var exports$2t = {}, + _dewExec$2s = false; + +var _global$J = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2s() { + if (_dewExec$2s) return exports$2t; + _dewExec$2s = true; + var process$1$1 = process$1; + var defaultEncoding; + /* istanbul ignore next */ + + if (_global$J.process && _global$J.process.browser) { + defaultEncoding = "utf-8"; + } else if (_global$J.process && _global$J.process.version) { + var pVersionMajor = parseInt(process$1$1.version.split(".")[0].slice(1), 10); + defaultEncoding = pVersionMajor >= 6 ? "utf-8" : "binary"; + } else { + defaultEncoding = "utf-8"; + } + + exports$2t = defaultEncoding; + return exports$2t; +} + +var exports$2s = {}, + _dewExec$2r = false; +function dew$2r() { + if (_dewExec$2r) return exports$2s; + _dewExec$2r = true; + + var Buffer = dew$2P().Buffer; + + exports$2s = function (thing, encoding, name) { + if (Buffer.isBuffer(thing)) { + return thing; + } else if (typeof thing === "string") { + return Buffer.from(thing, encoding); + } else if (ArrayBuffer.isView(thing)) { + return Buffer.from(thing.buffer); + } else { + throw new TypeError(name + " must be a string, a Buffer, a typed array or a DataView"); + } + }; + + return exports$2s; +} + +var exports$2r = {}, + _dewExec$2q = false; + +var _global$I = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2q() { + if (_dewExec$2q) return exports$2r; + _dewExec$2q = true; + + var md5 = dew$2w(); + + var RIPEMD160 = dew$2K(); + + var sha = dew$2C(); + + var Buffer = dew$2P().Buffer; + + var checkParameters = dew$2t(); + + var defaultEncoding = dew$2s(); + + var toBuffer = dew$2r(); + + var ZEROS = Buffer.alloc(128); + var sizes = { + md5: 16, + sha1: 20, + sha224: 28, + sha256: 32, + sha384: 48, + sha512: 64, + rmd160: 20, + ripemd160: 20 + }; + + function Hmac(alg, key, saltLen) { + var hash = getDigest(alg); + var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + + if (key.length > blocksize) { + key = hash(key); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + + var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]); + var opad = Buffer.allocUnsafe(blocksize + sizes[alg]); + + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + + var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4); + ipad.copy(ipad1, 0, 0, blocksize); + (this || _global$I).ipad1 = ipad1; + (this || _global$I).ipad2 = ipad; + (this || _global$I).opad = opad; + (this || _global$I).alg = alg; + (this || _global$I).blocksize = blocksize; + (this || _global$I).hash = hash; + (this || _global$I).size = sizes[alg]; + } + + Hmac.prototype.run = function (data, ipad) { + data.copy(ipad, (this || _global$I).blocksize); + var h = this.hash(ipad); + h.copy((this || _global$I).opad, (this || _global$I).blocksize); + return this.hash((this || _global$I).opad); + }; + + function getDigest(alg) { + function shaFunc(data) { + return sha(alg).update(data).digest(); + } + + function rmd160Func(data) { + return new RIPEMD160().update(data).digest(); + } + + if (alg === "rmd160" || alg === "ripemd160") return rmd160Func; + if (alg === "md5") return md5; + return shaFunc; + } + + function pbkdf2(password, salt, iterations, keylen, digest) { + checkParameters(iterations, keylen); + password = toBuffer(password, defaultEncoding, "Password"); + salt = toBuffer(salt, defaultEncoding, "Salt"); + digest = digest || "sha1"; + var hmac = new Hmac(digest, password, salt.length); + var DK = Buffer.allocUnsafe(keylen); + var block1 = Buffer.allocUnsafe(salt.length + 4); + salt.copy(block1, 0, 0, salt.length); + var destPos = 0; + var hLen = sizes[digest]; + var l = Math.ceil(keylen / hLen); + + for (var i = 1; i <= l; i++) { + block1.writeUInt32BE(i, salt.length); + var T = hmac.run(block1, hmac.ipad1); + var U = T; + + for (var j = 1; j < iterations; j++) { + U = hmac.run(U, hmac.ipad2); + + for (var k = 0; k < hLen; k++) T[k] ^= U[k]; + } + + T.copy(DK, destPos); + destPos += hLen; + } + + return DK; + } + + exports$2r = pbkdf2; + return exports$2r; +} + +var exports$2q = {}, + _dewExec$2p = false; + +var _global$H = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2p() { + if (_dewExec$2p) return exports$2q; + _dewExec$2p = true; + + var Buffer = dew$2P().Buffer; + + var checkParameters = dew$2t(); + + var defaultEncoding = dew$2s(); + + var sync = dew$2q(); + + var toBuffer = dew$2r(); + + var ZERO_BUF; + var subtle = _global$H.crypto && _global$H.crypto.subtle; + var toBrowser = { + sha: "SHA-1", + "sha-1": "SHA-1", + sha1: "SHA-1", + sha256: "SHA-256", + "sha-256": "SHA-256", + sha384: "SHA-384", + "sha-384": "SHA-384", + "sha-512": "SHA-512", + sha512: "SHA-512" + }; + var checks = []; + + function checkNative(algo) { + if (_global$H.process && !_global$H.process.browser) { + return Promise.resolve(false); + } + + if (!subtle || !subtle.importKey || !subtle.deriveBits) { + return Promise.resolve(false); + } + + if (checks[algo] !== undefined) { + return checks[algo]; + } + + ZERO_BUF = ZERO_BUF || Buffer.alloc(8); + var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () { + return true; + }).catch(function () { + return false; + }); + checks[algo] = prom; + return prom; + } + + var nextTick; + + function getNextTick() { + if (nextTick) { + return nextTick; + } + + if (_global$H.process && _global$H.process.nextTick) { + nextTick = _global$H.process.nextTick; + } else if (_global$H.queueMicrotask) { + nextTick = _global$H.queueMicrotask; + } else if (_global$H.setImmediate) { + nextTick = _global$H.setImmediate; + } else { + nextTick = _global$H.setTimeout; + } + + return nextTick; + } + + function browserPbkdf2(password, salt, iterations, length, algo) { + return subtle.importKey("raw", password, { + name: "PBKDF2" + }, false, ["deriveBits"]).then(function (key) { + return subtle.deriveBits({ + name: "PBKDF2", + salt: salt, + iterations: iterations, + hash: { + name: algo + } + }, key, length << 3); + }).then(function (res) { + return Buffer.from(res); + }); + } + + function resolvePromise(promise, callback) { + promise.then(function (out) { + getNextTick()(function () { + callback(null, out); + }); + }, function (e) { + getNextTick()(function () { + callback(e); + }); + }); + } + + exports$2q = function (password, salt, iterations, keylen, digest, callback) { + if (typeof digest === "function") { + callback = digest; + digest = undefined; + } + + digest = digest || "sha1"; + var algo = toBrowser[digest.toLowerCase()]; + + if (!algo || typeof _global$H.Promise !== "function") { + getNextTick()(function () { + var out; + + try { + out = sync(password, salt, iterations, keylen, digest); + } catch (e) { + return callback(e); + } + + callback(null, out); + }); + return; + } + + checkParameters(iterations, keylen); + password = toBuffer(password, defaultEncoding, "Password"); + salt = toBuffer(salt, defaultEncoding, "Salt"); + if (typeof callback !== "function") throw new Error("No callback provided to pbkdf2"); + resolvePromise(checkNative(algo).then(function (resp) { + if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo); + return sync(password, salt, iterations, keylen, digest); + }), callback); + }; + + return exports$2q; +} + +var exports$2p = {}, + _dewExec$2o = false; +function dew$2o() { + if (_dewExec$2o) return exports$2p; + _dewExec$2o = true; + exports$2p.pbkdf2 = dew$2p(); + exports$2p.pbkdf2Sync = dew$2q(); + return exports$2p; +} + +var exports$2o = {}, + _dewExec$2n = false; +function dew$2n() { + if (_dewExec$2n) return exports$2o; + _dewExec$2n = true; + + exports$2o.readUInt32BE = function readUInt32BE(bytes, off) { + var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off]; + return res >>> 0; + }; + + exports$2o.writeUInt32BE = function writeUInt32BE(bytes, value, off) { + bytes[0 + off] = value >>> 24; + bytes[1 + off] = value >>> 16 & 255; + bytes[2 + off] = value >>> 8 & 255; + bytes[3 + off] = value & 255; + }; + + exports$2o.ip = function ip(inL, inR, out, off) { + var outL = 0; + var outR = 0; + + for (var i = 6; i >= 0; i -= 2) { + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >>> j + i & 1; + } + + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inL >>> j + i & 1; + } + } + + for (var i = 6; i >= 0; i -= 2) { + for (var j = 1; j <= 25; j += 8) { + outR <<= 1; + outR |= inR >>> j + i & 1; + } + + for (var j = 1; j <= 25; j += 8) { + outR <<= 1; + outR |= inL >>> j + i & 1; + } + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$2o.rip = function rip(inL, inR, out, off) { + var outL = 0; + var outR = 0; + + for (var i = 0; i < 4; i++) { + for (var j = 24; j >= 0; j -= 8) { + outL <<= 1; + outL |= inR >>> j + i & 1; + outL <<= 1; + outL |= inL >>> j + i & 1; + } + } + + for (var i = 4; i < 8; i++) { + for (var j = 24; j >= 0; j -= 8) { + outR <<= 1; + outR |= inR >>> j + i & 1; + outR <<= 1; + outR |= inL >>> j + i & 1; + } + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$2o.pc1 = function pc1(inL, inR, out, off) { + var outL = 0; + var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63 + // 6, 14, 22, 30, 39, 47, 55, 63 + // 5, 13, 21, 29, 39, 47, 55, 63 + // 4, 12, 20, 28 + + for (var i = 7; i >= 5; i--) { + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >> j + i & 1; + } + + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inL >> j + i & 1; + } + } + + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >> j + i & 1; + } // 1, 9, 17, 25, 33, 41, 49, 57 + // 2, 10, 18, 26, 34, 42, 50, 58 + // 3, 11, 19, 27, 35, 43, 51, 59 + // 36, 44, 52, 60 + + + for (var i = 1; i <= 3; i++) { + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inR >> j + i & 1; + } + + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inL >> j + i & 1; + } + } + + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inL >> j + i & 1; + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$2o.r28shl = function r28shl(num, shift) { + return num << shift & 268435455 | num >>> 28 - shift; + }; + + var pc2table = [// inL => outL + 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, // inR => outR + 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24]; + + exports$2o.pc2 = function pc2(inL, inR, out, off) { + var outL = 0; + var outR = 0; + var len = pc2table.length >>> 1; + + for (var i = 0; i < len; i++) { + outL <<= 1; + outL |= inL >>> pc2table[i] & 1; + } + + for (var i = len; i < pc2table.length; i++) { + outR <<= 1; + outR |= inR >>> pc2table[i] & 1; + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$2o.expand = function expand(r, out, off) { + var outL = 0; + var outR = 0; + outL = (r & 1) << 5 | r >>> 27; + + for (var i = 23; i >= 15; i -= 4) { + outL <<= 6; + outL |= r >>> i & 63; + } + + for (var i = 11; i >= 3; i -= 4) { + outR |= r >>> i & 63; + outR <<= 6; + } + + outR |= (r & 31) << 1 | r >>> 31; + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11]; + + exports$2o.substitute = function substitute(inL, inR) { + var out = 0; + + for (var i = 0; i < 4; i++) { + var b = inL >>> 18 - i * 6 & 63; + var sb = sTable[i * 64 + b]; + out <<= 4; + out |= sb; + } + + for (var i = 0; i < 4; i++) { + var b = inR >>> 18 - i * 6 & 63; + var sb = sTable[4 * 64 + i * 64 + b]; + out <<= 4; + out |= sb; + } + + return out >>> 0; + }; + + var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7]; + + exports$2o.permute = function permute(num) { + var out = 0; + + for (var i = 0; i < permuteTable.length; i++) { + out <<= 1; + out |= num >>> permuteTable[i] & 1; + } + + return out >>> 0; + }; + + exports$2o.padSplit = function padSplit(num, size, group) { + var str = num.toString(2); + + while (str.length < size) str = "0" + str; + + var out = []; + + for (var i = 0; i < size; i += group) out.push(str.slice(i, i + group)); + + return out.join(" "); + }; + + return exports$2o; +} + +var exports$2n = {}, + _dewExec$2m = false; +function dew$2m() { + if (_dewExec$2m) return exports$2n; + _dewExec$2m = true; + exports$2n = assert; + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } + + assert.equal = function assertEqual(l, r, msg) { + if (l != r) throw new Error(msg || "Assertion failed: " + l + " != " + r); + }; + + return exports$2n; +} + +var exports$2m = {}, + _dewExec$2l = false; +function dew$2l() { + if (_dewExec$2l) return exports$2m; + _dewExec$2l = true; + + var assert = dew$2m(); + + function Cipher(options) { + this.options = options; + this.type = this.options.type; + this.blockSize = 8; + + this._init(); + + this.buffer = new Array(this.blockSize); + this.bufferOff = 0; + } + + exports$2m = Cipher; + + Cipher.prototype._init = function _init() {// Might be overrided + }; + + Cipher.prototype.update = function update(data) { + if (data.length === 0) return []; + if (this.type === "decrypt") return this._updateDecrypt(data);else return this._updateEncrypt(data); + }; + + Cipher.prototype._buffer = function _buffer(data, off) { + // Append data to buffer + var min = Math.min(this.buffer.length - this.bufferOff, data.length - off); + + for (var i = 0; i < min; i++) this.buffer[this.bufferOff + i] = data[off + i]; + + this.bufferOff += min; // Shift next + + return min; + }; + + Cipher.prototype._flushBuffer = function _flushBuffer(out, off) { + this._update(this.buffer, 0, out, off); + + this.bufferOff = 0; + return this.blockSize; + }; + + Cipher.prototype._updateEncrypt = function _updateEncrypt(data) { + var inputOff = 0; + var outputOff = 0; + var count = (this.bufferOff + data.length) / this.blockSize | 0; + var out = new Array(count * this.blockSize); + + if (this.bufferOff !== 0) { + inputOff += this._buffer(data, inputOff); + if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff); + } // Write blocks + + + var max = data.length - (data.length - inputOff) % this.blockSize; + + for (; inputOff < max; inputOff += this.blockSize) { + this._update(data, inputOff, out, outputOff); + + outputOff += this.blockSize; + } // Queue rest + + + for (; inputOff < data.length; inputOff++, this.bufferOff++) this.buffer[this.bufferOff] = data[inputOff]; + + return out; + }; + + Cipher.prototype._updateDecrypt = function _updateDecrypt(data) { + var inputOff = 0; + var outputOff = 0; + var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1; + var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal + + for (; count > 0; count--) { + inputOff += this._buffer(data, inputOff); + outputOff += this._flushBuffer(out, outputOff); + } // Buffer rest of the input + + + inputOff += this._buffer(data, inputOff); + return out; + }; + + Cipher.prototype.final = function final(buffer) { + var first; + if (buffer) first = this.update(buffer); + var last; + if (this.type === "encrypt") last = this._finalEncrypt();else last = this._finalDecrypt(); + if (first) return first.concat(last);else return last; + }; + + Cipher.prototype._pad = function _pad(buffer, off) { + if (off === 0) return false; + + while (off < buffer.length) buffer[off++] = 0; + + return true; + }; + + Cipher.prototype._finalEncrypt = function _finalEncrypt() { + if (!this._pad(this.buffer, this.bufferOff)) return []; + var out = new Array(this.blockSize); + + this._update(this.buffer, 0, out, 0); + + return out; + }; + + Cipher.prototype._unpad = function _unpad(buffer) { + return buffer; + }; + + Cipher.prototype._finalDecrypt = function _finalDecrypt() { + assert.equal(this.bufferOff, this.blockSize, "Not enough data to decrypt"); + var out = new Array(this.blockSize); + + this._flushBuffer(out, 0); + + return this._unpad(out); + }; + + return exports$2m; +} + +var exports$2l = {}, + _dewExec$2k = false; +function dew$2k() { + if (_dewExec$2k) return exports$2l; + _dewExec$2k = true; + + var assert = dew$2m(); + + var inherits = dew$f$4(); + + var utils = dew$2n(); + + var Cipher = dew$2l(); + + function DESState() { + this.tmp = new Array(2); + this.keys = null; + } + + function DES(options) { + Cipher.call(this, options); + var state = new DESState(); + this._desState = state; + this.deriveKeys(state, options.key); + } + + inherits(DES, Cipher); + exports$2l = DES; + + DES.create = function create(options) { + return new DES(options); + }; + + var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]; + + DES.prototype.deriveKeys = function deriveKeys(state, key) { + state.keys = new Array(16 * 2); + assert.equal(key.length, this.blockSize, "Invalid key length"); + var kL = utils.readUInt32BE(key, 0); + var kR = utils.readUInt32BE(key, 4); + utils.pc1(kL, kR, state.tmp, 0); + kL = state.tmp[0]; + kR = state.tmp[1]; + + for (var i = 0; i < state.keys.length; i += 2) { + var shift = shiftTable[i >>> 1]; + kL = utils.r28shl(kL, shift); + kR = utils.r28shl(kR, shift); + utils.pc2(kL, kR, state.keys, i); + } + }; + + DES.prototype._update = function _update(inp, inOff, out, outOff) { + var state = this._desState; + var l = utils.readUInt32BE(inp, inOff); + var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation + + utils.ip(l, r, state.tmp, 0); + l = state.tmp[0]; + r = state.tmp[1]; + if (this.type === "encrypt") this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0); + l = state.tmp[0]; + r = state.tmp[1]; + utils.writeUInt32BE(out, l, outOff); + utils.writeUInt32BE(out, r, outOff + 4); + }; + + DES.prototype._pad = function _pad(buffer, off) { + var value = buffer.length - off; + + for (var i = off; i < buffer.length; i++) buffer[i] = value; + + return true; + }; + + DES.prototype._unpad = function _unpad(buffer) { + var pad = buffer[buffer.length - 1]; + + for (var i = buffer.length - pad; i < buffer.length; i++) assert.equal(buffer[i], pad); + + return buffer.slice(0, buffer.length - pad); + }; + + DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) { + var l = lStart; + var r = rStart; // Apply f() x16 times + + for (var i = 0; i < state.keys.length; i += 2) { + var keyL = state.keys[i]; + var keyR = state.keys[i + 1]; // f(r, k) + + utils.expand(r, state.tmp, 0); + keyL ^= state.tmp[0]; + keyR ^= state.tmp[1]; + var s = utils.substitute(keyL, keyR); + var f = utils.permute(s); + var t = r; + r = (l ^ f) >>> 0; + l = t; + } // Reverse Initial Permutation + + + utils.rip(r, l, out, off); + }; + + DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) { + var l = rStart; + var r = lStart; // Apply f() x16 times + + for (var i = state.keys.length - 2; i >= 0; i -= 2) { + var keyL = state.keys[i]; + var keyR = state.keys[i + 1]; // f(r, k) + + utils.expand(l, state.tmp, 0); + keyL ^= state.tmp[0]; + keyR ^= state.tmp[1]; + var s = utils.substitute(keyL, keyR); + var f = utils.permute(s); + var t = l; + l = (r ^ f) >>> 0; + r = t; + } // Reverse Initial Permutation + + + utils.rip(l, r, out, off); + }; + + return exports$2l; +} + +var exports$2k = {}, + _dewExec$2j = false; +function dew$2j() { + if (_dewExec$2j) return exports$2k; + _dewExec$2j = true; + + var assert = dew$2m(); + + var inherits = dew$f$4(); + + var proto = {}; + + function CBCState(iv) { + assert.equal(iv.length, 8, "Invalid IV length"); + this.iv = new Array(8); + + for (var i = 0; i < this.iv.length; i++) this.iv[i] = iv[i]; + } + + function instantiate(Base) { + function CBC(options) { + Base.call(this, options); + + this._cbcInit(); + } + + inherits(CBC, Base); + var keys = Object.keys(proto); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + CBC.prototype[key] = proto[key]; + } + + CBC.create = function create(options) { + return new CBC(options); + }; + + return CBC; + } + + exports$2k.instantiate = instantiate; + + proto._cbcInit = function _cbcInit() { + var state = new CBCState(this.options.iv); + this._cbcState = state; + }; + + proto._update = function _update(inp, inOff, out, outOff) { + var state = this._cbcState; + var superProto = this.constructor.super_.prototype; + var iv = state.iv; + + if (this.type === "encrypt") { + for (var i = 0; i < this.blockSize; i++) iv[i] ^= inp[inOff + i]; + + superProto._update.call(this, iv, 0, out, outOff); + + for (var i = 0; i < this.blockSize; i++) iv[i] = out[outOff + i]; + } else { + superProto._update.call(this, inp, inOff, out, outOff); + + for (var i = 0; i < this.blockSize; i++) out[outOff + i] ^= iv[i]; + + for (var i = 0; i < this.blockSize; i++) iv[i] = inp[inOff + i]; + } + }; + + return exports$2k; +} + +var exports$2j = {}, + _dewExec$2i = false; +function dew$2i() { + if (_dewExec$2i) return exports$2j; + _dewExec$2i = true; + + var assert = dew$2m(); + + var inherits = dew$f$4(); + + var Cipher = dew$2l(); + + var DES = dew$2k(); + + function EDEState(type, key) { + assert.equal(key.length, 24, "Invalid key length"); + var k1 = key.slice(0, 8); + var k2 = key.slice(8, 16); + var k3 = key.slice(16, 24); + + if (type === "encrypt") { + this.ciphers = [DES.create({ + type: "encrypt", + key: k1 + }), DES.create({ + type: "decrypt", + key: k2 + }), DES.create({ + type: "encrypt", + key: k3 + })]; + } else { + this.ciphers = [DES.create({ + type: "decrypt", + key: k3 + }), DES.create({ + type: "encrypt", + key: k2 + }), DES.create({ + type: "decrypt", + key: k1 + })]; + } + } + + function EDE(options) { + Cipher.call(this, options); + var state = new EDEState(this.type, this.options.key); + this._edeState = state; + } + + inherits(EDE, Cipher); + exports$2j = EDE; + + EDE.create = function create(options) { + return new EDE(options); + }; + + EDE.prototype._update = function _update(inp, inOff, out, outOff) { + var state = this._edeState; + + state.ciphers[0]._update(inp, inOff, out, outOff); + + state.ciphers[1]._update(out, outOff, out, outOff); + + state.ciphers[2]._update(out, outOff, out, outOff); + }; + + EDE.prototype._pad = DES.prototype._pad; + EDE.prototype._unpad = DES.prototype._unpad; + return exports$2j; +} + +var exports$2i = {}, + _dewExec$2h = false; +function dew$2h() { + if (_dewExec$2h) return exports$2i; + _dewExec$2h = true; + exports$2i.utils = dew$2n(); + exports$2i.Cipher = dew$2l(); + exports$2i.DES = dew$2k(); + exports$2i.CBC = dew$2j(); + exports$2i.EDE = dew$2i(); + return exports$2i; +} + +var exports$2h = {}, + _dewExec$2g = false; + +var _global$G = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$2g() { + if (_dewExec$2g) return exports$2h; + _dewExec$2g = true; + + var CipherBase = dew$2z(); + + var des = dew$2h(); + + var inherits = dew$f$4(); + + var Buffer = dew$2P().Buffer; + + var modes = { + "des-ede3-cbc": des.CBC.instantiate(des.EDE), + "des-ede3": des.EDE, + "des-ede-cbc": des.CBC.instantiate(des.EDE), + "des-ede": des.EDE, + "des-cbc": des.CBC.instantiate(des.DES), + "des-ecb": des.DES + }; + modes.des = modes["des-cbc"]; + modes.des3 = modes["des-ede3-cbc"]; + exports$2h = DES; + inherits(DES, CipherBase); + + function DES(opts) { + CipherBase.call(this || _global$G); + var modeName = opts.mode.toLowerCase(); + var mode = modes[modeName]; + var type; + + if (opts.decrypt) { + type = "decrypt"; + } else { + type = "encrypt"; + } + + var key = opts.key; + + if (!Buffer.isBuffer(key)) { + key = Buffer.from(key); + } + + if (modeName === "des-ede" || modeName === "des-ede-cbc") { + key = Buffer.concat([key, key.slice(0, 8)]); + } + + var iv = opts.iv; + + if (!Buffer.isBuffer(iv)) { + iv = Buffer.from(iv); + } + + (this || _global$G)._des = mode.create({ + key: key, + iv: iv, + type: type + }); + } + + DES.prototype._update = function (data) { + return Buffer.from((this || _global$G)._des.update(data)); + }; + + DES.prototype._final = function () { + return Buffer.from((this || _global$G)._des.final()); + }; + + return exports$2h; +} + +var exports$2g = {}, + _dewExec$2f = false; +function dew$2f() { + if (_dewExec$2f) return exports$2g; + _dewExec$2f = true; + + exports$2g.encrypt = function (self, block) { + return self._cipher.encryptBlock(block); + }; + + exports$2g.decrypt = function (self, block) { + return self._cipher.decryptBlock(block); + }; + + return exports$2g; +} + +var exports$2f = {}, + _dewExec$2e = false; +function dew$2e() { + if (_dewExec$2e) return exports$2f; + _dewExec$2e = true; + var Buffer = buffer.Buffer; + + exports$2f = function xor(a, b) { + var length = Math.min(a.length, b.length); + var buffer = new Buffer(length); + + for (var i = 0; i < length; ++i) { + buffer[i] = a[i] ^ b[i]; + } + + return buffer; + }; + + return exports$2f; +} + +var exports$2e = {}, + _dewExec$2d = false; +function dew$2d() { + if (_dewExec$2d) return exports$2e; + _dewExec$2d = true; + + var xor = dew$2e(); + + exports$2e.encrypt = function (self, block) { + var data = xor(block, self._prev); + self._prev = self._cipher.encryptBlock(data); + return self._prev; + }; + + exports$2e.decrypt = function (self, block) { + var pad = self._prev; + self._prev = block; + + var out = self._cipher.decryptBlock(block); + + return xor(out, pad); + }; + + return exports$2e; +} + +var exports$2d = {}, + _dewExec$2c = false; +function dew$2c() { + if (_dewExec$2c) return exports$2d; + _dewExec$2c = true; + + var Buffer = dew$2P().Buffer; + + var xor = dew$2e(); + + function encryptStart(self, data, decrypt) { + var len = data.length; + var out = xor(data, self._cache); + self._cache = self._cache.slice(len); + self._prev = Buffer.concat([self._prev, decrypt ? data : out]); + return out; + } + + exports$2d.encrypt = function (self, data, decrypt) { + var out = Buffer.allocUnsafe(0); + var len; + + while (data.length) { + if (self._cache.length === 0) { + self._cache = self._cipher.encryptBlock(self._prev); + self._prev = Buffer.allocUnsafe(0); + } + + if (self._cache.length <= data.length) { + len = self._cache.length; + out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]); + data = data.slice(len); + } else { + out = Buffer.concat([out, encryptStart(self, data, decrypt)]); + break; + } + } + + return out; + }; + + return exports$2d; +} + +var exports$2c = {}, + _dewExec$2b = false; +function dew$2b() { + if (_dewExec$2b) return exports$2c; + _dewExec$2b = true; + + var Buffer = dew$2P().Buffer; + + function encryptByte(self, byteParam, decrypt) { + var pad = self._cipher.encryptBlock(self._prev); + + var out = pad[0] ^ byteParam; + self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]); + return out; + } + + exports$2c.encrypt = function (self, chunk, decrypt) { + var len = chunk.length; + var out = Buffer.allocUnsafe(len); + var i = -1; + + while (++i < len) { + out[i] = encryptByte(self, chunk[i], decrypt); + } + + return out; + }; + + return exports$2c; +} + +var exports$2b = {}, + _dewExec$2a = false; +function dew$2a() { + if (_dewExec$2a) return exports$2b; + _dewExec$2a = true; + + var Buffer = dew$2P().Buffer; + + function encryptByte(self, byteParam, decrypt) { + var pad; + var i = -1; + var len = 8; + var out = 0; + var bit, value; + + while (++i < len) { + pad = self._cipher.encryptBlock(self._prev); + bit = byteParam & 1 << 7 - i ? 128 : 0; + value = pad[0] ^ bit; + out += (value & 128) >> i % 8; + self._prev = shiftIn(self._prev, decrypt ? bit : value); + } + + return out; + } + + function shiftIn(buffer, value) { + var len = buffer.length; + var i = -1; + var out = Buffer.allocUnsafe(buffer.length); + buffer = Buffer.concat([buffer, Buffer.from([value])]); + + while (++i < len) { + out[i] = buffer[i] << 1 | buffer[i + 1] >> 7; + } + + return out; + } + + exports$2b.encrypt = function (self, chunk, decrypt) { + var len = chunk.length; + var out = Buffer.allocUnsafe(len); + var i = -1; + + while (++i < len) { + out[i] = encryptByte(self, chunk[i], decrypt); + } + + return out; + }; + + return exports$2b; +} + +var exports$2a = {}, + _dewExec$29 = false; +function dew$29() { + if (_dewExec$29) return exports$2a; + _dewExec$29 = true; + var Buffer = buffer.Buffer; + + var xor = dew$2e(); + + function getBlock(self) { + self._prev = self._cipher.encryptBlock(self._prev); + return self._prev; + } + + exports$2a.encrypt = function (self, chunk) { + while (self._cache.length < chunk.length) { + self._cache = Buffer.concat([self._cache, getBlock(self)]); + } + + var pad = self._cache.slice(0, chunk.length); + + self._cache = self._cache.slice(chunk.length); + return xor(chunk, pad); + }; + + return exports$2a; +} + +var exports$29 = {}, + _dewExec$28 = false; +function dew$28() { + if (_dewExec$28) return exports$29; + _dewExec$28 = true; + + function incr32(iv) { + var len = iv.length; + var item; + + while (len--) { + item = iv.readUInt8(len); + + if (item === 255) { + iv.writeUInt8(0, len); + } else { + item++; + iv.writeUInt8(item, len); + break; + } + } + } + + exports$29 = incr32; + return exports$29; +} + +var exports$28 = {}, + _dewExec$27 = false; +function dew$27() { + if (_dewExec$27) return exports$28; + _dewExec$27 = true; + + var xor = dew$2e(); + + var Buffer = dew$2P().Buffer; + + var incr32 = dew$28(); + + function getBlock(self) { + var out = self._cipher.encryptBlockRaw(self._prev); + + incr32(self._prev); + return out; + } + + var blockSize = 16; + + exports$28.encrypt = function (self, chunk) { + var chunkNum = Math.ceil(chunk.length / blockSize); + var start = self._cache.length; + self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]); + + for (var i = 0; i < chunkNum; i++) { + var out = getBlock(self); + var offset = start + i * blockSize; + + self._cache.writeUInt32BE(out[0], offset + 0); + + self._cache.writeUInt32BE(out[1], offset + 4); + + self._cache.writeUInt32BE(out[2], offset + 8); + + self._cache.writeUInt32BE(out[3], offset + 12); + } + + var pad = self._cache.slice(0, chunk.length); + + self._cache = self._cache.slice(chunk.length); + return xor(chunk, pad); + }; + + return exports$28; +} + +var _list$1 = { + "aes-128-ecb": { + "cipher": "AES", + "key": 128, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-192-ecb": { + "cipher": "AES", + "key": 192, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-256-ecb": { + "cipher": "AES", + "key": 256, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-128-cbc": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-192-cbc": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-256-cbc": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes128": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes192": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes256": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-128-cfb": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-192-cfb": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-256-cfb": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-128-cfb8": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-192-cfb8": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-256-cfb8": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-128-cfb1": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-192-cfb1": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-256-cfb1": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-128-ofb": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-192-ofb": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-256-ofb": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-128-ctr": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-192-ctr": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-256-ctr": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-128-gcm": { + "cipher": "AES", + "key": 128, + "iv": 12, + "mode": "GCM", + "type": "auth" + }, + "aes-192-gcm": { + "cipher": "AES", + "key": 192, + "iv": 12, + "mode": "GCM", + "type": "auth" + }, + "aes-256-gcm": { + "cipher": "AES", + "key": 256, + "iv": 12, + "mode": "GCM", + "type": "auth" + } +}; + +var exports$27 = {}, + _dewExec$26 = false; +function dew$26() { + if (_dewExec$26) return exports$27; + _dewExec$26 = true; + var modeModules = { + ECB: dew$2f(), + CBC: dew$2d(), + CFB: dew$2c(), + CFB8: dew$2b(), + CFB1: dew$2a(), + OFB: dew$29(), + CTR: dew$27(), + GCM: dew$27() + }; + var modes = _list$1; + + for (var key in modes) { + modes[key].module = modeModules[modes[key].mode]; + } + + exports$27 = modes; + return exports$27; +} + +var exports$26 = {}, + _dewExec$25 = false; + +var _global$F = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$25() { + if (_dewExec$25) return exports$26; + _dewExec$25 = true; + + // based on the aes implimentation in triple sec + // https://github.com/keybase/triplesec + // which is in turn based on the one from crypto-js + // https://code.google.com/p/crypto-js/ + var Buffer = dew$2P().Buffer; + + function asUInt32Array(buf) { + if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); + var len = buf.length / 4 | 0; + var out = new Array(len); + + for (var i = 0; i < len; i++) { + out[i] = buf.readUInt32BE(i * 4); + } + + return out; + } + + function scrubVec(v) { + for (var i = 0; i < v.length; v++) { + v[i] = 0; + } + } + + function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) { + var SUB_MIX0 = SUB_MIX[0]; + var SUB_MIX1 = SUB_MIX[1]; + var SUB_MIX2 = SUB_MIX[2]; + var SUB_MIX3 = SUB_MIX[3]; + var s0 = M[0] ^ keySchedule[0]; + var s1 = M[1] ^ keySchedule[1]; + var s2 = M[2] ^ keySchedule[2]; + var s3 = M[3] ^ keySchedule[3]; + var t0, t1, t2, t3; + var ksRow = 4; + + for (var round = 1; round < nRounds; round++) { + t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 255] ^ SUB_MIX2[s2 >>> 8 & 255] ^ SUB_MIX3[s3 & 255] ^ keySchedule[ksRow++]; + t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 255] ^ SUB_MIX2[s3 >>> 8 & 255] ^ SUB_MIX3[s0 & 255] ^ keySchedule[ksRow++]; + t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 255] ^ SUB_MIX2[s0 >>> 8 & 255] ^ SUB_MIX3[s1 & 255] ^ keySchedule[ksRow++]; + t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 255] ^ SUB_MIX2[s1 >>> 8 & 255] ^ SUB_MIX3[s2 & 255] ^ keySchedule[ksRow++]; + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 255] << 16 | SBOX[s2 >>> 8 & 255] << 8 | SBOX[s3 & 255]) ^ keySchedule[ksRow++]; + t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 255] << 16 | SBOX[s3 >>> 8 & 255] << 8 | SBOX[s0 & 255]) ^ keySchedule[ksRow++]; + t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 255] << 16 | SBOX[s0 >>> 8 & 255] << 8 | SBOX[s1 & 255]) ^ keySchedule[ksRow++]; + t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 255] << 16 | SBOX[s1 >>> 8 & 255] << 8 | SBOX[s2 & 255]) ^ keySchedule[ksRow++]; + t0 = t0 >>> 0; + t1 = t1 >>> 0; + t2 = t2 >>> 0; + t3 = t3 >>> 0; + return [t0, t1, t2, t3]; + } // AES constants + + + var RCON = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]; + + var G = function () { + // Compute double table + var d = new Array(256); + + for (var j = 0; j < 256; j++) { + if (j < 128) { + d[j] = j << 1; + } else { + d[j] = j << 1 ^ 283; + } + } + + var SBOX = []; + var INV_SBOX = []; + var SUB_MIX = [[], [], [], []]; + var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8) + + var x = 0; + var xi = 0; + + for (var i = 0; i < 256; ++i) { + // Compute sbox + var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4; + sx = sx >>> 8 ^ sx & 255 ^ 99; + SBOX[x] = sx; + INV_SBOX[sx] = x; // Compute multiplication + + var x2 = d[x]; + var x4 = d[x2]; + var x8 = d[x4]; // Compute sub bytes, mix columns tables + + var t = d[sx] * 257 ^ sx * 16843008; + SUB_MIX[0][x] = t << 24 | t >>> 8; + SUB_MIX[1][x] = t << 16 | t >>> 16; + SUB_MIX[2][x] = t << 8 | t >>> 24; + SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables + + t = x8 * 16843009 ^ x4 * 65537 ^ x2 * 257 ^ x * 16843008; + INV_SUB_MIX[0][sx] = t << 24 | t >>> 8; + INV_SUB_MIX[1][sx] = t << 16 | t >>> 16; + INV_SUB_MIX[2][sx] = t << 8 | t >>> 24; + INV_SUB_MIX[3][sx] = t; + + if (x === 0) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } + + return { + SBOX: SBOX, + INV_SBOX: INV_SBOX, + SUB_MIX: SUB_MIX, + INV_SUB_MIX: INV_SUB_MIX + }; + }(); + + function AES(key) { + (this || _global$F)._key = asUInt32Array(key); + + this._reset(); + } + + AES.blockSize = 4 * 4; + AES.keySize = 256 / 8; + AES.prototype.blockSize = AES.blockSize; + AES.prototype.keySize = AES.keySize; + + AES.prototype._reset = function () { + var keyWords = (this || _global$F)._key; + var keySize = keyWords.length; + var nRounds = keySize + 6; + var ksRows = (nRounds + 1) * 4; + var keySchedule = []; + + for (var k = 0; k < keySize; k++) { + keySchedule[k] = keyWords[k]; + } + + for (k = keySize; k < ksRows; k++) { + var t = keySchedule[k - 1]; + + if (k % keySize === 0) { + t = t << 8 | t >>> 24; + t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; + t ^= RCON[k / keySize | 0] << 24; + } else if (keySize > 6 && k % keySize === 4) { + t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; + } + + keySchedule[k] = keySchedule[k - keySize] ^ t; + } + + var invKeySchedule = []; + + for (var ik = 0; ik < ksRows; ik++) { + var ksR = ksRows - ik; + var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]; + + if (ik < 4 || ksR <= 4) { + invKeySchedule[ik] = tt; + } else { + invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 255]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 255]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 255]]; + } + } + + (this || _global$F)._nRounds = nRounds; + (this || _global$F)._keySchedule = keySchedule; + (this || _global$F)._invKeySchedule = invKeySchedule; + }; + + AES.prototype.encryptBlockRaw = function (M) { + M = asUInt32Array(M); + return cryptBlock(M, (this || _global$F)._keySchedule, G.SUB_MIX, G.SBOX, (this || _global$F)._nRounds); + }; + + AES.prototype.encryptBlock = function (M) { + var out = this.encryptBlockRaw(M); + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[1], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[3], 12); + return buf; + }; + + AES.prototype.decryptBlock = function (M) { + M = asUInt32Array(M); // swap + + var m1 = M[1]; + M[1] = M[3]; + M[3] = m1; + var out = cryptBlock(M, (this || _global$F)._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, (this || _global$F)._nRounds); + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[3], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[1], 12); + return buf; + }; + + AES.prototype.scrub = function () { + scrubVec((this || _global$F)._keySchedule); + scrubVec((this || _global$F)._invKeySchedule); + scrubVec((this || _global$F)._key); + }; + + exports$26.AES = AES; + return exports$26; +} + +var exports$25 = {}, + _dewExec$24 = false; + +var _global$E = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$24() { + if (_dewExec$24) return exports$25; + _dewExec$24 = true; + + var Buffer = dew$2P().Buffer; + + var ZEROES = Buffer.alloc(16, 0); + + function toArray(buf) { + return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)]; + } + + function fromArray(out) { + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0] >>> 0, 0); + buf.writeUInt32BE(out[1] >>> 0, 4); + buf.writeUInt32BE(out[2] >>> 0, 8); + buf.writeUInt32BE(out[3] >>> 0, 12); + return buf; + } + + function GHASH(key) { + (this || _global$E).h = key; + (this || _global$E).state = Buffer.alloc(16, 0); + (this || _global$E).cache = Buffer.allocUnsafe(0); + } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html + // by Juho Vähä-Herttua + + + GHASH.prototype.ghash = function (block) { + var i = -1; + + while (++i < block.length) { + (this || _global$E).state[i] ^= block[i]; + } + + this._multiply(); + }; + + GHASH.prototype._multiply = function () { + var Vi = toArray((this || _global$E).h); + var Zi = [0, 0, 0, 0]; + var j, xi, lsbVi; + var i = -1; + + while (++i < 128) { + xi = ((this || _global$E).state[~~(i / 8)] & 1 << 7 - i % 8) !== 0; + + if (xi) { + // Z_i+1 = Z_i ^ V_i + Zi[0] ^= Vi[0]; + Zi[1] ^= Vi[1]; + Zi[2] ^= Vi[2]; + Zi[3] ^= Vi[3]; + } // Store the value of LSB(V_i) + + + lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1 + + for (j = 3; j > 0; j--) { + Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31; + } + + Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R + + if (lsbVi) { + Vi[0] = Vi[0] ^ 225 << 24; + } + } + + (this || _global$E).state = fromArray(Zi); + }; + + GHASH.prototype.update = function (buf) { + (this || _global$E).cache = Buffer.concat([(this || _global$E).cache, buf]); + var chunk; + + while ((this || _global$E).cache.length >= 16) { + chunk = (this || _global$E).cache.slice(0, 16); + (this || _global$E).cache = (this || _global$E).cache.slice(16); + this.ghash(chunk); + } + }; + + GHASH.prototype.final = function (abl, bl) { + if ((this || _global$E).cache.length) { + this.ghash(Buffer.concat([(this || _global$E).cache, ZEROES], 16)); + } + + this.ghash(fromArray([0, abl, 0, bl])); + return (this || _global$E).state; + }; + + exports$25 = GHASH; + return exports$25; +} + +var exports$24 = {}, + _dewExec$23 = false; + +var _global$D = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$23() { + if (_dewExec$23) return exports$24; + _dewExec$23 = true; + + var aes = dew$25(); + + var Buffer = dew$2P().Buffer; + + var Transform = dew$2z(); + + var inherits = dew$f$4(); + + var GHASH = dew$24(); + + var xor = dew$2e(); + + var incr32 = dew$28(); + + function xorTest(a, b) { + var out = 0; + if (a.length !== b.length) out++; + var len = Math.min(a.length, b.length); + + for (var i = 0; i < len; ++i) { + out += a[i] ^ b[i]; + } + + return out; + } + + function calcIv(self, iv, ck) { + if (iv.length === 12) { + self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]); + return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]); + } + + var ghash = new GHASH(ck); + var len = iv.length; + var toPad = len % 16; + ghash.update(iv); + + if (toPad) { + toPad = 16 - toPad; + ghash.update(Buffer.alloc(toPad, 0)); + } + + ghash.update(Buffer.alloc(8, 0)); + var ivBits = len * 8; + var tail = Buffer.alloc(8); + tail.writeUIntBE(ivBits, 0, 8); + ghash.update(tail); + self._finID = ghash.state; + var out = Buffer.from(self._finID); + incr32(out); + return out; + } + + function StreamCipher(mode, key, iv, decrypt) { + Transform.call(this || _global$D); + var h = Buffer.alloc(4, 0); + (this || _global$D)._cipher = new aes.AES(key); + + var ck = (this || _global$D)._cipher.encryptBlock(h); + + (this || _global$D)._ghash = new GHASH(ck); + iv = calcIv(this || _global$D, iv, ck); + (this || _global$D)._prev = Buffer.from(iv); + (this || _global$D)._cache = Buffer.allocUnsafe(0); + (this || _global$D)._secCache = Buffer.allocUnsafe(0); + (this || _global$D)._decrypt = decrypt; + (this || _global$D)._alen = 0; + (this || _global$D)._len = 0; + (this || _global$D)._mode = mode; + (this || _global$D)._authTag = null; + (this || _global$D)._called = false; + } + + inherits(StreamCipher, Transform); + + StreamCipher.prototype._update = function (chunk) { + if (!(this || _global$D)._called && (this || _global$D)._alen) { + var rump = 16 - (this || _global$D)._alen % 16; + + if (rump < 16) { + rump = Buffer.alloc(rump, 0); + + (this || _global$D)._ghash.update(rump); + } + } + + (this || _global$D)._called = true; + + var out = (this || _global$D)._mode.encrypt(this || _global$D, chunk); + + if ((this || _global$D)._decrypt) { + (this || _global$D)._ghash.update(chunk); + } else { + (this || _global$D)._ghash.update(out); + } + + (this || _global$D)._len += chunk.length; + return out; + }; + + StreamCipher.prototype._final = function () { + if ((this || _global$D)._decrypt && !(this || _global$D)._authTag) throw new Error("Unsupported state or unable to authenticate data"); + var tag = xor((this || _global$D)._ghash.final((this || _global$D)._alen * 8, (this || _global$D)._len * 8), (this || _global$D)._cipher.encryptBlock((this || _global$D)._finID)); + if ((this || _global$D)._decrypt && xorTest(tag, (this || _global$D)._authTag)) throw new Error("Unsupported state or unable to authenticate data"); + (this || _global$D)._authTag = tag; + + (this || _global$D)._cipher.scrub(); + }; + + StreamCipher.prototype.getAuthTag = function getAuthTag() { + if ((this || _global$D)._decrypt || !Buffer.isBuffer((this || _global$D)._authTag)) throw new Error("Attempting to get auth tag in unsupported state"); + return (this || _global$D)._authTag; + }; + + StreamCipher.prototype.setAuthTag = function setAuthTag(tag) { + if (!(this || _global$D)._decrypt) throw new Error("Attempting to set auth tag in unsupported state"); + (this || _global$D)._authTag = tag; + }; + + StreamCipher.prototype.setAAD = function setAAD(buf) { + if ((this || _global$D)._called) throw new Error("Attempting to set AAD in unsupported state"); + + (this || _global$D)._ghash.update(buf); + + (this || _global$D)._alen += buf.length; + }; + + exports$24 = StreamCipher; + return exports$24; +} + +var exports$23 = {}, + _dewExec$22 = false; + +var _global$C = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$22() { + if (_dewExec$22) return exports$23; + _dewExec$22 = true; + + var aes = dew$25(); + + var Buffer = dew$2P().Buffer; + + var Transform = dew$2z(); + + var inherits = dew$f$4(); + + function StreamCipher(mode, key, iv, decrypt) { + Transform.call(this || _global$C); + (this || _global$C)._cipher = new aes.AES(key); + (this || _global$C)._prev = Buffer.from(iv); + (this || _global$C)._cache = Buffer.allocUnsafe(0); + (this || _global$C)._secCache = Buffer.allocUnsafe(0); + (this || _global$C)._decrypt = decrypt; + (this || _global$C)._mode = mode; + } + + inherits(StreamCipher, Transform); + + StreamCipher.prototype._update = function (chunk) { + return (this || _global$C)._mode.encrypt(this || _global$C, chunk, (this || _global$C)._decrypt); + }; + + StreamCipher.prototype._final = function () { + (this || _global$C)._cipher.scrub(); + }; + + exports$23 = StreamCipher; + return exports$23; +} + +var exports$22 = {}, + _dewExec$21 = false; +function dew$21() { + if (_dewExec$21) return exports$22; + _dewExec$21 = true; + + var Buffer = dew$2P().Buffer; + + var MD5 = dew$2L(); + /* eslint-disable camelcase */ + + + function EVP_BytesToKey(password, salt, keyBits, ivLen) { + if (!Buffer.isBuffer(password)) password = Buffer.from(password, "binary"); + + if (salt) { + if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, "binary"); + if (salt.length !== 8) throw new RangeError("salt should be Buffer with 8 byte length"); + } + + var keyLen = keyBits / 8; + var key = Buffer.alloc(keyLen); + var iv = Buffer.alloc(ivLen || 0); + var tmp = Buffer.alloc(0); + + while (keyLen > 0 || ivLen > 0) { + var hash = new MD5(); + hash.update(tmp); + hash.update(password); + if (salt) hash.update(salt); + tmp = hash.digest(); + var used = 0; + + if (keyLen > 0) { + var keyStart = key.length - keyLen; + used = Math.min(keyLen, tmp.length); + tmp.copy(key, keyStart, 0, used); + keyLen -= used; + } + + if (used < tmp.length && ivLen > 0) { + var ivStart = iv.length - ivLen; + var length = Math.min(ivLen, tmp.length - used); + tmp.copy(iv, ivStart, used, used + length); + ivLen -= length; + } + } + + tmp.fill(0); + return { + key: key, + iv: iv + }; + } + + exports$22 = EVP_BytesToKey; + return exports$22; +} + +var exports$21 = {}, + _dewExec$20 = false; + +var _global$B = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$20() { + if (_dewExec$20) return exports$21; + _dewExec$20 = true; + + var MODES = dew$26(); + + var AuthCipher = dew$23(); + + var Buffer = dew$2P().Buffer; + + var StreamCipher = dew$22(); + + var Transform = dew$2z(); + + var aes = dew$25(); + + var ebtk = dew$21(); + + var inherits = dew$f$4(); + + function Cipher(mode, key, iv) { + Transform.call(this || _global$B); + (this || _global$B)._cache = new Splitter(); + (this || _global$B)._cipher = new aes.AES(key); + (this || _global$B)._prev = Buffer.from(iv); + (this || _global$B)._mode = mode; + (this || _global$B)._autopadding = true; + } + + inherits(Cipher, Transform); + + Cipher.prototype._update = function (data) { + (this || _global$B)._cache.add(data); + + var chunk; + var thing; + var out = []; + + while (chunk = (this || _global$B)._cache.get()) { + thing = (this || _global$B)._mode.encrypt(this || _global$B, chunk); + out.push(thing); + } + + return Buffer.concat(out); + }; + + var PADDING = Buffer.alloc(16, 16); + + Cipher.prototype._final = function () { + var chunk = (this || _global$B)._cache.flush(); + + if ((this || _global$B)._autopadding) { + chunk = (this || _global$B)._mode.encrypt(this || _global$B, chunk); + + (this || _global$B)._cipher.scrub(); + + return chunk; + } + + if (!chunk.equals(PADDING)) { + (this || _global$B)._cipher.scrub(); + + throw new Error("data not multiple of block length"); + } + }; + + Cipher.prototype.setAutoPadding = function (setTo) { + (this || _global$B)._autopadding = !!setTo; + return this || _global$B; + }; + + function Splitter() { + (this || _global$B).cache = Buffer.allocUnsafe(0); + } + + Splitter.prototype.add = function (data) { + (this || _global$B).cache = Buffer.concat([(this || _global$B).cache, data]); + }; + + Splitter.prototype.get = function () { + if ((this || _global$B).cache.length > 15) { + var out = (this || _global$B).cache.slice(0, 16); + + (this || _global$B).cache = (this || _global$B).cache.slice(16); + return out; + } + + return null; + }; + + Splitter.prototype.flush = function () { + var len = 16 - (this || _global$B).cache.length; + var padBuff = Buffer.allocUnsafe(len); + var i = -1; + + while (++i < len) { + padBuff.writeUInt8(len, i); + } + + return Buffer.concat([(this || _global$B).cache, padBuff]); + }; + + function createCipheriv(suite, password, iv) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + if (typeof password === "string") password = Buffer.from(password); + if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + if (typeof iv === "string") iv = Buffer.from(iv); + if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + + if (config.type === "stream") { + return new StreamCipher(config.module, password, iv); + } else if (config.type === "auth") { + return new AuthCipher(config.module, password, iv); + } + + return new Cipher(config.module, password, iv); + } + + function createCipher(suite, password) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + var keys = ebtk(password, false, config.key, config.iv); + return createCipheriv(suite, keys.key, keys.iv); + } + + exports$21.createCipheriv = createCipheriv; + exports$21.createCipher = createCipher; + return exports$21; +} + +var exports$20 = {}, + _dewExec$1$ = false; + +var _global$A = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1$() { + if (_dewExec$1$) return exports$20; + _dewExec$1$ = true; + + var AuthCipher = dew$23(); + + var Buffer = dew$2P().Buffer; + + var MODES = dew$26(); + + var StreamCipher = dew$22(); + + var Transform = dew$2z(); + + var aes = dew$25(); + + var ebtk = dew$21(); + + var inherits = dew$f$4(); + + function Decipher(mode, key, iv) { + Transform.call(this || _global$A); + (this || _global$A)._cache = new Splitter(); + (this || _global$A)._last = void 0; + (this || _global$A)._cipher = new aes.AES(key); + (this || _global$A)._prev = Buffer.from(iv); + (this || _global$A)._mode = mode; + (this || _global$A)._autopadding = true; + } + + inherits(Decipher, Transform); + + Decipher.prototype._update = function (data) { + (this || _global$A)._cache.add(data); + + var chunk; + var thing; + var out = []; + + while (chunk = (this || _global$A)._cache.get((this || _global$A)._autopadding)) { + thing = (this || _global$A)._mode.decrypt(this || _global$A, chunk); + out.push(thing); + } + + return Buffer.concat(out); + }; + + Decipher.prototype._final = function () { + var chunk = (this || _global$A)._cache.flush(); + + if ((this || _global$A)._autopadding) { + return unpad((this || _global$A)._mode.decrypt(this || _global$A, chunk)); + } else if (chunk) { + throw new Error("data not multiple of block length"); + } + }; + + Decipher.prototype.setAutoPadding = function (setTo) { + (this || _global$A)._autopadding = !!setTo; + return this || _global$A; + }; + + function Splitter() { + (this || _global$A).cache = Buffer.allocUnsafe(0); + } + + Splitter.prototype.add = function (data) { + (this || _global$A).cache = Buffer.concat([(this || _global$A).cache, data]); + }; + + Splitter.prototype.get = function (autoPadding) { + var out; + + if (autoPadding) { + if ((this || _global$A).cache.length > 16) { + out = (this || _global$A).cache.slice(0, 16); + (this || _global$A).cache = (this || _global$A).cache.slice(16); + return out; + } + } else { + if ((this || _global$A).cache.length >= 16) { + out = (this || _global$A).cache.slice(0, 16); + (this || _global$A).cache = (this || _global$A).cache.slice(16); + return out; + } + } + + return null; + }; + + Splitter.prototype.flush = function () { + if ((this || _global$A).cache.length) return (this || _global$A).cache; + }; + + function unpad(last) { + var padded = last[15]; + + if (padded < 1 || padded > 16) { + throw new Error("unable to decrypt data"); + } + + var i = -1; + + while (++i < padded) { + if (last[i + (16 - padded)] !== padded) { + throw new Error("unable to decrypt data"); + } + } + + if (padded === 16) return; + return last.slice(0, 16 - padded); + } + + function createDecipheriv(suite, password, iv) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + if (typeof iv === "string") iv = Buffer.from(iv); + if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + if (typeof password === "string") password = Buffer.from(password); + if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + + if (config.type === "stream") { + return new StreamCipher(config.module, password, iv, true); + } else if (config.type === "auth") { + return new AuthCipher(config.module, password, iv, true); + } + + return new Decipher(config.module, password, iv); + } + + function createDecipher(suite, password) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + var keys = ebtk(password, false, config.key, config.iv); + return createDecipheriv(suite, keys.key, keys.iv); + } + + exports$20.createDecipher = createDecipher; + exports$20.createDecipheriv = createDecipheriv; + return exports$20; +} + +var exports$1$ = {}, + _dewExec$1_ = false; +function dew$1_() { + if (_dewExec$1_) return exports$1$; + _dewExec$1_ = true; + + var ciphers = dew$20(); + + var deciphers = dew$1$(); + + var modes = _list$1; + + function getCiphers() { + return Object.keys(modes); + } + + exports$1$.createCipher = exports$1$.Cipher = ciphers.createCipher; + exports$1$.createCipheriv = exports$1$.Cipheriv = ciphers.createCipheriv; + exports$1$.createDecipher = exports$1$.Decipher = deciphers.createDecipher; + exports$1$.createDecipheriv = exports$1$.Decipheriv = deciphers.createDecipheriv; + exports$1$.listCiphers = exports$1$.getCiphers = getCiphers; + return exports$1$; +} + +var exports$1_ = {}, + _dewExec$1Z = false; +function dew$1Z() { + if (_dewExec$1Z) return exports$1_; + _dewExec$1Z = true; + exports$1_["des-ecb"] = { + key: 8, + iv: 0 + }; + exports$1_["des-cbc"] = exports$1_.des = { + key: 8, + iv: 8 + }; + exports$1_["des-ede3-cbc"] = exports$1_.des3 = { + key: 24, + iv: 8 + }; + exports$1_["des-ede3"] = { + key: 24, + iv: 0 + }; + exports$1_["des-ede-cbc"] = { + key: 16, + iv: 8 + }; + exports$1_["des-ede"] = { + key: 16, + iv: 0 + }; + return exports$1_; +} + +var exports$1Z = {}, + _dewExec$1Y = false; +function dew$1Y() { + if (_dewExec$1Y) return exports$1Z; + _dewExec$1Y = true; + + var DES = dew$2g(); + + var aes = dew$1_(); + + var aesModes = dew$26(); + + var desModes = dew$1Z(); + + var ebtk = dew$21(); + + function createCipher(suite, password) { + suite = suite.toLowerCase(); + var keyLen, ivLen; + + if (aesModes[suite]) { + keyLen = aesModes[suite].key; + ivLen = aesModes[suite].iv; + } else if (desModes[suite]) { + keyLen = desModes[suite].key * 8; + ivLen = desModes[suite].iv; + } else { + throw new TypeError("invalid suite type"); + } + + var keys = ebtk(password, false, keyLen, ivLen); + return createCipheriv(suite, keys.key, keys.iv); + } + + function createDecipher(suite, password) { + suite = suite.toLowerCase(); + var keyLen, ivLen; + + if (aesModes[suite]) { + keyLen = aesModes[suite].key; + ivLen = aesModes[suite].iv; + } else if (desModes[suite]) { + keyLen = desModes[suite].key * 8; + ivLen = desModes[suite].iv; + } else { + throw new TypeError("invalid suite type"); + } + + var keys = ebtk(password, false, keyLen, ivLen); + return createDecipheriv(suite, keys.key, keys.iv); + } + + function createCipheriv(suite, key, iv) { + suite = suite.toLowerCase(); + if (aesModes[suite]) return aes.createCipheriv(suite, key, iv); + if (desModes[suite]) return new DES({ + key: key, + iv: iv, + mode: suite + }); + throw new TypeError("invalid suite type"); + } + + function createDecipheriv(suite, key, iv) { + suite = suite.toLowerCase(); + if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv); + if (desModes[suite]) return new DES({ + key: key, + iv: iv, + mode: suite, + decrypt: true + }); + throw new TypeError("invalid suite type"); + } + + function getCiphers() { + return Object.keys(desModes).concat(aes.getCiphers()); + } + + exports$1Z.createCipher = exports$1Z.Cipher = createCipher; + exports$1Z.createCipheriv = exports$1Z.Cipheriv = createCipheriv; + exports$1Z.createDecipher = exports$1Z.Decipher = createDecipher; + exports$1Z.createDecipheriv = exports$1Z.Decipheriv = createDecipheriv; + exports$1Z.listCiphers = exports$1Z.getCiphers = getCiphers; + return exports$1Z; +} + +var exports$1Y = {}, + _dewExec$1X = false; +var module$a = { + exports: exports$1Y +}; + +var _global$z = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1X() { + if (_dewExec$1X) return module$a.exports; + _dewExec$1X = true; + + (function (module, exports) { + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. + + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + + var TempCtor = function () {}; + + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN + + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } + + (this || _global$z).negative = 0; + (this || _global$z).words = null; + (this || _global$z).length = 0; // Reduction context + + (this || _global$z).red = null; + + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + + this._init(number || 0, base || 10, endian || "be"); + } + } + + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = buffer.Buffer; + } + } catch (e) {} + + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + + if (base === "hex") { + base = 16; + } + + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + + if (number[0] === "-") { + start++; + (this || _global$z).negative = 1; + } + + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } + }; + + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$z).negative = 1; + number = -number; + } + + if (number < 67108864) { + (this || _global$z).words = [number & 67108863]; + (this || _global$z).length = 1; + } else if (number < 4503599627370496) { + (this || _global$z).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$z).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + + (this || _global$z).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$z).length = 3; + } + + if (endian !== "le") return; // Reverse the bytes + + this._initArray(this.toArray(), base, endian); + }; + + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + + if (number.length <= 0) { + (this || _global$z).words = [0]; + (this || _global$z).length = 1; + return this || _global$z; + } + + (this || _global$z).length = Math.ceil(number.length / 3); + (this || _global$z).words = new Array((this || _global$z).length); + + for (var i = 0; i < (this || _global$z).length; i++) { + (this || _global$z).words[i] = 0; + } + + var j, w; + var off = 0; + + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$z).words[j] |= w << off & 67108863; + (this || _global$z).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$z).words[j] |= w << off & 67108863; + (this || _global$z).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } + + return this.strip(); + }; + + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // 'A' - 'F' + + if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; // '0' - '9' + } else { + return c - 48 & 15; + } + } + + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); + + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } + + return r; + } + + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$z).length = Math.ceil((number.length - start) / 6); + (this || _global$z).words = new Array((this || _global$z).length); + + for (var i = 0; i < (this || _global$z).length; i++) { + (this || _global$z).words[i] = 0; + } // 24-bits chunks + + + var off = 0; + var j = 0; + var w; + + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$z).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$z).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$z).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$z).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + + this.strip(); + }; + + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' + + if (c >= 49) { + r += c - 49 + 10; // 'A' + } else if (c >= 17) { + r += c - 17 + 10; // '0' - '9' + } else { + r += c; + } + } + + return r; + } + + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$z).words = [0]; + (this || _global$z).length = 1; // Find length of limb in base + + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + + if ((this || _global$z).words[0] + word < 67108864) { + (this || _global$z).words[0] += word; + } else { + this._iaddn(word); + } + } + + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + + for (i = 0; i < mod; i++) { + pow *= base; + } + + this.imuln(pow); + + if ((this || _global$z).words[0] + word < 67108864) { + (this || _global$z).words[0] += word; + } else { + this._iaddn(word); + } + } + + this.strip(); + }; + + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$z).length); + + for (var i = 0; i < (this || _global$z).length; i++) { + dest.words[i] = (this || _global$z).words[i]; + } + + dest.length = (this || _global$z).length; + dest.negative = (this || _global$z).negative; + dest.red = (this || _global$z).red; + }; + + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + + BN.prototype._expand = function _expand(size) { + while ((this || _global$z).length < size) { + (this || _global$z).words[(this || _global$z).length++] = 0; + } + + return this || _global$z; + }; // Remove leading `0` from `this` + + + BN.prototype.strip = function strip() { + while ((this || _global$z).length > 1 && (this || _global$z).words[(this || _global$z).length - 1] === 0) { + (this || _global$z).length--; + } + + return this._normSign(); + }; + + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$z).length === 1 && (this || _global$z).words[0] === 0) { + (this || _global$z).negative = 0; + } + + return this || _global$z; + }; + + BN.prototype.inspect = function inspect() { + return ((this || _global$z).red ? ""; + }; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ + + + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + + for (var i = 0; i < (this || _global$z).length; i++) { + var w = (this || _global$z).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + + if (carry !== 0 || i !== (this || _global$z).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + + off += 2; + + if (off >= 26) { + off -= 26; + i--; + } + } + + if (carry !== 0) { + out = carry.toString(16) + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$z).negative !== 0) { + out = "-" + out; + } + + return out; + } + + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); + + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + + if (this.isZero()) { + out = "0" + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$z).negative !== 0) { + out = "-" + out; + } + + return out; + } + + assert(false, "Base should be between 2 and 36"); + }; + + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$z).words[0]; + + if ((this || _global$z).length === 2) { + ret += (this || _global$z).words[1] * 67108864; + } else if ((this || _global$z).length === 3 && (this || _global$z).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$z).words[1] * 67108864; + } else if ((this || _global$z).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + + return (this || _global$z).negative !== 0 ? -ret : ret; + }; + + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; + + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; + + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } + } else { + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + + for (; i < reqLength; i++) { + res[i] = 0; + } + } + + return res; + }; + + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + + if (t >= 4096) { + r += 13; + t >>>= 13; + } + + if (t >= 64) { + r += 7; + t >>>= 7; + } + + if (t >= 8) { + r += 4; + t >>>= 4; + } + + if (t >= 2) { + r += 2; + t >>>= 2; + } + + return r + t; + }; + } + + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } + + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } + + if ((t & 1) === 0) { + r++; + } + + return r; + }; // Return number of used bits in a BN + + + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$z).words[(this || _global$z).length - 1]; + + var hi = this._countBits(w); + + return ((this || _global$z).length - 1) * 26 + hi; + }; + + function toBitArray(num) { + var w = new Array(num.bitLength()); + + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + + return w; + } // Number of trailing zero bits + + + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; + + for (var i = 0; i < (this || _global$z).length; i++) { + var b = this._zeroBits((this || _global$z).words[i]); + + r += b; + if (b !== 26) break; + } + + return r; + }; + + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; + + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$z).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + + return this.clone(); + }; + + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } + + return this.clone(); + }; + + BN.prototype.isNeg = function isNeg() { + return (this || _global$z).negative !== 0; + }; // Return negative clone of `this` + + + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; + + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$z).negative ^= 1; + } + + return this || _global$z; + }; // Or `num` with `this` in-place + + + BN.prototype.iuor = function iuor(num) { + while ((this || _global$z).length < num.length) { + (this || _global$z).words[(this || _global$z).length++] = 0; + } + + for (var i = 0; i < num.length; i++) { + (this || _global$z).words[i] = (this || _global$z).words[i] | num.words[i]; + } + + return this.strip(); + }; + + BN.prototype.ior = function ior(num) { + assert(((this || _global$z).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` + + + BN.prototype.or = function or(num) { + if ((this || _global$z).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$z); + }; + + BN.prototype.uor = function uor(num) { + if ((this || _global$z).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$z); + }; // And `num` with `this` in-place + + + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + + if ((this || _global$z).length > num.length) { + b = num; + } else { + b = this || _global$z; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$z).words[i] = (this || _global$z).words[i] & num.words[i]; + } + + (this || _global$z).length = b.length; + return this.strip(); + }; + + BN.prototype.iand = function iand(num) { + assert(((this || _global$z).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` + + + BN.prototype.and = function and(num) { + if ((this || _global$z).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$z); + }; + + BN.prototype.uand = function uand(num) { + if ((this || _global$z).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$z); + }; // Xor `num` with `this` in-place + + + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + + if ((this || _global$z).length > num.length) { + a = this || _global$z; + b = num; + } else { + a = num; + b = this || _global$z; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$z).words[i] = a.words[i] ^ b.words[i]; + } + + if ((this || _global$z) !== a) { + for (; i < a.length; i++) { + (this || _global$z).words[i] = a.words[i]; + } + } + + (this || _global$z).length = a.length; + return this.strip(); + }; + + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$z).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` + + + BN.prototype.xor = function xor(num) { + if ((this || _global$z).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$z); + }; + + BN.prototype.uxor = function uxor(num) { + if ((this || _global$z).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$z); + }; // Not ``this`` with ``width`` bitwidth + + + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes + + this._expand(bytesNeeded); + + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words + + + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$z).words[i] = ~(this || _global$z).words[i] & 67108863; + } // Handle the residue + + + if (bitsLeft > 0) { + (this || _global$z).words[i] = ~(this || _global$z).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes + + + return this.strip(); + }; + + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` + + + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + + this._expand(off + 1); + + if (val) { + (this || _global$z).words[off] = (this || _global$z).words[off] | 1 << wbit; + } else { + (this || _global$z).words[off] = (this || _global$z).words[off] & ~(1 << wbit); + } + + return this.strip(); + }; // Add `num` to `this` in-place + + + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive + + if ((this || _global$z).negative !== 0 && num.negative === 0) { + (this || _global$z).negative = 0; + r = this.isub(num); + (this || _global$z).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$z).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length + + + var a, b; + + if ((this || _global$z).length > num.length) { + a = this || _global$z; + b = num; + } else { + a = num; + b = this || _global$z; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$z).words[i] = r & 67108863; + carry = r >>> 26; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$z).words[i] = r & 67108863; + carry = r >>> 26; + } + + (this || _global$z).length = a.length; + + if (carry !== 0) { + (this || _global$z).words[(this || _global$z).length] = carry; + (this || _global$z).length++; // Copy the rest of the words + } else if (a !== (this || _global$z)) { + for (; i < a.length; i++) { + (this || _global$z).words[i] = a.words[i]; + } + } + + return this || _global$z; + }; // Add `num` to `this` + + + BN.prototype.add = function add(num) { + var res; + + if (num.negative !== 0 && (this || _global$z).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$z).negative !== 0) { + (this || _global$z).negative = 0; + res = num.sub(this || _global$z); + (this || _global$z).negative = 1; + return res; + } + + if ((this || _global$z).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$z); + }; // Subtract `num` from `this` in-place + + + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$z).negative !== 0) { + (this || _global$z).negative = 0; + this.iadd(num); + (this || _global$z).negative = 1; + return this._normSign(); + } // At this point both numbers are positive + + + var cmp = this.cmp(num); // Optimization - zeroify + + if (cmp === 0) { + (this || _global$z).negative = 0; + (this || _global$z).length = 1; + (this || _global$z).words[0] = 0; + return this || _global$z; + } // a > b + + + var a, b; + + if (cmp > 0) { + a = this || _global$z; + b = num; + } else { + a = num; + b = this || _global$z; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$z).words[i] = r & 67108863; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$z).words[i] = r & 67108863; + } // Copy rest of the words + + + if (carry === 0 && i < a.length && a !== (this || _global$z)) { + for (; i < a.length; i++) { + (this || _global$z).words[i] = a.words[i]; + } + } + + (this || _global$z).length = Math.max((this || _global$z).length, i); + + if (a !== (this || _global$z)) { + (this || _global$z).negative = 1; + } + + return this.strip(); + }; // Subtract `num` from `this` + + + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; + + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; + + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } + + out.words[k] = rword | 0; + carry = ncarry | 0; + } + + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } + + return out.strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). + + + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ + + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ + + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ + + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ + + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ + + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ + + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ + + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ + + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ + + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ + + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ + + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ + + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ + + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ + + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ + + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + + if (c !== 0) { + o[19] = c; + out.length++; + } + + return out; + }; // Polyfill comb + + + if (!Math.imul) { + comb10MulTo = smallMulTo; + } + + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; + + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } + + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } + + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } + + return out.strip(); + } + + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } + + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$z).length + num.length; + + if ((this || _global$z).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$z, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$z, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$z, num, out); + } else { + res = jumboMulTo(this || _global$z, num, out); + } + + return res; + }; // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion + + + function FFTM(x, y) { + (this || _global$z).x = x; + (this || _global$z).y = y; + } + + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; + + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } + + return t; + }; // Returns binary-reversed representation of `x` + + + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } + + return rb; + }; // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm + + + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; + + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); + + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); + + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; + + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + /* jshint maxdepth : false */ + + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } + } + }; + + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; + + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } + + return 1 << i + 1 + odd; + }; + + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; + + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; + } + }; + + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; + + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; + + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } + + return ws; + }; + + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; + + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } // Pad with zeroes + + + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } + + assert(carry === 0); + assert((carry & ~8191) === 0); + }; + + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); + + for (var i = 0; i < N; i++) { + ph[i] = 0; + } + + return ph; + }; + + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); + + var _ = this.stub(N); + + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); + + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } + + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; // Multiply `this` by `num` + + + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$z).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT + + + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$z).length + num.length); + return jumboMulTo(this || _global$z, num, out); + }; // In-place Multiplication + + + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$z); + }; + + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); // Carry + + var carry = 0; + + for (var i = 0; i < (this || _global$z).length; i++) { + var w = ((this || _global$z).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum + + carry += lo >>> 26; + (this || _global$z).words[i] = lo & 67108863; + } + + if (carry !== 0) { + (this || _global$z).words[i] = carry; + (this || _global$z).length++; + } + + return this || _global$z; + }; + + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` + + + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$z); + }; // `this` * `this` in-place + + + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) + + + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes + + var res = this || _global$z; + + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } + + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } + + return res; + }; // Shift-left in-place + + + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; + + if (r !== 0) { + var carry = 0; + + for (i = 0; i < (this || _global$z).length; i++) { + var newCarry = (this || _global$z).words[i] & carryMask; + var c = ((this || _global$z).words[i] | 0) - newCarry << r; + (this || _global$z).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } + + if (carry) { + (this || _global$z).words[i] = carry; + (this || _global$z).length++; + } + } + + if (s !== 0) { + for (i = (this || _global$z).length - 1; i >= 0; i--) { + (this || _global$z).words[i + s] = (this || _global$z).words[i]; + } + + for (i = 0; i < s; i++) { + (this || _global$z).words[i] = 0; + } + + (this || _global$z).length += s; + } + + return this.strip(); + }; + + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$z).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits + + + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; + + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } + + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$z).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part + + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$z).words[i]; + } + + maskedWords.length = s; + } + + if (s === 0) ; else if ((this || _global$z).length > s) { + (this || _global$z).length -= s; + + for (i = 0; i < (this || _global$z).length; i++) { + (this || _global$z).words[i] = (this || _global$z).words[i + s]; + } + } else { + (this || _global$z).words[0] = 0; + (this || _global$z).length = 1; + } + + var carry = 0; + + for (i = (this || _global$z).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$z).words[i] | 0; + (this || _global$z).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask + + + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } + + if ((this || _global$z).length === 0) { + (this || _global$z).words[0] = 0; + (this || _global$z).length = 1; + } + + return this.strip(); + }; + + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$z).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left + + + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; + + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right + + + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; + + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set + + + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$z).length <= s) return false; // Check bit and return + + var w = (this || _global$z).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) + + + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$z).negative === 0, "imaskn works only with positive numbers"); + + if ((this || _global$z).length <= s) { + return this || _global$z; + } + + if (r !== 0) { + s++; + } + + (this || _global$z).length = Math.min(s, (this || _global$z).length); + + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$z).words[(this || _global$z).length - 1] &= mask; + } + + return this.strip(); + }; // Return only lowers bits of number + + + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` + + + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change + + if ((this || _global$z).negative !== 0) { + if ((this || _global$z).length === 1 && ((this || _global$z).words[0] | 0) < num) { + (this || _global$z).words[0] = num - ((this || _global$z).words[0] | 0); + (this || _global$z).negative = 0; + return this || _global$z; + } + + (this || _global$z).negative = 0; + this.isubn(num); + (this || _global$z).negative = 1; + return this || _global$z; + } // Add without checks + + + return this._iaddn(num); + }; + + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$z).words[0] += num; // Carry + + for (var i = 0; i < (this || _global$z).length && (this || _global$z).words[i] >= 67108864; i++) { + (this || _global$z).words[i] -= 67108864; + + if (i === (this || _global$z).length - 1) { + (this || _global$z).words[i + 1] = 1; + } else { + (this || _global$z).words[i + 1]++; + } + } + + (this || _global$z).length = Math.max((this || _global$z).length, i + 1); + return this || _global$z; + }; // Subtract plain number `num` from `this` + + + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); + + if ((this || _global$z).negative !== 0) { + (this || _global$z).negative = 0; + this.iaddn(num); + (this || _global$z).negative = 1; + return this || _global$z; + } + + (this || _global$z).words[0] -= num; + + if ((this || _global$z).length === 1 && (this || _global$z).words[0] < 0) { + (this || _global$z).words[0] = -(this || _global$z).words[0]; + (this || _global$z).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$z).length && (this || _global$z).words[i] < 0; i++) { + (this || _global$z).words[i] += 67108864; + (this || _global$z).words[i + 1] -= 1; + } + } + + return this.strip(); + }; + + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; + + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; + + BN.prototype.iabs = function iabs() { + (this || _global$z).negative = 0; + return this || _global$z; + }; + + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; + + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + + this._expand(len); + + var w; + var carry = 0; + + for (i = 0; i < num.length; i++) { + w = ((this || _global$z).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$z).words[i + shift] = w & 67108863; + } + + for (; i < (this || _global$z).length - shift; i++) { + w = ((this || _global$z).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$z).words[i + shift] = w & 67108863; + } + + if (carry === 0) return this.strip(); // Subtraction overflow + + assert(carry === -1); + carry = 0; + + for (i = 0; i < (this || _global$z).length; i++) { + w = -((this || _global$z).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$z).words[i] = w & 67108863; + } + + (this || _global$z).negative = 1; + return this.strip(); + }; + + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$z).length - num.length; + var a = this.clone(); + var b = num; // Normalize + + var bhi = b.words[b.length - 1] | 0; + + var bhiBits = this._countBits(bhi); + + shift = 26 - bhiBits; + + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient + + + var m = a.length - b.length; + var q; + + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); + + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } + + var diff = a.clone()._ishlnsubmul(b, 1, m); + + if (diff.negative === 0) { + a = diff; + + if (q) { + q.words[m] = 1; + } + } + + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) + + qj = Math.min(qj / bhi | 0, 67108863); + + a._ishlnsubmul(b, qj, j); + + while (a.negative !== 0) { + qj--; + a.negative = 0; + + a._ishlnsubmul(b, 1, j); + + if (!a.isZero()) { + a.negative ^= 1; + } + } + + if (q) { + q.words[j] = qj; + } + } + + if (q) { + q.strip(); + } + + a.strip(); // Denormalize + + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } + + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested + + + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); + + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } + + var div, mod, res; + + if ((this || _global$z).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } + + return { + div: div, + mod: mod + }; + } + + if ((this || _global$z).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + return { + div: div, + mod: res.mod + }; + } + + if (((this || _global$z).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } + + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value + + + if (num.length > (this || _global$z).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$z + }; + } // Very short reduction + + + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } + + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } + + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } + + return this._wordDiv(num, mode); + }; // Find `this` / `num` + + + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` + + + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; + + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) + + + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division + + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down + + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; + + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + + for (var i = (this || _global$z).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$z).words[i] | 0)) % num; + } + + return acc; + }; // In-place division by number + + + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + + for (var i = (this || _global$z).length - 1; i >= 0; i--) { + var w = ((this || _global$z).words[i] | 0) + carry * 67108864; + (this || _global$z).words[i] = w / num | 0; + carry = w % num; + } + + return this.strip(); + }; + + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; + + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$z; + var y = p.clone(); + + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x + + + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y + + var C = new BN(0); + var D = new BN(1); + var g = 0; + + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } + + var yp = y.clone(); + var xp = x.clone(); + + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + x.iushrn(i); + + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + + A.iushrn(1); + B.iushrn(1); + } + } + + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + y.iushrn(j); + + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + + C.iushrn(1); + D.iushrn(1); + } + } + + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed + + + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$z; + var b = p.clone(); + + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } + + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); + + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + a.iushrn(i); + + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } + + x1.iushrn(1); + } + } + + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + b.iushrn(j); + + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } + + x2.iushrn(1); + } + } + + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + + var res; + + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + + if (res.cmpn(0) < 0) { + res.iadd(p); + } + + return res; + }; + + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two + + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + + do { + while (a.isEven()) { + a.iushrn(1); + } + + while (b.isEven()) { + b.iushrn(1); + } + + var r = a.cmp(b); + + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + + a.isub(b); + } while (true); + + return b.iushln(shift); + }; // Invert number in the field F(num) + + + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + + BN.prototype.isEven = function isEven() { + return ((this || _global$z).words[0] & 1) === 0; + }; + + BN.prototype.isOdd = function isOdd() { + return ((this || _global$z).words[0] & 1) === 1; + }; // And first word and num + + + BN.prototype.andln = function andln(num) { + return (this || _global$z).words[0] & num; + }; // Increment at the bit position in-line + + + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$z).length <= s) { + this._expand(s + 1); + + (this || _global$z).words[s] |= q; + return this || _global$z; + } // Add bit and propagate, if needed + + + var carry = q; + + for (var i = s; carry !== 0 && i < (this || _global$z).length; i++) { + var w = (this || _global$z).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$z).words[i] = w; + } + + if (carry !== 0) { + (this || _global$z).words[i] = carry; + (this || _global$z).length++; + } + + return this || _global$z; + }; + + BN.prototype.isZero = function isZero() { + return (this || _global$z).length === 1 && (this || _global$z).words[0] === 0; + }; + + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$z).negative !== 0 && !negative) return -1; + if ((this || _global$z).negative === 0 && negative) return 1; + this.strip(); + var res; + + if ((this || _global$z).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$z).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + + if ((this || _global$z).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + + + BN.prototype.cmp = function cmp(num) { + if ((this || _global$z).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$z).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$z).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison + + + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$z).length > num.length) return 1; + if ((this || _global$z).length < num.length) return -1; + var res = 0; + + for (var i = (this || _global$z).length - 1; i >= 0; i--) { + var a = (this || _global$z).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + + break; + } + + return res; + }; + + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + + + BN.red = function red(num) { + return new Red(num); + }; + + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$z).red, "Already a number in reduction context"); + assert((this || _global$z).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$z)._forceRed(ctx); + }; + + BN.prototype.fromRed = function fromRed() { + assert((this || _global$z).red, "fromRed works only with numbers in reduction context"); + return (this || _global$z).red.convertFrom(this || _global$z); + }; + + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$z).red = ctx; + return this || _global$z; + }; + + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$z).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$z).red, "redAdd works only with red numbers"); + return (this || _global$z).red.add(this || _global$z, num); + }; + + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$z).red, "redIAdd works only with red numbers"); + return (this || _global$z).red.iadd(this || _global$z, num); + }; + + BN.prototype.redSub = function redSub(num) { + assert((this || _global$z).red, "redSub works only with red numbers"); + return (this || _global$z).red.sub(this || _global$z, num); + }; + + BN.prototype.redISub = function redISub(num) { + assert((this || _global$z).red, "redISub works only with red numbers"); + return (this || _global$z).red.isub(this || _global$z, num); + }; + + BN.prototype.redShl = function redShl(num) { + assert((this || _global$z).red, "redShl works only with red numbers"); + return (this || _global$z).red.shl(this || _global$z, num); + }; + + BN.prototype.redMul = function redMul(num) { + assert((this || _global$z).red, "redMul works only with red numbers"); + + (this || _global$z).red._verify2(this || _global$z, num); + + return (this || _global$z).red.mul(this || _global$z, num); + }; + + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$z).red, "redMul works only with red numbers"); + + (this || _global$z).red._verify2(this || _global$z, num); + + return (this || _global$z).red.imul(this || _global$z, num); + }; + + BN.prototype.redSqr = function redSqr() { + assert((this || _global$z).red, "redSqr works only with red numbers"); + + (this || _global$z).red._verify1(this || _global$z); + + return (this || _global$z).red.sqr(this || _global$z); + }; + + BN.prototype.redISqr = function redISqr() { + assert((this || _global$z).red, "redISqr works only with red numbers"); + + (this || _global$z).red._verify1(this || _global$z); + + return (this || _global$z).red.isqr(this || _global$z); + }; // Square root over p + + + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$z).red, "redSqrt works only with red numbers"); + + (this || _global$z).red._verify1(this || _global$z); + + return (this || _global$z).red.sqrt(this || _global$z); + }; + + BN.prototype.redInvm = function redInvm() { + assert((this || _global$z).red, "redInvm works only with red numbers"); + + (this || _global$z).red._verify1(this || _global$z); + + return (this || _global$z).red.invm(this || _global$z); + }; // Return negative clone of `this` % `red modulo` + + + BN.prototype.redNeg = function redNeg() { + assert((this || _global$z).red, "redNeg works only with red numbers"); + + (this || _global$z).red._verify1(this || _global$z); + + return (this || _global$z).red.neg(this || _global$z); + }; + + BN.prototype.redPow = function redPow(num) { + assert((this || _global$z).red && !num.red, "redPow(normalNum)"); + + (this || _global$z).red._verify1(this || _global$z); + + return (this || _global$z).red.pow(this || _global$z, num); + }; // Prime numbers with efficient reduction + + + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime + + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$z).name = name; + (this || _global$z).p = new BN(p, 16); + (this || _global$z).n = (this || _global$z).p.bitLength(); + (this || _global$z).k = new BN(1).iushln((this || _global$z).n).isub((this || _global$z).p); + (this || _global$z).tmp = this._tmp(); + } + + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$z).n / 13)); + return tmp; + }; + + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + + do { + this.split(r, (this || _global$z).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$z).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$z).n); + + var cmp = rlen < (this || _global$z).n ? -1 : r.ucmp((this || _global$z).p); + + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$z).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + + return r; + }; + + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$z).n, 0, out); + }; + + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$z).k); + }; + + function K256() { + MPrime.call(this || _global$z, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + + inherits(K256, MPrime); + + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + + output.length = outLen; + + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs + + + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + + prev >>>= 22; + input.words[i - 10] = prev; + + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + + var lo = 0; + + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction + + + if (num.words[num.length - 1] === 0) { + num.length--; + + if (num.words[num.length - 1] === 0) { + num.length--; + } + } + + return num; + }; + + function P224() { + MPrime.call(this || _global$z, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } + + inherits(P224, MPrime); + + function P192() { + MPrime.call(this || _global$z, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } + + inherits(P192, MPrime); + + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$z, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } + + inherits(P25519, MPrime); + + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } + + if (carry !== 0) { + num.words[num.length++] = carry; + } + + return num; + }; // Exported mostly for testing purposes, use plain name instead + + + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // + + + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + + (this || _global$z).m = prime.p; + (this || _global$z).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$z).m = m; + (this || _global$z).prime = null; + } + } + + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; + + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; + + Red.prototype.imod = function imod(a) { + if ((this || _global$z).prime) return (this || _global$z).prime.ireduce(a)._forceRed(this || _global$z); + return a.umod((this || _global$z).m)._forceRed(this || _global$z); + }; + + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } + + return (this || _global$z).m.sub(a)._forceRed(this || _global$z); + }; + + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + + var res = a.add(b); + + if (res.cmp((this || _global$z).m) >= 0) { + res.isub((this || _global$z).m); + } + + return res._forceRed(this || _global$z); + }; + + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + + var res = a.iadd(b); + + if (res.cmp((this || _global$z).m) >= 0) { + res.isub((this || _global$z).m); + } + + return res; + }; + + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); + + var res = a.sub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$z).m); + } + + return res._forceRed(this || _global$z); + }; + + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); + + var res = a.isub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$z).m); + } + + return res; + }; + + Red.prototype.shl = function shl(a, num) { + this._verify1(a); + + return this.imod(a.ushln(num)); + }; + + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); + + return this.imod(a.imul(b)); + }; + + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); + + return this.imod(a.mul(b)); + }; + + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; + + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + + var mod3 = (this || _global$z).m.andln(3); + + assert(mod3 % 2 === 1); // Fast case + + if (mod3 === 3) { + var pow = (this || _global$z).m.add(new BN(1)).iushrn(2); + + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) + + + var q = (this || _global$z).m.subn(1); + + var s = 0; + + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$z); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + + var lpow = (this || _global$z).m.subn(1).iushrn(1); + + var z = (this || _global$z).m.bitLength(); + + z = new BN(2 * z * z).toRed(this || _global$z); + + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } + + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; + + while (t.cmp(one) !== 0) { + var tmp = t; + + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } + + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } + + return r; + }; + + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$z).m); + + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$z); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$z); + wnd[1] = a; + + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + + if (start === 0) { + start = 26; + } + + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + + if (res !== wnd[0]) { + res = this.sqr(res); + } + + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + + start = 26; + } + + return res; + }; + + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$z).m); + return r === num ? r.clone() : r; + }; + + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // + + + BN.mont = function mont(num) { + return new Mont(num); + }; + + function Mont(m) { + Red.call(this || _global$z, m); + (this || _global$z).shift = (this || _global$z).m.bitLength(); + + if ((this || _global$z).shift % 26 !== 0) { + (this || _global$z).shift += 26 - (this || _global$z).shift % 26; + } + + (this || _global$z).r = new BN(1).iushln((this || _global$z).shift); + (this || _global$z).r2 = this.imod((this || _global$z).r.sqr()); + (this || _global$z).rinv = (this || _global$z).r._invmp((this || _global$z).m); + (this || _global$z).minv = (this || _global$z).rinv.mul((this || _global$z).r).isubn(1).div((this || _global$z).m); + (this || _global$z).minv = (this || _global$z).minv.umod((this || _global$z).r); + (this || _global$z).minv = (this || _global$z).r.sub((this || _global$z).minv); + } + + inherits(Mont, Red); + + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$z).shift)); + }; + + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$z).rinv)); + r.red = null; + return r; + }; + + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + + var t = a.imul(b); + var c = t.maskn((this || _global$z).shift).mul((this || _global$z).minv).imaskn((this || _global$z).shift).mul((this || _global$z).m); + var u = t.isub(c).iushrn((this || _global$z).shift); + var res = u; + + if (u.cmp((this || _global$z).m) >= 0) { + res = u.isub((this || _global$z).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$z).m); + } + + return res._forceRed(this || _global$z); + }; + + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$z); + var t = a.mul(b); + var c = t.maskn((this || _global$z).shift).mul((this || _global$z).minv).imaskn((this || _global$z).shift).mul((this || _global$z).m); + var u = t.isub(c).iushrn((this || _global$z).shift); + var res = u; + + if (u.cmp((this || _global$z).m) >= 0) { + res = u.isub((this || _global$z).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$z).m); + } + + return res._forceRed(this || _global$z); + }; + + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$z).m).mul((this || _global$z).r2)); + return res._forceRed(this || _global$z); + }; + })(module$a, exports$1Y); + + return module$a.exports; +} + +var exports$1X = {}, + _dewExec$1W = false; +var module$9 = { + exports: exports$1X +}; + +var _global$y = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1W() { + if (_dewExec$1W) return module$9.exports; + _dewExec$1W = true; + + (function (module, exports) { + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. + + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + + var TempCtor = function () {}; + + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN + + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } + + (this || _global$y).negative = 0; + (this || _global$y).words = null; + (this || _global$y).length = 0; // Reduction context + + (this || _global$y).red = null; + + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + + this._init(number || 0, base || 10, endian || "be"); + } + } + + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = buffer.Buffer; + } + } catch (e) {} + + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + + if (base === "hex") { + base = 16; + } + + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + + if (number[0] === "-") { + start++; + (this || _global$y).negative = 1; + } + + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } + }; + + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$y).negative = 1; + number = -number; + } + + if (number < 67108864) { + (this || _global$y).words = [number & 67108863]; + (this || _global$y).length = 1; + } else if (number < 4503599627370496) { + (this || _global$y).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$y).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + + (this || _global$y).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$y).length = 3; + } + + if (endian !== "le") return; // Reverse the bytes + + this._initArray(this.toArray(), base, endian); + }; + + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + + if (number.length <= 0) { + (this || _global$y).words = [0]; + (this || _global$y).length = 1; + return this || _global$y; + } + + (this || _global$y).length = Math.ceil(number.length / 3); + (this || _global$y).words = new Array((this || _global$y).length); + + for (var i = 0; i < (this || _global$y).length; i++) { + (this || _global$y).words[i] = 0; + } + + var j, w; + var off = 0; + + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$y).words[j] |= w << off & 67108863; + (this || _global$y).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$y).words[j] |= w << off & 67108863; + (this || _global$y).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } + + return this.strip(); + }; + + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // 'A' - 'F' + + if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; // '0' - '9' + } else { + return c - 48 & 15; + } + } + + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); + + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } + + return r; + } + + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$y).length = Math.ceil((number.length - start) / 6); + (this || _global$y).words = new Array((this || _global$y).length); + + for (var i = 0; i < (this || _global$y).length; i++) { + (this || _global$y).words[i] = 0; + } // 24-bits chunks + + + var off = 0; + var j = 0; + var w; + + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$y).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$y).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$y).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$y).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + + this.strip(); + }; + + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' + + if (c >= 49) { + r += c - 49 + 10; // 'A' + } else if (c >= 17) { + r += c - 17 + 10; // '0' - '9' + } else { + r += c; + } + } + + return r; + } + + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$y).words = [0]; + (this || _global$y).length = 1; // Find length of limb in base + + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + + if ((this || _global$y).words[0] + word < 67108864) { + (this || _global$y).words[0] += word; + } else { + this._iaddn(word); + } + } + + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + + for (i = 0; i < mod; i++) { + pow *= base; + } + + this.imuln(pow); + + if ((this || _global$y).words[0] + word < 67108864) { + (this || _global$y).words[0] += word; + } else { + this._iaddn(word); + } + } + + this.strip(); + }; + + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$y).length); + + for (var i = 0; i < (this || _global$y).length; i++) { + dest.words[i] = (this || _global$y).words[i]; + } + + dest.length = (this || _global$y).length; + dest.negative = (this || _global$y).negative; + dest.red = (this || _global$y).red; + }; + + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + + BN.prototype._expand = function _expand(size) { + while ((this || _global$y).length < size) { + (this || _global$y).words[(this || _global$y).length++] = 0; + } + + return this || _global$y; + }; // Remove leading `0` from `this` + + + BN.prototype.strip = function strip() { + while ((this || _global$y).length > 1 && (this || _global$y).words[(this || _global$y).length - 1] === 0) { + (this || _global$y).length--; + } + + return this._normSign(); + }; + + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$y).length === 1 && (this || _global$y).words[0] === 0) { + (this || _global$y).negative = 0; + } + + return this || _global$y; + }; + + BN.prototype.inspect = function inspect() { + return ((this || _global$y).red ? ""; + }; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ + + + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + + for (var i = 0; i < (this || _global$y).length; i++) { + var w = (this || _global$y).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + + if (carry !== 0 || i !== (this || _global$y).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + + off += 2; + + if (off >= 26) { + off -= 26; + i--; + } + } + + if (carry !== 0) { + out = carry.toString(16) + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$y).negative !== 0) { + out = "-" + out; + } + + return out; + } + + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); + + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + + if (this.isZero()) { + out = "0" + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$y).negative !== 0) { + out = "-" + out; + } + + return out; + } + + assert(false, "Base should be between 2 and 36"); + }; + + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$y).words[0]; + + if ((this || _global$y).length === 2) { + ret += (this || _global$y).words[1] * 67108864; + } else if ((this || _global$y).length === 3 && (this || _global$y).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$y).words[1] * 67108864; + } else if ((this || _global$y).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + + return (this || _global$y).negative !== 0 ? -ret : ret; + }; + + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; + + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; + + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } + } else { + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + + for (; i < reqLength; i++) { + res[i] = 0; + } + } + + return res; + }; + + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + + if (t >= 4096) { + r += 13; + t >>>= 13; + } + + if (t >= 64) { + r += 7; + t >>>= 7; + } + + if (t >= 8) { + r += 4; + t >>>= 4; + } + + if (t >= 2) { + r += 2; + t >>>= 2; + } + + return r + t; + }; + } + + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } + + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } + + if ((t & 1) === 0) { + r++; + } + + return r; + }; // Return number of used bits in a BN + + + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$y).words[(this || _global$y).length - 1]; + + var hi = this._countBits(w); + + return ((this || _global$y).length - 1) * 26 + hi; + }; + + function toBitArray(num) { + var w = new Array(num.bitLength()); + + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + + return w; + } // Number of trailing zero bits + + + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; + + for (var i = 0; i < (this || _global$y).length; i++) { + var b = this._zeroBits((this || _global$y).words[i]); + + r += b; + if (b !== 26) break; + } + + return r; + }; + + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; + + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$y).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + + return this.clone(); + }; + + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } + + return this.clone(); + }; + + BN.prototype.isNeg = function isNeg() { + return (this || _global$y).negative !== 0; + }; // Return negative clone of `this` + + + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; + + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$y).negative ^= 1; + } + + return this || _global$y; + }; // Or `num` with `this` in-place + + + BN.prototype.iuor = function iuor(num) { + while ((this || _global$y).length < num.length) { + (this || _global$y).words[(this || _global$y).length++] = 0; + } + + for (var i = 0; i < num.length; i++) { + (this || _global$y).words[i] = (this || _global$y).words[i] | num.words[i]; + } + + return this.strip(); + }; + + BN.prototype.ior = function ior(num) { + assert(((this || _global$y).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` + + + BN.prototype.or = function or(num) { + if ((this || _global$y).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$y); + }; + + BN.prototype.uor = function uor(num) { + if ((this || _global$y).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$y); + }; // And `num` with `this` in-place + + + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + + if ((this || _global$y).length > num.length) { + b = num; + } else { + b = this || _global$y; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$y).words[i] = (this || _global$y).words[i] & num.words[i]; + } + + (this || _global$y).length = b.length; + return this.strip(); + }; + + BN.prototype.iand = function iand(num) { + assert(((this || _global$y).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` + + + BN.prototype.and = function and(num) { + if ((this || _global$y).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$y); + }; + + BN.prototype.uand = function uand(num) { + if ((this || _global$y).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$y); + }; // Xor `num` with `this` in-place + + + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + + if ((this || _global$y).length > num.length) { + a = this || _global$y; + b = num; + } else { + a = num; + b = this || _global$y; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$y).words[i] = a.words[i] ^ b.words[i]; + } + + if ((this || _global$y) !== a) { + for (; i < a.length; i++) { + (this || _global$y).words[i] = a.words[i]; + } + } + + (this || _global$y).length = a.length; + return this.strip(); + }; + + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$y).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` + + + BN.prototype.xor = function xor(num) { + if ((this || _global$y).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$y); + }; + + BN.prototype.uxor = function uxor(num) { + if ((this || _global$y).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$y); + }; // Not ``this`` with ``width`` bitwidth + + + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes + + this._expand(bytesNeeded); + + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words + + + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$y).words[i] = ~(this || _global$y).words[i] & 67108863; + } // Handle the residue + + + if (bitsLeft > 0) { + (this || _global$y).words[i] = ~(this || _global$y).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes + + + return this.strip(); + }; + + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` + + + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + + this._expand(off + 1); + + if (val) { + (this || _global$y).words[off] = (this || _global$y).words[off] | 1 << wbit; + } else { + (this || _global$y).words[off] = (this || _global$y).words[off] & ~(1 << wbit); + } + + return this.strip(); + }; // Add `num` to `this` in-place + + + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive + + if ((this || _global$y).negative !== 0 && num.negative === 0) { + (this || _global$y).negative = 0; + r = this.isub(num); + (this || _global$y).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$y).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length + + + var a, b; + + if ((this || _global$y).length > num.length) { + a = this || _global$y; + b = num; + } else { + a = num; + b = this || _global$y; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$y).words[i] = r & 67108863; + carry = r >>> 26; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$y).words[i] = r & 67108863; + carry = r >>> 26; + } + + (this || _global$y).length = a.length; + + if (carry !== 0) { + (this || _global$y).words[(this || _global$y).length] = carry; + (this || _global$y).length++; // Copy the rest of the words + } else if (a !== (this || _global$y)) { + for (; i < a.length; i++) { + (this || _global$y).words[i] = a.words[i]; + } + } + + return this || _global$y; + }; // Add `num` to `this` + + + BN.prototype.add = function add(num) { + var res; + + if (num.negative !== 0 && (this || _global$y).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$y).negative !== 0) { + (this || _global$y).negative = 0; + res = num.sub(this || _global$y); + (this || _global$y).negative = 1; + return res; + } + + if ((this || _global$y).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$y); + }; // Subtract `num` from `this` in-place + + + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$y).negative !== 0) { + (this || _global$y).negative = 0; + this.iadd(num); + (this || _global$y).negative = 1; + return this._normSign(); + } // At this point both numbers are positive + + + var cmp = this.cmp(num); // Optimization - zeroify + + if (cmp === 0) { + (this || _global$y).negative = 0; + (this || _global$y).length = 1; + (this || _global$y).words[0] = 0; + return this || _global$y; + } // a > b + + + var a, b; + + if (cmp > 0) { + a = this || _global$y; + b = num; + } else { + a = num; + b = this || _global$y; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$y).words[i] = r & 67108863; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$y).words[i] = r & 67108863; + } // Copy rest of the words + + + if (carry === 0 && i < a.length && a !== (this || _global$y)) { + for (; i < a.length; i++) { + (this || _global$y).words[i] = a.words[i]; + } + } + + (this || _global$y).length = Math.max((this || _global$y).length, i); + + if (a !== (this || _global$y)) { + (this || _global$y).negative = 1; + } + + return this.strip(); + }; // Subtract `num` from `this` + + + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; + + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; + + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } + + out.words[k] = rword | 0; + carry = ncarry | 0; + } + + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } + + return out.strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). + + + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ + + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ + + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ + + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ + + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ + + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ + + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ + + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ + + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ + + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ + + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ + + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ + + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ + + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ + + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ + + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + + if (c !== 0) { + o[19] = c; + out.length++; + } + + return out; + }; // Polyfill comb + + + if (!Math.imul) { + comb10MulTo = smallMulTo; + } + + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; + + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } + + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } + + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } + + return out.strip(); + } + + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } + + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$y).length + num.length; + + if ((this || _global$y).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$y, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$y, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$y, num, out); + } else { + res = jumboMulTo(this || _global$y, num, out); + } + + return res; + }; // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion + + + function FFTM(x, y) { + (this || _global$y).x = x; + (this || _global$y).y = y; + } + + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; + + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } + + return t; + }; // Returns binary-reversed representation of `x` + + + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } + + return rb; + }; // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm + + + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; + + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); + + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); + + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; + + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + /* jshint maxdepth : false */ + + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } + } + }; + + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; + + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } + + return 1 << i + 1 + odd; + }; + + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; + + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; + } + }; + + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; + + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; + + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } + + return ws; + }; + + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; + + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } // Pad with zeroes + + + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } + + assert(carry === 0); + assert((carry & ~8191) === 0); + }; + + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); + + for (var i = 0; i < N; i++) { + ph[i] = 0; + } + + return ph; + }; + + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); + + var _ = this.stub(N); + + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); + + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } + + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; // Multiply `this` by `num` + + + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$y).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT + + + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$y).length + num.length); + return jumboMulTo(this || _global$y, num, out); + }; // In-place Multiplication + + + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$y); + }; + + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); // Carry + + var carry = 0; + + for (var i = 0; i < (this || _global$y).length; i++) { + var w = ((this || _global$y).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum + + carry += lo >>> 26; + (this || _global$y).words[i] = lo & 67108863; + } + + if (carry !== 0) { + (this || _global$y).words[i] = carry; + (this || _global$y).length++; + } + + return this || _global$y; + }; + + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` + + + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$y); + }; // `this` * `this` in-place + + + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) + + + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes + + var res = this || _global$y; + + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } + + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } + + return res; + }; // Shift-left in-place + + + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; + + if (r !== 0) { + var carry = 0; + + for (i = 0; i < (this || _global$y).length; i++) { + var newCarry = (this || _global$y).words[i] & carryMask; + var c = ((this || _global$y).words[i] | 0) - newCarry << r; + (this || _global$y).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } + + if (carry) { + (this || _global$y).words[i] = carry; + (this || _global$y).length++; + } + } + + if (s !== 0) { + for (i = (this || _global$y).length - 1; i >= 0; i--) { + (this || _global$y).words[i + s] = (this || _global$y).words[i]; + } + + for (i = 0; i < s; i++) { + (this || _global$y).words[i] = 0; + } + + (this || _global$y).length += s; + } + + return this.strip(); + }; + + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$y).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits + + + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; + + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } + + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$y).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part + + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$y).words[i]; + } + + maskedWords.length = s; + } + + if (s === 0) ; else if ((this || _global$y).length > s) { + (this || _global$y).length -= s; + + for (i = 0; i < (this || _global$y).length; i++) { + (this || _global$y).words[i] = (this || _global$y).words[i + s]; + } + } else { + (this || _global$y).words[0] = 0; + (this || _global$y).length = 1; + } + + var carry = 0; + + for (i = (this || _global$y).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$y).words[i] | 0; + (this || _global$y).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask + + + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } + + if ((this || _global$y).length === 0) { + (this || _global$y).words[0] = 0; + (this || _global$y).length = 1; + } + + return this.strip(); + }; + + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$y).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left + + + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; + + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right + + + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; + + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set + + + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$y).length <= s) return false; // Check bit and return + + var w = (this || _global$y).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) + + + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$y).negative === 0, "imaskn works only with positive numbers"); + + if ((this || _global$y).length <= s) { + return this || _global$y; + } + + if (r !== 0) { + s++; + } + + (this || _global$y).length = Math.min(s, (this || _global$y).length); + + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$y).words[(this || _global$y).length - 1] &= mask; + } + + return this.strip(); + }; // Return only lowers bits of number + + + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` + + + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change + + if ((this || _global$y).negative !== 0) { + if ((this || _global$y).length === 1 && ((this || _global$y).words[0] | 0) < num) { + (this || _global$y).words[0] = num - ((this || _global$y).words[0] | 0); + (this || _global$y).negative = 0; + return this || _global$y; + } + + (this || _global$y).negative = 0; + this.isubn(num); + (this || _global$y).negative = 1; + return this || _global$y; + } // Add without checks + + + return this._iaddn(num); + }; + + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$y).words[0] += num; // Carry + + for (var i = 0; i < (this || _global$y).length && (this || _global$y).words[i] >= 67108864; i++) { + (this || _global$y).words[i] -= 67108864; + + if (i === (this || _global$y).length - 1) { + (this || _global$y).words[i + 1] = 1; + } else { + (this || _global$y).words[i + 1]++; + } + } + + (this || _global$y).length = Math.max((this || _global$y).length, i + 1); + return this || _global$y; + }; // Subtract plain number `num` from `this` + + + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); + + if ((this || _global$y).negative !== 0) { + (this || _global$y).negative = 0; + this.iaddn(num); + (this || _global$y).negative = 1; + return this || _global$y; + } + + (this || _global$y).words[0] -= num; + + if ((this || _global$y).length === 1 && (this || _global$y).words[0] < 0) { + (this || _global$y).words[0] = -(this || _global$y).words[0]; + (this || _global$y).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$y).length && (this || _global$y).words[i] < 0; i++) { + (this || _global$y).words[i] += 67108864; + (this || _global$y).words[i + 1] -= 1; + } + } + + return this.strip(); + }; + + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; + + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; + + BN.prototype.iabs = function iabs() { + (this || _global$y).negative = 0; + return this || _global$y; + }; + + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; + + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + + this._expand(len); + + var w; + var carry = 0; + + for (i = 0; i < num.length; i++) { + w = ((this || _global$y).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$y).words[i + shift] = w & 67108863; + } + + for (; i < (this || _global$y).length - shift; i++) { + w = ((this || _global$y).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$y).words[i + shift] = w & 67108863; + } + + if (carry === 0) return this.strip(); // Subtraction overflow + + assert(carry === -1); + carry = 0; + + for (i = 0; i < (this || _global$y).length; i++) { + w = -((this || _global$y).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$y).words[i] = w & 67108863; + } + + (this || _global$y).negative = 1; + return this.strip(); + }; + + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$y).length - num.length; + var a = this.clone(); + var b = num; // Normalize + + var bhi = b.words[b.length - 1] | 0; + + var bhiBits = this._countBits(bhi); + + shift = 26 - bhiBits; + + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient + + + var m = a.length - b.length; + var q; + + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); + + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } + + var diff = a.clone()._ishlnsubmul(b, 1, m); + + if (diff.negative === 0) { + a = diff; + + if (q) { + q.words[m] = 1; + } + } + + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) + + qj = Math.min(qj / bhi | 0, 67108863); + + a._ishlnsubmul(b, qj, j); + + while (a.negative !== 0) { + qj--; + a.negative = 0; + + a._ishlnsubmul(b, 1, j); + + if (!a.isZero()) { + a.negative ^= 1; + } + } + + if (q) { + q.words[j] = qj; + } + } + + if (q) { + q.strip(); + } + + a.strip(); // Denormalize + + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } + + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested + + + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); + + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } + + var div, mod, res; + + if ((this || _global$y).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } + + return { + div: div, + mod: mod + }; + } + + if ((this || _global$y).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + return { + div: div, + mod: res.mod + }; + } + + if (((this || _global$y).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } + + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value + + + if (num.length > (this || _global$y).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$y + }; + } // Very short reduction + + + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } + + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } + + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } + + return this._wordDiv(num, mode); + }; // Find `this` / `num` + + + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` + + + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; + + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) + + + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division + + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down + + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; + + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + + for (var i = (this || _global$y).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$y).words[i] | 0)) % num; + } + + return acc; + }; // In-place division by number + + + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + + for (var i = (this || _global$y).length - 1; i >= 0; i--) { + var w = ((this || _global$y).words[i] | 0) + carry * 67108864; + (this || _global$y).words[i] = w / num | 0; + carry = w % num; + } + + return this.strip(); + }; + + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; + + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$y; + var y = p.clone(); + + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x + + + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y + + var C = new BN(0); + var D = new BN(1); + var g = 0; + + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } + + var yp = y.clone(); + var xp = x.clone(); + + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + x.iushrn(i); + + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + + A.iushrn(1); + B.iushrn(1); + } + } + + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + y.iushrn(j); + + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + + C.iushrn(1); + D.iushrn(1); + } + } + + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed + + + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$y; + var b = p.clone(); + + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } + + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); + + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + a.iushrn(i); + + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } + + x1.iushrn(1); + } + } + + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + b.iushrn(j); + + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } + + x2.iushrn(1); + } + } + + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + + var res; + + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + + if (res.cmpn(0) < 0) { + res.iadd(p); + } + + return res; + }; + + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two + + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + + do { + while (a.isEven()) { + a.iushrn(1); + } + + while (b.isEven()) { + b.iushrn(1); + } + + var r = a.cmp(b); + + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + + a.isub(b); + } while (true); + + return b.iushln(shift); + }; // Invert number in the field F(num) + + + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + + BN.prototype.isEven = function isEven() { + return ((this || _global$y).words[0] & 1) === 0; + }; + + BN.prototype.isOdd = function isOdd() { + return ((this || _global$y).words[0] & 1) === 1; + }; // And first word and num + + + BN.prototype.andln = function andln(num) { + return (this || _global$y).words[0] & num; + }; // Increment at the bit position in-line + + + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$y).length <= s) { + this._expand(s + 1); + + (this || _global$y).words[s] |= q; + return this || _global$y; + } // Add bit and propagate, if needed + + + var carry = q; + + for (var i = s; carry !== 0 && i < (this || _global$y).length; i++) { + var w = (this || _global$y).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$y).words[i] = w; + } + + if (carry !== 0) { + (this || _global$y).words[i] = carry; + (this || _global$y).length++; + } + + return this || _global$y; + }; + + BN.prototype.isZero = function isZero() { + return (this || _global$y).length === 1 && (this || _global$y).words[0] === 0; + }; + + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$y).negative !== 0 && !negative) return -1; + if ((this || _global$y).negative === 0 && negative) return 1; + this.strip(); + var res; + + if ((this || _global$y).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$y).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + + if ((this || _global$y).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + + + BN.prototype.cmp = function cmp(num) { + if ((this || _global$y).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$y).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$y).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison + + + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$y).length > num.length) return 1; + if ((this || _global$y).length < num.length) return -1; + var res = 0; + + for (var i = (this || _global$y).length - 1; i >= 0; i--) { + var a = (this || _global$y).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + + break; + } + + return res; + }; + + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + + + BN.red = function red(num) { + return new Red(num); + }; + + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$y).red, "Already a number in reduction context"); + assert((this || _global$y).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$y)._forceRed(ctx); + }; + + BN.prototype.fromRed = function fromRed() { + assert((this || _global$y).red, "fromRed works only with numbers in reduction context"); + return (this || _global$y).red.convertFrom(this || _global$y); + }; + + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$y).red = ctx; + return this || _global$y; + }; + + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$y).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$y).red, "redAdd works only with red numbers"); + return (this || _global$y).red.add(this || _global$y, num); + }; + + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$y).red, "redIAdd works only with red numbers"); + return (this || _global$y).red.iadd(this || _global$y, num); + }; + + BN.prototype.redSub = function redSub(num) { + assert((this || _global$y).red, "redSub works only with red numbers"); + return (this || _global$y).red.sub(this || _global$y, num); + }; + + BN.prototype.redISub = function redISub(num) { + assert((this || _global$y).red, "redISub works only with red numbers"); + return (this || _global$y).red.isub(this || _global$y, num); + }; + + BN.prototype.redShl = function redShl(num) { + assert((this || _global$y).red, "redShl works only with red numbers"); + return (this || _global$y).red.shl(this || _global$y, num); + }; + + BN.prototype.redMul = function redMul(num) { + assert((this || _global$y).red, "redMul works only with red numbers"); + + (this || _global$y).red._verify2(this || _global$y, num); + + return (this || _global$y).red.mul(this || _global$y, num); + }; + + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$y).red, "redMul works only with red numbers"); + + (this || _global$y).red._verify2(this || _global$y, num); + + return (this || _global$y).red.imul(this || _global$y, num); + }; + + BN.prototype.redSqr = function redSqr() { + assert((this || _global$y).red, "redSqr works only with red numbers"); + + (this || _global$y).red._verify1(this || _global$y); + + return (this || _global$y).red.sqr(this || _global$y); + }; + + BN.prototype.redISqr = function redISqr() { + assert((this || _global$y).red, "redISqr works only with red numbers"); + + (this || _global$y).red._verify1(this || _global$y); + + return (this || _global$y).red.isqr(this || _global$y); + }; // Square root over p + + + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$y).red, "redSqrt works only with red numbers"); + + (this || _global$y).red._verify1(this || _global$y); + + return (this || _global$y).red.sqrt(this || _global$y); + }; + + BN.prototype.redInvm = function redInvm() { + assert((this || _global$y).red, "redInvm works only with red numbers"); + + (this || _global$y).red._verify1(this || _global$y); + + return (this || _global$y).red.invm(this || _global$y); + }; // Return negative clone of `this` % `red modulo` + + + BN.prototype.redNeg = function redNeg() { + assert((this || _global$y).red, "redNeg works only with red numbers"); + + (this || _global$y).red._verify1(this || _global$y); + + return (this || _global$y).red.neg(this || _global$y); + }; + + BN.prototype.redPow = function redPow(num) { + assert((this || _global$y).red && !num.red, "redPow(normalNum)"); + + (this || _global$y).red._verify1(this || _global$y); + + return (this || _global$y).red.pow(this || _global$y, num); + }; // Prime numbers with efficient reduction + + + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime + + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$y).name = name; + (this || _global$y).p = new BN(p, 16); + (this || _global$y).n = (this || _global$y).p.bitLength(); + (this || _global$y).k = new BN(1).iushln((this || _global$y).n).isub((this || _global$y).p); + (this || _global$y).tmp = this._tmp(); + } + + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$y).n / 13)); + return tmp; + }; + + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + + do { + this.split(r, (this || _global$y).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$y).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$y).n); + + var cmp = rlen < (this || _global$y).n ? -1 : r.ucmp((this || _global$y).p); + + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$y).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + + return r; + }; + + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$y).n, 0, out); + }; + + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$y).k); + }; + + function K256() { + MPrime.call(this || _global$y, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + + inherits(K256, MPrime); + + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + + output.length = outLen; + + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs + + + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + + prev >>>= 22; + input.words[i - 10] = prev; + + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + + var lo = 0; + + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction + + + if (num.words[num.length - 1] === 0) { + num.length--; + + if (num.words[num.length - 1] === 0) { + num.length--; + } + } + + return num; + }; + + function P224() { + MPrime.call(this || _global$y, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } + + inherits(P224, MPrime); + + function P192() { + MPrime.call(this || _global$y, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } + + inherits(P192, MPrime); + + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$y, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } + + inherits(P25519, MPrime); + + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } + + if (carry !== 0) { + num.words[num.length++] = carry; + } + + return num; + }; // Exported mostly for testing purposes, use plain name instead + + + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // + + + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + + (this || _global$y).m = prime.p; + (this || _global$y).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$y).m = m; + (this || _global$y).prime = null; + } + } + + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; + + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; + + Red.prototype.imod = function imod(a) { + if ((this || _global$y).prime) return (this || _global$y).prime.ireduce(a)._forceRed(this || _global$y); + return a.umod((this || _global$y).m)._forceRed(this || _global$y); + }; + + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } + + return (this || _global$y).m.sub(a)._forceRed(this || _global$y); + }; + + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + + var res = a.add(b); + + if (res.cmp((this || _global$y).m) >= 0) { + res.isub((this || _global$y).m); + } + + return res._forceRed(this || _global$y); + }; + + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + + var res = a.iadd(b); + + if (res.cmp((this || _global$y).m) >= 0) { + res.isub((this || _global$y).m); + } + + return res; + }; + + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); + + var res = a.sub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$y).m); + } + + return res._forceRed(this || _global$y); + }; + + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); + + var res = a.isub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$y).m); + } + + return res; + }; + + Red.prototype.shl = function shl(a, num) { + this._verify1(a); + + return this.imod(a.ushln(num)); + }; + + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); + + return this.imod(a.imul(b)); + }; + + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); + + return this.imod(a.mul(b)); + }; + + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; + + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + + var mod3 = (this || _global$y).m.andln(3); + + assert(mod3 % 2 === 1); // Fast case + + if (mod3 === 3) { + var pow = (this || _global$y).m.add(new BN(1)).iushrn(2); + + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) + + + var q = (this || _global$y).m.subn(1); + + var s = 0; + + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$y); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + + var lpow = (this || _global$y).m.subn(1).iushrn(1); + + var z = (this || _global$y).m.bitLength(); + + z = new BN(2 * z * z).toRed(this || _global$y); + + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } + + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; + + while (t.cmp(one) !== 0) { + var tmp = t; + + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } + + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } + + return r; + }; + + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$y).m); + + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$y); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$y); + wnd[1] = a; + + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + + if (start === 0) { + start = 26; + } + + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + + if (res !== wnd[0]) { + res = this.sqr(res); + } + + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + + start = 26; + } + + return res; + }; + + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$y).m); + return r === num ? r.clone() : r; + }; + + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // + + + BN.mont = function mont(num) { + return new Mont(num); + }; + + function Mont(m) { + Red.call(this || _global$y, m); + (this || _global$y).shift = (this || _global$y).m.bitLength(); + + if ((this || _global$y).shift % 26 !== 0) { + (this || _global$y).shift += 26 - (this || _global$y).shift % 26; + } + + (this || _global$y).r = new BN(1).iushln((this || _global$y).shift); + (this || _global$y).r2 = this.imod((this || _global$y).r.sqr()); + (this || _global$y).rinv = (this || _global$y).r._invmp((this || _global$y).m); + (this || _global$y).minv = (this || _global$y).rinv.mul((this || _global$y).r).isubn(1).div((this || _global$y).m); + (this || _global$y).minv = (this || _global$y).minv.umod((this || _global$y).r); + (this || _global$y).minv = (this || _global$y).r.sub((this || _global$y).minv); + } + + inherits(Mont, Red); + + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$y).shift)); + }; + + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$y).rinv)); + r.red = null; + return r; + }; + + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + + var t = a.imul(b); + var c = t.maskn((this || _global$y).shift).mul((this || _global$y).minv).imaskn((this || _global$y).shift).mul((this || _global$y).m); + var u = t.isub(c).iushrn((this || _global$y).shift); + var res = u; + + if (u.cmp((this || _global$y).m) >= 0) { + res = u.isub((this || _global$y).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$y).m); + } + + return res._forceRed(this || _global$y); + }; + + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$y); + var t = a.mul(b); + var c = t.maskn((this || _global$y).shift).mul((this || _global$y).minv).imaskn((this || _global$y).shift).mul((this || _global$y).m); + var u = t.isub(c).iushrn((this || _global$y).shift); + var res = u; + + if (u.cmp((this || _global$y).m) >= 0) { + res = u.isub((this || _global$y).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$y).m); + } + + return res._forceRed(this || _global$y); + }; + + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$y).m).mul((this || _global$y).r2)); + return res._forceRed(this || _global$y); + }; + })(module$9, exports$1X); + + return module$9.exports; +} + +var exports$1W = {}, + _dewExec$1V = false; +function dew$1V() { + if (_dewExec$1V) return exports$1W; + _dewExec$1V = true; + exports$1W = exports$1W = dew$3$2(); + exports$1W.Stream = exports$1W; + exports$1W.Readable = exports$1W; + exports$1W.Writable = dew$8$2(); + exports$1W.Duplex = dew$7$2(); + exports$1W.Transform = dew$2$2(); + exports$1W.PassThrough = dew$1$2(); + exports$1W.finished = dew$6$2(); + exports$1W.pipeline = dew$2B(); + return exports$1W; +} + +var exports$1U = {}, + _dewExec$1T = false; +function dew$1T() { + if (_dewExec$1T) return exports$1U; + _dewExec$1T = true; + + /*! safe-buffer. MIT License. Feross Aboukhadijeh */ + + /* eslint-disable node/no-deprecated-api */ + var buffer = e$1$1$1; + var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers + + function copyProps(src, dst) { + for (var key in src) { + dst[key] = src[key]; + } + } + + if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + exports$1U = buffer; + } else { + // Copy properties from require('buffer') + copyProps(buffer, exports$1U); + exports$1U.Buffer = SafeBuffer; + } + + function SafeBuffer(arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length); + } + + SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer + + copyProps(Buffer, SafeBuffer); + + SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === "number") { + throw new TypeError("Argument must not be a number"); + } + + return Buffer(arg, encodingOrOffset, length); + }; + + SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + var buf = Buffer(size); + + if (fill !== undefined) { + if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } + } else { + buf.fill(0); + } + + return buf; + }; + + SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return Buffer(size); + }; + + SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return buffer.SlowBuffer(size); + }; + + return exports$1U; +} + +var exports$1T = {}, + _dewExec$1S = false; + +var _global$w = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1S() { + if (_dewExec$1S) return exports$1T; + _dewExec$1S = true; + var process = T$9; + // limit of Crypto.getRandomValues() + // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues + var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes + // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 + + var MAX_UINT32 = 4294967295; + + function oldBrowser() { + throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11"); + } + + var Buffer = dew$1T().Buffer; + + var crypto = _global$w.crypto || _global$w.msCrypto; + + if (crypto && crypto.getRandomValues) { + exports$1T = randomBytes; + } else { + exports$1T = oldBrowser; + } + + function randomBytes(size, cb) { + // phantomjs needs to throw + if (size > MAX_UINT32) throw new RangeError("requested too many random bytes"); + var bytes = Buffer.allocUnsafe(size); + + if (size > 0) { + // getRandomValues fails on IE if size == 0 + if (size > MAX_BYTES) { + // this is the max bytes crypto.getRandomValues + // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues + for (var generated = 0; generated < size; generated += MAX_BYTES) { + // buffer.slice automatically checks if the end is past the end of + // the buffer so we don't have to here + crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES)); + } + } else { + crypto.getRandomValues(bytes); + } + } + + if (typeof cb === "function") { + return process.nextTick(function () { + cb(null, bytes); + }); + } + + return bytes; + } + + return exports$1T; +} + +var exports$1S = {}, + _dewExec$1R = false; +function dew$1R() { + if (_dewExec$1R) return exports$1S; + _dewExec$1R = true; + + var Buffer = dew$1T().Buffer; + + var Transform = dew$1V().Transform; + + var inherits = dew$f$2(); + + function throwIfNotStringOrBuffer(val, prefix) { + if (!Buffer.isBuffer(val) && typeof val !== "string") { + throw new TypeError(prefix + " must be a string or a buffer"); + } + } + + function HashBase(blockSize) { + Transform.call(this); + this._block = Buffer.allocUnsafe(blockSize); + this._blockSize = blockSize; + this._blockOffset = 0; + this._length = [0, 0, 0, 0]; + this._finalized = false; + } + + inherits(HashBase, Transform); + + HashBase.prototype._transform = function (chunk, encoding, callback) { + var error = null; + + try { + this.update(chunk, encoding); + } catch (err) { + error = err; + } + + callback(error); + }; + + HashBase.prototype._flush = function (callback) { + var error = null; + + try { + this.push(this.digest()); + } catch (err) { + error = err; + } + + callback(error); + }; + + HashBase.prototype.update = function (data, encoding) { + throwIfNotStringOrBuffer(data, "Data"); + if (this._finalized) throw new Error("Digest already called"); + if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data + + var block = this._block; + var offset = 0; + + while (this._blockOffset + data.length - offset >= this._blockSize) { + for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]; + + this._update(); + + this._blockOffset = 0; + } + + while (offset < data.length) block[this._blockOffset++] = data[offset++]; // update length + + + for (var j = 0, carry = data.length * 8; carry > 0; ++j) { + this._length[j] += carry; + carry = this._length[j] / 4294967296 | 0; + if (carry > 0) this._length[j] -= 4294967296 * carry; + } + + return this; + }; + + HashBase.prototype._update = function () { + throw new Error("_update is not implemented"); + }; + + HashBase.prototype.digest = function (encoding) { + if (this._finalized) throw new Error("Digest already called"); + this._finalized = true; + + var digest = this._digest(); + + if (encoding !== undefined) digest = digest.toString(encoding); // reset state + + this._block.fill(0); + + this._blockOffset = 0; + + for (var i = 0; i < 4; ++i) this._length[i] = 0; + + return digest; + }; + + HashBase.prototype._digest = function () { + throw new Error("_digest is not implemented"); + }; + + exports$1S = HashBase; + return exports$1S; +} + +var exports$1R = {}, + _dewExec$1Q = false; +function dew$1Q() { + if (_dewExec$1Q) return exports$1R; + _dewExec$1Q = true; + + var inherits = dew$f$2(); + + var HashBase = dew$1R(); + + var Buffer = dew$1T().Buffer; + + var ARRAY16 = new Array(16); + + function MD5() { + HashBase.call(this, 64); // state + + this._a = 1732584193; + this._b = 4023233417; + this._c = 2562383102; + this._d = 271733878; + } + + inherits(MD5, HashBase); + + MD5.prototype._update = function () { + var M = ARRAY16; + + for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4); + + var a = this._a; + var b = this._b; + var c = this._c; + var d = this._d; + a = fnF(a, b, c, d, M[0], 3614090360, 7); + d = fnF(d, a, b, c, M[1], 3905402710, 12); + c = fnF(c, d, a, b, M[2], 606105819, 17); + b = fnF(b, c, d, a, M[3], 3250441966, 22); + a = fnF(a, b, c, d, M[4], 4118548399, 7); + d = fnF(d, a, b, c, M[5], 1200080426, 12); + c = fnF(c, d, a, b, M[6], 2821735955, 17); + b = fnF(b, c, d, a, M[7], 4249261313, 22); + a = fnF(a, b, c, d, M[8], 1770035416, 7); + d = fnF(d, a, b, c, M[9], 2336552879, 12); + c = fnF(c, d, a, b, M[10], 4294925233, 17); + b = fnF(b, c, d, a, M[11], 2304563134, 22); + a = fnF(a, b, c, d, M[12], 1804603682, 7); + d = fnF(d, a, b, c, M[13], 4254626195, 12); + c = fnF(c, d, a, b, M[14], 2792965006, 17); + b = fnF(b, c, d, a, M[15], 1236535329, 22); + a = fnG(a, b, c, d, M[1], 4129170786, 5); + d = fnG(d, a, b, c, M[6], 3225465664, 9); + c = fnG(c, d, a, b, M[11], 643717713, 14); + b = fnG(b, c, d, a, M[0], 3921069994, 20); + a = fnG(a, b, c, d, M[5], 3593408605, 5); + d = fnG(d, a, b, c, M[10], 38016083, 9); + c = fnG(c, d, a, b, M[15], 3634488961, 14); + b = fnG(b, c, d, a, M[4], 3889429448, 20); + a = fnG(a, b, c, d, M[9], 568446438, 5); + d = fnG(d, a, b, c, M[14], 3275163606, 9); + c = fnG(c, d, a, b, M[3], 4107603335, 14); + b = fnG(b, c, d, a, M[8], 1163531501, 20); + a = fnG(a, b, c, d, M[13], 2850285829, 5); + d = fnG(d, a, b, c, M[2], 4243563512, 9); + c = fnG(c, d, a, b, M[7], 1735328473, 14); + b = fnG(b, c, d, a, M[12], 2368359562, 20); + a = fnH(a, b, c, d, M[5], 4294588738, 4); + d = fnH(d, a, b, c, M[8], 2272392833, 11); + c = fnH(c, d, a, b, M[11], 1839030562, 16); + b = fnH(b, c, d, a, M[14], 4259657740, 23); + a = fnH(a, b, c, d, M[1], 2763975236, 4); + d = fnH(d, a, b, c, M[4], 1272893353, 11); + c = fnH(c, d, a, b, M[7], 4139469664, 16); + b = fnH(b, c, d, a, M[10], 3200236656, 23); + a = fnH(a, b, c, d, M[13], 681279174, 4); + d = fnH(d, a, b, c, M[0], 3936430074, 11); + c = fnH(c, d, a, b, M[3], 3572445317, 16); + b = fnH(b, c, d, a, M[6], 76029189, 23); + a = fnH(a, b, c, d, M[9], 3654602809, 4); + d = fnH(d, a, b, c, M[12], 3873151461, 11); + c = fnH(c, d, a, b, M[15], 530742520, 16); + b = fnH(b, c, d, a, M[2], 3299628645, 23); + a = fnI(a, b, c, d, M[0], 4096336452, 6); + d = fnI(d, a, b, c, M[7], 1126891415, 10); + c = fnI(c, d, a, b, M[14], 2878612391, 15); + b = fnI(b, c, d, a, M[5], 4237533241, 21); + a = fnI(a, b, c, d, M[12], 1700485571, 6); + d = fnI(d, a, b, c, M[3], 2399980690, 10); + c = fnI(c, d, a, b, M[10], 4293915773, 15); + b = fnI(b, c, d, a, M[1], 2240044497, 21); + a = fnI(a, b, c, d, M[8], 1873313359, 6); + d = fnI(d, a, b, c, M[15], 4264355552, 10); + c = fnI(c, d, a, b, M[6], 2734768916, 15); + b = fnI(b, c, d, a, M[13], 1309151649, 21); + a = fnI(a, b, c, d, M[4], 4149444226, 6); + d = fnI(d, a, b, c, M[11], 3174756917, 10); + c = fnI(c, d, a, b, M[2], 718787259, 15); + b = fnI(b, c, d, a, M[9], 3951481745, 21); + this._a = this._a + a | 0; + this._b = this._b + b | 0; + this._c = this._c + c | 0; + this._d = this._d + d | 0; + }; + + MD5.prototype._digest = function () { + // create padding and handle blocks + this._block[this._blockOffset++] = 128; + + if (this._blockOffset > 56) { + this._block.fill(0, this._blockOffset, 64); + + this._update(); + + this._blockOffset = 0; + } + + this._block.fill(0, this._blockOffset, 56); + + this._block.writeUInt32LE(this._length[0], 56); + + this._block.writeUInt32LE(this._length[1], 60); + + this._update(); // produce result + + + var buffer = Buffer.allocUnsafe(16); + buffer.writeInt32LE(this._a, 0); + buffer.writeInt32LE(this._b, 4); + buffer.writeInt32LE(this._c, 8); + buffer.writeInt32LE(this._d, 12); + return buffer; + }; + + function rotl(x, n) { + return x << n | x >>> 32 - n; + } + + function fnF(a, b, c, d, m, k, s) { + return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0; + } + + function fnG(a, b, c, d, m, k, s) { + return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0; + } + + function fnH(a, b, c, d, m, k, s) { + return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0; + } + + function fnI(a, b, c, d, m, k, s) { + return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0; + } + + exports$1R = MD5; + return exports$1R; +} + +var exports$1Q = {}, + _dewExec$1P = false; +function dew$1P() { + if (_dewExec$1P) return exports$1Q; + _dewExec$1P = true; + var Buffer = e$1$1$1.Buffer; + + var inherits = dew$f$2(); + + var HashBase = dew$1R(); + + var ARRAY16 = new Array(16); + var zl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]; + var zr = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; + var sl = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]; + var sr = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; + var hl = [0, 1518500249, 1859775393, 2400959708, 2840853838]; + var hr = [1352829926, 1548603684, 1836072691, 2053994217, 0]; + + function RIPEMD160() { + HashBase.call(this, 64); // state + + this._a = 1732584193; + this._b = 4023233417; + this._c = 2562383102; + this._d = 271733878; + this._e = 3285377520; + } + + inherits(RIPEMD160, HashBase); + + RIPEMD160.prototype._update = function () { + var words = ARRAY16; + + for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4); + + var al = this._a | 0; + var bl = this._b | 0; + var cl = this._c | 0; + var dl = this._d | 0; + var el = this._e | 0; + var ar = this._a | 0; + var br = this._b | 0; + var cr = this._c | 0; + var dr = this._d | 0; + var er = this._e | 0; // computation + + for (var i = 0; i < 80; i += 1) { + var tl; + var tr; + + if (i < 16) { + tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]); + tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]); + } else if (i < 32) { + tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]); + tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]); + } else if (i < 48) { + tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]); + tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]); + } else if (i < 64) { + tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]); + tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]); + } else { + // if (i<80) { + tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]); + tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]); + } + + al = el; + el = dl; + dl = rotl(cl, 10); + cl = bl; + bl = tl; + ar = er; + er = dr; + dr = rotl(cr, 10); + cr = br; + br = tr; + } // update state + + + var t = this._b + cl + dr | 0; + this._b = this._c + dl + er | 0; + this._c = this._d + el + ar | 0; + this._d = this._e + al + br | 0; + this._e = this._a + bl + cr | 0; + this._a = t; + }; + + RIPEMD160.prototype._digest = function () { + // create padding and handle blocks + this._block[this._blockOffset++] = 128; + + if (this._blockOffset > 56) { + this._block.fill(0, this._blockOffset, 64); + + this._update(); + + this._blockOffset = 0; + } + + this._block.fill(0, this._blockOffset, 56); + + this._block.writeUInt32LE(this._length[0], 56); + + this._block.writeUInt32LE(this._length[1], 60); + + this._update(); // produce result + + + var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20); + buffer.writeInt32LE(this._a, 0); + buffer.writeInt32LE(this._b, 4); + buffer.writeInt32LE(this._c, 8); + buffer.writeInt32LE(this._d, 12); + buffer.writeInt32LE(this._e, 16); + return buffer; + }; + + function rotl(x, n) { + return x << n | x >>> 32 - n; + } + + function fn1(a, b, c, d, e, m, k, s) { + return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0; + } + + function fn2(a, b, c, d, e, m, k, s) { + return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0; + } + + function fn3(a, b, c, d, e, m, k, s) { + return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0; + } + + function fn4(a, b, c, d, e, m, k, s) { + return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0; + } + + function fn5(a, b, c, d, e, m, k, s) { + return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0; + } + + exports$1Q = RIPEMD160; + return exports$1Q; +} + +var exports$1P = {}, + _dewExec$1O = false; + +var _global$v = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1O() { + if (_dewExec$1O) return exports$1P; + _dewExec$1O = true; + + var Buffer = dew$1T().Buffer; // prototype class for hash functions + + + function Hash(blockSize, finalSize) { + (this || _global$v)._block = Buffer.alloc(blockSize); + (this || _global$v)._finalSize = finalSize; + (this || _global$v)._blockSize = blockSize; + (this || _global$v)._len = 0; + } + + Hash.prototype.update = function (data, enc) { + if (typeof data === "string") { + enc = enc || "utf8"; + data = Buffer.from(data, enc); + } + + var block = (this || _global$v)._block; + var blockSize = (this || _global$v)._blockSize; + var length = data.length; + var accum = (this || _global$v)._len; + + for (var offset = 0; offset < length;) { + var assigned = accum % blockSize; + var remainder = Math.min(length - offset, blockSize - assigned); + + for (var i = 0; i < remainder; i++) { + block[assigned + i] = data[offset + i]; + } + + accum += remainder; + offset += remainder; + + if (accum % blockSize === 0) { + this._update(block); + } + } + + (this || _global$v)._len += length; + return this || _global$v; + }; + + Hash.prototype.digest = function (enc) { + var rem = (this || _global$v)._len % (this || _global$v)._blockSize; + (this || _global$v)._block[rem] = 128; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest + // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize + + (this || _global$v)._block.fill(0, rem + 1); + + if (rem >= (this || _global$v)._finalSize) { + this._update((this || _global$v)._block); + + (this || _global$v)._block.fill(0); + } + + var bits = (this || _global$v)._len * 8; // uint32 + + if (bits <= 4294967295) { + (this || _global$v)._block.writeUInt32BE(bits, (this || _global$v)._blockSize - 4); // uint64 + + } else { + var lowBits = (bits & 4294967295) >>> 0; + var highBits = (bits - lowBits) / 4294967296; + + (this || _global$v)._block.writeUInt32BE(highBits, (this || _global$v)._blockSize - 8); + + (this || _global$v)._block.writeUInt32BE(lowBits, (this || _global$v)._blockSize - 4); + } + + this._update((this || _global$v)._block); + + var hash = this._hash(); + + return enc ? hash.toString(enc) : hash; + }; + + Hash.prototype._update = function () { + throw new Error("_update must be implemented by subclass"); + }; + + exports$1P = Hash; + return exports$1P; +} + +var exports$1O = {}, + _dewExec$1N = false; + +var _global$u = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1N() { + if (_dewExec$1N) return exports$1O; + _dewExec$1N = true; + + /* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined + * in FIPS PUB 180-1 + * This source code is derived from sha1.js of the same repository. + * The difference between SHA-0 and SHA-1 is just a bitwise rotate left + * operation was added. + */ + var inherits = dew$f$2(); + + var Hash = dew$1O(); + + var Buffer = dew$1T().Buffer; + + var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; + var W = new Array(80); + + function Sha() { + this.init(); + (this || _global$u)._w = W; + Hash.call(this || _global$u, 64, 56); + } + + inherits(Sha, Hash); + + Sha.prototype.init = function () { + (this || _global$u)._a = 1732584193; + (this || _global$u)._b = 4023233417; + (this || _global$u)._c = 2562383102; + (this || _global$u)._d = 271733878; + (this || _global$u)._e = 3285377520; + return this || _global$u; + }; + + function rotl5(num) { + return num << 5 | num >>> 27; + } + + function rotl30(num) { + return num << 30 | num >>> 2; + } + + function ft(s, b, c, d) { + if (s === 0) return b & c | ~b & d; + if (s === 2) return b & c | b & d | c & d; + return b ^ c ^ d; + } + + Sha.prototype._update = function (M) { + var W = (this || _global$u)._w; + var a = (this || _global$u)._a | 0; + var b = (this || _global$u)._b | 0; + var c = (this || _global$u)._c | 0; + var d = (this || _global$u)._d | 0; + var e = (this || _global$u)._e | 0; + + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + + for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + + for (var j = 0; j < 80; ++j) { + var s = ~~(j / 20); + var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; + e = d; + d = c; + c = rotl30(b); + b = a; + a = t; + } + + (this || _global$u)._a = a + (this || _global$u)._a | 0; + (this || _global$u)._b = b + (this || _global$u)._b | 0; + (this || _global$u)._c = c + (this || _global$u)._c | 0; + (this || _global$u)._d = d + (this || _global$u)._d | 0; + (this || _global$u)._e = e + (this || _global$u)._e | 0; + }; + + Sha.prototype._hash = function () { + var H = Buffer.allocUnsafe(20); + H.writeInt32BE((this || _global$u)._a | 0, 0); + H.writeInt32BE((this || _global$u)._b | 0, 4); + H.writeInt32BE((this || _global$u)._c | 0, 8); + H.writeInt32BE((this || _global$u)._d | 0, 12); + H.writeInt32BE((this || _global$u)._e | 0, 16); + return H; + }; + + exports$1O = Sha; + return exports$1O; +} + +var exports$1N = {}, + _dewExec$1M = false; + +var _global$t = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1M() { + if (_dewExec$1M) return exports$1N; + _dewExec$1M = true; + + /* + * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined + * in FIPS PUB 180-1 + * Version 2.1a Copyright Paul Johnston 2000 - 2002. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * Distributed under the BSD License + * See http://pajhome.org.uk/crypt/md5 for details. + */ + var inherits = dew$f$2(); + + var Hash = dew$1O(); + + var Buffer = dew$1T().Buffer; + + var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; + var W = new Array(80); + + function Sha1() { + this.init(); + (this || _global$t)._w = W; + Hash.call(this || _global$t, 64, 56); + } + + inherits(Sha1, Hash); + + Sha1.prototype.init = function () { + (this || _global$t)._a = 1732584193; + (this || _global$t)._b = 4023233417; + (this || _global$t)._c = 2562383102; + (this || _global$t)._d = 271733878; + (this || _global$t)._e = 3285377520; + return this || _global$t; + }; + + function rotl1(num) { + return num << 1 | num >>> 31; + } + + function rotl5(num) { + return num << 5 | num >>> 27; + } + + function rotl30(num) { + return num << 30 | num >>> 2; + } + + function ft(s, b, c, d) { + if (s === 0) return b & c | ~b & d; + if (s === 2) return b & c | b & d | c & d; + return b ^ c ^ d; + } + + Sha1.prototype._update = function (M) { + var W = (this || _global$t)._w; + var a = (this || _global$t)._a | 0; + var b = (this || _global$t)._b | 0; + var c = (this || _global$t)._c | 0; + var d = (this || _global$t)._d | 0; + var e = (this || _global$t)._e | 0; + + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + + for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]); + + for (var j = 0; j < 80; ++j) { + var s = ~~(j / 20); + var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; + e = d; + d = c; + c = rotl30(b); + b = a; + a = t; + } + + (this || _global$t)._a = a + (this || _global$t)._a | 0; + (this || _global$t)._b = b + (this || _global$t)._b | 0; + (this || _global$t)._c = c + (this || _global$t)._c | 0; + (this || _global$t)._d = d + (this || _global$t)._d | 0; + (this || _global$t)._e = e + (this || _global$t)._e | 0; + }; + + Sha1.prototype._hash = function () { + var H = Buffer.allocUnsafe(20); + H.writeInt32BE((this || _global$t)._a | 0, 0); + H.writeInt32BE((this || _global$t)._b | 0, 4); + H.writeInt32BE((this || _global$t)._c | 0, 8); + H.writeInt32BE((this || _global$t)._d | 0, 12); + H.writeInt32BE((this || _global$t)._e | 0, 16); + return H; + }; + + exports$1N = Sha1; + return exports$1N; +} + +var exports$1M = {}, + _dewExec$1L = false; + +var _global$s = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1L() { + if (_dewExec$1L) return exports$1M; + _dewExec$1L = true; + + /** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ + var inherits = dew$f$2(); + + var Hash = dew$1O(); + + var Buffer = dew$1T().Buffer; + + var K = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298]; + var W = new Array(64); + + function Sha256() { + this.init(); + (this || _global$s)._w = W; // new Array(64) + + Hash.call(this || _global$s, 64, 56); + } + + inherits(Sha256, Hash); + + Sha256.prototype.init = function () { + (this || _global$s)._a = 1779033703; + (this || _global$s)._b = 3144134277; + (this || _global$s)._c = 1013904242; + (this || _global$s)._d = 2773480762; + (this || _global$s)._e = 1359893119; + (this || _global$s)._f = 2600822924; + (this || _global$s)._g = 528734635; + (this || _global$s)._h = 1541459225; + return this || _global$s; + }; + + function ch(x, y, z) { + return z ^ x & (y ^ z); + } + + function maj(x, y, z) { + return x & y | z & (x | y); + } + + function sigma0(x) { + return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10); + } + + function sigma1(x) { + return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7); + } + + function gamma0(x) { + return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3; + } + + function gamma1(x) { + return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10; + } + + Sha256.prototype._update = function (M) { + var W = (this || _global$s)._w; + var a = (this || _global$s)._a | 0; + var b = (this || _global$s)._b | 0; + var c = (this || _global$s)._c | 0; + var d = (this || _global$s)._d | 0; + var e = (this || _global$s)._e | 0; + var f = (this || _global$s)._f | 0; + var g = (this || _global$s)._g | 0; + var h = (this || _global$s)._h | 0; + + for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + + for (; i < 64; ++i) W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0; + + for (var j = 0; j < 64; ++j) { + var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0; + var T2 = sigma0(a) + maj(a, b, c) | 0; + h = g; + g = f; + f = e; + e = d + T1 | 0; + d = c; + c = b; + b = a; + a = T1 + T2 | 0; + } + + (this || _global$s)._a = a + (this || _global$s)._a | 0; + (this || _global$s)._b = b + (this || _global$s)._b | 0; + (this || _global$s)._c = c + (this || _global$s)._c | 0; + (this || _global$s)._d = d + (this || _global$s)._d | 0; + (this || _global$s)._e = e + (this || _global$s)._e | 0; + (this || _global$s)._f = f + (this || _global$s)._f | 0; + (this || _global$s)._g = g + (this || _global$s)._g | 0; + (this || _global$s)._h = h + (this || _global$s)._h | 0; + }; + + Sha256.prototype._hash = function () { + var H = Buffer.allocUnsafe(32); + H.writeInt32BE((this || _global$s)._a, 0); + H.writeInt32BE((this || _global$s)._b, 4); + H.writeInt32BE((this || _global$s)._c, 8); + H.writeInt32BE((this || _global$s)._d, 12); + H.writeInt32BE((this || _global$s)._e, 16); + H.writeInt32BE((this || _global$s)._f, 20); + H.writeInt32BE((this || _global$s)._g, 24); + H.writeInt32BE((this || _global$s)._h, 28); + return H; + }; + + exports$1M = Sha256; + return exports$1M; +} + +var exports$1L = {}, + _dewExec$1K = false; + +var _global$r = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1K() { + if (_dewExec$1K) return exports$1L; + _dewExec$1K = true; + + /** + * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined + * in FIPS 180-2 + * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. + * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet + * + */ + var inherits = dew$f$2(); + + var Sha256 = dew$1L(); + + var Hash = dew$1O(); + + var Buffer = dew$1T().Buffer; + + var W = new Array(64); + + function Sha224() { + this.init(); + (this || _global$r)._w = W; // new Array(64) + + Hash.call(this || _global$r, 64, 56); + } + + inherits(Sha224, Sha256); + + Sha224.prototype.init = function () { + (this || _global$r)._a = 3238371032; + (this || _global$r)._b = 914150663; + (this || _global$r)._c = 812702999; + (this || _global$r)._d = 4144912697; + (this || _global$r)._e = 4290775857; + (this || _global$r)._f = 1750603025; + (this || _global$r)._g = 1694076839; + (this || _global$r)._h = 3204075428; + return this || _global$r; + }; + + Sha224.prototype._hash = function () { + var H = Buffer.allocUnsafe(28); + H.writeInt32BE((this || _global$r)._a, 0); + H.writeInt32BE((this || _global$r)._b, 4); + H.writeInt32BE((this || _global$r)._c, 8); + H.writeInt32BE((this || _global$r)._d, 12); + H.writeInt32BE((this || _global$r)._e, 16); + H.writeInt32BE((this || _global$r)._f, 20); + H.writeInt32BE((this || _global$r)._g, 24); + return H; + }; + + exports$1L = Sha224; + return exports$1L; +} + +var exports$1K = {}, + _dewExec$1J = false; + +var _global$q = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1J() { + if (_dewExec$1J) return exports$1K; + _dewExec$1J = true; + + var inherits = dew$f$2(); + + var Hash = dew$1O(); + + var Buffer = dew$1T().Buffer; + + var K = [1116352408, 3609767458, 1899447441, 602891725, 3049323471, 3964484399, 3921009573, 2173295548, 961987163, 4081628472, 1508970993, 3053834265, 2453635748, 2937671579, 2870763221, 3664609560, 3624381080, 2734883394, 310598401, 1164996542, 607225278, 1323610764, 1426881987, 3590304994, 1925078388, 4068182383, 2162078206, 991336113, 2614888103, 633803317, 3248222580, 3479774868, 3835390401, 2666613458, 4022224774, 944711139, 264347078, 2341262773, 604807628, 2007800933, 770255983, 1495990901, 1249150122, 1856431235, 1555081692, 3175218132, 1996064986, 2198950837, 2554220882, 3999719339, 2821834349, 766784016, 2952996808, 2566594879, 3210313671, 3203337956, 3336571891, 1034457026, 3584528711, 2466948901, 113926993, 3758326383, 338241895, 168717936, 666307205, 1188179964, 773529912, 1546045734, 1294757372, 1522805485, 1396182291, 2643833823, 1695183700, 2343527390, 1986661051, 1014477480, 2177026350, 1206759142, 2456956037, 344077627, 2730485921, 1290863460, 2820302411, 3158454273, 3259730800, 3505952657, 3345764771, 106217008, 3516065817, 3606008344, 3600352804, 1432725776, 4094571909, 1467031594, 275423344, 851169720, 430227734, 3100823752, 506948616, 1363258195, 659060556, 3750685593, 883997877, 3785050280, 958139571, 3318307427, 1322822218, 3812723403, 1537002063, 2003034995, 1747873779, 3602036899, 1955562222, 1575990012, 2024104815, 1125592928, 2227730452, 2716904306, 2361852424, 442776044, 2428436474, 593698344, 2756734187, 3733110249, 3204031479, 2999351573, 3329325298, 3815920427, 3391569614, 3928383900, 3515267271, 566280711, 3940187606, 3454069534, 4118630271, 4000239992, 116418474, 1914138554, 174292421, 2731055270, 289380356, 3203993006, 460393269, 320620315, 685471733, 587496836, 852142971, 1086792851, 1017036298, 365543100, 1126000580, 2618297676, 1288033470, 3409855158, 1501505948, 4234509866, 1607167915, 987167468, 1816402316, 1246189591]; + var W = new Array(160); + + function Sha512() { + this.init(); + (this || _global$q)._w = W; + Hash.call(this || _global$q, 128, 112); + } + + inherits(Sha512, Hash); + + Sha512.prototype.init = function () { + (this || _global$q)._ah = 1779033703; + (this || _global$q)._bh = 3144134277; + (this || _global$q)._ch = 1013904242; + (this || _global$q)._dh = 2773480762; + (this || _global$q)._eh = 1359893119; + (this || _global$q)._fh = 2600822924; + (this || _global$q)._gh = 528734635; + (this || _global$q)._hh = 1541459225; + (this || _global$q)._al = 4089235720; + (this || _global$q)._bl = 2227873595; + (this || _global$q)._cl = 4271175723; + (this || _global$q)._dl = 1595750129; + (this || _global$q)._el = 2917565137; + (this || _global$q)._fl = 725511199; + (this || _global$q)._gl = 4215389547; + (this || _global$q)._hl = 327033209; + return this || _global$q; + }; + + function Ch(x, y, z) { + return z ^ x & (y ^ z); + } + + function maj(x, y, z) { + return x & y | z & (x | y); + } + + function sigma0(x, xl) { + return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25); + } + + function sigma1(x, xl) { + return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23); + } + + function Gamma0(x, xl) { + return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7; + } + + function Gamma0l(x, xl) { + return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25); + } + + function Gamma1(x, xl) { + return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6; + } + + function Gamma1l(x, xl) { + return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26); + } + + function getCarry(a, b) { + return a >>> 0 < b >>> 0 ? 1 : 0; + } + + Sha512.prototype._update = function (M) { + var W = (this || _global$q)._w; + var ah = (this || _global$q)._ah | 0; + var bh = (this || _global$q)._bh | 0; + var ch = (this || _global$q)._ch | 0; + var dh = (this || _global$q)._dh | 0; + var eh = (this || _global$q)._eh | 0; + var fh = (this || _global$q)._fh | 0; + var gh = (this || _global$q)._gh | 0; + var hh = (this || _global$q)._hh | 0; + var al = (this || _global$q)._al | 0; + var bl = (this || _global$q)._bl | 0; + var cl = (this || _global$q)._cl | 0; + var dl = (this || _global$q)._dl | 0; + var el = (this || _global$q)._el | 0; + var fl = (this || _global$q)._fl | 0; + var gl = (this || _global$q)._gl | 0; + var hl = (this || _global$q)._hl | 0; + + for (var i = 0; i < 32; i += 2) { + W[i] = M.readInt32BE(i * 4); + W[i + 1] = M.readInt32BE(i * 4 + 4); + } + + for (; i < 160; i += 2) { + var xh = W[i - 15 * 2]; + var xl = W[i - 15 * 2 + 1]; + var gamma0 = Gamma0(xh, xl); + var gamma0l = Gamma0l(xl, xh); + xh = W[i - 2 * 2]; + xl = W[i - 2 * 2 + 1]; + var gamma1 = Gamma1(xh, xl); + var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + + var Wi7h = W[i - 7 * 2]; + var Wi7l = W[i - 7 * 2 + 1]; + var Wi16h = W[i - 16 * 2]; + var Wi16l = W[i - 16 * 2 + 1]; + var Wil = gamma0l + Wi7l | 0; + var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0; + Wil = Wil + gamma1l | 0; + Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0; + Wil = Wil + Wi16l | 0; + Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0; + W[i] = Wih; + W[i + 1] = Wil; + } + + for (var j = 0; j < 160; j += 2) { + Wih = W[j]; + Wil = W[j + 1]; + var majh = maj(ah, bh, ch); + var majl = maj(al, bl, cl); + var sigma0h = sigma0(ah, al); + var sigma0l = sigma0(al, ah); + var sigma1h = sigma1(eh, el); + var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j] + + var Kih = K[j]; + var Kil = K[j + 1]; + var chh = Ch(eh, fh, gh); + var chl = Ch(el, fl, gl); + var t1l = hl + sigma1l | 0; + var t1h = hh + sigma1h + getCarry(t1l, hl) | 0; + t1l = t1l + chl | 0; + t1h = t1h + chh + getCarry(t1l, chl) | 0; + t1l = t1l + Kil | 0; + t1h = t1h + Kih + getCarry(t1l, Kil) | 0; + t1l = t1l + Wil | 0; + t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj + + var t2l = sigma0l + majl | 0; + var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0; + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + el = dl + t1l | 0; + eh = dh + t1h + getCarry(el, dl) | 0; + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + al = t1l + t2l | 0; + ah = t1h + t2h + getCarry(al, t1l) | 0; + } + + (this || _global$q)._al = (this || _global$q)._al + al | 0; + (this || _global$q)._bl = (this || _global$q)._bl + bl | 0; + (this || _global$q)._cl = (this || _global$q)._cl + cl | 0; + (this || _global$q)._dl = (this || _global$q)._dl + dl | 0; + (this || _global$q)._el = (this || _global$q)._el + el | 0; + (this || _global$q)._fl = (this || _global$q)._fl + fl | 0; + (this || _global$q)._gl = (this || _global$q)._gl + gl | 0; + (this || _global$q)._hl = (this || _global$q)._hl + hl | 0; + (this || _global$q)._ah = (this || _global$q)._ah + ah + getCarry((this || _global$q)._al, al) | 0; + (this || _global$q)._bh = (this || _global$q)._bh + bh + getCarry((this || _global$q)._bl, bl) | 0; + (this || _global$q)._ch = (this || _global$q)._ch + ch + getCarry((this || _global$q)._cl, cl) | 0; + (this || _global$q)._dh = (this || _global$q)._dh + dh + getCarry((this || _global$q)._dl, dl) | 0; + (this || _global$q)._eh = (this || _global$q)._eh + eh + getCarry((this || _global$q)._el, el) | 0; + (this || _global$q)._fh = (this || _global$q)._fh + fh + getCarry((this || _global$q)._fl, fl) | 0; + (this || _global$q)._gh = (this || _global$q)._gh + gh + getCarry((this || _global$q)._gl, gl) | 0; + (this || _global$q)._hh = (this || _global$q)._hh + hh + getCarry((this || _global$q)._hl, hl) | 0; + }; + + Sha512.prototype._hash = function () { + var H = Buffer.allocUnsafe(64); + + function writeInt64BE(h, l, offset) { + H.writeInt32BE(h, offset); + H.writeInt32BE(l, offset + 4); + } + + writeInt64BE((this || _global$q)._ah, (this || _global$q)._al, 0); + writeInt64BE((this || _global$q)._bh, (this || _global$q)._bl, 8); + writeInt64BE((this || _global$q)._ch, (this || _global$q)._cl, 16); + writeInt64BE((this || _global$q)._dh, (this || _global$q)._dl, 24); + writeInt64BE((this || _global$q)._eh, (this || _global$q)._el, 32); + writeInt64BE((this || _global$q)._fh, (this || _global$q)._fl, 40); + writeInt64BE((this || _global$q)._gh, (this || _global$q)._gl, 48); + writeInt64BE((this || _global$q)._hh, (this || _global$q)._hl, 56); + return H; + }; + + exports$1K = Sha512; + return exports$1K; +} + +var exports$1J = {}, + _dewExec$1I = false; + +var _global$p = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1I() { + if (_dewExec$1I) return exports$1J; + _dewExec$1I = true; + + var inherits = dew$f$2(); + + var SHA512 = dew$1J(); + + var Hash = dew$1O(); + + var Buffer = dew$1T().Buffer; + + var W = new Array(160); + + function Sha384() { + this.init(); + (this || _global$p)._w = W; + Hash.call(this || _global$p, 128, 112); + } + + inherits(Sha384, SHA512); + + Sha384.prototype.init = function () { + (this || _global$p)._ah = 3418070365; + (this || _global$p)._bh = 1654270250; + (this || _global$p)._ch = 2438529370; + (this || _global$p)._dh = 355462360; + (this || _global$p)._eh = 1731405415; + (this || _global$p)._fh = 2394180231; + (this || _global$p)._gh = 3675008525; + (this || _global$p)._hh = 1203062813; + (this || _global$p)._al = 3238371032; + (this || _global$p)._bl = 914150663; + (this || _global$p)._cl = 812702999; + (this || _global$p)._dl = 4144912697; + (this || _global$p)._el = 4290775857; + (this || _global$p)._fl = 1750603025; + (this || _global$p)._gl = 1694076839; + (this || _global$p)._hl = 3204075428; + return this || _global$p; + }; + + Sha384.prototype._hash = function () { + var H = Buffer.allocUnsafe(48); + + function writeInt64BE(h, l, offset) { + H.writeInt32BE(h, offset); + H.writeInt32BE(l, offset + 4); + } + + writeInt64BE((this || _global$p)._ah, (this || _global$p)._al, 0); + writeInt64BE((this || _global$p)._bh, (this || _global$p)._bl, 8); + writeInt64BE((this || _global$p)._ch, (this || _global$p)._cl, 16); + writeInt64BE((this || _global$p)._dh, (this || _global$p)._dl, 24); + writeInt64BE((this || _global$p)._eh, (this || _global$p)._el, 32); + writeInt64BE((this || _global$p)._fh, (this || _global$p)._fl, 40); + return H; + }; + + exports$1J = Sha384; + return exports$1J; +} + +var exports$1I = {}, + _dewExec$1H = false; +var module$7 = { + exports: exports$1I +}; +function dew$1H() { + if (_dewExec$1H) return module$7.exports; + _dewExec$1H = true; + + var exports = module$7.exports = function SHA(algorithm) { + algorithm = algorithm.toLowerCase(); + var Algorithm = exports[algorithm]; + if (!Algorithm) throw new Error(algorithm + " is not supported (we accept pull requests)"); + return new Algorithm(); + }; + + exports.sha = dew$1N(); + exports.sha1 = dew$1M(); + exports.sha224 = dew$1K(); + exports.sha256 = dew$1L(); + exports.sha384 = dew$1I(); + exports.sha512 = dew$1J(); + return module$7.exports; +} + +var e$g=y$o.EventEmitter;var e$1$1={};const t$c={};function n$q(e,n,r){r||(r=Error);class o extends r{constructor(e,t,r){super(function(e,t,r){return "string"==typeof n?n:n(e,t,r)}(e,t,r));}}o.prototype.name=r.name,o.prototype.code=e,t$c[e]=o;}function r$h(e,t){if(Array.isArray(e)){const n=e.length;return e=e.map(e=>String(e)),n>2?`one of ${t} ${e.slice(0,n-1).join(", ")}, or `+e[n-1]:2===n?`one of ${t} ${e[0]} or ${e[1]}`:`of ${t} ${e[0]}`}return `of ${t} ${String(e)}`}n$q("ERR_INVALID_OPT_VALUE",(function(e,t){return 'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),n$q("ERR_INVALID_ARG_TYPE",(function(e,t,n){let o;var E;let u;if("string"==typeof t&&(E="not ",t.substr(0,E.length)===E)?(o="must not be",t=t.replace(/^not /,"")):o="must be",function(e,t,n){return (void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}(e," argument"))u=`The ${e} ${o} ${r$h(t,"type")}`;else {u=`The "${e}" ${function(e,t,n){return "number"!=typeof n&&(n=0),!(n+t.length>e.length)&&-1!==e.indexOf(t,n)}(e,".")?"property":"argument"} ${o} ${r$h(t,"type")}`;}return u+=`. Received type ${typeof n}`,u}),TypeError),n$q("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),n$q("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return "The "+e+" method is not implemented"})),n$q("ERR_STREAM_PREMATURE_CLOSE","Premature close"),n$q("ERR_STREAM_DESTROYED",(function(e){return "Cannot call "+e+" after a stream was destroyed"})),n$q("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),n$q("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),n$q("ERR_STREAM_WRITE_AFTER_END","write after end"),n$q("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),n$q("ERR_UNKNOWN_ENCODING",(function(e){return "Unknown encoding: "+e}),TypeError),n$q("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e$1$1.codes=t$c;var r$1$1=function(){throw new Error("Readable.from is not available in the browser")};var r$2$1="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function e$2$1(e){try{if(!r$2$1.localStorage)return !1}catch(r){return !1}var t=r$2$1.localStorage[e];return null!=t&&"true"===String(t).toLowerCase()}var t$1$1=function(t,n){if(e$2$1("noDeprecation"))return t;var o=!1;return function(){if(!o){if(e$2$1("throwDeprecation"))throw new Error(n);e$2$1("traceDeprecation")?console.trace(n):console.warn(n),o=!0;}return t.apply(this||r$2$1,arguments)}};function u$p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r);}return n}function f$v(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h$l(e,t){for(var n=0;n0?this.tail.next=t:this.head=t,this.tail=t,++this.length;}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length;}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0;}},{key:"join",value:function(e){if(0===this.length)return "";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return c$n.alloc(0);for(var t,n,r,i=c$n.allocUnsafe(e>>>0),a=this.head,o=0;a;)t=a.data,n=i,r=o,void c$n.prototype.copy.call(t,n,r),o+=a.data.length,a=a.next;return i}},{key:"consume",value:function(e,t){var n;return ei.length?i.length:e;if(a===i.length?r+=i:r+=i.slice(0,e),0==(e-=a)){a===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(a));break}++n;}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=c$n.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),0==(e-=a)){a===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(a));break}++r;}return this.length-=r,t}},{key:p$s,value:function(e,t){return b$j(this,function(e){for(var t=1;t0)if("string"==typeof t||o.objectMode||Object.getPrototypeOf(t)===c.prototype||(t=function(e){return c.from(e)}(t)),r)o.endEmitted?x(e,new P):q(e,o,t,!0);else if(o.ended)x(e,new O);else {if(o.destroyed)return !1;o.reading=!1,o.decoder&&!n?(t=o.decoder.write(t),o.objectMode||0!==t.length?q(e,o,t,!1):N(e,o)):q(e,o,t,!1);}else r||(o.reading=!1,N(e,o));return !o.ended&&(o.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function B(e){var t=e._readableState;p("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(p("emitReadable",t.flowing),t.emittedReadable=!0,u.nextTick(I,e));}function I(e){var t=e._readableState;p("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,J(e);}function N(e,t){t.readingMore||(t.readingMore=!0,u.nextTick(U,e,t));}function U(e,t){for(;!t.reading&&!t.ended&&(t.length0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume();}function K(e){p("readable nexttick read 0"),e.read(0);}function z(e,t){p("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),J(e),t.flowing&&!t.reading&&e.read(0);}function J(e){var t=e._readableState;for(p("flow",t.flowing);t.flowing&&null!==e.read(););}function Q(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n;}function X(e){var t=e._readableState;p("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,u.nextTick(Z,t,e));}function Z(e,t){if(p("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy();}}function $(e,t){for(var n=0,r=e.length;n=t.highWaterMark:t.length>0)||t.ended))return p("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?X(this):B(this),null;if(0===(e=W(e,t))&&t.ended)return 0===t.length&&X(this),null;var r,i=t.needReadable;return p("need readable",i),(0===t.length||t.length-e0?Q(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&X(this)),null!==r&&this.emit("data",r),r},C.prototype._read=function(e){x(this,new T("_read()"));},C.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e);}r.pipesCount+=1,p("pipe count=%d opts=%j",r.pipesCount,t);var i=(!t||!1!==t.end)&&e!==u.stdout&&e!==u.stderr?o:g;function a(t,i){p("onunpipe"),t===n&&i&&!1===i.hasUnpiped&&(i.hasUnpiped=!0,p("cleanup"),e.removeListener("close",c),e.removeListener("finish",b),e.removeListener("drain",s),e.removeListener("error",h),e.removeListener("unpipe",a),n.removeListener("end",o),n.removeListener("end",g),n.removeListener("data",d),l=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||s());}function o(){p("onend"),e.end();}r.endEmitted?u.nextTick(i):n.once("end",i),e.on("unpipe",a);var s=function(e){return function(){var t=e._readableState;p("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&f(e,"data")&&(t.flowing=!0,J(e));}}(n);e.on("drain",s);var l=!1;function d(t){p("ondata");var i=e.write(t);p("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==$(r.pipes,e))&&!l&&(p("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause());}function h(t){p("onerror",t),g(),e.removeListener("error",h),0===f(e,"error")&&x(e,t);}function c(){e.removeListener("finish",b),g();}function b(){p("onfinish"),e.removeListener("close",c),g();}function g(){p("unpipe"),n.unpipe(e);}return n.on("data",d),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n);}(e,"error",h),e.once("close",c),e.once("finish",b),e.emit("pipe",n),r.flowing||(p("pipe resume"),n.resume()),e},C.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,p("on readable",r.length,r.reading),r.length?B(this):r.reading||u.nextTick(K,this))),n},C.prototype.addListener=C.prototype.on,C.prototype.removeListener=function(e,t){var n=h.prototype.removeListener.call(this,e,t);return "readable"===e&&u.nextTick(H,this),n},C.prototype.removeAllListeners=function(e){var t=h.prototype.removeAllListeners.apply(this,arguments);return "readable"!==e&&void 0!==e||u.nextTick(H,this),t},C.prototype.resume=function(){var e=this._readableState;return e.flowing||(p("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,u.nextTick(z,e,t));}(this,e)),e.paused=!1,this},C.prototype.pause=function(){return p("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(p("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},C.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(p("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e);}t.push(null);})),e.on("data",(function(i){(p("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()));})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a-1))throw new M(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(P.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(P.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),P.prototype._write=function(e,t,n){n(new w("_write()"));},P.prototype._writev=null,P.prototype.end=function(e,t,n){var i=this._writableState;return "function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,t,n){t.ending=!0,q(e,t),n&&(t.finished?r.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1;}(this,i,n),this},Object.defineProperty(P.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(P.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e);}}),P.prototype.destroy=b.destroy,P.prototype._undestroy=b.undestroy,P.prototype._destroy=function(e,t){t(e);},z$9}var Z$3={},$$3=!1;function ee$1(){if($$3)return Z$3;$$3=!0;var e=T$9,t=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};Z$3=d;var n=K$8(),r=X$4();t$2$2(d,n);for(var a=t(r.prototype),s=0;s0?this.tail.next=t:this.head=t,this.tail=t,++this.length;}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length;}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0;}},{key:"join",value:function(e){if(0===this.length)return "";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return b$1$1.alloc(0);for(var t,n,r,i=b$1$1.allocUnsafe(e>>>0),a=this.head,o=0;a;)t=a.data,n=i,r=o,void b$1$1.prototype.copy.call(t,n,r),o+=a.data.length,a=a.next;return i}},{key:"consume",value:function(e,t){var n;return ei.length?i.length:e;if(a===i.length?r+=i:r+=i.slice(0,e),0==(e-=a)){a===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(a));break}++n;}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=b$1$1.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),0==(e-=a)){a===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(a));break}++r;}return this.length-=r,t}},{key:g$1$1,value:function(e,t){return p$1$1(this,function(e){for(var t=1;t0)if("string"==typeof t||o.objectMode||Object.getPrototypeOf(t)===c.prototype||(t=function(e){return c.from(e)}(t)),r)o.endEmitted?P(e,new x):W(e,o,t,!0);else if(o.ended)P(e,new O);else {if(o.destroyed)return !1;o.reading=!1,o.decoder&&!n?(t=o.decoder.write(t),o.objectMode||0!==t.length?W(e,o,t,!1):N(e,o)):W(e,o,t,!1);}else r||(o.reading=!1,N(e,o));return !o.ended&&(o.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function q(e){var t=e._readableState;p("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(p("emitReadable",t.flowing),t.emittedReadable=!0,u.nextTick(I,e));}function I(e){var t=e._readableState;p("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,J(e);}function N(e,t){t.readingMore||(t.readingMore=!0,u.nextTick(G,e,t));}function G(e,t){for(;!t.reading&&!t.ended&&(t.length0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume();}function K(e){p("readable nexttick read 0"),e.read(0);}function z(e,t){p("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),J(e),t.flowing&&!t.reading&&e.read(0);}function J(e){var t=e._readableState;for(p("flow",t.flowing);t.flowing&&null!==e.read(););}function Q(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n;}function X(e){var t=e._readableState;p("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,u.nextTick($,t,e));}function $(e,t){if(p("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy();}}function ee(e,t){for(var n=0,r=e.length;n=t.highWaterMark:t.length>0)||t.ended))return p("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?X(this):q(this),null;if(0===(e=B(e,t))&&t.ended)return 0===t.length&&X(this),null;var r,i=t.needReadable;return p("need readable",i),(0===t.length||t.length-e0?Q(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&X(this)),null!==r&&this.emit("data",r),r},C.prototype._read=function(e){P(this,new T("_read()"));},C.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e);}r.pipesCount+=1,p("pipe count=%d opts=%j",r.pipesCount,t);var i=(!t||!1!==t.end)&&e!==u.stdout&&e!==u.stderr?o:g;function a(t,i){p("onunpipe"),t===n&&i&&!1===i.hasUnpiped&&(i.hasUnpiped=!0,p("cleanup"),e.removeListener("close",c),e.removeListener("finish",b),e.removeListener("drain",s),e.removeListener("error",h),e.removeListener("unpipe",a),n.removeListener("end",o),n.removeListener("end",g),n.removeListener("data",d),l=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||s());}function o(){p("onend"),e.end();}r.endEmitted?u.nextTick(i):n.once("end",i),e.on("unpipe",a);var s=function(e){return function(){var t=e._readableState;p("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&f(e,"data")&&(t.flowing=!0,J(e));}}(n);e.on("drain",s);var l=!1;function d(t){p("ondata");var i=e.write(t);p("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==ee(r.pipes,e))&&!l&&(p("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause());}function h(t){p("onerror",t),g(),e.removeListener("error",h),0===f(e,"error")&&P(e,t);}function c(){e.removeListener("finish",b),g();}function b(){p("onfinish"),e.removeListener("close",c),g();}function g(){p("unpipe"),n.unpipe(e);}return n.on("data",d),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n);}(e,"error",h),e.once("close",c),e.once("finish",b),e.emit("pipe",n),r.flowing||(p("pipe resume"),n.resume()),e},C.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,p("on readable",r.length,r.reading),r.length?q(this):r.reading||u.nextTick(K,this))),n},C.prototype.addListener=C.prototype.on,C.prototype.removeListener=function(e,t){var n=h.prototype.removeListener.call(this,e,t);return "readable"===e&&u.nextTick(Y,this),n},C.prototype.removeAllListeners=function(e){var t=h.prototype.removeAllListeners.apply(this,arguments);return "readable"!==e&&void 0!==e||u.nextTick(Y,this),t},C.prototype.resume=function(){var e=this._readableState;return e.flowing||(p("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,u.nextTick(z,e,t));}(this,e)),e.paused=!1,this},C.prototype.pause=function(){return p("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(p("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},C.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(p("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e);}t.push(null);})),e.on("data",(function(i){(p("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()));})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a-1))throw new M(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(x.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(x.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),x.prototype._write=function(e,t,n){n(new w("_write()"));},x.prototype._writev=null,x.prototype.end=function(e,t,n){var i=this._writableState;return "function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,t,n){t.ending=!0,W(e,t),n&&(t.finished?r.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1;}(this,i,n),this},Object.defineProperty(x.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(x.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e);}}),x.prototype.destroy=b.destroy,x.prototype._undestroy=b.undestroy,x.prototype._destroy=function(e,t){t(e);},Y$1$1}var Q$1$1={},X$1$1=!1;function Z$1$1(){if(X$1$1)return Q$1$1;X$1$1=!0;var e=T$9,t=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};Q$1$1=d;var n=G$1$1(),r=J$1$1();t$2$2(d,n);for(var a=t(r.prototype),s=0;s0,(function(r){o||(o=r),r&&i.forEach(a$1$1),e||(i.forEach(a$1$1),f(o));}))}));return n.reduce(c$2$1)}; + +var l$r,d$n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;l$r=p$r;var f$u=y$o.EventEmitter;function p$r(){f$u.call(this||d$n);}t$2$2(p$r,f$u),p$r.Readable=t$2$1,p$r.Writable=t$4$1,p$r.Duplex=t$5$1,p$r.Transform=p$2$1,p$r.PassThrough=s$1$1,p$r.finished=n$1$1,p$r.pipeline=v$2$1,p$r.Stream=p$r,p$r.prototype.pipe=function(e,r){var t=this||d$n;function o(r){e.writable&&!1===e.write(r)&&t.pause&&t.pause();}function i(){t.readable&&t.resume&&t.resume();}t.on("data",o),e.on("drain",i),e._isStdio||r&&!1===r.end||(t.on("end",a),t.on("close",s));var n=!1;function a(){n||(n=!0,e.end());}function s(){n||(n=!0,"function"==typeof e.destroy&&e.destroy());}function m(e){if(l(),0===f$u.listenerCount(this||d$n,"error"))throw e}function l(){t.removeListener("data",o),e.removeListener("drain",i),t.removeListener("end",a),t.removeListener("close",s),t.removeListener("error",m),e.removeListener("error",m),t.removeListener("end",l),t.removeListener("close",l),e.removeListener("close",l);}return t.on("error",m),e.on("error",m),t.on("end",l),t.on("close",l),e.on("close",l),e.emit("pipe",t),e};var b$i=l$r;b$i.Readable;b$i.Writable;b$i.Duplex;b$i.Transform;b$i.PassThrough;b$i.finished;b$i.pipeline;b$i.Stream; + +var exports$1H = {}, + _dewExec$1G = false; + +var _global$o = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1G() { + if (_dewExec$1G) return exports$1H; + _dewExec$1G = true; + + var Buffer = dew$1T().Buffer; + + var Transform = b$i.Transform; + var StringDecoder = e$1$2.StringDecoder; + + var inherits = dew$f$2(); + + function CipherBase(hashMode) { + Transform.call(this || _global$o); + (this || _global$o).hashMode = typeof hashMode === "string"; + + if ((this || _global$o).hashMode) { + (this || _global$o)[hashMode] = (this || _global$o)._finalOrDigest; + } else { + (this || _global$o).final = (this || _global$o)._finalOrDigest; + } + + if ((this || _global$o)._final) { + (this || _global$o).__final = (this || _global$o)._final; + (this || _global$o)._final = null; + } + + (this || _global$o)._decoder = null; + (this || _global$o)._encoding = null; + } + + inherits(CipherBase, Transform); + + CipherBase.prototype.update = function (data, inputEnc, outputEnc) { + if (typeof data === "string") { + data = Buffer.from(data, inputEnc); + } + + var outData = this._update(data); + + if ((this || _global$o).hashMode) return this || _global$o; + + if (outputEnc) { + outData = this._toString(outData, outputEnc); + } + + return outData; + }; + + CipherBase.prototype.setAutoPadding = function () {}; + + CipherBase.prototype.getAuthTag = function () { + throw new Error("trying to get auth tag in unsupported state"); + }; + + CipherBase.prototype.setAuthTag = function () { + throw new Error("trying to set auth tag in unsupported state"); + }; + + CipherBase.prototype.setAAD = function () { + throw new Error("trying to set aad in unsupported state"); + }; + + CipherBase.prototype._transform = function (data, _, next) { + var err; + + try { + if ((this || _global$o).hashMode) { + this._update(data); + } else { + this.push(this._update(data)); + } + } catch (e) { + err = e; + } finally { + next(err); + } + }; + + CipherBase.prototype._flush = function (done) { + var err; + + try { + this.push(this.__final()); + } catch (e) { + err = e; + } + + done(err); + }; + + CipherBase.prototype._finalOrDigest = function (outputEnc) { + var outData = this.__final() || Buffer.alloc(0); + + if (outputEnc) { + outData = this._toString(outData, outputEnc, true); + } + + return outData; + }; + + CipherBase.prototype._toString = function (value, enc, fin) { + if (!(this || _global$o)._decoder) { + (this || _global$o)._decoder = new StringDecoder(enc); + (this || _global$o)._encoding = enc; + } + + if ((this || _global$o)._encoding !== enc) throw new Error("can't switch encodings"); + + var out = (this || _global$o)._decoder.write(value); + + if (fin) { + out += (this || _global$o)._decoder.end(); + } + + return out; + }; + + exports$1H = CipherBase; + return exports$1H; +} + +var exports$1G = {}, + _dewExec$1F = false; +function dew$1F() { + if (_dewExec$1F) return exports$1G; + _dewExec$1F = true; + + var inherits = dew$f$2(); + + var MD5 = dew$1Q(); + + var RIPEMD160 = dew$1P(); + + var sha = dew$1H(); + + var Base = dew$1G(); + + function Hash(hash) { + Base.call(this, "digest"); + this._hash = hash; + } + + inherits(Hash, Base); + + Hash.prototype._update = function (data) { + this._hash.update(data); + }; + + Hash.prototype._final = function () { + return this._hash.digest(); + }; + + exports$1G = function createHash(alg) { + alg = alg.toLowerCase(); + if (alg === "md5") return new MD5(); + if (alg === "rmd160" || alg === "ripemd160") return new RIPEMD160(); + return new Hash(sha(alg)); + }; + + return exports$1G; +} + +var exports$1F = {}, + _dewExec$1E = false; +function dew$1E() { + if (_dewExec$1E) return exports$1F; + _dewExec$1E = true; + + var inherits = dew$f$2(); + + var Buffer = dew$1T().Buffer; + + var Base = dew$1G(); + + var ZEROS = Buffer.alloc(128); + var blocksize = 64; + + function Hmac(alg, key) { + Base.call(this, "digest"); + + if (typeof key === "string") { + key = Buffer.from(key); + } + + this._alg = alg; + this._key = key; + + if (key.length > blocksize) { + key = alg(key); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + + var ipad = this._ipad = Buffer.allocUnsafe(blocksize); + var opad = this._opad = Buffer.allocUnsafe(blocksize); + + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + + this._hash = [ipad]; + } + + inherits(Hmac, Base); + + Hmac.prototype._update = function (data) { + this._hash.push(data); + }; + + Hmac.prototype._final = function () { + var h = this._alg(Buffer.concat(this._hash)); + + return this._alg(Buffer.concat([this._opad, h])); + }; + + exports$1F = Hmac; + return exports$1F; +} + +var exports$1E = {}, + _dewExec$1D = false; +function dew$1D() { + if (_dewExec$1D) return exports$1E; + _dewExec$1D = true; + + var MD5 = dew$1Q(); + + exports$1E = function (buffer) { + return new MD5().update(buffer).digest(); + }; + + return exports$1E; +} + +var exports$1D = {}, + _dewExec$1C = false; +function dew$1C() { + if (_dewExec$1C) return exports$1D; + _dewExec$1C = true; + + var inherits = dew$f$2(); + + var Legacy = dew$1E(); + + var Base = dew$1G(); + + var Buffer = dew$1T().Buffer; + + var md5 = dew$1D(); + + var RIPEMD160 = dew$1P(); + + var sha = dew$1H(); + + var ZEROS = Buffer.alloc(128); + + function Hmac(alg, key) { + Base.call(this, "digest"); + + if (typeof key === "string") { + key = Buffer.from(key); + } + + var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + this._alg = alg; + this._key = key; + + if (key.length > blocksize) { + var hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + key = hash.update(key).digest(); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + + var ipad = this._ipad = Buffer.allocUnsafe(blocksize); + var opad = this._opad = Buffer.allocUnsafe(blocksize); + + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + + this._hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + + this._hash.update(ipad); + } + + inherits(Hmac, Base); + + Hmac.prototype._update = function (data) { + this._hash.update(data); + }; + + Hmac.prototype._final = function () { + var h = this._hash.digest(); + + var hash = this._alg === "rmd160" ? new RIPEMD160() : sha(this._alg); + return hash.update(this._opad).update(h).digest(); + }; + + exports$1D = function createHmac(alg, key) { + alg = alg.toLowerCase(); + + if (alg === "rmd160" || alg === "ripemd160") { + return new Hmac("rmd160", key); + } + + if (alg === "md5") { + return new Legacy(md5, key); + } + + return new Hmac(alg, key); + }; + + return exports$1D; +} + +var _algorithms = { + "sha224WithRSAEncryption": { + "sign": "rsa", + "hash": "sha224", + "id": "302d300d06096086480165030402040500041c" + }, + "RSA-SHA224": { + "sign": "ecdsa/rsa", + "hash": "sha224", + "id": "302d300d06096086480165030402040500041c" + }, + "sha256WithRSAEncryption": { + "sign": "rsa", + "hash": "sha256", + "id": "3031300d060960864801650304020105000420" + }, + "RSA-SHA256": { + "sign": "ecdsa/rsa", + "hash": "sha256", + "id": "3031300d060960864801650304020105000420" + }, + "sha384WithRSAEncryption": { + "sign": "rsa", + "hash": "sha384", + "id": "3041300d060960864801650304020205000430" + }, + "RSA-SHA384": { + "sign": "ecdsa/rsa", + "hash": "sha384", + "id": "3041300d060960864801650304020205000430" + }, + "sha512WithRSAEncryption": { + "sign": "rsa", + "hash": "sha512", + "id": "3051300d060960864801650304020305000440" + }, + "RSA-SHA512": { + "sign": "ecdsa/rsa", + "hash": "sha512", + "id": "3051300d060960864801650304020305000440" + }, + "RSA-SHA1": { + "sign": "rsa", + "hash": "sha1", + "id": "3021300906052b0e03021a05000414" + }, + "ecdsa-with-SHA1": { + "sign": "ecdsa", + "hash": "sha1", + "id": "" + }, + "sha256": { + "sign": "ecdsa", + "hash": "sha256", + "id": "" + }, + "sha224": { + "sign": "ecdsa", + "hash": "sha224", + "id": "" + }, + "sha384": { + "sign": "ecdsa", + "hash": "sha384", + "id": "" + }, + "sha512": { + "sign": "ecdsa", + "hash": "sha512", + "id": "" + }, + "DSA-SHA": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA-SHA1": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA": { + "sign": "dsa", + "hash": "sha1", + "id": "" + }, + "DSA-WITH-SHA224": { + "sign": "dsa", + "hash": "sha224", + "id": "" + }, + "DSA-SHA224": { + "sign": "dsa", + "hash": "sha224", + "id": "" + }, + "DSA-WITH-SHA256": { + "sign": "dsa", + "hash": "sha256", + "id": "" + }, + "DSA-SHA256": { + "sign": "dsa", + "hash": "sha256", + "id": "" + }, + "DSA-WITH-SHA384": { + "sign": "dsa", + "hash": "sha384", + "id": "" + }, + "DSA-SHA384": { + "sign": "dsa", + "hash": "sha384", + "id": "" + }, + "DSA-WITH-SHA512": { + "sign": "dsa", + "hash": "sha512", + "id": "" + }, + "DSA-SHA512": { + "sign": "dsa", + "hash": "sha512", + "id": "" + }, + "DSA-RIPEMD160": { + "sign": "dsa", + "hash": "rmd160", + "id": "" + }, + "ripemd160WithRSA": { + "sign": "rsa", + "hash": "rmd160", + "id": "3021300906052b2403020105000414" + }, + "RSA-RIPEMD160": { + "sign": "rsa", + "hash": "rmd160", + "id": "3021300906052b2403020105000414" + }, + "md5WithRSAEncryption": { + "sign": "rsa", + "hash": "md5", + "id": "3020300c06082a864886f70d020505000410" + }, + "RSA-MD5": { + "sign": "rsa", + "hash": "md5", + "id": "3020300c06082a864886f70d020505000410" + } +}; + +var exports$1C = {}, + _dewExec$1B = false; +function dew$1B() { + if (_dewExec$1B) return exports$1C; + _dewExec$1B = true; + exports$1C = _algorithms; + return exports$1C; +} + +var exports$1B = {}, + _dewExec$1A = false; +function dew$1A() { + if (_dewExec$1A) return exports$1B; + _dewExec$1A = true; + var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs + + exports$1B = function (iterations, keylen) { + if (typeof iterations !== "number") { + throw new TypeError("Iterations not a number"); + } + + if (iterations < 0) { + throw new TypeError("Bad iterations"); + } + + if (typeof keylen !== "number") { + throw new TypeError("Key length not a number"); + } + + if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { + /* eslint no-self-compare: 0 */ + throw new TypeError("Bad key length"); + } + }; + + return exports$1B; +} + +var exports$1A = {}, + _dewExec$1z = false; + +var _global$n = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1z() { + if (_dewExec$1z) return exports$1A; + _dewExec$1z = true; + var process = T$9; + var defaultEncoding; + /* istanbul ignore next */ + + if (_global$n.process && _global$n.process.browser) { + defaultEncoding = "utf-8"; + } else if (_global$n.process && _global$n.process.version) { + var pVersionMajor = parseInt(process.version.split(".")[0].slice(1), 10); + defaultEncoding = pVersionMajor >= 6 ? "utf-8" : "binary"; + } else { + defaultEncoding = "utf-8"; + } + + exports$1A = defaultEncoding; + return exports$1A; +} + +var exports$1z = {}, + _dewExec$1y = false; +function dew$1y() { + if (_dewExec$1y) return exports$1z; + _dewExec$1y = true; + + var Buffer = dew$1T().Buffer; + + exports$1z = function (thing, encoding, name) { + if (Buffer.isBuffer(thing)) { + return thing; + } else if (typeof thing === "string") { + return Buffer.from(thing, encoding); + } else if (ArrayBuffer.isView(thing)) { + return Buffer.from(thing.buffer); + } else { + throw new TypeError(name + " must be a string, a Buffer, a typed array or a DataView"); + } + }; + + return exports$1z; +} + +var exports$1y = {}, + _dewExec$1x = false; + +var _global$m = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1x() { + if (_dewExec$1x) return exports$1y; + _dewExec$1x = true; + + var md5 = dew$1D(); + + var RIPEMD160 = dew$1P(); + + var sha = dew$1H(); + + var Buffer = dew$1T().Buffer; + + var checkParameters = dew$1A(); + + var defaultEncoding = dew$1z(); + + var toBuffer = dew$1y(); + + var ZEROS = Buffer.alloc(128); + var sizes = { + md5: 16, + sha1: 20, + sha224: 28, + sha256: 32, + sha384: 48, + sha512: 64, + rmd160: 20, + ripemd160: 20 + }; + + function Hmac(alg, key, saltLen) { + var hash = getDigest(alg); + var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + + if (key.length > blocksize) { + key = hash(key); + } else if (key.length < blocksize) { + key = Buffer.concat([key, ZEROS], blocksize); + } + + var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]); + var opad = Buffer.allocUnsafe(blocksize + sizes[alg]); + + for (var i = 0; i < blocksize; i++) { + ipad[i] = key[i] ^ 54; + opad[i] = key[i] ^ 92; + } + + var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4); + ipad.copy(ipad1, 0, 0, blocksize); + (this || _global$m).ipad1 = ipad1; + (this || _global$m).ipad2 = ipad; + (this || _global$m).opad = opad; + (this || _global$m).alg = alg; + (this || _global$m).blocksize = blocksize; + (this || _global$m).hash = hash; + (this || _global$m).size = sizes[alg]; + } + + Hmac.prototype.run = function (data, ipad) { + data.copy(ipad, (this || _global$m).blocksize); + var h = this.hash(ipad); + h.copy((this || _global$m).opad, (this || _global$m).blocksize); + return this.hash((this || _global$m).opad); + }; + + function getDigest(alg) { + function shaFunc(data) { + return sha(alg).update(data).digest(); + } + + function rmd160Func(data) { + return new RIPEMD160().update(data).digest(); + } + + if (alg === "rmd160" || alg === "ripemd160") return rmd160Func; + if (alg === "md5") return md5; + return shaFunc; + } + + function pbkdf2(password, salt, iterations, keylen, digest) { + checkParameters(iterations, keylen); + password = toBuffer(password, defaultEncoding, "Password"); + salt = toBuffer(salt, defaultEncoding, "Salt"); + digest = digest || "sha1"; + var hmac = new Hmac(digest, password, salt.length); + var DK = Buffer.allocUnsafe(keylen); + var block1 = Buffer.allocUnsafe(salt.length + 4); + salt.copy(block1, 0, 0, salt.length); + var destPos = 0; + var hLen = sizes[digest]; + var l = Math.ceil(keylen / hLen); + + for (var i = 1; i <= l; i++) { + block1.writeUInt32BE(i, salt.length); + var T = hmac.run(block1, hmac.ipad1); + var U = T; + + for (var j = 1; j < iterations; j++) { + U = hmac.run(U, hmac.ipad2); + + for (var k = 0; k < hLen; k++) T[k] ^= U[k]; + } + + T.copy(DK, destPos); + destPos += hLen; + } + + return DK; + } + + exports$1y = pbkdf2; + return exports$1y; +} + +var exports$1x = {}, + _dewExec$1w = false; + +var _global$l = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1w() { + if (_dewExec$1w) return exports$1x; + _dewExec$1w = true; + + var Buffer = dew$1T().Buffer; + + var checkParameters = dew$1A(); + + var defaultEncoding = dew$1z(); + + var sync = dew$1x(); + + var toBuffer = dew$1y(); + + var ZERO_BUF; + var subtle = _global$l.crypto && _global$l.crypto.subtle; + var toBrowser = { + sha: "SHA-1", + "sha-1": "SHA-1", + sha1: "SHA-1", + sha256: "SHA-256", + "sha-256": "SHA-256", + sha384: "SHA-384", + "sha-384": "SHA-384", + "sha-512": "SHA-512", + sha512: "SHA-512" + }; + var checks = []; + + function checkNative(algo) { + if (_global$l.process && !_global$l.process.browser) { + return Promise.resolve(false); + } + + if (!subtle || !subtle.importKey || !subtle.deriveBits) { + return Promise.resolve(false); + } + + if (checks[algo] !== undefined) { + return checks[algo]; + } + + ZERO_BUF = ZERO_BUF || Buffer.alloc(8); + var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () { + return true; + }).catch(function () { + return false; + }); + checks[algo] = prom; + return prom; + } + + var nextTick; + + function getNextTick() { + if (nextTick) { + return nextTick; + } + + if (_global$l.process && _global$l.process.nextTick) { + nextTick = _global$l.process.nextTick; + } else if (_global$l.queueMicrotask) { + nextTick = _global$l.queueMicrotask; + } else if (_global$l.setImmediate) { + nextTick = _global$l.setImmediate; + } else { + nextTick = _global$l.setTimeout; + } + + return nextTick; + } + + function browserPbkdf2(password, salt, iterations, length, algo) { + return subtle.importKey("raw", password, { + name: "PBKDF2" + }, false, ["deriveBits"]).then(function (key) { + return subtle.deriveBits({ + name: "PBKDF2", + salt: salt, + iterations: iterations, + hash: { + name: algo + } + }, key, length << 3); + }).then(function (res) { + return Buffer.from(res); + }); + } + + function resolvePromise(promise, callback) { + promise.then(function (out) { + getNextTick()(function () { + callback(null, out); + }); + }, function (e) { + getNextTick()(function () { + callback(e); + }); + }); + } + + exports$1x = function (password, salt, iterations, keylen, digest, callback) { + if (typeof digest === "function") { + callback = digest; + digest = undefined; + } + + digest = digest || "sha1"; + var algo = toBrowser[digest.toLowerCase()]; + + if (!algo || typeof _global$l.Promise !== "function") { + getNextTick()(function () { + var out; + + try { + out = sync(password, salt, iterations, keylen, digest); + } catch (e) { + return callback(e); + } + + callback(null, out); + }); + return; + } + + checkParameters(iterations, keylen); + password = toBuffer(password, defaultEncoding, "Password"); + salt = toBuffer(salt, defaultEncoding, "Salt"); + if (typeof callback !== "function") throw new Error("No callback provided to pbkdf2"); + resolvePromise(checkNative(algo).then(function (resp) { + if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo); + return sync(password, salt, iterations, keylen, digest); + }), callback); + }; + + return exports$1x; +} + +var exports$1w = {}, + _dewExec$1v = false; +function dew$1v() { + if (_dewExec$1v) return exports$1w; + _dewExec$1v = true; + exports$1w.pbkdf2 = dew$1w(); + exports$1w.pbkdf2Sync = dew$1x(); + return exports$1w; +} + +var exports$1v = {}, + _dewExec$1u = false; +function dew$1u() { + if (_dewExec$1u) return exports$1v; + _dewExec$1u = true; + + exports$1v.readUInt32BE = function readUInt32BE(bytes, off) { + var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off]; + return res >>> 0; + }; + + exports$1v.writeUInt32BE = function writeUInt32BE(bytes, value, off) { + bytes[0 + off] = value >>> 24; + bytes[1 + off] = value >>> 16 & 255; + bytes[2 + off] = value >>> 8 & 255; + bytes[3 + off] = value & 255; + }; + + exports$1v.ip = function ip(inL, inR, out, off) { + var outL = 0; + var outR = 0; + + for (var i = 6; i >= 0; i -= 2) { + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >>> j + i & 1; + } + + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inL >>> j + i & 1; + } + } + + for (var i = 6; i >= 0; i -= 2) { + for (var j = 1; j <= 25; j += 8) { + outR <<= 1; + outR |= inR >>> j + i & 1; + } + + for (var j = 1; j <= 25; j += 8) { + outR <<= 1; + outR |= inL >>> j + i & 1; + } + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$1v.rip = function rip(inL, inR, out, off) { + var outL = 0; + var outR = 0; + + for (var i = 0; i < 4; i++) { + for (var j = 24; j >= 0; j -= 8) { + outL <<= 1; + outL |= inR >>> j + i & 1; + outL <<= 1; + outL |= inL >>> j + i & 1; + } + } + + for (var i = 4; i < 8; i++) { + for (var j = 24; j >= 0; j -= 8) { + outR <<= 1; + outR |= inR >>> j + i & 1; + outR <<= 1; + outR |= inL >>> j + i & 1; + } + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$1v.pc1 = function pc1(inL, inR, out, off) { + var outL = 0; + var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63 + // 6, 14, 22, 30, 39, 47, 55, 63 + // 5, 13, 21, 29, 39, 47, 55, 63 + // 4, 12, 20, 28 + + for (var i = 7; i >= 5; i--) { + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >> j + i & 1; + } + + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inL >> j + i & 1; + } + } + + for (var j = 0; j <= 24; j += 8) { + outL <<= 1; + outL |= inR >> j + i & 1; + } // 1, 9, 17, 25, 33, 41, 49, 57 + // 2, 10, 18, 26, 34, 42, 50, 58 + // 3, 11, 19, 27, 35, 43, 51, 59 + // 36, 44, 52, 60 + + + for (var i = 1; i <= 3; i++) { + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inR >> j + i & 1; + } + + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inL >> j + i & 1; + } + } + + for (var j = 0; j <= 24; j += 8) { + outR <<= 1; + outR |= inL >> j + i & 1; + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$1v.r28shl = function r28shl(num, shift) { + return num << shift & 268435455 | num >>> 28 - shift; + }; + + var pc2table = [// inL => outL + 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, // inR => outR + 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24]; + + exports$1v.pc2 = function pc2(inL, inR, out, off) { + var outL = 0; + var outR = 0; + var len = pc2table.length >>> 1; + + for (var i = 0; i < len; i++) { + outL <<= 1; + outL |= inL >>> pc2table[i] & 1; + } + + for (var i = len; i < pc2table.length; i++) { + outR <<= 1; + outR |= inR >>> pc2table[i] & 1; + } + + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + exports$1v.expand = function expand(r, out, off) { + var outL = 0; + var outR = 0; + outL = (r & 1) << 5 | r >>> 27; + + for (var i = 23; i >= 15; i -= 4) { + outL <<= 6; + outL |= r >>> i & 63; + } + + for (var i = 11; i >= 3; i -= 4) { + outR |= r >>> i & 63; + outR <<= 6; + } + + outR |= (r & 31) << 1 | r >>> 31; + out[off + 0] = outL >>> 0; + out[off + 1] = outR >>> 0; + }; + + var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11]; + + exports$1v.substitute = function substitute(inL, inR) { + var out = 0; + + for (var i = 0; i < 4; i++) { + var b = inL >>> 18 - i * 6 & 63; + var sb = sTable[i * 64 + b]; + out <<= 4; + out |= sb; + } + + for (var i = 0; i < 4; i++) { + var b = inR >>> 18 - i * 6 & 63; + var sb = sTable[4 * 64 + i * 64 + b]; + out <<= 4; + out |= sb; + } + + return out >>> 0; + }; + + var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7]; + + exports$1v.permute = function permute(num) { + var out = 0; + + for (var i = 0; i < permuteTable.length; i++) { + out <<= 1; + out |= num >>> permuteTable[i] & 1; + } + + return out >>> 0; + }; + + exports$1v.padSplit = function padSplit(num, size, group) { + var str = num.toString(2); + + while (str.length < size) str = "0" + str; + + var out = []; + + for (var i = 0; i < size; i += group) out.push(str.slice(i, i + group)); + + return out.join(" "); + }; + + return exports$1v; +} + +var exports$1u = {}, + _dewExec$1t = false; +function dew$1t() { + if (_dewExec$1t) return exports$1u; + _dewExec$1t = true; + exports$1u = assert; + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } + + assert.equal = function assertEqual(l, r, msg) { + if (l != r) throw new Error(msg || "Assertion failed: " + l + " != " + r); + }; + + return exports$1u; +} + +var exports$1t = {}, + _dewExec$1s = false; +function dew$1s() { + if (_dewExec$1s) return exports$1t; + _dewExec$1s = true; + + var assert = dew$1t(); + + function Cipher(options) { + this.options = options; + this.type = this.options.type; + this.blockSize = 8; + + this._init(); + + this.buffer = new Array(this.blockSize); + this.bufferOff = 0; + } + + exports$1t = Cipher; + + Cipher.prototype._init = function _init() {// Might be overrided + }; + + Cipher.prototype.update = function update(data) { + if (data.length === 0) return []; + if (this.type === "decrypt") return this._updateDecrypt(data);else return this._updateEncrypt(data); + }; + + Cipher.prototype._buffer = function _buffer(data, off) { + // Append data to buffer + var min = Math.min(this.buffer.length - this.bufferOff, data.length - off); + + for (var i = 0; i < min; i++) this.buffer[this.bufferOff + i] = data[off + i]; + + this.bufferOff += min; // Shift next + + return min; + }; + + Cipher.prototype._flushBuffer = function _flushBuffer(out, off) { + this._update(this.buffer, 0, out, off); + + this.bufferOff = 0; + return this.blockSize; + }; + + Cipher.prototype._updateEncrypt = function _updateEncrypt(data) { + var inputOff = 0; + var outputOff = 0; + var count = (this.bufferOff + data.length) / this.blockSize | 0; + var out = new Array(count * this.blockSize); + + if (this.bufferOff !== 0) { + inputOff += this._buffer(data, inputOff); + if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff); + } // Write blocks + + + var max = data.length - (data.length - inputOff) % this.blockSize; + + for (; inputOff < max; inputOff += this.blockSize) { + this._update(data, inputOff, out, outputOff); + + outputOff += this.blockSize; + } // Queue rest + + + for (; inputOff < data.length; inputOff++, this.bufferOff++) this.buffer[this.bufferOff] = data[inputOff]; + + return out; + }; + + Cipher.prototype._updateDecrypt = function _updateDecrypt(data) { + var inputOff = 0; + var outputOff = 0; + var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1; + var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal + + for (; count > 0; count--) { + inputOff += this._buffer(data, inputOff); + outputOff += this._flushBuffer(out, outputOff); + } // Buffer rest of the input + + + inputOff += this._buffer(data, inputOff); + return out; + }; + + Cipher.prototype.final = function final(buffer) { + var first; + if (buffer) first = this.update(buffer); + var last; + if (this.type === "encrypt") last = this._finalEncrypt();else last = this._finalDecrypt(); + if (first) return first.concat(last);else return last; + }; + + Cipher.prototype._pad = function _pad(buffer, off) { + if (off === 0) return false; + + while (off < buffer.length) buffer[off++] = 0; + + return true; + }; + + Cipher.prototype._finalEncrypt = function _finalEncrypt() { + if (!this._pad(this.buffer, this.bufferOff)) return []; + var out = new Array(this.blockSize); + + this._update(this.buffer, 0, out, 0); + + return out; + }; + + Cipher.prototype._unpad = function _unpad(buffer) { + return buffer; + }; + + Cipher.prototype._finalDecrypt = function _finalDecrypt() { + assert.equal(this.bufferOff, this.blockSize, "Not enough data to decrypt"); + var out = new Array(this.blockSize); + + this._flushBuffer(out, 0); + + return this._unpad(out); + }; + + return exports$1t; +} + +var exports$1s = {}, + _dewExec$1r = false; +function dew$1r() { + if (_dewExec$1r) return exports$1s; + _dewExec$1r = true; + + var assert = dew$1t(); + + var inherits = dew$f$2(); + + var utils = dew$1u(); + + var Cipher = dew$1s(); + + function DESState() { + this.tmp = new Array(2); + this.keys = null; + } + + function DES(options) { + Cipher.call(this, options); + var state = new DESState(); + this._desState = state; + this.deriveKeys(state, options.key); + } + + inherits(DES, Cipher); + exports$1s = DES; + + DES.create = function create(options) { + return new DES(options); + }; + + var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]; + + DES.prototype.deriveKeys = function deriveKeys(state, key) { + state.keys = new Array(16 * 2); + assert.equal(key.length, this.blockSize, "Invalid key length"); + var kL = utils.readUInt32BE(key, 0); + var kR = utils.readUInt32BE(key, 4); + utils.pc1(kL, kR, state.tmp, 0); + kL = state.tmp[0]; + kR = state.tmp[1]; + + for (var i = 0; i < state.keys.length; i += 2) { + var shift = shiftTable[i >>> 1]; + kL = utils.r28shl(kL, shift); + kR = utils.r28shl(kR, shift); + utils.pc2(kL, kR, state.keys, i); + } + }; + + DES.prototype._update = function _update(inp, inOff, out, outOff) { + var state = this._desState; + var l = utils.readUInt32BE(inp, inOff); + var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation + + utils.ip(l, r, state.tmp, 0); + l = state.tmp[0]; + r = state.tmp[1]; + if (this.type === "encrypt") this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0); + l = state.tmp[0]; + r = state.tmp[1]; + utils.writeUInt32BE(out, l, outOff); + utils.writeUInt32BE(out, r, outOff + 4); + }; + + DES.prototype._pad = function _pad(buffer, off) { + var value = buffer.length - off; + + for (var i = off; i < buffer.length; i++) buffer[i] = value; + + return true; + }; + + DES.prototype._unpad = function _unpad(buffer) { + var pad = buffer[buffer.length - 1]; + + for (var i = buffer.length - pad; i < buffer.length; i++) assert.equal(buffer[i], pad); + + return buffer.slice(0, buffer.length - pad); + }; + + DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) { + var l = lStart; + var r = rStart; // Apply f() x16 times + + for (var i = 0; i < state.keys.length; i += 2) { + var keyL = state.keys[i]; + var keyR = state.keys[i + 1]; // f(r, k) + + utils.expand(r, state.tmp, 0); + keyL ^= state.tmp[0]; + keyR ^= state.tmp[1]; + var s = utils.substitute(keyL, keyR); + var f = utils.permute(s); + var t = r; + r = (l ^ f) >>> 0; + l = t; + } // Reverse Initial Permutation + + + utils.rip(r, l, out, off); + }; + + DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) { + var l = rStart; + var r = lStart; // Apply f() x16 times + + for (var i = state.keys.length - 2; i >= 0; i -= 2) { + var keyL = state.keys[i]; + var keyR = state.keys[i + 1]; // f(r, k) + + utils.expand(l, state.tmp, 0); + keyL ^= state.tmp[0]; + keyR ^= state.tmp[1]; + var s = utils.substitute(keyL, keyR); + var f = utils.permute(s); + var t = l; + l = (r ^ f) >>> 0; + r = t; + } // Reverse Initial Permutation + + + utils.rip(l, r, out, off); + }; + + return exports$1s; +} + +var exports$1r = {}, + _dewExec$1q = false; +function dew$1q() { + if (_dewExec$1q) return exports$1r; + _dewExec$1q = true; + + var assert = dew$1t(); + + var inherits = dew$f$2(); + + var proto = {}; + + function CBCState(iv) { + assert.equal(iv.length, 8, "Invalid IV length"); + this.iv = new Array(8); + + for (var i = 0; i < this.iv.length; i++) this.iv[i] = iv[i]; + } + + function instantiate(Base) { + function CBC(options) { + Base.call(this, options); + + this._cbcInit(); + } + + inherits(CBC, Base); + var keys = Object.keys(proto); + + for (var i = 0; i < keys.length; i++) { + var key = keys[i]; + CBC.prototype[key] = proto[key]; + } + + CBC.create = function create(options) { + return new CBC(options); + }; + + return CBC; + } + + exports$1r.instantiate = instantiate; + + proto._cbcInit = function _cbcInit() { + var state = new CBCState(this.options.iv); + this._cbcState = state; + }; + + proto._update = function _update(inp, inOff, out, outOff) { + var state = this._cbcState; + var superProto = this.constructor.super_.prototype; + var iv = state.iv; + + if (this.type === "encrypt") { + for (var i = 0; i < this.blockSize; i++) iv[i] ^= inp[inOff + i]; + + superProto._update.call(this, iv, 0, out, outOff); + + for (var i = 0; i < this.blockSize; i++) iv[i] = out[outOff + i]; + } else { + superProto._update.call(this, inp, inOff, out, outOff); + + for (var i = 0; i < this.blockSize; i++) out[outOff + i] ^= iv[i]; + + for (var i = 0; i < this.blockSize; i++) iv[i] = inp[inOff + i]; + } + }; + + return exports$1r; +} + +var exports$1q = {}, + _dewExec$1p = false; +function dew$1p() { + if (_dewExec$1p) return exports$1q; + _dewExec$1p = true; + + var assert = dew$1t(); + + var inherits = dew$f$2(); + + var Cipher = dew$1s(); + + var DES = dew$1r(); + + function EDEState(type, key) { + assert.equal(key.length, 24, "Invalid key length"); + var k1 = key.slice(0, 8); + var k2 = key.slice(8, 16); + var k3 = key.slice(16, 24); + + if (type === "encrypt") { + this.ciphers = [DES.create({ + type: "encrypt", + key: k1 + }), DES.create({ + type: "decrypt", + key: k2 + }), DES.create({ + type: "encrypt", + key: k3 + })]; + } else { + this.ciphers = [DES.create({ + type: "decrypt", + key: k3 + }), DES.create({ + type: "encrypt", + key: k2 + }), DES.create({ + type: "decrypt", + key: k1 + })]; + } + } + + function EDE(options) { + Cipher.call(this, options); + var state = new EDEState(this.type, this.options.key); + this._edeState = state; + } + + inherits(EDE, Cipher); + exports$1q = EDE; + + EDE.create = function create(options) { + return new EDE(options); + }; + + EDE.prototype._update = function _update(inp, inOff, out, outOff) { + var state = this._edeState; + + state.ciphers[0]._update(inp, inOff, out, outOff); + + state.ciphers[1]._update(out, outOff, out, outOff); + + state.ciphers[2]._update(out, outOff, out, outOff); + }; + + EDE.prototype._pad = DES.prototype._pad; + EDE.prototype._unpad = DES.prototype._unpad; + return exports$1q; +} + +var exports$1p = {}, + _dewExec$1o = false; +function dew$1o() { + if (_dewExec$1o) return exports$1p; + _dewExec$1o = true; + exports$1p.utils = dew$1u(); + exports$1p.Cipher = dew$1s(); + exports$1p.DES = dew$1r(); + exports$1p.CBC = dew$1q(); + exports$1p.EDE = dew$1p(); + return exports$1p; +} + +var exports$1o = {}, + _dewExec$1n = false; + +var _global$k = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1n() { + if (_dewExec$1n) return exports$1o; + _dewExec$1n = true; + + var CipherBase = dew$1G(); + + var des = dew$1o(); + + var inherits = dew$f$2(); + + var Buffer = dew$1T().Buffer; + + var modes = { + "des-ede3-cbc": des.CBC.instantiate(des.EDE), + "des-ede3": des.EDE, + "des-ede-cbc": des.CBC.instantiate(des.EDE), + "des-ede": des.EDE, + "des-cbc": des.CBC.instantiate(des.DES), + "des-ecb": des.DES + }; + modes.des = modes["des-cbc"]; + modes.des3 = modes["des-ede3-cbc"]; + exports$1o = DES; + inherits(DES, CipherBase); + + function DES(opts) { + CipherBase.call(this || _global$k); + var modeName = opts.mode.toLowerCase(); + var mode = modes[modeName]; + var type; + + if (opts.decrypt) { + type = "decrypt"; + } else { + type = "encrypt"; + } + + var key = opts.key; + + if (!Buffer.isBuffer(key)) { + key = Buffer.from(key); + } + + if (modeName === "des-ede" || modeName === "des-ede-cbc") { + key = Buffer.concat([key, key.slice(0, 8)]); + } + + var iv = opts.iv; + + if (!Buffer.isBuffer(iv)) { + iv = Buffer.from(iv); + } + + (this || _global$k)._des = mode.create({ + key: key, + iv: iv, + type: type + }); + } + + DES.prototype._update = function (data) { + return Buffer.from((this || _global$k)._des.update(data)); + }; + + DES.prototype._final = function () { + return Buffer.from((this || _global$k)._des.final()); + }; + + return exports$1o; +} + +var exports$1n = {}, + _dewExec$1m = false; +function dew$1m() { + if (_dewExec$1m) return exports$1n; + _dewExec$1m = true; + + exports$1n.encrypt = function (self, block) { + return self._cipher.encryptBlock(block); + }; + + exports$1n.decrypt = function (self, block) { + return self._cipher.decryptBlock(block); + }; + + return exports$1n; +} + +var exports$1m = {}, + _dewExec$1l = false; +function dew$1l() { + if (_dewExec$1l) return exports$1m; + _dewExec$1l = true; + var Buffer = e$1$1$1.Buffer; + + exports$1m = function xor(a, b) { + var length = Math.min(a.length, b.length); + var buffer = new Buffer(length); + + for (var i = 0; i < length; ++i) { + buffer[i] = a[i] ^ b[i]; + } + + return buffer; + }; + + return exports$1m; +} + +var exports$1l = {}, + _dewExec$1k = false; +function dew$1k() { + if (_dewExec$1k) return exports$1l; + _dewExec$1k = true; + + var xor = dew$1l(); + + exports$1l.encrypt = function (self, block) { + var data = xor(block, self._prev); + self._prev = self._cipher.encryptBlock(data); + return self._prev; + }; + + exports$1l.decrypt = function (self, block) { + var pad = self._prev; + self._prev = block; + + var out = self._cipher.decryptBlock(block); + + return xor(out, pad); + }; + + return exports$1l; +} + +var exports$1k = {}, + _dewExec$1j = false; +function dew$1j() { + if (_dewExec$1j) return exports$1k; + _dewExec$1j = true; + + var Buffer = dew$1T().Buffer; + + var xor = dew$1l(); + + function encryptStart(self, data, decrypt) { + var len = data.length; + var out = xor(data, self._cache); + self._cache = self._cache.slice(len); + self._prev = Buffer.concat([self._prev, decrypt ? data : out]); + return out; + } + + exports$1k.encrypt = function (self, data, decrypt) { + var out = Buffer.allocUnsafe(0); + var len; + + while (data.length) { + if (self._cache.length === 0) { + self._cache = self._cipher.encryptBlock(self._prev); + self._prev = Buffer.allocUnsafe(0); + } + + if (self._cache.length <= data.length) { + len = self._cache.length; + out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]); + data = data.slice(len); + } else { + out = Buffer.concat([out, encryptStart(self, data, decrypt)]); + break; + } + } + + return out; + }; + + return exports$1k; +} + +var exports$1j$1 = {}, + _dewExec$1i$1 = false; +function dew$1i$1() { + if (_dewExec$1i$1) return exports$1j$1; + _dewExec$1i$1 = true; + + var Buffer = dew$1T().Buffer; + + function encryptByte(self, byteParam, decrypt) { + var pad = self._cipher.encryptBlock(self._prev); + + var out = pad[0] ^ byteParam; + self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]); + return out; + } + + exports$1j$1.encrypt = function (self, chunk, decrypt) { + var len = chunk.length; + var out = Buffer.allocUnsafe(len); + var i = -1; + + while (++i < len) { + out[i] = encryptByte(self, chunk[i], decrypt); + } + + return out; + }; + + return exports$1j$1; +} + +var exports$1i$1 = {}, + _dewExec$1h$1 = false; +function dew$1h$1() { + if (_dewExec$1h$1) return exports$1i$1; + _dewExec$1h$1 = true; + + var Buffer = dew$1T().Buffer; + + function encryptByte(self, byteParam, decrypt) { + var pad; + var i = -1; + var len = 8; + var out = 0; + var bit, value; + + while (++i < len) { + pad = self._cipher.encryptBlock(self._prev); + bit = byteParam & 1 << 7 - i ? 128 : 0; + value = pad[0] ^ bit; + out += (value & 128) >> i % 8; + self._prev = shiftIn(self._prev, decrypt ? bit : value); + } + + return out; + } + + function shiftIn(buffer, value) { + var len = buffer.length; + var i = -1; + var out = Buffer.allocUnsafe(buffer.length); + buffer = Buffer.concat([buffer, Buffer.from([value])]); + + while (++i < len) { + out[i] = buffer[i] << 1 | buffer[i + 1] >> 7; + } + + return out; + } + + exports$1i$1.encrypt = function (self, chunk, decrypt) { + var len = chunk.length; + var out = Buffer.allocUnsafe(len); + var i = -1; + + while (++i < len) { + out[i] = encryptByte(self, chunk[i], decrypt); + } + + return out; + }; + + return exports$1i$1; +} + +var exports$1h$1 = {}, + _dewExec$1g$1 = false; +function dew$1g$1() { + if (_dewExec$1g$1) return exports$1h$1; + _dewExec$1g$1 = true; + var Buffer = e$1$1$1.Buffer; + + var xor = dew$1l(); + + function getBlock(self) { + self._prev = self._cipher.encryptBlock(self._prev); + return self._prev; + } + + exports$1h$1.encrypt = function (self, chunk) { + while (self._cache.length < chunk.length) { + self._cache = Buffer.concat([self._cache, getBlock(self)]); + } + + var pad = self._cache.slice(0, chunk.length); + + self._cache = self._cache.slice(chunk.length); + return xor(chunk, pad); + }; + + return exports$1h$1; +} + +var exports$1g$1 = {}, + _dewExec$1f$1 = false; +function dew$1f$1() { + if (_dewExec$1f$1) return exports$1g$1; + _dewExec$1f$1 = true; + + function incr32(iv) { + var len = iv.length; + var item; + + while (len--) { + item = iv.readUInt8(len); + + if (item === 255) { + iv.writeUInt8(0, len); + } else { + item++; + iv.writeUInt8(item, len); + break; + } + } + } + + exports$1g$1 = incr32; + return exports$1g$1; +} + +var exports$1f$1 = {}, + _dewExec$1e$1 = false; +function dew$1e$1() { + if (_dewExec$1e$1) return exports$1f$1; + _dewExec$1e$1 = true; + + var xor = dew$1l(); + + var Buffer = dew$1T().Buffer; + + var incr32 = dew$1f$1(); + + function getBlock(self) { + var out = self._cipher.encryptBlockRaw(self._prev); + + incr32(self._prev); + return out; + } + + var blockSize = 16; + + exports$1f$1.encrypt = function (self, chunk) { + var chunkNum = Math.ceil(chunk.length / blockSize); + var start = self._cache.length; + self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]); + + for (var i = 0; i < chunkNum; i++) { + var out = getBlock(self); + var offset = start + i * blockSize; + + self._cache.writeUInt32BE(out[0], offset + 0); + + self._cache.writeUInt32BE(out[1], offset + 4); + + self._cache.writeUInt32BE(out[2], offset + 8); + + self._cache.writeUInt32BE(out[3], offset + 12); + } + + var pad = self._cache.slice(0, chunk.length); + + self._cache = self._cache.slice(chunk.length); + return xor(chunk, pad); + }; + + return exports$1f$1; +} + +var _list = { + "aes-128-ecb": { + "cipher": "AES", + "key": 128, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-192-ecb": { + "cipher": "AES", + "key": 192, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-256-ecb": { + "cipher": "AES", + "key": 256, + "iv": 0, + "mode": "ECB", + "type": "block" + }, + "aes-128-cbc": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-192-cbc": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-256-cbc": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes128": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes192": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes256": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CBC", + "type": "block" + }, + "aes-128-cfb": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-192-cfb": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-256-cfb": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB", + "type": "stream" + }, + "aes-128-cfb8": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-192-cfb8": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-256-cfb8": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB8", + "type": "stream" + }, + "aes-128-cfb1": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-192-cfb1": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-256-cfb1": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CFB1", + "type": "stream" + }, + "aes-128-ofb": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-192-ofb": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-256-ofb": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "OFB", + "type": "stream" + }, + "aes-128-ctr": { + "cipher": "AES", + "key": 128, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-192-ctr": { + "cipher": "AES", + "key": 192, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-256-ctr": { + "cipher": "AES", + "key": 256, + "iv": 16, + "mode": "CTR", + "type": "stream" + }, + "aes-128-gcm": { + "cipher": "AES", + "key": 128, + "iv": 12, + "mode": "GCM", + "type": "auth" + }, + "aes-192-gcm": { + "cipher": "AES", + "key": 192, + "iv": 12, + "mode": "GCM", + "type": "auth" + }, + "aes-256-gcm": { + "cipher": "AES", + "key": 256, + "iv": 12, + "mode": "GCM", + "type": "auth" + } +}; + +var exports$1e$1 = {}, + _dewExec$1d$1 = false; +function dew$1d$1() { + if (_dewExec$1d$1) return exports$1e$1; + _dewExec$1d$1 = true; + var modeModules = { + ECB: dew$1m(), + CBC: dew$1k(), + CFB: dew$1j(), + CFB8: dew$1i$1(), + CFB1: dew$1h$1(), + OFB: dew$1g$1(), + CTR: dew$1e$1(), + GCM: dew$1e$1() + }; + var modes = _list; + + for (var key in modes) { + modes[key].module = modeModules[modes[key].mode]; + } + + exports$1e$1 = modes; + return exports$1e$1; +} + +var exports$1d$1 = {}, + _dewExec$1c$1 = false; + +var _global$j$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1c$1() { + if (_dewExec$1c$1) return exports$1d$1; + _dewExec$1c$1 = true; + + // based on the aes implimentation in triple sec + // https://github.com/keybase/triplesec + // which is in turn based on the one from crypto-js + // https://code.google.com/p/crypto-js/ + var Buffer = dew$1T().Buffer; + + function asUInt32Array(buf) { + if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); + var len = buf.length / 4 | 0; + var out = new Array(len); + + for (var i = 0; i < len; i++) { + out[i] = buf.readUInt32BE(i * 4); + } + + return out; + } + + function scrubVec(v) { + for (var i = 0; i < v.length; v++) { + v[i] = 0; + } + } + + function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) { + var SUB_MIX0 = SUB_MIX[0]; + var SUB_MIX1 = SUB_MIX[1]; + var SUB_MIX2 = SUB_MIX[2]; + var SUB_MIX3 = SUB_MIX[3]; + var s0 = M[0] ^ keySchedule[0]; + var s1 = M[1] ^ keySchedule[1]; + var s2 = M[2] ^ keySchedule[2]; + var s3 = M[3] ^ keySchedule[3]; + var t0, t1, t2, t3; + var ksRow = 4; + + for (var round = 1; round < nRounds; round++) { + t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 255] ^ SUB_MIX2[s2 >>> 8 & 255] ^ SUB_MIX3[s3 & 255] ^ keySchedule[ksRow++]; + t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 255] ^ SUB_MIX2[s3 >>> 8 & 255] ^ SUB_MIX3[s0 & 255] ^ keySchedule[ksRow++]; + t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 255] ^ SUB_MIX2[s0 >>> 8 & 255] ^ SUB_MIX3[s1 & 255] ^ keySchedule[ksRow++]; + t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 255] ^ SUB_MIX2[s1 >>> 8 & 255] ^ SUB_MIX3[s2 & 255] ^ keySchedule[ksRow++]; + s0 = t0; + s1 = t1; + s2 = t2; + s3 = t3; + } + + t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 255] << 16 | SBOX[s2 >>> 8 & 255] << 8 | SBOX[s3 & 255]) ^ keySchedule[ksRow++]; + t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 255] << 16 | SBOX[s3 >>> 8 & 255] << 8 | SBOX[s0 & 255]) ^ keySchedule[ksRow++]; + t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 255] << 16 | SBOX[s0 >>> 8 & 255] << 8 | SBOX[s1 & 255]) ^ keySchedule[ksRow++]; + t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 255] << 16 | SBOX[s1 >>> 8 & 255] << 8 | SBOX[s2 & 255]) ^ keySchedule[ksRow++]; + t0 = t0 >>> 0; + t1 = t1 >>> 0; + t2 = t2 >>> 0; + t3 = t3 >>> 0; + return [t0, t1, t2, t3]; + } // AES constants + + + var RCON = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]; + + var G = function () { + // Compute double table + var d = new Array(256); + + for (var j = 0; j < 256; j++) { + if (j < 128) { + d[j] = j << 1; + } else { + d[j] = j << 1 ^ 283; + } + } + + var SBOX = []; + var INV_SBOX = []; + var SUB_MIX = [[], [], [], []]; + var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8) + + var x = 0; + var xi = 0; + + for (var i = 0; i < 256; ++i) { + // Compute sbox + var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4; + sx = sx >>> 8 ^ sx & 255 ^ 99; + SBOX[x] = sx; + INV_SBOX[sx] = x; // Compute multiplication + + var x2 = d[x]; + var x4 = d[x2]; + var x8 = d[x4]; // Compute sub bytes, mix columns tables + + var t = d[sx] * 257 ^ sx * 16843008; + SUB_MIX[0][x] = t << 24 | t >>> 8; + SUB_MIX[1][x] = t << 16 | t >>> 16; + SUB_MIX[2][x] = t << 8 | t >>> 24; + SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables + + t = x8 * 16843009 ^ x4 * 65537 ^ x2 * 257 ^ x * 16843008; + INV_SUB_MIX[0][sx] = t << 24 | t >>> 8; + INV_SUB_MIX[1][sx] = t << 16 | t >>> 16; + INV_SUB_MIX[2][sx] = t << 8 | t >>> 24; + INV_SUB_MIX[3][sx] = t; + + if (x === 0) { + x = xi = 1; + } else { + x = x2 ^ d[d[d[x8 ^ x2]]]; + xi ^= d[d[xi]]; + } + } + + return { + SBOX: SBOX, + INV_SBOX: INV_SBOX, + SUB_MIX: SUB_MIX, + INV_SUB_MIX: INV_SUB_MIX + }; + }(); + + function AES(key) { + (this || _global$j$1)._key = asUInt32Array(key); + + this._reset(); + } + + AES.blockSize = 4 * 4; + AES.keySize = 256 / 8; + AES.prototype.blockSize = AES.blockSize; + AES.prototype.keySize = AES.keySize; + + AES.prototype._reset = function () { + var keyWords = (this || _global$j$1)._key; + var keySize = keyWords.length; + var nRounds = keySize + 6; + var ksRows = (nRounds + 1) * 4; + var keySchedule = []; + + for (var k = 0; k < keySize; k++) { + keySchedule[k] = keyWords[k]; + } + + for (k = keySize; k < ksRows; k++) { + var t = keySchedule[k - 1]; + + if (k % keySize === 0) { + t = t << 8 | t >>> 24; + t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; + t ^= RCON[k / keySize | 0] << 24; + } else if (keySize > 6 && k % keySize === 4) { + t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; + } + + keySchedule[k] = keySchedule[k - keySize] ^ t; + } + + var invKeySchedule = []; + + for (var ik = 0; ik < ksRows; ik++) { + var ksR = ksRows - ik; + var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]; + + if (ik < 4 || ksR <= 4) { + invKeySchedule[ik] = tt; + } else { + invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 255]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 255]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 255]]; + } + } + + (this || _global$j$1)._nRounds = nRounds; + (this || _global$j$1)._keySchedule = keySchedule; + (this || _global$j$1)._invKeySchedule = invKeySchedule; + }; + + AES.prototype.encryptBlockRaw = function (M) { + M = asUInt32Array(M); + return cryptBlock(M, (this || _global$j$1)._keySchedule, G.SUB_MIX, G.SBOX, (this || _global$j$1)._nRounds); + }; + + AES.prototype.encryptBlock = function (M) { + var out = this.encryptBlockRaw(M); + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[1], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[3], 12); + return buf; + }; + + AES.prototype.decryptBlock = function (M) { + M = asUInt32Array(M); // swap + + var m1 = M[1]; + M[1] = M[3]; + M[3] = m1; + var out = cryptBlock(M, (this || _global$j$1)._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, (this || _global$j$1)._nRounds); + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0], 0); + buf.writeUInt32BE(out[3], 4); + buf.writeUInt32BE(out[2], 8); + buf.writeUInt32BE(out[1], 12); + return buf; + }; + + AES.prototype.scrub = function () { + scrubVec((this || _global$j$1)._keySchedule); + scrubVec((this || _global$j$1)._invKeySchedule); + scrubVec((this || _global$j$1)._key); + }; + + exports$1d$1.AES = AES; + return exports$1d$1; +} + +var exports$1c$1 = {}, + _dewExec$1b$1 = false; + +var _global$i$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1b$1() { + if (_dewExec$1b$1) return exports$1c$1; + _dewExec$1b$1 = true; + + var Buffer = dew$1T().Buffer; + + var ZEROES = Buffer.alloc(16, 0); + + function toArray(buf) { + return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)]; + } + + function fromArray(out) { + var buf = Buffer.allocUnsafe(16); + buf.writeUInt32BE(out[0] >>> 0, 0); + buf.writeUInt32BE(out[1] >>> 0, 4); + buf.writeUInt32BE(out[2] >>> 0, 8); + buf.writeUInt32BE(out[3] >>> 0, 12); + return buf; + } + + function GHASH(key) { + (this || _global$i$1).h = key; + (this || _global$i$1).state = Buffer.alloc(16, 0); + (this || _global$i$1).cache = Buffer.allocUnsafe(0); + } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html + // by Juho Vähä-Herttua + + + GHASH.prototype.ghash = function (block) { + var i = -1; + + while (++i < block.length) { + (this || _global$i$1).state[i] ^= block[i]; + } + + this._multiply(); + }; + + GHASH.prototype._multiply = function () { + var Vi = toArray((this || _global$i$1).h); + var Zi = [0, 0, 0, 0]; + var j, xi, lsbVi; + var i = -1; + + while (++i < 128) { + xi = ((this || _global$i$1).state[~~(i / 8)] & 1 << 7 - i % 8) !== 0; + + if (xi) { + // Z_i+1 = Z_i ^ V_i + Zi[0] ^= Vi[0]; + Zi[1] ^= Vi[1]; + Zi[2] ^= Vi[2]; + Zi[3] ^= Vi[3]; + } // Store the value of LSB(V_i) + + + lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1 + + for (j = 3; j > 0; j--) { + Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31; + } + + Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R + + if (lsbVi) { + Vi[0] = Vi[0] ^ 225 << 24; + } + } + + (this || _global$i$1).state = fromArray(Zi); + }; + + GHASH.prototype.update = function (buf) { + (this || _global$i$1).cache = Buffer.concat([(this || _global$i$1).cache, buf]); + var chunk; + + while ((this || _global$i$1).cache.length >= 16) { + chunk = (this || _global$i$1).cache.slice(0, 16); + (this || _global$i$1).cache = (this || _global$i$1).cache.slice(16); + this.ghash(chunk); + } + }; + + GHASH.prototype.final = function (abl, bl) { + if ((this || _global$i$1).cache.length) { + this.ghash(Buffer.concat([(this || _global$i$1).cache, ZEROES], 16)); + } + + this.ghash(fromArray([0, abl, 0, bl])); + return (this || _global$i$1).state; + }; + + exports$1c$1 = GHASH; + return exports$1c$1; +} + +var exports$1b$1 = {}, + _dewExec$1a$1 = false; + +var _global$h$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$1a$1() { + if (_dewExec$1a$1) return exports$1b$1; + _dewExec$1a$1 = true; + + var aes = dew$1c$1(); + + var Buffer = dew$1T().Buffer; + + var Transform = dew$1G(); + + var inherits = dew$f$2(); + + var GHASH = dew$1b$1(); + + var xor = dew$1l(); + + var incr32 = dew$1f$1(); + + function xorTest(a, b) { + var out = 0; + if (a.length !== b.length) out++; + var len = Math.min(a.length, b.length); + + for (var i = 0; i < len; ++i) { + out += a[i] ^ b[i]; + } + + return out; + } + + function calcIv(self, iv, ck) { + if (iv.length === 12) { + self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]); + return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]); + } + + var ghash = new GHASH(ck); + var len = iv.length; + var toPad = len % 16; + ghash.update(iv); + + if (toPad) { + toPad = 16 - toPad; + ghash.update(Buffer.alloc(toPad, 0)); + } + + ghash.update(Buffer.alloc(8, 0)); + var ivBits = len * 8; + var tail = Buffer.alloc(8); + tail.writeUIntBE(ivBits, 0, 8); + ghash.update(tail); + self._finID = ghash.state; + var out = Buffer.from(self._finID); + incr32(out); + return out; + } + + function StreamCipher(mode, key, iv, decrypt) { + Transform.call(this || _global$h$1); + var h = Buffer.alloc(4, 0); + (this || _global$h$1)._cipher = new aes.AES(key); + + var ck = (this || _global$h$1)._cipher.encryptBlock(h); + + (this || _global$h$1)._ghash = new GHASH(ck); + iv = calcIv(this || _global$h$1, iv, ck); + (this || _global$h$1)._prev = Buffer.from(iv); + (this || _global$h$1)._cache = Buffer.allocUnsafe(0); + (this || _global$h$1)._secCache = Buffer.allocUnsafe(0); + (this || _global$h$1)._decrypt = decrypt; + (this || _global$h$1)._alen = 0; + (this || _global$h$1)._len = 0; + (this || _global$h$1)._mode = mode; + (this || _global$h$1)._authTag = null; + (this || _global$h$1)._called = false; + } + + inherits(StreamCipher, Transform); + + StreamCipher.prototype._update = function (chunk) { + if (!(this || _global$h$1)._called && (this || _global$h$1)._alen) { + var rump = 16 - (this || _global$h$1)._alen % 16; + + if (rump < 16) { + rump = Buffer.alloc(rump, 0); + + (this || _global$h$1)._ghash.update(rump); + } + } + + (this || _global$h$1)._called = true; + + var out = (this || _global$h$1)._mode.encrypt(this || _global$h$1, chunk); + + if ((this || _global$h$1)._decrypt) { + (this || _global$h$1)._ghash.update(chunk); + } else { + (this || _global$h$1)._ghash.update(out); + } + + (this || _global$h$1)._len += chunk.length; + return out; + }; + + StreamCipher.prototype._final = function () { + if ((this || _global$h$1)._decrypt && !(this || _global$h$1)._authTag) throw new Error("Unsupported state or unable to authenticate data"); + var tag = xor((this || _global$h$1)._ghash.final((this || _global$h$1)._alen * 8, (this || _global$h$1)._len * 8), (this || _global$h$1)._cipher.encryptBlock((this || _global$h$1)._finID)); + if ((this || _global$h$1)._decrypt && xorTest(tag, (this || _global$h$1)._authTag)) throw new Error("Unsupported state or unable to authenticate data"); + (this || _global$h$1)._authTag = tag; + + (this || _global$h$1)._cipher.scrub(); + }; + + StreamCipher.prototype.getAuthTag = function getAuthTag() { + if ((this || _global$h$1)._decrypt || !Buffer.isBuffer((this || _global$h$1)._authTag)) throw new Error("Attempting to get auth tag in unsupported state"); + return (this || _global$h$1)._authTag; + }; + + StreamCipher.prototype.setAuthTag = function setAuthTag(tag) { + if (!(this || _global$h$1)._decrypt) throw new Error("Attempting to set auth tag in unsupported state"); + (this || _global$h$1)._authTag = tag; + }; + + StreamCipher.prototype.setAAD = function setAAD(buf) { + if ((this || _global$h$1)._called) throw new Error("Attempting to set AAD in unsupported state"); + + (this || _global$h$1)._ghash.update(buf); + + (this || _global$h$1)._alen += buf.length; + }; + + exports$1b$1 = StreamCipher; + return exports$1b$1; +} + +var exports$1a$1 = {}, + _dewExec$19$1 = false; + +var _global$g$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$19$1() { + if (_dewExec$19$1) return exports$1a$1; + _dewExec$19$1 = true; + + var aes = dew$1c$1(); + + var Buffer = dew$1T().Buffer; + + var Transform = dew$1G(); + + var inherits = dew$f$2(); + + function StreamCipher(mode, key, iv, decrypt) { + Transform.call(this || _global$g$1); + (this || _global$g$1)._cipher = new aes.AES(key); + (this || _global$g$1)._prev = Buffer.from(iv); + (this || _global$g$1)._cache = Buffer.allocUnsafe(0); + (this || _global$g$1)._secCache = Buffer.allocUnsafe(0); + (this || _global$g$1)._decrypt = decrypt; + (this || _global$g$1)._mode = mode; + } + + inherits(StreamCipher, Transform); + + StreamCipher.prototype._update = function (chunk) { + return (this || _global$g$1)._mode.encrypt(this || _global$g$1, chunk, (this || _global$g$1)._decrypt); + }; + + StreamCipher.prototype._final = function () { + (this || _global$g$1)._cipher.scrub(); + }; + + exports$1a$1 = StreamCipher; + return exports$1a$1; +} + +var exports$19$1 = {}, + _dewExec$18$1 = false; +function dew$18$1() { + if (_dewExec$18$1) return exports$19$1; + _dewExec$18$1 = true; + + var Buffer = dew$1T().Buffer; + + var MD5 = dew$1Q(); + /* eslint-disable camelcase */ + + + function EVP_BytesToKey(password, salt, keyBits, ivLen) { + if (!Buffer.isBuffer(password)) password = Buffer.from(password, "binary"); + + if (salt) { + if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, "binary"); + if (salt.length !== 8) throw new RangeError("salt should be Buffer with 8 byte length"); + } + + var keyLen = keyBits / 8; + var key = Buffer.alloc(keyLen); + var iv = Buffer.alloc(ivLen || 0); + var tmp = Buffer.alloc(0); + + while (keyLen > 0 || ivLen > 0) { + var hash = new MD5(); + hash.update(tmp); + hash.update(password); + if (salt) hash.update(salt); + tmp = hash.digest(); + var used = 0; + + if (keyLen > 0) { + var keyStart = key.length - keyLen; + used = Math.min(keyLen, tmp.length); + tmp.copy(key, keyStart, 0, used); + keyLen -= used; + } + + if (used < tmp.length && ivLen > 0) { + var ivStart = iv.length - ivLen; + var length = Math.min(ivLen, tmp.length - used); + tmp.copy(iv, ivStart, used, used + length); + ivLen -= length; + } + } + + tmp.fill(0); + return { + key: key, + iv: iv + }; + } + + exports$19$1 = EVP_BytesToKey; + return exports$19$1; +} + +var exports$18$1 = {}, + _dewExec$17$1 = false; + +var _global$f$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$17$1() { + if (_dewExec$17$1) return exports$18$1; + _dewExec$17$1 = true; + + var MODES = dew$1d$1(); + + var AuthCipher = dew$1a$1(); + + var Buffer = dew$1T().Buffer; + + var StreamCipher = dew$19$1(); + + var Transform = dew$1G(); + + var aes = dew$1c$1(); + + var ebtk = dew$18$1(); + + var inherits = dew$f$2(); + + function Cipher(mode, key, iv) { + Transform.call(this || _global$f$1); + (this || _global$f$1)._cache = new Splitter(); + (this || _global$f$1)._cipher = new aes.AES(key); + (this || _global$f$1)._prev = Buffer.from(iv); + (this || _global$f$1)._mode = mode; + (this || _global$f$1)._autopadding = true; + } + + inherits(Cipher, Transform); + + Cipher.prototype._update = function (data) { + (this || _global$f$1)._cache.add(data); + + var chunk; + var thing; + var out = []; + + while (chunk = (this || _global$f$1)._cache.get()) { + thing = (this || _global$f$1)._mode.encrypt(this || _global$f$1, chunk); + out.push(thing); + } + + return Buffer.concat(out); + }; + + var PADDING = Buffer.alloc(16, 16); + + Cipher.prototype._final = function () { + var chunk = (this || _global$f$1)._cache.flush(); + + if ((this || _global$f$1)._autopadding) { + chunk = (this || _global$f$1)._mode.encrypt(this || _global$f$1, chunk); + + (this || _global$f$1)._cipher.scrub(); + + return chunk; + } + + if (!chunk.equals(PADDING)) { + (this || _global$f$1)._cipher.scrub(); + + throw new Error("data not multiple of block length"); + } + }; + + Cipher.prototype.setAutoPadding = function (setTo) { + (this || _global$f$1)._autopadding = !!setTo; + return this || _global$f$1; + }; + + function Splitter() { + (this || _global$f$1).cache = Buffer.allocUnsafe(0); + } + + Splitter.prototype.add = function (data) { + (this || _global$f$1).cache = Buffer.concat([(this || _global$f$1).cache, data]); + }; + + Splitter.prototype.get = function () { + if ((this || _global$f$1).cache.length > 15) { + var out = (this || _global$f$1).cache.slice(0, 16); + + (this || _global$f$1).cache = (this || _global$f$1).cache.slice(16); + return out; + } + + return null; + }; + + Splitter.prototype.flush = function () { + var len = 16 - (this || _global$f$1).cache.length; + var padBuff = Buffer.allocUnsafe(len); + var i = -1; + + while (++i < len) { + padBuff.writeUInt8(len, i); + } + + return Buffer.concat([(this || _global$f$1).cache, padBuff]); + }; + + function createCipheriv(suite, password, iv) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + if (typeof password === "string") password = Buffer.from(password); + if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + if (typeof iv === "string") iv = Buffer.from(iv); + if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + + if (config.type === "stream") { + return new StreamCipher(config.module, password, iv); + } else if (config.type === "auth") { + return new AuthCipher(config.module, password, iv); + } + + return new Cipher(config.module, password, iv); + } + + function createCipher(suite, password) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + var keys = ebtk(password, false, config.key, config.iv); + return createCipheriv(suite, keys.key, keys.iv); + } + + exports$18$1.createCipheriv = createCipheriv; + exports$18$1.createCipher = createCipher; + return exports$18$1; +} + +var exports$17$1 = {}, + _dewExec$16$1 = false; + +var _global$e$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$16$1() { + if (_dewExec$16$1) return exports$17$1; + _dewExec$16$1 = true; + + var AuthCipher = dew$1a$1(); + + var Buffer = dew$1T().Buffer; + + var MODES = dew$1d$1(); + + var StreamCipher = dew$19$1(); + + var Transform = dew$1G(); + + var aes = dew$1c$1(); + + var ebtk = dew$18$1(); + + var inherits = dew$f$2(); + + function Decipher(mode, key, iv) { + Transform.call(this || _global$e$1); + (this || _global$e$1)._cache = new Splitter(); + (this || _global$e$1)._last = void 0; + (this || _global$e$1)._cipher = new aes.AES(key); + (this || _global$e$1)._prev = Buffer.from(iv); + (this || _global$e$1)._mode = mode; + (this || _global$e$1)._autopadding = true; + } + + inherits(Decipher, Transform); + + Decipher.prototype._update = function (data) { + (this || _global$e$1)._cache.add(data); + + var chunk; + var thing; + var out = []; + + while (chunk = (this || _global$e$1)._cache.get((this || _global$e$1)._autopadding)) { + thing = (this || _global$e$1)._mode.decrypt(this || _global$e$1, chunk); + out.push(thing); + } + + return Buffer.concat(out); + }; + + Decipher.prototype._final = function () { + var chunk = (this || _global$e$1)._cache.flush(); + + if ((this || _global$e$1)._autopadding) { + return unpad((this || _global$e$1)._mode.decrypt(this || _global$e$1, chunk)); + } else if (chunk) { + throw new Error("data not multiple of block length"); + } + }; + + Decipher.prototype.setAutoPadding = function (setTo) { + (this || _global$e$1)._autopadding = !!setTo; + return this || _global$e$1; + }; + + function Splitter() { + (this || _global$e$1).cache = Buffer.allocUnsafe(0); + } + + Splitter.prototype.add = function (data) { + (this || _global$e$1).cache = Buffer.concat([(this || _global$e$1).cache, data]); + }; + + Splitter.prototype.get = function (autoPadding) { + var out; + + if (autoPadding) { + if ((this || _global$e$1).cache.length > 16) { + out = (this || _global$e$1).cache.slice(0, 16); + (this || _global$e$1).cache = (this || _global$e$1).cache.slice(16); + return out; + } + } else { + if ((this || _global$e$1).cache.length >= 16) { + out = (this || _global$e$1).cache.slice(0, 16); + (this || _global$e$1).cache = (this || _global$e$1).cache.slice(16); + return out; + } + } + + return null; + }; + + Splitter.prototype.flush = function () { + if ((this || _global$e$1).cache.length) return (this || _global$e$1).cache; + }; + + function unpad(last) { + var padded = last[15]; + + if (padded < 1 || padded > 16) { + throw new Error("unable to decrypt data"); + } + + var i = -1; + + while (++i < padded) { + if (last[i + (16 - padded)] !== padded) { + throw new Error("unable to decrypt data"); + } + } + + if (padded === 16) return; + return last.slice(0, 16 - padded); + } + + function createDecipheriv(suite, password, iv) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + if (typeof iv === "string") iv = Buffer.from(iv); + if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + if (typeof password === "string") password = Buffer.from(password); + if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + + if (config.type === "stream") { + return new StreamCipher(config.module, password, iv, true); + } else if (config.type === "auth") { + return new AuthCipher(config.module, password, iv, true); + } + + return new Decipher(config.module, password, iv); + } + + function createDecipher(suite, password) { + var config = MODES[suite.toLowerCase()]; + if (!config) throw new TypeError("invalid suite type"); + var keys = ebtk(password, false, config.key, config.iv); + return createDecipheriv(suite, keys.key, keys.iv); + } + + exports$17$1.createDecipher = createDecipher; + exports$17$1.createDecipheriv = createDecipheriv; + return exports$17$1; +} + +var exports$16$1 = {}, + _dewExec$15$1 = false; +function dew$15$1() { + if (_dewExec$15$1) return exports$16$1; + _dewExec$15$1 = true; + + var ciphers = dew$17$1(); + + var deciphers = dew$16$1(); + + var modes = _list; + + function getCiphers() { + return Object.keys(modes); + } + + exports$16$1.createCipher = exports$16$1.Cipher = ciphers.createCipher; + exports$16$1.createCipheriv = exports$16$1.Cipheriv = ciphers.createCipheriv; + exports$16$1.createDecipher = exports$16$1.Decipher = deciphers.createDecipher; + exports$16$1.createDecipheriv = exports$16$1.Decipheriv = deciphers.createDecipheriv; + exports$16$1.listCiphers = exports$16$1.getCiphers = getCiphers; + return exports$16$1; +} + +var exports$15$1 = {}, + _dewExec$14$1 = false; +function dew$14$1() { + if (_dewExec$14$1) return exports$15$1; + _dewExec$14$1 = true; + exports$15$1["des-ecb"] = { + key: 8, + iv: 0 + }; + exports$15$1["des-cbc"] = exports$15$1.des = { + key: 8, + iv: 8 + }; + exports$15$1["des-ede3-cbc"] = exports$15$1.des3 = { + key: 24, + iv: 8 + }; + exports$15$1["des-ede3"] = { + key: 24, + iv: 0 + }; + exports$15$1["des-ede-cbc"] = { + key: 16, + iv: 8 + }; + exports$15$1["des-ede"] = { + key: 16, + iv: 0 + }; + return exports$15$1; +} + +var exports$14$1 = {}, + _dewExec$13$1 = false; +function dew$13$1() { + if (_dewExec$13$1) return exports$14$1; + _dewExec$13$1 = true; + + var DES = dew$1n(); + + var aes = dew$15$1(); + + var aesModes = dew$1d$1(); + + var desModes = dew$14$1(); + + var ebtk = dew$18$1(); + + function createCipher(suite, password) { + suite = suite.toLowerCase(); + var keyLen, ivLen; + + if (aesModes[suite]) { + keyLen = aesModes[suite].key; + ivLen = aesModes[suite].iv; + } else if (desModes[suite]) { + keyLen = desModes[suite].key * 8; + ivLen = desModes[suite].iv; + } else { + throw new TypeError("invalid suite type"); + } + + var keys = ebtk(password, false, keyLen, ivLen); + return createCipheriv(suite, keys.key, keys.iv); + } + + function createDecipher(suite, password) { + suite = suite.toLowerCase(); + var keyLen, ivLen; + + if (aesModes[suite]) { + keyLen = aesModes[suite].key; + ivLen = aesModes[suite].iv; + } else if (desModes[suite]) { + keyLen = desModes[suite].key * 8; + ivLen = desModes[suite].iv; + } else { + throw new TypeError("invalid suite type"); + } + + var keys = ebtk(password, false, keyLen, ivLen); + return createDecipheriv(suite, keys.key, keys.iv); + } + + function createCipheriv(suite, key, iv) { + suite = suite.toLowerCase(); + if (aesModes[suite]) return aes.createCipheriv(suite, key, iv); + if (desModes[suite]) return new DES({ + key: key, + iv: iv, + mode: suite + }); + throw new TypeError("invalid suite type"); + } + + function createDecipheriv(suite, key, iv) { + suite = suite.toLowerCase(); + if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv); + if (desModes[suite]) return new DES({ + key: key, + iv: iv, + mode: suite, + decrypt: true + }); + throw new TypeError("invalid suite type"); + } + + function getCiphers() { + return Object.keys(desModes).concat(aes.getCiphers()); + } + + exports$14$1.createCipher = exports$14$1.Cipher = createCipher; + exports$14$1.createCipheriv = exports$14$1.Cipheriv = createCipheriv; + exports$14$1.createDecipher = exports$14$1.Decipher = createDecipher; + exports$14$1.createDecipheriv = exports$14$1.Decipheriv = createDecipheriv; + exports$14$1.listCiphers = exports$14$1.getCiphers = getCiphers; + return exports$14$1; +} + +var exports$13$1 = {}, + _dewExec$12$1 = false; +var module$6 = { + exports: exports$13$1 +}; + +var _global$d$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$12$1() { + if (_dewExec$12$1) return module$6.exports; + _dewExec$12$1 = true; + + (function (module, exports) { + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. + + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + + var TempCtor = function () {}; + + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN + + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } + + (this || _global$d$1).negative = 0; + (this || _global$d$1).words = null; + (this || _global$d$1).length = 0; // Reduction context + + (this || _global$d$1).red = null; + + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + + this._init(number || 0, base || 10, endian || "be"); + } + } + + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = e$1$1$1.Buffer; + } + } catch (e) {} + + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + + if (base === "hex") { + base = 16; + } + + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + + if (number[0] === "-") { + start++; + (this || _global$d$1).negative = 1; + } + + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } + }; + + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$d$1).negative = 1; + number = -number; + } + + if (number < 67108864) { + (this || _global$d$1).words = [number & 67108863]; + (this || _global$d$1).length = 1; + } else if (number < 4503599627370496) { + (this || _global$d$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$d$1).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + + (this || _global$d$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$d$1).length = 3; + } + + if (endian !== "le") return; // Reverse the bytes + + this._initArray(this.toArray(), base, endian); + }; + + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + + if (number.length <= 0) { + (this || _global$d$1).words = [0]; + (this || _global$d$1).length = 1; + return this || _global$d$1; + } + + (this || _global$d$1).length = Math.ceil(number.length / 3); + (this || _global$d$1).words = new Array((this || _global$d$1).length); + + for (var i = 0; i < (this || _global$d$1).length; i++) { + (this || _global$d$1).words[i] = 0; + } + + var j, w; + var off = 0; + + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$d$1).words[j] |= w << off & 67108863; + (this || _global$d$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$d$1).words[j] |= w << off & 67108863; + (this || _global$d$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } + + return this.strip(); + }; + + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // 'A' - 'F' + + if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; // '0' - '9' + } else { + return c - 48 & 15; + } + } + + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); + + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } + + return r; + } + + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$d$1).length = Math.ceil((number.length - start) / 6); + (this || _global$d$1).words = new Array((this || _global$d$1).length); + + for (var i = 0; i < (this || _global$d$1).length; i++) { + (this || _global$d$1).words[i] = 0; + } // 24-bits chunks + + + var off = 0; + var j = 0; + var w; + + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$d$1).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$d$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$d$1).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$d$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + + this.strip(); + }; + + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' + + if (c >= 49) { + r += c - 49 + 10; // 'A' + } else if (c >= 17) { + r += c - 17 + 10; // '0' - '9' + } else { + r += c; + } + } + + return r; + } + + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$d$1).words = [0]; + (this || _global$d$1).length = 1; // Find length of limb in base + + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + + if ((this || _global$d$1).words[0] + word < 67108864) { + (this || _global$d$1).words[0] += word; + } else { + this._iaddn(word); + } + } + + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + + for (i = 0; i < mod; i++) { + pow *= base; + } + + this.imuln(pow); + + if ((this || _global$d$1).words[0] + word < 67108864) { + (this || _global$d$1).words[0] += word; + } else { + this._iaddn(word); + } + } + + this.strip(); + }; + + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$d$1).length); + + for (var i = 0; i < (this || _global$d$1).length; i++) { + dest.words[i] = (this || _global$d$1).words[i]; + } + + dest.length = (this || _global$d$1).length; + dest.negative = (this || _global$d$1).negative; + dest.red = (this || _global$d$1).red; + }; + + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + + BN.prototype._expand = function _expand(size) { + while ((this || _global$d$1).length < size) { + (this || _global$d$1).words[(this || _global$d$1).length++] = 0; + } + + return this || _global$d$1; + }; // Remove leading `0` from `this` + + + BN.prototype.strip = function strip() { + while ((this || _global$d$1).length > 1 && (this || _global$d$1).words[(this || _global$d$1).length - 1] === 0) { + (this || _global$d$1).length--; + } + + return this._normSign(); + }; + + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$d$1).length === 1 && (this || _global$d$1).words[0] === 0) { + (this || _global$d$1).negative = 0; + } + + return this || _global$d$1; + }; + + BN.prototype.inspect = function inspect() { + return ((this || _global$d$1).red ? ""; + }; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ + + + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + + for (var i = 0; i < (this || _global$d$1).length; i++) { + var w = (this || _global$d$1).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + + if (carry !== 0 || i !== (this || _global$d$1).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + + off += 2; + + if (off >= 26) { + off -= 26; + i--; + } + } + + if (carry !== 0) { + out = carry.toString(16) + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$d$1).negative !== 0) { + out = "-" + out; + } + + return out; + } + + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); + + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + + if (this.isZero()) { + out = "0" + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$d$1).negative !== 0) { + out = "-" + out; + } + + return out; + } + + assert(false, "Base should be between 2 and 36"); + }; + + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$d$1).words[0]; + + if ((this || _global$d$1).length === 2) { + ret += (this || _global$d$1).words[1] * 67108864; + } else if ((this || _global$d$1).length === 3 && (this || _global$d$1).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$d$1).words[1] * 67108864; + } else if ((this || _global$d$1).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + + return (this || _global$d$1).negative !== 0 ? -ret : ret; + }; + + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; + + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; + + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } + } else { + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + + for (; i < reqLength; i++) { + res[i] = 0; + } + } + + return res; + }; + + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + + if (t >= 4096) { + r += 13; + t >>>= 13; + } + + if (t >= 64) { + r += 7; + t >>>= 7; + } + + if (t >= 8) { + r += 4; + t >>>= 4; + } + + if (t >= 2) { + r += 2; + t >>>= 2; + } + + return r + t; + }; + } + + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } + + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } + + if ((t & 1) === 0) { + r++; + } + + return r; + }; // Return number of used bits in a BN + + + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$d$1).words[(this || _global$d$1).length - 1]; + + var hi = this._countBits(w); + + return ((this || _global$d$1).length - 1) * 26 + hi; + }; + + function toBitArray(num) { + var w = new Array(num.bitLength()); + + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + + return w; + } // Number of trailing zero bits + + + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; + + for (var i = 0; i < (this || _global$d$1).length; i++) { + var b = this._zeroBits((this || _global$d$1).words[i]); + + r += b; + if (b !== 26) break; + } + + return r; + }; + + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; + + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$d$1).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + + return this.clone(); + }; + + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } + + return this.clone(); + }; + + BN.prototype.isNeg = function isNeg() { + return (this || _global$d$1).negative !== 0; + }; // Return negative clone of `this` + + + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; + + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$d$1).negative ^= 1; + } + + return this || _global$d$1; + }; // Or `num` with `this` in-place + + + BN.prototype.iuor = function iuor(num) { + while ((this || _global$d$1).length < num.length) { + (this || _global$d$1).words[(this || _global$d$1).length++] = 0; + } + + for (var i = 0; i < num.length; i++) { + (this || _global$d$1).words[i] = (this || _global$d$1).words[i] | num.words[i]; + } + + return this.strip(); + }; + + BN.prototype.ior = function ior(num) { + assert(((this || _global$d$1).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` + + + BN.prototype.or = function or(num) { + if ((this || _global$d$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$d$1); + }; + + BN.prototype.uor = function uor(num) { + if ((this || _global$d$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$d$1); + }; // And `num` with `this` in-place + + + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + + if ((this || _global$d$1).length > num.length) { + b = num; + } else { + b = this || _global$d$1; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$d$1).words[i] = (this || _global$d$1).words[i] & num.words[i]; + } + + (this || _global$d$1).length = b.length; + return this.strip(); + }; + + BN.prototype.iand = function iand(num) { + assert(((this || _global$d$1).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` + + + BN.prototype.and = function and(num) { + if ((this || _global$d$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$d$1); + }; + + BN.prototype.uand = function uand(num) { + if ((this || _global$d$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$d$1); + }; // Xor `num` with `this` in-place + + + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + + if ((this || _global$d$1).length > num.length) { + a = this || _global$d$1; + b = num; + } else { + a = num; + b = this || _global$d$1; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$d$1).words[i] = a.words[i] ^ b.words[i]; + } + + if ((this || _global$d$1) !== a) { + for (; i < a.length; i++) { + (this || _global$d$1).words[i] = a.words[i]; + } + } + + (this || _global$d$1).length = a.length; + return this.strip(); + }; + + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$d$1).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` + + + BN.prototype.xor = function xor(num) { + if ((this || _global$d$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$d$1); + }; + + BN.prototype.uxor = function uxor(num) { + if ((this || _global$d$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$d$1); + }; // Not ``this`` with ``width`` bitwidth + + + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes + + this._expand(bytesNeeded); + + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words + + + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$d$1).words[i] = ~(this || _global$d$1).words[i] & 67108863; + } // Handle the residue + + + if (bitsLeft > 0) { + (this || _global$d$1).words[i] = ~(this || _global$d$1).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes + + + return this.strip(); + }; + + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` + + + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + + this._expand(off + 1); + + if (val) { + (this || _global$d$1).words[off] = (this || _global$d$1).words[off] | 1 << wbit; + } else { + (this || _global$d$1).words[off] = (this || _global$d$1).words[off] & ~(1 << wbit); + } + + return this.strip(); + }; // Add `num` to `this` in-place + + + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive + + if ((this || _global$d$1).negative !== 0 && num.negative === 0) { + (this || _global$d$1).negative = 0; + r = this.isub(num); + (this || _global$d$1).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$d$1).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length + + + var a, b; + + if ((this || _global$d$1).length > num.length) { + a = this || _global$d$1; + b = num; + } else { + a = num; + b = this || _global$d$1; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$d$1).words[i] = r & 67108863; + carry = r >>> 26; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$d$1).words[i] = r & 67108863; + carry = r >>> 26; + } + + (this || _global$d$1).length = a.length; + + if (carry !== 0) { + (this || _global$d$1).words[(this || _global$d$1).length] = carry; + (this || _global$d$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$d$1)) { + for (; i < a.length; i++) { + (this || _global$d$1).words[i] = a.words[i]; + } + } + + return this || _global$d$1; + }; // Add `num` to `this` + + + BN.prototype.add = function add(num) { + var res; + + if (num.negative !== 0 && (this || _global$d$1).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$d$1).negative !== 0) { + (this || _global$d$1).negative = 0; + res = num.sub(this || _global$d$1); + (this || _global$d$1).negative = 1; + return res; + } + + if ((this || _global$d$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$d$1); + }; // Subtract `num` from `this` in-place + + + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$d$1).negative !== 0) { + (this || _global$d$1).negative = 0; + this.iadd(num); + (this || _global$d$1).negative = 1; + return this._normSign(); + } // At this point both numbers are positive + + + var cmp = this.cmp(num); // Optimization - zeroify + + if (cmp === 0) { + (this || _global$d$1).negative = 0; + (this || _global$d$1).length = 1; + (this || _global$d$1).words[0] = 0; + return this || _global$d$1; + } // a > b + + + var a, b; + + if (cmp > 0) { + a = this || _global$d$1; + b = num; + } else { + a = num; + b = this || _global$d$1; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$d$1).words[i] = r & 67108863; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$d$1).words[i] = r & 67108863; + } // Copy rest of the words + + + if (carry === 0 && i < a.length && a !== (this || _global$d$1)) { + for (; i < a.length; i++) { + (this || _global$d$1).words[i] = a.words[i]; + } + } + + (this || _global$d$1).length = Math.max((this || _global$d$1).length, i); + + if (a !== (this || _global$d$1)) { + (this || _global$d$1).negative = 1; + } + + return this.strip(); + }; // Subtract `num` from `this` + + + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; + + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; + + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } + + out.words[k] = rword | 0; + carry = ncarry | 0; + } + + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } + + return out.strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). + + + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ + + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ + + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ + + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ + + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ + + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ + + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ + + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ + + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ + + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ + + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ + + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ + + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ + + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ + + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ + + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + + if (c !== 0) { + o[19] = c; + out.length++; + } + + return out; + }; // Polyfill comb + + + if (!Math.imul) { + comb10MulTo = smallMulTo; + } + + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; + + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } + + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } + + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } + + return out.strip(); + } + + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } + + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$d$1).length + num.length; + + if ((this || _global$d$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$d$1, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$d$1, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$d$1, num, out); + } else { + res = jumboMulTo(this || _global$d$1, num, out); + } + + return res; + }; // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion + + + function FFTM(x, y) { + (this || _global$d$1).x = x; + (this || _global$d$1).y = y; + } + + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; + + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } + + return t; + }; // Returns binary-reversed representation of `x` + + + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } + + return rb; + }; // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm + + + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; + + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); + + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); + + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; + + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + /* jshint maxdepth : false */ + + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } + } + }; + + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; + + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } + + return 1 << i + 1 + odd; + }; + + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; + + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; + } + }; + + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; + + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; + + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } + + return ws; + }; + + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; + + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } // Pad with zeroes + + + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } + + assert(carry === 0); + assert((carry & ~8191) === 0); + }; + + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); + + for (var i = 0; i < N; i++) { + ph[i] = 0; + } + + return ph; + }; + + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); + + var _ = this.stub(N); + + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); + + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } + + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; // Multiply `this` by `num` + + + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$d$1).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT + + + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$d$1).length + num.length); + return jumboMulTo(this || _global$d$1, num, out); + }; // In-place Multiplication + + + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$d$1); + }; + + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); // Carry + + var carry = 0; + + for (var i = 0; i < (this || _global$d$1).length; i++) { + var w = ((this || _global$d$1).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum + + carry += lo >>> 26; + (this || _global$d$1).words[i] = lo & 67108863; + } + + if (carry !== 0) { + (this || _global$d$1).words[i] = carry; + (this || _global$d$1).length++; + } + + return this || _global$d$1; + }; + + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` + + + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$d$1); + }; // `this` * `this` in-place + + + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) + + + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes + + var res = this || _global$d$1; + + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } + + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } + + return res; + }; // Shift-left in-place + + + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; + + if (r !== 0) { + var carry = 0; + + for (i = 0; i < (this || _global$d$1).length; i++) { + var newCarry = (this || _global$d$1).words[i] & carryMask; + var c = ((this || _global$d$1).words[i] | 0) - newCarry << r; + (this || _global$d$1).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } + + if (carry) { + (this || _global$d$1).words[i] = carry; + (this || _global$d$1).length++; + } + } + + if (s !== 0) { + for (i = (this || _global$d$1).length - 1; i >= 0; i--) { + (this || _global$d$1).words[i + s] = (this || _global$d$1).words[i]; + } + + for (i = 0; i < s; i++) { + (this || _global$d$1).words[i] = 0; + } + + (this || _global$d$1).length += s; + } + + return this.strip(); + }; + + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$d$1).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits + + + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; + + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } + + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$d$1).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part + + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$d$1).words[i]; + } + + maskedWords.length = s; + } + + if (s === 0) ; else if ((this || _global$d$1).length > s) { + (this || _global$d$1).length -= s; + + for (i = 0; i < (this || _global$d$1).length; i++) { + (this || _global$d$1).words[i] = (this || _global$d$1).words[i + s]; + } + } else { + (this || _global$d$1).words[0] = 0; + (this || _global$d$1).length = 1; + } + + var carry = 0; + + for (i = (this || _global$d$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$d$1).words[i] | 0; + (this || _global$d$1).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask + + + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } + + if ((this || _global$d$1).length === 0) { + (this || _global$d$1).words[0] = 0; + (this || _global$d$1).length = 1; + } + + return this.strip(); + }; + + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$d$1).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left + + + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; + + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right + + + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; + + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set + + + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$d$1).length <= s) return false; // Check bit and return + + var w = (this || _global$d$1).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) + + + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$d$1).negative === 0, "imaskn works only with positive numbers"); + + if ((this || _global$d$1).length <= s) { + return this || _global$d$1; + } + + if (r !== 0) { + s++; + } + + (this || _global$d$1).length = Math.min(s, (this || _global$d$1).length); + + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$d$1).words[(this || _global$d$1).length - 1] &= mask; + } + + return this.strip(); + }; // Return only lowers bits of number + + + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` + + + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change + + if ((this || _global$d$1).negative !== 0) { + if ((this || _global$d$1).length === 1 && ((this || _global$d$1).words[0] | 0) < num) { + (this || _global$d$1).words[0] = num - ((this || _global$d$1).words[0] | 0); + (this || _global$d$1).negative = 0; + return this || _global$d$1; + } + + (this || _global$d$1).negative = 0; + this.isubn(num); + (this || _global$d$1).negative = 1; + return this || _global$d$1; + } // Add without checks + + + return this._iaddn(num); + }; + + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$d$1).words[0] += num; // Carry + + for (var i = 0; i < (this || _global$d$1).length && (this || _global$d$1).words[i] >= 67108864; i++) { + (this || _global$d$1).words[i] -= 67108864; + + if (i === (this || _global$d$1).length - 1) { + (this || _global$d$1).words[i + 1] = 1; + } else { + (this || _global$d$1).words[i + 1]++; + } + } + + (this || _global$d$1).length = Math.max((this || _global$d$1).length, i + 1); + return this || _global$d$1; + }; // Subtract plain number `num` from `this` + + + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); + + if ((this || _global$d$1).negative !== 0) { + (this || _global$d$1).negative = 0; + this.iaddn(num); + (this || _global$d$1).negative = 1; + return this || _global$d$1; + } + + (this || _global$d$1).words[0] -= num; + + if ((this || _global$d$1).length === 1 && (this || _global$d$1).words[0] < 0) { + (this || _global$d$1).words[0] = -(this || _global$d$1).words[0]; + (this || _global$d$1).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$d$1).length && (this || _global$d$1).words[i] < 0; i++) { + (this || _global$d$1).words[i] += 67108864; + (this || _global$d$1).words[i + 1] -= 1; + } + } + + return this.strip(); + }; + + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; + + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; + + BN.prototype.iabs = function iabs() { + (this || _global$d$1).negative = 0; + return this || _global$d$1; + }; + + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; + + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + + this._expand(len); + + var w; + var carry = 0; + + for (i = 0; i < num.length; i++) { + w = ((this || _global$d$1).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$d$1).words[i + shift] = w & 67108863; + } + + for (; i < (this || _global$d$1).length - shift; i++) { + w = ((this || _global$d$1).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$d$1).words[i + shift] = w & 67108863; + } + + if (carry === 0) return this.strip(); // Subtraction overflow + + assert(carry === -1); + carry = 0; + + for (i = 0; i < (this || _global$d$1).length; i++) { + w = -((this || _global$d$1).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$d$1).words[i] = w & 67108863; + } + + (this || _global$d$1).negative = 1; + return this.strip(); + }; + + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$d$1).length - num.length; + var a = this.clone(); + var b = num; // Normalize + + var bhi = b.words[b.length - 1] | 0; + + var bhiBits = this._countBits(bhi); + + shift = 26 - bhiBits; + + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient + + + var m = a.length - b.length; + var q; + + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); + + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } + + var diff = a.clone()._ishlnsubmul(b, 1, m); + + if (diff.negative === 0) { + a = diff; + + if (q) { + q.words[m] = 1; + } + } + + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) + + qj = Math.min(qj / bhi | 0, 67108863); + + a._ishlnsubmul(b, qj, j); + + while (a.negative !== 0) { + qj--; + a.negative = 0; + + a._ishlnsubmul(b, 1, j); + + if (!a.isZero()) { + a.negative ^= 1; + } + } + + if (q) { + q.words[j] = qj; + } + } + + if (q) { + q.strip(); + } + + a.strip(); // Denormalize + + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } + + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested + + + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); + + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } + + var div, mod, res; + + if ((this || _global$d$1).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } + + return { + div: div, + mod: mod + }; + } + + if ((this || _global$d$1).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + return { + div: div, + mod: res.mod + }; + } + + if (((this || _global$d$1).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } + + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value + + + if (num.length > (this || _global$d$1).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$d$1 + }; + } // Very short reduction + + + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } + + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } + + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } + + return this._wordDiv(num, mode); + }; // Find `this` / `num` + + + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` + + + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; + + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) + + + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division + + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down + + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; + + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + + for (var i = (this || _global$d$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$d$1).words[i] | 0)) % num; + } + + return acc; + }; // In-place division by number + + + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + + for (var i = (this || _global$d$1).length - 1; i >= 0; i--) { + var w = ((this || _global$d$1).words[i] | 0) + carry * 67108864; + (this || _global$d$1).words[i] = w / num | 0; + carry = w % num; + } + + return this.strip(); + }; + + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; + + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$d$1; + var y = p.clone(); + + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x + + + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y + + var C = new BN(0); + var D = new BN(1); + var g = 0; + + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } + + var yp = y.clone(); + var xp = x.clone(); + + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + x.iushrn(i); + + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + + A.iushrn(1); + B.iushrn(1); + } + } + + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + y.iushrn(j); + + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + + C.iushrn(1); + D.iushrn(1); + } + } + + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed + + + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$d$1; + var b = p.clone(); + + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } + + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); + + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + a.iushrn(i); + + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } + + x1.iushrn(1); + } + } + + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + b.iushrn(j); + + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } + + x2.iushrn(1); + } + } + + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + + var res; + + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + + if (res.cmpn(0) < 0) { + res.iadd(p); + } + + return res; + }; + + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two + + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + + do { + while (a.isEven()) { + a.iushrn(1); + } + + while (b.isEven()) { + b.iushrn(1); + } + + var r = a.cmp(b); + + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + + a.isub(b); + } while (true); + + return b.iushln(shift); + }; // Invert number in the field F(num) + + + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + + BN.prototype.isEven = function isEven() { + return ((this || _global$d$1).words[0] & 1) === 0; + }; + + BN.prototype.isOdd = function isOdd() { + return ((this || _global$d$1).words[0] & 1) === 1; + }; // And first word and num + + + BN.prototype.andln = function andln(num) { + return (this || _global$d$1).words[0] & num; + }; // Increment at the bit position in-line + + + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$d$1).length <= s) { + this._expand(s + 1); + + (this || _global$d$1).words[s] |= q; + return this || _global$d$1; + } // Add bit and propagate, if needed + + + var carry = q; + + for (var i = s; carry !== 0 && i < (this || _global$d$1).length; i++) { + var w = (this || _global$d$1).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$d$1).words[i] = w; + } + + if (carry !== 0) { + (this || _global$d$1).words[i] = carry; + (this || _global$d$1).length++; + } + + return this || _global$d$1; + }; + + BN.prototype.isZero = function isZero() { + return (this || _global$d$1).length === 1 && (this || _global$d$1).words[0] === 0; + }; + + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$d$1).negative !== 0 && !negative) return -1; + if ((this || _global$d$1).negative === 0 && negative) return 1; + this.strip(); + var res; + + if ((this || _global$d$1).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$d$1).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + + if ((this || _global$d$1).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + + + BN.prototype.cmp = function cmp(num) { + if ((this || _global$d$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$d$1).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$d$1).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison + + + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$d$1).length > num.length) return 1; + if ((this || _global$d$1).length < num.length) return -1; + var res = 0; + + for (var i = (this || _global$d$1).length - 1; i >= 0; i--) { + var a = (this || _global$d$1).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + + break; + } + + return res; + }; + + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + + + BN.red = function red(num) { + return new Red(num); + }; + + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$d$1).red, "Already a number in reduction context"); + assert((this || _global$d$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$d$1)._forceRed(ctx); + }; + + BN.prototype.fromRed = function fromRed() { + assert((this || _global$d$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$d$1).red.convertFrom(this || _global$d$1); + }; + + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$d$1).red = ctx; + return this || _global$d$1; + }; + + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$d$1).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$d$1).red, "redAdd works only with red numbers"); + return (this || _global$d$1).red.add(this || _global$d$1, num); + }; + + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$d$1).red, "redIAdd works only with red numbers"); + return (this || _global$d$1).red.iadd(this || _global$d$1, num); + }; + + BN.prototype.redSub = function redSub(num) { + assert((this || _global$d$1).red, "redSub works only with red numbers"); + return (this || _global$d$1).red.sub(this || _global$d$1, num); + }; + + BN.prototype.redISub = function redISub(num) { + assert((this || _global$d$1).red, "redISub works only with red numbers"); + return (this || _global$d$1).red.isub(this || _global$d$1, num); + }; + + BN.prototype.redShl = function redShl(num) { + assert((this || _global$d$1).red, "redShl works only with red numbers"); + return (this || _global$d$1).red.shl(this || _global$d$1, num); + }; + + BN.prototype.redMul = function redMul(num) { + assert((this || _global$d$1).red, "redMul works only with red numbers"); + + (this || _global$d$1).red._verify2(this || _global$d$1, num); + + return (this || _global$d$1).red.mul(this || _global$d$1, num); + }; + + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$d$1).red, "redMul works only with red numbers"); + + (this || _global$d$1).red._verify2(this || _global$d$1, num); + + return (this || _global$d$1).red.imul(this || _global$d$1, num); + }; + + BN.prototype.redSqr = function redSqr() { + assert((this || _global$d$1).red, "redSqr works only with red numbers"); + + (this || _global$d$1).red._verify1(this || _global$d$1); + + return (this || _global$d$1).red.sqr(this || _global$d$1); + }; + + BN.prototype.redISqr = function redISqr() { + assert((this || _global$d$1).red, "redISqr works only with red numbers"); + + (this || _global$d$1).red._verify1(this || _global$d$1); + + return (this || _global$d$1).red.isqr(this || _global$d$1); + }; // Square root over p + + + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$d$1).red, "redSqrt works only with red numbers"); + + (this || _global$d$1).red._verify1(this || _global$d$1); + + return (this || _global$d$1).red.sqrt(this || _global$d$1); + }; + + BN.prototype.redInvm = function redInvm() { + assert((this || _global$d$1).red, "redInvm works only with red numbers"); + + (this || _global$d$1).red._verify1(this || _global$d$1); + + return (this || _global$d$1).red.invm(this || _global$d$1); + }; // Return negative clone of `this` % `red modulo` + + + BN.prototype.redNeg = function redNeg() { + assert((this || _global$d$1).red, "redNeg works only with red numbers"); + + (this || _global$d$1).red._verify1(this || _global$d$1); + + return (this || _global$d$1).red.neg(this || _global$d$1); + }; + + BN.prototype.redPow = function redPow(num) { + assert((this || _global$d$1).red && !num.red, "redPow(normalNum)"); + + (this || _global$d$1).red._verify1(this || _global$d$1); + + return (this || _global$d$1).red.pow(this || _global$d$1, num); + }; // Prime numbers with efficient reduction + + + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime + + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$d$1).name = name; + (this || _global$d$1).p = new BN(p, 16); + (this || _global$d$1).n = (this || _global$d$1).p.bitLength(); + (this || _global$d$1).k = new BN(1).iushln((this || _global$d$1).n).isub((this || _global$d$1).p); + (this || _global$d$1).tmp = this._tmp(); + } + + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$d$1).n / 13)); + return tmp; + }; + + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + + do { + this.split(r, (this || _global$d$1).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$d$1).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$d$1).n); + + var cmp = rlen < (this || _global$d$1).n ? -1 : r.ucmp((this || _global$d$1).p); + + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$d$1).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + + return r; + }; + + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$d$1).n, 0, out); + }; + + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$d$1).k); + }; + + function K256() { + MPrime.call(this || _global$d$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + + inherits(K256, MPrime); + + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + + output.length = outLen; + + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs + + + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + + prev >>>= 22; + input.words[i - 10] = prev; + + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + + var lo = 0; + + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction + + + if (num.words[num.length - 1] === 0) { + num.length--; + + if (num.words[num.length - 1] === 0) { + num.length--; + } + } + + return num; + }; + + function P224() { + MPrime.call(this || _global$d$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } + + inherits(P224, MPrime); + + function P192() { + MPrime.call(this || _global$d$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } + + inherits(P192, MPrime); + + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$d$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } + + inherits(P25519, MPrime); + + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } + + if (carry !== 0) { + num.words[num.length++] = carry; + } + + return num; + }; // Exported mostly for testing purposes, use plain name instead + + + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // + + + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + + (this || _global$d$1).m = prime.p; + (this || _global$d$1).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$d$1).m = m; + (this || _global$d$1).prime = null; + } + } + + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; + + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; + + Red.prototype.imod = function imod(a) { + if ((this || _global$d$1).prime) return (this || _global$d$1).prime.ireduce(a)._forceRed(this || _global$d$1); + return a.umod((this || _global$d$1).m)._forceRed(this || _global$d$1); + }; + + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } + + return (this || _global$d$1).m.sub(a)._forceRed(this || _global$d$1); + }; + + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + + var res = a.add(b); + + if (res.cmp((this || _global$d$1).m) >= 0) { + res.isub((this || _global$d$1).m); + } + + return res._forceRed(this || _global$d$1); + }; + + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + + var res = a.iadd(b); + + if (res.cmp((this || _global$d$1).m) >= 0) { + res.isub((this || _global$d$1).m); + } + + return res; + }; + + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); + + var res = a.sub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$d$1).m); + } + + return res._forceRed(this || _global$d$1); + }; + + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); + + var res = a.isub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$d$1).m); + } + + return res; + }; + + Red.prototype.shl = function shl(a, num) { + this._verify1(a); + + return this.imod(a.ushln(num)); + }; + + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); + + return this.imod(a.imul(b)); + }; + + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); + + return this.imod(a.mul(b)); + }; + + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; + + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + + var mod3 = (this || _global$d$1).m.andln(3); + + assert(mod3 % 2 === 1); // Fast case + + if (mod3 === 3) { + var pow = (this || _global$d$1).m.add(new BN(1)).iushrn(2); + + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) + + + var q = (this || _global$d$1).m.subn(1); + + var s = 0; + + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$d$1); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + + var lpow = (this || _global$d$1).m.subn(1).iushrn(1); + + var z = (this || _global$d$1).m.bitLength(); + + z = new BN(2 * z * z).toRed(this || _global$d$1); + + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } + + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; + + while (t.cmp(one) !== 0) { + var tmp = t; + + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } + + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } + + return r; + }; + + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$d$1).m); + + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$d$1); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$d$1); + wnd[1] = a; + + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + + if (start === 0) { + start = 26; + } + + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + + if (res !== wnd[0]) { + res = this.sqr(res); + } + + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + + start = 26; + } + + return res; + }; + + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$d$1).m); + return r === num ? r.clone() : r; + }; + + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // + + + BN.mont = function mont(num) { + return new Mont(num); + }; + + function Mont(m) { + Red.call(this || _global$d$1, m); + (this || _global$d$1).shift = (this || _global$d$1).m.bitLength(); + + if ((this || _global$d$1).shift % 26 !== 0) { + (this || _global$d$1).shift += 26 - (this || _global$d$1).shift % 26; + } + + (this || _global$d$1).r = new BN(1).iushln((this || _global$d$1).shift); + (this || _global$d$1).r2 = this.imod((this || _global$d$1).r.sqr()); + (this || _global$d$1).rinv = (this || _global$d$1).r._invmp((this || _global$d$1).m); + (this || _global$d$1).minv = (this || _global$d$1).rinv.mul((this || _global$d$1).r).isubn(1).div((this || _global$d$1).m); + (this || _global$d$1).minv = (this || _global$d$1).minv.umod((this || _global$d$1).r); + (this || _global$d$1).minv = (this || _global$d$1).r.sub((this || _global$d$1).minv); + } + + inherits(Mont, Red); + + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$d$1).shift)); + }; + + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$d$1).rinv)); + r.red = null; + return r; + }; + + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + + var t = a.imul(b); + var c = t.maskn((this || _global$d$1).shift).mul((this || _global$d$1).minv).imaskn((this || _global$d$1).shift).mul((this || _global$d$1).m); + var u = t.isub(c).iushrn((this || _global$d$1).shift); + var res = u; + + if (u.cmp((this || _global$d$1).m) >= 0) { + res = u.isub((this || _global$d$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$d$1).m); + } + + return res._forceRed(this || _global$d$1); + }; + + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$d$1); + var t = a.mul(b); + var c = t.maskn((this || _global$d$1).shift).mul((this || _global$d$1).minv).imaskn((this || _global$d$1).shift).mul((this || _global$d$1).m); + var u = t.isub(c).iushrn((this || _global$d$1).shift); + var res = u; + + if (u.cmp((this || _global$d$1).m) >= 0) { + res = u.isub((this || _global$d$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$d$1).m); + } + + return res._forceRed(this || _global$d$1); + }; + + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$d$1).m).mul((this || _global$d$1).r2)); + return res._forceRed(this || _global$d$1); + }; + })(module$6, exports$13$1); + + return module$6.exports; +} + +var exports$12$1 = {}, + _dewExec$11$1 = false; +var module$5 = { + exports: exports$12$1 +}; + +var _global$c$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$11$1() { + if (_dewExec$11$1) return module$5.exports; + _dewExec$11$1 = true; + + (function (module, exports) { + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. + + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + + var TempCtor = function () {}; + + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN + + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } + + (this || _global$c$1).negative = 0; + (this || _global$c$1).words = null; + (this || _global$c$1).length = 0; // Reduction context + + (this || _global$c$1).red = null; + + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + + this._init(number || 0, base || 10, endian || "be"); + } + } + + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = e$1$1$1.Buffer; + } + } catch (e) {} + + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + + if (base === "hex") { + base = 16; + } + + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + + if (number[0] === "-") { + start++; + (this || _global$c$1).negative = 1; + } + + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } + }; + + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$c$1).negative = 1; + number = -number; + } + + if (number < 67108864) { + (this || _global$c$1).words = [number & 67108863]; + (this || _global$c$1).length = 1; + } else if (number < 4503599627370496) { + (this || _global$c$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$c$1).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + + (this || _global$c$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$c$1).length = 3; + } + + if (endian !== "le") return; // Reverse the bytes + + this._initArray(this.toArray(), base, endian); + }; + + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + + if (number.length <= 0) { + (this || _global$c$1).words = [0]; + (this || _global$c$1).length = 1; + return this || _global$c$1; + } + + (this || _global$c$1).length = Math.ceil(number.length / 3); + (this || _global$c$1).words = new Array((this || _global$c$1).length); + + for (var i = 0; i < (this || _global$c$1).length; i++) { + (this || _global$c$1).words[i] = 0; + } + + var j, w; + var off = 0; + + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$c$1).words[j] |= w << off & 67108863; + (this || _global$c$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$c$1).words[j] |= w << off & 67108863; + (this || _global$c$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } + + return this.strip(); + }; + + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // 'A' - 'F' + + if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; // '0' - '9' + } else { + return c - 48 & 15; + } + } + + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); + + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } + + return r; + } + + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$c$1).length = Math.ceil((number.length - start) / 6); + (this || _global$c$1).words = new Array((this || _global$c$1).length); + + for (var i = 0; i < (this || _global$c$1).length; i++) { + (this || _global$c$1).words[i] = 0; + } // 24-bits chunks + + + var off = 0; + var j = 0; + var w; + + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$c$1).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$c$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$c$1).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$c$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + + this.strip(); + }; + + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' + + if (c >= 49) { + r += c - 49 + 10; // 'A' + } else if (c >= 17) { + r += c - 17 + 10; // '0' - '9' + } else { + r += c; + } + } + + return r; + } + + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$c$1).words = [0]; + (this || _global$c$1).length = 1; // Find length of limb in base + + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + + if ((this || _global$c$1).words[0] + word < 67108864) { + (this || _global$c$1).words[0] += word; + } else { + this._iaddn(word); + } + } + + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + + for (i = 0; i < mod; i++) { + pow *= base; + } + + this.imuln(pow); + + if ((this || _global$c$1).words[0] + word < 67108864) { + (this || _global$c$1).words[0] += word; + } else { + this._iaddn(word); + } + } + + this.strip(); + }; + + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$c$1).length); + + for (var i = 0; i < (this || _global$c$1).length; i++) { + dest.words[i] = (this || _global$c$1).words[i]; + } + + dest.length = (this || _global$c$1).length; + dest.negative = (this || _global$c$1).negative; + dest.red = (this || _global$c$1).red; + }; + + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + + BN.prototype._expand = function _expand(size) { + while ((this || _global$c$1).length < size) { + (this || _global$c$1).words[(this || _global$c$1).length++] = 0; + } + + return this || _global$c$1; + }; // Remove leading `0` from `this` + + + BN.prototype.strip = function strip() { + while ((this || _global$c$1).length > 1 && (this || _global$c$1).words[(this || _global$c$1).length - 1] === 0) { + (this || _global$c$1).length--; + } + + return this._normSign(); + }; + + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$c$1).length === 1 && (this || _global$c$1).words[0] === 0) { + (this || _global$c$1).negative = 0; + } + + return this || _global$c$1; + }; + + BN.prototype.inspect = function inspect() { + return ((this || _global$c$1).red ? ""; + }; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ + + + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + + for (var i = 0; i < (this || _global$c$1).length; i++) { + var w = (this || _global$c$1).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + + if (carry !== 0 || i !== (this || _global$c$1).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + + off += 2; + + if (off >= 26) { + off -= 26; + i--; + } + } + + if (carry !== 0) { + out = carry.toString(16) + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$c$1).negative !== 0) { + out = "-" + out; + } + + return out; + } + + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); + + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + + if (this.isZero()) { + out = "0" + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$c$1).negative !== 0) { + out = "-" + out; + } + + return out; + } + + assert(false, "Base should be between 2 and 36"); + }; + + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$c$1).words[0]; + + if ((this || _global$c$1).length === 2) { + ret += (this || _global$c$1).words[1] * 67108864; + } else if ((this || _global$c$1).length === 3 && (this || _global$c$1).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$c$1).words[1] * 67108864; + } else if ((this || _global$c$1).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + + return (this || _global$c$1).negative !== 0 ? -ret : ret; + }; + + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; + + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; + + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } + } else { + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + + for (; i < reqLength; i++) { + res[i] = 0; + } + } + + return res; + }; + + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + + if (t >= 4096) { + r += 13; + t >>>= 13; + } + + if (t >= 64) { + r += 7; + t >>>= 7; + } + + if (t >= 8) { + r += 4; + t >>>= 4; + } + + if (t >= 2) { + r += 2; + t >>>= 2; + } + + return r + t; + }; + } + + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } + + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } + + if ((t & 1) === 0) { + r++; + } + + return r; + }; // Return number of used bits in a BN + + + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$c$1).words[(this || _global$c$1).length - 1]; + + var hi = this._countBits(w); + + return ((this || _global$c$1).length - 1) * 26 + hi; + }; + + function toBitArray(num) { + var w = new Array(num.bitLength()); + + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + + return w; + } // Number of trailing zero bits + + + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; + + for (var i = 0; i < (this || _global$c$1).length; i++) { + var b = this._zeroBits((this || _global$c$1).words[i]); + + r += b; + if (b !== 26) break; + } + + return r; + }; + + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; + + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$c$1).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + + return this.clone(); + }; + + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } + + return this.clone(); + }; + + BN.prototype.isNeg = function isNeg() { + return (this || _global$c$1).negative !== 0; + }; // Return negative clone of `this` + + + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; + + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$c$1).negative ^= 1; + } + + return this || _global$c$1; + }; // Or `num` with `this` in-place + + + BN.prototype.iuor = function iuor(num) { + while ((this || _global$c$1).length < num.length) { + (this || _global$c$1).words[(this || _global$c$1).length++] = 0; + } + + for (var i = 0; i < num.length; i++) { + (this || _global$c$1).words[i] = (this || _global$c$1).words[i] | num.words[i]; + } + + return this.strip(); + }; + + BN.prototype.ior = function ior(num) { + assert(((this || _global$c$1).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` + + + BN.prototype.or = function or(num) { + if ((this || _global$c$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$c$1); + }; + + BN.prototype.uor = function uor(num) { + if ((this || _global$c$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$c$1); + }; // And `num` with `this` in-place + + + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + + if ((this || _global$c$1).length > num.length) { + b = num; + } else { + b = this || _global$c$1; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$c$1).words[i] = (this || _global$c$1).words[i] & num.words[i]; + } + + (this || _global$c$1).length = b.length; + return this.strip(); + }; + + BN.prototype.iand = function iand(num) { + assert(((this || _global$c$1).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` + + + BN.prototype.and = function and(num) { + if ((this || _global$c$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$c$1); + }; + + BN.prototype.uand = function uand(num) { + if ((this || _global$c$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$c$1); + }; // Xor `num` with `this` in-place + + + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + + if ((this || _global$c$1).length > num.length) { + a = this || _global$c$1; + b = num; + } else { + a = num; + b = this || _global$c$1; + } + + for (var i = 0; i < b.length; i++) { + (this || _global$c$1).words[i] = a.words[i] ^ b.words[i]; + } + + if ((this || _global$c$1) !== a) { + for (; i < a.length; i++) { + (this || _global$c$1).words[i] = a.words[i]; + } + } + + (this || _global$c$1).length = a.length; + return this.strip(); + }; + + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$c$1).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` + + + BN.prototype.xor = function xor(num) { + if ((this || _global$c$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$c$1); + }; + + BN.prototype.uxor = function uxor(num) { + if ((this || _global$c$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$c$1); + }; // Not ``this`` with ``width`` bitwidth + + + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes + + this._expand(bytesNeeded); + + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words + + + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$c$1).words[i] = ~(this || _global$c$1).words[i] & 67108863; + } // Handle the residue + + + if (bitsLeft > 0) { + (this || _global$c$1).words[i] = ~(this || _global$c$1).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes + + + return this.strip(); + }; + + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` + + + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + + this._expand(off + 1); + + if (val) { + (this || _global$c$1).words[off] = (this || _global$c$1).words[off] | 1 << wbit; + } else { + (this || _global$c$1).words[off] = (this || _global$c$1).words[off] & ~(1 << wbit); + } + + return this.strip(); + }; // Add `num` to `this` in-place + + + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive + + if ((this || _global$c$1).negative !== 0 && num.negative === 0) { + (this || _global$c$1).negative = 0; + r = this.isub(num); + (this || _global$c$1).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$c$1).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length + + + var a, b; + + if ((this || _global$c$1).length > num.length) { + a = this || _global$c$1; + b = num; + } else { + a = num; + b = this || _global$c$1; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$c$1).words[i] = r & 67108863; + carry = r >>> 26; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$c$1).words[i] = r & 67108863; + carry = r >>> 26; + } + + (this || _global$c$1).length = a.length; + + if (carry !== 0) { + (this || _global$c$1).words[(this || _global$c$1).length] = carry; + (this || _global$c$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$c$1)) { + for (; i < a.length; i++) { + (this || _global$c$1).words[i] = a.words[i]; + } + } + + return this || _global$c$1; + }; // Add `num` to `this` + + + BN.prototype.add = function add(num) { + var res; + + if (num.negative !== 0 && (this || _global$c$1).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$c$1).negative !== 0) { + (this || _global$c$1).negative = 0; + res = num.sub(this || _global$c$1); + (this || _global$c$1).negative = 1; + return res; + } + + if ((this || _global$c$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$c$1); + }; // Subtract `num` from `this` in-place + + + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$c$1).negative !== 0) { + (this || _global$c$1).negative = 0; + this.iadd(num); + (this || _global$c$1).negative = 1; + return this._normSign(); + } // At this point both numbers are positive + + + var cmp = this.cmp(num); // Optimization - zeroify + + if (cmp === 0) { + (this || _global$c$1).negative = 0; + (this || _global$c$1).length = 1; + (this || _global$c$1).words[0] = 0; + return this || _global$c$1; + } // a > b + + + var a, b; + + if (cmp > 0) { + a = this || _global$c$1; + b = num; + } else { + a = num; + b = this || _global$c$1; + } + + var carry = 0; + + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$c$1).words[i] = r & 67108863; + } + + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$c$1).words[i] = r & 67108863; + } // Copy rest of the words + + + if (carry === 0 && i < a.length && a !== (this || _global$c$1)) { + for (; i < a.length; i++) { + (this || _global$c$1).words[i] = a.words[i]; + } + } + + (this || _global$c$1).length = Math.max((this || _global$c$1).length, i); + + if (a !== (this || _global$c$1)) { + (this || _global$c$1).negative = 1; + } + + return this.strip(); + }; // Subtract `num` from `this` + + + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; + + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; + + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } + + out.words[k] = rword | 0; + carry = ncarry | 0; + } + + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } + + return out.strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). + + + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ + + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ + + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ + + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ + + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ + + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ + + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ + + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ + + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ + + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ + + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ + + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ + + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ + + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ + + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ + + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + + if (c !== 0) { + o[19] = c; + out.length++; + } + + return out; + }; // Polyfill comb + + + if (!Math.imul) { + comb10MulTo = smallMulTo; + } + + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; + + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } + + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } + + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } + + return out.strip(); + } + + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } + + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$c$1).length + num.length; + + if ((this || _global$c$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$c$1, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$c$1, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$c$1, num, out); + } else { + res = jumboMulTo(this || _global$c$1, num, out); + } + + return res; + }; // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion + + + function FFTM(x, y) { + (this || _global$c$1).x = x; + (this || _global$c$1).y = y; + } + + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; + + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } + + return t; + }; // Returns binary-reversed representation of `x` + + + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } + + return rb; + }; // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm + + + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; + + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); + + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); + + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; + + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + /* jshint maxdepth : false */ + + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } + } + }; + + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; + + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } + + return 1 << i + 1 + odd; + }; + + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; + + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; + } + }; + + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; + + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; + + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } + + return ws; + }; + + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; + + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } // Pad with zeroes + + + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } + + assert(carry === 0); + assert((carry & ~8191) === 0); + }; + + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); + + for (var i = 0; i < N; i++) { + ph[i] = 0; + } + + return ph; + }; + + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); + + var _ = this.stub(N); + + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); + + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } + + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; // Multiply `this` by `num` + + + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$c$1).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT + + + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$c$1).length + num.length); + return jumboMulTo(this || _global$c$1, num, out); + }; // In-place Multiplication + + + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$c$1); + }; + + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); // Carry + + var carry = 0; + + for (var i = 0; i < (this || _global$c$1).length; i++) { + var w = ((this || _global$c$1).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum + + carry += lo >>> 26; + (this || _global$c$1).words[i] = lo & 67108863; + } + + if (carry !== 0) { + (this || _global$c$1).words[i] = carry; + (this || _global$c$1).length++; + } + + return this || _global$c$1; + }; + + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` + + + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$c$1); + }; // `this` * `this` in-place + + + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) + + + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes + + var res = this || _global$c$1; + + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } + + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } + + return res; + }; // Shift-left in-place + + + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; + + if (r !== 0) { + var carry = 0; + + for (i = 0; i < (this || _global$c$1).length; i++) { + var newCarry = (this || _global$c$1).words[i] & carryMask; + var c = ((this || _global$c$1).words[i] | 0) - newCarry << r; + (this || _global$c$1).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } + + if (carry) { + (this || _global$c$1).words[i] = carry; + (this || _global$c$1).length++; + } + } + + if (s !== 0) { + for (i = (this || _global$c$1).length - 1; i >= 0; i--) { + (this || _global$c$1).words[i + s] = (this || _global$c$1).words[i]; + } + + for (i = 0; i < s; i++) { + (this || _global$c$1).words[i] = 0; + } + + (this || _global$c$1).length += s; + } + + return this.strip(); + }; + + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$c$1).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits + + + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; + + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } + + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$c$1).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part + + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$c$1).words[i]; + } + + maskedWords.length = s; + } + + if (s === 0) ; else if ((this || _global$c$1).length > s) { + (this || _global$c$1).length -= s; + + for (i = 0; i < (this || _global$c$1).length; i++) { + (this || _global$c$1).words[i] = (this || _global$c$1).words[i + s]; + } + } else { + (this || _global$c$1).words[0] = 0; + (this || _global$c$1).length = 1; + } + + var carry = 0; + + for (i = (this || _global$c$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$c$1).words[i] | 0; + (this || _global$c$1).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask + + + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } + + if ((this || _global$c$1).length === 0) { + (this || _global$c$1).words[0] = 0; + (this || _global$c$1).length = 1; + } + + return this.strip(); + }; + + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$c$1).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left + + + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; + + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right + + + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; + + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set + + + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$c$1).length <= s) return false; // Check bit and return + + var w = (this || _global$c$1).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) + + + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$c$1).negative === 0, "imaskn works only with positive numbers"); + + if ((this || _global$c$1).length <= s) { + return this || _global$c$1; + } + + if (r !== 0) { + s++; + } + + (this || _global$c$1).length = Math.min(s, (this || _global$c$1).length); + + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$c$1).words[(this || _global$c$1).length - 1] &= mask; + } + + return this.strip(); + }; // Return only lowers bits of number + + + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` + + + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change + + if ((this || _global$c$1).negative !== 0) { + if ((this || _global$c$1).length === 1 && ((this || _global$c$1).words[0] | 0) < num) { + (this || _global$c$1).words[0] = num - ((this || _global$c$1).words[0] | 0); + (this || _global$c$1).negative = 0; + return this || _global$c$1; + } + + (this || _global$c$1).negative = 0; + this.isubn(num); + (this || _global$c$1).negative = 1; + return this || _global$c$1; + } // Add without checks + + + return this._iaddn(num); + }; + + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$c$1).words[0] += num; // Carry + + for (var i = 0; i < (this || _global$c$1).length && (this || _global$c$1).words[i] >= 67108864; i++) { + (this || _global$c$1).words[i] -= 67108864; + + if (i === (this || _global$c$1).length - 1) { + (this || _global$c$1).words[i + 1] = 1; + } else { + (this || _global$c$1).words[i + 1]++; + } + } + + (this || _global$c$1).length = Math.max((this || _global$c$1).length, i + 1); + return this || _global$c$1; + }; // Subtract plain number `num` from `this` + + + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); + + if ((this || _global$c$1).negative !== 0) { + (this || _global$c$1).negative = 0; + this.iaddn(num); + (this || _global$c$1).negative = 1; + return this || _global$c$1; + } + + (this || _global$c$1).words[0] -= num; + + if ((this || _global$c$1).length === 1 && (this || _global$c$1).words[0] < 0) { + (this || _global$c$1).words[0] = -(this || _global$c$1).words[0]; + (this || _global$c$1).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$c$1).length && (this || _global$c$1).words[i] < 0; i++) { + (this || _global$c$1).words[i] += 67108864; + (this || _global$c$1).words[i + 1] -= 1; + } + } + + return this.strip(); + }; + + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; + + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; + + BN.prototype.iabs = function iabs() { + (this || _global$c$1).negative = 0; + return this || _global$c$1; + }; + + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; + + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + + this._expand(len); + + var w; + var carry = 0; + + for (i = 0; i < num.length; i++) { + w = ((this || _global$c$1).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$c$1).words[i + shift] = w & 67108863; + } + + for (; i < (this || _global$c$1).length - shift; i++) { + w = ((this || _global$c$1).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$c$1).words[i + shift] = w & 67108863; + } + + if (carry === 0) return this.strip(); // Subtraction overflow + + assert(carry === -1); + carry = 0; + + for (i = 0; i < (this || _global$c$1).length; i++) { + w = -((this || _global$c$1).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$c$1).words[i] = w & 67108863; + } + + (this || _global$c$1).negative = 1; + return this.strip(); + }; + + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$c$1).length - num.length; + var a = this.clone(); + var b = num; // Normalize + + var bhi = b.words[b.length - 1] | 0; + + var bhiBits = this._countBits(bhi); + + shift = 26 - bhiBits; + + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient + + + var m = a.length - b.length; + var q; + + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); + + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } + + var diff = a.clone()._ishlnsubmul(b, 1, m); + + if (diff.negative === 0) { + a = diff; + + if (q) { + q.words[m] = 1; + } + } + + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) + + qj = Math.min(qj / bhi | 0, 67108863); + + a._ishlnsubmul(b, qj, j); + + while (a.negative !== 0) { + qj--; + a.negative = 0; + + a._ishlnsubmul(b, 1, j); + + if (!a.isZero()) { + a.negative ^= 1; + } + } + + if (q) { + q.words[j] = qj; + } + } + + if (q) { + q.strip(); + } + + a.strip(); // Denormalize + + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } + + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested + + + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); + + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } + + var div, mod, res; + + if ((this || _global$c$1).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } + + return { + div: div, + mod: mod + }; + } + + if ((this || _global$c$1).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); + + if (mode !== "mod") { + div = res.div.neg(); + } + + return { + div: div, + mod: res.mod + }; + } + + if (((this || _global$c$1).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); + + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } + + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value + + + if (num.length > (this || _global$c$1).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$c$1 + }; + } // Very short reduction + + + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } + + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } + + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } + + return this._wordDiv(num, mode); + }; // Find `this` / `num` + + + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` + + + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; + + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) + + + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division + + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down + + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; + + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + + for (var i = (this || _global$c$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$c$1).words[i] | 0)) % num; + } + + return acc; + }; // In-place division by number + + + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + + for (var i = (this || _global$c$1).length - 1; i >= 0; i--) { + var w = ((this || _global$c$1).words[i] | 0) + carry * 67108864; + (this || _global$c$1).words[i] = w / num | 0; + carry = w % num; + } + + return this.strip(); + }; + + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; + + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$c$1; + var y = p.clone(); + + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x + + + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y + + var C = new BN(0); + var D = new BN(1); + var g = 0; + + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } + + var yp = y.clone(); + var xp = x.clone(); + + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + x.iushrn(i); + + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + + A.iushrn(1); + B.iushrn(1); + } + } + + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + y.iushrn(j); + + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + + C.iushrn(1); + D.iushrn(1); + } + } + + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed + + + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$c$1; + var b = p.clone(); + + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } + + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); + + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + + if (i > 0) { + a.iushrn(i); + + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } + + x1.iushrn(1); + } + } + + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + b.iushrn(j); + + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } + + x2.iushrn(1); + } + } + + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + + var res; + + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + + if (res.cmpn(0) < 0) { + res.iadd(p); + } + + return res; + }; + + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two + + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + + do { + while (a.isEven()) { + a.iushrn(1); + } + + while (b.isEven()) { + b.iushrn(1); + } + + var r = a.cmp(b); + + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + + a.isub(b); + } while (true); + + return b.iushln(shift); + }; // Invert number in the field F(num) + + + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + + BN.prototype.isEven = function isEven() { + return ((this || _global$c$1).words[0] & 1) === 0; + }; + + BN.prototype.isOdd = function isOdd() { + return ((this || _global$c$1).words[0] & 1) === 1; + }; // And first word and num + + + BN.prototype.andln = function andln(num) { + return (this || _global$c$1).words[0] & num; + }; // Increment at the bit position in-line + + + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$c$1).length <= s) { + this._expand(s + 1); + + (this || _global$c$1).words[s] |= q; + return this || _global$c$1; + } // Add bit and propagate, if needed + + + var carry = q; + + for (var i = s; carry !== 0 && i < (this || _global$c$1).length; i++) { + var w = (this || _global$c$1).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$c$1).words[i] = w; + } + + if (carry !== 0) { + (this || _global$c$1).words[i] = carry; + (this || _global$c$1).length++; + } + + return this || _global$c$1; + }; + + BN.prototype.isZero = function isZero() { + return (this || _global$c$1).length === 1 && (this || _global$c$1).words[0] === 0; + }; + + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$c$1).negative !== 0 && !negative) return -1; + if ((this || _global$c$1).negative === 0 && negative) return 1; + this.strip(); + var res; + + if ((this || _global$c$1).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$c$1).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + + if ((this || _global$c$1).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + + + BN.prototype.cmp = function cmp(num) { + if ((this || _global$c$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$c$1).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$c$1).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison + + + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$c$1).length > num.length) return 1; + if ((this || _global$c$1).length < num.length) return -1; + var res = 0; + + for (var i = (this || _global$c$1).length - 1; i >= 0; i--) { + var a = (this || _global$c$1).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + + break; + } + + return res; + }; + + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + + + BN.red = function red(num) { + return new Red(num); + }; + + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$c$1).red, "Already a number in reduction context"); + assert((this || _global$c$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$c$1)._forceRed(ctx); + }; + + BN.prototype.fromRed = function fromRed() { + assert((this || _global$c$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$c$1).red.convertFrom(this || _global$c$1); + }; + + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$c$1).red = ctx; + return this || _global$c$1; + }; + + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$c$1).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$c$1).red, "redAdd works only with red numbers"); + return (this || _global$c$1).red.add(this || _global$c$1, num); + }; + + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$c$1).red, "redIAdd works only with red numbers"); + return (this || _global$c$1).red.iadd(this || _global$c$1, num); + }; + + BN.prototype.redSub = function redSub(num) { + assert((this || _global$c$1).red, "redSub works only with red numbers"); + return (this || _global$c$1).red.sub(this || _global$c$1, num); + }; + + BN.prototype.redISub = function redISub(num) { + assert((this || _global$c$1).red, "redISub works only with red numbers"); + return (this || _global$c$1).red.isub(this || _global$c$1, num); + }; + + BN.prototype.redShl = function redShl(num) { + assert((this || _global$c$1).red, "redShl works only with red numbers"); + return (this || _global$c$1).red.shl(this || _global$c$1, num); + }; + + BN.prototype.redMul = function redMul(num) { + assert((this || _global$c$1).red, "redMul works only with red numbers"); + + (this || _global$c$1).red._verify2(this || _global$c$1, num); + + return (this || _global$c$1).red.mul(this || _global$c$1, num); + }; + + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$c$1).red, "redMul works only with red numbers"); + + (this || _global$c$1).red._verify2(this || _global$c$1, num); + + return (this || _global$c$1).red.imul(this || _global$c$1, num); + }; + + BN.prototype.redSqr = function redSqr() { + assert((this || _global$c$1).red, "redSqr works only with red numbers"); + + (this || _global$c$1).red._verify1(this || _global$c$1); + + return (this || _global$c$1).red.sqr(this || _global$c$1); + }; + + BN.prototype.redISqr = function redISqr() { + assert((this || _global$c$1).red, "redISqr works only with red numbers"); + + (this || _global$c$1).red._verify1(this || _global$c$1); + + return (this || _global$c$1).red.isqr(this || _global$c$1); + }; // Square root over p + + + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$c$1).red, "redSqrt works only with red numbers"); + + (this || _global$c$1).red._verify1(this || _global$c$1); + + return (this || _global$c$1).red.sqrt(this || _global$c$1); + }; + + BN.prototype.redInvm = function redInvm() { + assert((this || _global$c$1).red, "redInvm works only with red numbers"); + + (this || _global$c$1).red._verify1(this || _global$c$1); + + return (this || _global$c$1).red.invm(this || _global$c$1); + }; // Return negative clone of `this` % `red modulo` + + + BN.prototype.redNeg = function redNeg() { + assert((this || _global$c$1).red, "redNeg works only with red numbers"); + + (this || _global$c$1).red._verify1(this || _global$c$1); + + return (this || _global$c$1).red.neg(this || _global$c$1); + }; + + BN.prototype.redPow = function redPow(num) { + assert((this || _global$c$1).red && !num.red, "redPow(normalNum)"); + + (this || _global$c$1).red._verify1(this || _global$c$1); + + return (this || _global$c$1).red.pow(this || _global$c$1, num); + }; // Prime numbers with efficient reduction + + + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime + + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$c$1).name = name; + (this || _global$c$1).p = new BN(p, 16); + (this || _global$c$1).n = (this || _global$c$1).p.bitLength(); + (this || _global$c$1).k = new BN(1).iushln((this || _global$c$1).n).isub((this || _global$c$1).p); + (this || _global$c$1).tmp = this._tmp(); + } + + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$c$1).n / 13)); + return tmp; + }; + + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + + do { + this.split(r, (this || _global$c$1).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$c$1).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$c$1).n); + + var cmp = rlen < (this || _global$c$1).n ? -1 : r.ucmp((this || _global$c$1).p); + + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$c$1).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + + return r; + }; + + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$c$1).n, 0, out); + }; + + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$c$1).k); + }; + + function K256() { + MPrime.call(this || _global$c$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + + inherits(K256, MPrime); + + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + + output.length = outLen; + + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs + + + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + + prev >>>= 22; + input.words[i - 10] = prev; + + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + + var lo = 0; + + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction + + + if (num.words[num.length - 1] === 0) { + num.length--; + + if (num.words[num.length - 1] === 0) { + num.length--; + } + } + + return num; + }; + + function P224() { + MPrime.call(this || _global$c$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } + + inherits(P224, MPrime); + + function P192() { + MPrime.call(this || _global$c$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } + + inherits(P192, MPrime); + + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$c$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } + + inherits(P25519, MPrime); + + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } + + if (carry !== 0) { + num.words[num.length++] = carry; + } + + return num; + }; // Exported mostly for testing purposes, use plain name instead + + + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // + + + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + + (this || _global$c$1).m = prime.p; + (this || _global$c$1).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$c$1).m = m; + (this || _global$c$1).prime = null; + } + } + + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; + + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; + + Red.prototype.imod = function imod(a) { + if ((this || _global$c$1).prime) return (this || _global$c$1).prime.ireduce(a)._forceRed(this || _global$c$1); + return a.umod((this || _global$c$1).m)._forceRed(this || _global$c$1); + }; + + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } + + return (this || _global$c$1).m.sub(a)._forceRed(this || _global$c$1); + }; + + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + + var res = a.add(b); + + if (res.cmp((this || _global$c$1).m) >= 0) { + res.isub((this || _global$c$1).m); + } + + return res._forceRed(this || _global$c$1); + }; + + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + + var res = a.iadd(b); + + if (res.cmp((this || _global$c$1).m) >= 0) { + res.isub((this || _global$c$1).m); + } + + return res; + }; + + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); + + var res = a.sub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$c$1).m); + } + + return res._forceRed(this || _global$c$1); + }; + + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); + + var res = a.isub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$c$1).m); + } + + return res; + }; + + Red.prototype.shl = function shl(a, num) { + this._verify1(a); + + return this.imod(a.ushln(num)); + }; + + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); + + return this.imod(a.imul(b)); + }; + + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); + + return this.imod(a.mul(b)); + }; + + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; + + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + + var mod3 = (this || _global$c$1).m.andln(3); + + assert(mod3 % 2 === 1); // Fast case + + if (mod3 === 3) { + var pow = (this || _global$c$1).m.add(new BN(1)).iushrn(2); + + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) + + + var q = (this || _global$c$1).m.subn(1); + + var s = 0; + + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$c$1); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + + var lpow = (this || _global$c$1).m.subn(1).iushrn(1); + + var z = (this || _global$c$1).m.bitLength(); + + z = new BN(2 * z * z).toRed(this || _global$c$1); + + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } + + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; + + while (t.cmp(one) !== 0) { + var tmp = t; + + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } + + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } + + return r; + }; + + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$c$1).m); + + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$c$1); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$c$1); + wnd[1] = a; + + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + + if (start === 0) { + start = 26; + } + + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + + if (res !== wnd[0]) { + res = this.sqr(res); + } + + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + + start = 26; + } + + return res; + }; + + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$c$1).m); + return r === num ? r.clone() : r; + }; + + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // + + + BN.mont = function mont(num) { + return new Mont(num); + }; + + function Mont(m) { + Red.call(this || _global$c$1, m); + (this || _global$c$1).shift = (this || _global$c$1).m.bitLength(); + + if ((this || _global$c$1).shift % 26 !== 0) { + (this || _global$c$1).shift += 26 - (this || _global$c$1).shift % 26; + } + + (this || _global$c$1).r = new BN(1).iushln((this || _global$c$1).shift); + (this || _global$c$1).r2 = this.imod((this || _global$c$1).r.sqr()); + (this || _global$c$1).rinv = (this || _global$c$1).r._invmp((this || _global$c$1).m); + (this || _global$c$1).minv = (this || _global$c$1).rinv.mul((this || _global$c$1).r).isubn(1).div((this || _global$c$1).m); + (this || _global$c$1).minv = (this || _global$c$1).minv.umod((this || _global$c$1).r); + (this || _global$c$1).minv = (this || _global$c$1).r.sub((this || _global$c$1).minv); + } + + inherits(Mont, Red); + + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$c$1).shift)); + }; + + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$c$1).rinv)); + r.red = null; + return r; + }; + + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + + var t = a.imul(b); + var c = t.maskn((this || _global$c$1).shift).mul((this || _global$c$1).minv).imaskn((this || _global$c$1).shift).mul((this || _global$c$1).m); + var u = t.isub(c).iushrn((this || _global$c$1).shift); + var res = u; + + if (u.cmp((this || _global$c$1).m) >= 0) { + res = u.isub((this || _global$c$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$c$1).m); + } + + return res._forceRed(this || _global$c$1); + }; + + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$c$1); + var t = a.mul(b); + var c = t.maskn((this || _global$c$1).shift).mul((this || _global$c$1).minv).imaskn((this || _global$c$1).shift).mul((this || _global$c$1).m); + var u = t.isub(c).iushrn((this || _global$c$1).shift); + var res = u; + + if (u.cmp((this || _global$c$1).m) >= 0) { + res = u.isub((this || _global$c$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$c$1).m); + } + + return res._forceRed(this || _global$c$1); + }; + + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$c$1).m).mul((this || _global$c$1).r2)); + return res._forceRed(this || _global$c$1); + }; + })(module$5, exports$12$1); + + return module$5.exports; +} + +var _global$b$1="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,exports$11$1={},indexOf=function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;n4294967295)throw new RangeError("requested too many random bytes");var o=t.allocUnsafe(e);if(e>0)if(e>65536)for(var a=0;a=this._blockSize;){for(var s=this._blockOffset;s0;++f)this._length[f]+=n,(n=this._length[f]/4294967296|0)>0&&(this._length[f]-=4294967296*n);return this},s.prototype._update=function(){throw new Error("_update is not implemented")},s.prototype.digest=function(t){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var i=this._digest();void 0!==t&&(i=i.toString(t)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return i},s.prototype._digest=function(){throw new Error("_digest is not implemented")};var f$1=s;var h=t$2$2,r=f$1,_=u$q.Buffer,e$1=new Array(16);function n$1(){r.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878;}function o$2(t,i){return t<>>32-i}function f$2(t,i,s,h,r,_,e){return o$2(t+(i&s|~i&h)+r+_|0,e)+i|0}function c(t,i,s,h,r,_,e){return o$2(t+(i&h|s&~h)+r+_|0,e)+i|0}function a$1(t,i,s,h,r,_,e){return o$2(t+(i^s^h)+r+_|0,e)+i|0}function l(t,i,s,h,r,_,e){return o$2(t+(s^(i|~h))+r+_|0,e)+i|0}h(n$1,r),n$1.prototype._update=function(){for(var t=e$1,i=0;i<16;++i)t[i]=this._block.readInt32LE(4*i);var s=this._a,h=this._b,r=this._c,_=this._d;s=f$2(s,h,r,_,t[0],3614090360,7),_=f$2(_,s,h,r,t[1],3905402710,12),r=f$2(r,_,s,h,t[2],606105819,17),h=f$2(h,r,_,s,t[3],3250441966,22),s=f$2(s,h,r,_,t[4],4118548399,7),_=f$2(_,s,h,r,t[5],1200080426,12),r=f$2(r,_,s,h,t[6],2821735955,17),h=f$2(h,r,_,s,t[7],4249261313,22),s=f$2(s,h,r,_,t[8],1770035416,7),_=f$2(_,s,h,r,t[9],2336552879,12),r=f$2(r,_,s,h,t[10],4294925233,17),h=f$2(h,r,_,s,t[11],2304563134,22),s=f$2(s,h,r,_,t[12],1804603682,7),_=f$2(_,s,h,r,t[13],4254626195,12),r=f$2(r,_,s,h,t[14],2792965006,17),s=c(s,h=f$2(h,r,_,s,t[15],1236535329,22),r,_,t[1],4129170786,5),_=c(_,s,h,r,t[6],3225465664,9),r=c(r,_,s,h,t[11],643717713,14),h=c(h,r,_,s,t[0],3921069994,20),s=c(s,h,r,_,t[5],3593408605,5),_=c(_,s,h,r,t[10],38016083,9),r=c(r,_,s,h,t[15],3634488961,14),h=c(h,r,_,s,t[4],3889429448,20),s=c(s,h,r,_,t[9],568446438,5),_=c(_,s,h,r,t[14],3275163606,9),r=c(r,_,s,h,t[3],4107603335,14),h=c(h,r,_,s,t[8],1163531501,20),s=c(s,h,r,_,t[13],2850285829,5),_=c(_,s,h,r,t[2],4243563512,9),r=c(r,_,s,h,t[7],1735328473,14),s=a$1(s,h=c(h,r,_,s,t[12],2368359562,20),r,_,t[5],4294588738,4),_=a$1(_,s,h,r,t[8],2272392833,11),r=a$1(r,_,s,h,t[11],1839030562,16),h=a$1(h,r,_,s,t[14],4259657740,23),s=a$1(s,h,r,_,t[1],2763975236,4),_=a$1(_,s,h,r,t[4],1272893353,11),r=a$1(r,_,s,h,t[7],4139469664,16),h=a$1(h,r,_,s,t[10],3200236656,23),s=a$1(s,h,r,_,t[13],681279174,4),_=a$1(_,s,h,r,t[0],3936430074,11),r=a$1(r,_,s,h,t[3],3572445317,16),h=a$1(h,r,_,s,t[6],76029189,23),s=a$1(s,h,r,_,t[9],3654602809,4),_=a$1(_,s,h,r,t[12],3873151461,11),r=a$1(r,_,s,h,t[15],530742520,16),s=l(s,h=a$1(h,r,_,s,t[2],3299628645,23),r,_,t[0],4096336452,6),_=l(_,s,h,r,t[7],1126891415,10),r=l(r,_,s,h,t[14],2878612391,15),h=l(h,r,_,s,t[5],4237533241,21),s=l(s,h,r,_,t[12],1700485571,6),_=l(_,s,h,r,t[3],2399980690,10),r=l(r,_,s,h,t[10],4293915773,15),h=l(h,r,_,s,t[1],2240044497,21),s=l(s,h,r,_,t[8],1873313359,6),_=l(_,s,h,r,t[15],4264355552,10),r=l(r,_,s,h,t[6],2734768916,15),h=l(h,r,_,s,t[13],1309151649,21),s=l(s,h,r,_,t[4],4149444226,6),_=l(_,s,h,r,t[11],3174756917,10),r=l(r,_,s,h,t[2],718787259,15),h=l(h,r,_,s,t[9],3951481745,21),this._a=this._a+s|0,this._b=this._b+h|0,this._c=this._c+r|0,this._d=this._d+_|0;},n$1.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var t=_.allocUnsafe(16);return t.writeInt32LE(this._a,0),t.writeInt32LE(this._b,4),t.writeInt32LE(this._c,8),t.writeInt32LE(this._d,12),t};var u=n$1;var h$1=e$1$1$1.Buffer,_$1=t$2$2,r$1=f$1,e$2=new Array(16),n$2=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],o$3=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],f$3=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],c$1=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],a$2=[0,1518500249,1859775393,2400959708,2840853838],l$1=[1352829926,1548603684,1836072691,2053994217,0];function u$1(){r$1.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520;}function b(t,i){return t<>>32-i}function d(t,i,s,h,_,r,e,n){return b(t+(i^s^h)+r+e|0,n)+_|0}function k(t,i,s,h,_,r,e,n){return b(t+(i&s|~i&h)+r+e|0,n)+_|0}function p(t,i,s,h,_,r,e,n){return b(t+((i|~s)^h)+r+e|0,n)+_|0}function w(t,i,s,h,_,r,e,n){return b(t+(i&h|s&~h)+r+e|0,n)+_|0}function E(t,i,s,h,_,r,e,n){return b(t+(i^(s|~h))+r+e|0,n)+_|0}_$1(u$1,r$1),u$1.prototype._update=function(){for(var t=e$2,i=0;i<16;++i)t[i]=this._block.readInt32LE(4*i);for(var s=0|this._a,h=0|this._b,_=0|this._c,r=0|this._d,u=0|this._e,I=0|this._a,L=0|this._b,v=0|this._c,m=0|this._d,O=0|this._e,g=0;g<80;g+=1){var y,U;g<16?(y=d(s,h,_,r,u,t[n$2[g]],a$2[0],f$3[g]),U=E(I,L,v,m,O,t[o$3[g]],l$1[0],c$1[g])):g<32?(y=k(s,h,_,r,u,t[n$2[g]],a$2[1],f$3[g]),U=w(I,L,v,m,O,t[o$3[g]],l$1[1],c$1[g])):g<48?(y=p(s,h,_,r,u,t[n$2[g]],a$2[2],f$3[g]),U=p(I,L,v,m,O,t[o$3[g]],l$1[2],c$1[g])):g<64?(y=w(s,h,_,r,u,t[n$2[g]],a$2[3],f$3[g]),U=k(I,L,v,m,O,t[o$3[g]],l$1[3],c$1[g])):(y=E(s,h,_,r,u,t[n$2[g]],a$2[4],f$3[g]),U=d(I,L,v,m,O,t[o$3[g]],l$1[4],c$1[g])),s=u,u=r,r=b(_,10),_=h,h=y,I=O,O=m,m=b(v,10),v=L,L=U;}var x=this._b+_+m|0;this._b=this._c+r+O|0,this._c=this._d+u+I|0,this._d=this._e+s+L|0,this._e=this._a+h+v|0,this._a=x;},u$1.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var t=h$1.alloc?h$1.alloc(20):new h$1(20);return t.writeInt32LE(this._a,0),t.writeInt32LE(this._b,4),t.writeInt32LE(this._c,8),t.writeInt32LE(this._d,12),t.writeInt32LE(this._e,16),t};var I=u$1;var s$1="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,h$2=u$q.Buffer;function e$3(t,i){(this||s$1)._block=h$2.alloc(t),(this||s$1)._finalSize=i,(this||s$1)._blockSize=t,(this||s$1)._len=0;}e$3.prototype.update=function(t,i){"string"==typeof t&&(i=i||"utf8",t=h$2.from(t,i));for(var e=(this||s$1)._block,_=(this||s$1)._blockSize,n=t.length,r=(this||s$1)._len,o=0;o=(this||s$1)._finalSize&&(this._update((this||s$1)._block),(this||s$1)._block.fill(0));var h=8*(this||s$1)._len;if(h<=4294967295)(this||s$1)._block.writeUInt32BE(h,(this||s$1)._blockSize-4);else {var e=(4294967295&h)>>>0,_=(h-e)/4294967296;(this||s$1)._block.writeUInt32BE(_,(this||s$1)._blockSize-8),(this||s$1)._block.writeUInt32BE(e,(this||s$1)._blockSize-4);}this._update((this||s$1)._block);var n=this._hash();return t?n.toString(t):n},e$3.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var _$2=e$3,n$3="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,r$2=t$2$2,o$4=_$2,f$4=u$q.Buffer,l$2=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],a$3=new Array(64);function u$2(){this.init(),(this||n$3)._w=a$3,o$4.call(this||n$3,64,56);}function c$2(t,i,s){return s^t&(i^s)}function b$1(t,i,s){return t&i|s&(t|i)}function p$1(t){return (t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10)}function d$1(t){return (t>>>6|t<<26)^(t>>>11|t<<21)^(t>>>25|t<<7)}function k$1(t){return (t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3}r$2(u$2,o$4),u$2.prototype.init=function(){return (this||n$3)._a=1779033703,(this||n$3)._b=3144134277,(this||n$3)._c=1013904242,(this||n$3)._d=2773480762,(this||n$3)._e=1359893119,(this||n$3)._f=2600822924,(this||n$3)._g=528734635,(this||n$3)._h=1541459225,this||n$3},u$2.prototype._update=function(t){for(var i,s=(this||n$3)._w,h=0|(this||n$3)._a,e=0|(this||n$3)._b,_=0|(this||n$3)._c,r=0|(this||n$3)._d,o=0|(this||n$3)._e,f=0|(this||n$3)._f,a=0|(this||n$3)._g,u=0|(this||n$3)._h,w=0;w<16;++w)s[w]=t.readInt32BE(4*w);for(;w<64;++w)s[w]=0|(((i=s[w-2])>>>17|i<<15)^(i>>>19|i<<13)^i>>>10)+s[w-7]+k$1(s[w-15])+s[w-16];for(var g=0;g<64;++g){var B=u+d$1(o)+c$2(o,f,a)+l$2[g]+s[g]|0,v=p$1(h)+b$1(h,e,_)|0;u=a,a=f,f=o,o=r+B|0,r=_,_=e,e=h,h=B+v|0;}(this||n$3)._a=h+(this||n$3)._a|0,(this||n$3)._b=e+(this||n$3)._b|0,(this||n$3)._c=_+(this||n$3)._c|0,(this||n$3)._d=r+(this||n$3)._d|0,(this||n$3)._e=o+(this||n$3)._e|0,(this||n$3)._f=f+(this||n$3)._f|0,(this||n$3)._g=a+(this||n$3)._g|0,(this||n$3)._h=u+(this||n$3)._h|0;},u$2.prototype._hash=function(){var t=f$4.allocUnsafe(32);return t.writeInt32BE((this||n$3)._a,0),t.writeInt32BE((this||n$3)._b,4),t.writeInt32BE((this||n$3)._c,8),t.writeInt32BE((this||n$3)._d,12),t.writeInt32BE((this||n$3)._e,16),t.writeInt32BE((this||n$3)._f,20),t.writeInt32BE((this||n$3)._g,24),t.writeInt32BE((this||n$3)._h,28),t};var w$1=u$2;var _$3="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,e$4=t$2$2,n$4=_$2,r$3=u$q.Buffer,l$3=[1518500249,1859775393,-1894007588,-899497514],o$5=new Array(80);function f$5(){this.init(),(this||_$3)._w=o$5,n$4.call(this||_$3,64,56);}function a$4(t){return t<<30|t>>>2}function u$3(t,i,h,s){return 0===t?i&h|~i&s:2===t?i&h|i&s|h&s:i^h^s}e$4(f$5,n$4),f$5.prototype.init=function(){return (this||_$3)._a=1732584193,(this||_$3)._b=4023233417,(this||_$3)._c=2562383102,(this||_$3)._d=271733878,(this||_$3)._e=3285377520,this||_$3},f$5.prototype._update=function(t){for(var i,h=(this||_$3)._w,s=0|(this||_$3)._a,e=0|(this||_$3)._b,n=0|(this||_$3)._c,r=0|(this||_$3)._d,o=0|(this||_$3)._e,f=0;f<16;++f)h[f]=t.readInt32BE(4*f);for(;f<80;++f)h[f]=h[f-3]^h[f-8]^h[f-14]^h[f-16];for(var c=0;c<80;++c){var d=~~(c/20),p=0|((i=s)<<5|i>>>27)+u$3(d,e,n,r)+o+h[c]+l$3[d];o=r,r=n,n=a$4(e),e=s,s=p;}(this||_$3)._a=s+(this||_$3)._a|0,(this||_$3)._b=e+(this||_$3)._b|0,(this||_$3)._c=n+(this||_$3)._c|0,(this||_$3)._d=r+(this||_$3)._d|0,(this||_$3)._e=o+(this||_$3)._e|0;},f$5.prototype._hash=function(){var t=r$3.allocUnsafe(20);return t.writeInt32BE(0|(this||_$3)._a,0),t.writeInt32BE(0|(this||_$3)._b,4),t.writeInt32BE(0|(this||_$3)._c,8),t.writeInt32BE(0|(this||_$3)._d,12),t.writeInt32BE(0|(this||_$3)._e,16),t};var c$3=f$5,d$2="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,p$2=t$2$2,b$2=_$2,w$2=u$q.Buffer,g=[1518500249,1859775393,-1894007588,-899497514],B=new Array(80);function y(){this.init(),(this||d$2)._w=B,b$2.call(this||d$2,64,56);}function E$1(t){return t<<5|t>>>27}function I$1(t){return t<<30|t>>>2}function v(t,i,h,s){return 0===t?i&h|~i&s:2===t?i&h|i&s|h&s:i^h^s}p$2(y,b$2),y.prototype.init=function(){return (this||d$2)._a=1732584193,(this||d$2)._b=4023233417,(this||d$2)._c=2562383102,(this||d$2)._d=271733878,(this||d$2)._e=3285377520,this||d$2},y.prototype._update=function(t){for(var i,h=(this||d$2)._w,s=0|(this||d$2)._a,_=0|(this||d$2)._b,e=0|(this||d$2)._c,n=0|(this||d$2)._d,r=0|(this||d$2)._e,l=0;l<16;++l)h[l]=t.readInt32BE(4*l);for(;l<80;++l)h[l]=(i=h[l-3]^h[l-8]^h[l-14]^h[l-16])<<1|i>>>31;for(var o=0;o<80;++o){var f=~~(o/20),a=E$1(s)+v(f,_,e,n)+r+h[o]+g[f]|0;r=n,n=e,e=I$1(_),_=s,s=a;}(this||d$2)._a=s+(this||d$2)._a|0,(this||d$2)._b=_+(this||d$2)._b|0,(this||d$2)._c=e+(this||d$2)._c|0,(this||d$2)._d=n+(this||d$2)._d|0,(this||d$2)._e=r+(this||d$2)._e|0;},y.prototype._hash=function(){var t=w$2.allocUnsafe(20);return t.writeInt32BE(0|(this||d$2)._a,0),t.writeInt32BE(0|(this||d$2)._b,4),t.writeInt32BE(0|(this||d$2)._c,8),t.writeInt32BE(0|(this||d$2)._d,12),t.writeInt32BE(0|(this||d$2)._e,16),t};var T=y,m="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,A=t$2$2,U=w$1,x=_$2,j=u$q.Buffer,q=new Array(64);function C(){this.init(),(this||m)._w=q,x.call(this||m,64,56);}A(C,U),C.prototype.init=function(){return (this||m)._a=3238371032,(this||m)._b=914150663,(this||m)._c=812702999,(this||m)._d=4144912697,(this||m)._e=4290775857,(this||m)._f=1750603025,(this||m)._g=1694076839,(this||m)._h=3204075428,this||m},C.prototype._hash=function(){var t=j.allocUnsafe(28);return t.writeInt32BE((this||m)._a,0),t.writeInt32BE((this||m)._b,4),t.writeInt32BE((this||m)._c,8),t.writeInt32BE((this||m)._d,12),t.writeInt32BE((this||m)._e,16),t.writeInt32BE((this||m)._f,20),t.writeInt32BE((this||m)._g,24),t};var L=C,k$2="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,z=t$2$2,D=_$2,F=u$q.Buffer,G=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],H=new Array(160);function J(){this.init(),(this||k$2)._w=H,D.call(this||k$2,128,112);}function K(t,i,h){return h^t&(i^h)}function M(t,i,h){return t&i|h&(t|i)}function N(t,i){return (t>>>28|i<<4)^(i>>>2|t<<30)^(i>>>7|t<<25)}function O(t,i){return (t>>>14|i<<18)^(t>>>18|i<<14)^(i>>>9|t<<23)}function P(t,i){return (t>>>1|i<<31)^(t>>>8|i<<24)^t>>>7}function Q(t,i){return (t>>>1|i<<31)^(t>>>8|i<<24)^(t>>>7|i<<25)}function R(t,i){return (t>>>19|i<<13)^(i>>>29|t<<3)^t>>>6}function S(t,i){return (t>>>19|i<<13)^(i>>>29|t<<3)^(t>>>6|i<<26)}function V(t,i){return t>>>0>>0?1:0}z(J,D),J.prototype.init=function(){return (this||k$2)._ah=1779033703,(this||k$2)._bh=3144134277,(this||k$2)._ch=1013904242,(this||k$2)._dh=2773480762,(this||k$2)._eh=1359893119,(this||k$2)._fh=2600822924,(this||k$2)._gh=528734635,(this||k$2)._hh=1541459225,(this||k$2)._al=4089235720,(this||k$2)._bl=2227873595,(this||k$2)._cl=4271175723,(this||k$2)._dl=1595750129,(this||k$2)._el=2917565137,(this||k$2)._fl=725511199,(this||k$2)._gl=4215389547,(this||k$2)._hl=327033209,this||k$2},J.prototype._update=function(t){for(var i=(this||k$2)._w,h=0|(this||k$2)._ah,s=0|(this||k$2)._bh,_=0|(this||k$2)._ch,e=0|(this||k$2)._dh,n=0|(this||k$2)._eh,r=0|(this||k$2)._fh,l=0|(this||k$2)._gh,o=0|(this||k$2)._hh,f=0|(this||k$2)._al,a=0|(this||k$2)._bl,u=0|(this||k$2)._cl,c=0|(this||k$2)._dl,d=0|(this||k$2)._el,p=0|(this||k$2)._fl,b=0|(this||k$2)._gl,w=0|(this||k$2)._hl,g=0;g<32;g+=2)i[g]=t.readInt32BE(4*g),i[g+1]=t.readInt32BE(4*g+4);for(;g<160;g+=2){var B=i[g-30],y=i[g-30+1],E=P(B,y),I=Q(y,B),v=R(B=i[g-4],y=i[g-4+1]),T=S(y,B),m=i[g-14],A=i[g-14+1],U=i[g-32],x=i[g-32+1],j=I+A|0,q=E+m+V(j,I)|0;q=(q=q+v+V(j=j+T|0,T)|0)+U+V(j=j+x|0,x)|0,i[g]=q,i[g+1]=j;}for(var C=0;C<160;C+=2){q=i[C],j=i[C+1];var L=M(h,s,_),z=M(f,a,u),D=N(h,f),F=N(f,h),H=O(n,d),J=O(d,n),W=G[C],X=G[C+1],Y=K(n,r,l),Z=K(d,p,b),$=w+J|0,tt=o+H+V($,w)|0;tt=(tt=(tt=tt+Y+V($=$+Z|0,Z)|0)+W+V($=$+X|0,X)|0)+q+V($=$+j|0,j)|0;var it=F+z|0,ht=D+L+V(it,F)|0;o=l,w=b,l=r,b=p,r=n,p=d,n=e+tt+V(d=c+$|0,c)|0,e=_,c=u,_=s,u=a,s=h,a=f,h=tt+ht+V(f=$+it|0,$)|0;}(this||k$2)._al=(this||k$2)._al+f|0,(this||k$2)._bl=(this||k$2)._bl+a|0,(this||k$2)._cl=(this||k$2)._cl+u|0,(this||k$2)._dl=(this||k$2)._dl+c|0,(this||k$2)._el=(this||k$2)._el+d|0,(this||k$2)._fl=(this||k$2)._fl+p|0,(this||k$2)._gl=(this||k$2)._gl+b|0,(this||k$2)._hl=(this||k$2)._hl+w|0,(this||k$2)._ah=(this||k$2)._ah+h+V((this||k$2)._al,f)|0,(this||k$2)._bh=(this||k$2)._bh+s+V((this||k$2)._bl,a)|0,(this||k$2)._ch=(this||k$2)._ch+_+V((this||k$2)._cl,u)|0,(this||k$2)._dh=(this||k$2)._dh+e+V((this||k$2)._dl,c)|0,(this||k$2)._eh=(this||k$2)._eh+n+V((this||k$2)._el,d)|0,(this||k$2)._fh=(this||k$2)._fh+r+V((this||k$2)._fl,p)|0,(this||k$2)._gh=(this||k$2)._gh+l+V((this||k$2)._gl,b)|0,(this||k$2)._hh=(this||k$2)._hh+o+V((this||k$2)._hl,w)|0;},J.prototype._hash=function(){var t=F.allocUnsafe(64);function i(i,h,s){t.writeInt32BE(i,s),t.writeInt32BE(h,s+4);}return i((this||k$2)._ah,(this||k$2)._al,0),i((this||k$2)._bh,(this||k$2)._bl,8),i((this||k$2)._ch,(this||k$2)._cl,16),i((this||k$2)._dh,(this||k$2)._dl,24),i((this||k$2)._eh,(this||k$2)._el,32),i((this||k$2)._fh,(this||k$2)._fl,40),i((this||k$2)._gh,(this||k$2)._gl,48),i((this||k$2)._hh,(this||k$2)._hl,56),t};var W=J,X="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,Y=t$2$2,Z=W,$=_$2,tt=u$q.Buffer,it=new Array(160);function ht(){this.init(),(this||X)._w=it,$.call(this||X,128,112);}Y(ht,Z),ht.prototype.init=function(){return (this||X)._ah=3418070365,(this||X)._bh=1654270250,(this||X)._ch=2438529370,(this||X)._dh=355462360,(this||X)._eh=1731405415,(this||X)._fh=2394180231,(this||X)._gh=3675008525,(this||X)._hh=1203062813,(this||X)._al=3238371032,(this||X)._bl=914150663,(this||X)._cl=812702999,(this||X)._dl=4144912697,(this||X)._el=4290775857,(this||X)._fl=1750603025,(this||X)._gl=1694076839,(this||X)._hl=3204075428,this||X},ht.prototype._hash=function(){var t=tt.allocUnsafe(48);function i(i,h,s){t.writeInt32BE(i,s),t.writeInt32BE(h,s+4);}return i((this||X)._ah,(this||X)._al,0),i((this||X)._bh,(this||X)._bl,8),i((this||X)._ch,(this||X)._cl,16),i((this||X)._dh,(this||X)._dl,24),i((this||X)._eh,(this||X)._el,32),i((this||X)._fh,(this||X)._fl,40),t};var st,_t=ht,et={exports:st={}};(st=et.exports=function(t){t=t.toLowerCase();var i=st[t];if(!i)throw new Error(t+" is not supported (we accept pull requests)");return new i}).sha=c$3,st.sha1=T,st.sha224=L,st.sha256=w$1,st.sha384=_t,st.sha512=W;var nt=et.exports;var e$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,n$5=u$q.Buffer,s$2=b$i.Transform,h$3=e$1$2.StringDecoder;function a$5(t){s$2.call(this||e$5),(this||e$5).hashMode="string"==typeof t,(this||e$5).hashMode?(this||e$5)[t]=(this||e$5)._finalOrDigest:(this||e$5).final=(this||e$5)._finalOrDigest,(this||e$5)._final&&((this||e$5).__final=(this||e$5)._final,(this||e$5)._final=null),(this||e$5)._decoder=null,(this||e$5)._encoding=null;}t$2$2(a$5,s$2),a$5.prototype.update=function(t,i,r){"string"==typeof t&&(t=n$5.from(t,i));var o=this._update(t);return (this||e$5).hashMode?this||e$5:(r&&(o=this._toString(o,r)),o)},a$5.prototype.setAutoPadding=function(){},a$5.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")},a$5.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")},a$5.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")},a$5.prototype._transform=function(t,i,r){var o;try{(this||e$5).hashMode?this._update(t):this.push(this._update(t));}catch(t){o=t;}finally{r(o);}},a$5.prototype._flush=function(t){var i;try{this.push(this.__final());}catch(t){i=t;}t(i);},a$5.prototype._finalOrDigest=function(t){var i=this.__final()||n$5.alloc(0);return t&&(i=this._toString(i,t,!0)),i},a$5.prototype._toString=function(t,i,r){if((this||e$5)._decoder||((this||e$5)._decoder=new h$3(i),(this||e$5)._encoding=i),(this||e$5)._encoding!==i)throw new Error("can't switch encodings");var o=(this||e$5)._decoder.write(t);return r&&(o+=(this||e$5)._decoder.end()),o};var f$6=a$5;var m$1=u,n$6=I,p$3=nt,s$3=f$6;function a$6(t){s$3.call(this,"digest"),this._hash=t;}t$2$2(a$6,s$3),a$6.prototype._update=function(t){this._hash.update(t);},a$6.prototype._final=function(){return this._hash.digest()};var h$4=function(t){return "md5"===(t=t.toLowerCase())?new m$1:"rmd160"===t||"ripemd160"===t?new n$6:new a$6(p$3(t))};var e$6=u,r$4=function(t){return (new e$6).update(t).digest()};var o$6=t$2$2,h$5=u$q.Buffer,n$7=f$6,p$4=h$5.alloc(128);function f$7(t,a){n$7.call(this,"digest"),"string"==typeof a&&(a=h$5.from(a)),this._alg=t,this._key=a,a.length>64?a=t(a):a.length<64&&(a=h$5.concat([a,p$4],64));for(var e=this._ipad=h$5.allocUnsafe(64),i=this._opad=h$5.allocUnsafe(64),r=0;r<64;r++)e[r]=54^a[r],i[r]=92^a[r];this._hash=[e];}o$6(f$7,n$7),f$7.prototype._update=function(t){this._hash.push(t);},f$7.prototype._final=function(){var t=this._alg(h$5.concat(this._hash));return this._alg(h$5.concat([this._opad,t]))};var l$4=t$2$2,d$3=f$7,c$4=f$6,_$4=u$q.Buffer,m$2=r$4,u$4=I,g$1=nt,v$1=_$4.alloc(128);function y$1(t,a){c$4.call(this,"digest"),"string"==typeof a&&(a=_$4.from(a));var e="sha512"===t||"sha384"===t?128:64;(this._alg=t,this._key=a,a.length>e)?a=("rmd160"===t?new u$4:g$1(t)).update(a).digest():a.lengtha$7||n!=n)throw new TypeError("Bad key length")},c$5=T$9;c$5.browser?u$5="utf-8":u$5=parseInt(c$5.version.split(".")[0].slice(1),10)>=6?"utf-8":"binary";var l$5=u$5,p$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,d$4=r$4,m$3=I,y$2=nt,b$3=h$6,v$2=l$5,w$4=u$q.Buffer,g$2=w$4.alloc(128),B$1={md5:16,sha1:20,sha224:28,sha256:32,sha384:48,sha512:64,rmd160:20,ripemd160:20};function T$1(r,e,t){var n=function(r){function e(e){return y$2(r).update(e).digest()}return "rmd160"===r||"ripemd160"===r?function(r){return (new m$3).update(r).digest()}:"md5"===r?d$4:e}(r),o="sha512"===r||"sha384"===r?128:64;e.length>o?e=n(e):e.length0;i--)e+=this._buffer(t,e),r+=this._flushBuffer(n,r);return e+=this._buffer(t,e),n},u$6.prototype.final=function(t){var e,r;return t&&(e=this.update(t)),r="encrypt"===this.type?this._finalEncrypt():this._finalDecrypt(),e?e.concat(r):r},u$6.prototype._pad=function(t,e){if(0===e)return !1;for(;e>>1];r=c$6.r28shl(r,f),i=c$6.r28shl(i,f),c$6.pc2(r,i,t.keys,n);}},v$3.prototype._update=function(t,e,r,i){var n=this._desState,f=c$6.readUInt32BE(t,e),o=c$6.readUInt32BE(t,e+4);c$6.ip(f,o,n.tmp,0),f=n.tmp[0],o=n.tmp[1],"encrypt"===this.type?this._encrypt(n,f,o,n.tmp,0):this._decrypt(n,f,o,n.tmp,0),f=n.tmp[0],o=n.tmp[1],c$6.writeUInt32BE(r,f,i),c$6.writeUInt32BE(r,o,i+4);},v$3.prototype._pad=function(t,e){for(var r=t.length-e,i=e;i>>0,f=h;}c$6.rip(o,f,i,n);},v$3.prototype._decrypt=function(t,e,r,i,n){for(var f=r,o=e,p=t.keys.length-2;p>=0;p-=2){var u=t.keys[p],s=t.keys[p+1];c$6.expand(f,t.tmp,0),u^=t.tmp[0],s^=t.tmp[1];var a=c$6.substitute(u,s),h=f;f=(o^c$6.permute(a))>>>0,o=h;}c$6.rip(f,o,i,n);};var _$5=s$6,b$4={},k$4=o$7,g$3=t$2$2,m$4={};function S$2(t){k$4.equal(t.length,8,"Invalid IV length"),this.iv=new Array(8);for(var e=0;e>p%8,e._prev=k$5(e._prev,r?t:a);return n}function k$5(e,c){var r=e.length,t=-1,a=m$5.allocUnsafe(e.length);for(e=m$5.concat([e,m$5.from([c])]);++t>7;return a}l$8.encrypt=function(e,c,r){for(var t=c.length,a=m$5.allocUnsafe(t),p=-1;++p>>24]^l[_>>>16&255]^f[d>>>8&255]^u[255&y]^e[B++],h=c[_>>>24]^l[d>>>16&255]^f[y>>>8&255]^u[255&p]^e[B++],o=c[d>>>24]^l[y>>>16&255]^f[p>>>8&255]^u[255&_]^e[B++],s=c[y>>>24]^l[p>>>16&255]^f[_>>>8&255]^u[255&d]^e[B++],p=a,_=h,d=o,y=s;return a=(r[p>>>24]<<24|r[_>>>16&255]<<16|r[d>>>8&255]<<8|r[255&y])^e[B++],h=(r[_>>>24]<<24|r[d>>>16&255]<<16|r[y>>>8&255]<<8|r[255&p])^e[B++],o=(r[d>>>24]<<24|r[y>>>16&255]<<16|r[p>>>8&255]<<8|r[255&_])^e[B++],s=(r[y>>>24]<<24|r[p>>>16&255]<<16|r[_>>>8&255]<<8|r[255&d])^e[B++],[a>>>=0,h>>>=0,o>>>=0,s>>>=0]}var f$d=[0,1,2,4,8,16,32,64,128,27,54],u$8=function(){for(var t=new Array(256),e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;for(var i=[],r=[],n=[[],[],[],[]],a=[[],[],[],[]],h=0,o=0,s=0;s<256;++s){var c=o^o<<1^o<<2^o<<3^o<<4;c=c>>>8^255&c^99,i[h]=c,r[c]=h;var l=t[h],f=t[l],u=t[f],p=257*t[c]^16843008*c;n[0][h]=p<<24|p>>>8,n[1][h]=p<<16|p>>>16,n[2][h]=p<<8|p>>>24,n[3][h]=p,p=16843009*u^65537*f^257*l^16843008*h,a[0][c]=p<<24|p>>>8,a[1][c]=p<<16|p>>>16,a[2][c]=p<<8|p>>>24,a[3][c]=p,0===h?h=o=1:(h=l^t[t[t[u^l]]],o^=t[t[o]]);}return {SBOX:i,INV_SBOX:r,SUB_MIX:n,INV_SUB_MIX:a}}();function p$9(t){(this||a$b)._key=s$8(t),this._reset();}p$9.blockSize=16,p$9.keySize=32,p$9.prototype.blockSize=p$9.blockSize,p$9.prototype.keySize=p$9.keySize,p$9.prototype._reset=function(){for(var t=(this||a$b)._key,e=t.length,i=e+6,r=4*(i+1),n=[],h=0;h>>24,o=u$8.SBOX[o>>>24]<<24|u$8.SBOX[o>>>16&255]<<16|u$8.SBOX[o>>>8&255]<<8|u$8.SBOX[255&o],o^=f$d[h/e|0]<<24):e>6&&h%e==4&&(o=u$8.SBOX[o>>>24]<<24|u$8.SBOX[o>>>16&255]<<16|u$8.SBOX[o>>>8&255]<<8|u$8.SBOX[255&o]),n[h]=n[h-e]^o;}for(var s=[],c=0;c>>24]]^u$8.INV_SUB_MIX[1][u$8.SBOX[p>>>16&255]]^u$8.INV_SUB_MIX[2][u$8.SBOX[p>>>8&255]]^u$8.INV_SUB_MIX[3][u$8.SBOX[255&p]];}(this||a$b)._nRounds=i,(this||a$b)._keySchedule=n,(this||a$b)._invKeySchedule=s;},p$9.prototype.encryptBlockRaw=function(t){return l$9(t=s$8(t),(this||a$b)._keySchedule,u$8.SUB_MIX,u$8.SBOX,(this||a$b)._nRounds)},p$9.prototype.encryptBlock=function(t){var e=this.encryptBlockRaw(t),i=o$b.allocUnsafe(16);return i.writeUInt32BE(e[0],0),i.writeUInt32BE(e[1],4),i.writeUInt32BE(e[2],8),i.writeUInt32BE(e[3],12),i},p$9.prototype.decryptBlock=function(t){var e=(t=s$8(t))[1];t[1]=t[3],t[3]=e;var i=l$9(t,(this||a$b)._invKeySchedule,u$8.INV_SUB_MIX,u$8.INV_SBOX,(this||a$b)._nRounds),r=o$b.allocUnsafe(16);return r.writeUInt32BE(i[0],0),r.writeUInt32BE(i[3],4),r.writeUInt32BE(i[2],8),r.writeUInt32BE(i[1],12),r},p$9.prototype.scrub=function(){c$8((this||a$b)._keySchedule),c$8((this||a$b)._invKeySchedule),c$8((this||a$b)._key);},h$9.AES=p$9;var _$7="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,d$8=u$q.Buffer,y$5=d$8.alloc(16,0);function B$4(t){var e=d$8.allocUnsafe(16);return e.writeUInt32BE(t[0]>>>0,0),e.writeUInt32BE(t[1]>>>0,4),e.writeUInt32BE(t[2]>>>0,8),e.writeUInt32BE(t[3]>>>0,12),e}function g$5(t){(this||_$7).h=t,(this||_$7).state=d$8.alloc(16,0),(this||_$7).cache=d$8.allocUnsafe(0);}g$5.prototype.ghash=function(t){for(var e=-1;++e0;e--)r[e]=r[e]>>>1|(1&r[e-1])<<31;r[0]=r[0]>>>1,i&&(r[0]=r[0]^225<<24);}(this||_$7).state=B$4(n);},g$5.prototype.update=function(t){var e;for((this||_$7).cache=d$8.concat([(this||_$7).cache,t]);(this||_$7).cache.length>=16;)e=(this||_$7).cache.slice(0,16),(this||_$7).cache=(this||_$7).cache.slice(16),this.ghash(e);},g$5.prototype.final=function(t,e){return (this||_$7).cache.length&&this.ghash(d$8.concat([(this||_$7).cache,y$5],16)),this.ghash(B$4([0,t,0,e])),(this||_$7).state};var S$4=g$5,v$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,I$5=h$9,U$4=u$q.Buffer,w$7=f$6,m$6=S$4,E$5=f$b,b$6=t$1;function X$1(t,e,i,r){w$7.call(this||v$5);var n=U$4.alloc(4,0);(this||v$5)._cipher=new I$5.AES(e);var a=(this||v$5)._cipher.encryptBlock(n);(this||v$5)._ghash=new m$6(a),i=function(t,e,i){if(12===e.length)return t._finID=U$4.concat([e,U$4.from([0,0,0,1])]),U$4.concat([e,U$4.from([0,0,0,2])]);var r=new m$6(i),n=e.length,a=n%16;r.update(e),a&&(a=16-a,r.update(U$4.alloc(a,0))),r.update(U$4.alloc(8,0));var h=8*n,o=U$4.alloc(8);o.writeUIntBE(h,0,8),r.update(o),t._finID=r.state;var s=U$4.from(t._finID);return b$6(s),s}(this||v$5,i,a),(this||v$5)._prev=U$4.from(i),(this||v$5)._cache=U$4.allocUnsafe(0),(this||v$5)._secCache=U$4.allocUnsafe(0),(this||v$5)._decrypt=r,(this||v$5)._alen=0,(this||v$5)._len=0,(this||v$5)._mode=t,(this||v$5)._authTag=null,(this||v$5)._called=!1;}t$2$2(X$1,w$7),X$1.prototype._update=function(t){if(!(this||v$5)._called&&(this||v$5)._alen){var e=16-(this||v$5)._alen%16;e<16&&(e=U$4.alloc(e,0),(this||v$5)._ghash.update(e));}(this||v$5)._called=!0;var i=(this||v$5)._mode.encrypt(this||v$5,t);return (this||v$5)._decrypt?(this||v$5)._ghash.update(t):(this||v$5)._ghash.update(i),(this||v$5)._len+=t.length,i},X$1.prototype._final=function(){if((this||v$5)._decrypt&&!(this||v$5)._authTag)throw new Error("Unsupported state or unable to authenticate data");var t=E$5((this||v$5)._ghash.final(8*(this||v$5)._alen,8*(this||v$5)._len),(this||v$5)._cipher.encryptBlock((this||v$5)._finID));if((this||v$5)._decrypt&&function(t,e){var i=0;t.length!==e.length&&i++;for(var r=Math.min(t.length,e.length),n=0;n0||l>0;){var u=new f$e;u.update(h),u.update(r),e&&u.update(e),h=u.digest();var g=0;if(n>0){var m=o.length-n;g=Math.min(n,h.length),h.copy(o,m,0,g),n-=g;}if(g0){var p=i.length-l,v=Math.min(l,h.length-g);h.copy(i,p,g,g+v),l-=v;}}return h.fill(0),{key:o,iv:i}};var c$9="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,s$9={},f$f=k$6,p$a=u$q.Buffer,u$9=M$2,l$a=V$1,d$9=f$6,y$6=h$9,m$7=a$c;function g$6(t,e,r){d$9.call(this||c$9),(this||c$9)._cache=new v$6,(this||c$9)._last=void 0,(this||c$9)._cipher=new y$6.AES(e),(this||c$9)._prev=p$a.from(r),(this||c$9)._mode=t,(this||c$9)._autopadding=!0;}function v$6(){(this||c$9).cache=p$a.allocUnsafe(0);}function w$8(t,e,r){var i=u$9[t.toLowerCase()];if(!i)throw new TypeError("invalid suite type");if("string"==typeof r&&(r=p$a.from(r)),"GCM"!==i.mode&&r.length!==i.iv)throw new TypeError("invalid iv length "+r.length);if("string"==typeof e&&(e=p$a.from(e)),e.length!==i.key/8)throw new TypeError("invalid key length "+e.length);return "stream"===i.type?new l$a(i.module,e,r,!0):"auth"===i.type?new f$f(i.module,e,r,!0):new g$6(i.module,e,r)}t$2$2(g$6,d$9),g$6.prototype._update=function(t){var e,r;(this||c$9)._cache.add(t);for(var i=[];e=(this||c$9)._cache.get((this||c$9)._autopadding);)r=(this||c$9)._mode.decrypt(this||c$9,e),i.push(r);return p$a.concat(i)},g$6.prototype._final=function(){var t=(this||c$9)._cache.flush();if((this||c$9)._autopadding)return function(t){var e=t[15];if(e<1||e>16)throw new Error("unable to decrypt data");var r=-1;for(;++r16)return e=(this||c$9).cache.slice(0,16),(this||c$9).cache=(this||c$9).cache.slice(16),e}else if((this||c$9).cache.length>=16)return e=(this||c$9).cache.slice(0,16),(this||c$9).cache=(this||c$9).cache.slice(16),e;return null},v$6.prototype.flush=function(){if((this||c$9).cache.length)return (this||c$9).cache},s$9.createDecipher=function(t,e){var r=u$9[t.toLowerCase()];if(!r)throw new TypeError("invalid suite type");var i=m$7(e,!1,r.key,r.iv);return w$8(t,i.key,i.iv)},s$9.createDecipheriv=w$8;var c$a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,s$a={},f$g=M$2,p$b=k$6,l$b=u$q.Buffer,u$a=V$1,d$a=f$6,m$8=h$9,y$7=a$c;function v$7(t,e,r){d$a.call(this||c$a),(this||c$a)._cache=new g$7,(this||c$a)._cipher=new m$8.AES(e),(this||c$a)._prev=l$b.from(r),(this||c$a)._mode=t,(this||c$a)._autopadding=!0;}t$2$2(v$7,d$a),v$7.prototype._update=function(t){var e,r;(this||c$a)._cache.add(t);for(var i=[];e=(this||c$a)._cache.get();)r=(this||c$a)._mode.encrypt(this||c$a,e),i.push(r);return l$b.concat(i)};var _$8=l$b.alloc(16,16);function g$7(){(this||c$a).cache=l$b.allocUnsafe(0);}function w$9(t,e,r){var i=f$g[t.toLowerCase()];if(!i)throw new TypeError("invalid suite type");if("string"==typeof e&&(e=l$b.from(e)),e.length!==i.key/8)throw new TypeError("invalid key length "+e.length);if("string"==typeof r&&(r=l$b.from(r)),"GCM"!==i.mode&&r.length!==i.iv)throw new TypeError("invalid iv length "+r.length);return "stream"===i.type?new u$a(i.module,e,r):"auth"===i.type?new p$b(i.module,e,r):new v$7(i.module,e,r)}v$7.prototype._final=function(){var t=(this||c$a)._cache.flush();if((this||c$a)._autopadding)return t=(this||c$a)._mode.encrypt(this||c$a,t),(this||c$a)._cipher.scrub(),t;if(!t.equals(_$8))throw (this||c$a)._cipher.scrub(),new Error("data not multiple of block length")},v$7.prototype.setAutoPadding=function(t){return (this||c$a)._autopadding=!!t,this||c$a},g$7.prototype.add=function(t){(this||c$a).cache=l$b.concat([(this||c$a).cache,t]);},g$7.prototype.get=function(){if((this||c$a).cache.length>15){var t=(this||c$a).cache.slice(0,16);return (this||c$a).cache=(this||c$a).cache.slice(16),t}return null},g$7.prototype.flush=function(){for(var t=16-(this||c$a).cache.length,e=l$b.allocUnsafe(t),r=-1;++r=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o;}return h}function a(t,i,r,h){for(var n=0,e=Math.min(t.length,r),o=i;o=49?s-49+10:s>=17?s-17+10:s;}return n}o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,i){return t.cmp(i)>0?t:i},o.min=function(t,i){return t.cmp(i)<0?t:i},o.prototype._init=function(t,r,h){if("number"==typeof t)return this._initNumber(t,r,h);if("object"==typeof t)return this._initArray(t,r,h);"hex"===r&&(r=16),n(r===(0|r)&&r>=2&&r<=36);var e=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&e++,16===r?this._parseHex(t,e):this._parseBase(t,r,e),"-"===t[0]&&((this||i$3).negative=1),this.strip(),"le"===h&&this._initArray(this.toArray(),r,h);},o.prototype._initNumber=function(t,r,h){t<0&&((this||i$3).negative=1,t=-t),t<67108864?((this||i$3).words=[67108863&t],(this||i$3).length=1):t<4503599627370496?((this||i$3).words=[67108863&t,t/67108864&67108863],(this||i$3).length=2):(n(t<9007199254740992),(this||i$3).words=[67108863&t,t/67108864&67108863,1],(this||i$3).length=3),"le"===h&&this._initArray(this.toArray(),r,h);},o.prototype._initArray=function(t,r,h){if(n("number"==typeof t.length),t.length<=0)return (this||i$3).words=[0],(this||i$3).length=1,this||i$3;(this||i$3).length=Math.ceil(t.length/3),(this||i$3).words=new Array((this||i$3).length);for(var e=0;e<(this||i$3).length;e++)(this||i$3).words[e]=0;var o,s,u=0;if("be"===h)for(e=t.length-1,o=0;e>=0;e-=3)s=t[e]|t[e-1]<<8|t[e-2]<<16,(this||i$3).words[o]|=s<>>26-u&67108863,(u+=24)>=26&&(u-=26,o++);else if("le"===h)for(e=0,o=0;e>>26-u&67108863,(u+=24)>=26&&(u-=26,o++);return this.strip()},o.prototype._parseHex=function(t,r){(this||i$3).length=Math.ceil((t.length-r)/6),(this||i$3).words=new Array((this||i$3).length);for(var h=0;h<(this||i$3).length;h++)(this||i$3).words[h]=0;var n,e,o=0;for(h=t.length-6,n=0;h>=r;h-=6)e=u(t,h,h+6),(this||i$3).words[n]|=e<>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);h+6!==r&&(e=u(t,r,h+6),(this||i$3).words[n]|=e<>>26-o&4194303),this.strip();},o.prototype._parseBase=function(t,r,h){(this||i$3).words=[0],(this||i$3).length=1;for(var n=0,e=1;e<=67108863;e*=r)n++;n--,e=e/r|0;for(var o=t.length-h,s=o%n,u=Math.min(o,o-s)+h,l=0,m=h;m1&&0===(this||i$3).words[(this||i$3).length-1];)(this||i$3).length--;return this._normSign()},o.prototype._normSign=function(){return 1===(this||i$3).length&&0===(this||i$3).words[0]&&((this||i$3).negative=0),this||i$3},o.prototype.inspect=function(){return ((this||i$3).red?""};var l=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],m=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,r){r.negative=i.negative^t.negative;var h=t.length+i.length|0;r.length=h,h=h-1|0;var n=0|t.words[0],e=0|i.words[0],o=n*e,s=67108863&o,u=o/67108864|0;r.words[0]=s;for(var a=1;a>>26,m=67108863&u,f=Math.min(a,i.length-1),d=Math.max(0,a-t.length+1);d<=f;d++){var p=a-d|0;l+=(o=(n=0|t.words[p])*(e=0|i.words[d])+m)/67108864|0,m=67108863&o;}r.words[a]=0|m,u=0|l;}return 0!==u?r.words[a]=0|u:r.length--,r.strip()}o.prototype.toString=function(t,r){var h;if(r=0|r||1,16===(t=t||10)||"hex"===t){h="";for(var e=0,o=0,s=0;s<(this||i$3).length;s++){var u=(this||i$3).words[s],a=(16777215&(u<>>24-e&16777215)||s!==(this||i$3).length-1?l[6-a.length]+a+h:a+h,(e+=2)>=26&&(e-=26,s--);}for(0!==o&&(h=o.toString(16)+h);h.length%r!=0;)h="0"+h;return 0!==(this||i$3).negative&&(h="-"+h),h}if(t===(0|t)&&t>=2&&t<=36){var d=m[t],p=f[t];h="";var M=this.clone();for(M.negative=0;!M.isZero();){var v=M.modn(p).toString(t);h=(M=M.idivn(p)).isZero()?v+h:l[d-v.length]+v+h;}for(this.isZero()&&(h="0"+h);h.length%r!=0;)h="0"+h;return 0!==(this||i$3).negative&&(h="-"+h),h}n(!1,"Base should be between 2 and 36");},o.prototype.toNumber=function(){var t=(this||i$3).words[0];return 2===(this||i$3).length?t+=67108864*(this||i$3).words[1]:3===(this||i$3).length&&1===(this||i$3).words[2]?t+=4503599627370496+67108864*(this||i$3).words[1]:(this||i$3).length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==(this||i$3).negative?-t:t},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(t,i){return n(void 0!==s),this.toArrayLike(s,t,i)},o.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},o.prototype.toArrayLike=function(t,i,r){var h=this.byteLength(),e=r||Math.max(1,h);n(h<=e,"byte array longer than desired length"),n(e>0,"Requested array length <= 0"),this.strip();var o,s,u="le"===i,a=new t(e),l=this.clone();if(u){for(s=0;!l.isZero();s++)o=l.andln(255),l.iushrn(8),a[s]=o;for(;s=4096&&(r+=13,i>>>=13),i>=64&&(r+=7,i>>>=7),i>=8&&(r+=4,i>>>=4),i>=2&&(r+=2,i>>>=2),r+i},o.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,r=0;return 0==(8191&i)&&(r+=13,i>>>=13),0==(127&i)&&(r+=7,i>>>=7),0==(15&i)&&(r+=4,i>>>=4),0==(3&i)&&(r+=2,i>>>=2),0==(1&i)&&r++,r},o.prototype.bitLength=function(){var t=(this||i$3).words[(this||i$3).length-1],r=this._countBits(t);return 26*((this||i$3).length-1)+r},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<(this||i$3).length;r++){var h=this._zeroBits((this||i$3).words[r]);if(t+=h,26!==h)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==(this||i$3).negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==(this||i$3).negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||((this||i$3).negative^=1),this||i$3},o.prototype.iuor=function(t){for(;(this||i$3).lengtht.length?this.clone().ior(t):t.clone().ior(this||i$3)},o.prototype.uor=function(t){return (this||i$3).length>t.length?this.clone().iuor(t):t.clone().iuor(this||i$3)},o.prototype.iuand=function(t){var r;r=(this||i$3).length>t.length?t:this||i$3;for(var h=0;ht.length?this.clone().iand(t):t.clone().iand(this||i$3)},o.prototype.uand=function(t){return (this||i$3).length>t.length?this.clone().iuand(t):t.clone().iuand(this||i$3)},o.prototype.iuxor=function(t){var r,h;(this||i$3).length>t.length?(r=this||i$3,h=t):(r=t,h=this||i$3);for(var n=0;nt.length?this.clone().ixor(t):t.clone().ixor(this||i$3)},o.prototype.uxor=function(t){return (this||i$3).length>t.length?this.clone().iuxor(t):t.clone().iuxor(this||i$3)},o.prototype.inotn=function(t){n("number"==typeof t&&t>=0);var r=0|Math.ceil(t/26),h=t%26;this._expand(r),h>0&&r--;for(var e=0;e0&&((this||i$3).words[e]=~(this||i$3).words[e]&67108863>>26-h),this.strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,r){n("number"==typeof t&&t>=0);var h=t/26|0,e=t%26;return this._expand(h+1),(this||i$3).words[h]=r?(this||i$3).words[h]|1<t.length?(h=this||i$3,n=t):(h=t,n=this||i$3);for(var e=0,o=0;o>>26;for(;0!==e&&o>>26;if((this||i$3).length=h.length,0!==e)(this||i$3).words[(this||i$3).length]=e,(this||i$3).length++;else if(h!==(this||i$3))for(;ot.length?this.clone().iadd(t):t.clone().iadd(this||i$3)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}if(0!==(this||i$3).negative)return (this||i$3).negative=0,this.iadd(t),(this||i$3).negative=1,this._normSign();var h,n,e=this.cmp(t);if(0===e)return (this||i$3).negative=0,(this||i$3).length=1,(this||i$3).words[0]=0,this||i$3;e>0?(h=this||i$3,n=t):(h=t,n=this||i$3);for(var o=0,s=0;s>26,(this||i$3).words[s]=67108863&r;for(;0!==o&&s>26,(this||i$3).words[s]=67108863&r;if(0===o&&s>>13,d=0|o[1],p=8191&d,M=d>>>13,v=0|o[2],g=8191&v,c=v>>>13,w=0|o[3],y=8191&w,b=w>>>13,_=0|o[4],k=8191&_,A=_>>>13,x=0|o[5],S=8191&x,Z=x>>>13,R=0|o[6],q=8191&R,B=R>>>13,N=0|o[7],L=8191&N,I=N>>>13,T=0|o[8],z=8191&T,E=T>>>13,O=0|o[9],j=8191&O,K=O>>>13,P=0|s[0],F=8191&P,C=P>>>13,D=0|s[1],H=8191&D,J=D>>>13,U=0|s[2],G=8191&U,Q=U>>>13,V=0|s[3],W=8191&V,X=V>>>13,Y=0|s[4],$=8191&Y,tt=Y>>>13,it=0|s[5],rt=8191&it,ht=it>>>13,nt=0|s[6],et=8191&nt,ot=nt>>>13,st=0|s[7],ut=8191&st,at=st>>>13,lt=0|s[8],mt=8191<,ft=lt>>>13,dt=0|s[9],pt=8191&dt,Mt=dt>>>13;r.negative=t.negative^i.negative,r.length=19;var vt=(a+(h=Math.imul(m,F))|0)+((8191&(n=(n=Math.imul(m,C))+Math.imul(f,F)|0))<<13)|0;a=((e=Math.imul(f,C))+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,h=Math.imul(p,F),n=(n=Math.imul(p,C))+Math.imul(M,F)|0,e=Math.imul(M,C);var gt=(a+(h=h+Math.imul(m,H)|0)|0)+((8191&(n=(n=n+Math.imul(m,J)|0)+Math.imul(f,H)|0))<<13)|0;a=((e=e+Math.imul(f,J)|0)+(n>>>13)|0)+(gt>>>26)|0,gt&=67108863,h=Math.imul(g,F),n=(n=Math.imul(g,C))+Math.imul(c,F)|0,e=Math.imul(c,C),h=h+Math.imul(p,H)|0,n=(n=n+Math.imul(p,J)|0)+Math.imul(M,H)|0,e=e+Math.imul(M,J)|0;var ct=(a+(h=h+Math.imul(m,G)|0)|0)+((8191&(n=(n=n+Math.imul(m,Q)|0)+Math.imul(f,G)|0))<<13)|0;a=((e=e+Math.imul(f,Q)|0)+(n>>>13)|0)+(ct>>>26)|0,ct&=67108863,h=Math.imul(y,F),n=(n=Math.imul(y,C))+Math.imul(b,F)|0,e=Math.imul(b,C),h=h+Math.imul(g,H)|0,n=(n=n+Math.imul(g,J)|0)+Math.imul(c,H)|0,e=e+Math.imul(c,J)|0,h=h+Math.imul(p,G)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(M,G)|0,e=e+Math.imul(M,Q)|0;var wt=(a+(h=h+Math.imul(m,W)|0)|0)+((8191&(n=(n=n+Math.imul(m,X)|0)+Math.imul(f,W)|0))<<13)|0;a=((e=e+Math.imul(f,X)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,h=Math.imul(k,F),n=(n=Math.imul(k,C))+Math.imul(A,F)|0,e=Math.imul(A,C),h=h+Math.imul(y,H)|0,n=(n=n+Math.imul(y,J)|0)+Math.imul(b,H)|0,e=e+Math.imul(b,J)|0,h=h+Math.imul(g,G)|0,n=(n=n+Math.imul(g,Q)|0)+Math.imul(c,G)|0,e=e+Math.imul(c,Q)|0,h=h+Math.imul(p,W)|0,n=(n=n+Math.imul(p,X)|0)+Math.imul(M,W)|0,e=e+Math.imul(M,X)|0;var yt=(a+(h=h+Math.imul(m,$)|0)|0)+((8191&(n=(n=n+Math.imul(m,tt)|0)+Math.imul(f,$)|0))<<13)|0;a=((e=e+Math.imul(f,tt)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,h=Math.imul(S,F),n=(n=Math.imul(S,C))+Math.imul(Z,F)|0,e=Math.imul(Z,C),h=h+Math.imul(k,H)|0,n=(n=n+Math.imul(k,J)|0)+Math.imul(A,H)|0,e=e+Math.imul(A,J)|0,h=h+Math.imul(y,G)|0,n=(n=n+Math.imul(y,Q)|0)+Math.imul(b,G)|0,e=e+Math.imul(b,Q)|0,h=h+Math.imul(g,W)|0,n=(n=n+Math.imul(g,X)|0)+Math.imul(c,W)|0,e=e+Math.imul(c,X)|0,h=h+Math.imul(p,$)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(M,$)|0,e=e+Math.imul(M,tt)|0;var bt=(a+(h=h+Math.imul(m,rt)|0)|0)+((8191&(n=(n=n+Math.imul(m,ht)|0)+Math.imul(f,rt)|0))<<13)|0;a=((e=e+Math.imul(f,ht)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,h=Math.imul(q,F),n=(n=Math.imul(q,C))+Math.imul(B,F)|0,e=Math.imul(B,C),h=h+Math.imul(S,H)|0,n=(n=n+Math.imul(S,J)|0)+Math.imul(Z,H)|0,e=e+Math.imul(Z,J)|0,h=h+Math.imul(k,G)|0,n=(n=n+Math.imul(k,Q)|0)+Math.imul(A,G)|0,e=e+Math.imul(A,Q)|0,h=h+Math.imul(y,W)|0,n=(n=n+Math.imul(y,X)|0)+Math.imul(b,W)|0,e=e+Math.imul(b,X)|0,h=h+Math.imul(g,$)|0,n=(n=n+Math.imul(g,tt)|0)+Math.imul(c,$)|0,e=e+Math.imul(c,tt)|0,h=h+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,ht)|0)+Math.imul(M,rt)|0,e=e+Math.imul(M,ht)|0;var _t=(a+(h=h+Math.imul(m,et)|0)|0)+((8191&(n=(n=n+Math.imul(m,ot)|0)+Math.imul(f,et)|0))<<13)|0;a=((e=e+Math.imul(f,ot)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,h=Math.imul(L,F),n=(n=Math.imul(L,C))+Math.imul(I,F)|0,e=Math.imul(I,C),h=h+Math.imul(q,H)|0,n=(n=n+Math.imul(q,J)|0)+Math.imul(B,H)|0,e=e+Math.imul(B,J)|0,h=h+Math.imul(S,G)|0,n=(n=n+Math.imul(S,Q)|0)+Math.imul(Z,G)|0,e=e+Math.imul(Z,Q)|0,h=h+Math.imul(k,W)|0,n=(n=n+Math.imul(k,X)|0)+Math.imul(A,W)|0,e=e+Math.imul(A,X)|0,h=h+Math.imul(y,$)|0,n=(n=n+Math.imul(y,tt)|0)+Math.imul(b,$)|0,e=e+Math.imul(b,tt)|0,h=h+Math.imul(g,rt)|0,n=(n=n+Math.imul(g,ht)|0)+Math.imul(c,rt)|0,e=e+Math.imul(c,ht)|0,h=h+Math.imul(p,et)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(M,et)|0,e=e+Math.imul(M,ot)|0;var kt=(a+(h=h+Math.imul(m,ut)|0)|0)+((8191&(n=(n=n+Math.imul(m,at)|0)+Math.imul(f,ut)|0))<<13)|0;a=((e=e+Math.imul(f,at)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h=Math.imul(z,F),n=(n=Math.imul(z,C))+Math.imul(E,F)|0,e=Math.imul(E,C),h=h+Math.imul(L,H)|0,n=(n=n+Math.imul(L,J)|0)+Math.imul(I,H)|0,e=e+Math.imul(I,J)|0,h=h+Math.imul(q,G)|0,n=(n=n+Math.imul(q,Q)|0)+Math.imul(B,G)|0,e=e+Math.imul(B,Q)|0,h=h+Math.imul(S,W)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(Z,W)|0,e=e+Math.imul(Z,X)|0,h=h+Math.imul(k,$)|0,n=(n=n+Math.imul(k,tt)|0)+Math.imul(A,$)|0,e=e+Math.imul(A,tt)|0,h=h+Math.imul(y,rt)|0,n=(n=n+Math.imul(y,ht)|0)+Math.imul(b,rt)|0,e=e+Math.imul(b,ht)|0,h=h+Math.imul(g,et)|0,n=(n=n+Math.imul(g,ot)|0)+Math.imul(c,et)|0,e=e+Math.imul(c,ot)|0,h=h+Math.imul(p,ut)|0,n=(n=n+Math.imul(p,at)|0)+Math.imul(M,ut)|0,e=e+Math.imul(M,at)|0;var At=(a+(h=h+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,ft)|0)+Math.imul(f,mt)|0))<<13)|0;a=((e=e+Math.imul(f,ft)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,h=Math.imul(j,F),n=(n=Math.imul(j,C))+Math.imul(K,F)|0,e=Math.imul(K,C),h=h+Math.imul(z,H)|0,n=(n=n+Math.imul(z,J)|0)+Math.imul(E,H)|0,e=e+Math.imul(E,J)|0,h=h+Math.imul(L,G)|0,n=(n=n+Math.imul(L,Q)|0)+Math.imul(I,G)|0,e=e+Math.imul(I,Q)|0,h=h+Math.imul(q,W)|0,n=(n=n+Math.imul(q,X)|0)+Math.imul(B,W)|0,e=e+Math.imul(B,X)|0,h=h+Math.imul(S,$)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(Z,$)|0,e=e+Math.imul(Z,tt)|0,h=h+Math.imul(k,rt)|0,n=(n=n+Math.imul(k,ht)|0)+Math.imul(A,rt)|0,e=e+Math.imul(A,ht)|0,h=h+Math.imul(y,et)|0,n=(n=n+Math.imul(y,ot)|0)+Math.imul(b,et)|0,e=e+Math.imul(b,ot)|0,h=h+Math.imul(g,ut)|0,n=(n=n+Math.imul(g,at)|0)+Math.imul(c,ut)|0,e=e+Math.imul(c,at)|0,h=h+Math.imul(p,mt)|0,n=(n=n+Math.imul(p,ft)|0)+Math.imul(M,mt)|0,e=e+Math.imul(M,ft)|0;var xt=(a+(h=h+Math.imul(m,pt)|0)|0)+((8191&(n=(n=n+Math.imul(m,Mt)|0)+Math.imul(f,pt)|0))<<13)|0;a=((e=e+Math.imul(f,Mt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,h=Math.imul(j,H),n=(n=Math.imul(j,J))+Math.imul(K,H)|0,e=Math.imul(K,J),h=h+Math.imul(z,G)|0,n=(n=n+Math.imul(z,Q)|0)+Math.imul(E,G)|0,e=e+Math.imul(E,Q)|0,h=h+Math.imul(L,W)|0,n=(n=n+Math.imul(L,X)|0)+Math.imul(I,W)|0,e=e+Math.imul(I,X)|0,h=h+Math.imul(q,$)|0,n=(n=n+Math.imul(q,tt)|0)+Math.imul(B,$)|0,e=e+Math.imul(B,tt)|0,h=h+Math.imul(S,rt)|0,n=(n=n+Math.imul(S,ht)|0)+Math.imul(Z,rt)|0,e=e+Math.imul(Z,ht)|0,h=h+Math.imul(k,et)|0,n=(n=n+Math.imul(k,ot)|0)+Math.imul(A,et)|0,e=e+Math.imul(A,ot)|0,h=h+Math.imul(y,ut)|0,n=(n=n+Math.imul(y,at)|0)+Math.imul(b,ut)|0,e=e+Math.imul(b,at)|0,h=h+Math.imul(g,mt)|0,n=(n=n+Math.imul(g,ft)|0)+Math.imul(c,mt)|0,e=e+Math.imul(c,ft)|0;var St=(a+(h=h+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,Mt)|0)+Math.imul(M,pt)|0))<<13)|0;a=((e=e+Math.imul(M,Mt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,h=Math.imul(j,G),n=(n=Math.imul(j,Q))+Math.imul(K,G)|0,e=Math.imul(K,Q),h=h+Math.imul(z,W)|0,n=(n=n+Math.imul(z,X)|0)+Math.imul(E,W)|0,e=e+Math.imul(E,X)|0,h=h+Math.imul(L,$)|0,n=(n=n+Math.imul(L,tt)|0)+Math.imul(I,$)|0,e=e+Math.imul(I,tt)|0,h=h+Math.imul(q,rt)|0,n=(n=n+Math.imul(q,ht)|0)+Math.imul(B,rt)|0,e=e+Math.imul(B,ht)|0,h=h+Math.imul(S,et)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(Z,et)|0,e=e+Math.imul(Z,ot)|0,h=h+Math.imul(k,ut)|0,n=(n=n+Math.imul(k,at)|0)+Math.imul(A,ut)|0,e=e+Math.imul(A,at)|0,h=h+Math.imul(y,mt)|0,n=(n=n+Math.imul(y,ft)|0)+Math.imul(b,mt)|0,e=e+Math.imul(b,ft)|0;var Zt=(a+(h=h+Math.imul(g,pt)|0)|0)+((8191&(n=(n=n+Math.imul(g,Mt)|0)+Math.imul(c,pt)|0))<<13)|0;a=((e=e+Math.imul(c,Mt)|0)+(n>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,h=Math.imul(j,W),n=(n=Math.imul(j,X))+Math.imul(K,W)|0,e=Math.imul(K,X),h=h+Math.imul(z,$)|0,n=(n=n+Math.imul(z,tt)|0)+Math.imul(E,$)|0,e=e+Math.imul(E,tt)|0,h=h+Math.imul(L,rt)|0,n=(n=n+Math.imul(L,ht)|0)+Math.imul(I,rt)|0,e=e+Math.imul(I,ht)|0,h=h+Math.imul(q,et)|0,n=(n=n+Math.imul(q,ot)|0)+Math.imul(B,et)|0,e=e+Math.imul(B,ot)|0,h=h+Math.imul(S,ut)|0,n=(n=n+Math.imul(S,at)|0)+Math.imul(Z,ut)|0,e=e+Math.imul(Z,at)|0,h=h+Math.imul(k,mt)|0,n=(n=n+Math.imul(k,ft)|0)+Math.imul(A,mt)|0,e=e+Math.imul(A,ft)|0;var Rt=(a+(h=h+Math.imul(y,pt)|0)|0)+((8191&(n=(n=n+Math.imul(y,Mt)|0)+Math.imul(b,pt)|0))<<13)|0;a=((e=e+Math.imul(b,Mt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,h=Math.imul(j,$),n=(n=Math.imul(j,tt))+Math.imul(K,$)|0,e=Math.imul(K,tt),h=h+Math.imul(z,rt)|0,n=(n=n+Math.imul(z,ht)|0)+Math.imul(E,rt)|0,e=e+Math.imul(E,ht)|0,h=h+Math.imul(L,et)|0,n=(n=n+Math.imul(L,ot)|0)+Math.imul(I,et)|0,e=e+Math.imul(I,ot)|0,h=h+Math.imul(q,ut)|0,n=(n=n+Math.imul(q,at)|0)+Math.imul(B,ut)|0,e=e+Math.imul(B,at)|0,h=h+Math.imul(S,mt)|0,n=(n=n+Math.imul(S,ft)|0)+Math.imul(Z,mt)|0,e=e+Math.imul(Z,ft)|0;var qt=(a+(h=h+Math.imul(k,pt)|0)|0)+((8191&(n=(n=n+Math.imul(k,Mt)|0)+Math.imul(A,pt)|0))<<13)|0;a=((e=e+Math.imul(A,Mt)|0)+(n>>>13)|0)+(qt>>>26)|0,qt&=67108863,h=Math.imul(j,rt),n=(n=Math.imul(j,ht))+Math.imul(K,rt)|0,e=Math.imul(K,ht),h=h+Math.imul(z,et)|0,n=(n=n+Math.imul(z,ot)|0)+Math.imul(E,et)|0,e=e+Math.imul(E,ot)|0,h=h+Math.imul(L,ut)|0,n=(n=n+Math.imul(L,at)|0)+Math.imul(I,ut)|0,e=e+Math.imul(I,at)|0,h=h+Math.imul(q,mt)|0,n=(n=n+Math.imul(q,ft)|0)+Math.imul(B,mt)|0,e=e+Math.imul(B,ft)|0;var Bt=(a+(h=h+Math.imul(S,pt)|0)|0)+((8191&(n=(n=n+Math.imul(S,Mt)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((e=e+Math.imul(Z,Mt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,h=Math.imul(j,et),n=(n=Math.imul(j,ot))+Math.imul(K,et)|0,e=Math.imul(K,ot),h=h+Math.imul(z,ut)|0,n=(n=n+Math.imul(z,at)|0)+Math.imul(E,ut)|0,e=e+Math.imul(E,at)|0,h=h+Math.imul(L,mt)|0,n=(n=n+Math.imul(L,ft)|0)+Math.imul(I,mt)|0,e=e+Math.imul(I,ft)|0;var Nt=(a+(h=h+Math.imul(q,pt)|0)|0)+((8191&(n=(n=n+Math.imul(q,Mt)|0)+Math.imul(B,pt)|0))<<13)|0;a=((e=e+Math.imul(B,Mt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,h=Math.imul(j,ut),n=(n=Math.imul(j,at))+Math.imul(K,ut)|0,e=Math.imul(K,at),h=h+Math.imul(z,mt)|0,n=(n=n+Math.imul(z,ft)|0)+Math.imul(E,mt)|0,e=e+Math.imul(E,ft)|0;var Lt=(a+(h=h+Math.imul(L,pt)|0)|0)+((8191&(n=(n=n+Math.imul(L,Mt)|0)+Math.imul(I,pt)|0))<<13)|0;a=((e=e+Math.imul(I,Mt)|0)+(n>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,h=Math.imul(j,mt),n=(n=Math.imul(j,ft))+Math.imul(K,mt)|0,e=Math.imul(K,ft);var It=(a+(h=h+Math.imul(z,pt)|0)|0)+((8191&(n=(n=n+Math.imul(z,Mt)|0)+Math.imul(E,pt)|0))<<13)|0;a=((e=e+Math.imul(E,Mt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863;var Tt=(a+(h=Math.imul(j,pt))|0)+((8191&(n=(n=Math.imul(j,Mt))+Math.imul(K,pt)|0))<<13)|0;return a=((e=Math.imul(K,Mt))+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,u[0]=vt,u[1]=gt,u[2]=ct,u[3]=wt,u[4]=yt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=At,u[9]=xt,u[10]=St,u[11]=Zt,u[12]=Rt,u[13]=qt,u[14]=Bt,u[15]=Nt,u[16]=Lt,u[17]=It,u[18]=Tt,0!==a&&(u[19]=a,r.length++),r};function M(t,i,r){return (new v).mulp(t,i,r)}function v(t,r){(this||i$3).x=t,(this||i$3).y=r;}Math.imul||(p=d),o.prototype.mulTo=function(t,r){var h=(this||i$3).length+t.length;return 10===(this||i$3).length&&10===t.length?p(this||i$3,t,r):h<63?d(this||i$3,t,r):h<1024?function(t,i,r){r.negative=i.negative^t.negative,r.length=t.length+i.length;for(var h=0,n=0,e=0;e>>26)|0)>>>26,o&=67108863;}r.words[e]=s,h=o,o=n;}return 0!==h?r.words[e]=h:r.length--,r.strip()}(this||i$3,t,r):M(this||i$3,t,r)},v.prototype.makeRBT=function(t){for(var i=new Array(t),r=o.prototype._countBits(t)-1,h=0;h>=1;return h},v.prototype.permute=function(t,i,r,h,n,e){for(var o=0;o>>=1)n++;return 1<>>=13,r[2*o+1]=8191&e,e>>>=13;for(o=2*i;o>=26,r+=e/67108864|0,r+=o>>>26,(this||i$3).words[h]=67108863&o;}return 0!==r&&((this||i$3).words[h]=r,(this||i$3).length++),this||i$3},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this||i$3)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var r=function(t){for(var i=new Array(t.bitLength()),r=0;r>>n;}return i}(t);if(0===r.length)return new o(1);for(var h=this||i$3,n=0;n=0);var r,h=t%26,e=(t-h)/26,o=67108863>>>26-h<<26-h;if(0!==h){var s=0;for(r=0;r<(this||i$3).length;r++){var u=(this||i$3).words[r]&o,a=(0|(this||i$3).words[r])-u<>>26-h;}s&&((this||i$3).words[r]=s,(this||i$3).length++);}if(0!==e){for(r=(this||i$3).length-1;r>=0;r--)(this||i$3).words[r+e]=(this||i$3).words[r];for(r=0;r=0),e=r?(r-r%26)/26:0;var o=t%26,s=Math.min((t-o)/26,(this||i$3).length),u=67108863^67108863>>>o<s)for((this||i$3).length-=s,l=0;l<(this||i$3).length;l++)(this||i$3).words[l]=(this||i$3).words[l+s];else (this||i$3).words[0]=0,(this||i$3).length=1;var m=0;for(l=(this||i$3).length-1;l>=0&&(0!==m||l>=e);l--){var f=0|(this||i$3).words[l];(this||i$3).words[l]=m<<26-o|f>>>o,m=f&u;}return a&&0!==m&&(a.words[a.length++]=m),0===(this||i$3).length&&((this||i$3).words[0]=0,(this||i$3).length=1),this.strip()},o.prototype.ishrn=function(t,r,h){return n(0===(this||i$3).negative),this.iushrn(t,r,h)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){n("number"==typeof t&&t>=0);var r=t%26,h=(t-r)/26,e=1<=0);var r=t%26,h=(t-r)/26;if(n(0===(this||i$3).negative,"imaskn works only with positive numbers"),(this||i$3).length<=h)return this||i$3;if(0!==r&&h++,(this||i$3).length=Math.min(h,(this||i$3).length),0!==r){var e=67108863^67108863>>>r<=67108864;r++)(this||i$3).words[r]-=67108864,r===(this||i$3).length-1?(this||i$3).words[r+1]=1:(this||i$3).words[r+1]++;return (this||i$3).length=Math.max((this||i$3).length,r+1),this||i$3},o.prototype.isubn=function(t){if(n("number"==typeof t),n(t<67108864),t<0)return this.iaddn(-t);if(0!==(this||i$3).negative)return (this||i$3).negative=0,this.iaddn(t),(this||i$3).negative=1,this||i$3;if((this||i$3).words[0]-=t,1===(this||i$3).length&&(this||i$3).words[0]<0)(this||i$3).words[0]=-(this||i$3).words[0],(this||i$3).negative=1;else for(var r=0;r<(this||i$3).length&&(this||i$3).words[r]<0;r++)(this||i$3).words[r]+=67108864,(this||i$3).words[r+1]-=1;return this.strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return (this||i$3).negative=0,this||i$3},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,r,h){var e,o,s=t.length+h;this._expand(s);var u=0;for(e=0;e>26)-(a/67108864|0),(this||i$3).words[e+h]=67108863&o;}for(;e<(this||i$3).length-h;e++)u=(o=(0|(this||i$3).words[e+h])+u)>>26,(this||i$3).words[e+h]=67108863&o;if(0===u)return this.strip();for(n(-1===u),u=0,e=0;e<(this||i$3).length;e++)u=(o=-(0|(this||i$3).words[e])+u)>>26,(this||i$3).words[e]=67108863&o;return (this||i$3).negative=1,this.strip()},o.prototype._wordDiv=function(t,r){var h=((this||i$3).length,t.length),n=this.clone(),e=t,s=0|e.words[e.length-1];0!==(h=26-this._countBits(s))&&(e=e.ushln(h),n.iushln(h),s=0|e.words[e.length-1]);var u,a=n.length-e.length;if("mod"!==r){(u=new o(null)).length=a+1,u.words=new Array(u.length);for(var l=0;l=0;f--){var d=67108864*(0|n.words[e.length+f])+(0|n.words[e.length+f-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(e,d,f);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(e,1,f),n.isZero()||(n.negative^=1);u&&(u.words[f]=d);}return u&&u.strip(),n.strip(),"div"!==r&&0!==h&&n.iushrn(h),{div:u||null,mod:n}},o.prototype.divmod=function(t,r,h){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==(this||i$3).negative&&0===t.negative?(u=this.neg().divmod(t,r),"mod"!==r&&(e=u.div.neg()),"div"!==r&&(s=u.mod.neg(),h&&0!==s.negative&&s.iadd(t)),{div:e,mod:s}):0===(this||i$3).negative&&0!==t.negative?(u=this.divmod(t.neg(),r),"mod"!==r&&(e=u.div.neg()),{div:e,mod:u.mod}):0!=((this||i$3).negative&t.negative)?(u=this.neg().divmod(t.neg(),r),"div"!==r&&(s=u.mod.neg(),h&&0!==s.negative&&s.isub(t)),{div:u.div,mod:s}):t.length>(this||i$3).length||this.cmp(t)<0?{div:new o(0),mod:this||i$3}:1===t.length?"div"===r?{div:this.divn(t.words[0]),mod:null}:"mod"===r?{div:null,mod:new o(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modn(t.words[0]))}:this._wordDiv(t,r);var e,s,u;},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var r=0!==i.div.negative?i.mod.isub(t):i.mod,h=t.ushrn(1),n=t.andln(1),e=r.cmp(h);return e<0||1===n&&0===e?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},o.prototype.modn=function(t){n(t<=67108863);for(var r=(1<<26)%t,h=0,e=(this||i$3).length-1;e>=0;e--)h=(r*h+(0|(this||i$3).words[e]))%t;return h},o.prototype.idivn=function(t){n(t<=67108863);for(var r=0,h=(this||i$3).length-1;h>=0;h--){var e=(0|(this||i$3).words[h])+67108864*r;(this||i$3).words[h]=e/t|0,r=e%t;}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var r=this||i$3,h=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var e=new o(1),s=new o(0),u=new o(0),a=new o(1),l=0;r.isEven()&&h.isEven();)r.iushrn(1),h.iushrn(1),++l;for(var m=h.clone(),f=r.clone();!r.isZero();){for(var d=0,p=1;0==(r.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(r.iushrn(d);d-- >0;)(e.isOdd()||s.isOdd())&&(e.iadd(m),s.isub(f)),e.iushrn(1),s.iushrn(1);for(var M=0,v=1;0==(h.words[0]&v)&&M<26;++M,v<<=1);if(M>0)for(h.iushrn(M);M-- >0;)(u.isOdd()||a.isOdd())&&(u.iadd(m),a.isub(f)),u.iushrn(1),a.iushrn(1);r.cmp(h)>=0?(r.isub(h),e.isub(u),s.isub(a)):(h.isub(r),u.isub(e),a.isub(s));}return {a:u,b:a,gcd:h.iushln(l)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var r=this||i$3,h=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var e,s=new o(1),u=new o(0),a=h.clone();r.cmpn(1)>0&&h.cmpn(1)>0;){for(var l=0,m=1;0==(r.words[0]&m)&&l<26;++l,m<<=1);if(l>0)for(r.iushrn(l);l-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);for(var f=0,d=1;0==(h.words[0]&d)&&f<26;++f,d<<=1);if(f>0)for(h.iushrn(f);f-- >0;)u.isOdd()&&u.iadd(a),u.iushrn(1);r.cmp(h)>=0?(r.isub(h),s.isub(u)):(h.isub(r),u.isub(s));}return (e=0===r.cmpn(1)?s:u).cmpn(0)<0&&e.iadd(t),e},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),r=t.clone();i.negative=0,r.negative=0;for(var h=0;i.isEven()&&r.isEven();h++)i.iushrn(1),r.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=i.cmp(r);if(n<0){var e=i;i=r,r=e;}else if(0===n||0===r.cmpn(1))break;i.isub(r);}return r.iushln(h)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&(this||i$3).words[0])},o.prototype.isOdd=function(){return 1==(1&(this||i$3).words[0])},o.prototype.andln=function(t){return (this||i$3).words[0]&t},o.prototype.bincn=function(t){n("number"==typeof t);var r=t%26,h=(t-r)/26,e=1<>>26,u&=67108863,(this||i$3).words[s]=u;}return 0!==o&&((this||i$3).words[s]=o,(this||i$3).length++),this||i$3},o.prototype.isZero=function(){return 1===(this||i$3).length&&0===(this||i$3).words[0]},o.prototype.cmpn=function(t){var r,h=t<0;if(0!==(this||i$3).negative&&!h)return -1;if(0===(this||i$3).negative&&h)return 1;if(this.strip(),(this||i$3).length>1)r=1;else {h&&(t=-t),n(t<=67108863,"Number is too big");var e=0|(this||i$3).words[0];r=e===t?0:et.length)return 1;if((this||i$3).length=0;h--){var n=0|(this||i$3).words[h],e=0|t.words[h];if(n!==e){ne&&(r=1);break}}return r},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return -1===this.cmpn(t)},o.prototype.lt=function(t){return -1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new k(t)},o.prototype.toRed=function(t){return n(!(this||i$3).red,"Already a number in reduction context"),n(0===(this||i$3).negative,"red works only with positives"),t.convertTo(this||i$3)._forceRed(t)},o.prototype.fromRed=function(){return n((this||i$3).red,"fromRed works only with numbers in reduction context"),(this||i$3).red.convertFrom(this||i$3)},o.prototype._forceRed=function(t){return (this||i$3).red=t,this||i$3},o.prototype.forceRed=function(t){return n(!(this||i$3).red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n((this||i$3).red,"redAdd works only with red numbers"),(this||i$3).red.add(this||i$3,t)},o.prototype.redIAdd=function(t){return n((this||i$3).red,"redIAdd works only with red numbers"),(this||i$3).red.iadd(this||i$3,t)},o.prototype.redSub=function(t){return n((this||i$3).red,"redSub works only with red numbers"),(this||i$3).red.sub(this||i$3,t)},o.prototype.redISub=function(t){return n((this||i$3).red,"redISub works only with red numbers"),(this||i$3).red.isub(this||i$3,t)},o.prototype.redShl=function(t){return n((this||i$3).red,"redShl works only with red numbers"),(this||i$3).red.shl(this||i$3,t)},o.prototype.redMul=function(t){return n((this||i$3).red,"redMul works only with red numbers"),(this||i$3).red._verify2(this||i$3,t),(this||i$3).red.mul(this||i$3,t)},o.prototype.redIMul=function(t){return n((this||i$3).red,"redMul works only with red numbers"),(this||i$3).red._verify2(this||i$3,t),(this||i$3).red.imul(this||i$3,t)},o.prototype.redSqr=function(){return n((this||i$3).red,"redSqr works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.sqr(this||i$3)},o.prototype.redISqr=function(){return n((this||i$3).red,"redISqr works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.isqr(this||i$3)},o.prototype.redSqrt=function(){return n((this||i$3).red,"redSqrt works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.sqrt(this||i$3)},o.prototype.redInvm=function(){return n((this||i$3).red,"redInvm works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.invm(this||i$3)},o.prototype.redNeg=function(){return n((this||i$3).red,"redNeg works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.neg(this||i$3)},o.prototype.redPow=function(t){return n((this||i$3).red&&!t.red,"redPow(normalNum)"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.pow(this||i$3,t)};var g={k256:null,p224:null,p192:null,p25519:null};function c(t,r){(this||i$3).name=t,(this||i$3).p=new o(r,16),(this||i$3).n=(this||i$3).p.bitLength(),(this||i$3).k=new o(1).iushln((this||i$3).n).isub((this||i$3).p),(this||i$3).tmp=this._tmp();}function w(){c.call(this||i$3,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");}function y(){c.call(this||i$3,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");}function b(){c.call(this||i$3,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");}function _(){c.call(this||i$3,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");}function k(t){if("string"==typeof t){var r=o._prime(t);(this||i$3).m=r.p,(this||i$3).prime=r;}else n(t.gtn(1),"modulus must be greater than 1"),(this||i$3).m=t,(this||i$3).prime=null;}function A(t){k.call(this||i$3,t),(this||i$3).shift=(this||i$3).m.bitLength(),(this||i$3).shift%26!=0&&((this||i$3).shift+=26-(this||i$3).shift%26),(this||i$3).r=new o(1).iushln((this||i$3).shift),(this||i$3).r2=this.imod((this||i$3).r.sqr()),(this||i$3).rinv=(this||i$3).r._invmp((this||i$3).m),(this||i$3).minv=(this||i$3).rinv.mul((this||i$3).r).isubn(1).div((this||i$3).m),(this||i$3).minv=(this||i$3).minv.umod((this||i$3).r),(this||i$3).minv=(this||i$3).r.sub((this||i$3).minv);}c.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil((this||i$3).n/13)),t},c.prototype.ireduce=function(t){var r,h=t;do{this.split(h,(this||i$3).tmp),r=(h=(h=this.imulK(h)).iadd((this||i$3).tmp)).bitLength();}while(r>(this||i$3).n);var n=r<(this||i$3).n?-1:h.ucmp((this||i$3).p);return 0===n?(h.words[0]=0,h.length=1):n>0?h.isub((this||i$3).p):h.strip(),h},c.prototype.split=function(t,r){t.iushrn((this||i$3).n,0,r);},c.prototype.imulK=function(t){return t.imul((this||i$3).k)},e(w,c),w.prototype.split=function(t,i){for(var r=Math.min(t.length,9),h=0;h>>22,n=e;}n>>>=22,t.words[h-10]=n,0===n&&t.length>10?t.length-=10:t.length-=9;},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,r=0;r>>=26,t.words[r]=n,i=h;}return 0!==i&&(t.words[t.length++]=i),t},o._prime=function(t){if(g[t])return g[t];var i;if("k256"===t)i=new w;else if("p224"===t)i=new y;else if("p192"===t)i=new b;else {if("p25519"!==t)throw new Error("Unknown prime "+t);i=new _;}return g[t]=i,i},k.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers");},k.prototype._verify2=function(t,i){n(0==(t.negative|i.negative),"red works only with positives"),n(t.red&&t.red===i.red,"red works only with red numbers");},k.prototype.imod=function(t){return (this||i$3).prime?(this||i$3).prime.ireduce(t)._forceRed(this||i$3):t.umod((this||i$3).m)._forceRed(this||i$3)},k.prototype.neg=function(t){return t.isZero()?t.clone():(this||i$3).m.sub(t)._forceRed(this||i$3)},k.prototype.add=function(t,r){this._verify2(t,r);var h=t.add(r);return h.cmp((this||i$3).m)>=0&&h.isub((this||i$3).m),h._forceRed(this||i$3)},k.prototype.iadd=function(t,r){this._verify2(t,r);var h=t.iadd(r);return h.cmp((this||i$3).m)>=0&&h.isub((this||i$3).m),h},k.prototype.sub=function(t,r){this._verify2(t,r);var h=t.sub(r);return h.cmpn(0)<0&&h.iadd((this||i$3).m),h._forceRed(this||i$3)},k.prototype.isub=function(t,r){this._verify2(t,r);var h=t.isub(r);return h.cmpn(0)<0&&h.iadd((this||i$3).m),h},k.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},k.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},k.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},k.prototype.isqr=function(t){return this.imul(t,t.clone())},k.prototype.sqr=function(t){return this.mul(t,t)},k.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=(this||i$3).m.andln(3);if(n(r%2==1),3===r){var h=(this||i$3).m.add(new o(1)).iushrn(2);return this.pow(t,h)}for(var e=(this||i$3).m.subn(1),s=0;!e.isZero()&&0===e.andln(1);)s++,e.iushrn(1);n(!e.isZero());var u=new o(1).toRed(this||i$3),a=u.redNeg(),l=(this||i$3).m.subn(1).iushrn(1),m=(this||i$3).m.bitLength();for(m=new o(2*m*m).toRed(this||i$3);0!==this.pow(m,l).cmp(a);)m.redIAdd(a);for(var f=this.pow(m,e),d=this.pow(t,e.addn(1).iushrn(1)),p=this.pow(t,e),M=s;0!==p.cmp(u);){for(var v=p,g=0;0!==v.cmp(u);g++)v=v.redSqr();n(g=0;n--){for(var l=r.words[n],m=a-1;m>=0;m--){var f=l>>m&1;e!==h[0]&&(e=this.sqr(e)),0!==f||0!==s?(s<<=1,s|=f,(4===++u||0===n&&0===m)&&(e=this.mul(e,h[s]),u=0,s=0)):u=0;}a=26;}return e},k.prototype.convertTo=function(t){var r=t.umod((this||i$3).m);return r===t?r.clone():r},k.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},o.mont=function(t){return new A(t)},e(A,k),A.prototype.convertTo=function(t){return this.imod(t.ushln((this||i$3).shift))},A.prototype.convertFrom=function(t){var r=this.imod(t.mul((this||i$3).rinv));return r.red=null,r},A.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var h=t.imul(r),n=h.maskn((this||i$3).shift).mul((this||i$3).minv).imaskn((this||i$3).shift).mul((this||i$3).m),e=h.isub(n).iushrn((this||i$3).shift),o=e;return e.cmp((this||i$3).m)>=0?o=e.isub((this||i$3).m):e.cmpn(0)<0&&(o=e.iadd((this||i$3).m)),o._forceRed(this||i$3)},A.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new o(0)._forceRed(this||i$3);var h=t.mul(r),n=h.maskn((this||i$3).shift).mul((this||i$3).minv).imaskn((this||i$3).shift).mul((this||i$3).m),e=h.isub(n).iushrn((this||i$3).shift),s=e;return e.cmp((this||i$3).m)>=0?s=e.isub((this||i$3).m):e.cmpn(0)<0&&(s=e.iadd((this||i$3).m)),s._forceRed(this||i$3)},A.prototype.invm=function(t){return this.imod(t._invmp((this||i$3).m).mul((this||i$3).r2))._forceRed(this||i$3)};}(h$a,r$7);var n$c=h$a.exports;var t$5,e$a,r$8=Object.freeze({}),n$d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function o$d(t){(this||n$d).rand=t;}if((t$5=function(t){return e$a||(e$a=new o$d(null)),e$a.generate(t)}).Rand=o$d,o$d.prototype.generate=function(t){return this._rand(t)},o$d.prototype._rand=function(t){if((this||n$d).rand.getBytes)return (this||n$d).rand.getBytes(t);for(var e=new Uint8Array(t),r=0;r=0);return a},d$b.prototype._randrange=function(r,e){var n=e.sub(r);return r.add(this._randbelow(n))},d$b.prototype.test=function(r,e,n){var t=r.bitLength(),a=o$e.mont(r),d=new o$e(1).toRed(a);e||(e=Math.max(1,t/48|0));for(var i=r.subn(1),f=0;!i.testn(f);f++);for(var u=r.shrn(f),p=i.toRed(a);e>0;e--){var c=this._randrange(new o$e(2),i);n&&n(c);var s=c.toRed(a).redPow(u);if(0!==s.cmp(d)&&0!==s.cmp(p)){for(var m=1;m0;e--){var p=this._randrange(new o$e(2),d),c=r.gcd(p);if(0!==c.cmpn(1))return c;var s=p.toRed(t).redPow(f);if(0!==s.cmp(a)&&0!==s.cmp(u)){for(var m=1;mf;)c.ishrn(1);if(c.isEven()&&c.iadd(i$5),c.testn(1)||c.iadd(o$f),e.cmp(o$f)){if(!e.cmp(p$e))for(;c.mod(s$c).cmp(m$9);)c.iadd(h$b);}else for(;c.mod(t$7).cmp(u$b);)c.iadd(h$b);if(_$9(a=c.shrn(1))&&_$9(c)&&g$8(a)&&g$8(c)&&n$f.test(a)&&n$f.test(c))return c}}var y$9,P$2=b$7,B$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,K$2=e$1$1$1.Buffer,R$1=n$c,S$5=new i$4,x$2=new R$1(24),C$2=new R$1(11),D$2=new R$1(10),G$1=new R$1(3),H$2=new R$1(7),T$3=P$2,j$1=a;function E$6(f,e){return e=e||"utf8",K$2.isBuffer(f)||(f=new K$2(f,e)),(this||B$5)._pub=new R$1(f),this||B$5}function L$1(f,e){return e=e||"utf8",K$2.isBuffer(f)||(f=new K$2(f,e)),(this||B$5)._priv=new R$1(f),this||B$5}y$9=k$7;var M$4={};function k$7(f,e,c){this.setGenerator(e),(this||B$5).__prime=new R$1(f),(this||B$5)._prime=R$1.mont((this||B$5).__prime),(this||B$5)._primeLen=f.length,(this||B$5)._pub=void 0,(this||B$5)._priv=void 0,(this||B$5)._primeCode=void 0,c?((this||B$5).setPublicKey=E$6,(this||B$5).setPrivateKey=L$1):(this||B$5)._primeCode=8;}function A$5(f,e){var c=new K$2(f.toArray());return e?c.toString(e):c}Object.defineProperty(k$7.prototype,"verifyError",{enumerable:!0,get:function(){return "number"!=typeof(this||B$5)._primeCode&&((this||B$5)._primeCode=function(f,e){var c=e.toString("hex"),a=[c,f.toString(16)].join("_");if(a in M$4)return M$4[a];var b,d=0;if(f.isEven()||!T$3.simpleSieve||!T$3.fermatTest(f)||!S$5.test(f))return d+=1,d+="02"===c||"05"===c?8:4,M$4[a]=d,d;switch(S$5.test(f.shrn(1))||(d+=2),c){case"02":f.mod(x$2).cmp(C$2)&&(d+=8);break;case"05":(b=f.mod(D$2)).cmp(G$1)&&b.cmp(H$2)&&(d+=8);break;default:d+=4;}return M$4[a]=d,d}((this||B$5).__prime,(this||B$5).__gen)),(this||B$5)._primeCode}}),k$7.prototype.generateKeys=function(){return (this||B$5)._priv||((this||B$5)._priv=new R$1(j$1((this||B$5)._primeLen))),(this||B$5)._pub=(this||B$5)._gen.toRed((this||B$5)._prime).redPow((this||B$5)._priv).fromRed(),this.getPublicKey()},k$7.prototype.computeSecret=function(f){var e=(f=(f=new R$1(f)).toRed((this||B$5)._prime)).redPow((this||B$5)._priv).fromRed(),c=new K$2(e.toArray()),a=this.getPrime();if(c.length=0||!r.umod(e.prime1)||!r.umod(e.prime2);)r=new n$g(d$d(o));return r}m$a=t$8,t$8.getr=i$6;var l$d=m$a;var r$a={},e$b=r$a;function t$9(r){return 1===r.length?"0"+r:r}function n$h(r){for(var e="",n=0;n>8,f=255&o;u?t.push(u,f):t.push(f);}return t},e$b.zero2=t$9,e$b.toHex=n$h,e$b.encode=function(r,e){return "hex"===e?n$h(r):r};var n$i={},a$g=n$i,i$7=n$c,o$g=o$7,c$d=r$a;a$g.assert=o$g,a$g.toArray=c$d.toArray,a$g.zero2=c$d.zero2,a$g.toHex=c$d.toHex,a$g.encode=c$d.encode,a$g.getNAF=function(r,t,e){var n=new Array(Math.max(r.bitLength(),e)+1);n.fill(0);for(var a=1<(a>>1)-1?(a>>1)-s:s,i.isubn(c)):c=0,n[o]=c,i.iushrn(1);}return n},a$g.getJSF=function(r,t){var e=[[],[]];r=r.clone(),t=t.clone();for(var n=0,a=0;r.cmpn(-n)>0||t.cmpn(-a)>0;){var i,o,c,s=r.andln(3)+n&3,l=t.andln(3)+a&3;if(3===s&&(s=-1),3===l&&(l=-1),0==(1&s))i=0;else i=3!==(c=r.andln(7)+n&7)&&5!==c||2!==l?s:-s;if(e[0].push(i),0==(1&l))o=0;else o=3!==(c=t.andln(7)+a&7)&&5!==c||2!==s?l:-l;e[1].push(o),2*n===i+1&&(n=1-n),2*a===o+1&&(a=1-a),r.iushrn(1),t.iushrn(1);}return e},a$g.cachedProperty=function(r,t,e){var n="_"+t;r.prototype[t]=function(){return void 0!==this[n]?this[n]:this[n]=e.call(this)};},a$g.parseBytes=function(r){return "string"==typeof r?a$g.toArray(r,"hex"):r},a$g.intFromLE=function(r){return new i$7(r,"hex","le")};var s$d,l$e=n$c,u$d=n$i,h$c=u$d.assert;function p$f(r,t){if(r instanceof p$f)return r;this._importDER(r,t)||(h$c(r.r&&r.s,"Signature without r or s"),this.r=new l$e(r.r,16),this.s=new l$e(r.s,16),void 0===r.recoveryParam?this.recoveryParam=null:this.recoveryParam=r.recoveryParam);}function f$j(){this.place=0;}function v$a(r,t){var e=r[t.place++];if(!(128&e))return e;for(var n=15&e,a=0,i=0,o=t.place;i>>3);for(r.push(128|e);--e;)r.push(t>>>(e<<3)&255);r.push(t);}s$d=p$f,p$f.prototype._importDER=function(r,t){r=u$d.toArray(r,t);var e=new f$j;if(48!==r[e.place++])return !1;if(v$a(r,e)+e.place!==r.length)return !1;if(2!==r[e.place++])return !1;var n=v$a(r,e),a=r.slice(e.place,n+e.place);if(e.place+=n,2!==r[e.place++])return !1;var i=v$a(r,e);if(r.length!==i+e.place)return !1;var o=r.slice(e.place,i+e.place);return 0===a[0]&&128&a[1]&&(a=a.slice(1)),0===o[0]&&128&o[1]&&(o=o.slice(1)),this.r=new l$e(a),this.s=new l$e(o),this.recoveryParam=null,!0},p$f.prototype.toDER=function(r){var t=this.r.toArray(),e=this.s.toArray();for(128&t[0]&&(t=[0].concat(t)),128&e[0]&&(e=[0].concat(e)),t=m$b(t),e=m$b(e);!(e[0]||128&e[1]);)e=e.slice(1);var n=[2];y$a(n,t.length),(n=n.concat(t)).push(2),y$a(n,e.length);var a=n.concat(e),i=[48];return y$a(i,a.length),i=i.concat(a),u$d.encode(i,r)};var d$e=s$d;var r$b={},i$8=o$7,e$c=t$2$2;function h$d(t,n){return 55296==(64512&t.charCodeAt(n))&&(!(n<0||n+1>=t.length)&&56320==(64512&t.charCodeAt(n+1)))}function o$h(t){return (t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function u$e(t){return 1===t.length?"0"+t:t}function s$e(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}r$b.inherits=e$c,r$b.toArray=function(t,n){if(Array.isArray(t))return t.slice();if(!t)return [];var r=[];if("string"==typeof t)if(n){if("hex"===n)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),e=0;e>6|192,r[i++]=63&o|128):h$d(t,e)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++e)),r[i++]=o>>18|240,r[i++]=o>>12&63|128,r[i++]=o>>6&63|128,r[i++]=63&o|128):(r[i++]=o>>12|224,r[i++]=o>>6&63|128,r[i++]=63&o|128);}else for(e=0;e>>0;}return o},r$b.split32=function(t,n){for(var r=new Array(4*t.length),i=0,e=0;i>>24,r[e+1]=h>>>16&255,r[e+2]=h>>>8&255,r[e+3]=255&h):(r[e+3]=h>>>24,r[e+2]=h>>>16&255,r[e+1]=h>>>8&255,r[e]=255&h);}return r},r$b.rotr32=function(t,n){return t>>>n|t<<32-n},r$b.rotl32=function(t,n){return t<>>32-n},r$b.sum32=function(t,n){return t+n>>>0},r$b.sum32_3=function(t,n,r){return t+n+r>>>0},r$b.sum32_4=function(t,n,r,i){return t+n+r+i>>>0},r$b.sum32_5=function(t,n,r,i,e){return t+n+r+i+e>>>0},r$b.sum64=function(t,n,r,i){var e=t[n],h=i+t[n+1]>>>0,o=(h>>0,t[n+1]=h;},r$b.sum64_hi=function(t,n,r,i){return (n+i>>>0>>0},r$b.sum64_lo=function(t,n,r,i){return n+i>>>0},r$b.sum64_4_hi=function(t,n,r,i,e,h,o,u){var s=0,a=n;return s+=(a=a+i>>>0)>>0)>>0)>>0},r$b.sum64_4_lo=function(t,n,r,i,e,h,o,u){return n+i+h+u>>>0},r$b.sum64_5_hi=function(t,n,r,i,e,h,o,u,s,a){var l=0,g=n;return l+=(g=g+i>>>0)>>0)>>0)>>0)>>0},r$b.sum64_5_lo=function(t,n,r,i,e,h,o,u,s,a){return n+i+h+u+a>>>0},r$b.rotr64_hi=function(t,n,r){return (n<<32-r|t>>>r)>>>0},r$b.rotr64_lo=function(t,n,r){return (t<<32-r|n>>>r)>>>0},r$b.shr64_hi=function(t,n,r){return t>>>r},r$b.shr64_lo=function(t,n,r){return (t<<32-r|n>>>r)>>>0};var a$h={},l$f=r$b,g$9=o$7;function c$e(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32;}a$h.BlockHash=c$e,c$e.prototype.update=function(t,n){if(t=l$f.toArray(t,n),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=l$f.join32(t,0,t.length-r,this.endian);for(var i=0;i>>24&255,i[e++]=t>>>16&255,i[e++]=t>>>8&255,i[e++]=255&t;}else for(i[e++]=255&t,i[e++]=t>>>8&255,i[e++]=t>>>16&255,i[e++]=t>>>24&255,i[e++]=0,i[e++]=0,i[e++]=0,i[e++]=0,h=8;h>>3},s$g.g1_256=function(t){return n$k(t,17)^n$k(t,19)^t>>>10};var u$g,a$j=r$b,c$g=a$h,f$l=s$g,_$b=o$7,g$b=a$j.sum32,m$d=a$j.sum32_4,p$h=a$j.sum32_5,l$h=f$l.ch32,v$c=f$l.maj32,d$g=f$l.s0_256,k$9=f$l.s1_256,b$9=f$l.g0_256,j$3=f$l.g1_256,x$4=c$g.BlockHash,y$c=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function S$7(){if(!(this instanceof S$7))return new S$7;x$4.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=y$c,this.W=new Array(64);}a$j.inherits(S$7,x$4),u$g=S$7,S$7.blockSize=512,S$7.outSize=256,S$7.hmacStrength=192,S$7.padLength=64,S$7.prototype._update=function(t,h){for(var i=this.W,s=0;s<16;s++)i[s]=t[h+s];for(;sthis.blockSize&&(t=(new this.Hash).update(t).digest()),T$4(t.length<=this.blockSize);for(var h=t.length;h=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,i,s);}s$h=o$l,o$l.prototype._init=function(t,e,i){var s=t.concat(e).concat(i);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var h=0;h=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(i||[])),this._reseed=1;},o$l.prototype.generate=function(t,e,i,s){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(s=i,i=e,e=null),i&&(i=r$f.toArray(i,s||"hex"),this._update(i));for(var h=[];h.length0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red));}function p$j(e,f){this.curve=e,this.type=f,this.precomputed=null;}b$b=h$f,h$f.prototype.point=function(){throw new Error("Not implemented")},h$f.prototype.validate=function(){throw new Error("Not implemented")},h$f.prototype._fixedNafMul=function(e,f){u$i(e.precomputed);var d=e._getDoubles(),c=s$i(f,1,this._bitLength),t=(1<=r;f--)b=(b<<1)+c[f];a.push(b);}for(var i=this.jpoint(null,null,null),n=this.jpoint(null,null,null),o=t;o>0;o--){for(r=0;r=0;b--){for(f=0;b>=0&&0===a[b];b--)f++;if(b>=0&&f++,r=r.dblp(f),b<0)break;var i=a[b];u$i(0!==i),r="affine"===e.type?i>0?r.mixedAdd(t[i-1>>1]):r.mixedAdd(t[-i-1>>1].neg()):i>0?r.add(t[i-1>>1]):r.add(t[-i-1>>1].neg());}return "affine"===e.type?r.toP():r},h$f.prototype._wnafMulAdd=function(e,f,d,c,t){for(var a=this._wnafT1,r=this._wnafT2,b=this._wnafT3,i=0,n=0;n=1;n-=2){var h=n-1,p=n;if(1===a[h]&&1===a[p]){var l=[f[h],null,null,f[p]];0===f[h].y.cmp(f[p].y)?(l[1]=f[h].add(f[p]),l[2]=f[h].toJ().mixedAdd(f[p].neg())):0===f[h].y.cmp(f[p].y.redNeg())?(l[1]=f[h].toJ().mixedAdd(f[p]),l[2]=f[h].add(f[p].neg())):(l[1]=f[h].toJ().mixedAdd(f[p]),l[2]=f[h].toJ().mixedAdd(f[p].neg()));var v=[-3,-1,-5,-7,0,7,5,1,3],y=o$m(d[h],d[p]);i=Math.max(y[0].length,i),b[h]=new Array(i),b[p]=new Array(i);for(var m=0;m=0;n--){for(var w=0;n>=0;){var M=!0;for(m=0;m=0&&w++,A=A.dblp(w),n<0)break;for(m=0;m0?x=r[m][_-1>>1]:_<0&&(x=r[m][-_-1>>1].neg()),A="affine"===x.type?A.mixedAdd(x):A.add(x));}}for(n=0;n=Math.ceil((e.bitLength()+1)/f.step)},p$j.prototype._getDoubles=function(e,f){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var d=[this],c=this,t=0;t=0&&(a=f,r=d),c.negative&&(c=c.neg(),t=t.neg()),a.negative&&(a=a.neg(),r=r.neg()),[{a:c,b:t},{a,b:r}]},A$8.prototype._endoSplit=function(e){var f=this.endo.basis,d=f[0],c=f[1],t=c.b.mul(e).divRound(this.n),a=d.b.neg().mul(e).divRound(this.n),r=t.mul(d.a),b=a.mul(c.a),i=t.mul(d.b),n=a.mul(c.b);return {k1:e.sub(r).sub(b),k2:i.add(n).neg()}},A$8.prototype.pointFromX=function(e,f){(e=new y$e(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),c=d.redSqrt();if(0!==c.redSqr().redSub(d).cmp(this.zero))throw new Error("invalid point");var t=c.fromRed().isOdd();return (f&&!t||!f&&t)&&(c=c.redNeg()),this.point(e,c)},A$8.prototype.validate=function(e){if(e.inf)return !0;var f=e.x,d=e.y,c=this.a.redMul(f),t=f.redSqr().redMul(f).redIAdd(c).redIAdd(this.b);return 0===d.redSqr().redISub(t).cmpn(0)},A$8.prototype._endoWnafMulAdd=function(e,f,d){for(var c=this._endoWnafT1,t=this._endoWnafT2,a=0;a":""},I$8.prototype.isInfinity=function(){return this.inf},I$8.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var f=this.y.redSub(e.y);0!==f.cmpn(0)&&(f=f.redMul(this.x.redSub(e.x).redInvm()));var d=f.redSqr().redISub(this.x).redISub(e.x),c=f.redMul(this.x.redSub(d)).redISub(this.y);return this.curve.point(d,c)},I$8.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var f=this.curve.a,d=this.x.redSqr(),c=e.redInvm(),t=d.redAdd(d).redIAdd(d).redIAdd(f).redMul(c),a=t.redSqr().redISub(this.x.redAdd(this.x)),r=t.redMul(this.x.redSub(a)).redISub(this.y);return this.curve.point(a,r)},I$8.prototype.getX=function(){return this.x.fromRed()},I$8.prototype.getY=function(){return this.y.fromRed()},I$8.prototype.mul=function(e){return e=new y$e(e,16),this.isInfinity()?this:this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},I$8.prototype.mulAdd=function(e,f,d){var c=[this,f],t=[e,d];return this.curve.endo?this.curve._endoWnafMulAdd(c,t):this.curve._wnafMulAdd(1,c,t,2)},I$8.prototype.jmulAdd=function(e,f,d){var c=[this,f],t=[e,d];return this.curve.endo?this.curve._endoWnafMulAdd(c,t,!0):this.curve._wnafMulAdd(1,c,t,2,!0)},I$8.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},I$8.prototype.neg=function(e){if(this.inf)return this;var f=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var d=this.precomputed,c=function(e){return e.neg()};f.precomputed={naf:d.naf&&{wnd:d.naf.wnd,points:d.naf.points.map(c)},doubles:d.doubles&&{step:d.doubles.step,points:d.doubles.points.map(c)}};}return f},I$8.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},m$f(w$e,S$9.BasePoint),A$8.prototype.jpoint=function(e,f,d){return new w$e(this,e,f,d)},w$e.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),f=e.redSqr(),d=this.x.redMul(f),c=this.y.redMul(f).redMul(e);return this.curve.point(d,c)},w$e.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},w$e.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var f=e.z.redSqr(),d=this.z.redSqr(),c=this.x.redMul(f),t=e.x.redMul(d),a=this.y.redMul(f.redMul(e.z)),r=e.y.redMul(d.redMul(this.z)),b=c.redSub(t),i=a.redSub(r);if(0===b.cmpn(0))return 0!==i.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var n=b.redSqr(),s=n.redMul(b),o=c.redMul(n),u=i.redSqr().redIAdd(s).redISub(o).redISub(o),h=i.redMul(o.redISub(u)).redISub(a.redMul(s)),p=this.z.redMul(e.z).redMul(b);return this.curve.jpoint(u,h,p)},w$e.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var f=this.z.redSqr(),d=this.x,c=e.x.redMul(f),t=this.y,a=e.y.redMul(f).redMul(this.z),r=d.redSub(c),b=t.redSub(a);if(0===r.cmpn(0))return 0!==b.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var i=r.redSqr(),n=i.redMul(r),s=d.redMul(i),o=b.redSqr().redIAdd(n).redISub(s).redISub(s),u=b.redMul(s.redISub(o)).redISub(t.redMul(n)),h=this.z.redMul(r);return this.curve.jpoint(o,u,h)},w$e.prototype.dblp=function(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var f=this,d=0;d=0)return !1;if(d.redIAdd(t),0===this.x.cmp(d))return !0}},w$e.prototype.inspect=function(){return this.isInfinity()?"":""},w$e.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var M$6,x$6=l$j,_$d=n$c,z$6=t$2$2,q$4=v$e,R$3=n$i;function P$4(e){q$4.call(this,"mont",e),this.a=new _$d(e.a,16).toRed(this.red),this.b=new _$d(e.b,16).toRed(this.red),this.i4=new _$d(4).toRed(this.red).redInvm(),this.two=new _$d(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two));}function j$5(e,f,d){q$4.BasePoint.call(this,e,"projective"),null===f&&null===d?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new _$d(f,16),this.z=new _$d(d,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)));}z$6(P$4,q$4),M$6=P$4,P$4.prototype.validate=function(e){var f=e.normalize().x,d=f.redSqr(),c=d.redMul(f).redAdd(d.redMul(this.a)).redAdd(f);return 0===c.redSqrt().redSqr().cmp(c)},z$6(j$5,q$4.BasePoint),P$4.prototype.decodePoint=function(e,f){return this.point(R$3.toArray(e,f),1)},P$4.prototype.point=function(e,f){return new j$5(this,e,f)},P$4.prototype.pointFromJSON=function(e){return j$5.fromJSON(this,e)},j$5.prototype.precompute=function(){},j$5.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},j$5.fromJSON=function(e,f){return new j$5(e,f[0],f[1]||e.one)},j$5.prototype.inspect=function(){return this.isInfinity()?"":""},j$5.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},j$5.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),f=this.x.redSub(this.z).redSqr(),d=e.redSub(f),c=e.redMul(f),t=d.redMul(f.redAdd(this.curve.a24.redMul(d)));return this.curve.point(c,t)},j$5.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},j$5.prototype.diffAdd=function(e,f){var d=this.x.redAdd(this.z),c=this.x.redSub(this.z),t=e.x.redAdd(e.z),a=e.x.redSub(e.z).redMul(d),r=t.redMul(c),b=f.z.redMul(a.redAdd(r).redSqr()),i=f.x.redMul(a.redISub(r).redSqr());return this.curve.point(b,i)},j$5.prototype.mul=function(e){for(var f=e.clone(),d=this,c=this.curve.point(null,null),t=[];0!==f.cmpn(0);f.iushrn(1))t.push(f.andln(1));for(var a=t.length-1;a>=0;a--)0===t[a]?(d=d.diffAdd(c,this),c=c.dbl()):(c=d.diffAdd(c,this),d=d.dbl());return c},j$5.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},j$5.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},j$5.prototype.eq=function(e){return 0===this.getX().cmp(e.getX())},j$5.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},j$5.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var N$4,E$8=M$6,k$b=n$c,O$5=t$2$2,L$4=v$e,B$8=n$i.assert;function F$5(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,L$4.call(this,"edwards",e),this.a=new k$b(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new k$b(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new k$b(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),B$8(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|e.c);}function C$5(e,f,d,c,t){L$4.BasePoint.call(this,e,"projective"),null===f&&null===d&&null===c?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new k$b(f,16),this.y=new k$b(d,16),this.z=c?new k$b(c,16):this.curve.one,this.t=t&&new k$b(t,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))));}O$5(F$5,L$4),N$4=F$5,F$5.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},F$5.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},F$5.prototype.jpoint=function(e,f,d,c){return this.point(e,f,d,c)},F$5.prototype.pointFromX=function(e,f){(e=new k$b(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr(),c=this.c2.redSub(this.a.redMul(d)),t=this.one.redSub(this.c2.redMul(this.d).redMul(d)),a=c.redMul(t.redInvm()),r=a.redSqrt();if(0!==r.redSqr().redSub(a).cmp(this.zero))throw new Error("invalid point");var b=r.fromRed().isOdd();return (f&&!b||!f&&b)&&(r=r.redNeg()),this.point(e,r)},F$5.prototype.pointFromY=function(e,f){(e=new k$b(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr(),c=d.redSub(this.c2),t=d.redMul(this.d).redMul(this.c2).redSub(this.a),a=c.redMul(t.redInvm());if(0===a.cmp(this.zero)){if(f)throw new Error("invalid point");return this.point(this.zero,e)}var r=a.redSqrt();if(0!==r.redSqr().redSub(a).cmp(this.zero))throw new Error("invalid point");return r.fromRed().isOdd()!==f&&(r=r.redNeg()),this.point(r,e)},F$5.prototype.validate=function(e){if(e.isInfinity())return !0;e.normalize();var f=e.x.redSqr(),d=e.y.redSqr(),c=f.redMul(this.a).redAdd(d),t=this.c2.redMul(this.one.redAdd(this.d.redMul(f).redMul(d)));return 0===c.cmp(t)},O$5(C$5,L$4.BasePoint),F$5.prototype.pointFromJSON=function(e){return C$5.fromJSON(this,e)},F$5.prototype.point=function(e,f,d,c){return new C$5(this,e,f,d,c)},C$5.fromJSON=function(e,f){return new C$5(e,f[0],f[1],f[2])},C$5.prototype.inspect=function(){return this.isInfinity()?"":""},C$5.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},C$5.prototype._extDbl=function(){var e=this.x.redSqr(),f=this.y.redSqr(),d=this.z.redSqr();d=d.redIAdd(d);var c=this.curve._mulA(e),t=this.x.redAdd(this.y).redSqr().redISub(e).redISub(f),a=c.redAdd(f),r=a.redSub(d),b=c.redSub(f),i=t.redMul(r),n=a.redMul(b),s=t.redMul(b),o=r.redMul(a);return this.curve.point(i,n,o,s)},C$5.prototype._projDbl=function(){var e,f,d,c=this.x.redAdd(this.y).redSqr(),t=this.x.redSqr(),a=this.y.redSqr();if(this.curve.twisted){var r=(n=this.curve._mulA(t)).redAdd(a);if(this.zOne)e=c.redSub(t).redSub(a).redMul(r.redSub(this.curve.two)),f=r.redMul(n.redSub(a)),d=r.redSqr().redSub(r).redSub(r);else {var b=this.z.redSqr(),i=r.redSub(b).redISub(b);e=c.redSub(t).redISub(a).redMul(i),f=r.redMul(n.redSub(a)),d=r.redMul(i);}}else {var n=t.redAdd(a);b=this.curve._mulC(this.z).redSqr(),i=n.redSub(b).redSub(b);e=this.curve._mulC(c.redISub(n)).redMul(i),f=this.curve._mulC(n).redMul(t.redISub(a)),d=n.redMul(i);}return this.curve.point(e,f,d)},C$5.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},C$5.prototype._extAdd=function(e){var f=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),d=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),c=this.t.redMul(this.curve.dd).redMul(e.t),t=this.z.redMul(e.z.redAdd(e.z)),a=d.redSub(f),r=t.redSub(c),b=t.redAdd(c),i=d.redAdd(f),n=a.redMul(r),s=b.redMul(i),o=a.redMul(i),u=r.redMul(b);return this.curve.point(n,s,u,o)},C$5.prototype._projAdd=function(e){var f,d,c=this.z.redMul(e.z),t=c.redSqr(),a=this.x.redMul(e.x),r=this.y.redMul(e.y),b=this.curve.d.redMul(a).redMul(r),i=t.redSub(b),n=t.redAdd(b),s=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(a).redISub(r),o=c.redMul(i).redMul(s);return this.curve.twisted?(f=c.redMul(n).redMul(r.redSub(this.curve._mulA(a))),d=i.redMul(n)):(f=c.redMul(n).redMul(r.redSub(a)),d=this.curve._mulC(i).redMul(n)),this.curve.point(o,f,d)},C$5.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},C$5.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},C$5.prototype.mulAdd=function(e,f,d){return this.curve._wnafMulAdd(1,[this,f],[e,d],2,!1)},C$5.prototype.jmulAdd=function(e,f,d){return this.curve._wnafMulAdd(1,[this,f],[e,d],2,!0)},C$5.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),this.z=this.curve.one,this.zOne=!0,this},C$5.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},C$5.prototype.getX=function(){return this.normalize(),this.x.fromRed()},C$5.prototype.getY=function(){return this.normalize(),this.y.fromRed()},C$5.prototype.eq=function(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},C$5.prototype.eqXToP=function(e){var f=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(f))return !0;for(var d=e.clone(),c=this.curve.redN.redMul(this.z);;){if(d.iadd(this.curve.n),d.cmp(this.curve.p)>=0)return !1;if(f.redIAdd(c),0===this.x.cmp(f))return !0}},C$5.prototype.toP=C$5.prototype.normalize,C$5.prototype.mixedAdd=C$5.prototype.add;var T$5=N$4,J$3={},X$3=J$3;X$3.base=v$e,X$3.short=x$6,X$3.mont=E$8,X$3.edwards=T$5;var D$4,Y$2={doubles:{step:4,points:[["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a","f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"],["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508","11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"],["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739","d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"],["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640","4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"],["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c","4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"],["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda","96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"],["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa","5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"],["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0","cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"],["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d","9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"],["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d","e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"],["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1","9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"],["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0","5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"],["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047","10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"],["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862","283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"],["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7","7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"],["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd","56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"],["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83","7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"],["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a","53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"],["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8","bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"],["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d","4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"],["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725","7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"],["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754","4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"],["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c","17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"],["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6","6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"],["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39","c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"],["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891","893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"],["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b","febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"],["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03","2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"],["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d","eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"],["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070","7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"],["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4","e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"],["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da","662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"],["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11","1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"],["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e","efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"],["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41","2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"],["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef","67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"],["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8","db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"],["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d","648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"],["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96","35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"],["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd","ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"],["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5","9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"],["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266","40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"],["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71","34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"],["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac","c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"],["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751","1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"],["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e","493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"],["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241","c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"],["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3","be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"],["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f","4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"],["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19","aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"],["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be","b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"],["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9","6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"],["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2","8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"],["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13","7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"],["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c","ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"],["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba","2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"],["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151","e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"],["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073","d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"],["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458","38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"],["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b","69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"],["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366","d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"],["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa","40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"],["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0","620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"],["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787","7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"],["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e","ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]]},naf:{wnd:7,points:[["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9","388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"],["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4","d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"],["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc","6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"],["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe","cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"],["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb","d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"],["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8","ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"],["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e","581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"],["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34","4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"],["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c","85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"],["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5","321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"],["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"],["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714","73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"],["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729","a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"],["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db","2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"],["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4","e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"],["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5","b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"],["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479","2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"],["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d","80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"],["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f","1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"],["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb","d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"],["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9","eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"],["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963","758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"],["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74","958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"],["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530","e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"],["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b","5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"],["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247","cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"],["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1","cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"],["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120","4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"],["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435","91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"],["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18","673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"],["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8","59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"],["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb","3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"],["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f","55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"],["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143","efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"],["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba","e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"],["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45","f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"],["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a","744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"],["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e","c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"],["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8","e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"],["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c","30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"],["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519","e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"],["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab","100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"],["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca","ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"],["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf","8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"],["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610","68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"],["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4","f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"],["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c","d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"],["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940","edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"],["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980","a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"],["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3","66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"],["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf","9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"],["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63","4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"],["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448","fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"],["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf","5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"],["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5","8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"],["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6","8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"],["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5","5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"],["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99","f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"],["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51","f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"],["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5","42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"],["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5","204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"],["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997","4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"],["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881","73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"],["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5","39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"],["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66","d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"],["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726","ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"],["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede","6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"],["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94","60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"],["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31","3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"],["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51","b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"],["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252","ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"],["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5","cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"],["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b","6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"],["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4","322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"],["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f","6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"],["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889","2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"],["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246","b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"],["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984","998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"],["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a","b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"],["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030","bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"],["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197","6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"],["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593","c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"],["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef","21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"],["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38","60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"],["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a","49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"],["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111","5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"],["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502","7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"],["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea","be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"],["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26","8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"],["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986","39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"],["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e","62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"],["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4","25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"],["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda","ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"],["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859","cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"],["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f","f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"],["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c","6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"],["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942","fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"],["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a","1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"],["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80","5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"],["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d","438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"],["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1","cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"],["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63","c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"],["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352","6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"],["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193","ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"],["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00","9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"],["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58","ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"],["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7","d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"],["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8","c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"],["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e","67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"],["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d","cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"],["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b","299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"],["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f","f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"],["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6","462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"],["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297","62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"],["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a","7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"],["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c","ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"],["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52","4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"],["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb","bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"],["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065","bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"],["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917","603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"],["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9","cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"],["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3","553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"],["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57","712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"],["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66","ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"],["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8","9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"],["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721","9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"],["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180","4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]]}},W$3={},K$4=W$3,U$6=X$2,G$3=J$3,H$5=n$i.assert;function Q$2(e){"short"===e.type?this.curve=new G$3.short(e):"edwards"===e.type?this.curve=new G$3.edwards(e):this.curve=new G$3.mont(e),this.g=this.curve.g,this.n=this.curve.n,this.hash=e.hash,H$5(this.g.validate(),"Invalid curve"),H$5(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O");}function V$3(e,f){Object.defineProperty(K$4,e,{configurable:!0,enumerable:!0,get:function(){var d=new Q$2(f);return Object.defineProperty(K$4,e,{configurable:!0,enumerable:!0,value:d}),d}});}K$4.PresetCurve=Q$2,V$3("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:U$6.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),V$3("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:U$6.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),V$3("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:U$6.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),V$3("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:U$6.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),V$3("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:U$6.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),V$3("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:U$6.sha256,gRed:!1,g:["9"]}),V$3("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:U$6.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{D$4=Y$2;}catch(e){D$4=void 0;}V$3("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:U$6.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",D$4]});var Z$1,$$1=n$c,ee=n$i.assert;function fe(e,f){this.ec=e,this.priv=null,this.pub=null,f.priv&&this._importPrivate(f.priv,f.privEnc),f.pub&&this._importPublic(f.pub,f.pubEnc);}Z$1=fe,fe.fromPublic=function(e,f,d){return f instanceof fe?f:new fe(e,{pub:f,pubEnc:d})},fe.fromPrivate=function(e,f,d){return f instanceof fe?f:new fe(e,{priv:f,privEnc:d})},fe.prototype.validate=function(){var e=this.getPublic();return e.isInfinity()?{result:!1,reason:"Invalid public key"}:e.validate()?e.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},fe.prototype.getPublic=function(e,f){return "string"==typeof e&&(f=e,e=null),this.pub||(this.pub=this.ec.g.mul(this.priv)),f?this.pub.encode(f,e):this.pub},fe.prototype.getPrivate=function(e){return "hex"===e?this.priv.toString(16,2):this.priv},fe.prototype._importPrivate=function(e,f){this.priv=new $$1(e,f||16),this.priv=this.priv.umod(this.ec.curve.n);},fe.prototype._importPublic=function(e,f){if(e.x||e.y)return "mont"===this.ec.curve.type?ee(e.x,"Need x coordinate"):"short"!==this.ec.curve.type&&"edwards"!==this.ec.curve.type||ee(e.x&&e.y,"Need both x and y coordinate"),this.pub=this.ec.curve.point(e.x,e.y),void 0;this.pub=this.ec.curve.decodePoint(e,f);},fe.prototype.derive=function(e){return e.mul(this.priv).getX()},fe.prototype.sign=function(e,f,d){return this.ec.sign(e,this,f,d)},fe.prototype.verify=function(e,f){return this.ec.verify(e,f,this)},fe.prototype.inspect=function(){return ""};var de,ce=Z$1,te=n$c,ae=a$l,re=W$3,be=f$i,ie=n$i.assert,ne=ce,se=d$e;function oe(e){if(!(this instanceof oe))return new oe(e);"string"==typeof e&&(ie(re.hasOwnProperty(e),"Unknown curve "+e),e=re[e]),e instanceof re.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash;}de=oe,oe.prototype.keyPair=function(e){return new ne(this,e)},oe.prototype.keyFromPrivate=function(e,f){return ne.fromPrivate(this,e,f)},oe.prototype.keyFromPublic=function(e,f){return ne.fromPublic(this,e,f)},oe.prototype.genKeyPair=function(e){e||(e={});for(var f=new ae({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||be(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()}),d=this.n.byteLength(),c=this.n.sub(new te(2));;){var t=new te(f.generate(d));if(!(t.cmp(c)>0))return t.iaddn(1),this.keyFromPrivate(t);}},oe.prototype._truncateToN=function(e,f){var d=8*e.byteLength()-this.n.bitLength();return d>0&&(e=e.ushrn(d)),!f&&e.cmp(this.n)>=0?e.sub(this.n):e},oe.prototype.sign=function(e,f,d,c){"object"==typeof d&&(c=d,d=null),c||(c={}),f=this.keyFromPrivate(f,d),e=this._truncateToN(new te(e,16));for(var t=this.n.byteLength(),a=f.getPrivate().toArray("be",t),r=e.toArray("be",t),b=new ae({hash:this.hash,entropy:a,nonce:r,pers:c.pers,persEnc:c.persEnc||"utf8"}),i=this.n.sub(new te(1)),n=0;;n++){var s=c.k?c.k(n):new te(b.generate(this.n.byteLength()));if(!((s=this._truncateToN(s,!0)).cmpn(1)<=0||s.cmp(i)>=0)){var o=this.g.mul(s);if(!o.isInfinity()){var u=o.getX(),h=u.umod(this.n);if(0!==h.cmpn(0)){var p=s.invm(this.n).mul(h.mul(f.getPrivate()).iadd(e));if(0!==(p=p.umod(this.n)).cmpn(0)){var l=(o.getY().isOdd()?1:0)|(0!==u.cmp(h)?2:0);return c.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),l^=1),new se({r:h,s:p,recoveryParam:l})}}}}}},oe.prototype.verify=function(e,f,d,c){e=this._truncateToN(new te(e,16)),d=this.keyFromPublic(d,c);var t=(f=new se(f,"hex")).r,a=f.s;if(t.cmpn(1)<0||t.cmp(this.n)>=0)return !1;if(a.cmpn(1)<0||a.cmp(this.n)>=0)return !1;var r,b=a.invm(this.n),i=b.mul(e).umod(this.n),n=b.mul(t).umod(this.n);return this.curve._maxwellTrick?!(r=this.g.jmulAdd(i,d.getPublic(),n)).isInfinity()&&r.eqXToP(t):!(r=this.g.mulAdd(i,d.getPublic(),n)).isInfinity()&&0===r.getX().umod(this.n).cmp(t)},oe.prototype.recoverPubKey=function(e,f,d,c){ie((3&d)===d,"The recovery param is more than two bits"),f=new se(f,c);var t=this.n,a=new te(e),r=f.r,b=f.s,i=1&d,n=d>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&n)throw new Error("Unable to find sencond key candinate");r=n?this.curve.pointFromX(r.add(this.curve.n),i):this.curve.pointFromX(r,i);var s=f.r.invm(t),o=t.sub(a).mul(s).umod(t),u=b.mul(s).umod(t);return this.g.mulAdd(o,r,u)},oe.prototype.getKeyRecoveryParam=function(e,f,d,c){if(null!==(f=new se(f,c)).recoveryParam)return f.recoveryParam;for(var t=0;t<4;t++){var a;try{a=this.recoverPubKey(e,f,t);}catch(e){continue}if(a.eq(d))return t}throw new Error("Unable to find valid recovery factor")};var ue=de,he=n$i,pe=he.assert,le=he.parseBytes,ve=he.cachedProperty;function ye(e,f){this.eddsa=e,this._secret=le(f.secret),e.isPoint(f.pub)?this._pub=f.pub:this._pubBytes=le(f.pub);}ye.fromPublic=function(e,f){return f instanceof ye?f:new ye(e,{pub:f})},ye.fromSecret=function(e,f){return f instanceof ye?f:new ye(e,{secret:f})},ye.prototype.secret=function(){return this._secret},ve(ye,"pubBytes",(function(){return this.eddsa.encodePoint(this.pub())})),ve(ye,"pub",(function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())})),ve(ye,"privBytes",(function(){var e=this.eddsa,f=this.hash(),d=e.encodingLength-1,c=f.slice(0,e.encodingLength);return c[0]&=248,c[d]&=127,c[d]|=64,c})),ve(ye,"priv",(function(){return this.eddsa.decodeInt(this.privBytes())})),ve(ye,"hash",(function(){return this.eddsa.hash().update(this.secret()).digest()})),ve(ye,"messagePrefix",(function(){return this.hash().slice(this.eddsa.encodingLength)})),ye.prototype.sign=function(e){return pe(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)},ye.prototype.verify=function(e,f){return this.eddsa.verify(e,f,this)},ye.prototype.getSecret=function(e){return pe(this._secret,"KeyPair is public only"),he.encode(this.secret(),e)},ye.prototype.getPublic=function(e){return he.encode(this.pubBytes(),e)};var me=ye,Se=n$c,ge=n$i,Ae=ge.assert,Ie=ge.cachedProperty,we=ge.parseBytes;function Me(e,f){this.eddsa=e,"object"!=typeof f&&(f=we(f)),Array.isArray(f)&&(f={R:f.slice(0,e.encodingLength),S:f.slice(e.encodingLength)}),Ae(f.R&&f.S,"Signature without R or S"),e.isPoint(f.R)&&(this._R=f.R),f.S instanceof Se&&(this._S=f.S),this._Rencoded=Array.isArray(f.R)?f.R:f.Rencoded,this._Sencoded=Array.isArray(f.S)?f.S:f.Sencoded;}Ie(Me,"S",(function(){return this.eddsa.decodeInt(this.Sencoded())})),Ie(Me,"R",(function(){return this.eddsa.decodePoint(this.Rencoded())})),Ie(Me,"Rencoded",(function(){return this.eddsa.encodePoint(this.R())})),Ie(Me,"Sencoded",(function(){return this.eddsa.encodeInt(this.S())})),Me.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},Me.prototype.toHex=function(){return ge.encode(this.toBytes(),"hex").toUpperCase()};var xe,_e=Me,ze=X$2,qe=W$3,Re=n$i,Pe=Re.assert,je=Re.parseBytes,Ne=me,Ee=_e;function ke(e){if(Pe("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof ke))return new ke(e);e=qe[e].curve;this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=ze.sha512;}xe=ke,ke.prototype.sign=function(e,f){e=je(e);var d=this.keyFromSecret(f),c=this.hashInt(d.messagePrefix(),e),t=this.g.mul(c),a=this.encodePoint(t),r=this.hashInt(a,d.pubBytes(),e).mul(d.priv()),b=c.add(r).umod(this.curve.n);return this.makeSignature({R:t,S:b,Rencoded:a})},ke.prototype.verify=function(e,f,d){e=je(e),f=this.makeSignature(f);var c=this.keyFromPublic(d),t=this.hashInt(f.Rencoded(),c.pubBytes(),e),a=this.g.mul(f.S());return f.R().add(c.pub().mul(t)).eq(a)},ke.prototype.hashInt=function(){for(var e=this.hash(),f=0;f","MIT",{url:"https://github.com/indutny/elliptic/issues"},"https://github.com/indutny/elliptic",{brfs:"^1.4.3",coveralls:"^3.0.8",grunt:"^1.0.4","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.2",jscs:"^3.0.7",jshint:"^2.10.3",mocha:"^6.2.2"},{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"}][1],Be.utils=n$i,Be.rand=f$i,Be.curve=J$3,Be.curves=W$3,Be.ec=ue,Be.eddsa=Oe; +var o$n={},s$j=!1,a$m="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;var u$j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,c$i={},f$n=t$2$2;function l$k(e){(this||u$j)._reporterState={obj:null,path:[],options:e||{},errors:[]};}function h$g(e,t){(this||u$j).path=e,this.rethrow(t);}c$i.Reporter=l$k,l$k.prototype.isError=function(e){return e instanceof h$g},l$k.prototype.save=function(){var e=(this||u$j)._reporterState;return {obj:e.obj,pathLen:e.path.length}},l$k.prototype.restore=function(e){var t=(this||u$j)._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen);},l$k.prototype.enterKey=function(e){return (this||u$j)._reporterState.path.push(e)},l$k.prototype.exitKey=function(e){var t=(this||u$j)._reporterState;t.path=t.path.slice(0,e-1);},l$k.prototype.leaveKey=function(e,t,r){var n=(this||u$j)._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r);},l$k.prototype.path=function(){return (this||u$j)._reporterState.path.join("/")},l$k.prototype.enterObject=function(){var e=(this||u$j)._reporterState,t=e.obj;return e.obj={},t},l$k.prototype.leaveObject=function(e){var t=(this||u$j)._reporterState,r=t.obj;return t.obj=e,r},l$k.prototype.error=function(e){var t,r=(this||u$j)._reporterState,n=e instanceof h$g;if(t=n?e:new h$g(r.path.map((function(e){return "["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!r.options.partial)throw t;return n||r.errors.push(t),t},l$k.prototype.wrapResult=function(e){var t=(this||u$j)._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},f$n(h$g,Error),h$g.prototype.rethrow=function(e){if((this||u$j).message=e+" at: "+((this||u$j).path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this||u$j,h$g),!(this||u$j).stack)try{throw new Error((this||u$j).message)}catch(e){(this||u$j).stack=e.stack;}return this||u$j};var p$k={},d$i=!1,g$e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function y$f(){if(d$i)return p$k;d$i=!0;var e=t$2$2,r=E$9().Reporter,i=e$1$1$1.Buffer;function o(e,t){if(r.call(this||g$e,t),!i.isBuffer(e))return this.error("Input not Buffer"),void 0;(this||g$e).base=e,(this||g$e).offset=0,(this||g$e).length=e.length;}function s(e,t){if(Array.isArray(e))(this||g$e).length=0,(this||g$e).value=e.map((function(e){return e instanceof s||(e=new s(e,t)),(this||g$e).length+=e.length,e}),this||g$e);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");(this||g$e).value=e,(this||g$e).length=1;}else if("string"==typeof e)(this||g$e).value=e,(this||g$e).length=i.byteLength(e);else {if(!i.isBuffer(e))return t.error("Unsupported type: "+typeof e);(this||g$e).value=e,(this||g$e).length=e.length;}}return e(o,r),p$k.DecoderBuffer=o,o.prototype.save=function(){return {offset:(this||g$e).offset,reporter:r.prototype.save.call(this||g$e)}},o.prototype.restore=function(e){var t=new o((this||g$e).base);return t.offset=e.offset,t.length=(this||g$e).offset,(this||g$e).offset=e.offset,r.prototype.restore.call(this||g$e,e.reporter),t},o.prototype.isEmpty=function(){return (this||g$e).offset===(this||g$e).length},o.prototype.readUInt8=function(e){return (this||g$e).offset+1<=(this||g$e).length?(this||g$e).base.readUInt8((this||g$e).offset++,!0):this.error(e||"DecoderBuffer overrun")},o.prototype.skip=function(e,t){if(!((this||g$e).offset+e<=(this||g$e).length))return this.error(t||"DecoderBuffer overrun");var r=new o((this||g$e).base);return r._reporterState=(this||g$e)._reporterState,r.offset=(this||g$e).offset,r.length=(this||g$e).offset+e,(this||g$e).offset+=e,r},o.prototype.raw=function(e){return (this||g$e).base.slice(e?e.offset:(this||g$e).offset,(this||g$e).length)},p$k.EncoderBuffer=s,s.prototype.join=function(e,t){return e||(e=new i((this||g$e).length)),t||(t=0),0===(this||g$e).length||(Array.isArray((this||g$e).value)?(this||g$e).value.forEach((function(r){r.join(e,t),t+=r.length;})):("number"==typeof(this||g$e).value?e[t]=(this||g$e).value:"string"==typeof(this||g$e).value?e.write((this||g$e).value,t):i.isBuffer((this||g$e).value)&&(this||g$e).value.copy(e,t),t+=(this||g$e).length)),e},p$k}var _$e={},v$f=!1,b$c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;var m$g={},S$a=!1;function E$9(){if(S$a)return m$g;S$a=!0;var e=m$g;return e.Reporter=c$i.Reporter,e.DecoderBuffer=y$f().DecoderBuffer,e.EncoderBuffer=y$f().EncoderBuffer,e.Node=function(){if(v$f)return _$e;v$f=!0;var e=E$9().Reporter,t=E$9().EncoderBuffer,r=E$9().DecoderBuffer,n=o$7,o=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],s=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(o);function a(e,t){var r={};(this||b$c)._baseState=r,r.enc=e,r.parent=t||null,r.children=null,r.tag=null,r.args=null,r.reverseArgs=null,r.choice=null,r.optional=!1,r.any=!1,r.obj=!1,r.use=null,r.useDecoder=null,r.key=null,r.default=null,r.explicit=null,r.implicit=null,r.contains=null,r.parent||(r.children=[],this._wrap());}_$e=a;var u=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];return a.prototype.clone=function(){var e=(this||b$c)._baseState,t={};u.forEach((function(r){t[r]=e[r];}));var r=new(this||b$c).constructor(t.parent);return r._baseState=t,r},a.prototype._wrap=function(){var e=(this||b$c)._baseState;s.forEach((function(t){(this||b$c)[t]=function(){var r=new(this||b$c).constructor(this||b$c);return e.children.push(r),r[t].apply(r,arguments)};}),this||b$c);},a.prototype._init=function(e){var t=(this||b$c)._baseState;n(null===t.parent),e.call(this||b$c),t.children=t.children.filter((function(e){return e._baseState.parent===(this||b$c)}),this||b$c),n.equal(t.children.length,1,"Root node can have only one child");},a.prototype._useArgs=function(e){var t=(this||b$c)._baseState,r=e.filter((function(e){return e instanceof(this||b$c).constructor}),this||b$c);e=e.filter((function(e){return !(e instanceof(this||b$c).constructor)}),this||b$c),0!==r.length&&(n(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this||b$c;}),this||b$c)),0!==e.length&&(n(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;var t={};return Object.keys(e).forEach((function(r){r==(0|r)&&(r|=0);var n=e[r];t[n]=r;})),t})));},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){a.prototype[e]=function(){var t=(this||b$c)._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)};})),o.forEach((function(e){a.prototype[e]=function(){var t=(this||b$c)._baseState,r=Array.prototype.slice.call(arguments);return n(null===t.tag),t.tag=e,this._useArgs(r),this||b$c};})),a.prototype.use=function(e){n(e);var t=(this||b$c)._baseState;return n(null===t.use),t.use=e,this||b$c},a.prototype.optional=function(){return (this||b$c)._baseState.optional=!0,this||b$c},a.prototype.def=function(e){var t=(this||b$c)._baseState;return n(null===t.default),t.default=e,t.optional=!0,this||b$c},a.prototype.explicit=function(e){var t=(this||b$c)._baseState;return n(null===t.explicit&&null===t.implicit),t.explicit=e,this||b$c},a.prototype.implicit=function(e){var t=(this||b$c)._baseState;return n(null===t.explicit&&null===t.implicit),t.implicit=e,this||b$c},a.prototype.obj=function(){var e=(this||b$c)._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this||b$c},a.prototype.key=function(e){var t=(this||b$c)._baseState;return n(null===t.key),t.key=e,this||b$c},a.prototype.any=function(){return (this||b$c)._baseState.any=!0,this||b$c},a.prototype.choice=function(e){var t=(this||b$c)._baseState;return n(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this||b$c},a.prototype.contains=function(e){var t=(this||b$c)._baseState;return n(null===t.use),t.contains=e,this||b$c},a.prototype._decode=function(e,t){var n=(this||b$c)._baseState;if(null===n.parent)return e.wrapResult(n.children[0]._decode(e,t));var i,o=n.default,s=!0,a=null;if(null!==n.key&&(a=e.enterKey(n.key)),n.optional){var u=null;if(null!==n.explicit?u=n.explicit:null!==n.implicit?u=n.implicit:null!==n.tag&&(u=n.tag),null!==u||n.any){if(s=this._peekTag(e,u,n.any),e.isError(s))return s}else {var c=e.save();try{null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),s=!0;}catch(e){s=!1;}e.restore(c);}}if(n.obj&&s&&(i=e.enterObject()),s){if(null!==n.explicit){var f=this._decodeTag(e,n.explicit);if(e.isError(f))return f;e=f;}var l=e.offset;if(null===n.use&&null===n.choice){if(n.any)c=e.save();var h=this._decodeTag(e,null!==n.implicit?n.implicit:n.tag,n.any);if(e.isError(h))return h;n.any?o=e.raw(c):e=h;}if(t&&t.track&&null!==n.tag&&t.track(e.path(),l,e.length,"tagged"),t&&t.track&&null!==n.tag&&t.track(e.path(),e.offset,e.length,"content"),o=n.any?o:null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),e.isError(o))return o;if(n.any||null!==n.choice||null===n.children||n.children.forEach((function(r){r._decode(e,t);})),n.contains&&("octstr"===n.tag||"bitstr"===n.tag)){var p=new r(o);o=this._getUse(n.contains,e._reporterState.obj)._decode(p,t);}}return n.obj&&s&&(o=e.leaveObject(i)),null===n.key||null===o&&!0!==s?null!==a&&e.exitKey(a):e.leaveKey(a,n.key,o),o},a.prototype._decodeGeneric=function(e,t,r){var n=(this||b$c)._baseState;return "seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,n.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&n.args?this._decodeObjid(t,n.args[0],n.args[1],r):"objid"===e?this._decodeObjid(t,null,null,r):"gentime"===e||"utctime"===e?this._decodeTime(t,e,r):"null_"===e?this._decodeNull(t,r):"bool"===e?this._decodeBool(t,r):"objDesc"===e?this._decodeStr(t,e,r):"int"===e||"enum"===e?this._decodeInt(t,n.args&&n.args[0],r):null!==n.use?this._getUse(n.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},a.prototype._getUse=function(e,t){var r=(this||b$c)._baseState;return r.useDecoder=this._use(e,t),n(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},a.prototype._decodeChoice=function(e,t){var r=(this||b$c)._baseState,n=null,i=!1;return Object.keys(r.choice).some((function(o){var s=e.save(),a=r.choice[o];try{var u=a._decode(e,t);if(e.isError(u))return !1;n={type:o,value:u},i=!0;}catch(t){return e.restore(s),!1}return !0}),this||b$c),i?n:e.error("Choice not matched")},a.prototype._createEncoderBuffer=function(e){return new t(e,(this||b$c).reporter)},a.prototype._encode=function(e,t,r){var n=(this||b$c)._baseState;if(null===n.default||n.default!==e){var i=this._encodeValue(e,t,r);if(void 0!==i&&!this._skipDefault(i,t,r))return i}},a.prototype._encodeValue=function(t,r,n){var i=(this||b$c)._baseState;if(null===i.parent)return i.children[0]._encode(t,r||new e);var o=null;if((this||b$c).reporter=r,i.optional&&void 0===t){if(null===i.default)return;t=i.default;}var s=null,a=!1;if(i.any)o=this._createEncoderBuffer(t);else if(i.choice)o=this._encodeChoice(t,r);else if(i.contains)s=this._getUse(i.contains,n)._encode(t,r),a=!0;else if(i.children)s=i.children.map((function(e){if("null_"===e._baseState.tag)return e._encode(null,r,t);if(null===e._baseState.key)return r.error("Child should have a key");var n=r.enterKey(e._baseState.key);if("object"!=typeof t)return r.error("Child expected, but input is not object");var i=e._encode(t[e._baseState.key],r,t);return r.leaveKey(n),i}),this||b$c).filter((function(e){return e})),s=this._createEncoderBuffer(s);else if("seqof"===i.tag||"setof"===i.tag){if(!i.args||1!==i.args.length)return r.error("Too many args for : "+i.tag);if(!Array.isArray(t))return r.error("seqof/setof, but data is not Array");var u=this.clone();u._baseState.implicit=null,s=this._createEncoderBuffer(t.map((function(e){var n=(this||b$c)._baseState;return this._getUse(n.args[0],t)._encode(e,r)}),u));}else null!==i.use?o=this._getUse(i.use,n)._encode(t,r):(s=this._encodePrimitive(i.tag,t),a=!0);if(!i.any&&null===i.choice){var c=null!==i.implicit?i.implicit:i.tag,f=null===i.implicit?"universal":"context";null===c?null===i.use&&r.error("Tag could be omitted only for .use()"):null===i.use&&(o=this._encodeComposite(c,a,f,s));}return null!==i.explicit&&(o=this._encodeComposite(i.explicit,!1,"context",o)),o},a.prototype._encodeChoice=function(e,t){var r=(this||b$c)._baseState,i=r.choice[e.type];return i||n(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),i._encode(e.value,t)},a.prototype._encodePrimitive=function(e,t){var r=(this||b$c)._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&r.args)return this._encodeObjid(t,r.reverseArgs[0],r.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,r.args&&r.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},a.prototype._isNumstr=function(e){return /^[0-9 ]*$/.test(e)},a.prototype._isPrintstr=function(e){return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(e)},_$e}(),m$g}var j$6={},w$f=!1;var B$9={},k$c=!1;function T$6(){if(k$c)return B$9;k$c=!0;var e=B$9;return e._reverse=function(e){var t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);var n=e[r];t[n]=r;})),t},e.der=function(){if(w$f)return j$6;w$f=!0;var e=T$6();return j$6.tagClass={0:"universal",1:"application",2:"context",3:"private"},j$6.tagClassByName=e._reverse(j$6.tagClass),j$6.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},j$6.tagByName=e._reverse(j$6.tag),j$6}(),B$9}var D$5={},U$7=!1,N$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function C$6(){if(U$7)return D$5;U$7=!0;var e=t$2$2,r=Y$3(),n=r.base,i=r.bignum,o=r.constants.der;function s(e){(this||N$5).enc="der",(this||N$5).name=e.name,(this||N$5).entity=e,(this||N$5).tree=new a,(this||N$5).tree._init(e.body);}function a(e){n.Node.call(this||N$5,"der",e);}function u(e,t){var r=e.readUInt8(t);if(e.isError(r))return r;var n=o.tagClass[r>>6],i=0==(32&r);if(31==(31&r)){var s=r;for(r=0;128==(128&s);){if(s=e.readUInt8(t),e.isError(s))return s;r<<=7,r|=127&s;}}else r&=31;return {cls:n,primitive:i,tag:r,tagStr:o.tag[r]}}function c(e,t,r){var n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(0==(128&n))return n;var i=127&n;if(i>4)return e.error("length octect is too long");n=0;for(var o=0;o=31)return n.error("Multi-octet tag encoding unsupported");t||(i|=32);return i|=s.tagClassByName[r||"universal"]<<6}(e,t,n,(this||R$4).reporter);if(i.length<128)return (o=new r(2))[0]=a,o[1]=i.length,this._createEncoderBuffer([o,i]);for(var u=1,c=i.length;c>=256;c>>=8)u++;(o=new r(2+u))[0]=a,o[1]=128|u;c=1+u;for(var f=i.length;f>0;c--,f>>=8)o[c]=255&f;return this._createEncoderBuffer([o,i])},u.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){for(var n=new r(2*e.length),i=0;i=40)return (this||R$4).reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1]);}var o=0;for(i=0;i=128;s>>=7)o++;}var a=new r(o),u=a.length-1;for(i=e.length-1;i>=0;i--){s=e[i];for(a[u--]=127&s;(s>>=7)>0;)a[u--]=128|127&s;}return this._createEncoderBuffer(a)},u.prototype._encodeTime=function(e,t){var r,n=new Date(e);return "gentime"===t?r=[c(n.getFullYear()),c(n.getUTCMonth()+1),c(n.getUTCDate()),c(n.getUTCHours()),c(n.getUTCMinutes()),c(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[c(n.getFullYear()%100),c(n.getUTCMonth()+1),c(n.getUTCDate()),c(n.getUTCHours()),c(n.getUTCMinutes()),c(n.getUTCSeconds()),"Z"].join(""):(this||R$4).reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},u.prototype._encodeNull=function(){return this._createEncoderBuffer("")},u.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return (this||R$4).reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return (this||R$4).reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e];}if("number"!=typeof e&&!r.isBuffer(e)){var n=e.toArray();!e.sign&&128&n[0]&&n.unshift(0),e=new r(n);}if(r.isBuffer(e)){var i=e.length;0===e.length&&i++;var o=new r(i);return e.copy(o),0===e.length&&(o[0]=0),this._createEncoderBuffer(o)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);i=1;for(var s=e;s>=256;s>>=8)i++;for(s=(o=new Array(i)).length-1;s>=0;s--)o[s]=255&e,e>>=8;return 128&o[0]&&o.unshift(0),this._createEncoderBuffer(new r(o))},u.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},u.prototype._use=function(e,t){return "function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},u.prototype._skipDefault=function(e,t,r){var n,i=(this||R$4)._baseState;if(null===i.default)return !1;var o=e.join();if(void 0===i.defaultBuffer&&(i.defaultBuffer=this._encodeValue(i.default,t,r).join()),o.length!==i.defaultBuffer.length)return !1;for(n=0;n0&&r.ishrn(n),r}function _$f(e,t,r){var n,a;do{for(n=new f$q(0);8*n.length=t)throw new Error("invalid sig")}var K$7=function(e,t,r,n,a){var o=T$7(r);if("ec"===o.type){if("ecdsa"!==n&&"ecdsa/rsa"!==n)throw new Error("wrong public key type");return function(e,t,r){var n=P$7[r.data.algorithm.curve.join(".")];if(!n)throw new Error("unknown curve "+r.data.algorithm.curve.join("."));var a=new j$8(n),o=r.data.subjectPrivateKey.data;return a.verify(t,e,o)}(e,t,o)}if("dsa"===o.type){if("dsa"!==n)throw new Error("wrong public key type");return function(e,t,r){var n=r.data.p,a=r.data.q,o=r.data.g,i=r.data.pub_key,s=T$7.signature.decode(e,"der"),h=s.s,u=s.r;A$a(h,a),A$a(u,a);var p=R$5.mont(n),d=h.invm(a);return 0===o.toRed(p).redPow(new R$5(t).mul(d).mod(a)).fromRed().mul(i.toRed(p).redPow(u.mul(d).mod(a)).fromRed()).mod(n).mod(a).cmp(u)}(e,t,o)}if("rsa"!==n&&"ecdsa/rsa"!==n)throw new Error("wrong public key type");t=L$6.concat([a,t]);for(var i=o.modulus.byteLength(),s=[1],h=0;t.length+s.length+2e-i-2)throw new Error("message too long");var l=B$b.alloc(e-t-i-2),f=e-a-1,u=g$g(a),c=v$j(B$b.concat([o,l,B$b.alloc(1,1),n],f),w$h(u,f)),p=v$j(u,w$h(c,a));return new y$k(B$b.concat([B$b.alloc(1),p,c],e))}(a,n);else if(1===t)o=function(r,n,e){var t,o=n.length,a=r.modulus.byteLength();if(o>a-11)throw new Error("message too long");t=e?B$b.alloc(a-o-3,255):function(r){var n,e=B$b.allocUnsafe(r),t=0,o=g$g(2*r),a=0;for(;t=0)throw new Error("data too long for modulus")}return e?b$g(o,a):E$c(o,a)},L$7=v$h,k$f=u$n,D$7=c$m,U$9=n$c,R$6=l$d,S$c=h$4,j$9=h$j,A$b=u$q.Buffer;var I$a=function(r,n,e){var t;t=r.padding?r.padding:e?1:4;var o,a=L$7(r),i=a.modulus.byteLength();if(n.length>i||new U$9(n).cmp(a.modulus)>=0)throw new Error("decryption error");o=e?j$9(new U$9(n),a):R$6(n,a);var l=A$b.alloc(i-o.length);if(o=A$b.concat([l,o],i),4===t)return function(r,n){var e=r.modulus.byteLength(),t=S$c("sha1").update(A$b.alloc(0)).digest(),o=t.length;if(0!==n[0])throw new Error("decryption error");var a=n.slice(1,o+1),i=n.slice(o+1),l=D$7(a,k$f(i,o)),f=D$7(i,k$f(l,e-o-1));if(function(r,n){r=A$b.from(r),n=A$b.from(n);var e=0,t=r.length;r.length!==n.length&&(e++,t=Math.min(r.length,n.length));var o=-1;for(;++o=n.length){a++;break}var i=n.slice(2,o-1);("0002"!==t.toString("hex")&&!e||"0001"!==t.toString("hex")&&e)&&a++;i.length<8&&a++;if(a)throw new Error("decryption error");return n.slice(o)}(0,o,e);if(3===t)return o;throw new Error("unknown padding")},M$9={};M$9.publicEncrypt=x$9,M$9.privateDecrypt=I$a,M$9.privateEncrypt=function(r,n){return M$9.publicEncrypt(r,n,!0)},M$9.publicDecrypt=function(r,n){return M$9.privateDecrypt(r,n,!0)};var o$r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,t$b={},f$t=T$9;function i$d(){throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11")}var u$o=u$q,a$o=a,s$o=u$o.Buffer,l$p=u$o.kMaxLength,m$l=o$r.crypto||o$r.msCrypto,p$q=Math.pow(2,32)-1;function y$l(r,e){if("number"!=typeof r||r!=r)throw new TypeError("offset must be a number");if(r>p$q||r<0)throw new TypeError("offset must be a uint32");if(r>l$p||r>e)throw new RangeError("offset out of range")}function b$h(r,e,n){if("number"!=typeof r||r!=r)throw new TypeError("size must be a number");if(r>p$q||r<0)throw new TypeError("size must be a uint32");if(r+e>n||r>l$p)throw new RangeError("buffer too small")}function w$i(r,e,n,o){if(f$t.browser){var t=r.buffer,i=new Uint8Array(t,e,n);return m$l.getRandomValues(i),o?(f$t.nextTick((function(){o(null,r);})),void 0):r}return o?(a$o(n,(function(n,t){if(n)return o(n);t.copy(r,e),o(null,r);})),void 0):(a$o(n).copy(r,e),r)}m$l&&m$l.getRandomValues||!f$t.browser?(t$b.randomFill=function(r,e,n,t){if(!(s$o.isBuffer(r)||r instanceof o$r.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if("function"==typeof e)t=e,e=0,n=r.length;else if("function"==typeof n)t=n,n=r.length-e;else if("function"!=typeof t)throw new TypeError('"cb" argument must be a function');return y$l(e,r.length),b$h(n,e,r.length),w$i(r,e,n,t)},t$b.randomFillSync=function(r,e,n){void 0===e&&(e=0);if(!(s$o.isBuffer(r)||r instanceof o$r.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');y$l(e,r.length),void 0===n&&(n=r.length-e);return b$h(n,e,r.length),w$i(r,e,n)}):(t$b.randomFill=i$d,t$b.randomFillSync=i$d);var l$q={};l$q.randomBytes=l$q.rng=l$q.pseudoRandomBytes=l$q.prng=a,l$q.createHash=l$q.Hash=h$4,l$q.createHmac=l$q.Hmac=w$3;var D$8=s$4,s$p=Object.keys(D$8),_$g=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(s$p);l$q.getHashes=function(){return _$g};var h$k=M$1;l$q.pbkdf2=h$k.pbkdf2,l$q.pbkdf2Sync=h$k.pbkdf2Sync;var y$m=p$d;l$q.Cipher=y$m.Cipher,l$q.createCipher=y$m.createCipher,l$q.Cipheriv=y$m.Cipheriv,l$q.createCipheriv=y$m.createCipheriv,l$q.Decipher=y$m.Decipher,l$q.createDecipher=y$m.createDecipher,l$q.Decipheriv=y$m.Decipheriv,l$q.createDecipheriv=y$m.createDecipheriv,l$q.getCiphers=y$m.getCiphers,l$q.listCiphers=y$m.listCiphers;var E$d=O$3;l$q.DiffieHellmanGroup=E$d.DiffieHellmanGroup,l$q.createDiffieHellmanGroup=E$d.createDiffieHellmanGroup,l$q.getDiffieHellman=E$d.getDiffieHellman,l$q.createDiffieHellman=E$d.createDiffieHellman,l$q.DiffieHellman=E$d.DiffieHellman;var S$d=z$8;l$q.createSign=S$d.createSign,l$q.Sign=S$d.Sign,l$q.createVerify=S$d.createVerify,l$q.Verify=S$d.Verify,l$q.createECDH=f$r;var C$8=M$9;l$q.publicEncrypt=C$8.publicEncrypt,l$q.privateEncrypt=C$8.privateEncrypt,l$q.publicDecrypt=C$8.publicDecrypt,l$q.privateDecrypt=C$8.privateDecrypt;var N$6=t$b;l$q.randomFill=N$6.randomFill,l$q.randomFillSync=N$6.randomFillSync,l$q.createCredentials=function(){throw new Error(["sorry, createCredentials is not implemented yet","we accept pull requests","https://github.com/crypto-browserify/crypto-browserify"].join("\n"))},l$q.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}; + +var exports$10$1 = {}, + _dewExec$10$1 = false; + +var _global$a$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$10$1() { + if (_dewExec$10$1) return exports$10$1; + _dewExec$10$1 = true; + var r; + + exports$10$1 = function rand(len) { + if (!r) r = new Rand(null); + return r.generate(len); + }; + + function Rand(rand) { + (this || _global$a$1).rand = rand; + } + + exports$10$1.Rand = Rand; + + Rand.prototype.generate = function generate(len) { + return this._rand(len); + }; // Emulate crypto API using randy + + + Rand.prototype._rand = function _rand(n) { + if ((this || _global$a$1).rand.getBytes) return (this || _global$a$1).rand.getBytes(n); + var res = new Uint8Array(n); + + for (var i = 0; i < res.length; i++) res[i] = (this || _global$a$1).rand.getByte(); + + return res; + }; + + if (typeof self === "object") { + if (self.crypto && self.crypto.getRandomValues) { + // Modern browsers + Rand.prototype._rand = function _rand(n) { + var arr = new Uint8Array(n); + self.crypto.getRandomValues(arr); + return arr; + }; + } else if (self.msCrypto && self.msCrypto.getRandomValues) { + // IE + Rand.prototype._rand = function _rand(n) { + var arr = new Uint8Array(n); + self.msCrypto.getRandomValues(arr); + return arr; + }; // Safari's WebWorkers do not have `crypto` + + } else if (typeof window === "object") { + // Old junk + Rand.prototype._rand = function () { + throw new Error("Not implemented yet"); + }; + } + } else { + // Node.js or Web worker with no crypto support + try { + var crypto = l$q; + if (typeof crypto.randomBytes !== "function") throw new Error("Not supported"); + + Rand.prototype._rand = function _rand(n) { + return crypto.randomBytes(n); + }; + } catch (e) {} + } + + return exports$10$1; +} + +var exports$$$1 = {}, + _dewExec$$$1 = false; + +var _global$9$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$$$1() { + if (_dewExec$$$1) return exports$$$1; + _dewExec$$$1 = true; + + var bn = dew$11$1(); + + var brorand = dew$10$1(); + + function MillerRabin(rand) { + (this || _global$9$1).rand = rand || new brorand.Rand(); + } + + exports$$$1 = MillerRabin; + + MillerRabin.create = function create(rand) { + return new MillerRabin(rand); + }; + + MillerRabin.prototype._randbelow = function _randbelow(n) { + var len = n.bitLength(); + var min_bytes = Math.ceil(len / 8); // Generage random bytes until a number less than n is found. + // This ensures that 0..n-1 have an equal probability of being selected. + + do var a = new bn((this || _global$9$1).rand.generate(min_bytes)); while (a.cmp(n) >= 0); + + return a; + }; + + MillerRabin.prototype._randrange = function _randrange(start, stop) { + // Generate a random number greater than or equal to start and less than stop. + var size = stop.sub(start); + return start.add(this._randbelow(size)); + }; + + MillerRabin.prototype.test = function test(n, k, cb) { + var len = n.bitLength(); + var red = bn.mont(n); + var rone = new bn(1).toRed(red); + if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d; + + var n1 = n.subn(1); + + for (var s = 0; !n1.testn(s); s++) {} + + var d = n.shrn(s); + var rn1 = n1.toRed(red); + var prime = true; + + for (; k > 0; k--) { + var a = this._randrange(new bn(2), n1); + + if (cb) cb(a); + var x = a.toRed(red).redPow(d); + if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue; + + for (var i = 1; i < s; i++) { + x = x.redSqr(); + if (x.cmp(rone) === 0) return false; + if (x.cmp(rn1) === 0) break; + } + + if (i === s) return false; + } + + return prime; + }; + + MillerRabin.prototype.getDivisor = function getDivisor(n, k) { + var len = n.bitLength(); + var red = bn.mont(n); + var rone = new bn(1).toRed(red); + if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d; + + var n1 = n.subn(1); + + for (var s = 0; !n1.testn(s); s++) {} + + var d = n.shrn(s); + var rn1 = n1.toRed(red); + + for (; k > 0; k--) { + var a = this._randrange(new bn(2), n1); + + var g = n.gcd(a); + if (g.cmpn(1) !== 0) return g; + var x = a.toRed(red).redPow(d); + if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue; + + for (var i = 1; i < s; i++) { + x = x.redSqr(); + if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n); + if (x.cmp(rn1) === 0) break; + } + + if (i === s) { + x = x.redSqr(); + return x.fromRed().subn(1).gcd(n); + } + } + + return false; + }; + + return exports$$$1; +} + +var exports$_$1 = {}, + _dewExec$_$1 = false; +function dew$_$1() { + if (_dewExec$_$1) return exports$_$1; + _dewExec$_$1 = true; + + var randomBytes = dew$1S(); + + exports$_$1 = findPrime; + findPrime.simpleSieve = simpleSieve; + findPrime.fermatTest = fermatTest; + + var BN = dew$12$1(); + + var TWENTYFOUR = new BN(24); + + var MillerRabin = dew$$$1(); + + var millerRabin = new MillerRabin(); + var ONE = new BN(1); + var TWO = new BN(2); + var FIVE = new BN(5); + new BN(16); + new BN(8); + var TEN = new BN(10); + var THREE = new BN(3); + new BN(7); + var ELEVEN = new BN(11); + var FOUR = new BN(4); + new BN(12); + var primes = null; + + function _getPrimes() { + if (primes !== null) return primes; + var limit = 1048576; + var res = []; + res[0] = 2; + + for (var i = 1, k = 3; k < limit; k += 2) { + var sqrt = Math.ceil(Math.sqrt(k)); + + for (var j = 0; j < i && res[j] <= sqrt; j++) if (k % res[j] === 0) break; + + if (i !== j && res[j] <= sqrt) continue; + res[i++] = k; + } + + primes = res; + return res; + } + + function simpleSieve(p) { + var primes = _getPrimes(); + + for (var i = 0; i < primes.length; i++) if (p.modn(primes[i]) === 0) { + if (p.cmpn(primes[i]) === 0) { + return true; + } else { + return false; + } + } + + return true; + } + + function fermatTest(p) { + var red = BN.mont(p); + return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0; + } + + function findPrime(bits, gen) { + if (bits < 16) { + // this is what openssl does + if (gen === 2 || gen === 5) { + return new BN([140, 123]); + } else { + return new BN([140, 39]); + } + } + + gen = new BN(gen); + var num, n2; + + while (true) { + num = new BN(randomBytes(Math.ceil(bits / 8))); + + while (num.bitLength() > bits) { + num.ishrn(1); + } + + if (num.isEven()) { + num.iadd(ONE); + } + + if (!num.testn(1)) { + num.iadd(TWO); + } + + if (!gen.cmp(TWO)) { + while (num.mod(TWENTYFOUR).cmp(ELEVEN)) { + num.iadd(FOUR); + } + } else if (!gen.cmp(FIVE)) { + while (num.mod(TEN).cmp(THREE)) { + num.iadd(FOUR); + } + } + + n2 = num.shrn(1); + + if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) { + return num; + } + } + } + + return exports$_$1; +} + +var _primes$1 = { + "modp1": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff" + }, + "modp2": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff" + }, + "modp5": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff" + }, + "modp14": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff" + }, + "modp15": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff" + }, + "modp16": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff" + }, + "modp17": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff" + }, + "modp18": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff" + } +}; + +var exports$Z$1 = {}, + _dewExec$Z$1 = false; + +var _global$8$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$Z$1() { + if (_dewExec$Z$1) return exports$Z$1; + _dewExec$Z$1 = true; + var Buffer = e$1$1$1.Buffer; + + var BN = dew$12$1(); + + var MillerRabin = dew$$$1(); + + var millerRabin = new MillerRabin(); + var TWENTYFOUR = new BN(24); + var ELEVEN = new BN(11); + var TEN = new BN(10); + var THREE = new BN(3); + var SEVEN = new BN(7); + + var primes = dew$_$1(); + + var randomBytes = dew$1S(); + + exports$Z$1 = DH; + + function setPublicKey(pub, enc) { + enc = enc || "utf8"; + + if (!Buffer.isBuffer(pub)) { + pub = new Buffer(pub, enc); + } + + (this || _global$8$1)._pub = new BN(pub); + return this || _global$8$1; + } + + function setPrivateKey(priv, enc) { + enc = enc || "utf8"; + + if (!Buffer.isBuffer(priv)) { + priv = new Buffer(priv, enc); + } + + (this || _global$8$1)._priv = new BN(priv); + return this || _global$8$1; + } + + var primeCache = {}; + + function checkPrime(prime, generator) { + var gen = generator.toString("hex"); + var hex = [gen, prime.toString(16)].join("_"); + + if (hex in primeCache) { + return primeCache[hex]; + } + + var error = 0; + + if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) { + //not a prime so +1 + error += 1; + + if (gen === "02" || gen === "05") { + // we'd be able to check the generator + // it would fail so +8 + error += 8; + } else { + //we wouldn't be able to test the generator + // so +4 + error += 4; + } + + primeCache[hex] = error; + return error; + } + + if (!millerRabin.test(prime.shrn(1))) { + //not a safe prime + error += 2; + } + + var rem; + + switch (gen) { + case "02": + if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) { + // unsuidable generator + error += 8; + } + + break; + + case "05": + rem = prime.mod(TEN); + + if (rem.cmp(THREE) && rem.cmp(SEVEN)) { + // prime mod 10 needs to equal 3 or 7 + error += 8; + } + + break; + + default: + error += 4; + } + + primeCache[hex] = error; + return error; + } + + function DH(prime, generator, malleable) { + this.setGenerator(generator); + (this || _global$8$1).__prime = new BN(prime); + (this || _global$8$1)._prime = BN.mont((this || _global$8$1).__prime); + (this || _global$8$1)._primeLen = prime.length; + (this || _global$8$1)._pub = undefined; + (this || _global$8$1)._priv = undefined; + (this || _global$8$1)._primeCode = undefined; + + if (malleable) { + (this || _global$8$1).setPublicKey = setPublicKey; + (this || _global$8$1).setPrivateKey = setPrivateKey; + } else { + (this || _global$8$1)._primeCode = 8; + } + } + + Object.defineProperty(DH.prototype, "verifyError", { + enumerable: true, + get: function () { + if (typeof (this || _global$8$1)._primeCode !== "number") { + (this || _global$8$1)._primeCode = checkPrime((this || _global$8$1).__prime, (this || _global$8$1).__gen); + } + + return (this || _global$8$1)._primeCode; + } + }); + + DH.prototype.generateKeys = function () { + if (!(this || _global$8$1)._priv) { + (this || _global$8$1)._priv = new BN(randomBytes((this || _global$8$1)._primeLen)); + } + + (this || _global$8$1)._pub = (this || _global$8$1)._gen.toRed((this || _global$8$1)._prime).redPow((this || _global$8$1)._priv).fromRed(); + return this.getPublicKey(); + }; + + DH.prototype.computeSecret = function (other) { + other = new BN(other); + other = other.toRed((this || _global$8$1)._prime); + var secret = other.redPow((this || _global$8$1)._priv).fromRed(); + var out = new Buffer(secret.toArray()); + var prime = this.getPrime(); + + if (out.length < prime.length) { + var front = new Buffer(prime.length - out.length); + front.fill(0); + out = Buffer.concat([front, out]); + } + + return out; + }; + + DH.prototype.getPublicKey = function getPublicKey(enc) { + return formatReturnValue((this || _global$8$1)._pub, enc); + }; + + DH.prototype.getPrivateKey = function getPrivateKey(enc) { + return formatReturnValue((this || _global$8$1)._priv, enc); + }; + + DH.prototype.getPrime = function (enc) { + return formatReturnValue((this || _global$8$1).__prime, enc); + }; + + DH.prototype.getGenerator = function (enc) { + return formatReturnValue((this || _global$8$1)._gen, enc); + }; + + DH.prototype.setGenerator = function (gen, enc) { + enc = enc || "utf8"; + + if (!Buffer.isBuffer(gen)) { + gen = new Buffer(gen, enc); + } + + (this || _global$8$1).__gen = gen; + (this || _global$8$1)._gen = new BN(gen); + return this || _global$8$1; + }; + + function formatReturnValue(bn, enc) { + var buf = new Buffer(bn.toArray()); + + if (!enc) { + return buf; + } else { + return buf.toString(enc); + } + } + + return exports$Z$1; +} + +var exports$Y$1 = {}, + _dewExec$Y$1 = false; +function dew$Y$1() { + if (_dewExec$Y$1) return exports$Y$1; + _dewExec$Y$1 = true; + var Buffer = e$1$1$1.Buffer; + + var generatePrime = dew$_$1(); + + var primes = _primes$1; + + var DH = dew$Z$1(); + + function getDiffieHellman(mod) { + var prime = new Buffer(primes[mod].prime, "hex"); + var gen = new Buffer(primes[mod].gen, "hex"); + return new DH(prime, gen); + } + + var ENCODINGS = { + "binary": true, + "hex": true, + "base64": true + }; + + function createDiffieHellman(prime, enc, generator, genc) { + if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) { + return createDiffieHellman(prime, "binary", enc, generator); + } + + enc = enc || "binary"; + genc = genc || "binary"; + generator = generator || new Buffer([2]); + + if (!Buffer.isBuffer(generator)) { + generator = new Buffer(generator, genc); + } + + if (typeof prime === "number") { + return new DH(generatePrime(prime, generator), generator, true); + } + + if (!Buffer.isBuffer(prime)) { + prime = new Buffer(prime, enc); + } + + return new DH(prime, generator, true); + } + + exports$Y$1.DiffieHellmanGroup = exports$Y$1.createDiffieHellmanGroup = exports$Y$1.getDiffieHellman = getDiffieHellman; + exports$Y$1.createDiffieHellman = exports$Y$1.DiffieHellman = createDiffieHellman; + return exports$Y$1; +} + +var exports$X$1 = {}, + _dewExec$X$1 = false; +var module$4$1 = { + exports: exports$X$1 +}; + +var _global$7$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$X$1() { + if (_dewExec$X$1) return module$4$1.exports; + _dewExec$X$1 = true; + + (function (module, exports) { + + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. + + + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; + + var TempCtor = function () {}; + + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN + + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } + + (this || _global$7$1).negative = 0; + (this || _global$7$1).words = null; + (this || _global$7$1).length = 0; // Reduction context + + (this || _global$7$1).red = null; + + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } + + this._init(number || 0, base || 10, endian || "be"); + } + } + + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } + + BN.BN = BN; + BN.wordSize = 26; + var Buffer; + + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = e$1$1$1.Buffer; + } + } catch (e) {} + + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } + + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; + + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; + + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } + + if (typeof number === "object") { + return this._initArray(number, base, endian); + } + + if (base === "hex") { + base = 16; + } + + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; + + if (number[0] === "-") { + start++; + (this || _global$7$1).negative = 1; + } + + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); + + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } + }; + + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$7$1).negative = 1; + number = -number; + } + + if (number < 67108864) { + (this || _global$7$1).words = [number & 67108863]; + (this || _global$7$1).length = 1; + } else if (number < 4503599627370496) { + (this || _global$7$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$7$1).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + + (this || _global$7$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$7$1).length = 3; + } + + if (endian !== "le") return; // Reverse the bytes + + this._initArray(this.toArray(), base, endian); + }; + + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); + + if (number.length <= 0) { + (this || _global$7$1).words = [0]; + (this || _global$7$1).length = 1; + return this || _global$7$1; + } - if (nOrig !== n && state.ended) endReadable(this); + (this || _global$7$1).length = Math.ceil(number.length / 3); + (this || _global$7$1).words = new Array((this || _global$7$1).length); + + for (var i = 0; i < (this || _global$7$1).length; i++) { + (this || _global$7$1).words[i] = 0; + } + + var j, w; + var off = 0; + + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$7$1).words[j] |= w << off & 67108863; + (this || _global$7$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$7$1).words[j] |= w << off & 67108863; + (this || _global$7$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } + + return this._strip(); + }; + + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // '0' - '9' + + if (c >= 48 && c <= 57) { + return c - 48; // 'A' - 'F' + } else if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; + } else { + assert(false, "Invalid character in " + string); + } } - if (ret !== null) this.emit("data", ret); - return ret; - }; + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); - function onEofChunk(stream, state) { - debug("onEofChunk"); - if (state.ended) return; + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } - if (state.decoder) { - var chunk = state.decoder.end(); + return r; + } - if (chunk && chunk.length) { - state.buffer.push(chunk); - state.length += state.objectMode ? 1 : chunk.length; + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$7$1).length = Math.ceil((number.length - start) / 6); + (this || _global$7$1).words = new Array((this || _global$7$1).length); + + for (var i = 0; i < (this || _global$7$1).length; i++) { + (this || _global$7$1).words[i] = 0; + } // 24-bits chunks + + + var off = 0; + var j = 0; + var w; + + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$7$1).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$7$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; + + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$7$1).words[j] |= w & 67108863; + + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$7$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } + + this._strip(); + }; + + function parseBase(str, start, end, mul) { + var r = 0; + var b = 0; + var len = Math.min(str.length, end); + + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' + + if (c >= 49) { + b = c - 49 + 10; // 'A' + } else if (c >= 17) { + b = c - 17 + 10; // '0' - '9' + } else { + b = c; + } + + assert(c >= 0 && b < mul, "Invalid character"); + r += b; } + + return r; } - state.ended = true; + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$7$1).words = [0]; + (this || _global$7$1).length = 1; // Find length of limb in base - if (state.sync) { - // if we are sync, wait until next tick to emit the data. - // Otherwise we risk emitting data in the flow() - // the readable code triggers during a read() call - emitReadable(stream); + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } + + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; + + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); + + if ((this || _global$7$1).words[0] + word < 67108864) { + (this || _global$7$1).words[0] += word; + } else { + this._iaddn(word); + } + } + + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); + + for (i = 0; i < mod; i++) { + pow *= base; + } + + this.imuln(pow); + + if ((this || _global$7$1).words[0] + word < 67108864) { + (this || _global$7$1).words[0] += word; + } else { + this._iaddn(word); + } + } + + this._strip(); + }; + + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$7$1).length); + + for (var i = 0; i < (this || _global$7$1).length; i++) { + dest.words[i] = (this || _global$7$1).words[i]; + } + + dest.length = (this || _global$7$1).length; + dest.negative = (this || _global$7$1).negative; + dest.red = (this || _global$7$1).red; + }; + + function move(dest, src) { + dest.words = src.words; + dest.length = src.length; + dest.negative = src.negative; + dest.red = src.red; + } + + BN.prototype._move = function _move(dest) { + move(dest, this || _global$7$1); + }; + + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + + BN.prototype._expand = function _expand(size) { + while ((this || _global$7$1).length < size) { + (this || _global$7$1).words[(this || _global$7$1).length++] = 0; + } + + return this || _global$7$1; + }; // Remove leading `0` from `this` + + + BN.prototype._strip = function strip() { + while ((this || _global$7$1).length > 1 && (this || _global$7$1).words[(this || _global$7$1).length - 1] === 0) { + (this || _global$7$1).length--; + } + + return this._normSign(); + }; + + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$7$1).length === 1 && (this || _global$7$1).words[0] === 0) { + (this || _global$7$1).negative = 0; + } + + return this || _global$7$1; + }; // Check Symbol.for because not everywhere where Symbol defined + // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility + + + if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") { + try { + BN.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect; + } catch (e) { + BN.prototype.inspect = inspect; + } } else { - // emit 'readable' now to make sure it gets picked up. - state.needReadable = false; + BN.prototype.inspect = inspect; + } + + function inspect() { + return ((this || _global$7$1).red ? ""; + } + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ + + + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; + + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + + for (var i = 0; i < (this || _global$7$1).length; i++) { + var w = (this || _global$7$1).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + + if (carry !== 0 || i !== (this || _global$7$1).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + + off += 2; + + if (off >= 26) { + off -= 26; + i--; + } + } + + if (carry !== 0) { + out = carry.toString(16) + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$7$1).negative !== 0) { + out = "-" + out; + } + + return out; + } + + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + + while (!c.isZero()) { + var r = c.modrn(groupBase).toString(base); + c = c.idivn(groupBase); + + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + + if (this.isZero()) { + out = "0" + out; + } + + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$7$1).negative !== 0) { + out = "-" + out; + } + + return out; + } + + assert(false, "Base should be between 2 and 36"); + }; + + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$7$1).words[0]; + + if ((this || _global$7$1).length === 2) { + ret += (this || _global$7$1).words[1] * 67108864; + } else if ((this || _global$7$1).length === 3 && (this || _global$7$1).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$7$1).words[1] * 67108864; + } else if ((this || _global$7$1).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } + + return (this || _global$7$1).negative !== 0 ? -ret : ret; + }; + + BN.prototype.toJSON = function toJSON() { + return this.toString(16, 2); + }; + + if (Buffer) { + BN.prototype.toBuffer = function toBuffer(endian, length) { + return this.toArrayLike(Buffer, endian, length); + }; + } + + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + var allocate = function allocate(ArrayType, size) { + if (ArrayType.allocUnsafe) { + return ArrayType.allocUnsafe(size); + } + + return new ArrayType(size); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + this._strip(); + + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + var res = allocate(ArrayType, reqLength); + var postfix = endian === "le" ? "LE" : "BE"; + this["_toArrayLike" + postfix](res, byteLength); + return res; + }; + + BN.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) { + var position = 0; + var carry = 0; + + for (var i = 0, shift = 0; i < (this || _global$7$1).length; i++) { + var word = (this || _global$7$1).words[i] << shift | carry; + res[position++] = word & 255; + + if (position < res.length) { + res[position++] = word >> 8 & 255; + } + + if (position < res.length) { + res[position++] = word >> 16 & 255; + } + + if (shift === 6) { + if (position < res.length) { + res[position++] = word >> 24 & 255; + } + + carry = 0; + shift = 0; + } else { + carry = word >>> 24; + shift += 2; + } + } + + if (position < res.length) { + res[position++] = carry; + + while (position < res.length) { + res[position++] = 0; + } + } + }; + + BN.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) { + var position = res.length - 1; + var carry = 0; + + for (var i = 0, shift = 0; i < (this || _global$7$1).length; i++) { + var word = (this || _global$7$1).words[i] << shift | carry; + res[position--] = word & 255; + + if (position >= 0) { + res[position--] = word >> 8 & 255; + } + + if (position >= 0) { + res[position--] = word >> 16 & 255; + } + + if (shift === 6) { + if (position >= 0) { + res[position--] = word >> 24 & 255; + } + + carry = 0; + shift = 0; + } else { + carry = word >>> 24; + shift += 2; + } + } + + if (position >= 0) { + res[position--] = carry; + + while (position >= 0) { + res[position--] = 0; + } + } + }; + + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; - if (!state.emittedReadable) { - state.emittedReadable = true; - emitReadable_(stream); - } - } - } // Don't emit readable right away in sync mode, because this can trigger - // another read() call => stack overflow. This way, it might trigger - // a nextTick recursion warning, but that's not so bad. + if (t >= 4096) { + r += 13; + t >>>= 13; + } + if (t >= 64) { + r += 7; + t >>>= 7; + } - function emitReadable(stream) { - var state = stream._readableState; - debug("emitReadable", state.needReadable, state.emittedReadable); - state.needReadable = false; + if (t >= 8) { + r += 4; + t >>>= 4; + } - if (!state.emittedReadable) { - debug("emitReadable", state.flowing); - state.emittedReadable = true; - process.nextTick(emitReadable_, stream); + if (t >= 2) { + r += 2; + t >>>= 2; + } + + return r + t; + }; } - } - function emitReadable_(stream) { - var state = stream._readableState; - debug("emitReadable_", state.destroyed, state.length, state.ended); + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; - if (!state.destroyed && (state.length || state.ended)) { - stream.emit("readable"); - state.emittedReadable = false; - } // The stream needs another readable event if - // 1. It is not flowing, as the flow mechanism will take - // care of it. - // 2. It is not ended. - // 3. It is below the highWaterMark, so we can schedule - // another readable later. + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; + } + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } - state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark; - flow(stream); - } // at this point, the user has presumably seen the 'readable' event, - // and called read() to consume some data. that may have triggered - // in turn another _read(n) call, in which case reading = true if - // it's in progress. - // However, if we're not ended, or reading, and the length < hwm, - // then go ahead and try to read some more preemptively. + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } - function maybeReadMore(stream, state) { - if (!state.readingMore) { - state.readingMore = true; - process.nextTick(maybeReadMore_, stream, state); - } - } + if ((t & 1) === 0) { + r++; + } - function maybeReadMore_(stream, state) { - // Attempt to read more data if we should. - // - // The conditions for reading more data are (one of): - // - Not enough data buffered (state.length < state.highWaterMark). The loop - // is responsible for filling the buffer with enough data if such data - // is available. If highWaterMark is 0 and we are not in the flowing mode - // we should _not_ attempt to buffer any extra data. We'll get more data - // when the stream consumer calls read() instead. - // - No data in the buffer, and the stream is in flowing mode. In this mode - // the loop below is responsible for ensuring read() is called. Failing to - // call read here would abort the flow and there's no other mechanism for - // continuing the flow if the stream consumer has just subscribed to the - // 'data' event. - // - // In addition to the above conditions to keep reading data, the following - // conditions prevent the data from being read: - // - The stream has ended (state.ended). - // - There is already a pending 'read' operation (state.reading). This is a - // case where the the stream has called the implementation defined _read() - // method, but they are processing the call asynchronously and have _not_ - // called push() with new data. In this case we skip performing more - // read()s. The execution ends in this method again after the _read() ends - // up calling push() with more data. - while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { - var len = state.length; - debug("maybeReadMore read 0"); - stream.read(0); - if (len === state.length) // didn't get any data, stop spinning. - break; - } + return r; + }; // Return number of used bits in a BN - state.readingMore = false; - } // abstract method. to be overridden in specific implementation classes. - // call cb(er, data) where data is <= n in length. - // for virtual (non-string, non-buffer) streams, "length" is somewhat - // arbitrary, and perhaps not very meaningful. + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$7$1).words[(this || _global$7$1).length - 1]; + + var hi = this._countBits(w); - Readable.prototype._read = function (n) { - errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED("_read()")); - }; + return ((this || _global$7$1).length - 1) * 26 + hi; + }; - Readable.prototype.pipe = function (dest, pipeOpts) { - var src = this; - var state = this._readableState; + function toBitArray(num) { + var w = new Array(num.bitLength()); - switch (state.pipesCount) { - case 0: - state.pipes = dest; - break; + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = num.words[off] >>> wbit & 1; + } - case 1: - state.pipes = [state.pipes, dest]; - break; + return w; + } // Number of trailing zero bits - default: - state.pipes.push(dest); - break; - } - state.pipesCount += 1; - debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts); - var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process.stdout && dest !== process.stderr; - var endFn = doEnd ? onend : unpipe; - if (state.endEmitted) process.nextTick(endFn);else src.once("end", endFn); - dest.on("unpipe", onunpipe); + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; - function onunpipe(readable, unpipeInfo) { - debug("onunpipe"); + for (var i = 0; i < (this || _global$7$1).length; i++) { + var b = this._zeroBits((this || _global$7$1).words[i]); - if (readable === src) { - if (unpipeInfo && unpipeInfo.hasUnpiped === false) { - unpipeInfo.hasUnpiped = true; - cleanup(); - } + r += b; + if (b !== 26) break; } - } - function onend() { - debug("onend"); - dest.end(); - } // when the dest drains, it reduces the awaitDrain counter - // on the source. This would be more elegant with a .once() - // handler in flow(), but adding and removing repeatedly is - // too slow. + return r; + }; + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; - var ondrain = pipeOnDrain(src); - dest.on("drain", ondrain); - var cleanedUp = false; + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$7$1).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } - function cleanup() { - debug("cleanup"); // cleanup event handlers once the pipe is broken + return this.clone(); + }; - dest.removeListener("close", onclose); - dest.removeListener("finish", onfinish); - dest.removeListener("drain", ondrain); - dest.removeListener("error", onerror); - dest.removeListener("unpipe", onunpipe); - src.removeListener("end", onend); - src.removeListener("end", unpipe); - src.removeListener("data", ondata); - cleanedUp = true; // if the reader is waiting for a drain event from this - // specific writer, then it would cause it to never start - // flowing again. - // So, if this is awaiting a drain, then we just call it now. - // If we don't know, then assume that we are waiting for one. + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } - if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); - } + return this.clone(); + }; - src.on("data", ondata); + BN.prototype.isNeg = function isNeg() { + return (this || _global$7$1).negative !== 0; + }; // Return negative clone of `this` - function ondata(chunk) { - debug("ondata"); - var ret = dest.write(chunk); - debug("dest.write", ret); - if (ret === false) { - // If the user unpiped during `dest.write()`, it is possible - // to get stuck in a permanently paused state if that write - // also returned false. - // => Check whether `dest` is still a piping destination. - if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { - debug("false write response, pause", state.awaitDrain); - state.awaitDrain++; - } + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; - src.pause(); + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$7$1).negative ^= 1; } - } // if the dest has an error, then stop piping into it. - // however, don't suppress the throwing behavior for this. - - - function onerror(er) { - debug("onerror", er); - unpipe(); - dest.removeListener("error", onerror); - if (EElistenerCount(dest, "error") === 0) errorOrDestroy(dest, er); - } // Make sure our error handler is attached before userland ones. + return this || _global$7$1; + }; // Or `num` with `this` in-place - prependListener(dest, "error", onerror); // Both close and finish should trigger unpipe, but only once. - function onclose() { - dest.removeListener("finish", onfinish); - unpipe(); - } + BN.prototype.iuor = function iuor(num) { + while ((this || _global$7$1).length < num.length) { + (this || _global$7$1).words[(this || _global$7$1).length++] = 0; + } - dest.once("close", onclose); + for (var i = 0; i < num.length; i++) { + (this || _global$7$1).words[i] = (this || _global$7$1).words[i] | num.words[i]; + } - function onfinish() { - debug("onfinish"); - dest.removeListener("close", onclose); - unpipe(); - } + return this._strip(); + }; - dest.once("finish", onfinish); + BN.prototype.ior = function ior(num) { + assert(((this || _global$7$1).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` - function unpipe() { - debug("unpipe"); - src.unpipe(dest); - } // tell the dest that it's being piped to + BN.prototype.or = function or(num) { + if ((this || _global$7$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$7$1); + }; - dest.emit("pipe", src); // start the flow if it hasn't been started already. + BN.prototype.uor = function uor(num) { + if ((this || _global$7$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$7$1); + }; // And `num` with `this` in-place - if (!state.flowing) { - debug("pipe resume"); - src.resume(); - } - return dest; - }; + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; - function pipeOnDrain(src) { - return function pipeOnDrainFunctionResult() { - var state = src._readableState; - debug("pipeOnDrain", state.awaitDrain); - if (state.awaitDrain) state.awaitDrain--; + if ((this || _global$7$1).length > num.length) { + b = num; + } else { + b = this || _global$7$1; + } - if (state.awaitDrain === 0 && EElistenerCount(src, "data")) { - state.flowing = true; - flow(src); + for (var i = 0; i < b.length; i++) { + (this || _global$7$1).words[i] = (this || _global$7$1).words[i] & num.words[i]; } + + (this || _global$7$1).length = b.length; + return this._strip(); }; - } - Readable.prototype.unpipe = function (dest) { - var state = this._readableState; - var unpipeInfo = { - hasUnpiped: false - }; // if we're not piping anywhere, then do nothing. + BN.prototype.iand = function iand(num) { + assert(((this || _global$7$1).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` - if (state.pipesCount === 0) return this; // just one destination. most common case. - if (state.pipesCount === 1) { - // passed in one, but it's not the right one. - if (dest && dest !== state.pipes) return this; - if (!dest) dest = state.pipes; // got a match. + BN.prototype.and = function and(num) { + if ((this || _global$7$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$7$1); + }; - state.pipes = null; - state.pipesCount = 0; - state.flowing = false; - if (dest) dest.emit("unpipe", this, unpipeInfo); - return this; - } // slow case. multiple pipe destinations. + BN.prototype.uand = function uand(num) { + if ((this || _global$7$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$7$1); + }; // Xor `num` with `this` in-place - if (!dest) { - // remove all. - var dests = state.pipes; - var len = state.pipesCount; - state.pipes = null; - state.pipesCount = 0; - state.flowing = false; + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; - for (var i = 0; i < len; i++) { - dests[i].emit("unpipe", this, { - hasUnpiped: false - }); + if ((this || _global$7$1).length > num.length) { + a = this || _global$7$1; + b = num; + } else { + a = num; + b = this || _global$7$1; } - return this; - } // try to find the right one. + for (var i = 0; i < b.length; i++) { + (this || _global$7$1).words[i] = a.words[i] ^ b.words[i]; + } + + if ((this || _global$7$1) !== a) { + for (; i < a.length; i++) { + (this || _global$7$1).words[i] = a.words[i]; + } + } + (this || _global$7$1).length = a.length; + return this._strip(); + }; - var index = indexOf(state.pipes, dest); - if (index === -1) return this; - state.pipes.splice(index, 1); - state.pipesCount -= 1; - if (state.pipesCount === 1) state.pipes = state.pipes[0]; - dest.emit("unpipe", this, unpipeInfo); - return this; - }; // set up data events if they are asked for - // Ensure readable listeners eventually get something + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$7$1).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` - Readable.prototype.on = function (ev, fn) { - var res = Stream.prototype.on.call(this, ev, fn); - var state = this._readableState; + BN.prototype.xor = function xor(num) { + if ((this || _global$7$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$7$1); + }; - if (ev === "data") { - // update readableListening so that resume() may be a no-op - // a few lines down. This is needed to support once('readable'). - state.readableListening = this.listenerCount("readable") > 0; // Try start flowing on next tick if stream isn't explicitly paused + BN.prototype.uxor = function uxor(num) { + if ((this || _global$7$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$7$1); + }; // Not ``this`` with ``width`` bitwidth - if (state.flowing !== false) this.resume(); - } else if (ev === "readable") { - if (!state.endEmitted && !state.readableListening) { - state.readableListening = state.needReadable = true; - state.flowing = false; - state.emittedReadable = false; - debug("on readable", state.length, state.reading); - if (state.length) { - emitReadable(this); - } else if (!state.reading) { - process.nextTick(nReadingNextTick, this); - } - } - } + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes - return res; - }; + this._expand(bytesNeeded); - Readable.prototype.addListener = Readable.prototype.on; + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words - Readable.prototype.removeListener = function (ev, fn) { - var res = Stream.prototype.removeListener.call(this, ev, fn); - if (ev === "readable") { - // We need to check if there is someone still listening to - // readable and reset the state. However this needs to happen - // after readable has been emitted but before I/O (nextTick) to - // support once('readable', fn) cycles. This means that calling - // resume within the same tick will have no - // effect. - process.nextTick(updateReadableListening, this); - } + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$7$1).words[i] = ~(this || _global$7$1).words[i] & 67108863; + } // Handle the residue - return res; - }; - Readable.prototype.removeAllListeners = function (ev) { - var res = Stream.prototype.removeAllListeners.apply(this, arguments); + if (bitsLeft > 0) { + (this || _global$7$1).words[i] = ~(this || _global$7$1).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes - if (ev === "readable" || ev === undefined) { - // We need to check if there is someone still listening to - // readable and reset the state. However this needs to happen - // after readable has been emitted but before I/O (nextTick) to - // support once('readable', fn) cycles. This means that calling - // resume within the same tick will have no - // effect. - process.nextTick(updateReadableListening, this); - } - return res; - }; + return this._strip(); + }; - function updateReadableListening(self) { - var state = self._readableState; - state.readableListening = self.listenerCount("readable") > 0; + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` - if (state.resumeScheduled && !state.paused) { - // flowing needs to be set to true now, otherwise - // the upcoming resume will not flow. - state.flowing = true; // crude way to check if we should resume - } else if (self.listenerCount("data") > 0) { - self.resume(); - } - } - function nReadingNextTick(self) { - debug("readable nexttick read 0"); - self.read(0); - } // pause() and resume() are remnants of the legacy readable stream API - // If the user uses them, then switch into old mode. + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; + this._expand(off + 1); - Readable.prototype.resume = function () { - var state = this._readableState; + if (val) { + (this || _global$7$1).words[off] = (this || _global$7$1).words[off] | 1 << wbit; + } else { + (this || _global$7$1).words[off] = (this || _global$7$1).words[off] & ~(1 << wbit); + } - if (!state.flowing) { - debug("resume"); // we flow only if there is no one listening - // for readable, but we still have to call - // resume() + return this._strip(); + }; // Add `num` to `this` in-place - state.flowing = !state.readableListening; - resume(this, state); - } - state.paused = false; - return this; - }; + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive - function resume(stream, state) { - if (!state.resumeScheduled) { - state.resumeScheduled = true; - process.nextTick(resume_, stream, state); - } - } + if ((this || _global$7$1).negative !== 0 && num.negative === 0) { + (this || _global$7$1).negative = 0; + r = this.isub(num); + (this || _global$7$1).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$7$1).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length - function resume_(stream, state) { - debug("resume", state.reading); - if (!state.reading) { - stream.read(0); - } + var a, b; - state.resumeScheduled = false; - stream.emit("resume"); - flow(stream); - if (state.flowing && !state.reading) stream.read(0); - } + if ((this || _global$7$1).length > num.length) { + a = this || _global$7$1; + b = num; + } else { + a = num; + b = this || _global$7$1; + } - Readable.prototype.pause = function () { - debug("call pause flowing=%j", this._readableState.flowing); + var carry = 0; - if (this._readableState.flowing !== false) { - debug("pause"); - this._readableState.flowing = false; - this.emit("pause"); - } + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$7$1).words[i] = r & 67108863; + carry = r >>> 26; + } - this._readableState.paused = true; - return this; - }; + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$7$1).words[i] = r & 67108863; + carry = r >>> 26; + } - function flow(stream) { - var state = stream._readableState; - debug("flow", state.flowing); + (this || _global$7$1).length = a.length; - while (state.flowing && stream.read() !== null) { - } - } // wrap an old-style stream as the async data source. - // This is *not* part of the readable stream interface. - // It is an ugly unfortunate mess of history. + if (carry !== 0) { + (this || _global$7$1).words[(this || _global$7$1).length] = carry; + (this || _global$7$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$7$1)) { + for (; i < a.length; i++) { + (this || _global$7$1).words[i] = a.words[i]; + } + } + return this || _global$7$1; + }; // Add `num` to `this` - Readable.prototype.wrap = function (stream) { - var _this = this; - var state = this._readableState; - var paused = false; - stream.on("end", function () { - debug("wrapped end"); + BN.prototype.add = function add(num) { + var res; - if (state.decoder && !state.ended) { - var chunk = state.decoder.end(); - if (chunk && chunk.length) _this.push(chunk); + if (num.negative !== 0 && (this || _global$7$1).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$7$1).negative !== 0) { + (this || _global$7$1).negative = 0; + res = num.sub(this || _global$7$1); + (this || _global$7$1).negative = 1; + return res; } - _this.push(null); - }); - stream.on("data", function (chunk) { - debug("wrapped data"); - if (state.decoder) chunk = state.decoder.write(chunk); // don't skip over falsy values in objectMode - - if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + if ((this || _global$7$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$7$1); + }; // Subtract `num` from `this` in-place - var ret = _this.push(chunk); - if (!ret) { - paused = true; - stream.pause(); - } - }); // proxy all the other methods. - // important when wrapping filters and duplexes. + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$7$1).negative !== 0) { + (this || _global$7$1).negative = 0; + this.iadd(num); + (this || _global$7$1).negative = 1; + return this._normSign(); + } // At this point both numbers are positive - for (var i in stream) { - if (this[i] === undefined && typeof stream[i] === "function") { - this[i] = function methodWrap(method) { - return function methodWrapReturnFunction() { - return stream[method].apply(stream, arguments); - }; - }(i); - } - } // proxy certain important events. + var cmp = this.cmp(num); // Optimization - zeroify - for (var n = 0; n < kProxyEvents.length; n++) { - stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n])); - } // when we try to consume some more bytes, simply unpause the - // underlying stream. + if (cmp === 0) { + (this || _global$7$1).negative = 0; + (this || _global$7$1).length = 1; + (this || _global$7$1).words[0] = 0; + return this || _global$7$1; + } // a > b - this._read = function (n) { - debug("wrapped _read", n); + var a, b; - if (paused) { - paused = false; - stream.resume(); + if (cmp > 0) { + a = this || _global$7$1; + b = num; + } else { + a = num; + b = this || _global$7$1; } - }; - return this; - }; + var carry = 0; - if (typeof Symbol === "function") { - Readable.prototype[Symbol.asyncIterator] = function () { - if (createReadableStreamAsyncIterator === undefined) { - createReadableStreamAsyncIterator = dew$5$2(); + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$7$1).words[i] = r & 67108863; } - return createReadableStreamAsyncIterator(this); - }; - } + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$7$1).words[i] = r & 67108863; + } // Copy rest of the words - Object.defineProperty(Readable.prototype, "readableHighWaterMark", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._readableState.highWaterMark; - } - }); - Object.defineProperty(Readable.prototype, "readableBuffer", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._readableState && this._readableState.buffer; - } - }); - Object.defineProperty(Readable.prototype, "readableFlowing", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._readableState.flowing; - }, - set: function set(state) { - if (this._readableState) { - this._readableState.flowing = state; + + if (carry === 0 && i < a.length && a !== (this || _global$7$1)) { + for (; i < a.length; i++) { + (this || _global$7$1).words[i] = a.words[i]; + } } - } - }); // exposed for testing purposes only. - Readable._fromList = fromList; - Object.defineProperty(Readable.prototype, "readableLength", { - // making it explicit this property is not enumerable - // because otherwise some prototype manipulation in - // userland will fail - enumerable: false, - get: function get() { - return this._readableState.length; - } - }); // Pluck off n bytes from an array of buffers. - // Length is the combined lengths of all the buffers in the list. - // This function is designed to be inlinable, so please take care when making - // changes to the function body. + (this || _global$7$1).length = Math.max((this || _global$7$1).length, i); - function fromList(n, state) { - // nothing buffered - if (state.length === 0) return null; - var ret; - if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { - // read it all, truncate the list - if (state.decoder) ret = state.buffer.join("");else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length); - state.buffer.clear(); - } else { - // read part of list - ret = state.buffer.consume(n, state.decoder); - } - return ret; - } + if (a !== (this || _global$7$1)) { + (this || _global$7$1).negative = 1; + } - function endReadable(stream) { - var state = stream._readableState; - debug("endReadable", state.endEmitted); + return this._strip(); + }; // Subtract `num` from `this` - if (!state.endEmitted) { - state.ended = true; - process.nextTick(endReadableNT, state, stream); - } - } - function endReadableNT(state, stream) { - debug("endReadableNT", state.endEmitted, state.length); // Check that we didn't get one last unshift. + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; - if (!state.endEmitted && state.length === 0) { - state.endEmitted = true; - stream.readable = false; - stream.emit("end"); + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) - if (state.autoDestroy) { - // In case of duplex streams we need a way to detect - // if the writable side is ready for autoDestroy as well - var wState = stream._writableState; + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; - if (!wState || wState.autoDestroy && wState.finished) { - stream.destroy(); + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); + + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; } - } - } - } - if (typeof Symbol === "function") { - Readable.from = function (iterable, opts) { - if (from === undefined) { - from = dew$4$2(); + out.words[k] = rword | 0; + carry = ncarry | 0; } - return from(Readable, iterable, opts); - }; - } - - function indexOf(xs, x) { - for (var i = 0, l = xs.length; i < l; i++) { - if (xs[i] === x) return i; - } - - return -1; - } + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } - return exports$3$2; -} + return out._strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). -var exports$2$2 = {}, - _dewExec$2$2 = false; -function dew$2$2() { - if (_dewExec$2$2) return exports$2$2; - _dewExec$2$2 = true; - exports$2$2 = Transform; - var _require$codes = dew$b$2().codes, - ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, - ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, - ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING, - ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0; + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ - var Duplex = dew$7$2(); + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ - dew$f$2()(Transform, Duplex); + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ - function afterTransform(er, data) { - var ts = this._transformState; - ts.transforming = false; - var cb = ts.writecb; + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ - if (cb === null) { - return this.emit("error", new ERR_MULTIPLE_CALLBACK()); - } + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ - ts.writechunk = null; - ts.writecb = null; - if (data != null) // single equals check for both `null` and `undefined` - this.push(data); - cb(er); - var rs = this._readableState; - rs.reading = false; + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ - if (rs.needReadable || rs.length < rs.highWaterMark) { - this._read(rs.highWaterMark); - } - } + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ - function Transform(options) { - if (!(this instanceof Transform)) return new Transform(options); - Duplex.call(this, options); - this._transformState = { - afterTransform: afterTransform.bind(this), - needTransform: false, - transforming: false, - writecb: null, - writechunk: null, - writeencoding: null - }; // start out asking for a readable event once data is transformed. + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ - this._readableState.needReadable = true; // we have implemented the _read method, and done the other things - // that Readable wants before the first _read call, so unset the - // sync guard flag. + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ - this._readableState.sync = false; + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ - if (options) { - if (typeof options.transform === "function") this._transform = options.transform; - if (typeof options.flush === "function") this._flush = options.flush; - } // When the writable side finishes, then flush out anything remaining. + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ - this.on("prefinish", prefinish); - } + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ - function prefinish() { - var _this = this; + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ - if (typeof this._flush === "function" && !this._readableState.destroyed) { - this._flush(function (er, data) { - done(_this, er, data); - }); - } else { - done(this, null, null); - } - } + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ - Transform.prototype.push = function (chunk, encoding) { - this._transformState.needTransform = false; - return Duplex.prototype.push.call(this, chunk, encoding); - }; // This is the part where you do stuff! - // override this function in implementation classes. - // 'chunk' is an input chunk. - // - // Call `push(newChunk)` to pass along transformed output - // to the readable side. You may call 'push' zero or more times. - // - // Call `cb(err)` when you are done with this chunk. If you pass - // an error, then that'll put the hurt on the whole operation. If you - // never call cb(), then you'll never get another chunk. + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ - Transform.prototype._transform = function (chunk, encoding, cb) { - cb(new ERR_METHOD_NOT_IMPLEMENTED("_transform()")); - }; + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ - Transform.prototype._write = function (chunk, encoding, cb) { - var ts = this._transformState; - ts.writecb = cb; - ts.writechunk = chunk; - ts.writeencoding = encoding; + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ - if (!ts.transforming) { - var rs = this._readableState; - if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); - } - }; // Doesn't matter what the args are here. - // _transform does all the work. - // That we got here means that the readable side wants more data. + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; + if (c !== 0) { + o[19] = c; + out.length++; + } - Transform.prototype._read = function (n) { - var ts = this._transformState; + return out; + }; // Polyfill comb - if (ts.writechunk !== null && !ts.transforming) { - ts.transforming = true; - this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); - } else { - // mark that we need a transform, so that any data that comes in - // will get processed, now that we've asked for it. - ts.needTransform = true; + if (!Math.imul) { + comb10MulTo = smallMulTo; } - }; - - Transform.prototype._destroy = function (err, cb) { - Duplex.prototype._destroy.call(this, err, function (err2) { - cb(err2); - }); - }; - function done(stream, er, data) { - if (er) return stream.emit("error", er); - if (data != null) // single equals check for both `null` and `undefined` - stream.push(data); // TODO(BridgeAR): Write a test for these two error cases - // if there's nothing in the write buffer, then that means - // that nothing more will ever be provided + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; - if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0(); - if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING(); - return stream.push(null); - } + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); - return exports$2$2; -} + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } -var exports$1$2 = {}, - _dewExec$1$2 = false; -function dew$1$2() { - if (_dewExec$1$2) return exports$1$2; - _dewExec$1$2 = true; - exports$1$2 = PassThrough; + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } - var Transform = dew$2$2(); + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } - dew$f$2()(PassThrough, Transform); + return out._strip(); + } - function PassThrough(options) { - if (!(this instanceof PassThrough)) return new PassThrough(options); - Transform.call(this, options); - } + function jumboMulTo(self, num, out) { + // Temporary disable, see https://github.com/indutny/bn.js/issues/211 + // var fftm = new FFTM(); + // return fftm.mulp(self, num, out); + return bigMulTo(self, num, out); + } - PassThrough.prototype._transform = function (chunk, encoding, cb) { - cb(null, chunk); - }; + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$7$1).length + num.length; - return exports$1$2; -} + if ((this || _global$7$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$7$1, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$7$1, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$7$1, num, out); + } else { + res = jumboMulTo(this || _global$7$1, num, out); + } -var exports$2C = {}, - _dewExec$2B = false; -function dew$2B() { - if (_dewExec$2B) return exports$2C; - _dewExec$2B = true; - var eos; + return res; + }; // Cooley-Tukey algorithm for FFT - function once(callback) { - var called = false; - return function () { - if (called) return; - called = true; - callback.apply(void 0, arguments); - }; - } - var _require$codes = dew$b$2().codes, - ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, - ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED; + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$7$1).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT - function noop(err) { - // Rethrow the error if it exists to avoid swallowing it - if (err) throw err; - } - function isRequest(stream) { - return stream.setHeader && typeof stream.abort === "function"; - } + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$7$1).length + num.length); + return jumboMulTo(this || _global$7$1, num, out); + }; // In-place Multiplication - function destroyer(stream, reading, writing, callback) { - callback = once(callback); - var closed = false; - stream.on("close", function () { - closed = true; - }); - if (eos === undefined) eos = dew$6$2(); - eos(stream, { - readable: reading, - writable: writing - }, function (err) { - if (err) return callback(err); - closed = true; - callback(); - }); - var destroyed = false; - return function (err) { - if (closed) return; - if (destroyed) return; - destroyed = true; // request.destroy just do .end - .abort is what we want - if (isRequest(stream)) return stream.abort(); - if (typeof stream.destroy === "function") return stream.destroy(); - callback(err || new ERR_STREAM_DESTROYED("pipe")); + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$7$1); }; - } - - function call(fn) { - fn(); - } - function pipe(from, to) { - return from.pipe(to); - } + BN.prototype.imuln = function imuln(num) { + var isNegNum = num < 0; + if (isNegNum) num = -num; + assert(typeof num === "number"); + assert(num < 67108864); // Carry - function popCallback(streams) { - if (!streams.length) return noop; - if (typeof streams[streams.length - 1] !== "function") return noop; - return streams.pop(); - } + var carry = 0; - function pipeline() { - for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) { - streams[_key] = arguments[_key]; - } + for (var i = 0; i < (this || _global$7$1).length; i++) { + var w = ((this || _global$7$1).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - var callback = popCallback(streams); - if (Array.isArray(streams[0])) streams = streams[0]; + carry += lo >>> 26; + (this || _global$7$1).words[i] = lo & 67108863; + } - if (streams.length < 2) { - throw new ERR_MISSING_ARGS("streams"); - } + if (carry !== 0) { + (this || _global$7$1).words[i] = carry; + (this || _global$7$1).length++; + } - var error; - var destroys = streams.map(function (stream, i) { - var reading = i < streams.length - 1; - var writing = i > 0; - return destroyer(stream, reading, writing, function (err) { - if (!error) error = err; - if (err) destroys.forEach(call); - if (reading) return; - destroys.forEach(call); - callback(error); - }); - }); - return streams.reduce(pipe); - } + return isNegNum ? this.ineg() : this || _global$7$1; + }; - exports$2C = pipeline; - return exports$2C; -} + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` -var exports$2B = {}, - _dewExec$2A = false; -var _global$L = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$7$1); + }; // `this` * `this` in-place -function dew$2A() { - if (_dewExec$2A) return exports$2B; - _dewExec$2A = true; - // Copyright Joyent, Inc. and other Node contributors. - // - // Permission is hereby granted, free of charge, to any person obtaining a - // copy of this software and associated documentation files (the - // "Software"), to deal in the Software without restriction, including - // without limitation the rights to use, copy, modify, merge, publish, - // distribute, sublicense, and/or sell copies of the Software, and to permit - // persons to whom the Software is furnished to do so, subject to the - // following conditions: - // - // The above copyright notice and this permission notice shall be included - // in all copies or substantial portions of the Software. - // - // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS - // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF - // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN - // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR - // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE - // USE OR OTHER DEALINGS IN THE SOFTWARE. - exports$2B = Stream; - var EE = y$o.EventEmitter; - var inherits = dew$f$2(); + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) - inherits(Stream, EE); - Stream.Readable = dew$3$2(); - Stream.Writable = dew$8$2(); - Stream.Duplex = dew$7$2(); - Stream.Transform = dew$2$2(); - Stream.PassThrough = dew$1$2(); - Stream.finished = dew$6$2(); - Stream.pipeline = dew$2B(); // Backwards-compat with node 0.4.x - Stream.Stream = Stream; // old-style streams. Note that the pipe method (the only relevant - // part of this class) is overridden in the Readable class. + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes - function Stream() { - EE.call(this || _global$L); - } + var res = this || _global$7$1; - Stream.prototype.pipe = function (dest, options) { - var source = this || _global$L; + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } - function ondata(chunk) { - if (dest.writable) { - if (false === dest.write(chunk) && source.pause) { - source.pause(); + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); } } - } - - source.on("data", ondata); - function ondrain() { - if (source.readable && source.resume) { - source.resume(); - } - } + return res; + }; // Shift-left in-place - dest.on("drain", ondrain); // If the 'end' option is not supplied, dest.end() will be called when - // source gets the 'end' or 'close' events. Only dest.end() once. - if (!dest._isStdio && (!options || options.end !== false)) { - source.on("end", onend); - source.on("close", onclose); - } + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; - var didOnEnd = false; + if (r !== 0) { + var carry = 0; - function onend() { - if (didOnEnd) return; - didOnEnd = true; - dest.end(); - } + for (i = 0; i < (this || _global$7$1).length; i++) { + var newCarry = (this || _global$7$1).words[i] & carryMask; + var c = ((this || _global$7$1).words[i] | 0) - newCarry << r; + (this || _global$7$1).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } - function onclose() { - if (didOnEnd) return; - didOnEnd = true; - if (typeof dest.destroy === "function") dest.destroy(); - } // don't leave dangling pipes when there are errors. + if (carry) { + (this || _global$7$1).words[i] = carry; + (this || _global$7$1).length++; + } + } + if (s !== 0) { + for (i = (this || _global$7$1).length - 1; i >= 0; i--) { + (this || _global$7$1).words[i + s] = (this || _global$7$1).words[i]; + } - function onerror(er) { - cleanup(); + for (i = 0; i < s; i++) { + (this || _global$7$1).words[i] = 0; + } - if (EE.listenerCount(this || _global$L, "error") === 0) { - throw er; // Unhandled stream error in pipe. + (this || _global$7$1).length += s; } - } - source.on("error", onerror); - dest.on("error", onerror); // remove all the event listeners that were added. + return this._strip(); + }; - function cleanup() { - source.removeListener("data", ondata); - dest.removeListener("drain", ondrain); - source.removeListener("end", onend); - source.removeListener("close", onclose); - source.removeListener("error", onerror); - dest.removeListener("error", onerror); - source.removeListener("end", cleanup); - source.removeListener("close", cleanup); - dest.removeListener("close", cleanup); - } + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$7$1).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits - source.on("end", cleanup); - source.on("close", cleanup); - dest.on("close", cleanup); - dest.emit("pipe", source); // Allow for unix-like usage: A.pipe(B).pipe(C) - return dest; - }; + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; - return exports$2B; -} + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } -var stream = dew$2A(); + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$7$1).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part -stream.Readable; -stream.Writable; -stream.Duplex; -stream.Transform; -stream.PassThrough; -stream.finished; -stream.pipeline; -stream.Stream; + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$7$1).words[i]; + } -({ - finished: promisify(stream.finished), - pipeline: promisify(stream.pipeline) -}); + maskedWords.length = s; + } -var exports$2A = {}, - _dewExec$2z = false; + if (s === 0) ; else if ((this || _global$7$1).length > s) { + (this || _global$7$1).length -= s; -var _global$K = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + for (i = 0; i < (this || _global$7$1).length; i++) { + (this || _global$7$1).words[i] = (this || _global$7$1).words[i + s]; + } + } else { + (this || _global$7$1).words[0] = 0; + (this || _global$7$1).length = 1; + } -function dew$2z() { - if (_dewExec$2z) return exports$2A; - _dewExec$2z = true; + var carry = 0; - var Buffer = dew$2P().Buffer; + for (i = (this || _global$7$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$7$1).words[i] | 0; + (this || _global$7$1).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask - var Transform = stream.Transform; - var StringDecoder = e$1$2.StringDecoder; - var inherits = dew$2R(); + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } - function CipherBase(hashMode) { - Transform.call(this || _global$K); - (this || _global$K).hashMode = typeof hashMode === "string"; + if ((this || _global$7$1).length === 0) { + (this || _global$7$1).words[0] = 0; + (this || _global$7$1).length = 1; + } - if ((this || _global$K).hashMode) { - (this || _global$K)[hashMode] = (this || _global$K)._finalOrDigest; - } else { - (this || _global$K).final = (this || _global$K)._finalOrDigest; - } + return this._strip(); + }; - if ((this || _global$K)._final) { - (this || _global$K).__final = (this || _global$K)._final; - (this || _global$K)._final = null; - } + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$7$1).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left - (this || _global$K)._decoder = null; - (this || _global$K)._encoding = null; - } - inherits(CipherBase, Transform); + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; - CipherBase.prototype.update = function (data, inputEnc, outputEnc) { - if (typeof data === "string") { - data = Buffer.from(data, inputEnc); - } + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right - var outData = this._update(data); - if ((this || _global$K).hashMode) return this || _global$K; + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; - if (outputEnc) { - outData = this._toString(outData, outputEnc); - } + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set - return outData; - }; - CipherBase.prototype.setAutoPadding = function () {}; + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words - CipherBase.prototype.getAuthTag = function () { - throw new Error("trying to get auth tag in unsupported state"); - }; + if ((this || _global$7$1).length <= s) return false; // Check bit and return - CipherBase.prototype.setAuthTag = function () { - throw new Error("trying to set auth tag in unsupported state"); - }; + var w = (this || _global$7$1).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) - CipherBase.prototype.setAAD = function () { - throw new Error("trying to set aad in unsupported state"); - }; - CipherBase.prototype._transform = function (data, _, next) { - var err; + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$7$1).negative === 0, "imaskn works only with positive numbers"); - try { - if ((this || _global$K).hashMode) { - this._update(data); - } else { - this.push(this._update(data)); + if ((this || _global$7$1).length <= s) { + return this || _global$7$1; } - } catch (e) { - err = e; - } finally { - next(err); - } - }; - CipherBase.prototype._flush = function (done) { - var err; + if (r !== 0) { + s++; + } - try { - this.push(this.__final()); - } catch (e) { - err = e; - } + (this || _global$7$1).length = Math.min(s, (this || _global$7$1).length); + + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$7$1).words[(this || _global$7$1).length - 1] &= mask; + } - done(err); - }; + return this._strip(); + }; // Return only lowers bits of number - CipherBase.prototype._finalOrDigest = function (outputEnc) { - var outData = this.__final() || Buffer.alloc(0); - if (outputEnc) { - outData = this._toString(outData, outputEnc, true); - } + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` - return outData; - }; - CipherBase.prototype._toString = function (value, enc, fin) { - if (!(this || _global$K)._decoder) { - (this || _global$K)._decoder = new StringDecoder(enc); - (this || _global$K)._encoding = enc; - } + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$K)._encoding !== enc) throw new Error("can't switch encodings"); + if ((this || _global$7$1).negative !== 0) { + if ((this || _global$7$1).length === 1 && ((this || _global$7$1).words[0] | 0) <= num) { + (this || _global$7$1).words[0] = num - ((this || _global$7$1).words[0] | 0); + (this || _global$7$1).negative = 0; + return this || _global$7$1; + } - var out = (this || _global$K)._decoder.write(value); + (this || _global$7$1).negative = 0; + this.isubn(num); + (this || _global$7$1).negative = 1; + return this || _global$7$1; + } // Add without checks - if (fin) { - out += (this || _global$K)._decoder.end(); - } - return out; - }; + return this._iaddn(num); + }; - exports$2A = CipherBase; - return exports$2A; -} + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$7$1).words[0] += num; // Carry -var exports$2z = {}, - _dewExec$2y = false; -function dew$2y() { - if (_dewExec$2y) return exports$2z; - _dewExec$2y = true; + for (var i = 0; i < (this || _global$7$1).length && (this || _global$7$1).words[i] >= 67108864; i++) { + (this || _global$7$1).words[i] -= 67108864; - var inherits = dew$2R(); + if (i === (this || _global$7$1).length - 1) { + (this || _global$7$1).words[i + 1] = 1; + } else { + (this || _global$7$1).words[i + 1]++; + } + } - var MD5 = dew$2L(); + (this || _global$7$1).length = Math.max((this || _global$7$1).length, i + 1); + return this || _global$7$1; + }; // Subtract plain number `num` from `this` - var RIPEMD160 = dew$2K(); - var sha = dew$2C(); + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); - var Base = dew$2z(); + if ((this || _global$7$1).negative !== 0) { + (this || _global$7$1).negative = 0; + this.iaddn(num); + (this || _global$7$1).negative = 1; + return this || _global$7$1; + } - function Hash(hash) { - Base.call(this, "digest"); - this._hash = hash; - } + (this || _global$7$1).words[0] -= num; - inherits(Hash, Base); + if ((this || _global$7$1).length === 1 && (this || _global$7$1).words[0] < 0) { + (this || _global$7$1).words[0] = -(this || _global$7$1).words[0]; + (this || _global$7$1).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$7$1).length && (this || _global$7$1).words[i] < 0; i++) { + (this || _global$7$1).words[i] += 67108864; + (this || _global$7$1).words[i + 1] -= 1; + } + } - Hash.prototype._update = function (data) { - this._hash.update(data); - }; + return this._strip(); + }; - Hash.prototype._final = function () { - return this._hash.digest(); - }; + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; - exports$2z = function createHash(alg) { - alg = alg.toLowerCase(); - if (alg === "md5") return new MD5(); - if (alg === "rmd160" || alg === "ripemd160") return new RIPEMD160(); - return new Hash(sha(alg)); - }; + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; - return exports$2z; -} + BN.prototype.iabs = function iabs() { + (this || _global$7$1).negative = 0; + return this || _global$7$1; + }; -var exports$2y = {}, - _dewExec$2x = false; -function dew$2x() { - if (_dewExec$2x) return exports$2y; - _dewExec$2x = true; + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; - var inherits = dew$2R(); + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; - var Buffer = dew$2P().Buffer; + this._expand(len); - var Base = dew$2z(); + var w; + var carry = 0; - var ZEROS = Buffer.alloc(128); - var blocksize = 64; + for (i = 0; i < num.length; i++) { + w = ((this || _global$7$1).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$7$1).words[i + shift] = w & 67108863; + } - function Hmac(alg, key) { - Base.call(this, "digest"); + for (; i < (this || _global$7$1).length - shift; i++) { + w = ((this || _global$7$1).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$7$1).words[i + shift] = w & 67108863; + } - if (typeof key === "string") { - key = Buffer.from(key); - } + if (carry === 0) return this._strip(); // Subtraction overflow - this._alg = alg; - this._key = key; + assert(carry === -1); + carry = 0; - if (key.length > blocksize) { - key = alg(key); - } else if (key.length < blocksize) { - key = Buffer.concat([key, ZEROS], blocksize); - } + for (i = 0; i < (this || _global$7$1).length; i++) { + w = -((this || _global$7$1).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$7$1).words[i] = w & 67108863; + } - var ipad = this._ipad = Buffer.allocUnsafe(blocksize); - var opad = this._opad = Buffer.allocUnsafe(blocksize); + (this || _global$7$1).negative = 1; + return this._strip(); + }; - for (var i = 0; i < blocksize; i++) { - ipad[i] = key[i] ^ 54; - opad[i] = key[i] ^ 92; - } + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$7$1).length - num.length; + var a = this.clone(); + var b = num; // Normalize - this._hash = [ipad]; - } + var bhi = b.words[b.length - 1] | 0; - inherits(Hmac, Base); + var bhiBits = this._countBits(bhi); - Hmac.prototype._update = function (data) { - this._hash.push(data); - }; + shift = 26 - bhiBits; - Hmac.prototype._final = function () { - var h = this._alg(Buffer.concat(this._hash)); + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient - return this._alg(Buffer.concat([this._opad, h])); - }; - exports$2y = Hmac; - return exports$2y; -} + var m = a.length - b.length; + var q; -var exports$2x = {}, - _dewExec$2w = false; -function dew$2w() { - if (_dewExec$2w) return exports$2x; - _dewExec$2w = true; + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); - var MD5 = dew$2L(); + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } - exports$2x = function (buffer) { - return new MD5().update(buffer).digest(); - }; + var diff = a.clone()._ishlnsubmul(b, 1, m); - return exports$2x; -} + if (diff.negative === 0) { + a = diff; -var exports$2w = {}, - _dewExec$2v = false; -function dew$2v() { - if (_dewExec$2v) return exports$2w; - _dewExec$2v = true; + if (q) { + q.words[m] = 1; + } + } - var inherits = dew$2R(); + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) - var Legacy = dew$2x(); + qj = Math.min(qj / bhi | 0, 67108863); - var Base = dew$2z(); + a._ishlnsubmul(b, qj, j); - var Buffer = dew$2P().Buffer; + while (a.negative !== 0) { + qj--; + a.negative = 0; - var md5 = dew$2w(); + a._ishlnsubmul(b, 1, j); - var RIPEMD160 = dew$2K(); + if (!a.isZero()) { + a.negative ^= 1; + } + } - var sha = dew$2C(); + if (q) { + q.words[j] = qj; + } + } - var ZEROS = Buffer.alloc(128); + if (q) { + q._strip(); + } - function Hmac(alg, key) { - Base.call(this, "digest"); + a._strip(); // Denormalize - if (typeof key === "string") { - key = Buffer.from(key); - } - var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; - this._alg = alg; - this._key = key; + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); + } - if (key.length > blocksize) { - var hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); - key = hash.update(key).digest(); - } else if (key.length < blocksize) { - key = Buffer.concat([key, ZEROS], blocksize); - } + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested - var ipad = this._ipad = Buffer.allocUnsafe(blocksize); - var opad = this._opad = Buffer.allocUnsafe(blocksize); - for (var i = 0; i < blocksize; i++) { - ipad[i] = key[i] ^ 54; - opad[i] = key[i] ^ 92; - } + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); - this._hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } - this._hash.update(ipad); - } + var div, mod, res; - inherits(Hmac, Base); + if ((this || _global$7$1).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); - Hmac.prototype._update = function (data) { - this._hash.update(data); - }; + if (mode !== "mod") { + div = res.div.neg(); + } - Hmac.prototype._final = function () { - var h = this._hash.digest(); + if (mode !== "div") { + mod = res.mod.neg(); - var hash = this._alg === "rmd160" ? new RIPEMD160() : sha(this._alg); - return hash.update(this._opad).update(h).digest(); - }; + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } - exports$2w = function createHmac(alg, key) { - alg = alg.toLowerCase(); + return { + div: div, + mod: mod + }; + } - if (alg === "rmd160" || alg === "ripemd160") { - return new Hmac("rmd160", key); - } + if ((this || _global$7$1).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); - if (alg === "md5") { - return new Legacy(md5, key); - } + if (mode !== "mod") { + div = res.div.neg(); + } - return new Hmac(alg, key); - }; + return { + div: div, + mod: res.mod + }; + } - return exports$2w; -} + if (((this || _global$7$1).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); -var _algorithms$1 = { - "sha224WithRSAEncryption": { - "sign": "rsa", - "hash": "sha224", - "id": "302d300d06096086480165030402040500041c" - }, - "RSA-SHA224": { - "sign": "ecdsa/rsa", - "hash": "sha224", - "id": "302d300d06096086480165030402040500041c" - }, - "sha256WithRSAEncryption": { - "sign": "rsa", - "hash": "sha256", - "id": "3031300d060960864801650304020105000420" - }, - "RSA-SHA256": { - "sign": "ecdsa/rsa", - "hash": "sha256", - "id": "3031300d060960864801650304020105000420" - }, - "sha384WithRSAEncryption": { - "sign": "rsa", - "hash": "sha384", - "id": "3041300d060960864801650304020205000430" - }, - "RSA-SHA384": { - "sign": "ecdsa/rsa", - "hash": "sha384", - "id": "3041300d060960864801650304020205000430" - }, - "sha512WithRSAEncryption": { - "sign": "rsa", - "hash": "sha512", - "id": "3051300d060960864801650304020305000440" - }, - "RSA-SHA512": { - "sign": "ecdsa/rsa", - "hash": "sha512", - "id": "3051300d060960864801650304020305000440" - }, - "RSA-SHA1": { - "sign": "rsa", - "hash": "sha1", - "id": "3021300906052b0e03021a05000414" - }, - "ecdsa-with-SHA1": { - "sign": "ecdsa", - "hash": "sha1", - "id": "" - }, - "sha256": { - "sign": "ecdsa", - "hash": "sha256", - "id": "" - }, - "sha224": { - "sign": "ecdsa", - "hash": "sha224", - "id": "" - }, - "sha384": { - "sign": "ecdsa", - "hash": "sha384", - "id": "" - }, - "sha512": { - "sign": "ecdsa", - "hash": "sha512", - "id": "" - }, - "DSA-SHA": { - "sign": "dsa", - "hash": "sha1", - "id": "" - }, - "DSA-SHA1": { - "sign": "dsa", - "hash": "sha1", - "id": "" - }, - "DSA": { - "sign": "dsa", - "hash": "sha1", - "id": "" - }, - "DSA-WITH-SHA224": { - "sign": "dsa", - "hash": "sha224", - "id": "" - }, - "DSA-SHA224": { - "sign": "dsa", - "hash": "sha224", - "id": "" - }, - "DSA-WITH-SHA256": { - "sign": "dsa", - "hash": "sha256", - "id": "" - }, - "DSA-SHA256": { - "sign": "dsa", - "hash": "sha256", - "id": "" - }, - "DSA-WITH-SHA384": { - "sign": "dsa", - "hash": "sha384", - "id": "" - }, - "DSA-SHA384": { - "sign": "dsa", - "hash": "sha384", - "id": "" - }, - "DSA-WITH-SHA512": { - "sign": "dsa", - "hash": "sha512", - "id": "" - }, - "DSA-SHA512": { - "sign": "dsa", - "hash": "sha512", - "id": "" - }, - "DSA-RIPEMD160": { - "sign": "dsa", - "hash": "rmd160", - "id": "" - }, - "ripemd160WithRSA": { - "sign": "rsa", - "hash": "rmd160", - "id": "3021300906052b2403020105000414" - }, - "RSA-RIPEMD160": { - "sign": "rsa", - "hash": "rmd160", - "id": "3021300906052b2403020105000414" - }, - "md5WithRSAEncryption": { - "sign": "rsa", - "hash": "md5", - "id": "3020300c06082a864886f70d020505000410" - }, - "RSA-MD5": { - "sign": "rsa", - "hash": "md5", - "id": "3020300c06082a864886f70d020505000410" - } -}; + if (mode !== "div") { + mod = res.mod.neg(); -var exports$2v = {}, - _dewExec$2u = false; -function dew$2u() { - if (_dewExec$2u) return exports$2v; - _dewExec$2u = true; - exports$2v = _algorithms$1; - return exports$2v; -} + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } -var exports$2u = {}, - _dewExec$2t = false; -function dew$2t() { - if (_dewExec$2t) return exports$2u; - _dewExec$2t = true; - var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value - exports$2u = function (iterations, keylen) { - if (typeof iterations !== "number") { - throw new TypeError("Iterations not a number"); - } - if (iterations < 0) { - throw new TypeError("Bad iterations"); - } + if (num.length > (this || _global$7$1).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$7$1 + }; + } // Very short reduction - if (typeof keylen !== "number") { - throw new TypeError("Key length not a number"); - } - if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { - /* eslint no-self-compare: 0 */ - throw new TypeError("Bad key length"); - } - }; + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } - return exports$2u; -} + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modrn(num.words[0])) + }; + } -var exports$2t = {}, - _dewExec$2s = false; + return { + div: this.divn(num.words[0]), + mod: new BN(this.modrn(num.words[0])) + }; + } -var _global$J = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + return this._wordDiv(num, mode); + }; // Find `this` / `num` -function dew$2s() { - if (_dewExec$2s) return exports$2t; - _dewExec$2s = true; - var process$1 = process; - var defaultEncoding; - /* istanbul ignore next */ - if (_global$J.process && _global$J.process.browser) { - defaultEncoding = "utf-8"; - } else if (_global$J.process && _global$J.process.version) { - var pVersionMajor = parseInt(process$1.version.split(".")[0].slice(1), 10); - defaultEncoding = pVersionMajor >= 6 ? "utf-8" : "binary"; - } else { - defaultEncoding = "utf-8"; - } + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` - exports$2t = defaultEncoding; - return exports$2t; -} -var exports$2s = {}, - _dewExec$2r = false; -function dew$2r() { - if (_dewExec$2r) return exports$2s; - _dewExec$2r = true; + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; - var Buffer = dew$2P().Buffer; + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) - exports$2s = function (thing, encoding, name) { - if (Buffer.isBuffer(thing)) { - return thing; - } else if (typeof thing === "string") { - return Buffer.from(thing, encoding); - } else if (ArrayBuffer.isView(thing)) { - return Buffer.from(thing.buffer); - } else { - throw new TypeError(name + " must be a string, a Buffer, a typed array or a DataView"); - } - }; - return exports$2s; -} + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division -var exports$2r = {}, - _dewExec$2q = false; + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down -var _global$I = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up -function dew$2q() { - if (_dewExec$2q) return exports$2r; - _dewExec$2q = true; + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; - var md5 = dew$2w(); + BN.prototype.modrn = function modrn(num) { + var isNegNum = num < 0; + if (isNegNum) num = -num; + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; - var RIPEMD160 = dew$2K(); + for (var i = (this || _global$7$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$7$1).words[i] | 0)) % num; + } - var sha = dew$2C(); + return isNegNum ? -acc : acc; + }; // WARNING: DEPRECATED - var Buffer = dew$2P().Buffer; - var checkParameters = dew$2t(); + BN.prototype.modn = function modn(num) { + return this.modrn(num); + }; // In-place division by number - var defaultEncoding = dew$2s(); - var toBuffer = dew$2r(); + BN.prototype.idivn = function idivn(num) { + var isNegNum = num < 0; + if (isNegNum) num = -num; + assert(num <= 67108863); + var carry = 0; - var ZEROS = Buffer.alloc(128); - var sizes = { - md5: 16, - sha1: 20, - sha224: 28, - sha256: 32, - sha384: 48, - sha512: 64, - rmd160: 20, - ripemd160: 20 - }; + for (var i = (this || _global$7$1).length - 1; i >= 0; i--) { + var w = ((this || _global$7$1).words[i] | 0) + carry * 67108864; + (this || _global$7$1).words[i] = w / num | 0; + carry = w % num; + } - function Hmac(alg, key, saltLen) { - var hash = getDigest(alg); - var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + this._strip(); - if (key.length > blocksize) { - key = hash(key); - } else if (key.length < blocksize) { - key = Buffer.concat([key, ZEROS], blocksize); - } + return isNegNum ? this.ineg() : this || _global$7$1; + }; - var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]); - var opad = Buffer.allocUnsafe(blocksize + sizes[alg]); + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; - for (var i = 0; i < blocksize; i++) { - ipad[i] = key[i] ^ 54; - opad[i] = key[i] ^ 92; - } + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$7$1; + var y = p.clone(); - var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4); - ipad.copy(ipad1, 0, 0, blocksize); - (this || _global$I).ipad1 = ipad1; - (this || _global$I).ipad2 = ipad; - (this || _global$I).opad = opad; - (this || _global$I).alg = alg; - (this || _global$I).blocksize = blocksize; - (this || _global$I).hash = hash; - (this || _global$I).size = sizes[alg]; - } + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x - Hmac.prototype.run = function (data, ipad) { - data.copy(ipad, (this || _global$I).blocksize); - var h = this.hash(ipad); - h.copy((this || _global$I).opad, (this || _global$I).blocksize); - return this.hash((this || _global$I).opad); - }; - function getDigest(alg) { - function shaFunc(data) { - return sha(alg).update(data).digest(); - } + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y - function rmd160Func(data) { - return new RIPEMD160().update(data).digest(); - } + var C = new BN(0); + var D = new BN(1); + var g = 0; - if (alg === "rmd160" || alg === "ripemd160") return rmd160Func; - if (alg === "md5") return md5; - return shaFunc; - } + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } - function pbkdf2(password, salt, iterations, keylen, digest) { - checkParameters(iterations, keylen); - password = toBuffer(password, defaultEncoding, "Password"); - salt = toBuffer(salt, defaultEncoding, "Salt"); - digest = digest || "sha1"; - var hmac = new Hmac(digest, password, salt.length); - var DK = Buffer.allocUnsafe(keylen); - var block1 = Buffer.allocUnsafe(salt.length + 4); - salt.copy(block1, 0, 0, salt.length); - var destPos = 0; - var hLen = sizes[digest]; - var l = Math.ceil(keylen / hLen); + var yp = y.clone(); + var xp = x.clone(); - for (var i = 1; i <= l; i++) { - block1.writeUInt32BE(i, salt.length); - var T = hmac.run(block1, hmac.ipad1); - var U = T; + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - for (var j = 1; j < iterations; j++) { - U = hmac.run(U, hmac.ipad2); + if (i > 0) { + x.iushrn(i); - for (var k = 0; k < hLen; k++) T[k] ^= U[k]; + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } + + A.iushrn(1); + B.iushrn(1); + } + } + + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + + if (j > 0) { + y.iushrn(j); + + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } + + C.iushrn(1); + D.iushrn(1); + } + } + + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } } - T.copy(DK, destPos); - destPos += hLen; - } + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed - return DK; - } - exports$2r = pbkdf2; - return exports$2r; -} + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$7$1; + var b = p.clone(); -var exports$2q = {}, - _dewExec$2p = false; + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } -var _global$H = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); -function dew$2p() { - if (_dewExec$2p) return exports$2q; - _dewExec$2p = true; + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - var Buffer = dew$2P().Buffer; + if (i > 0) { + a.iushrn(i); - var checkParameters = dew$2t(); + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } - var defaultEncoding = dew$2s(); + x1.iushrn(1); + } + } - var sync = dew$2q(); + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - var toBuffer = dew$2r(); + if (j > 0) { + b.iushrn(j); - var ZERO_BUF; - var subtle = _global$H.crypto && _global$H.crypto.subtle; - var toBrowser = { - sha: "SHA-1", - "sha-1": "SHA-1", - sha1: "SHA-1", - sha256: "SHA-256", - "sha-256": "SHA-256", - sha384: "SHA-384", - "sha-384": "SHA-384", - "sha-512": "SHA-512", - sha512: "SHA-512" - }; - var checks = []; + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } - function checkNative(algo) { - if (_global$H.process && !_global$H.process.browser) { - return Promise.resolve(false); - } + x2.iushrn(1); + } + } + + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } + + var res; + + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + + if (res.cmpn(0) < 0) { + res.iadd(p); + } + + return res; + }; + + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two + + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + + do { + while (a.isEven()) { + a.iushrn(1); + } + + while (b.isEven()) { + b.iushrn(1); + } + + var r = a.cmp(b); + + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + + a.isub(b); + } while (true); + + return b.iushln(shift); + }; // Invert number in the field F(num) + + + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + + BN.prototype.isEven = function isEven() { + return ((this || _global$7$1).words[0] & 1) === 0; + }; + + BN.prototype.isOdd = function isOdd() { + return ((this || _global$7$1).words[0] & 1) === 1; + }; // And first word and num + + + BN.prototype.andln = function andln(num) { + return (this || _global$7$1).words[0] & num; + }; // Increment at the bit position in-line + + + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$7$1).length <= s) { + this._expand(s + 1); + + (this || _global$7$1).words[s] |= q; + return this || _global$7$1; + } // Add bit and propagate, if needed + + + var carry = q; + + for (var i = s; carry !== 0 && i < (this || _global$7$1).length; i++) { + var w = (this || _global$7$1).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$7$1).words[i] = w; + } + + if (carry !== 0) { + (this || _global$7$1).words[i] = carry; + (this || _global$7$1).length++; + } + + return this || _global$7$1; + }; + + BN.prototype.isZero = function isZero() { + return (this || _global$7$1).length === 1 && (this || _global$7$1).words[0] === 0; + }; + + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$7$1).negative !== 0 && !negative) return -1; + if ((this || _global$7$1).negative === 0 && negative) return 1; + + this._strip(); + + var res; + + if ((this || _global$7$1).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } - if (!subtle || !subtle.importKey || !subtle.deriveBits) { - return Promise.resolve(false); - } + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$7$1).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } - if (checks[algo] !== undefined) { - return checks[algo]; - } + if ((this || _global$7$1).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` - ZERO_BUF = ZERO_BUF || Buffer.alloc(8); - var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () { - return true; - }).catch(function () { - return false; - }); - checks[algo] = prom; - return prom; - } - var nextTick; + BN.prototype.cmp = function cmp(num) { + if ((this || _global$7$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$7$1).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$7$1).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison - function getNextTick() { - if (nextTick) { - return nextTick; - } - if (_global$H.process && _global$H.process.nextTick) { - nextTick = _global$H.process.nextTick; - } else if (_global$H.queueMicrotask) { - nextTick = _global$H.queueMicrotask; - } else if (_global$H.setImmediate) { - nextTick = _global$H.setImmediate; - } else { - nextTick = _global$H.setTimeout; - } + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$7$1).length > num.length) return 1; + if ((this || _global$7$1).length < num.length) return -1; + var res = 0; - return nextTick; - } + for (var i = (this || _global$7$1).length - 1; i >= 0; i--) { + var a = (this || _global$7$1).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; - function browserPbkdf2(password, salt, iterations, length, algo) { - return subtle.importKey("raw", password, { - name: "PBKDF2" - }, false, ["deriveBits"]).then(function (key) { - return subtle.deriveBits({ - name: "PBKDF2", - salt: salt, - iterations: iterations, - hash: { - name: algo + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; } - }, key, length << 3); - }).then(function (res) { - return Buffer.from(res); - }); - } - function resolvePromise(promise, callback) { - promise.then(function (out) { - getNextTick()(function () { - callback(null, out); - }); - }, function (e) { - getNextTick()(function () { - callback(e); - }); - }); - } + break; + } - exports$2q = function (password, salt, iterations, keylen, digest, callback) { - if (typeof digest === "function") { - callback = digest; - digest = undefined; - } + return res; + }; - digest = digest || "sha1"; - var algo = toBrowser[digest.toLowerCase()]; + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; - if (!algo || typeof _global$H.Promise !== "function") { - getNextTick()(function () { - var out; + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; - try { - out = sync(password, salt, iterations, keylen, digest); - } catch (e) { - return callback(e); - } + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; - callback(null, out); - }); - return; - } + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; - checkParameters(iterations, keylen); - password = toBuffer(password, defaultEncoding, "Password"); - salt = toBuffer(salt, defaultEncoding, "Salt"); - if (typeof callback !== "function") throw new Error("No callback provided to pbkdf2"); - resolvePromise(checkNative(algo).then(function (resp) { - if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo); - return sync(password, salt, iterations, keylen, digest); - }), callback); - }; + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; - return exports$2q; -} + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; -var exports$2p = {}, - _dewExec$2o = false; -function dew$2o() { - if (_dewExec$2o) return exports$2p; - _dewExec$2o = true; - exports$2p.pbkdf2 = dew$2p(); - exports$2p.pbkdf2Sync = dew$2q(); - return exports$2p; -} + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; -var exports$2o = {}, - _dewExec$2n = false; -function dew$2n() { - if (_dewExec$2n) return exports$2o; - _dewExec$2n = true; + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; - exports$2o.readUInt32BE = function readUInt32BE(bytes, off) { - var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off]; - return res >>> 0; - }; + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; - exports$2o.writeUInt32BE = function writeUInt32BE(bytes, value, off) { - bytes[0 + off] = value >>> 24; - bytes[1 + off] = value >>> 16 & 255; - bytes[2 + off] = value >>> 8 & 255; - bytes[3 + off] = value & 255; - }; + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // - exports$2o.ip = function ip(inL, inR, out, off) { - var outL = 0; - var outR = 0; - for (var i = 6; i >= 0; i -= 2) { - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inR >>> j + i & 1; - } + BN.red = function red(num) { + return new Red(num); + }; - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inL >>> j + i & 1; - } - } + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$7$1).red, "Already a number in reduction context"); + assert((this || _global$7$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$7$1)._forceRed(ctx); + }; - for (var i = 6; i >= 0; i -= 2) { - for (var j = 1; j <= 25; j += 8) { - outR <<= 1; - outR |= inR >>> j + i & 1; - } + BN.prototype.fromRed = function fromRed() { + assert((this || _global$7$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$7$1).red.convertFrom(this || _global$7$1); + }; - for (var j = 1; j <= 25; j += 8) { - outR <<= 1; - outR |= inL >>> j + i & 1; - } - } + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$7$1).red = ctx; + return this || _global$7$1; + }; - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; - }; + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$7$1).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; - exports$2o.rip = function rip(inL, inR, out, off) { - var outL = 0; - var outR = 0; + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$7$1).red, "redAdd works only with red numbers"); + return (this || _global$7$1).red.add(this || _global$7$1, num); + }; - for (var i = 0; i < 4; i++) { - for (var j = 24; j >= 0; j -= 8) { - outL <<= 1; - outL |= inR >>> j + i & 1; - outL <<= 1; - outL |= inL >>> j + i & 1; - } - } + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$7$1).red, "redIAdd works only with red numbers"); + return (this || _global$7$1).red.iadd(this || _global$7$1, num); + }; - for (var i = 4; i < 8; i++) { - for (var j = 24; j >= 0; j -= 8) { - outR <<= 1; - outR |= inR >>> j + i & 1; - outR <<= 1; - outR |= inL >>> j + i & 1; - } - } + BN.prototype.redSub = function redSub(num) { + assert((this || _global$7$1).red, "redSub works only with red numbers"); + return (this || _global$7$1).red.sub(this || _global$7$1, num); + }; - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; - }; + BN.prototype.redISub = function redISub(num) { + assert((this || _global$7$1).red, "redISub works only with red numbers"); + return (this || _global$7$1).red.isub(this || _global$7$1, num); + }; - exports$2o.pc1 = function pc1(inL, inR, out, off) { - var outL = 0; - var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63 - // 6, 14, 22, 30, 39, 47, 55, 63 - // 5, 13, 21, 29, 39, 47, 55, 63 - // 4, 12, 20, 28 + BN.prototype.redShl = function redShl(num) { + assert((this || _global$7$1).red, "redShl works only with red numbers"); + return (this || _global$7$1).red.shl(this || _global$7$1, num); + }; - for (var i = 7; i >= 5; i--) { - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inR >> j + i & 1; - } + BN.prototype.redMul = function redMul(num) { + assert((this || _global$7$1).red, "redMul works only with red numbers"); - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inL >> j + i & 1; - } - } + (this || _global$7$1).red._verify2(this || _global$7$1, num); - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inR >> j + i & 1; - } // 1, 9, 17, 25, 33, 41, 49, 57 - // 2, 10, 18, 26, 34, 42, 50, 58 - // 3, 11, 19, 27, 35, 43, 51, 59 - // 36, 44, 52, 60 + return (this || _global$7$1).red.mul(this || _global$7$1, num); + }; + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$7$1).red, "redMul works only with red numbers"); - for (var i = 1; i <= 3; i++) { - for (var j = 0; j <= 24; j += 8) { - outR <<= 1; - outR |= inR >> j + i & 1; - } + (this || _global$7$1).red._verify2(this || _global$7$1, num); - for (var j = 0; j <= 24; j += 8) { - outR <<= 1; - outR |= inL >> j + i & 1; - } - } + return (this || _global$7$1).red.imul(this || _global$7$1, num); + }; - for (var j = 0; j <= 24; j += 8) { - outR <<= 1; - outR |= inL >> j + i & 1; - } + BN.prototype.redSqr = function redSqr() { + assert((this || _global$7$1).red, "redSqr works only with red numbers"); - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; - }; + (this || _global$7$1).red._verify1(this || _global$7$1); - exports$2o.r28shl = function r28shl(num, shift) { - return num << shift & 268435455 | num >>> 28 - shift; - }; + return (this || _global$7$1).red.sqr(this || _global$7$1); + }; - var pc2table = [// inL => outL - 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, // inR => outR - 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24]; + BN.prototype.redISqr = function redISqr() { + assert((this || _global$7$1).red, "redISqr works only with red numbers"); - exports$2o.pc2 = function pc2(inL, inR, out, off) { - var outL = 0; - var outR = 0; - var len = pc2table.length >>> 1; + (this || _global$7$1).red._verify1(this || _global$7$1); - for (var i = 0; i < len; i++) { - outL <<= 1; - outL |= inL >>> pc2table[i] & 1; - } + return (this || _global$7$1).red.isqr(this || _global$7$1); + }; // Square root over p - for (var i = len; i < pc2table.length; i++) { - outR <<= 1; - outR |= inR >>> pc2table[i] & 1; - } - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; - }; + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$7$1).red, "redSqrt works only with red numbers"); - exports$2o.expand = function expand(r, out, off) { - var outL = 0; - var outR = 0; - outL = (r & 1) << 5 | r >>> 27; + (this || _global$7$1).red._verify1(this || _global$7$1); - for (var i = 23; i >= 15; i -= 4) { - outL <<= 6; - outL |= r >>> i & 63; - } + return (this || _global$7$1).red.sqrt(this || _global$7$1); + }; - for (var i = 11; i >= 3; i -= 4) { - outR |= r >>> i & 63; - outR <<= 6; - } + BN.prototype.redInvm = function redInvm() { + assert((this || _global$7$1).red, "redInvm works only with red numbers"); - outR |= (r & 31) << 1 | r >>> 31; - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; - }; + (this || _global$7$1).red._verify1(this || _global$7$1); - var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11]; + return (this || _global$7$1).red.invm(this || _global$7$1); + }; // Return negative clone of `this` % `red modulo` - exports$2o.substitute = function substitute(inL, inR) { - var out = 0; - for (var i = 0; i < 4; i++) { - var b = inL >>> 18 - i * 6 & 63; - var sb = sTable[i * 64 + b]; - out <<= 4; - out |= sb; - } + BN.prototype.redNeg = function redNeg() { + assert((this || _global$7$1).red, "redNeg works only with red numbers"); - for (var i = 0; i < 4; i++) { - var b = inR >>> 18 - i * 6 & 63; - var sb = sTable[4 * 64 + i * 64 + b]; - out <<= 4; - out |= sb; - } + (this || _global$7$1).red._verify1(this || _global$7$1); - return out >>> 0; - }; + return (this || _global$7$1).red.neg(this || _global$7$1); + }; - var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7]; + BN.prototype.redPow = function redPow(num) { + assert((this || _global$7$1).red && !num.red, "redPow(normalNum)"); - exports$2o.permute = function permute(num) { - var out = 0; + (this || _global$7$1).red._verify1(this || _global$7$1); - for (var i = 0; i < permuteTable.length; i++) { - out <<= 1; - out |= num >>> permuteTable[i] & 1; + return (this || _global$7$1).red.pow(this || _global$7$1, num); + }; // Prime numbers with efficient reduction + + + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime + + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$7$1).name = name; + (this || _global$7$1).p = new BN(p, 16); + (this || _global$7$1).n = (this || _global$7$1).p.bitLength(); + (this || _global$7$1).k = new BN(1).iushln((this || _global$7$1).n).isub((this || _global$7$1).p); + (this || _global$7$1).tmp = this._tmp(); } - return out >>> 0; - }; + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$7$1).n / 13)); + return tmp; + }; - exports$2o.padSplit = function padSplit(num, size, group) { - var str = num.toString(2); + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; - while (str.length < size) str = "0" + str; + do { + this.split(r, (this || _global$7$1).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$7$1).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$7$1).n); - var out = []; + var cmp = rlen < (this || _global$7$1).n ? -1 : r.ucmp((this || _global$7$1).p); - for (var i = 0; i < size; i += group) out.push(str.slice(i, i + group)); + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$7$1).p); + } else { + if (r.strip !== undefined) { + // r is a BN v4 instance + r.strip(); + } else { + // r is a BN v5 instance + r._strip(); + } + } - return out.join(" "); - }; + return r; + }; - return exports$2o; -} + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$7$1).n, 0, out); + }; -var exports$2n = {}, - _dewExec$2m = false; -function dew$2m() { - if (_dewExec$2m) return exports$2n; - _dewExec$2m = true; - exports$2n = assert; + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$7$1).k); + }; - function assert(val, msg) { - if (!val) throw new Error(msg || "Assertion failed"); - } + function K256() { + MPrime.call(this || _global$7$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } - assert.equal = function assertEqual(l, r, msg) { - if (l != r) throw new Error(msg || "Assertion failed: " + l + " != " + r); - }; + inherits(K256, MPrime); - return exports$2n; -} + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); -var exports$2m = {}, - _dewExec$2l = false; -function dew$2l() { - if (_dewExec$2l) return exports$2m; - _dewExec$2l = true; + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } - var assert = dew$2m(); + output.length = outLen; + + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs - function Cipher(options) { - this.options = options; - this.type = this.options.type; - this.blockSize = 8; - this._init(); + var prev = input.words[9]; + output.words[output.length++] = prev & mask; - this.buffer = new Array(this.blockSize); - this.bufferOff = 0; - } + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } - exports$2m = Cipher; + prev >>>= 22; + input.words[i - 10] = prev; - Cipher.prototype._init = function _init() {// Might be overrided - }; + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; - Cipher.prototype.update = function update(data) { - if (data.length === 0) return []; - if (this.type === "decrypt") return this._updateDecrypt(data);else return this._updateEncrypt(data); - }; + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 - Cipher.prototype._buffer = function _buffer(data, off) { - // Append data to buffer - var min = Math.min(this.buffer.length - this.bufferOff, data.length - off); + var lo = 0; - for (var i = 0; i < min; i++) this.buffer[this.bufferOff + i] = data[off + i]; + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction - this.bufferOff += min; // Shift next - return min; - }; + if (num.words[num.length - 1] === 0) { + num.length--; - Cipher.prototype._flushBuffer = function _flushBuffer(out, off) { - this._update(this.buffer, 0, out, off); + if (num.words[num.length - 1] === 0) { + num.length--; + } + } - this.bufferOff = 0; - return this.blockSize; - }; + return num; + }; - Cipher.prototype._updateEncrypt = function _updateEncrypt(data) { - var inputOff = 0; - var outputOff = 0; - var count = (this.bufferOff + data.length) / this.blockSize | 0; - var out = new Array(count * this.blockSize); + function P224() { + MPrime.call(this || _global$7$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } - if (this.bufferOff !== 0) { - inputOff += this._buffer(data, inputOff); - if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff); - } // Write blocks + inherits(P224, MPrime); + function P192() { + MPrime.call(this || _global$7$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } - var max = data.length - (data.length - inputOff) % this.blockSize; + inherits(P192, MPrime); - for (; inputOff < max; inputOff += this.blockSize) { - this._update(data, inputOff, out, outputOff); + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$7$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } - outputOff += this.blockSize; - } // Queue rest + inherits(P25519, MPrime); + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; - for (; inputOff < data.length; inputOff++, this.bufferOff++) this.buffer[this.bufferOff] = data[inputOff]; + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } - return out; - }; + if (carry !== 0) { + num.words[num.length++] = carry; + } - Cipher.prototype._updateDecrypt = function _updateDecrypt(data) { - var inputOff = 0; - var outputOff = 0; - var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1; - var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal + return num; + }; // Exported mostly for testing purposes, use plain name instead - for (; count > 0; count--) { - inputOff += this._buffer(data, inputOff); - outputOff += this._flushBuffer(out, outputOff); - } // Buffer rest of the input + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; - inputOff += this._buffer(data, inputOff); - return out; - }; + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } - Cipher.prototype.final = function final(buffer) { - var first; - if (buffer) first = this.update(buffer); - var last; - if (this.type === "encrypt") last = this._finalEncrypt();else last = this._finalDecrypt(); - if (first) return first.concat(last);else return last; - }; + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // - Cipher.prototype._pad = function _pad(buffer, off) { - if (off === 0) return false; - while (off < buffer.length) buffer[off++] = 0; + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); - return true; - }; + (this || _global$7$1).m = prime.p; + (this || _global$7$1).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$7$1).m = m; + (this || _global$7$1).prime = null; + } + } - Cipher.prototype._finalEncrypt = function _finalEncrypt() { - if (!this._pad(this.buffer, this.bufferOff)) return []; - var out = new Array(this.blockSize); + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; - this._update(this.buffer, 0, out, 0); + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; - return out; - }; + Red.prototype.imod = function imod(a) { + if ((this || _global$7$1).prime) return (this || _global$7$1).prime.ireduce(a)._forceRed(this || _global$7$1); + move(a, a.umod((this || _global$7$1).m)._forceRed(this || _global$7$1)); + return a; + }; - Cipher.prototype._unpad = function _unpad(buffer) { - return buffer; - }; + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } - Cipher.prototype._finalDecrypt = function _finalDecrypt() { - assert.equal(this.bufferOff, this.blockSize, "Not enough data to decrypt"); - var out = new Array(this.blockSize); + return (this || _global$7$1).m.sub(a)._forceRed(this || _global$7$1); + }; - this._flushBuffer(out, 0); + Red.prototype.add = function add(a, b) { + this._verify2(a, b); - return this._unpad(out); - }; + var res = a.add(b); - return exports$2m; -} + if (res.cmp((this || _global$7$1).m) >= 0) { + res.isub((this || _global$7$1).m); + } -var exports$2l = {}, - _dewExec$2k = false; -function dew$2k() { - if (_dewExec$2k) return exports$2l; - _dewExec$2k = true; + return res._forceRed(this || _global$7$1); + }; - var assert = dew$2m(); + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); - var inherits = dew$2R(); + var res = a.iadd(b); - var utils = dew$2n(); + if (res.cmp((this || _global$7$1).m) >= 0) { + res.isub((this || _global$7$1).m); + } - var Cipher = dew$2l(); + return res; + }; - function DESState() { - this.tmp = new Array(2); - this.keys = null; - } + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); - function DES(options) { - Cipher.call(this, options); - var state = new DESState(); - this._desState = state; - this.deriveKeys(state, options.key); - } + var res = a.sub(b); - inherits(DES, Cipher); - exports$2l = DES; + if (res.cmpn(0) < 0) { + res.iadd((this || _global$7$1).m); + } - DES.create = function create(options) { - return new DES(options); - }; + return res._forceRed(this || _global$7$1); + }; - var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]; + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); - DES.prototype.deriveKeys = function deriveKeys(state, key) { - state.keys = new Array(16 * 2); - assert.equal(key.length, this.blockSize, "Invalid key length"); - var kL = utils.readUInt32BE(key, 0); - var kR = utils.readUInt32BE(key, 4); - utils.pc1(kL, kR, state.tmp, 0); - kL = state.tmp[0]; - kR = state.tmp[1]; + var res = a.isub(b); - for (var i = 0; i < state.keys.length; i += 2) { - var shift = shiftTable[i >>> 1]; - kL = utils.r28shl(kL, shift); - kR = utils.r28shl(kR, shift); - utils.pc2(kL, kR, state.keys, i); - } - }; + if (res.cmpn(0) < 0) { + res.iadd((this || _global$7$1).m); + } - DES.prototype._update = function _update(inp, inOff, out, outOff) { - var state = this._desState; - var l = utils.readUInt32BE(inp, inOff); - var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation + return res; + }; - utils.ip(l, r, state.tmp, 0); - l = state.tmp[0]; - r = state.tmp[1]; - if (this.type === "encrypt") this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0); - l = state.tmp[0]; - r = state.tmp[1]; - utils.writeUInt32BE(out, l, outOff); - utils.writeUInt32BE(out, r, outOff + 4); - }; + Red.prototype.shl = function shl(a, num) { + this._verify1(a); - DES.prototype._pad = function _pad(buffer, off) { - var value = buffer.length - off; + return this.imod(a.ushln(num)); + }; - for (var i = off; i < buffer.length; i++) buffer[i] = value; + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); - return true; - }; + return this.imod(a.imul(b)); + }; - DES.prototype._unpad = function _unpad(buffer) { - var pad = buffer[buffer.length - 1]; + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); - for (var i = buffer.length - pad; i < buffer.length; i++) assert.equal(buffer[i], pad); + return this.imod(a.mul(b)); + }; - return buffer.slice(0, buffer.length - pad); - }; + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; - DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) { - var l = lStart; - var r = rStart; // Apply f() x16 times + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; - for (var i = 0; i < state.keys.length; i += 2) { - var keyL = state.keys[i]; - var keyR = state.keys[i + 1]; // f(r, k) + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); - utils.expand(r, state.tmp, 0); - keyL ^= state.tmp[0]; - keyR ^= state.tmp[1]; - var s = utils.substitute(keyL, keyR); - var f = utils.permute(s); - var t = r; - r = (l ^ f) >>> 0; - l = t; - } // Reverse Initial Permutation + var mod3 = (this || _global$7$1).m.andln(3); + assert(mod3 % 2 === 1); // Fast case - utils.rip(r, l, out, off); - }; + if (mod3 === 3) { + var pow = (this || _global$7$1).m.add(new BN(1)).iushrn(2); - DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) { - var l = rStart; - var r = lStart; // Apply f() x16 times + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) - for (var i = state.keys.length - 2; i >= 0; i -= 2) { - var keyL = state.keys[i]; - var keyR = state.keys[i + 1]; // f(r, k) - utils.expand(l, state.tmp, 0); - keyL ^= state.tmp[0]; - keyR ^= state.tmp[1]; - var s = utils.substitute(keyL, keyR); - var f = utils.permute(s); - var t = l; - l = (r ^ f) >>> 0; - r = t; - } // Reverse Initial Permutation + var q = (this || _global$7$1).m.subn(1); + var s = 0; - utils.rip(l, r, out, off); - }; + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } - return exports$2l; -} + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$7$1); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. -var exports$2k = {}, - _dewExec$2j = false; -function dew$2j() { - if (_dewExec$2j) return exports$2k; - _dewExec$2j = true; + var lpow = (this || _global$7$1).m.subn(1).iushrn(1); - var assert = dew$2m(); + var z = (this || _global$7$1).m.bitLength(); - var inherits = dew$2R(); + z = new BN(2 * z * z).toRed(this || _global$7$1); - var proto = {}; + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } - function CBCState(iv) { - assert.equal(iv.length, 8, "Invalid IV length"); - this.iv = new Array(8); + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; - for (var i = 0; i < this.iv.length; i++) this.iv[i] = iv[i]; - } + while (t.cmp(one) !== 0) { + var tmp = t; - function instantiate(Base) { - function CBC(options) { - Base.call(this, options); + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } - this._cbcInit(); - } + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } - inherits(CBC, Base); - var keys = Object.keys(proto); + return r; + }; - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - CBC.prototype[key] = proto[key]; - } + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$7$1).m); - CBC.create = function create(options) { - return new CBC(options); + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } }; - return CBC; - } + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$7$1); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$7$1); + wnd[1] = a; - exports$2k.instantiate = instantiate; + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } - proto._cbcInit = function _cbcInit() { - var state = new CBCState(this.options.iv); - this._cbcState = state; - }; + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; - proto._update = function _update(inp, inOff, out, outOff) { - var state = this._cbcState; - var superProto = this.constructor.super_.prototype; - var iv = state.iv; + if (start === 0) { + start = 26; + } - if (this.type === "encrypt") { - for (var i = 0; i < this.blockSize; i++) iv[i] ^= inp[inOff + i]; + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; - superProto._update.call(this, iv, 0, out, outOff); + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; - for (var i = 0; i < this.blockSize; i++) iv[i] = out[outOff + i]; - } else { - superProto._update.call(this, inp, inOff, out, outOff); + if (res !== wnd[0]) { + res = this.sqr(res); + } - for (var i = 0; i < this.blockSize; i++) out[outOff + i] ^= iv[i]; + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } - for (var i = 0; i < this.blockSize; i++) iv[i] = inp[inOff + i]; - } - }; + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } - return exports$2k; -} + start = 26; + } -var exports$2j = {}, - _dewExec$2i = false; -function dew$2i() { - if (_dewExec$2i) return exports$2j; - _dewExec$2i = true; + return res; + }; - var assert = dew$2m(); + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$7$1).m); + return r === num ? r.clone() : r; + }; + + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // + + + BN.mont = function mont(num) { + return new Mont(num); + }; + + function Mont(m) { + Red.call(this || _global$7$1, m); + (this || _global$7$1).shift = (this || _global$7$1).m.bitLength(); - var inherits = dew$2R(); + if ((this || _global$7$1).shift % 26 !== 0) { + (this || _global$7$1).shift += 26 - (this || _global$7$1).shift % 26; + } - var Cipher = dew$2l(); + (this || _global$7$1).r = new BN(1).iushln((this || _global$7$1).shift); + (this || _global$7$1).r2 = this.imod((this || _global$7$1).r.sqr()); + (this || _global$7$1).rinv = (this || _global$7$1).r._invmp((this || _global$7$1).m); + (this || _global$7$1).minv = (this || _global$7$1).rinv.mul((this || _global$7$1).r).isubn(1).div((this || _global$7$1).m); + (this || _global$7$1).minv = (this || _global$7$1).minv.umod((this || _global$7$1).r); + (this || _global$7$1).minv = (this || _global$7$1).r.sub((this || _global$7$1).minv); + } - var DES = dew$2k(); + inherits(Mont, Red); - function EDEState(type, key) { - assert.equal(key.length, 24, "Invalid key length"); - var k1 = key.slice(0, 8); - var k2 = key.slice(8, 16); - var k3 = key.slice(16, 24); + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$7$1).shift)); + }; - if (type === "encrypt") { - this.ciphers = [DES.create({ - type: "encrypt", - key: k1 - }), DES.create({ - type: "decrypt", - key: k2 - }), DES.create({ - type: "encrypt", - key: k3 - })]; - } else { - this.ciphers = [DES.create({ - type: "decrypt", - key: k3 - }), DES.create({ - type: "encrypt", - key: k2 - }), DES.create({ - type: "decrypt", - key: k1 - })]; - } - } + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$7$1).rinv)); + r.red = null; + return r; + }; - function EDE(options) { - Cipher.call(this, options); - var state = new EDEState(this.type, this.options.key); - this._edeState = state; - } + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } - inherits(EDE, Cipher); - exports$2j = EDE; + var t = a.imul(b); + var c = t.maskn((this || _global$7$1).shift).mul((this || _global$7$1).minv).imaskn((this || _global$7$1).shift).mul((this || _global$7$1).m); + var u = t.isub(c).iushrn((this || _global$7$1).shift); + var res = u; - EDE.create = function create(options) { - return new EDE(options); - }; + if (u.cmp((this || _global$7$1).m) >= 0) { + res = u.isub((this || _global$7$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$7$1).m); + } - EDE.prototype._update = function _update(inp, inOff, out, outOff) { - var state = this._edeState; + return res._forceRed(this || _global$7$1); + }; - state.ciphers[0]._update(inp, inOff, out, outOff); + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$7$1); + var t = a.mul(b); + var c = t.maskn((this || _global$7$1).shift).mul((this || _global$7$1).minv).imaskn((this || _global$7$1).shift).mul((this || _global$7$1).m); + var u = t.isub(c).iushrn((this || _global$7$1).shift); + var res = u; - state.ciphers[1]._update(out, outOff, out, outOff); + if (u.cmp((this || _global$7$1).m) >= 0) { + res = u.isub((this || _global$7$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$7$1).m); + } - state.ciphers[2]._update(out, outOff, out, outOff); - }; + return res._forceRed(this || _global$7$1); + }; - EDE.prototype._pad = DES.prototype._pad; - EDE.prototype._unpad = DES.prototype._unpad; - return exports$2j; -} + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$7$1).m).mul((this || _global$7$1).r2)); + return res._forceRed(this || _global$7$1); + }; + })(module$4$1, exports$X$1); -var exports$2i = {}, - _dewExec$2h = false; -function dew$2h() { - if (_dewExec$2h) return exports$2i; - _dewExec$2h = true; - exports$2i.utils = dew$2n(); - exports$2i.Cipher = dew$2l(); - exports$2i.DES = dew$2k(); - exports$2i.CBC = dew$2j(); - exports$2i.EDE = dew$2i(); - return exports$2i; + return module$4$1.exports; } -var exports$2h = {}, - _dewExec$2g = false; - -var _global$G = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var exports$W$1 = {}, + _dewExec$W$1 = false; +function dew$W$1() { + if (_dewExec$W$1) return exports$W$1; + _dewExec$W$1 = true; + var Buffer = e$1$1$1.Buffer; -function dew$2g() { - if (_dewExec$2g) return exports$2h; - _dewExec$2g = true; + var BN = dew$X$1(); - var CipherBase = dew$2z(); + var randomBytes = dew$1S(); - var des = dew$2h(); + function blind(priv) { + var r = getr(priv); + var blinder = r.toRed(BN.mont(priv.modulus)).redPow(new BN(priv.publicExponent)).fromRed(); + return { + blinder: blinder, + unblinder: r.invm(priv.modulus) + }; + } - var inherits = dew$2R(); + function getr(priv) { + var len = priv.modulus.byteLength(); + var r; - var Buffer = dew$2P().Buffer; + do { + r = new BN(randomBytes(len)); + } while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)); - var modes = { - "des-ede3-cbc": des.CBC.instantiate(des.EDE), - "des-ede3": des.EDE, - "des-ede-cbc": des.CBC.instantiate(des.EDE), - "des-ede": des.EDE, - "des-cbc": des.CBC.instantiate(des.DES), - "des-ecb": des.DES - }; - modes.des = modes["des-cbc"]; - modes.des3 = modes["des-ede3-cbc"]; - exports$2h = DES; - inherits(DES, CipherBase); + return r; + } - function DES(opts) { - CipherBase.call(this || _global$G); - var modeName = opts.mode.toLowerCase(); - var mode = modes[modeName]; - var type; + function crt(msg, priv) { + var blinds = blind(priv); + var len = priv.modulus.byteLength(); + var blinded = new BN(msg).mul(blinds.blinder).umod(priv.modulus); + var c1 = blinded.toRed(BN.mont(priv.prime1)); + var c2 = blinded.toRed(BN.mont(priv.prime2)); + var qinv = priv.coefficient; + var p = priv.prime1; + var q = priv.prime2; + var m1 = c1.redPow(priv.exponent1).fromRed(); + var m2 = c2.redPow(priv.exponent2).fromRed(); + var h = m1.isub(m2).imul(qinv).umod(p).imul(q); + return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer, "be", len); + } - if (opts.decrypt) { - type = "decrypt"; - } else { - type = "encrypt"; - } + crt.getr = getr; + exports$W$1 = crt; + return exports$W$1; +} - var key = opts.key; +var _package$1 = { + "_args": [ + [ + "elliptic@6.5.4", + "C:\\Users\\guybe\\Projects\\rollup-plugin-jspm" + ] + ], + "_from": "elliptic@6.5.4", + "_id": "elliptic@6.5.4", + "_inBundle": false, + "_integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", + "_location": "/@jspm/core/elliptic", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "registry": true, + "raw": "elliptic@6.5.4", + "name": "elliptic", + "escapedName": "elliptic", + "rawSpec": "6.5.4", + "saveSpec": null, + "fetchSpec": "6.5.4" + }, + "_requiredBy": [ + "/@jspm/core/browserify-sign", + "/@jspm/core/create-ecdh" + ], + "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", + "_spec": "6.5.4", + "_where": "C:\\Users\\guybe\\Projects\\rollup-plugin-jspm", + "author": { + "name": "Fedor Indutny", + "email": "fedor@indutny.com" + }, + "bugs": { + "url": "https://github.com/indutny/elliptic/issues" + }, + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + }, + "description": "EC cryptography", + "devDependencies": { + "brfs": "^2.0.2", + "coveralls": "^3.1.0", + "eslint": "^7.6.0", + "grunt": "^1.2.1", + "grunt-browserify": "^5.3.0", + "grunt-cli": "^1.3.2", + "grunt-contrib-connect": "^3.0.0", + "grunt-contrib-copy": "^1.0.0", + "grunt-contrib-uglify": "^5.0.0", + "grunt-mocha-istanbul": "^5.0.2", + "grunt-saucelabs": "^9.0.1", + "istanbul": "^0.4.5", + "mocha": "^8.0.1" + }, + "files": [ + "lib" + ], + "homepage": "https://github.com/indutny/elliptic", + "keywords": [ + "EC", + "Elliptic", + "curve", + "Cryptography" + ], + "license": "MIT", + "main": "lib/elliptic.js", + "name": "elliptic", + "repository": { + "type": "git", + "url": "git+ssh://git@github.com/indutny/elliptic.git" + }, + "scripts": { + "lint": "eslint lib test", + "lint:fix": "npm run lint -- --fix", + "test": "npm run lint && npm run unit", + "unit": "istanbul test _mocha --reporter=spec test/index.js", + "version": "grunt dist && git add dist/" + }, + "version": "6.5.4" +}; - if (!Buffer.isBuffer(key)) { - key = Buffer.from(key); - } +var exports$V$1 = {}, + _dewExec$V$1 = false; +var module$3$1 = { + exports: exports$V$1 +}; - if (modeName === "des-ede" || modeName === "des-ede-cbc") { - key = Buffer.concat([key, key.slice(0, 8)]); - } +var _global$6$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - var iv = opts.iv; +function dew$V$1() { + if (_dewExec$V$1) return module$3$1.exports; + _dewExec$V$1 = true; - if (!Buffer.isBuffer(iv)) { - iv = Buffer.from(iv); - } + (function (module, exports) { - (this || _global$G)._des = mode.create({ - key: key, - iv: iv, - type: type - }); - } + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. - DES.prototype._update = function (data) { - return Buffer.from((this || _global$G)._des.update(data)); - }; - DES.prototype._final = function () { - return Buffer.from((this || _global$G)._des.final()); - }; + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; - return exports$2h; -} + var TempCtor = function () {}; -var exports$2g = {}, - _dewExec$2f = false; -function dew$2f() { - if (_dewExec$2f) return exports$2g; - _dewExec$2f = true; + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN - exports$2g.encrypt = function (self, block) { - return self._cipher.encryptBlock(block); - }; - exports$2g.decrypt = function (self, block) { - return self._cipher.decryptBlock(block); - }; + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; + } - return exports$2g; -} + (this || _global$6$1).negative = 0; + (this || _global$6$1).words = null; + (this || _global$6$1).length = 0; // Reduction context -var exports$2f = {}, - _dewExec$2e = false; -function dew$2e() { - if (_dewExec$2e) return exports$2f; - _dewExec$2e = true; - var Buffer = buffer.Buffer; + (this || _global$6$1).red = null; - exports$2f = function xor(a, b) { - var length = Math.min(a.length, b.length); - var buffer = new Buffer(length); + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } - for (var i = 0; i < length; ++i) { - buffer[i] = a[i] ^ b[i]; + this._init(number || 0, base || 10, endian || "be"); + } } - return buffer; - }; - - return exports$2f; -} + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } -var exports$2e = {}, - _dewExec$2d = false; -function dew$2d() { - if (_dewExec$2d) return exports$2e; - _dewExec$2d = true; + BN.BN = BN; + BN.wordSize = 26; + var Buffer; - var xor = dew$2e(); + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = e$1$1$1.Buffer; + } + } catch (e) {} - exports$2e.encrypt = function (self, block) { - var data = xor(block, self._prev); - self._prev = self._cipher.encryptBlock(data); - return self._prev; - }; + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } - exports$2e.decrypt = function (self, block) { - var pad = self._prev; - self._prev = block; + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; - var out = self._cipher.decryptBlock(block); + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; - return xor(out, pad); - }; + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; - return exports$2e; -} + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } -var exports$2d = {}, - _dewExec$2c = false; -function dew$2c() { - if (_dewExec$2c) return exports$2d; - _dewExec$2c = true; + if (typeof number === "object") { + return this._initArray(number, base, endian); + } - var Buffer = dew$2P().Buffer; + if (base === "hex") { + base = 16; + } - var xor = dew$2e(); + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; - function encryptStart(self, data, decrypt) { - var len = data.length; - var out = xor(data, self._cache); - self._cache = self._cache.slice(len); - self._prev = Buffer.concat([self._prev, decrypt ? data : out]); - return out; - } + if (number[0] === "-") { + start++; + (this || _global$6$1).negative = 1; + } - exports$2d.encrypt = function (self, data, decrypt) { - var out = Buffer.allocUnsafe(0); - var len; + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); - while (data.length) { - if (self._cache.length === 0) { - self._cache = self._cipher.encryptBlock(self._prev); - self._prev = Buffer.allocUnsafe(0); + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } } + }; - if (self._cache.length <= data.length) { - len = self._cache.length; - out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]); - data = data.slice(len); - } else { - out = Buffer.concat([out, encryptStart(self, data, decrypt)]); - break; + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$6$1).negative = 1; + number = -number; } - } - return out; - }; - - return exports$2d; -} - -var exports$2c = {}, - _dewExec$2b = false; -function dew$2b() { - if (_dewExec$2b) return exports$2c; - _dewExec$2b = true; + if (number < 67108864) { + (this || _global$6$1).words = [number & 67108863]; + (this || _global$6$1).length = 1; + } else if (number < 4503599627370496) { + (this || _global$6$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$6$1).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - var Buffer = dew$2P().Buffer; + (this || _global$6$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$6$1).length = 3; + } - function encryptByte(self, byteParam, decrypt) { - var pad = self._cipher.encryptBlock(self._prev); + if (endian !== "le") return; // Reverse the bytes - var out = pad[0] ^ byteParam; - self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]); - return out; - } + this._initArray(this.toArray(), base, endian); + }; - exports$2c.encrypt = function (self, chunk, decrypt) { - var len = chunk.length; - var out = Buffer.allocUnsafe(len); - var i = -1; + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); - while (++i < len) { - out[i] = encryptByte(self, chunk[i], decrypt); - } + if (number.length <= 0) { + (this || _global$6$1).words = [0]; + (this || _global$6$1).length = 1; + return this || _global$6$1; + } - return out; - }; + (this || _global$6$1).length = Math.ceil(number.length / 3); + (this || _global$6$1).words = new Array((this || _global$6$1).length); - return exports$2c; -} + for (var i = 0; i < (this || _global$6$1).length; i++) { + (this || _global$6$1).words[i] = 0; + } -var exports$2b = {}, - _dewExec$2a = false; -function dew$2a() { - if (_dewExec$2a) return exports$2b; - _dewExec$2a = true; + var j, w; + var off = 0; - var Buffer = dew$2P().Buffer; + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$6$1).words[j] |= w << off & 67108863; + (this || _global$6$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; - function encryptByte(self, byteParam, decrypt) { - var pad; - var i = -1; - var len = 8; - var out = 0; - var bit, value; + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$6$1).words[j] |= w << off & 67108863; + (this || _global$6$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; - while (++i < len) { - pad = self._cipher.encryptBlock(self._prev); - bit = byteParam & 1 << 7 - i ? 128 : 0; - value = pad[0] ^ bit; - out += (value & 128) >> i % 8; - self._prev = shiftIn(self._prev, decrypt ? bit : value); - } + if (off >= 26) { + off -= 26; + j++; + } + } + } - return out; - } + return this.strip(); + }; - function shiftIn(buffer, value) { - var len = buffer.length; - var i = -1; - var out = Buffer.allocUnsafe(buffer.length); - buffer = Buffer.concat([buffer, Buffer.from([value])]); + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // 'A' - 'F' - while (++i < len) { - out[i] = buffer[i] << 1 | buffer[i + 1] >> 7; + if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; // '0' - '9' + } else { + return c - 48 & 15; + } } - return out; - } + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); - exports$2b.encrypt = function (self, chunk, decrypt) { - var len = chunk.length; - var out = Buffer.allocUnsafe(len); - var i = -1; + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } - while (++i < len) { - out[i] = encryptByte(self, chunk[i], decrypt); + return r; } - return out; - }; - - return exports$2b; -} + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$6$1).length = Math.ceil((number.length - start) / 6); + (this || _global$6$1).words = new Array((this || _global$6$1).length); -var exports$2a = {}, - _dewExec$29 = false; -function dew$29() { - if (_dewExec$29) return exports$2a; - _dewExec$29 = true; - var Buffer = buffer.Buffer; + for (var i = 0; i < (this || _global$6$1).length; i++) { + (this || _global$6$1).words[i] = 0; + } // 24-bits chunks - var xor = dew$2e(); - function getBlock(self) { - self._prev = self._cipher.encryptBlock(self._prev); - return self._prev; - } + var off = 0; + var j = 0; + var w; - exports$2a.encrypt = function (self, chunk) { - while (self._cache.length < chunk.length) { - self._cache = Buffer.concat([self._cache, getBlock(self)]); - } + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$6$1).words[j] |= w & 67108863; - var pad = self._cache.slice(0, chunk.length); + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$6$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } else { + var parseLength = number.length - start; - self._cache = self._cache.slice(chunk.length); - return xor(chunk, pad); - }; + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$6$1).words[j] |= w & 67108863; - return exports$2a; -} + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$6$1).words[j] |= w >>> 26; + } else { + off += 8; + } + } + } -var exports$29 = {}, - _dewExec$28 = false; -function dew$28() { - if (_dewExec$28) return exports$29; - _dewExec$28 = true; + this.strip(); + }; - function incr32(iv) { - var len = iv.length; - var item; + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); - while (len--) { - item = iv.readUInt8(len); + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' - if (item === 255) { - iv.writeUInt8(0, len); - } else { - item++; - iv.writeUInt8(item, len); - break; + if (c >= 49) { + r += c - 49 + 10; // 'A' + } else if (c >= 17) { + r += c - 17 + 10; // '0' - '9' + } else { + r += c; + } } + + return r; } - } - exports$29 = incr32; - return exports$29; -} + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$6$1).words = [0]; + (this || _global$6$1).length = 1; // Find length of limb in base -var exports$28 = {}, - _dewExec$27 = false; -function dew$27() { - if (_dewExec$27) return exports$28; - _dewExec$27 = true; + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; + } - var xor = dew$2e(); + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; - var Buffer = dew$2P().Buffer; + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); - var incr32 = dew$28(); + if ((this || _global$6$1).words[0] + word < 67108864) { + (this || _global$6$1).words[0] += word; + } else { + this._iaddn(word); + } + } - function getBlock(self) { - var out = self._cipher.encryptBlockRaw(self._prev); + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); - incr32(self._prev); - return out; - } + for (i = 0; i < mod; i++) { + pow *= base; + } - var blockSize = 16; + this.imuln(pow); - exports$28.encrypt = function (self, chunk) { - var chunkNum = Math.ceil(chunk.length / blockSize); - var start = self._cache.length; - self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]); + if ((this || _global$6$1).words[0] + word < 67108864) { + (this || _global$6$1).words[0] += word; + } else { + this._iaddn(word); + } + } - for (var i = 0; i < chunkNum; i++) { - var out = getBlock(self); - var offset = start + i * blockSize; + this.strip(); + }; - self._cache.writeUInt32BE(out[0], offset + 0); + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$6$1).length); - self._cache.writeUInt32BE(out[1], offset + 4); + for (var i = 0; i < (this || _global$6$1).length; i++) { + dest.words[i] = (this || _global$6$1).words[i]; + } - self._cache.writeUInt32BE(out[2], offset + 8); + dest.length = (this || _global$6$1).length; + dest.negative = (this || _global$6$1).negative; + dest.red = (this || _global$6$1).red; + }; - self._cache.writeUInt32BE(out[3], offset + 12); - } + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; - var pad = self._cache.slice(0, chunk.length); + BN.prototype._expand = function _expand(size) { + while ((this || _global$6$1).length < size) { + (this || _global$6$1).words[(this || _global$6$1).length++] = 0; + } - self._cache = self._cache.slice(chunk.length); - return xor(chunk, pad); - }; + return this || _global$6$1; + }; // Remove leading `0` from `this` - return exports$28; -} -var _list$1 = { - "aes-128-ecb": { - "cipher": "AES", - "key": 128, - "iv": 0, - "mode": "ECB", - "type": "block" - }, - "aes-192-ecb": { - "cipher": "AES", - "key": 192, - "iv": 0, - "mode": "ECB", - "type": "block" - }, - "aes-256-ecb": { - "cipher": "AES", - "key": 256, - "iv": 0, - "mode": "ECB", - "type": "block" - }, - "aes-128-cbc": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes-192-cbc": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes-256-cbc": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes128": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes192": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes256": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes-128-cfb": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB", - "type": "stream" - }, - "aes-192-cfb": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB", - "type": "stream" - }, - "aes-256-cfb": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB", - "type": "stream" - }, - "aes-128-cfb8": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB8", - "type": "stream" - }, - "aes-192-cfb8": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB8", - "type": "stream" - }, - "aes-256-cfb8": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB8", - "type": "stream" - }, - "aes-128-cfb1": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB1", - "type": "stream" - }, - "aes-192-cfb1": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB1", - "type": "stream" - }, - "aes-256-cfb1": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB1", - "type": "stream" - }, - "aes-128-ofb": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "OFB", - "type": "stream" - }, - "aes-192-ofb": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "OFB", - "type": "stream" - }, - "aes-256-ofb": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "OFB", - "type": "stream" - }, - "aes-128-ctr": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CTR", - "type": "stream" - }, - "aes-192-ctr": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CTR", - "type": "stream" - }, - "aes-256-ctr": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CTR", - "type": "stream" - }, - "aes-128-gcm": { - "cipher": "AES", - "key": 128, - "iv": 12, - "mode": "GCM", - "type": "auth" - }, - "aes-192-gcm": { - "cipher": "AES", - "key": 192, - "iv": 12, - "mode": "GCM", - "type": "auth" - }, - "aes-256-gcm": { - "cipher": "AES", - "key": 256, - "iv": 12, - "mode": "GCM", - "type": "auth" - } -}; + BN.prototype.strip = function strip() { + while ((this || _global$6$1).length > 1 && (this || _global$6$1).words[(this || _global$6$1).length - 1] === 0) { + (this || _global$6$1).length--; + } + + return this._normSign(); + }; + + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$6$1).length === 1 && (this || _global$6$1).words[0] === 0) { + (this || _global$6$1).negative = 0; + } + + return this || _global$6$1; + }; + + BN.prototype.inspect = function inspect() { + return ((this || _global$6$1).red ? ""; + }; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; + } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ -var exports$27 = {}, - _dewExec$26 = false; -function dew$26() { - if (_dewExec$26) return exports$27; - _dewExec$26 = true; - var modeModules = { - ECB: dew$2f(), - CBC: dew$2d(), - CFB: dew$2c(), - CFB8: dew$2b(), - CFB1: dew$2a(), - OFB: dew$29(), - CTR: dew$27(), - GCM: dew$27() - }; - var modes = _list$1; - for (var key in modes) { - modes[key].module = modeModules[modes[key].mode]; - } + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - exports$27 = modes; - return exports$27; -} + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; -var exports$26 = {}, - _dewExec$25 = false; + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; -var _global$F = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + for (var i = 0; i < (this || _global$6$1).length; i++) { + var w = (this || _global$6$1).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; -function dew$25() { - if (_dewExec$25) return exports$26; - _dewExec$25 = true; + if (carry !== 0 || i !== (this || _global$6$1).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } - // based on the aes implimentation in triple sec - // https://github.com/keybase/triplesec - // which is in turn based on the one from crypto-js - // https://code.google.com/p/crypto-js/ - var Buffer = dew$2P().Buffer; + off += 2; - function asUInt32Array(buf) { - if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); - var len = buf.length / 4 | 0; - var out = new Array(len); + if (off >= 26) { + off -= 26; + i--; + } + } - for (var i = 0; i < len; i++) { - out[i] = buf.readUInt32BE(i * 4); - } + if (carry !== 0) { + out = carry.toString(16) + out; + } - return out; - } + while (out.length % padding !== 0) { + out = "0" + out; + } - function scrubVec(v) { - for (var i = 0; i < v.length; v++) { - v[i] = 0; - } - } + if ((this || _global$6$1).negative !== 0) { + out = "-" + out; + } - function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) { - var SUB_MIX0 = SUB_MIX[0]; - var SUB_MIX1 = SUB_MIX[1]; - var SUB_MIX2 = SUB_MIX[2]; - var SUB_MIX3 = SUB_MIX[3]; - var s0 = M[0] ^ keySchedule[0]; - var s1 = M[1] ^ keySchedule[1]; - var s2 = M[2] ^ keySchedule[2]; - var s3 = M[3] ^ keySchedule[3]; - var t0, t1, t2, t3; - var ksRow = 4; + return out; + } - for (var round = 1; round < nRounds; round++) { - t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 255] ^ SUB_MIX2[s2 >>> 8 & 255] ^ SUB_MIX3[s3 & 255] ^ keySchedule[ksRow++]; - t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 255] ^ SUB_MIX2[s3 >>> 8 & 255] ^ SUB_MIX3[s0 & 255] ^ keySchedule[ksRow++]; - t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 255] ^ SUB_MIX2[s0 >>> 8 & 255] ^ SUB_MIX3[s1 & 255] ^ keySchedule[ksRow++]; - t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 255] ^ SUB_MIX2[s1 >>> 8 & 255] ^ SUB_MIX3[s2 & 255] ^ keySchedule[ksRow++]; - s0 = t0; - s1 = t1; - s2 = t2; - s3 = t3; - } + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 255] << 16 | SBOX[s2 >>> 8 & 255] << 8 | SBOX[s3 & 255]) ^ keySchedule[ksRow++]; - t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 255] << 16 | SBOX[s3 >>> 8 & 255] << 8 | SBOX[s0 & 255]) ^ keySchedule[ksRow++]; - t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 255] << 16 | SBOX[s0 >>> 8 & 255] << 8 | SBOX[s1 & 255]) ^ keySchedule[ksRow++]; - t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 255] << 16 | SBOX[s1 >>> 8 & 255] << 8 | SBOX[s2 & 255]) ^ keySchedule[ksRow++]; - t0 = t0 >>> 0; - t1 = t1 >>> 0; - t2 = t2 >>> 0; - t3 = t3 >>> 0; - return [t0, t1, t2, t3]; - } // AES constants + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); - var RCON = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]; + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } - var G = function () { - // Compute double table - var d = new Array(256); + if (this.isZero()) { + out = "0" + out; + } - for (var j = 0; j < 256; j++) { - if (j < 128) { - d[j] = j << 1; - } else { - d[j] = j << 1 ^ 283; + while (out.length % padding !== 0) { + out = "0" + out; + } + + if ((this || _global$6$1).negative !== 0) { + out = "-" + out; + } + + return out; } - } - var SBOX = []; - var INV_SBOX = []; - var SUB_MIX = [[], [], [], []]; - var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8) + assert(false, "Base should be between 2 and 36"); + }; - var x = 0; - var xi = 0; + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$6$1).words[0]; - for (var i = 0; i < 256; ++i) { - // Compute sbox - var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4; - sx = sx >>> 8 ^ sx & 255 ^ 99; - SBOX[x] = sx; - INV_SBOX[sx] = x; // Compute multiplication + if ((this || _global$6$1).length === 2) { + ret += (this || _global$6$1).words[1] * 67108864; + } else if ((this || _global$6$1).length === 3 && (this || _global$6$1).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$6$1).words[1] * 67108864; + } else if ((this || _global$6$1).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); + } - var x2 = d[x]; - var x4 = d[x2]; - var x8 = d[x4]; // Compute sub bytes, mix columns tables + return (this || _global$6$1).negative !== 0 ? -ret : ret; + }; - var t = d[sx] * 257 ^ sx * 16843008; - SUB_MIX[0][x] = t << 24 | t >>> 8; - SUB_MIX[1][x] = t << 16 | t >>> 16; - SUB_MIX[2][x] = t << 8 | t >>> 24; - SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables + BN.prototype.toJSON = function toJSON() { + return this.toString(16); + }; - t = x8 * 16843009 ^ x4 * 65537 ^ x2 * 257 ^ x * 16843008; - INV_SUB_MIX[0][sx] = t << 24 | t >>> 8; - INV_SUB_MIX[1][sx] = t << 16 | t >>> 16; - INV_SUB_MIX[2][sx] = t << 8 | t >>> 24; - INV_SUB_MIX[3][sx] = t; + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); + }; - if (x === 0) { - x = xi = 1; + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); + this.strip(); + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); + + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } } else { - x = x2 ^ d[d[d[x8 ^ x2]]]; - xi ^= d[d[xi]]; + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; + } + + for (; i < reqLength; i++) { + res[i] = 0; + } } - } - return { - SBOX: SBOX, - INV_SBOX: INV_SBOX, - SUB_MIX: SUB_MIX, - INV_SUB_MIX: INV_SUB_MIX + return res; }; - }(); - function AES(key) { - (this || _global$F)._key = asUInt32Array(key); + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; - this._reset(); - } + if (t >= 4096) { + r += 13; + t >>>= 13; + } - AES.blockSize = 4 * 4; - AES.keySize = 256 / 8; - AES.prototype.blockSize = AES.blockSize; - AES.prototype.keySize = AES.keySize; + if (t >= 64) { + r += 7; + t >>>= 7; + } - AES.prototype._reset = function () { - var keyWords = (this || _global$F)._key; - var keySize = keyWords.length; - var nRounds = keySize + 6; - var ksRows = (nRounds + 1) * 4; - var keySchedule = []; + if (t >= 8) { + r += 4; + t >>>= 4; + } - for (var k = 0; k < keySize; k++) { - keySchedule[k] = keyWords[k]; + if (t >= 2) { + r += 2; + t >>>= 2; + } + + return r + t; + }; } - for (k = keySize; k < ksRows; k++) { - var t = keySchedule[k - 1]; + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; - if (k % keySize === 0) { - t = t << 8 | t >>> 24; - t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; - t ^= RCON[k / keySize | 0] << 24; - } else if (keySize > 6 && k % keySize === 4) { - t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; } - keySchedule[k] = keySchedule[k - keySize] ^ t; - } + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } - var invKeySchedule = []; + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } - for (var ik = 0; ik < ksRows; ik++) { - var ksR = ksRows - ik; - var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]; + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } - if (ik < 4 || ksR <= 4) { - invKeySchedule[ik] = tt; - } else { - invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 255]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 255]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 255]]; + if ((t & 1) === 0) { + r++; } - } - (this || _global$F)._nRounds = nRounds; - (this || _global$F)._keySchedule = keySchedule; - (this || _global$F)._invKeySchedule = invKeySchedule; - }; + return r; + }; // Return number of used bits in a BN - AES.prototype.encryptBlockRaw = function (M) { - M = asUInt32Array(M); - return cryptBlock(M, (this || _global$F)._keySchedule, G.SUB_MIX, G.SBOX, (this || _global$F)._nRounds); - }; - AES.prototype.encryptBlock = function (M) { - var out = this.encryptBlockRaw(M); - var buf = Buffer.allocUnsafe(16); - buf.writeUInt32BE(out[0], 0); - buf.writeUInt32BE(out[1], 4); - buf.writeUInt32BE(out[2], 8); - buf.writeUInt32BE(out[3], 12); - return buf; - }; + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$6$1).words[(this || _global$6$1).length - 1]; - AES.prototype.decryptBlock = function (M) { - M = asUInt32Array(M); // swap + var hi = this._countBits(w); - var m1 = M[1]; - M[1] = M[3]; - M[3] = m1; - var out = cryptBlock(M, (this || _global$F)._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, (this || _global$F)._nRounds); - var buf = Buffer.allocUnsafe(16); - buf.writeUInt32BE(out[0], 0); - buf.writeUInt32BE(out[3], 4); - buf.writeUInt32BE(out[2], 8); - buf.writeUInt32BE(out[1], 12); - return buf; - }; + return ((this || _global$6$1).length - 1) * 26 + hi; + }; - AES.prototype.scrub = function () { - scrubVec((this || _global$F)._keySchedule); - scrubVec((this || _global$F)._invKeySchedule); - scrubVec((this || _global$F)._key); - }; + function toBitArray(num) { + var w = new Array(num.bitLength()); - exports$26.AES = AES; - return exports$26; -} + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } -var exports$25 = {}, - _dewExec$24 = false; + return w; + } // Number of trailing zero bits -var _global$E = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$24() { - if (_dewExec$24) return exports$25; - _dewExec$24 = true; + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; - var Buffer = dew$2P().Buffer; + for (var i = 0; i < (this || _global$6$1).length; i++) { + var b = this._zeroBits((this || _global$6$1).words[i]); - var ZEROES = Buffer.alloc(16, 0); + r += b; + if (b !== 26) break; + } - function toArray(buf) { - return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)]; - } + return r; + }; - function fromArray(out) { - var buf = Buffer.allocUnsafe(16); - buf.writeUInt32BE(out[0] >>> 0, 0); - buf.writeUInt32BE(out[1] >>> 0, 4); - buf.writeUInt32BE(out[2] >>> 0, 8); - buf.writeUInt32BE(out[3] >>> 0, 12); - return buf; - } + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); + }; - function GHASH(key) { - (this || _global$E).h = key; - (this || _global$E).state = Buffer.alloc(16, 0); - (this || _global$E).cache = Buffer.allocUnsafe(0); - } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html - // by Juho Vähä-Herttua + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$6$1).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } + return this.clone(); + }; - GHASH.prototype.ghash = function (block) { - var i = -1; + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } - while (++i < block.length) { - (this || _global$E).state[i] ^= block[i]; - } + return this.clone(); + }; - this._multiply(); - }; + BN.prototype.isNeg = function isNeg() { + return (this || _global$6$1).negative !== 0; + }; // Return negative clone of `this` - GHASH.prototype._multiply = function () { - var Vi = toArray((this || _global$E).h); - var Zi = [0, 0, 0, 0]; - var j, xi, lsbVi; - var i = -1; - while (++i < 128) { - xi = ((this || _global$E).state[~~(i / 8)] & 1 << 7 - i % 8) !== 0; + BN.prototype.neg = function neg() { + return this.clone().ineg(); + }; - if (xi) { - // Z_i+1 = Z_i ^ V_i - Zi[0] ^= Vi[0]; - Zi[1] ^= Vi[1]; - Zi[2] ^= Vi[2]; - Zi[3] ^= Vi[3]; - } // Store the value of LSB(V_i) + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$6$1).negative ^= 1; + } + + return this || _global$6$1; + }; // Or `num` with `this` in-place + + + BN.prototype.iuor = function iuor(num) { + while ((this || _global$6$1).length < num.length) { + (this || _global$6$1).words[(this || _global$6$1).length++] = 0; + } + + for (var i = 0; i < num.length; i++) { + (this || _global$6$1).words[i] = (this || _global$6$1).words[i] | num.words[i]; + } + + return this.strip(); + }; + + BN.prototype.ior = function ior(num) { + assert(((this || _global$6$1).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` + + + BN.prototype.or = function or(num) { + if ((this || _global$6$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$6$1); + }; + + BN.prototype.uor = function uor(num) { + if ((this || _global$6$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$6$1); + }; // And `num` with `this` in-place - lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1 + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; - for (j = 3; j > 0; j--) { - Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31; + if ((this || _global$6$1).length > num.length) { + b = num; + } else { + b = this || _global$6$1; } - Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R - - if (lsbVi) { - Vi[0] = Vi[0] ^ 225 << 24; + for (var i = 0; i < b.length; i++) { + (this || _global$6$1).words[i] = (this || _global$6$1).words[i] & num.words[i]; } - } - (this || _global$E).state = fromArray(Zi); - }; + (this || _global$6$1).length = b.length; + return this.strip(); + }; - GHASH.prototype.update = function (buf) { - (this || _global$E).cache = Buffer.concat([(this || _global$E).cache, buf]); - var chunk; + BN.prototype.iand = function iand(num) { + assert(((this || _global$6$1).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` - while ((this || _global$E).cache.length >= 16) { - chunk = (this || _global$E).cache.slice(0, 16); - (this || _global$E).cache = (this || _global$E).cache.slice(16); - this.ghash(chunk); - } - }; - GHASH.prototype.final = function (abl, bl) { - if ((this || _global$E).cache.length) { - this.ghash(Buffer.concat([(this || _global$E).cache, ZEROES], 16)); - } + BN.prototype.and = function and(num) { + if ((this || _global$6$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$6$1); + }; - this.ghash(fromArray([0, abl, 0, bl])); - return (this || _global$E).state; - }; + BN.prototype.uand = function uand(num) { + if ((this || _global$6$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$6$1); + }; // Xor `num` with `this` in-place - exports$25 = GHASH; - return exports$25; -} -var exports$24 = {}, - _dewExec$23 = false; + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; -var _global$D = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + if ((this || _global$6$1).length > num.length) { + a = this || _global$6$1; + b = num; + } else { + a = num; + b = this || _global$6$1; + } -function dew$23() { - if (_dewExec$23) return exports$24; - _dewExec$23 = true; + for (var i = 0; i < b.length; i++) { + (this || _global$6$1).words[i] = a.words[i] ^ b.words[i]; + } - var aes = dew$25(); + if ((this || _global$6$1) !== a) { + for (; i < a.length; i++) { + (this || _global$6$1).words[i] = a.words[i]; + } + } - var Buffer = dew$2P().Buffer; + (this || _global$6$1).length = a.length; + return this.strip(); + }; - var Transform = dew$2z(); + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$6$1).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` - var inherits = dew$2R(); - var GHASH = dew$24(); + BN.prototype.xor = function xor(num) { + if ((this || _global$6$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$6$1); + }; - var xor = dew$2e(); + BN.prototype.uxor = function uxor(num) { + if ((this || _global$6$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$6$1); + }; // Not ``this`` with ``width`` bitwidth - var incr32 = dew$28(); - function xorTest(a, b) { - var out = 0; - if (a.length !== b.length) out++; - var len = Math.min(a.length, b.length); + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes - for (var i = 0; i < len; ++i) { - out += a[i] ^ b[i]; - } + this._expand(bytesNeeded); - return out; - } + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words - function calcIv(self, iv, ck) { - if (iv.length === 12) { - self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]); - return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]); - } - var ghash = new GHASH(ck); - var len = iv.length; - var toPad = len % 16; - ghash.update(iv); + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$6$1).words[i] = ~(this || _global$6$1).words[i] & 67108863; + } // Handle the residue - if (toPad) { - toPad = 16 - toPad; - ghash.update(Buffer.alloc(toPad, 0)); - } - ghash.update(Buffer.alloc(8, 0)); - var ivBits = len * 8; - var tail = Buffer.alloc(8); - tail.writeUIntBE(ivBits, 0, 8); - ghash.update(tail); - self._finID = ghash.state; - var out = Buffer.from(self._finID); - incr32(out); - return out; - } + if (bitsLeft > 0) { + (this || _global$6$1).words[i] = ~(this || _global$6$1).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes - function StreamCipher(mode, key, iv, decrypt) { - Transform.call(this || _global$D); - var h = Buffer.alloc(4, 0); - (this || _global$D)._cipher = new aes.AES(key); - var ck = (this || _global$D)._cipher.encryptBlock(h); + return this.strip(); + }; - (this || _global$D)._ghash = new GHASH(ck); - iv = calcIv(this || _global$D, iv, ck); - (this || _global$D)._prev = Buffer.from(iv); - (this || _global$D)._cache = Buffer.allocUnsafe(0); - (this || _global$D)._secCache = Buffer.allocUnsafe(0); - (this || _global$D)._decrypt = decrypt; - (this || _global$D)._alen = 0; - (this || _global$D)._len = 0; - (this || _global$D)._mode = mode; - (this || _global$D)._authTag = null; - (this || _global$D)._called = false; - } + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` - inherits(StreamCipher, Transform); - StreamCipher.prototype._update = function (chunk) { - if (!(this || _global$D)._called && (this || _global$D)._alen) { - var rump = 16 - (this || _global$D)._alen % 16; + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; - if (rump < 16) { - rump = Buffer.alloc(rump, 0); + this._expand(off + 1); - (this || _global$D)._ghash.update(rump); + if (val) { + (this || _global$6$1).words[off] = (this || _global$6$1).words[off] | 1 << wbit; + } else { + (this || _global$6$1).words[off] = (this || _global$6$1).words[off] & ~(1 << wbit); } - } - - (this || _global$D)._called = true; - - var out = (this || _global$D)._mode.encrypt(this || _global$D, chunk); - - if ((this || _global$D)._decrypt) { - (this || _global$D)._ghash.update(chunk); - } else { - (this || _global$D)._ghash.update(out); - } - - (this || _global$D)._len += chunk.length; - return out; - }; - StreamCipher.prototype._final = function () { - if ((this || _global$D)._decrypt && !(this || _global$D)._authTag) throw new Error("Unsupported state or unable to authenticate data"); - var tag = xor((this || _global$D)._ghash.final((this || _global$D)._alen * 8, (this || _global$D)._len * 8), (this || _global$D)._cipher.encryptBlock((this || _global$D)._finID)); - if ((this || _global$D)._decrypt && xorTest(tag, (this || _global$D)._authTag)) throw new Error("Unsupported state or unable to authenticate data"); - (this || _global$D)._authTag = tag; + return this.strip(); + }; // Add `num` to `this` in-place - (this || _global$D)._cipher.scrub(); - }; - StreamCipher.prototype.getAuthTag = function getAuthTag() { - if ((this || _global$D)._decrypt || !Buffer.isBuffer((this || _global$D)._authTag)) throw new Error("Attempting to get auth tag in unsupported state"); - return (this || _global$D)._authTag; - }; + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive - StreamCipher.prototype.setAuthTag = function setAuthTag(tag) { - if (!(this || _global$D)._decrypt) throw new Error("Attempting to set auth tag in unsupported state"); - (this || _global$D)._authTag = tag; - }; + if ((this || _global$6$1).negative !== 0 && num.negative === 0) { + (this || _global$6$1).negative = 0; + r = this.isub(num); + (this || _global$6$1).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$6$1).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length - StreamCipher.prototype.setAAD = function setAAD(buf) { - if ((this || _global$D)._called) throw new Error("Attempting to set AAD in unsupported state"); - (this || _global$D)._ghash.update(buf); + var a, b; - (this || _global$D)._alen += buf.length; - }; + if ((this || _global$6$1).length > num.length) { + a = this || _global$6$1; + b = num; + } else { + a = num; + b = this || _global$6$1; + } - exports$24 = StreamCipher; - return exports$24; -} + var carry = 0; -var exports$23 = {}, - _dewExec$22 = false; + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$6$1).words[i] = r & 67108863; + carry = r >>> 26; + } -var _global$C = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$6$1).words[i] = r & 67108863; + carry = r >>> 26; + } -function dew$22() { - if (_dewExec$22) return exports$23; - _dewExec$22 = true; + (this || _global$6$1).length = a.length; - var aes = dew$25(); + if (carry !== 0) { + (this || _global$6$1).words[(this || _global$6$1).length] = carry; + (this || _global$6$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$6$1)) { + for (; i < a.length; i++) { + (this || _global$6$1).words[i] = a.words[i]; + } + } - var Buffer = dew$2P().Buffer; + return this || _global$6$1; + }; // Add `num` to `this` - var Transform = dew$2z(); - var inherits = dew$2R(); + BN.prototype.add = function add(num) { + var res; - function StreamCipher(mode, key, iv, decrypt) { - Transform.call(this || _global$C); - (this || _global$C)._cipher = new aes.AES(key); - (this || _global$C)._prev = Buffer.from(iv); - (this || _global$C)._cache = Buffer.allocUnsafe(0); - (this || _global$C)._secCache = Buffer.allocUnsafe(0); - (this || _global$C)._decrypt = decrypt; - (this || _global$C)._mode = mode; - } + if (num.negative !== 0 && (this || _global$6$1).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$6$1).negative !== 0) { + (this || _global$6$1).negative = 0; + res = num.sub(this || _global$6$1); + (this || _global$6$1).negative = 1; + return res; + } - inherits(StreamCipher, Transform); + if ((this || _global$6$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$6$1); + }; // Subtract `num` from `this` in-place - StreamCipher.prototype._update = function (chunk) { - return (this || _global$C)._mode.encrypt(this || _global$C, chunk, (this || _global$C)._decrypt); - }; - StreamCipher.prototype._final = function () { - (this || _global$C)._cipher.scrub(); - }; + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$6$1).negative !== 0) { + (this || _global$6$1).negative = 0; + this.iadd(num); + (this || _global$6$1).negative = 1; + return this._normSign(); + } // At this point both numbers are positive - exports$23 = StreamCipher; - return exports$23; -} -var exports$22 = {}, - _dewExec$21 = false; -function dew$21() { - if (_dewExec$21) return exports$22; - _dewExec$21 = true; + var cmp = this.cmp(num); // Optimization - zeroify - var Buffer = dew$2P().Buffer; + if (cmp === 0) { + (this || _global$6$1).negative = 0; + (this || _global$6$1).length = 1; + (this || _global$6$1).words[0] = 0; + return this || _global$6$1; + } // a > b - var MD5 = dew$2L(); - /* eslint-disable camelcase */ + var a, b; - function EVP_BytesToKey(password, salt, keyBits, ivLen) { - if (!Buffer.isBuffer(password)) password = Buffer.from(password, "binary"); + if (cmp > 0) { + a = this || _global$6$1; + b = num; + } else { + a = num; + b = this || _global$6$1; + } - if (salt) { - if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, "binary"); - if (salt.length !== 8) throw new RangeError("salt should be Buffer with 8 byte length"); - } + var carry = 0; - var keyLen = keyBits / 8; - var key = Buffer.alloc(keyLen); - var iv = Buffer.alloc(ivLen || 0); - var tmp = Buffer.alloc(0); + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$6$1).words[i] = r & 67108863; + } - while (keyLen > 0 || ivLen > 0) { - var hash = new MD5(); - hash.update(tmp); - hash.update(password); - if (salt) hash.update(salt); - tmp = hash.digest(); - var used = 0; + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$6$1).words[i] = r & 67108863; + } // Copy rest of the words - if (keyLen > 0) { - var keyStart = key.length - keyLen; - used = Math.min(keyLen, tmp.length); - tmp.copy(key, keyStart, 0, used); - keyLen -= used; - } - if (used < tmp.length && ivLen > 0) { - var ivStart = iv.length - ivLen; - var length = Math.min(ivLen, tmp.length - used); - tmp.copy(iv, ivStart, used, used + length); - ivLen -= length; + if (carry === 0 && i < a.length && a !== (this || _global$6$1)) { + for (; i < a.length; i++) { + (this || _global$6$1).words[i] = a.words[i]; + } } - } - tmp.fill(0); - return { - key: key, - iv: iv - }; - } + (this || _global$6$1).length = Math.max((this || _global$6$1).length, i); - exports$22 = EVP_BytesToKey; - return exports$22; -} + if (a !== (this || _global$6$1)) { + (this || _global$6$1).negative = 1; + } -var exports$21 = {}, - _dewExec$20 = false; + return this.strip(); + }; // Subtract `num` from `this` -var _global$B = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$20() { - if (_dewExec$20) return exports$21; - _dewExec$20 = true; + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); + }; - var MODES = dew$26(); + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) - var AuthCipher = dew$23(); + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; - var Buffer = dew$2P().Buffer; + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); - var StreamCipher = dew$22(); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } - var Transform = dew$2z(); + out.words[k] = rword | 0; + carry = ncarry | 0; + } - var aes = dew$25(); + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; + } - var ebtk = dew$21(); + return out.strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). - var inherits = dew$2R(); - function Cipher(mode, key, iv) { - Transform.call(this || _global$B); - (this || _global$B)._cache = new Splitter(); - (this || _global$B)._cipher = new aes.AES(key); - (this || _global$B)._prev = Buffer.from(iv); - (this || _global$B)._mode = mode; - (this || _global$B)._autopadding = true; - } + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ - inherits(Cipher, Transform); + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ - Cipher.prototype._update = function (data) { - (this || _global$B)._cache.add(data); + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ - var chunk; - var thing; - var out = []; + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ - while (chunk = (this || _global$B)._cache.get()) { - thing = (this || _global$B)._mode.encrypt(this || _global$B, chunk); - out.push(thing); - } + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ - return Buffer.concat(out); - }; + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ - var PADDING = Buffer.alloc(16, 16); + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ - Cipher.prototype._final = function () { - var chunk = (this || _global$B)._cache.flush(); + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ - if ((this || _global$B)._autopadding) { - chunk = (this || _global$B)._mode.encrypt(this || _global$B, chunk); + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ - (this || _global$B)._cipher.scrub(); + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ - return chunk; - } + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ - if (!chunk.equals(PADDING)) { - (this || _global$B)._cipher.scrub(); + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ - throw new Error("data not multiple of block length"); - } - }; + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ - Cipher.prototype.setAutoPadding = function (setTo) { - (this || _global$B)._autopadding = !!setTo; - return this || _global$B; - }; + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ - function Splitter() { - (this || _global$B).cache = Buffer.allocUnsafe(0); - } + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ - Splitter.prototype.add = function (data) { - (this || _global$B).cache = Buffer.concat([(this || _global$B).cache, data]); - }; + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ - Splitter.prototype.get = function () { - if ((this || _global$B).cache.length > 15) { - var out = (this || _global$B).cache.slice(0, 16); + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ - (this || _global$B).cache = (this || _global$B).cache.slice(16); - return out; - } + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ - return null; - }; + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ - Splitter.prototype.flush = function () { - var len = 16 - (this || _global$B).cache.length; - var padBuff = Buffer.allocUnsafe(len); - var i = -1; + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; - while (++i < len) { - padBuff.writeUInt8(len, i); - } + if (c !== 0) { + o[19] = c; + out.length++; + } - return Buffer.concat([(this || _global$B).cache, padBuff]); - }; + return out; + }; // Polyfill comb - function createCipheriv(suite, password, iv) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - if (typeof password === "string") password = Buffer.from(password); - if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); - if (typeof iv === "string") iv = Buffer.from(iv); - if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); - if (config.type === "stream") { - return new StreamCipher(config.module, password, iv); - } else if (config.type === "auth") { - return new AuthCipher(config.module, password, iv); + if (!Math.imul) { + comb10MulTo = smallMulTo; } - return new Cipher(config.module, password, iv); - } - - function createCipher(suite, password) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - var keys = ebtk(password, false, config.key, config.iv); - return createCipheriv(suite, keys.key, keys.iv); - } + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; - exports$21.createCipheriv = createCipheriv; - exports$21.createCipher = createCipher; - return exports$21; -} + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); -var exports$20 = {}, - _dewExec$1$ = false; + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; + } -var _global$A = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; + } -function dew$1$() { - if (_dewExec$1$) return exports$20; - _dewExec$1$ = true; + if (carry !== 0) { + out.words[k] = carry; + } else { + out.length--; + } - var AuthCipher = dew$23(); + return out.strip(); + } - var Buffer = dew$2P().Buffer; + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } - var MODES = dew$26(); + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$6$1).length + num.length; - var StreamCipher = dew$22(); + if ((this || _global$6$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$6$1, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$6$1, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$6$1, num, out); + } else { + res = jumboMulTo(this || _global$6$1, num, out); + } - var Transform = dew$2z(); + return res; + }; // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion - var aes = dew$25(); - var ebtk = dew$21(); + function FFTM(x, y) { + (this || _global$6$1).x = x; + (this || _global$6$1).y = y; + } - var inherits = dew$2R(); + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; - function Decipher(mode, key, iv) { - Transform.call(this || _global$A); - (this || _global$A)._cache = new Splitter(); - (this || _global$A)._last = void 0; - (this || _global$A)._cipher = new aes.AES(key); - (this || _global$A)._prev = Buffer.from(iv); - (this || _global$A)._mode = mode; - (this || _global$A)._autopadding = true; - } + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); + } - inherits(Decipher, Transform); + return t; + }; // Returns binary-reversed representation of `x` - Decipher.prototype._update = function (data) { - (this || _global$A)._cache.add(data); - var chunk; - var thing; - var out = []; + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; - while (chunk = (this || _global$A)._cache.get((this || _global$A)._autopadding)) { - thing = (this || _global$A)._mode.decrypt(this || _global$A, chunk); - out.push(thing); - } + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } - return Buffer.concat(out); - }; + return rb; + }; // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm - Decipher.prototype._final = function () { - var chunk = (this || _global$A)._cache.flush(); - if ((this || _global$A)._autopadding) { - return unpad((this || _global$A)._mode.decrypt(this || _global$A, chunk)); - } else if (chunk) { - throw new Error("data not multiple of block length"); - } - }; + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; + } + }; - Decipher.prototype.setAutoPadding = function (setTo) { - (this || _global$A)._autopadding = !!setTo; - return this || _global$A; - }; + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); - function Splitter() { - (this || _global$A).cache = Buffer.allocUnsafe(0); - } + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); - Splitter.prototype.add = function (data) { - (this || _global$A).cache = Buffer.concat([(this || _global$A).cache, data]); - }; + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; - Splitter.prototype.get = function (autoPadding) { - var out; + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + /* jshint maxdepth : false */ - if (autoPadding) { - if ((this || _global$A).cache.length > 16) { - out = (this || _global$A).cache.slice(0, 16); - (this || _global$A).cache = (this || _global$A).cache.slice(16); - return out; - } - } else { - if ((this || _global$A).cache.length >= 16) { - out = (this || _global$A).cache.slice(0, 16); - (this || _global$A).cache = (this || _global$A).cache.slice(16); - return out; + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } } - } - - return null; - }; + }; - Splitter.prototype.flush = function () { - if ((this || _global$A).cache.length) return (this || _global$A).cache; - }; + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; - function unpad(last) { - var padded = last[15]; + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; + } - if (padded < 1 || padded > 16) { - throw new Error("unable to decrypt data"); - } + return 1 << i + 1 + odd; + }; - var i = -1; + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; - while (++i < padded) { - if (last[i + (16 - padded)] !== padded) { - throw new Error("unable to decrypt data"); + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; } - } - - if (padded === 16) return; - return last.slice(0, 16 - padded); - } - - function createDecipheriv(suite, password, iv) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - if (typeof iv === "string") iv = Buffer.from(iv); - if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); - if (typeof password === "string") password = Buffer.from(password); - if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + }; - if (config.type === "stream") { - return new StreamCipher(config.module, password, iv, true); - } else if (config.type === "auth") { - return new AuthCipher(config.module, password, iv, true); - } + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; - return new Decipher(config.module, password, iv); - } + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; - function createDecipher(suite, password) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - var keys = ebtk(password, false, config.key, config.iv); - return createDecipheriv(suite, keys.key, keys.iv); - } + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } - exports$20.createDecipher = createDecipher; - exports$20.createDecipheriv = createDecipheriv; - return exports$20; -} + return ws; + }; -var exports$1$ = {}, - _dewExec$1_ = false; -function dew$1_() { - if (_dewExec$1_) return exports$1$; - _dewExec$1_ = true; + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; - var ciphers = dew$20(); + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } // Pad with zeroes - var deciphers = dew$1$(); - var modes = _list$1; + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } - function getCiphers() { - return Object.keys(modes); - } + assert(carry === 0); + assert((carry & ~8191) === 0); + }; - exports$1$.createCipher = exports$1$.Cipher = ciphers.createCipher; - exports$1$.createCipheriv = exports$1$.Cipheriv = ciphers.createCipheriv; - exports$1$.createDecipher = exports$1$.Decipher = deciphers.createDecipher; - exports$1$.createDecipheriv = exports$1$.Decipheriv = deciphers.createDecipheriv; - exports$1$.listCiphers = exports$1$.getCiphers = getCiphers; - return exports$1$; -} + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); -var exports$1_ = {}, - _dewExec$1Z = false; -function dew$1Z() { - if (_dewExec$1Z) return exports$1_; - _dewExec$1Z = true; - exports$1_["des-ecb"] = { - key: 8, - iv: 0 - }; - exports$1_["des-cbc"] = exports$1_.des = { - key: 8, - iv: 8 - }; - exports$1_["des-ede3-cbc"] = exports$1_.des3 = { - key: 24, - iv: 8 - }; - exports$1_["des-ede3"] = { - key: 24, - iv: 0 - }; - exports$1_["des-ede-cbc"] = { - key: 16, - iv: 8 - }; - exports$1_["des-ede"] = { - key: 16, - iv: 0 - }; - return exports$1_; -} + for (var i = 0; i < N; i++) { + ph[i] = 0; + } -var exports$1Z = {}, - _dewExec$1Y = false; -function dew$1Y() { - if (_dewExec$1Y) return exports$1Z; - _dewExec$1Y = true; + return ph; + }; - var DES = dew$2g(); + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); - var aes = dew$1_(); + var _ = this.stub(N); - var aesModes = dew$26(); + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); - var desModes = dew$1Z(); + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } - var ebtk = dew$21(); + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; // Multiply `this` by `num` - function createCipher(suite, password) { - suite = suite.toLowerCase(); - var keyLen, ivLen; - if (aesModes[suite]) { - keyLen = aesModes[suite].key; - ivLen = aesModes[suite].iv; - } else if (desModes[suite]) { - keyLen = desModes[suite].key * 8; - ivLen = desModes[suite].iv; - } else { - throw new TypeError("invalid suite type"); - } + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$6$1).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT - var keys = ebtk(password, false, keyLen, ivLen); - return createCipheriv(suite, keys.key, keys.iv); - } - function createDecipher(suite, password) { - suite = suite.toLowerCase(); - var keyLen, ivLen; + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$6$1).length + num.length); + return jumboMulTo(this || _global$6$1, num, out); + }; // In-place Multiplication - if (aesModes[suite]) { - keyLen = aesModes[suite].key; - ivLen = aesModes[suite].iv; - } else if (desModes[suite]) { - keyLen = desModes[suite].key * 8; - ivLen = desModes[suite].iv; - } else { - throw new TypeError("invalid suite type"); - } - var keys = ebtk(password, false, keyLen, ivLen); - return createDecipheriv(suite, keys.key, keys.iv); - } + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$6$1); + }; - function createCipheriv(suite, key, iv) { - suite = suite.toLowerCase(); - if (aesModes[suite]) return aes.createCipheriv(suite, key, iv); - if (desModes[suite]) return new DES({ - key: key, - iv: iv, - mode: suite - }); - throw new TypeError("invalid suite type"); - } + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); // Carry - function createDecipheriv(suite, key, iv) { - suite = suite.toLowerCase(); - if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv); - if (desModes[suite]) return new DES({ - key: key, - iv: iv, - mode: suite, - decrypt: true - }); - throw new TypeError("invalid suite type"); - } + var carry = 0; - function getCiphers() { - return Object.keys(desModes).concat(aes.getCiphers()); - } + for (var i = 0; i < (this || _global$6$1).length; i++) { + var w = ((this || _global$6$1).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - exports$1Z.createCipher = exports$1Z.Cipher = createCipher; - exports$1Z.createCipheriv = exports$1Z.Cipheriv = createCipheriv; - exports$1Z.createDecipher = exports$1Z.Decipher = createDecipher; - exports$1Z.createDecipheriv = exports$1Z.Decipheriv = createDecipheriv; - exports$1Z.listCiphers = exports$1Z.getCiphers = getCiphers; - return exports$1Z; -} + carry += lo >>> 26; + (this || _global$6$1).words[i] = lo & 67108863; + } -var exports$1Y = {}, - _dewExec$1X = false; -var module$a = { - exports: exports$1Y -}; + if (carry !== 0) { + (this || _global$6$1).words[i] = carry; + (this || _global$6$1).length++; + } -var _global$z = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + return this || _global$6$1; + }; -function dew$1X() { - if (_dewExec$1X) return module$a.exports; - _dewExec$1X = true; + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` - (function (module, exports) { - function assert(val, msg) { - if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$6$1); + }; // `this` * `this` in-place - function inherits(ctor, superCtor) { - ctor.super_ = superCtor; + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; - ctor.prototype = new TempCtor(); - ctor.prototype.constructor = ctor; - } // BN + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes + var res = this || _global$6$1; - function BN(number, base, endian) { - if (BN.isBN(number)) { - return number; + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; } - (this || _global$z).negative = 0; - (this || _global$z).words = null; - (this || _global$z).length = 0; // Reduction context + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } - (this || _global$z).red = null; + return res; + }; // Shift-left in-place - if (number !== null) { - if (base === "le" || base === "be") { - endian = base; - base = 10; - } - this._init(number || 0, base || 10, endian || "be"); - } - } + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; - if (typeof module === "object") { - module.exports = BN; - } else { - exports.BN = BN; - } + if (r !== 0) { + var carry = 0; - BN.BN = BN; - BN.wordSize = 26; - var Buffer; + for (i = 0; i < (this || _global$6$1).length; i++) { + var newCarry = (this || _global$6$1).words[i] & carryMask; + var c = ((this || _global$6$1).words[i] | 0) - newCarry << r; + (this || _global$6$1).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } - try { - if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { - Buffer = window.Buffer; - } else { - Buffer = buffer.Buffer; + if (carry) { + (this || _global$6$1).words[i] = carry; + (this || _global$6$1).length++; + } } - } catch (e) {} - BN.isBN = function isBN(num) { - if (num instanceof BN) { - return true; + if (s !== 0) { + for (i = (this || _global$6$1).length - 1; i >= 0; i--) { + (this || _global$6$1).words[i + s] = (this || _global$6$1).words[i]; + } + + for (i = 0; i < s; i++) { + (this || _global$6$1).words[i] = 0; + } + + (this || _global$6$1).length += s; } - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + return this.strip(); }; - BN.max = function max(left, right) { - if (left.cmp(right) > 0) return left; - return right; - }; + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$6$1).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits - BN.min = function min(left, right) { - if (left.cmp(right) < 0) return left; - return right; - }; - BN.prototype._init = function init(number, base, endian) { - if (typeof number === "number") { - return this._initNumber(number, base, endian); - } + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; - if (typeof number === "object") { - return this._initArray(number, base, endian); + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; } - if (base === "hex") { - base = 16; - } + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$6$1).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part - assert(base === (base | 0) && base >= 2 && base <= 36); - number = number.toString().replace(/\s+/g, ""); - var start = 0; + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$6$1).words[i]; + } - if (number[0] === "-") { - start++; - (this || _global$z).negative = 1; + maskedWords.length = s; } - if (start < number.length) { - if (base === 16) { - this._parseHex(number, start, endian); - } else { - this._parseBase(number, base, start); + if (s === 0) ; else if ((this || _global$6$1).length > s) { + (this || _global$6$1).length -= s; - if (endian === "le") { - this._initArray(this.toArray(), base, endian); - } + for (i = 0; i < (this || _global$6$1).length; i++) { + (this || _global$6$1).words[i] = (this || _global$6$1).words[i + s]; } + } else { + (this || _global$6$1).words[0] = 0; + (this || _global$6$1).length = 1; } - }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { - if (number < 0) { - (this || _global$z).negative = 1; - number = -number; - } + var carry = 0; - if (number < 67108864) { - (this || _global$z).words = [number & 67108863]; - (this || _global$z).length = 1; - } else if (number < 4503599627370496) { - (this || _global$z).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$z).length = 2; - } else { - assert(number < 9007199254740992); // 2 ^ 53 (unsafe) + for (i = (this || _global$6$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$6$1).words[i] | 0; + (this || _global$6$1).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask - (this || _global$z).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$z).length = 3; + + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; } - if (endian !== "le") return; // Reverse the bytes + if ((this || _global$6$1).length === 0) { + (this || _global$6$1).words[0] = 0; + (this || _global$6$1).length = 1; + } - this._initArray(this.toArray(), base, endian); + return this.strip(); }; - BN.prototype._initArray = function _initArray(number, base, endian) { - // Perhaps a Uint8Array - assert(typeof number.length === "number"); + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$6$1).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left - if (number.length <= 0) { - (this || _global$z).words = [0]; - (this || _global$z).length = 1; - return this || _global$z; - } - (this || _global$z).length = Math.ceil(number.length / 3); - (this || _global$z).words = new Array((this || _global$z).length); + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; - for (var i = 0; i < (this || _global$z).length; i++) { - (this || _global$z).words[i] = 0; - } + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right - var j, w; - var off = 0; - if (endian === "be") { - for (i = number.length - 1, j = 0; i >= 0; i -= 3) { - w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$z).words[j] |= w << off & 67108863; - (this || _global$z).words[j + 1] = w >>> 26 - off & 67108863; - off += 24; + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; - if (off >= 26) { - off -= 26; - j++; - } - } - } else if (endian === "le") { - for (i = 0, j = 0; i < number.length; i += 3) { - w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$z).words[j] |= w << off & 67108863; - (this || _global$z).words[j + 1] = w >>> 26 - off & 67108863; - off += 24; + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set - if (off >= 26) { - off -= 26; - j++; - } - } - } - return this.strip(); - }; + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // 'A' - 'F' + if ((this || _global$6$1).length <= s) return false; // Check bit and return - if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' - } else if (c >= 97 && c <= 102) { - return c - 87; // '0' - '9' - } else { - return c - 48 & 15; - } - } + var w = (this || _global$6$1).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) - function parseHexByte(string, lowerBound, index) { - var r = parseHex4Bits(string, index); - if (index - 1 >= lowerBound) { - r |= parseHex4Bits(string, index - 1) << 4; + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$6$1).negative === 0, "imaskn works only with positive numbers"); + + if ((this || _global$6$1).length <= s) { + return this || _global$6$1; } - return r; - } + if (r !== 0) { + s++; + } - BN.prototype._parseHex = function _parseHex(number, start, endian) { - // Create possibly bigger array to ensure that it fits the number - (this || _global$z).length = Math.ceil((number.length - start) / 6); - (this || _global$z).words = new Array((this || _global$z).length); + (this || _global$6$1).length = Math.min(s, (this || _global$6$1).length); - for (var i = 0; i < (this || _global$z).length; i++) { - (this || _global$z).words[i] = 0; - } // 24-bits chunks + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$6$1).words[(this || _global$6$1).length - 1] &= mask; + } + return this.strip(); + }; // Return only lowers bits of number - var off = 0; - var j = 0; - var w; - if (endian === "be") { - for (i = number.length - 1; i >= start; i -= 2) { - w = parseHexByte(number, start, i) << off; - (this || _global$z).words[j] |= w & 67108863; + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` - if (off >= 18) { - off -= 18; - j += 1; - (this || _global$z).words[j] |= w >>> 26; - } else { - off += 8; - } - } - } else { - var parseLength = number.length - start; - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { - w = parseHexByte(number, start, i) << off; - (this || _global$z).words[j] |= w & 67108863; + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change - if (off >= 18) { - off -= 18; - j += 1; - (this || _global$z).words[j] |= w >>> 26; - } else { - off += 8; - } + if ((this || _global$6$1).negative !== 0) { + if ((this || _global$6$1).length === 1 && ((this || _global$6$1).words[0] | 0) < num) { + (this || _global$6$1).words[0] = num - ((this || _global$6$1).words[0] | 0); + (this || _global$6$1).negative = 0; + return this || _global$6$1; } - } - this.strip(); + (this || _global$6$1).negative = 0; + this.isubn(num); + (this || _global$6$1).negative = 1; + return this || _global$6$1; + } // Add without checks + + + return this._iaddn(num); }; - function parseBase(str, start, end, mul) { - var r = 0; - var len = Math.min(str.length, end); + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$6$1).words[0] += num; // Carry - for (var i = start; i < len; i++) { - var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + for (var i = 0; i < (this || _global$6$1).length && (this || _global$6$1).words[i] >= 67108864; i++) { + (this || _global$6$1).words[i] -= 67108864; - if (c >= 49) { - r += c - 49 + 10; // 'A' - } else if (c >= 17) { - r += c - 17 + 10; // '0' - '9' + if (i === (this || _global$6$1).length - 1) { + (this || _global$6$1).words[i + 1] = 1; } else { - r += c; + (this || _global$6$1).words[i + 1]++; } } - return r; - } - - BN.prototype._parseBase = function _parseBase(number, base, start) { - // Initialize as zero - (this || _global$z).words = [0]; - (this || _global$z).length = 1; // Find length of limb in base - - for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { - limbLen++; - } + (this || _global$6$1).length = Math.max((this || _global$6$1).length, i + 1); + return this || _global$6$1; + }; // Subtract plain number `num` from `this` - limbLen--; - limbPow = limbPow / base | 0; - var total = number.length - start; - var mod = total % limbLen; - var end = Math.min(total, total - mod) + start; - var word = 0; - for (var i = start; i < end; i += limbLen) { - word = parseBase(number, i, i + limbLen, base); - this.imuln(limbPow); + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); - if ((this || _global$z).words[0] + word < 67108864) { - (this || _global$z).words[0] += word; - } else { - this._iaddn(word); - } + if ((this || _global$6$1).negative !== 0) { + (this || _global$6$1).negative = 0; + this.iaddn(num); + (this || _global$6$1).negative = 1; + return this || _global$6$1; } - if (mod !== 0) { - var pow = 1; - word = parseBase(number, i, number.length, base); - - for (i = 0; i < mod; i++) { - pow *= base; - } - - this.imuln(pow); + (this || _global$6$1).words[0] -= num; - if ((this || _global$z).words[0] + word < 67108864) { - (this || _global$z).words[0] += word; - } else { - this._iaddn(word); + if ((this || _global$6$1).length === 1 && (this || _global$6$1).words[0] < 0) { + (this || _global$6$1).words[0] = -(this || _global$6$1).words[0]; + (this || _global$6$1).negative = 1; + } else { + // Carry + for (var i = 0; i < (this || _global$6$1).length && (this || _global$6$1).words[i] < 0; i++) { + (this || _global$6$1).words[i] += 67108864; + (this || _global$6$1).words[i + 1] -= 1; } } - this.strip(); + return this.strip(); }; - BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$z).length); + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; - for (var i = 0; i < (this || _global$z).length; i++) { - dest.words[i] = (this || _global$z).words[i]; - } + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; - dest.length = (this || _global$z).length; - dest.negative = (this || _global$z).negative; - dest.red = (this || _global$z).red; + BN.prototype.iabs = function iabs() { + (this || _global$6$1).negative = 0; + return this || _global$6$1; }; - BN.prototype.clone = function clone() { - var r = new BN(null); - this.copy(r); - return r; + BN.prototype.abs = function abs() { + return this.clone().iabs(); }; - BN.prototype._expand = function _expand(size) { - while ((this || _global$z).length < size) { - (this || _global$z).words[(this || _global$z).length++] = 0; + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; + + this._expand(len); + + var w; + var carry = 0; + + for (i = 0; i < num.length; i++) { + w = ((this || _global$6$1).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$6$1).words[i + shift] = w & 67108863; } - return this || _global$z; - }; // Remove leading `0` from `this` - - - BN.prototype.strip = function strip() { - while ((this || _global$z).length > 1 && (this || _global$z).words[(this || _global$z).length - 1] === 0) { - (this || _global$z).length--; + for (; i < (this || _global$6$1).length - shift; i++) { + w = ((this || _global$6$1).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$6$1).words[i + shift] = w & 67108863; } - return this._normSign(); - }; + if (carry === 0) return this.strip(); // Subtraction overflow - BN.prototype._normSign = function _normSign() { - // -0 = 0 - if ((this || _global$z).length === 1 && (this || _global$z).words[0] === 0) { - (this || _global$z).negative = 0; + assert(carry === -1); + carry = 0; + + for (i = 0; i < (this || _global$6$1).length; i++) { + w = -((this || _global$6$1).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$6$1).words[i] = w & 67108863; } - return this || _global$z; + (this || _global$6$1).negative = 1; + return this.strip(); }; - BN.prototype.inspect = function inspect() { - return ((this || _global$z).red ? ""; - }; - /* - var zeros = []; - var groupSizes = []; - var groupBases = []; - var s = ''; - var i = -1; - while (++i < BN.wordSize) { - zeros[i] = s; - s += '0'; - } - groupSizes[0] = 0; - groupSizes[1] = 0; - groupBases[0] = 0; - groupBases[1] = 0; - var base = 2 - 1; - while (++base < 36 + 1) { - var groupSize = 0; - var groupBase = 1; - while (groupBase < (1 << BN.wordSize) / base) { - groupBase *= base; - groupSize += 1; - } - groupSizes[base] = groupSize; - groupBases[base] = groupBase; - } - */ + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$6$1).length - num.length; + var a = this.clone(); + var b = num; // Normalize + var bhi = b.words[b.length - 1] | 0; - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; - var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; - var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + var bhiBits = this._countBits(bhi); - BN.prototype.toString = function toString(base, padding) { - base = base || 10; - padding = padding | 0 || 1; - var out; + shift = 26 - bhiBits; - if (base === 16 || base === "hex") { - out = ""; - var off = 0; - var carry = 0; + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient - for (var i = 0; i < (this || _global$z).length; i++) { - var w = (this || _global$z).words[i]; - var word = ((w << off | carry) & 16777215).toString(16); - carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$z).length - 1) { - out = zeros[6 - word.length] + word + out; - } else { - out = word + out; - } + var m = a.length - b.length; + var q; - off += 2; + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); - if (off >= 26) { - off -= 26; - i--; - } + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; } + } - if (carry !== 0) { - out = carry.toString(16) + out; - } + var diff = a.clone()._ishlnsubmul(b, 1, m); - while (out.length % padding !== 0) { - out = "0" + out; - } + if (diff.negative === 0) { + a = diff; - if ((this || _global$z).negative !== 0) { - out = "-" + out; + if (q) { + q.words[m] = 1; } - - return out; } - if (base === (base | 0) && base >= 2 && base <= 36) { - // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) - var groupBase = groupBases[base]; - out = ""; - var c = this.clone(); - c.negative = 0; + qj = Math.min(qj / bhi | 0, 67108863); - while (!c.isZero()) { - var r = c.modn(groupBase).toString(base); - c = c.idivn(groupBase); + a._ishlnsubmul(b, qj, j); - if (!c.isZero()) { - out = zeros[groupSize - r.length] + r + out; - } else { - out = r + out; - } - } + while (a.negative !== 0) { + qj--; + a.negative = 0; - if (this.isZero()) { - out = "0" + out; - } + a._ishlnsubmul(b, 1, j); - while (out.length % padding !== 0) { - out = "0" + out; + if (!a.isZero()) { + a.negative ^= 1; + } } - if ((this || _global$z).negative !== 0) { - out = "-" + out; + if (q) { + q.words[j] = qj; } - - return out; } - assert(false, "Base should be between 2 and 36"); - }; + if (q) { + q.strip(); + } - BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$z).words[0]; + a.strip(); // Denormalize - if ((this || _global$z).length === 2) { - ret += (this || _global$z).words[1] * 67108864; - } else if ((this || _global$z).length === 3 && (this || _global$z).words[2] === 1) { - // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$z).words[1] * 67108864; - } else if ((this || _global$z).length > 2) { - assert(false, "Number can only safely store up to 53 bits"); + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); } - return (this || _global$z).negative !== 0 ? -ret : ret; - }; + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested - BN.prototype.toJSON = function toJSON() { - return this.toString(16); - }; - BN.prototype.toBuffer = function toBuffer(endian, length) { - assert(typeof Buffer !== "undefined"); - return this.toArrayLike(Buffer, endian, length); - }; + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); - BN.prototype.toArray = function toArray(endian, length) { - return this.toArrayLike(Array, endian, length); - }; + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { - var byteLength = this.byteLength(); - var reqLength = length || Math.max(1, byteLength); - assert(byteLength <= reqLength, "byte array longer than desired length"); - assert(reqLength > 0, "Requested array length <= 0"); - this.strip(); - var littleEndian = endian === "le"; - var res = new ArrayType(reqLength); - var b, i; - var q = this.clone(); + var div, mod, res; - if (!littleEndian) { - // Assume big-endian - for (i = 0; i < reqLength - byteLength; i++) { - res[i] = 0; - } + if ((this || _global$6$1).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); - for (i = 0; !q.isZero(); i++) { - b = q.andln(255); - q.iushrn(8); - res[reqLength - i - 1] = b; - } - } else { - for (i = 0; !q.isZero(); i++) { - b = q.andln(255); - q.iushrn(8); - res[i] = b; + if (mode !== "mod") { + div = res.div.neg(); } - for (; i < reqLength; i++) { - res[i] = 0; + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.iadd(num); + } } - } - return res; - }; + return { + div: div, + mod: mod + }; + } - if (Math.clz32) { - BN.prototype._countBits = function _countBits(w) { - return 32 - Math.clz32(w); - }; - } else { - BN.prototype._countBits = function _countBits(w) { - var t = w; - var r = 0; + if ((this || _global$6$1).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); - if (t >= 4096) { - r += 13; - t >>>= 13; + if (mode !== "mod") { + div = res.div.neg(); } - if (t >= 64) { - r += 7; - t >>>= 7; - } + return { + div: div, + mod: res.mod + }; + } - if (t >= 8) { - r += 4; - t >>>= 4; - } + if (((this || _global$6$1).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); - if (t >= 2) { - r += 2; - t >>>= 2; + if (mode !== "div") { + mod = res.mod.neg(); + + if (positive && mod.negative !== 0) { + mod.isub(num); + } } - return r + t; - }; - } + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value - BN.prototype._zeroBits = function _zeroBits(w) { - // Short-cut - if (w === 0) return 26; - var t = w; - var r = 0; - if ((t & 8191) === 0) { - r += 13; - t >>>= 13; - } + if (num.length > (this || _global$6$1).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$6$1 + }; + } // Very short reduction - if ((t & 127) === 0) { - r += 7; - t >>>= 7; - } - if ((t & 15) === 0) { - r += 4; - t >>>= 4; - } + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } - if ((t & 3) === 0) { - r += 2; - t >>>= 2; - } + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } - if ((t & 1) === 0) { - r++; + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; } - return r; - }; // Return number of used bits in a BN + return this._wordDiv(num, mode); + }; // Find `this` / `num` - BN.prototype.bitLength = function bitLength() { - var w = (this || _global$z).words[(this || _global$z).length - 1]; + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` - var hi = this._countBits(w); - return ((this || _global$z).length - 1) * 26 + hi; + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; }; - function toBitArray(num) { - var w = new Array(num.bitLength()); + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) - for (var bit = 0; bit < w.length; bit++) { - var off = bit / 26 | 0; - var wbit = bit % 26; - w[bit] = (num.words[off] & 1 << wbit) >>> wbit; - } - return w; - } // Number of trailing zero bits + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down - BN.prototype.zeroBits = function zeroBits() { - if (this.isZero()) return 0; - var r = 0; + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up - for (var i = 0; i < (this || _global$z).length; i++) { - var b = this._zeroBits((this || _global$z).words[i]); + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; - r += b; - if (b !== 26) break; + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; + + for (var i = (this || _global$6$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$6$1).words[i] | 0)) % num; } - return r; - }; + return acc; + }; // In-place division by number - BN.prototype.byteLength = function byteLength() { - return Math.ceil(this.bitLength() / 8); - }; - BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$z).negative !== 0) { - return this.abs().inotn(width).iaddn(1); + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; + + for (var i = (this || _global$6$1).length - 1; i >= 0; i--) { + var w = ((this || _global$6$1).words[i] | 0) + carry * 67108864; + (this || _global$6$1).words[i] = w / num | 0; + carry = w % num; } - return this.clone(); + return this.strip(); }; - BN.prototype.fromTwos = function fromTwos(width) { - if (this.testn(width - 1)) { - return this.notn(width).iaddn(1).ineg(); - } - - return this.clone(); + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); }; - BN.prototype.isNeg = function isNeg() { - return (this || _global$z).negative !== 0; - }; // Return negative clone of `this` + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$6$1; + var y = p.clone(); + + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x - BN.prototype.neg = function neg() { - return this.clone().ineg(); - }; + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y - BN.prototype.ineg = function ineg() { - if (!this.isZero()) { - (this || _global$z).negative ^= 1; + var C = new BN(0); + var D = new BN(1); + var g = 0; + + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; } - return this || _global$z; - }; // Or `num` with `this` in-place + var yp = y.clone(); + var xp = x.clone(); + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - BN.prototype.iuor = function iuor(num) { - while ((this || _global$z).length < num.length) { - (this || _global$z).words[(this || _global$z).length++] = 0; - } + if (i > 0) { + x.iushrn(i); - for (var i = 0; i < num.length; i++) { - (this || _global$z).words[i] = (this || _global$z).words[i] | num.words[i]; - } + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } - return this.strip(); - }; + A.iushrn(1); + B.iushrn(1); + } + } - BN.prototype.ior = function ior(num) { - assert(((this || _global$z).negative | num.negative) === 0); - return this.iuor(num); - }; // Or `num` with `this` + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + if (j > 0) { + y.iushrn(j); - BN.prototype.or = function or(num) { - if ((this || _global$z).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$z); - }; + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } - BN.prototype.uor = function uor(num) { - if ((this || _global$z).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$z); - }; // And `num` with `this` in-place + C.iushrn(1); + D.iushrn(1); + } + } + + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed - BN.prototype.iuand = function iuand(num) { - // b = min-length(num, this) - var b; - if ((this || _global$z).length > num.length) { - b = num; - } else { - b = this || _global$z; - } + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$6$1; + var b = p.clone(); - for (var i = 0; i < b.length; i++) { - (this || _global$z).words[i] = (this || _global$z).words[i] & num.words[i]; + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); } - (this || _global$z).length = b.length; - return this.strip(); - }; + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); - BN.prototype.iand = function iand(num) { - assert(((this || _global$z).negative | num.negative) === 0); - return this.iuand(num); - }; // And `num` with `this` + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + if (i > 0) { + a.iushrn(i); - BN.prototype.and = function and(num) { - if ((this || _global$z).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$z); - }; + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } - BN.prototype.uand = function uand(num) { - if ((this || _global$z).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$z); - }; // Xor `num` with `this` in-place + x1.iushrn(1); + } + } + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - BN.prototype.iuxor = function iuxor(num) { - // a.length > b.length - var a; - var b; + if (j > 0) { + b.iushrn(j); - if ((this || _global$z).length > num.length) { - a = this || _global$z; - b = num; - } else { - a = num; - b = this || _global$z; - } + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } - for (var i = 0; i < b.length; i++) { - (this || _global$z).words[i] = a.words[i] ^ b.words[i]; - } + x2.iushrn(1); + } + } - if ((this || _global$z) !== a) { - for (; i < a.length; i++) { - (this || _global$z).words[i] = a.words[i]; + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); } } - (this || _global$z).length = a.length; - return this.strip(); - }; + var res; - BN.prototype.ixor = function ixor(num) { - assert(((this || _global$z).negative | num.negative) === 0); - return this.iuxor(num); - }; // Xor `num` with `this` + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + if (res.cmpn(0) < 0) { + res.iadd(p); + } - BN.prototype.xor = function xor(num) { - if ((this || _global$z).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$z); + return res; }; - BN.prototype.uxor = function uxor(num) { - if ((this || _global$z).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$z); - }; // Not ``this`` with ``width`` bitwidth - + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two - BN.prototype.inotn = function inotn(width) { - assert(typeof width === "number" && width >= 0); - var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } - this._expand(bytesNeeded); + do { + while (a.isEven()) { + a.iushrn(1); + } - if (bitsLeft > 0) { - bytesNeeded--; - } // Handle complete words + while (b.isEven()) { + b.iushrn(1); + } + var r = a.cmp(b); - for (var i = 0; i < bytesNeeded; i++) { - (this || _global$z).words[i] = ~(this || _global$z).words[i] & 67108863; - } // Handle the residue + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + a.isub(b); + } while (true); - if (bitsLeft > 0) { - (this || _global$z).words[i] = ~(this || _global$z).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes + return b.iushln(shift); + }; // Invert number in the field F(num) - return this.strip(); + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); }; - BN.prototype.notn = function notn(width) { - return this.clone().inotn(width); - }; // Set `bit` of `this` - - - BN.prototype.setn = function setn(bit, val) { - assert(typeof bit === "number" && bit >= 0); - var off = bit / 26 | 0; - var wbit = bit % 26; - - this._expand(off + 1); - - if (val) { - (this || _global$z).words[off] = (this || _global$z).words[off] | 1 << wbit; - } else { - (this || _global$z).words[off] = (this || _global$z).words[off] & ~(1 << wbit); - } + BN.prototype.isEven = function isEven() { + return ((this || _global$6$1).words[0] & 1) === 0; + }; - return this.strip(); - }; // Add `num` to `this` in-place + BN.prototype.isOdd = function isOdd() { + return ((this || _global$6$1).words[0] & 1) === 1; + }; // And first word and num - BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + BN.prototype.andln = function andln(num) { + return (this || _global$6$1).words[0] & num; + }; // Increment at the bit position in-line - if ((this || _global$z).negative !== 0 && num.negative === 0) { - (this || _global$z).negative = 0; - r = this.isub(num); - (this || _global$z).negative ^= 1; - return this._normSign(); // positive + negative - } else if ((this || _global$z).negative === 0 && num.negative !== 0) { - num.negative = 0; - r = this.isub(num); - num.negative = 1; - return r._normSign(); - } // a.length > b.length + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words - var a, b; + if ((this || _global$6$1).length <= s) { + this._expand(s + 1); - if ((this || _global$z).length > num.length) { - a = this || _global$z; - b = num; - } else { - a = num; - b = this || _global$z; - } + (this || _global$6$1).words[s] |= q; + return this || _global$6$1; + } // Add bit and propagate, if needed - var carry = 0; - for (var i = 0; i < b.length; i++) { - r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$z).words[i] = r & 67108863; - carry = r >>> 26; - } + var carry = q; - for (; carry !== 0 && i < a.length; i++) { - r = (a.words[i] | 0) + carry; - (this || _global$z).words[i] = r & 67108863; - carry = r >>> 26; + for (var i = s; carry !== 0 && i < (this || _global$6$1).length; i++) { + var w = (this || _global$6$1).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$6$1).words[i] = w; } - (this || _global$z).length = a.length; - if (carry !== 0) { - (this || _global$z).words[(this || _global$z).length] = carry; - (this || _global$z).length++; // Copy the rest of the words - } else if (a !== (this || _global$z)) { - for (; i < a.length; i++) { - (this || _global$z).words[i] = a.words[i]; - } + (this || _global$6$1).words[i] = carry; + (this || _global$6$1).length++; } - return this || _global$z; - }; // Add `num` to `this` + return this || _global$6$1; + }; + BN.prototype.isZero = function isZero() { + return (this || _global$6$1).length === 1 && (this || _global$6$1).words[0] === 0; + }; - BN.prototype.add = function add(num) { + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$6$1).negative !== 0 && !negative) return -1; + if ((this || _global$6$1).negative === 0 && negative) return 1; + this.strip(); var res; - if (num.negative !== 0 && (this || _global$z).negative === 0) { - num.negative = 0; - res = this.sub(num); - num.negative ^= 1; - return res; - } else if (num.negative === 0 && (this || _global$z).negative !== 0) { - (this || _global$z).negative = 0; - res = num.sub(this || _global$z); - (this || _global$z).negative = 1; - return res; - } - - if ((this || _global$z).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$z); - }; // Subtract `num` from `this` in-place - - - BN.prototype.isub = function isub(num) { - // this - (-num) = this + num - if (num.negative !== 0) { - num.negative = 0; - var r = this.iadd(num); - num.negative = 1; - return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$z).negative !== 0) { - (this || _global$z).negative = 0; - this.iadd(num); - (this || _global$z).negative = 1; - return this._normSign(); - } // At this point both numbers are positive - - - var cmp = this.cmp(num); // Optimization - zeroify - - if (cmp === 0) { - (this || _global$z).negative = 0; - (this || _global$z).length = 1; - (this || _global$z).words[0] = 0; - return this || _global$z; - } // a > b + if ((this || _global$6$1).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$6$1).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } - var a, b; + if ((this || _global$6$1).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` - if (cmp > 0) { - a = this || _global$z; - b = num; - } else { - a = num; - b = this || _global$z; - } - var carry = 0; + BN.prototype.cmp = function cmp(num) { + if ((this || _global$6$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$6$1).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$6$1).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison - for (var i = 0; i < b.length; i++) { - r = (a.words[i] | 0) - (b.words[i] | 0) + carry; - carry = r >> 26; - (this || _global$z).words[i] = r & 67108863; - } - for (; carry !== 0 && i < a.length; i++) { - r = (a.words[i] | 0) + carry; - carry = r >> 26; - (this || _global$z).words[i] = r & 67108863; - } // Copy rest of the words + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$6$1).length > num.length) return 1; + if ((this || _global$6$1).length < num.length) return -1; + var res = 0; + for (var i = (this || _global$6$1).length - 1; i >= 0; i--) { + var a = (this || _global$6$1).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; - if (carry === 0 && i < a.length && a !== (this || _global$z)) { - for (; i < a.length; i++) { - (this || _global$z).words[i] = a.words[i]; + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; } - } - (this || _global$z).length = Math.max((this || _global$z).length, i); - - if (a !== (this || _global$z)) { - (this || _global$z).negative = 1; + break; } - return this.strip(); - }; // Subtract `num` from `this` - + return res; + }; - BN.prototype.sub = function sub(num) { - return this.clone().isub(num); + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; }; - function smallMulTo(self, num, out) { - out.negative = num.negative ^ self.negative; - var len = self.length + num.length | 0; - out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; - var a = self.words[0] | 0; - var b = num.words[0] | 0; - var r = a * b; - var lo = r & 67108863; - var carry = r / 67108864 | 0; - out.words[0] = lo; + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; - for (var k = 1; k < len; k++) { - // Sum all words with the same `i + j = k` and accumulate `ncarry`, - // note that ncarry could be >= 0x3ffffff - var ncarry = carry >>> 26; - var rword = carry & 67108863; - var maxJ = Math.min(k, num.length - 1); + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { - var i = k - j | 0; - a = self.words[i] | 0; - b = num.words[j] | 0; - r = a * b + rword; - ncarry += r / 67108864 | 0; - rword = r & 67108863; - } + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; - out.words[k] = rword | 0; - carry = ncarry | 0; - } + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; - if (carry !== 0) { - out.words[k] = carry | 0; - } else { - out.length--; - } + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; - return out.strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need - // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit - // multiplication (like elliptic secp256k1). + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; - var comb10MulTo = function comb10MulTo(self, num, out) { - var a = self.words; - var b = num.words; - var o = out.words; - var c = 0; - var lo; - var mid; - var hi; - var a0 = a[0] | 0; - var al0 = a0 & 8191; - var ah0 = a0 >>> 13; - var a1 = a[1] | 0; - var al1 = a1 & 8191; - var ah1 = a1 >>> 13; - var a2 = a[2] | 0; - var al2 = a2 & 8191; - var ah2 = a2 >>> 13; - var a3 = a[3] | 0; - var al3 = a3 & 8191; - var ah3 = a3 >>> 13; - var a4 = a[4] | 0; - var al4 = a4 & 8191; - var ah4 = a4 >>> 13; - var a5 = a[5] | 0; - var al5 = a5 & 8191; - var ah5 = a5 >>> 13; - var a6 = a[6] | 0; - var al6 = a6 & 8191; - var ah6 = a6 >>> 13; - var a7 = a[7] | 0; - var al7 = a7 & 8191; - var ah7 = a7 >>> 13; - var a8 = a[8] | 0; - var al8 = a8 & 8191; - var ah8 = a8 >>> 13; - var a9 = a[9] | 0; - var al9 = a9 & 8191; - var ah9 = a9 >>> 13; - var b0 = b[0] | 0; - var bl0 = b0 & 8191; - var bh0 = b0 >>> 13; - var b1 = b[1] | 0; - var bl1 = b1 & 8191; - var bh1 = b1 >>> 13; - var b2 = b[2] | 0; - var bl2 = b2 & 8191; - var bh2 = b2 >>> 13; - var b3 = b[3] | 0; - var bl3 = b3 & 8191; - var bh3 = b3 >>> 13; - var b4 = b[4] | 0; - var bl4 = b4 & 8191; - var bh4 = b4 >>> 13; - var b5 = b[5] | 0; - var bl5 = b5 & 8191; - var bh5 = b5 >>> 13; - var b6 = b[6] | 0; - var bl6 = b6 & 8191; - var bh6 = b6 >>> 13; - var b7 = b[7] | 0; - var bl7 = b7 & 8191; - var bh7 = b7 >>> 13; - var b8 = b[8] | 0; - var bl8 = b8 & 8191; - var bh8 = b8 >>> 13; - var b9 = b[9] | 0; - var bl9 = b9 & 8191; - var bh9 = b9 >>> 13; - out.negative = self.negative ^ num.negative; - out.length = 19; - /* k = 0 */ + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // - lo = Math.imul(al0, bl0); - mid = Math.imul(al0, bh0); - mid = mid + Math.imul(ah0, bl0) | 0; - hi = Math.imul(ah0, bh0); - var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; - w0 &= 67108863; - /* k = 1 */ - lo = Math.imul(al1, bl0); - mid = Math.imul(al1, bh0); - mid = mid + Math.imul(ah1, bl0) | 0; - hi = Math.imul(ah1, bh0); - lo = lo + Math.imul(al0, bl1) | 0; - mid = mid + Math.imul(al0, bh1) | 0; - mid = mid + Math.imul(ah0, bl1) | 0; - hi = hi + Math.imul(ah0, bh1) | 0; - var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; - w1 &= 67108863; - /* k = 2 */ + BN.red = function red(num) { + return new Red(num); + }; - lo = Math.imul(al2, bl0); - mid = Math.imul(al2, bh0); - mid = mid + Math.imul(ah2, bl0) | 0; - hi = Math.imul(ah2, bh0); - lo = lo + Math.imul(al1, bl1) | 0; - mid = mid + Math.imul(al1, bh1) | 0; - mid = mid + Math.imul(ah1, bl1) | 0; - hi = hi + Math.imul(ah1, bh1) | 0; - lo = lo + Math.imul(al0, bl2) | 0; - mid = mid + Math.imul(al0, bh2) | 0; - mid = mid + Math.imul(ah0, bl2) | 0; - hi = hi + Math.imul(ah0, bh2) | 0; - var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; - w2 &= 67108863; - /* k = 3 */ + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$6$1).red, "Already a number in reduction context"); + assert((this || _global$6$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$6$1)._forceRed(ctx); + }; - lo = Math.imul(al3, bl0); - mid = Math.imul(al3, bh0); - mid = mid + Math.imul(ah3, bl0) | 0; - hi = Math.imul(ah3, bh0); - lo = lo + Math.imul(al2, bl1) | 0; - mid = mid + Math.imul(al2, bh1) | 0; - mid = mid + Math.imul(ah2, bl1) | 0; - hi = hi + Math.imul(ah2, bh1) | 0; - lo = lo + Math.imul(al1, bl2) | 0; - mid = mid + Math.imul(al1, bh2) | 0; - mid = mid + Math.imul(ah1, bl2) | 0; - hi = hi + Math.imul(ah1, bh2) | 0; - lo = lo + Math.imul(al0, bl3) | 0; - mid = mid + Math.imul(al0, bh3) | 0; - mid = mid + Math.imul(ah0, bl3) | 0; - hi = hi + Math.imul(ah0, bh3) | 0; - var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; - w3 &= 67108863; - /* k = 4 */ + BN.prototype.fromRed = function fromRed() { + assert((this || _global$6$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$6$1).red.convertFrom(this || _global$6$1); + }; - lo = Math.imul(al4, bl0); - mid = Math.imul(al4, bh0); - mid = mid + Math.imul(ah4, bl0) | 0; - hi = Math.imul(ah4, bh0); - lo = lo + Math.imul(al3, bl1) | 0; - mid = mid + Math.imul(al3, bh1) | 0; - mid = mid + Math.imul(ah3, bl1) | 0; - hi = hi + Math.imul(ah3, bh1) | 0; - lo = lo + Math.imul(al2, bl2) | 0; - mid = mid + Math.imul(al2, bh2) | 0; - mid = mid + Math.imul(ah2, bl2) | 0; - hi = hi + Math.imul(ah2, bh2) | 0; - lo = lo + Math.imul(al1, bl3) | 0; - mid = mid + Math.imul(al1, bh3) | 0; - mid = mid + Math.imul(ah1, bl3) | 0; - hi = hi + Math.imul(ah1, bh3) | 0; - lo = lo + Math.imul(al0, bl4) | 0; - mid = mid + Math.imul(al0, bh4) | 0; - mid = mid + Math.imul(ah0, bl4) | 0; - hi = hi + Math.imul(ah0, bh4) | 0; - var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; - w4 &= 67108863; - /* k = 5 */ + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$6$1).red = ctx; + return this || _global$6$1; + }; - lo = Math.imul(al5, bl0); - mid = Math.imul(al5, bh0); - mid = mid + Math.imul(ah5, bl0) | 0; - hi = Math.imul(ah5, bh0); - lo = lo + Math.imul(al4, bl1) | 0; - mid = mid + Math.imul(al4, bh1) | 0; - mid = mid + Math.imul(ah4, bl1) | 0; - hi = hi + Math.imul(ah4, bh1) | 0; - lo = lo + Math.imul(al3, bl2) | 0; - mid = mid + Math.imul(al3, bh2) | 0; - mid = mid + Math.imul(ah3, bl2) | 0; - hi = hi + Math.imul(ah3, bh2) | 0; - lo = lo + Math.imul(al2, bl3) | 0; - mid = mid + Math.imul(al2, bh3) | 0; - mid = mid + Math.imul(ah2, bl3) | 0; - hi = hi + Math.imul(ah2, bh3) | 0; - lo = lo + Math.imul(al1, bl4) | 0; - mid = mid + Math.imul(al1, bh4) | 0; - mid = mid + Math.imul(ah1, bl4) | 0; - hi = hi + Math.imul(ah1, bh4) | 0; - lo = lo + Math.imul(al0, bl5) | 0; - mid = mid + Math.imul(al0, bh5) | 0; - mid = mid + Math.imul(ah0, bl5) | 0; - hi = hi + Math.imul(ah0, bh5) | 0; - var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; - w5 &= 67108863; - /* k = 6 */ + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$6$1).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; - lo = Math.imul(al6, bl0); - mid = Math.imul(al6, bh0); - mid = mid + Math.imul(ah6, bl0) | 0; - hi = Math.imul(ah6, bh0); - lo = lo + Math.imul(al5, bl1) | 0; - mid = mid + Math.imul(al5, bh1) | 0; - mid = mid + Math.imul(ah5, bl1) | 0; - hi = hi + Math.imul(ah5, bh1) | 0; - lo = lo + Math.imul(al4, bl2) | 0; - mid = mid + Math.imul(al4, bh2) | 0; - mid = mid + Math.imul(ah4, bl2) | 0; - hi = hi + Math.imul(ah4, bh2) | 0; - lo = lo + Math.imul(al3, bl3) | 0; - mid = mid + Math.imul(al3, bh3) | 0; - mid = mid + Math.imul(ah3, bl3) | 0; - hi = hi + Math.imul(ah3, bh3) | 0; - lo = lo + Math.imul(al2, bl4) | 0; - mid = mid + Math.imul(al2, bh4) | 0; - mid = mid + Math.imul(ah2, bl4) | 0; - hi = hi + Math.imul(ah2, bh4) | 0; - lo = lo + Math.imul(al1, bl5) | 0; - mid = mid + Math.imul(al1, bh5) | 0; - mid = mid + Math.imul(ah1, bl5) | 0; - hi = hi + Math.imul(ah1, bh5) | 0; - lo = lo + Math.imul(al0, bl6) | 0; - mid = mid + Math.imul(al0, bh6) | 0; - mid = mid + Math.imul(ah0, bl6) | 0; - hi = hi + Math.imul(ah0, bh6) | 0; - var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; - w6 &= 67108863; - /* k = 7 */ + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$6$1).red, "redAdd works only with red numbers"); + return (this || _global$6$1).red.add(this || _global$6$1, num); + }; - lo = Math.imul(al7, bl0); - mid = Math.imul(al7, bh0); - mid = mid + Math.imul(ah7, bl0) | 0; - hi = Math.imul(ah7, bh0); - lo = lo + Math.imul(al6, bl1) | 0; - mid = mid + Math.imul(al6, bh1) | 0; - mid = mid + Math.imul(ah6, bl1) | 0; - hi = hi + Math.imul(ah6, bh1) | 0; - lo = lo + Math.imul(al5, bl2) | 0; - mid = mid + Math.imul(al5, bh2) | 0; - mid = mid + Math.imul(ah5, bl2) | 0; - hi = hi + Math.imul(ah5, bh2) | 0; - lo = lo + Math.imul(al4, bl3) | 0; - mid = mid + Math.imul(al4, bh3) | 0; - mid = mid + Math.imul(ah4, bl3) | 0; - hi = hi + Math.imul(ah4, bh3) | 0; - lo = lo + Math.imul(al3, bl4) | 0; - mid = mid + Math.imul(al3, bh4) | 0; - mid = mid + Math.imul(ah3, bl4) | 0; - hi = hi + Math.imul(ah3, bh4) | 0; - lo = lo + Math.imul(al2, bl5) | 0; - mid = mid + Math.imul(al2, bh5) | 0; - mid = mid + Math.imul(ah2, bl5) | 0; - hi = hi + Math.imul(ah2, bh5) | 0; - lo = lo + Math.imul(al1, bl6) | 0; - mid = mid + Math.imul(al1, bh6) | 0; - mid = mid + Math.imul(ah1, bl6) | 0; - hi = hi + Math.imul(ah1, bh6) | 0; - lo = lo + Math.imul(al0, bl7) | 0; - mid = mid + Math.imul(al0, bh7) | 0; - mid = mid + Math.imul(ah0, bl7) | 0; - hi = hi + Math.imul(ah0, bh7) | 0; - var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; - w7 &= 67108863; - /* k = 8 */ + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$6$1).red, "redIAdd works only with red numbers"); + return (this || _global$6$1).red.iadd(this || _global$6$1, num); + }; - lo = Math.imul(al8, bl0); - mid = Math.imul(al8, bh0); - mid = mid + Math.imul(ah8, bl0) | 0; - hi = Math.imul(ah8, bh0); - lo = lo + Math.imul(al7, bl1) | 0; - mid = mid + Math.imul(al7, bh1) | 0; - mid = mid + Math.imul(ah7, bl1) | 0; - hi = hi + Math.imul(ah7, bh1) | 0; - lo = lo + Math.imul(al6, bl2) | 0; - mid = mid + Math.imul(al6, bh2) | 0; - mid = mid + Math.imul(ah6, bl2) | 0; - hi = hi + Math.imul(ah6, bh2) | 0; - lo = lo + Math.imul(al5, bl3) | 0; - mid = mid + Math.imul(al5, bh3) | 0; - mid = mid + Math.imul(ah5, bl3) | 0; - hi = hi + Math.imul(ah5, bh3) | 0; - lo = lo + Math.imul(al4, bl4) | 0; - mid = mid + Math.imul(al4, bh4) | 0; - mid = mid + Math.imul(ah4, bl4) | 0; - hi = hi + Math.imul(ah4, bh4) | 0; - lo = lo + Math.imul(al3, bl5) | 0; - mid = mid + Math.imul(al3, bh5) | 0; - mid = mid + Math.imul(ah3, bl5) | 0; - hi = hi + Math.imul(ah3, bh5) | 0; - lo = lo + Math.imul(al2, bl6) | 0; - mid = mid + Math.imul(al2, bh6) | 0; - mid = mid + Math.imul(ah2, bl6) | 0; - hi = hi + Math.imul(ah2, bh6) | 0; - lo = lo + Math.imul(al1, bl7) | 0; - mid = mid + Math.imul(al1, bh7) | 0; - mid = mid + Math.imul(ah1, bl7) | 0; - hi = hi + Math.imul(ah1, bh7) | 0; - lo = lo + Math.imul(al0, bl8) | 0; - mid = mid + Math.imul(al0, bh8) | 0; - mid = mid + Math.imul(ah0, bl8) | 0; - hi = hi + Math.imul(ah0, bh8) | 0; - var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; - w8 &= 67108863; - /* k = 9 */ + BN.prototype.redSub = function redSub(num) { + assert((this || _global$6$1).red, "redSub works only with red numbers"); + return (this || _global$6$1).red.sub(this || _global$6$1, num); + }; - lo = Math.imul(al9, bl0); - mid = Math.imul(al9, bh0); - mid = mid + Math.imul(ah9, bl0) | 0; - hi = Math.imul(ah9, bh0); - lo = lo + Math.imul(al8, bl1) | 0; - mid = mid + Math.imul(al8, bh1) | 0; - mid = mid + Math.imul(ah8, bl1) | 0; - hi = hi + Math.imul(ah8, bh1) | 0; - lo = lo + Math.imul(al7, bl2) | 0; - mid = mid + Math.imul(al7, bh2) | 0; - mid = mid + Math.imul(ah7, bl2) | 0; - hi = hi + Math.imul(ah7, bh2) | 0; - lo = lo + Math.imul(al6, bl3) | 0; - mid = mid + Math.imul(al6, bh3) | 0; - mid = mid + Math.imul(ah6, bl3) | 0; - hi = hi + Math.imul(ah6, bh3) | 0; - lo = lo + Math.imul(al5, bl4) | 0; - mid = mid + Math.imul(al5, bh4) | 0; - mid = mid + Math.imul(ah5, bl4) | 0; - hi = hi + Math.imul(ah5, bh4) | 0; - lo = lo + Math.imul(al4, bl5) | 0; - mid = mid + Math.imul(al4, bh5) | 0; - mid = mid + Math.imul(ah4, bl5) | 0; - hi = hi + Math.imul(ah4, bh5) | 0; - lo = lo + Math.imul(al3, bl6) | 0; - mid = mid + Math.imul(al3, bh6) | 0; - mid = mid + Math.imul(ah3, bl6) | 0; - hi = hi + Math.imul(ah3, bh6) | 0; - lo = lo + Math.imul(al2, bl7) | 0; - mid = mid + Math.imul(al2, bh7) | 0; - mid = mid + Math.imul(ah2, bl7) | 0; - hi = hi + Math.imul(ah2, bh7) | 0; - lo = lo + Math.imul(al1, bl8) | 0; - mid = mid + Math.imul(al1, bh8) | 0; - mid = mid + Math.imul(ah1, bl8) | 0; - hi = hi + Math.imul(ah1, bh8) | 0; - lo = lo + Math.imul(al0, bl9) | 0; - mid = mid + Math.imul(al0, bh9) | 0; - mid = mid + Math.imul(ah0, bl9) | 0; - hi = hi + Math.imul(ah0, bh9) | 0; - var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; - w9 &= 67108863; - /* k = 10 */ + BN.prototype.redISub = function redISub(num) { + assert((this || _global$6$1).red, "redISub works only with red numbers"); + return (this || _global$6$1).red.isub(this || _global$6$1, num); + }; - lo = Math.imul(al9, bl1); - mid = Math.imul(al9, bh1); - mid = mid + Math.imul(ah9, bl1) | 0; - hi = Math.imul(ah9, bh1); - lo = lo + Math.imul(al8, bl2) | 0; - mid = mid + Math.imul(al8, bh2) | 0; - mid = mid + Math.imul(ah8, bl2) | 0; - hi = hi + Math.imul(ah8, bh2) | 0; - lo = lo + Math.imul(al7, bl3) | 0; - mid = mid + Math.imul(al7, bh3) | 0; - mid = mid + Math.imul(ah7, bl3) | 0; - hi = hi + Math.imul(ah7, bh3) | 0; - lo = lo + Math.imul(al6, bl4) | 0; - mid = mid + Math.imul(al6, bh4) | 0; - mid = mid + Math.imul(ah6, bl4) | 0; - hi = hi + Math.imul(ah6, bh4) | 0; - lo = lo + Math.imul(al5, bl5) | 0; - mid = mid + Math.imul(al5, bh5) | 0; - mid = mid + Math.imul(ah5, bl5) | 0; - hi = hi + Math.imul(ah5, bh5) | 0; - lo = lo + Math.imul(al4, bl6) | 0; - mid = mid + Math.imul(al4, bh6) | 0; - mid = mid + Math.imul(ah4, bl6) | 0; - hi = hi + Math.imul(ah4, bh6) | 0; - lo = lo + Math.imul(al3, bl7) | 0; - mid = mid + Math.imul(al3, bh7) | 0; - mid = mid + Math.imul(ah3, bl7) | 0; - hi = hi + Math.imul(ah3, bh7) | 0; - lo = lo + Math.imul(al2, bl8) | 0; - mid = mid + Math.imul(al2, bh8) | 0; - mid = mid + Math.imul(ah2, bl8) | 0; - hi = hi + Math.imul(ah2, bh8) | 0; - lo = lo + Math.imul(al1, bl9) | 0; - mid = mid + Math.imul(al1, bh9) | 0; - mid = mid + Math.imul(ah1, bl9) | 0; - hi = hi + Math.imul(ah1, bh9) | 0; - var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; - w10 &= 67108863; - /* k = 11 */ + BN.prototype.redShl = function redShl(num) { + assert((this || _global$6$1).red, "redShl works only with red numbers"); + return (this || _global$6$1).red.shl(this || _global$6$1, num); + }; - lo = Math.imul(al9, bl2); - mid = Math.imul(al9, bh2); - mid = mid + Math.imul(ah9, bl2) | 0; - hi = Math.imul(ah9, bh2); - lo = lo + Math.imul(al8, bl3) | 0; - mid = mid + Math.imul(al8, bh3) | 0; - mid = mid + Math.imul(ah8, bl3) | 0; - hi = hi + Math.imul(ah8, bh3) | 0; - lo = lo + Math.imul(al7, bl4) | 0; - mid = mid + Math.imul(al7, bh4) | 0; - mid = mid + Math.imul(ah7, bl4) | 0; - hi = hi + Math.imul(ah7, bh4) | 0; - lo = lo + Math.imul(al6, bl5) | 0; - mid = mid + Math.imul(al6, bh5) | 0; - mid = mid + Math.imul(ah6, bl5) | 0; - hi = hi + Math.imul(ah6, bh5) | 0; - lo = lo + Math.imul(al5, bl6) | 0; - mid = mid + Math.imul(al5, bh6) | 0; - mid = mid + Math.imul(ah5, bl6) | 0; - hi = hi + Math.imul(ah5, bh6) | 0; - lo = lo + Math.imul(al4, bl7) | 0; - mid = mid + Math.imul(al4, bh7) | 0; - mid = mid + Math.imul(ah4, bl7) | 0; - hi = hi + Math.imul(ah4, bh7) | 0; - lo = lo + Math.imul(al3, bl8) | 0; - mid = mid + Math.imul(al3, bh8) | 0; - mid = mid + Math.imul(ah3, bl8) | 0; - hi = hi + Math.imul(ah3, bh8) | 0; - lo = lo + Math.imul(al2, bl9) | 0; - mid = mid + Math.imul(al2, bh9) | 0; - mid = mid + Math.imul(ah2, bl9) | 0; - hi = hi + Math.imul(ah2, bh9) | 0; - var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; - w11 &= 67108863; - /* k = 12 */ + BN.prototype.redMul = function redMul(num) { + assert((this || _global$6$1).red, "redMul works only with red numbers"); - lo = Math.imul(al9, bl3); - mid = Math.imul(al9, bh3); - mid = mid + Math.imul(ah9, bl3) | 0; - hi = Math.imul(ah9, bh3); - lo = lo + Math.imul(al8, bl4) | 0; - mid = mid + Math.imul(al8, bh4) | 0; - mid = mid + Math.imul(ah8, bl4) | 0; - hi = hi + Math.imul(ah8, bh4) | 0; - lo = lo + Math.imul(al7, bl5) | 0; - mid = mid + Math.imul(al7, bh5) | 0; - mid = mid + Math.imul(ah7, bl5) | 0; - hi = hi + Math.imul(ah7, bh5) | 0; - lo = lo + Math.imul(al6, bl6) | 0; - mid = mid + Math.imul(al6, bh6) | 0; - mid = mid + Math.imul(ah6, bl6) | 0; - hi = hi + Math.imul(ah6, bh6) | 0; - lo = lo + Math.imul(al5, bl7) | 0; - mid = mid + Math.imul(al5, bh7) | 0; - mid = mid + Math.imul(ah5, bl7) | 0; - hi = hi + Math.imul(ah5, bh7) | 0; - lo = lo + Math.imul(al4, bl8) | 0; - mid = mid + Math.imul(al4, bh8) | 0; - mid = mid + Math.imul(ah4, bl8) | 0; - hi = hi + Math.imul(ah4, bh8) | 0; - lo = lo + Math.imul(al3, bl9) | 0; - mid = mid + Math.imul(al3, bh9) | 0; - mid = mid + Math.imul(ah3, bl9) | 0; - hi = hi + Math.imul(ah3, bh9) | 0; - var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; - w12 &= 67108863; - /* k = 13 */ + (this || _global$6$1).red._verify2(this || _global$6$1, num); - lo = Math.imul(al9, bl4); - mid = Math.imul(al9, bh4); - mid = mid + Math.imul(ah9, bl4) | 0; - hi = Math.imul(ah9, bh4); - lo = lo + Math.imul(al8, bl5) | 0; - mid = mid + Math.imul(al8, bh5) | 0; - mid = mid + Math.imul(ah8, bl5) | 0; - hi = hi + Math.imul(ah8, bh5) | 0; - lo = lo + Math.imul(al7, bl6) | 0; - mid = mid + Math.imul(al7, bh6) | 0; - mid = mid + Math.imul(ah7, bl6) | 0; - hi = hi + Math.imul(ah7, bh6) | 0; - lo = lo + Math.imul(al6, bl7) | 0; - mid = mid + Math.imul(al6, bh7) | 0; - mid = mid + Math.imul(ah6, bl7) | 0; - hi = hi + Math.imul(ah6, bh7) | 0; - lo = lo + Math.imul(al5, bl8) | 0; - mid = mid + Math.imul(al5, bh8) | 0; - mid = mid + Math.imul(ah5, bl8) | 0; - hi = hi + Math.imul(ah5, bh8) | 0; - lo = lo + Math.imul(al4, bl9) | 0; - mid = mid + Math.imul(al4, bh9) | 0; - mid = mid + Math.imul(ah4, bl9) | 0; - hi = hi + Math.imul(ah4, bh9) | 0; - var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; - w13 &= 67108863; - /* k = 14 */ + return (this || _global$6$1).red.mul(this || _global$6$1, num); + }; - lo = Math.imul(al9, bl5); - mid = Math.imul(al9, bh5); - mid = mid + Math.imul(ah9, bl5) | 0; - hi = Math.imul(ah9, bh5); - lo = lo + Math.imul(al8, bl6) | 0; - mid = mid + Math.imul(al8, bh6) | 0; - mid = mid + Math.imul(ah8, bl6) | 0; - hi = hi + Math.imul(ah8, bh6) | 0; - lo = lo + Math.imul(al7, bl7) | 0; - mid = mid + Math.imul(al7, bh7) | 0; - mid = mid + Math.imul(ah7, bl7) | 0; - hi = hi + Math.imul(ah7, bh7) | 0; - lo = lo + Math.imul(al6, bl8) | 0; - mid = mid + Math.imul(al6, bh8) | 0; - mid = mid + Math.imul(ah6, bl8) | 0; - hi = hi + Math.imul(ah6, bh8) | 0; - lo = lo + Math.imul(al5, bl9) | 0; - mid = mid + Math.imul(al5, bh9) | 0; - mid = mid + Math.imul(ah5, bl9) | 0; - hi = hi + Math.imul(ah5, bh9) | 0; - var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; - w14 &= 67108863; - /* k = 15 */ + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$6$1).red, "redMul works only with red numbers"); - lo = Math.imul(al9, bl6); - mid = Math.imul(al9, bh6); - mid = mid + Math.imul(ah9, bl6) | 0; - hi = Math.imul(ah9, bh6); - lo = lo + Math.imul(al8, bl7) | 0; - mid = mid + Math.imul(al8, bh7) | 0; - mid = mid + Math.imul(ah8, bl7) | 0; - hi = hi + Math.imul(ah8, bh7) | 0; - lo = lo + Math.imul(al7, bl8) | 0; - mid = mid + Math.imul(al7, bh8) | 0; - mid = mid + Math.imul(ah7, bl8) | 0; - hi = hi + Math.imul(ah7, bh8) | 0; - lo = lo + Math.imul(al6, bl9) | 0; - mid = mid + Math.imul(al6, bh9) | 0; - mid = mid + Math.imul(ah6, bl9) | 0; - hi = hi + Math.imul(ah6, bh9) | 0; - var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; - w15 &= 67108863; - /* k = 16 */ + (this || _global$6$1).red._verify2(this || _global$6$1, num); + + return (this || _global$6$1).red.imul(this || _global$6$1, num); + }; + + BN.prototype.redSqr = function redSqr() { + assert((this || _global$6$1).red, "redSqr works only with red numbers"); + + (this || _global$6$1).red._verify1(this || _global$6$1); + + return (this || _global$6$1).red.sqr(this || _global$6$1); + }; + + BN.prototype.redISqr = function redISqr() { + assert((this || _global$6$1).red, "redISqr works only with red numbers"); + + (this || _global$6$1).red._verify1(this || _global$6$1); + + return (this || _global$6$1).red.isqr(this || _global$6$1); + }; // Square root over p + + + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$6$1).red, "redSqrt works only with red numbers"); + + (this || _global$6$1).red._verify1(this || _global$6$1); - lo = Math.imul(al9, bl7); - mid = Math.imul(al9, bh7); - mid = mid + Math.imul(ah9, bl7) | 0; - hi = Math.imul(ah9, bh7); - lo = lo + Math.imul(al8, bl8) | 0; - mid = mid + Math.imul(al8, bh8) | 0; - mid = mid + Math.imul(ah8, bl8) | 0; - hi = hi + Math.imul(ah8, bh8) | 0; - lo = lo + Math.imul(al7, bl9) | 0; - mid = mid + Math.imul(al7, bh9) | 0; - mid = mid + Math.imul(ah7, bl9) | 0; - hi = hi + Math.imul(ah7, bh9) | 0; - var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; - w16 &= 67108863; - /* k = 17 */ + return (this || _global$6$1).red.sqrt(this || _global$6$1); + }; - lo = Math.imul(al9, bl8); - mid = Math.imul(al9, bh8); - mid = mid + Math.imul(ah9, bl8) | 0; - hi = Math.imul(ah9, bh8); - lo = lo + Math.imul(al8, bl9) | 0; - mid = mid + Math.imul(al8, bh9) | 0; - mid = mid + Math.imul(ah8, bl9) | 0; - hi = hi + Math.imul(ah8, bh9) | 0; - var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; - w17 &= 67108863; - /* k = 18 */ + BN.prototype.redInvm = function redInvm() { + assert((this || _global$6$1).red, "redInvm works only with red numbers"); - lo = Math.imul(al9, bl9); - mid = Math.imul(al9, bh9); - mid = mid + Math.imul(ah9, bl9) | 0; - hi = Math.imul(ah9, bh9); - var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; - w18 &= 67108863; - o[0] = w0; - o[1] = w1; - o[2] = w2; - o[3] = w3; - o[4] = w4; - o[5] = w5; - o[6] = w6; - o[7] = w7; - o[8] = w8; - o[9] = w9; - o[10] = w10; - o[11] = w11; - o[12] = w12; - o[13] = w13; - o[14] = w14; - o[15] = w15; - o[16] = w16; - o[17] = w17; - o[18] = w18; + (this || _global$6$1).red._verify1(this || _global$6$1); - if (c !== 0) { - o[19] = c; - out.length++; - } + return (this || _global$6$1).red.invm(this || _global$6$1); + }; // Return negative clone of `this` % `red modulo` - return out; - }; // Polyfill comb + BN.prototype.redNeg = function redNeg() { + assert((this || _global$6$1).red, "redNeg works only with red numbers"); - if (!Math.imul) { - comb10MulTo = smallMulTo; - } + (this || _global$6$1).red._verify1(this || _global$6$1); - function bigMulTo(self, num, out) { - out.negative = num.negative ^ self.negative; - out.length = self.length + num.length; - var carry = 0; - var hncarry = 0; + return (this || _global$6$1).red.neg(this || _global$6$1); + }; - for (var k = 0; k < out.length - 1; k++) { - // Sum all words with the same `i + j = k` and accumulate `ncarry`, - // note that ncarry could be >= 0x3ffffff - var ncarry = hncarry; - hncarry = 0; - var rword = carry & 67108863; - var maxJ = Math.min(k, num.length - 1); + BN.prototype.redPow = function redPow(num) { + assert((this || _global$6$1).red && !num.red, "redPow(normalNum)"); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { - var i = k - j; - var a = self.words[i] | 0; - var b = num.words[j] | 0; - var r = a * b; - var lo = r & 67108863; - ncarry = ncarry + (r / 67108864 | 0) | 0; - lo = lo + rword | 0; - rword = lo & 67108863; - ncarry = ncarry + (lo >>> 26) | 0; - hncarry += ncarry >>> 26; - ncarry &= 67108863; - } + (this || _global$6$1).red._verify1(this || _global$6$1); - out.words[k] = rword; - carry = ncarry; - ncarry = hncarry; - } + return (this || _global$6$1).red.pow(this || _global$6$1, num); + }; // Prime numbers with efficient reduction - if (carry !== 0) { - out.words[k] = carry; - } else { - out.length--; - } - return out.strip(); - } + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime - function jumboMulTo(self, num, out) { - var fftm = new FFTM(); - return fftm.mulp(self, num, out); + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$6$1).name = name; + (this || _global$6$1).p = new BN(p, 16); + (this || _global$6$1).n = (this || _global$6$1).p.bitLength(); + (this || _global$6$1).k = new BN(1).iushln((this || _global$6$1).n).isub((this || _global$6$1).p); + (this || _global$6$1).tmp = this._tmp(); } - BN.prototype.mulTo = function mulTo(num, out) { - var res; - var len = (this || _global$z).length + num.length; + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$6$1).n / 13)); + return tmp; + }; - if ((this || _global$z).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$z, num, out); - } else if (len < 63) { - res = smallMulTo(this || _global$z, num, out); - } else if (len < 1024) { - res = bigMulTo(this || _global$z, num, out); + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + + do { + this.split(r, (this || _global$6$1).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$6$1).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$6$1).n); + + var cmp = rlen < (this || _global$6$1).n ? -1 : r.ucmp((this || _global$6$1).p); + + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$6$1).p); } else { - res = jumboMulTo(this || _global$z, num, out); + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } } - return res; - }; // Cooley-Tukey algorithm for FFT - // slightly revisited to rely on looping instead of recursion + return r; + }; + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$6$1).n, 0, out); + }; - function FFTM(x, y) { - (this || _global$z).x = x; - (this || _global$z).y = y; + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$6$1).k); + }; + + function K256() { + MPrime.call(this || _global$6$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - FFTM.prototype.makeRBT = function makeRBT(N) { - var t = new Array(N); - var l = BN.prototype._countBits(N) - 1; + inherits(K256, MPrime); - for (var i = 0; i < N; i++) { - t[i] = this.revBin(i, l, N); + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; } - return t; - }; // Returns binary-reversed representation of `x` + output.length = outLen; + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs - FFTM.prototype.revBin = function revBin(x, l, N) { - if (x === 0 || x === N - 1) return x; - var rb = 0; - for (var i = 0; i < l; i++) { - rb |= (x & 1) << l - i - 1; - x >>= 1; - } + var prev = input.words[9]; + output.words[output.length++] = prev & mask; - return rb; - }; // Performs "tweedling" phase, therefore 'emulating' - // behaviour of the recursive algorithm + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + prev >>>= 22; + input.words[i - 10] = prev; - FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { - for (var i = 0; i < N; i++) { - rtws[i] = rws[rbt[i]]; - itws[i] = iws[rbt[i]]; + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; } }; - FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { - this.permute(rbt, rws, iws, rtws, itws, N); + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 - for (var s = 1; s < N; s <<= 1) { - var l = s << 1; - var rtwdf = Math.cos(2 * Math.PI / l); - var itwdf = Math.sin(2 * Math.PI / l); + var lo = 0; - for (var p = 0; p < N; p += l) { - var rtwdf_ = rtwdf; - var itwdf_ = itwdf; + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction - for (var j = 0; j < s; j++) { - var re = rtws[p + j]; - var ie = itws[p + j]; - var ro = rtws[p + j + s]; - var io = itws[p + j + s]; - var rx = rtwdf_ * ro - itwdf_ * io; - io = rtwdf_ * io + itwdf_ * ro; - ro = rx; - rtws[p + j] = re + ro; - itws[p + j] = ie + io; - rtws[p + j + s] = re - ro; - itws[p + j + s] = ie - io; - /* jshint maxdepth : false */ - if (j !== l) { - rx = rtwdf * rtwdf_ - itwdf * itwdf_; - itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; - rtwdf_ = rx; - } - } + if (num.words[num.length - 1] === 0) { + num.length--; + + if (num.words[num.length - 1] === 0) { + num.length--; } } + + return num; }; - FFTM.prototype.guessLen13b = function guessLen13b(n, m) { - var N = Math.max(m, n) | 1; - var odd = N & 1; - var i = 0; + function P224() { + MPrime.call(this || _global$6$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } - for (N = N / 2 | 0; N; N = N >>> 1) { - i++; - } + inherits(P224, MPrime); - return 1 << i + 1 + odd; - }; + function P192() { + MPrime.call(this || _global$6$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } - FFTM.prototype.conjugate = function conjugate(rws, iws, N) { - if (N <= 1) return; + inherits(P192, MPrime); - for (var i = 0; i < N / 2; i++) { - var t = rws[i]; - rws[i] = rws[N - i - 1]; - rws[N - i - 1] = t; - t = iws[i]; - iws[i] = -iws[N - i - 1]; - iws[N - i - 1] = -t; - } - }; + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$6$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } - FFTM.prototype.normalize13b = function normalize13b(ws, N) { + inherits(P25519, MPrime); + + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 var carry = 0; - for (var i = 0; i < N / 2; i++) { - var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; - ws[i] = w & 67108863; + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } - if (w < 67108864) { - carry = 0; - } else { - carry = w / 67108864 | 0; - } + if (carry !== 0) { + num.words[num.length++] = carry; } - return ws; - }; + return num; + }; // Exported mostly for testing purposes, use plain name instead - FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { - var carry = 0; - for (var i = 0; i < len; i++) { - carry = carry + (ws[i] | 0); - rws[2 * i] = carry & 8191; - carry = carry >>> 13; - rws[2 * i + 1] = carry & 8191; - carry = carry >>> 13; - } // Pad with zeroes + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; + + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // - for (i = 2 * len; i < N; ++i) { - rws[i] = 0; + + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + + (this || _global$6$1).m = prime.p; + (this || _global$6$1).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$6$1).m = m; + (this || _global$6$1).prime = null; } + } - assert(carry === 0); - assert((carry & ~8191) === 0); + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); }; - FFTM.prototype.stub = function stub(N) { - var ph = new Array(N); + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; - for (var i = 0; i < N; i++) { - ph[i] = 0; + Red.prototype.imod = function imod(a) { + if ((this || _global$6$1).prime) return (this || _global$6$1).prime.ireduce(a)._forceRed(this || _global$6$1); + return a.umod((this || _global$6$1).m)._forceRed(this || _global$6$1); + }; + + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); } - return ph; + return (this || _global$6$1).m.sub(a)._forceRed(this || _global$6$1); }; - FFTM.prototype.mulp = function mulp(x, y, out) { - var N = 2 * this.guessLen13b(x.length, y.length); - var rbt = this.makeRBT(N); + Red.prototype.add = function add(a, b) { + this._verify2(a, b); - var _ = this.stub(N); + var res = a.add(b); - var rws = new Array(N); - var rwst = new Array(N); - var iwst = new Array(N); - var nrws = new Array(N); - var nrwst = new Array(N); - var niwst = new Array(N); - var rmws = out.words; - rmws.length = N; - this.convert13b(x.words, x.length, rws, N); - this.convert13b(y.words, y.length, nrws, N); - this.transform(rws, _, rwst, iwst, N, rbt); - this.transform(nrws, _, nrwst, niwst, N, rbt); + if (res.cmp((this || _global$6$1).m) >= 0) { + res.isub((this || _global$6$1).m); + } - for (var i = 0; i < N; i++) { - var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; - iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; - rwst[i] = rx; + return res._forceRed(this || _global$6$1); + }; + + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); + + var res = a.iadd(b); + + if (res.cmp((this || _global$6$1).m) >= 0) { + res.isub((this || _global$6$1).m); } - this.conjugate(rwst, iwst, N); - this.transform(rwst, iwst, rmws, _, N, rbt); - this.conjugate(rmws, _, N); - this.normalize13b(rmws, N); - out.negative = x.negative ^ y.negative; - out.length = x.length + y.length; - return out.strip(); - }; // Multiply `this` by `num` + return res; + }; + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); - BN.prototype.mul = function mul(num) { - var out = new BN(null); - out.words = new Array((this || _global$z).length + num.length); - return this.mulTo(num, out); - }; // Multiply employing FFT + var res = a.sub(b); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$6$1).m); + } - BN.prototype.mulf = function mulf(num) { - var out = new BN(null); - out.words = new Array((this || _global$z).length + num.length); - return jumboMulTo(this || _global$z, num, out); - }; // In-place Multiplication + return res._forceRed(this || _global$6$1); + }; + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); - BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$z); + var res = a.isub(b); + + if (res.cmpn(0) < 0) { + res.iadd((this || _global$6$1).m); + } + + return res; }; - BN.prototype.imuln = function imuln(num) { - assert(typeof num === "number"); - assert(num < 67108864); // Carry + Red.prototype.shl = function shl(a, num) { + this._verify1(a); - var carry = 0; + return this.imod(a.ushln(num)); + }; - for (var i = 0; i < (this || _global$z).length; i++) { - var w = ((this || _global$z).words[i] | 0) * num; - var lo = (w & 67108863) + (carry & 67108863); - carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); - carry += lo >>> 26; - (this || _global$z).words[i] = lo & 67108863; - } + return this.imod(a.imul(b)); + }; - if (carry !== 0) { - (this || _global$z).words[i] = carry; - (this || _global$z).length++; - } + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); - return this || _global$z; + return this.imod(a.mul(b)); }; - BN.prototype.muln = function muln(num) { - return this.clone().imuln(num); - }; // `this` * `this` + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; - BN.prototype.sqr = function sqr() { - return this.mul(this || _global$z); - }; // `this` * `this` in-place + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); + var mod3 = (this || _global$6$1).m.andln(3); - BN.prototype.isqr = function isqr() { - return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) + assert(mod3 % 2 === 1); // Fast case + if (mod3 === 3) { + var pow = (this || _global$6$1).m.add(new BN(1)).iushrn(2); - BN.prototype.pow = function pow(num) { - var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) - var res = this || _global$z; - for (var i = 0; i < w.length; i++, res = res.sqr()) { - if (w[i] !== 0) break; - } + var q = (this || _global$6$1).m.subn(1); - if (++i < w.length) { - for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { - if (w[i] === 0) continue; - res = res.mul(q); - } - } + var s = 0; - return res; - }; // Shift-left in-place + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$6$1); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. - BN.prototype.iushln = function iushln(bits) { - assert(typeof bits === "number" && bits >= 0); - var r = bits % 26; - var s = (bits - r) / 26; - var carryMask = 67108863 >>> 26 - r << 26 - r; - var i; + var lpow = (this || _global$6$1).m.subn(1).iushrn(1); - if (r !== 0) { - var carry = 0; + var z = (this || _global$6$1).m.bitLength(); - for (i = 0; i < (this || _global$z).length; i++) { - var newCarry = (this || _global$z).words[i] & carryMask; - var c = ((this || _global$z).words[i] | 0) - newCarry << r; - (this || _global$z).words[i] = c | carry; - carry = newCarry >>> 26 - r; - } + z = new BN(2 * z * z).toRed(this || _global$6$1); - if (carry) { - (this || _global$z).words[i] = carry; - (this || _global$z).length++; - } + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); } - if (s !== 0) { - for (i = (this || _global$z).length - 1; i >= 0; i--) { - (this || _global$z).words[i + s] = (this || _global$z).words[i]; - } + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; - for (i = 0; i < s; i++) { - (this || _global$z).words[i] = 0; + while (t.cmp(one) !== 0) { + var tmp = t; + + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); } - (this || _global$z).length += s; + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; } - return this.strip(); + return r; }; - BN.prototype.ishln = function ishln(bits) { - // TODO(indutny): implement me - assert((this || _global$z).negative === 0); - return this.iushln(bits); - }; // Shift-right in-place - // NOTE: `hint` is a lowest bit before trailing zeroes - // NOTE: if `extended` is present - it will be filled with destroyed bits - - - BN.prototype.iushrn = function iushrn(bits, hint, extended) { - assert(typeof bits === "number" && bits >= 0); - var h; + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$6$1).m); - if (hint) { - h = (hint - hint % 26) / 26; + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); } else { - h = 0; + return this.imod(inv); } + }; - var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$z).length); - var mask = 67108863 ^ 67108863 >>> r << r; - var maskedWords = extended; - h -= s; - h = Math.max(0, h); // Extended mode, copy masked part - - if (maskedWords) { - for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$z).words[i]; - } + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$6$1); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$6$1); + wnd[1] = a; - maskedWords.length = s; + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); } - if (s === 0) ; else if ((this || _global$z).length > s) { - (this || _global$z).length -= s; + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; - for (i = 0; i < (this || _global$z).length; i++) { - (this || _global$z).words[i] = (this || _global$z).words[i + s]; - } - } else { - (this || _global$z).words[0] = 0; - (this || _global$z).length = 1; + if (start === 0) { + start = 26; } - var carry = 0; + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; - for (i = (this || _global$z).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$z).words[i] | 0; - (this || _global$z).words[i] = carry << 26 - r | word >>> r; - carry = word & mask; - } // Push carried bits as a mask + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + if (res !== wnd[0]) { + res = this.sqr(res); + } - if (maskedWords && carry !== 0) { - maskedWords.words[maskedWords.length++] = carry; - } + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } - if ((this || _global$z).length === 0) { - (this || _global$z).words[0] = 0; - (this || _global$z).length = 1; + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + + start = 26; } - return this.strip(); + return res; }; - BN.prototype.ishrn = function ishrn(bits, hint, extended) { - // TODO(indutny): implement me - assert((this || _global$z).negative === 0); - return this.iushrn(bits, hint, extended); - }; // Shift-left - - - BN.prototype.shln = function shln(bits) { - return this.clone().ishln(bits); + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$6$1).m); + return r === num ? r.clone() : r; }; - BN.prototype.ushln = function ushln(bits) { - return this.clone().iushln(bits); - }; // Shift-right + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // - BN.prototype.shrn = function shrn(bits) { - return this.clone().ishrn(bits); + BN.mont = function mont(num) { + return new Mont(num); }; - BN.prototype.ushrn = function ushrn(bits) { - return this.clone().iushrn(bits); - }; // Test if n bit is set - - - BN.prototype.testn = function testn(bit) { - assert(typeof bit === "number" && bit >= 0); - var r = bit % 26; - var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + function Mont(m) { + Red.call(this || _global$6$1, m); + (this || _global$6$1).shift = (this || _global$6$1).m.bitLength(); - if ((this || _global$z).length <= s) return false; // Check bit and return + if ((this || _global$6$1).shift % 26 !== 0) { + (this || _global$6$1).shift += 26 - (this || _global$6$1).shift % 26; + } - var w = (this || _global$z).words[s]; - return !!(w & q); - }; // Return only lowers bits of number (in-place) + (this || _global$6$1).r = new BN(1).iushln((this || _global$6$1).shift); + (this || _global$6$1).r2 = this.imod((this || _global$6$1).r.sqr()); + (this || _global$6$1).rinv = (this || _global$6$1).r._invmp((this || _global$6$1).m); + (this || _global$6$1).minv = (this || _global$6$1).rinv.mul((this || _global$6$1).r).isubn(1).div((this || _global$6$1).m); + (this || _global$6$1).minv = (this || _global$6$1).minv.umod((this || _global$6$1).r); + (this || _global$6$1).minv = (this || _global$6$1).r.sub((this || _global$6$1).minv); + } + inherits(Mont, Red); - BN.prototype.imaskn = function imaskn(bits) { - assert(typeof bits === "number" && bits >= 0); - var r = bits % 26; - var s = (bits - r) / 26; - assert((this || _global$z).negative === 0, "imaskn works only with positive numbers"); + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$6$1).shift)); + }; - if ((this || _global$z).length <= s) { - return this || _global$z; - } + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$6$1).rinv)); + r.red = null; + return r; + }; - if (r !== 0) { - s++; + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; } - (this || _global$z).length = Math.min(s, (this || _global$z).length); + var t = a.imul(b); + var c = t.maskn((this || _global$6$1).shift).mul((this || _global$6$1).minv).imaskn((this || _global$6$1).shift).mul((this || _global$6$1).m); + var u = t.isub(c).iushrn((this || _global$6$1).shift); + var res = u; - if (r !== 0) { - var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$z).words[(this || _global$z).length - 1] &= mask; + if (u.cmp((this || _global$6$1).m) >= 0) { + res = u.isub((this || _global$6$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$6$1).m); } - return this.strip(); - }; // Return only lowers bits of number - - - BN.prototype.maskn = function maskn(bits) { - return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` - - - BN.prototype.iaddn = function iaddn(num) { - assert(typeof num === "number"); - assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + return res._forceRed(this || _global$6$1); + }; - if ((this || _global$z).negative !== 0) { - if ((this || _global$z).length === 1 && ((this || _global$z).words[0] | 0) < num) { - (this || _global$z).words[0] = num - ((this || _global$z).words[0] | 0); - (this || _global$z).negative = 0; - return this || _global$z; - } + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$6$1); + var t = a.mul(b); + var c = t.maskn((this || _global$6$1).shift).mul((this || _global$6$1).minv).imaskn((this || _global$6$1).shift).mul((this || _global$6$1).m); + var u = t.isub(c).iushrn((this || _global$6$1).shift); + var res = u; - (this || _global$z).negative = 0; - this.isubn(num); - (this || _global$z).negative = 1; - return this || _global$z; - } // Add without checks + if (u.cmp((this || _global$6$1).m) >= 0) { + res = u.isub((this || _global$6$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$6$1).m); + } + return res._forceRed(this || _global$6$1); + }; - return this._iaddn(num); + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$6$1).m).mul((this || _global$6$1).r2)); + return res._forceRed(this || _global$6$1); }; + })(module$3$1, exports$V$1); - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$z).words[0] += num; // Carry + return module$3$1.exports; +} - for (var i = 0; i < (this || _global$z).length && (this || _global$z).words[i] >= 67108864; i++) { - (this || _global$z).words[i] -= 67108864; +var exports$U$1 = {}, + _dewExec$U$1 = false; +function dew$U$1() { + if (_dewExec$U$1) return exports$U$1; + _dewExec$U$1 = true; + var utils = exports$U$1; - if (i === (this || _global$z).length - 1) { - (this || _global$z).words[i + 1] = 1; - } else { - (this || _global$z).words[i + 1]++; - } - } + function toArray(msg, enc) { + if (Array.isArray(msg)) return msg.slice(); + if (!msg) return []; + var res = []; - (this || _global$z).length = Math.max((this || _global$z).length, i + 1); - return this || _global$z; - }; // Subtract plain number `num` from `this` + if (typeof msg !== "string") { + for (var i = 0; i < msg.length; i++) res[i] = msg[i] | 0; + return res; + } - BN.prototype.isubn = function isubn(num) { - assert(typeof num === "number"); - assert(num < 67108864); - if (num < 0) return this.iaddn(-num); + if (enc === "hex") { + msg = msg.replace(/[^a-z0-9]+/ig, ""); + if (msg.length % 2 !== 0) msg = "0" + msg; - if ((this || _global$z).negative !== 0) { - (this || _global$z).negative = 0; - this.iaddn(num); - (this || _global$z).negative = 1; - return this || _global$z; + for (var i = 0; i < msg.length; i += 2) res.push(parseInt(msg[i] + msg[i + 1], 16)); + } else { + for (var i = 0; i < msg.length; i++) { + var c = msg.charCodeAt(i); + var hi = c >> 8; + var lo = c & 255; + if (hi) res.push(hi, lo);else res.push(lo); } + } - (this || _global$z).words[0] -= num; - - if ((this || _global$z).length === 1 && (this || _global$z).words[0] < 0) { - (this || _global$z).words[0] = -(this || _global$z).words[0]; - (this || _global$z).negative = 1; - } else { - // Carry - for (var i = 0; i < (this || _global$z).length && (this || _global$z).words[i] < 0; i++) { - (this || _global$z).words[i] += 67108864; - (this || _global$z).words[i + 1] -= 1; - } - } + return res; + } - return this.strip(); - }; + utils.toArray = toArray; - BN.prototype.addn = function addn(num) { - return this.clone().iaddn(num); - }; + function zero2(word) { + if (word.length === 1) return "0" + word;else return word; + } - BN.prototype.subn = function subn(num) { - return this.clone().isubn(num); - }; + utils.zero2 = zero2; - BN.prototype.iabs = function iabs() { - (this || _global$z).negative = 0; - return this || _global$z; - }; + function toHex(msg) { + var res = ""; - BN.prototype.abs = function abs() { - return this.clone().iabs(); - }; + for (var i = 0; i < msg.length; i++) res += zero2(msg[i].toString(16)); - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { - var len = num.length + shift; - var i; + return res; + } - this._expand(len); + utils.toHex = toHex; - var w; - var carry = 0; + utils.encode = function encode(arr, enc) { + if (enc === "hex") return toHex(arr);else return arr; + }; - for (i = 0; i < num.length; i++) { - w = ((this || _global$z).words[i + shift] | 0) + carry; - var right = (num.words[i] | 0) * mul; - w -= right & 67108863; - carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$z).words[i + shift] = w & 67108863; - } + return exports$U$1; +} - for (; i < (this || _global$z).length - shift; i++) { - w = ((this || _global$z).words[i + shift] | 0) + carry; - carry = w >> 26; - (this || _global$z).words[i + shift] = w & 67108863; - } +var exports$T$1 = {}, + _dewExec$T$1 = false; +function dew$T$1() { + if (_dewExec$T$1) return exports$T$1; + _dewExec$T$1 = true; + var utils = exports$T$1; - if (carry === 0) return this.strip(); // Subtraction overflow + var BN = dew$V$1(); - assert(carry === -1); - carry = 0; + var minAssert = dew$1t(); - for (i = 0; i < (this || _global$z).length; i++) { - w = -((this || _global$z).words[i] | 0) + carry; - carry = w >> 26; - (this || _global$z).words[i] = w & 67108863; - } + var minUtils = dew$U$1(); - (this || _global$z).negative = 1; - return this.strip(); - }; + utils.assert = minAssert; + utils.toArray = minUtils.toArray; + utils.zero2 = minUtils.zero2; + utils.toHex = minUtils.toHex; + utils.encode = minUtils.encode; // Represent num in a w-NAF form - BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$z).length - num.length; - var a = this.clone(); - var b = num; // Normalize + function getNAF(num, w, bits) { + var naf = new Array(Math.max(num.bitLength(), bits) + 1); + naf.fill(0); + var ws = 1 << w + 1; + var k = num.clone(); - var bhi = b.words[b.length - 1] | 0; + for (var i = 0; i < naf.length; i++) { + var z; + var mod = k.andln(ws - 1); - var bhiBits = this._countBits(bhi); + if (k.isOdd()) { + if (mod > (ws >> 1) - 1) z = (ws >> 1) - mod;else z = mod; + k.isubn(z); + } else { + z = 0; + } - shift = 26 - bhiBits; + naf[i] = z; + k.iushrn(1); + } - if (shift !== 0) { - b = b.ushln(shift); - a.iushln(shift); - bhi = b.words[b.length - 1] | 0; - } // Initialize quotient + return naf; + } + utils.getNAF = getNAF; // Represent k1, k2 in a Joint Sparse Form - var m = a.length - b.length; - var q; + function getJSF(k1, k2) { + var jsf = [[], []]; + k1 = k1.clone(); + k2 = k2.clone(); + var d1 = 0; + var d2 = 0; + var m8; - if (mode !== "mod") { - q = new BN(null); - q.length = m + 1; - q.words = new Array(q.length); + while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) { + // First phase + var m14 = k1.andln(3) + d1 & 3; + var m24 = k2.andln(3) + d2 & 3; + if (m14 === 3) m14 = -1; + if (m24 === 3) m24 = -1; + var u1; - for (var i = 0; i < q.length; i++) { - q.words[i] = 0; - } + if ((m14 & 1) === 0) { + u1 = 0; + } else { + m8 = k1.andln(7) + d1 & 7; + if ((m8 === 3 || m8 === 5) && m24 === 2) u1 = -m14;else u1 = m14; } - var diff = a.clone()._ishlnsubmul(b, 1, m); - - if (diff.negative === 0) { - a = diff; + jsf[0].push(u1); + var u2; - if (q) { - q.words[m] = 1; - } + if ((m24 & 1) === 0) { + u2 = 0; + } else { + m8 = k2.andln(7) + d2 & 7; + if ((m8 === 3 || m8 === 5) && m14 === 2) u2 = -m24;else u2 = m24; } - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + jsf[1].push(u2); // Second phase - qj = Math.min(qj / bhi | 0, 67108863); + if (2 * d1 === u1 + 1) d1 = 1 - d1; + if (2 * d2 === u2 + 1) d2 = 1 - d2; + k1.iushrn(1); + k2.iushrn(1); + } - a._ishlnsubmul(b, qj, j); + return jsf; + } - while (a.negative !== 0) { - qj--; - a.negative = 0; + utils.getJSF = getJSF; - a._ishlnsubmul(b, 1, j); + function cachedProperty(obj, name, computer) { + var key = "_" + name; - if (!a.isZero()) { - a.negative ^= 1; - } - } + obj.prototype[name] = function cachedProperty() { + return this[key] !== undefined ? this[key] : this[key] = computer.call(this); + }; + } - if (q) { - q.words[j] = qj; - } - } + utils.cachedProperty = cachedProperty; - if (q) { - q.strip(); - } + function parseBytes(bytes) { + return typeof bytes === "string" ? utils.toArray(bytes, "hex") : bytes; + } - a.strip(); // Denormalize + utils.parseBytes = parseBytes; - if (mode !== "div" && shift !== 0) { - a.iushrn(shift); - } + function intFromLE(bytes) { + return new BN(bytes, "hex", "le"); + } - return { - div: q || null, - mod: a - }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, - // to `div` to request div only, or be absent to - // request both div & mod - // 2) `positive` is true if unsigned mod is requested + utils.intFromLE = intFromLE; + return exports$T$1; +} +var exports$S$1 = {}, + _dewExec$S$1 = false; +function dew$S$1() { + if (_dewExec$S$1) return exports$S$1; + _dewExec$S$1 = true; - BN.prototype.divmod = function divmod(num, mode, positive) { - assert(!num.isZero()); + var BN = dew$V$1(); - if (this.isZero()) { - return { - div: new BN(0), - mod: new BN(0) - }; - } + var utils = dew$T$1(); - var div, mod, res; + var getNAF = utils.getNAF; + var getJSF = utils.getJSF; + var assert = utils.assert; - if ((this || _global$z).negative !== 0 && num.negative === 0) { - res = this.neg().divmod(num, mode); + function BaseCurve(type, conf) { + this.type = type; + this.p = new BN(conf.p, 16); // Use Montgomery, when there is no fast reduction for the prime - if (mode !== "mod") { - div = res.div.neg(); - } + this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); // Useful for many curves - if (mode !== "div") { - mod = res.mod.neg(); + this.zero = new BN(0).toRed(this.red); + this.one = new BN(1).toRed(this.red); + this.two = new BN(2).toRed(this.red); // Curve configuration, optional - if (positive && mod.negative !== 0) { - mod.iadd(num); - } - } + this.n = conf.n && new BN(conf.n, 16); + this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); // Temporary arrays - return { - div: div, - mod: mod - }; - } + this._wnafT1 = new Array(4); + this._wnafT2 = new Array(4); + this._wnafT3 = new Array(4); + this._wnafT4 = new Array(4); + this._bitLength = this.n ? this.n.bitLength() : 0; // Generalized Greg Maxwell's trick - if ((this || _global$z).negative === 0 && num.negative !== 0) { - res = this.divmod(num.neg(), mode); + var adjustCount = this.n && this.p.div(this.n); - if (mode !== "mod") { - div = res.div.neg(); - } + if (!adjustCount || adjustCount.cmpn(100) > 0) { + this.redN = null; + } else { + this._maxwellTrick = true; + this.redN = this.n.toRed(this.red); + } + } - return { - div: div, - mod: res.mod - }; - } + exports$S$1 = BaseCurve; - if (((this || _global$z).negative & num.negative) !== 0) { - res = this.neg().divmod(num.neg(), mode); + BaseCurve.prototype.point = function point() { + throw new Error("Not implemented"); + }; - if (mode !== "div") { - mod = res.mod.neg(); + BaseCurve.prototype.validate = function validate() { + throw new Error("Not implemented"); + }; - if (positive && mod.negative !== 0) { - mod.isub(num); - } - } + BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) { + assert(p.precomputed); - return { - div: res.div, - mod: mod - }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + var doubles = p._getDoubles(); + var naf = getNAF(k, 1, this._bitLength); + var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1); + I /= 3; // Translate into more windowed form - if (num.length > (this || _global$z).length || this.cmp(num) < 0) { - return { - div: new BN(0), - mod: this || _global$z - }; - } // Very short reduction + var repr = []; + var j; + var nafW; + for (j = 0; j < naf.length; j += doubles.step) { + nafW = 0; - if (num.length === 1) { - if (mode === "div") { - return { - div: this.divn(num.words[0]), - mod: null - }; - } + for (var l = j + doubles.step - 1; l >= j; l--) nafW = (nafW << 1) + naf[l]; - if (mode === "mod") { - return { - div: null, - mod: new BN(this.modn(num.words[0])) - }; - } + repr.push(nafW); + } - return { - div: this.divn(num.words[0]), - mod: new BN(this.modn(num.words[0])) - }; + var a = this.jpoint(null, null, null); + var b = this.jpoint(null, null, null); + + for (var i = I; i > 0; i--) { + for (j = 0; j < repr.length; j++) { + nafW = repr[j]; + if (nafW === i) b = b.mixedAdd(doubles.points[j]);else if (nafW === -i) b = b.mixedAdd(doubles.points[j].neg()); } - return this._wordDiv(num, mode); - }; // Find `this` / `num` + a = a.add(b); + } + return a.toP(); + }; - BN.prototype.div = function div(num) { - return this.divmod(num, "div", false).div; - }; // Find `this` % `num` + BaseCurve.prototype._wnafMul = function _wnafMul(p, k) { + var w = 4; // Precompute window + var nafPoints = p._getNAFPoints(w); - BN.prototype.mod = function mod(num) { - return this.divmod(num, "mod", false).mod; - }; + w = nafPoints.wnd; + var wnd = nafPoints.points; // Get NAF form - BN.prototype.umod = function umod(num) { - return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) + var naf = getNAF(k, w, this._bitLength); // Add `this`*(N+1) for every w-NAF index + var acc = this.jpoint(null, null, null); - BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + for (var i = naf.length - 1; i >= 0; i--) { + // Count zeroes + for (var l = 0; i >= 0 && naf[i] === 0; i--) l++; - if (dm.mod.isZero()) return dm.div; - var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; - var half = num.ushrn(1); - var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + if (i >= 0) l++; + acc = acc.dblp(l); + if (i < 0) break; + var z = naf[i]; + assert(z !== 0); - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + if (p.type === "affine") { + // J +- P + if (z > 0) acc = acc.mixedAdd(wnd[z - 1 >> 1]);else acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg()); + } else { + // J +- J + if (z > 0) acc = acc.add(wnd[z - 1 >> 1]);else acc = acc.add(wnd[-z - 1 >> 1].neg()); + } + } - return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); - }; + return p.type === "affine" ? acc.toP() : acc; + }; - BN.prototype.modn = function modn(num) { - assert(num <= 67108863); - var p = (1 << 26) % num; - var acc = 0; + BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) { + var wndWidth = this._wnafT1; + var wnd = this._wnafT2; + var naf = this._wnafT3; // Fill all arrays - for (var i = (this || _global$z).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$z).words[i] | 0)) % num; - } + var max = 0; + var i; + var j; + var p; - return acc; - }; // In-place division by number + for (i = 0; i < len; i++) { + p = points[i]; + var nafPoints = p._getNAFPoints(defW); - BN.prototype.idivn = function idivn(num) { - assert(num <= 67108863); - var carry = 0; + wndWidth[i] = nafPoints.wnd; + wnd[i] = nafPoints.points; + } // Comb small window NAFs - for (var i = (this || _global$z).length - 1; i >= 0; i--) { - var w = ((this || _global$z).words[i] | 0) + carry * 67108864; - (this || _global$z).words[i] = w / num | 0; - carry = w % num; - } - return this.strip(); - }; + for (i = len - 1; i >= 1; i -= 2) { + var a = i - 1; + var b = i; - BN.prototype.divn = function divn(num) { - return this.clone().idivn(num); - }; + if (wndWidth[a] !== 1 || wndWidth[b] !== 1) { + naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength); + naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength); + max = Math.max(naf[a].length, max); + max = Math.max(naf[b].length, max); + continue; + } - BN.prototype.egcd = function egcd(p) { - assert(p.negative === 0); - assert(!p.isZero()); - var x = this || _global$z; - var y = p.clone(); + var comb = [points[a], + /* 1 */ + null, + /* 3 */ + null, + /* 5 */ + points[b] + /* 7 */ + ]; // Try to avoid Projective points, if possible - if (x.negative !== 0) { - x = x.umod(p); + if (points[a].y.cmp(points[b].y) === 0) { + comb[1] = points[a].add(points[b]); + comb[2] = points[a].toJ().mixedAdd(points[b].neg()); + } else if (points[a].y.cmp(points[b].y.redNeg()) === 0) { + comb[1] = points[a].toJ().mixedAdd(points[b]); + comb[2] = points[a].add(points[b].neg()); } else { - x = x.clone(); - } // A * x + B * y = x - - - var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + comb[1] = points[a].toJ().mixedAdd(points[b]); + comb[2] = points[a].toJ().mixedAdd(points[b].neg()); + } - var C = new BN(0); - var D = new BN(1); - var g = 0; + var index = [-3, + /* -1 -1 */ + -1, + /* -1 0 */ + -5, + /* -1 1 */ + -7, + /* 0 -1 */ + 0, + /* 0 0 */ + 7, + /* 0 1 */ + 5, + /* 1 -1 */ + 1, + /* 1 0 */ + 3 + /* 1 1 */ + ]; + var jsf = getJSF(coeffs[a], coeffs[b]); + max = Math.max(jsf[0].length, max); + naf[a] = new Array(max); + naf[b] = new Array(max); - while (x.isEven() && y.isEven()) { - x.iushrn(1); - y.iushrn(1); - ++g; + for (j = 0; j < max; j++) { + var ja = jsf[0][j] | 0; + var jb = jsf[1][j] | 0; + naf[a][j] = index[(ja + 1) * 3 + (jb + 1)]; + naf[b][j] = 0; + wnd[a] = comb; } + } - var yp = y.clone(); - var xp = x.clone(); - - while (!x.isZero()) { - for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + var acc = this.jpoint(null, null, null); + var tmp = this._wnafT4; - if (i > 0) { - x.iushrn(i); + for (i = max; i >= 0; i--) { + var k = 0; - while (i-- > 0) { - if (A.isOdd() || B.isOdd()) { - A.iadd(yp); - B.isub(xp); - } + while (i >= 0) { + var zero = true; - A.iushrn(1); - B.iushrn(1); - } + for (j = 0; j < len; j++) { + tmp[j] = naf[j][i] | 0; + if (tmp[j] !== 0) zero = false; } - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + if (!zero) break; + k++; + i--; + } - if (j > 0) { - y.iushrn(j); + if (i >= 0) k++; + acc = acc.dblp(k); + if (i < 0) break; - while (j-- > 0) { - if (C.isOdd() || D.isOdd()) { - C.iadd(yp); - D.isub(xp); - } + for (j = 0; j < len; j++) { + var z = tmp[j]; + if (z === 0) continue;else if (z > 0) p = wnd[j][z - 1 >> 1];else if (z < 0) p = wnd[j][-z - 1 >> 1].neg(); + if (p.type === "affine") acc = acc.mixedAdd(p);else acc = acc.add(p); + } + } // Zeroify references - C.iushrn(1); - D.iushrn(1); - } - } - if (x.cmp(y) >= 0) { - x.isub(y); - A.isub(C); - B.isub(D); - } else { - y.isub(x); - C.isub(A); - D.isub(B); - } - } + for (i = 0; i < len; i++) wnd[i] = null; - return { - a: C, - b: D, - gcd: y.iushln(g) - }; - }; // This is reduced incarnation of the binary EEA - // above, designated to invert members of the - // _prime_ fields F(p) at a maximal speed + if (jacobianResult) return acc;else return acc.toP(); + }; + function BasePoint(curve, type) { + this.curve = curve; + this.type = type; + this.precomputed = null; + } - BN.prototype._invmp = function _invmp(p) { - assert(p.negative === 0); - assert(!p.isZero()); - var a = this || _global$z; - var b = p.clone(); + BaseCurve.BasePoint = BasePoint; - if (a.negative !== 0) { - a = a.umod(p); - } else { - a = a.clone(); - } + BasePoint.prototype.eq = function eq() { + throw new Error("Not implemented"); + }; - var x1 = new BN(1); - var x2 = new BN(0); - var delta = b.clone(); + BasePoint.prototype.validate = function validate() { + return this.curve.validate(this); + }; - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { - for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) { + bytes = utils.toArray(bytes, enc); + var len = this.p.byteLength(); // uncompressed, hybrid-odd, hybrid-even - if (i > 0) { - a.iushrn(i); + if ((bytes[0] === 4 || bytes[0] === 6 || bytes[0] === 7) && bytes.length - 1 === 2 * len) { + if (bytes[0] === 6) assert(bytes[bytes.length - 1] % 2 === 0);else if (bytes[0] === 7) assert(bytes[bytes.length - 1] % 2 === 1); + var res = this.point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len)); + return res; + } else if ((bytes[0] === 2 || bytes[0] === 3) && bytes.length - 1 === len) { + return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 3); + } - while (i-- > 0) { - if (x1.isOdd()) { - x1.iadd(delta); - } + throw new Error("Unknown point format"); + }; - x1.iushrn(1); - } - } + BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) { + return this.encode(enc, true); + }; - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + BasePoint.prototype._encode = function _encode(compact) { + var len = this.curve.p.byteLength(); + var x = this.getX().toArray("be", len); + if (compact) return [this.getY().isEven() ? 2 : 3].concat(x); + return [4].concat(x, this.getY().toArray("be", len)); + }; + + BasePoint.prototype.encode = function encode(enc, compact) { + return utils.encode(this._encode(compact), enc); + }; + + BasePoint.prototype.precompute = function precompute(power) { + if (this.precomputed) return this; + var precomputed = { + doubles: null, + naf: null, + beta: null + }; + precomputed.naf = this._getNAFPoints(8); + precomputed.doubles = this._getDoubles(4, power); + precomputed.beta = this._getBeta(); + this.precomputed = precomputed; + return this; + }; - if (j > 0) { - b.iushrn(j); + BasePoint.prototype._hasDoubles = function _hasDoubles(k) { + if (!this.precomputed) return false; + var doubles = this.precomputed.doubles; + if (!doubles) return false; + return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step); + }; - while (j-- > 0) { - if (x2.isOdd()) { - x2.iadd(delta); - } + BasePoint.prototype._getDoubles = function _getDoubles(step, power) { + if (this.precomputed && this.precomputed.doubles) return this.precomputed.doubles; + var doubles = [this]; + var acc = this; - x2.iushrn(1); - } - } + for (var i = 0; i < power; i += step) { + for (var j = 0; j < step; j++) acc = acc.dbl(); - if (a.cmp(b) >= 0) { - a.isub(b); - x1.isub(x2); - } else { - b.isub(a); - x2.isub(x1); - } - } + doubles.push(acc); + } - var res; + return { + step: step, + points: doubles + }; + }; - if (a.cmpn(1) === 0) { - res = x1; - } else { - res = x2; - } + BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) { + if (this.precomputed && this.precomputed.naf) return this.precomputed.naf; + var res = [this]; + var max = (1 << wnd) - 1; + var dbl = max === 1 ? null : this.dbl(); - if (res.cmpn(0) < 0) { - res.iadd(p); - } + for (var i = 1; i < max; i++) res[i] = res[i - 1].add(dbl); - return res; + return { + wnd: wnd, + points: res }; + }; - BN.prototype.gcd = function gcd(num) { - if (this.isZero()) return num.abs(); - if (num.isZero()) return this.abs(); - var a = this.clone(); - var b = num.clone(); - a.negative = 0; - b.negative = 0; // Remove common factor of two - - for (var shift = 0; a.isEven() && b.isEven(); shift++) { - a.iushrn(1); - b.iushrn(1); - } + BasePoint.prototype._getBeta = function _getBeta() { + return null; + }; - do { - while (a.isEven()) { - a.iushrn(1); - } + BasePoint.prototype.dblp = function dblp(k) { + var r = this; - while (b.isEven()) { - b.iushrn(1); - } + for (var i = 0; i < k; i++) r = r.dbl(); - var r = a.cmp(b); + return r; + }; - if (r < 0) { - // Swap `a` and `b` to make `a` always bigger than `b` - var t = a; - a = b; - b = t; - } else if (r === 0 || b.cmpn(1) === 0) { - break; - } + return exports$S$1; +} - a.isub(b); - } while (true); +var exports$R$1 = {}, + _dewExec$R$1 = false; +function dew$R$1() { + if (_dewExec$R$1) return exports$R$1; + _dewExec$R$1 = true; - return b.iushln(shift); - }; // Invert number in the field F(num) + var utils = dew$T$1(); + var BN = dew$V$1(); - BN.prototype.invm = function invm(num) { - return this.egcd(num).a.umod(num); - }; + var inherits = dew$f$2(); - BN.prototype.isEven = function isEven() { - return ((this || _global$z).words[0] & 1) === 0; - }; + var Base = dew$S$1(); - BN.prototype.isOdd = function isOdd() { - return ((this || _global$z).words[0] & 1) === 1; - }; // And first word and num + var assert = utils.assert; + function ShortCurve(conf) { + Base.call(this, "short", conf); + this.a = new BN(conf.a, 16).toRed(this.red); + this.b = new BN(conf.b, 16).toRed(this.red); + this.tinv = this.two.redInvm(); + this.zeroA = this.a.fromRed().cmpn(0) === 0; + this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; // If the curve is endomorphic, precalculate beta and lambda - BN.prototype.andln = function andln(num) { - return (this || _global$z).words[0] & num; - }; // Increment at the bit position in-line + this.endo = this._getEndomorphism(conf); + this._endoWnafT1 = new Array(4); + this._endoWnafT2 = new Array(4); + } + inherits(ShortCurve, Base); + exports$R$1 = ShortCurve; - BN.prototype.bincn = function bincn(bit) { - assert(typeof bit === "number"); - var r = bit % 26; - var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) { + // No efficient endomorphism + if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return; // Compute beta and lambda, that lambda * P = (beta * Px; Py) - if ((this || _global$z).length <= s) { - this._expand(s + 1); + var beta; + var lambda; - (this || _global$z).words[s] |= q; - return this || _global$z; - } // Add bit and propagate, if needed + if (conf.beta) { + beta = new BN(conf.beta, 16).toRed(this.red); + } else { + var betas = this._getEndoRoots(this.p); // Choose the smallest beta - var carry = q; + beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1]; + beta = beta.toRed(this.red); + } - for (var i = s; carry !== 0 && i < (this || _global$z).length; i++) { - var w = (this || _global$z).words[i] | 0; - w += carry; - carry = w >>> 26; - w &= 67108863; - (this || _global$z).words[i] = w; - } + if (conf.lambda) { + lambda = new BN(conf.lambda, 16); + } else { + // Choose the lambda that is matching selected beta + var lambdas = this._getEndoRoots(this.n); - if (carry !== 0) { - (this || _global$z).words[i] = carry; - (this || _global$z).length++; + if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) { + lambda = lambdas[0]; + } else { + lambda = lambdas[1]; + assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0); } + } // Get basis vectors, used for balanced length-two representation - return this || _global$z; - }; - - BN.prototype.isZero = function isZero() { - return (this || _global$z).length === 1 && (this || _global$z).words[0] === 0; - }; - BN.prototype.cmpn = function cmpn(num) { - var negative = num < 0; - if ((this || _global$z).negative !== 0 && !negative) return -1; - if ((this || _global$z).negative === 0 && negative) return 1; - this.strip(); - var res; + var basis; - if ((this || _global$z).length > 1) { - res = 1; - } else { - if (negative) { - num = -num; - } + if (conf.basis) { + basis = conf.basis.map(function (vec) { + return { + a: new BN(vec.a, 16), + b: new BN(vec.b, 16) + }; + }); + } else { + basis = this._getEndoBasis(lambda); + } - assert(num <= 67108863, "Number is too big"); - var w = (this || _global$z).words[0] | 0; - res = w === num ? 0 : w < num ? -1 : 1; - } + return { + beta: beta, + lambda: lambda, + basis: basis + }; + }; - if ((this || _global$z).negative !== 0) return -res | 0; - return res; - }; // Compare two numbers and return: - // 1 - if `this` > `num` - // 0 - if `this` == `num` - // -1 - if `this` < `num` + ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) { + // Find roots of for x^2 + x + 1 in F + // Root = (-1 +- Sqrt(-3)) / 2 + // + var red = num === this.p ? this.red : BN.mont(num); + var tinv = new BN(2).toRed(red).redInvm(); + var ntinv = tinv.redNeg(); + var s = new BN(3).toRed(red).redNeg().redSqrt().redMul(tinv); + var l1 = ntinv.redAdd(s).fromRed(); + var l2 = ntinv.redSub(s).fromRed(); + return [l1, l2]; + }; + ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) { + // aprxSqrt >= sqrt(this.n) + var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); // 3.74 + // Run EGCD, until r(L + 1) < aprxSqrt - BN.prototype.cmp = function cmp(num) { - if ((this || _global$z).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$z).negative === 0 && num.negative !== 0) return 1; - var res = this.ucmp(num); - if ((this || _global$z).negative !== 0) return -res | 0; - return res; - }; // Unsigned comparison + var u = lambda; + var v = this.n.clone(); + var x1 = new BN(1); + var y1 = new BN(0); + var x2 = new BN(0); + var y2 = new BN(1); // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n) + var a0; + var b0; // First vector - BN.prototype.ucmp = function ucmp(num) { - // At this point both numbers have the same sign - if ((this || _global$z).length > num.length) return 1; - if ((this || _global$z).length < num.length) return -1; - var res = 0; + var a1; + var b1; // Second vector - for (var i = (this || _global$z).length - 1; i >= 0; i--) { - var a = (this || _global$z).words[i] | 0; - var b = num.words[i] | 0; - if (a === b) continue; + var a2; + var b2; + var prevR; + var i = 0; + var r; + var x; - if (a < b) { - res = -1; - } else if (a > b) { - res = 1; - } + while (u.cmpn(0) !== 0) { + var q = v.div(u); + r = v.sub(q.mul(u)); + x = x2.sub(q.mul(x1)); + var y = y2.sub(q.mul(y1)); + if (!a1 && r.cmp(aprxSqrt) < 0) { + a0 = prevR.neg(); + b0 = x1; + a1 = r.neg(); + b1 = x; + } else if (a1 && ++i === 2) { break; } - return res; - }; + prevR = r; + v = u; + u = r; + x2 = x1; + x1 = x; + y2 = y1; + y1 = y; + } - BN.prototype.gtn = function gtn(num) { - return this.cmpn(num) === 1; - }; + a2 = r.neg(); + b2 = x; + var len1 = a1.sqr().add(b1.sqr()); + var len2 = a2.sqr().add(b2.sqr()); - BN.prototype.gt = function gt(num) { - return this.cmp(num) === 1; - }; + if (len2.cmp(len1) >= 0) { + a2 = a0; + b2 = b0; + } // Normalize signs - BN.prototype.gten = function gten(num) { - return this.cmpn(num) >= 0; - }; - BN.prototype.gte = function gte(num) { - return this.cmp(num) >= 0; - }; + if (a1.negative) { + a1 = a1.neg(); + b1 = b1.neg(); + } - BN.prototype.ltn = function ltn(num) { - return this.cmpn(num) === -1; - }; + if (a2.negative) { + a2 = a2.neg(); + b2 = b2.neg(); + } - BN.prototype.lt = function lt(num) { - return this.cmp(num) === -1; - }; + return [{ + a: a1, + b: b1 + }, { + a: a2, + b: b2 + }]; + }; - BN.prototype.lten = function lten(num) { - return this.cmpn(num) <= 0; - }; + ShortCurve.prototype._endoSplit = function _endoSplit(k) { + var basis = this.endo.basis; + var v1 = basis[0]; + var v2 = basis[1]; + var c1 = v2.b.mul(k).divRound(this.n); + var c2 = v1.b.neg().mul(k).divRound(this.n); + var p1 = c1.mul(v1.a); + var p2 = c2.mul(v2.a); + var q1 = c1.mul(v1.b); + var q2 = c2.mul(v2.b); // Calculate answer - BN.prototype.lte = function lte(num) { - return this.cmp(num) <= 0; + var k1 = k.sub(p1).sub(p2); + var k2 = q1.add(q2).neg(); + return { + k1: k1, + k2: k2 }; + }; - BN.prototype.eqn = function eqn(num) { - return this.cmpn(num) === 0; - }; + ShortCurve.prototype.pointFromX = function pointFromX(x, odd) { + x = new BN(x, 16); + if (!x.red) x = x.toRed(this.red); + var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b); + var y = y2.redSqrt(); + if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error("invalid point"); // XXX Is there any way to tell if the number is odd without converting it + // to non-red form? - BN.prototype.eq = function eq(num) { - return this.cmp(num) === 0; - }; // - // A reduce context, could be using montgomery or something better, depending - // on the `m` itself. - // + var isOdd = y.fromRed().isOdd(); + if (odd && !isOdd || !odd && isOdd) y = y.redNeg(); + return this.point(x, y); + }; + ShortCurve.prototype.validate = function validate(point) { + if (point.inf) return true; + var x = point.x; + var y = point.y; + var ax = this.a.redMul(x); + var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b); + return y.redSqr().redISub(rhs).cmpn(0) === 0; + }; - BN.red = function red(num) { - return new Red(num); - }; + ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) { + var npoints = this._endoWnafT1; + var ncoeffs = this._endoWnafT2; - BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$z).red, "Already a number in reduction context"); - assert((this || _global$z).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$z)._forceRed(ctx); - }; + for (var i = 0; i < points.length; i++) { + var split = this._endoSplit(coeffs[i]); - BN.prototype.fromRed = function fromRed() { - assert((this || _global$z).red, "fromRed works only with numbers in reduction context"); - return (this || _global$z).red.convertFrom(this || _global$z); - }; + var p = points[i]; - BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$z).red = ctx; - return this || _global$z; - }; + var beta = p._getBeta(); - BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$z).red, "Already a number in reduction context"); - return this._forceRed(ctx); - }; + if (split.k1.negative) { + split.k1.ineg(); + p = p.neg(true); + } - BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$z).red, "redAdd works only with red numbers"); - return (this || _global$z).red.add(this || _global$z, num); - }; + if (split.k2.negative) { + split.k2.ineg(); + beta = beta.neg(true); + } - BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$z).red, "redIAdd works only with red numbers"); - return (this || _global$z).red.iadd(this || _global$z, num); - }; + npoints[i * 2] = p; + npoints[i * 2 + 1] = beta; + ncoeffs[i * 2] = split.k1; + ncoeffs[i * 2 + 1] = split.k2; + } - BN.prototype.redSub = function redSub(num) { - assert((this || _global$z).red, "redSub works only with red numbers"); - return (this || _global$z).red.sub(this || _global$z, num); - }; + var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); // Clean-up references to points and coefficients - BN.prototype.redISub = function redISub(num) { - assert((this || _global$z).red, "redISub works only with red numbers"); - return (this || _global$z).red.isub(this || _global$z, num); - }; - BN.prototype.redShl = function redShl(num) { - assert((this || _global$z).red, "redShl works only with red numbers"); - return (this || _global$z).red.shl(this || _global$z, num); - }; + for (var j = 0; j < i * 2; j++) { + npoints[j] = null; + ncoeffs[j] = null; + } - BN.prototype.redMul = function redMul(num) { - assert((this || _global$z).red, "redMul works only with red numbers"); + return res; + }; - (this || _global$z).red._verify2(this || _global$z, num); + function Point(curve, x, y, isRed) { + Base.BasePoint.call(this, curve, "affine"); - return (this || _global$z).red.mul(this || _global$z, num); - }; + if (x === null && y === null) { + this.x = null; + this.y = null; + this.inf = true; + } else { + this.x = new BN(x, 16); + this.y = new BN(y, 16); // Force redgomery representation when loading from JSON - BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$z).red, "redMul works only with red numbers"); + if (isRed) { + this.x.forceRed(this.curve.red); + this.y.forceRed(this.curve.red); + } - (this || _global$z).red._verify2(this || _global$z, num); + if (!this.x.red) this.x = this.x.toRed(this.curve.red); + if (!this.y.red) this.y = this.y.toRed(this.curve.red); + this.inf = false; + } + } - return (this || _global$z).red.imul(this || _global$z, num); - }; + inherits(Point, Base.BasePoint); - BN.prototype.redSqr = function redSqr() { - assert((this || _global$z).red, "redSqr works only with red numbers"); + ShortCurve.prototype.point = function point(x, y, isRed) { + return new Point(this, x, y, isRed); + }; - (this || _global$z).red._verify1(this || _global$z); + ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) { + return Point.fromJSON(this, obj, red); + }; - return (this || _global$z).red.sqr(this || _global$z); - }; + Point.prototype._getBeta = function _getBeta() { + if (!this.curve.endo) return; + var pre = this.precomputed; + if (pre && pre.beta) return pre.beta; + var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y); - BN.prototype.redISqr = function redISqr() { - assert((this || _global$z).red, "redISqr works only with red numbers"); + if (pre) { + var curve = this.curve; - (this || _global$z).red._verify1(this || _global$z); + var endoMul = function (p) { + return curve.point(p.x.redMul(curve.endo.beta), p.y); + }; - return (this || _global$z).red.isqr(this || _global$z); - }; // Square root over p + pre.beta = beta; + beta.precomputed = { + beta: null, + naf: pre.naf && { + wnd: pre.naf.wnd, + points: pre.naf.points.map(endoMul) + }, + doubles: pre.doubles && { + step: pre.doubles.step, + points: pre.doubles.points.map(endoMul) + } + }; + } + return beta; + }; - BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$z).red, "redSqrt works only with red numbers"); + Point.prototype.toJSON = function toJSON() { + if (!this.precomputed) return [this.x, this.y]; + return [this.x, this.y, this.precomputed && { + doubles: this.precomputed.doubles && { + step: this.precomputed.doubles.step, + points: this.precomputed.doubles.points.slice(1) + }, + naf: this.precomputed.naf && { + wnd: this.precomputed.naf.wnd, + points: this.precomputed.naf.points.slice(1) + } + }]; + }; - (this || _global$z).red._verify1(this || _global$z); + Point.fromJSON = function fromJSON(curve, obj, red) { + if (typeof obj === "string") obj = JSON.parse(obj); + var res = curve.point(obj[0], obj[1], red); + if (!obj[2]) return res; - return (this || _global$z).red.sqrt(this || _global$z); + function obj2point(obj) { + return curve.point(obj[0], obj[1], red); + } + + var pre = obj[2]; + res.precomputed = { + beta: null, + doubles: pre.doubles && { + step: pre.doubles.step, + points: [res].concat(pre.doubles.points.map(obj2point)) + }, + naf: pre.naf && { + wnd: pre.naf.wnd, + points: [res].concat(pre.naf.points.map(obj2point)) + } }; + return res; + }; - BN.prototype.redInvm = function redInvm() { - assert((this || _global$z).red, "redInvm works only with red numbers"); + Point.prototype.inspect = function inspect() { + if (this.isInfinity()) return ""; + return ""; + }; - (this || _global$z).red._verify1(this || _global$z); + Point.prototype.isInfinity = function isInfinity() { + return this.inf; + }; - return (this || _global$z).red.invm(this || _global$z); - }; // Return negative clone of `this` % `red modulo` + Point.prototype.add = function add(p) { + // O + P = P + if (this.inf) return p; // P + O = P + if (p.inf) return this; // P + P = 2P - BN.prototype.redNeg = function redNeg() { - assert((this || _global$z).red, "redNeg works only with red numbers"); + if (this.eq(p)) return this.dbl(); // P + (-P) = O - (this || _global$z).red._verify1(this || _global$z); + if (this.neg().eq(p)) return this.curve.point(null, null); // P + Q = O - return (this || _global$z).red.neg(this || _global$z); - }; + if (this.x.cmp(p.x) === 0) return this.curve.point(null, null); + var c = this.y.redSub(p.y); + if (c.cmpn(0) !== 0) c = c.redMul(this.x.redSub(p.x).redInvm()); + var nx = c.redSqr().redISub(this.x).redISub(p.x); + var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); + return this.curve.point(nx, ny); + }; - BN.prototype.redPow = function redPow(num) { - assert((this || _global$z).red && !num.red, "redPow(normalNum)"); + Point.prototype.dbl = function dbl() { + if (this.inf) return this; // 2P = O - (this || _global$z).red._verify1(this || _global$z); + var ys1 = this.y.redAdd(this.y); + if (ys1.cmpn(0) === 0) return this.curve.point(null, null); + var a = this.curve.a; + var x2 = this.x.redSqr(); + var dyinv = ys1.redInvm(); + var c = x2.redAdd(x2).redIAdd(x2).redIAdd(a).redMul(dyinv); + var nx = c.redSqr().redISub(this.x.redAdd(this.x)); + var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); + return this.curve.point(nx, ny); + }; - return (this || _global$z).red.pow(this || _global$z, num); - }; // Prime numbers with efficient reduction + Point.prototype.getX = function getX() { + return this.x.fromRed(); + }; + Point.prototype.getY = function getY() { + return this.y.fromRed(); + }; - var primes = { - k256: null, - p224: null, - p192: null, - p25519: null - }; // Pseudo-Mersenne prime + Point.prototype.mul = function mul(k) { + k = new BN(k, 16); + if (this.isInfinity()) return this;else if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else if (this.curve.endo) return this.curve._endoWnafMulAdd([this], [k]);else return this.curve._wnafMul(this, k); + }; - function MPrime(name, p) { - // P = 2 ^ N - K - (this || _global$z).name = name; - (this || _global$z).p = new BN(p, 16); - (this || _global$z).n = (this || _global$z).p.bitLength(); - (this || _global$z).k = new BN(1).iushln((this || _global$z).n).isub((this || _global$z).p); - (this || _global$z).tmp = this._tmp(); - } + Point.prototype.mulAdd = function mulAdd(k1, p2, k2) { + var points = [this, p2]; + var coeffs = [k1, k2]; + if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs);else return this.curve._wnafMulAdd(1, points, coeffs, 2); + }; - MPrime.prototype._tmp = function _tmp() { - var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$z).n / 13)); - return tmp; - }; + Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) { + var points = [this, p2]; + var coeffs = [k1, k2]; + if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs, true);else return this.curve._wnafMulAdd(1, points, coeffs, 2, true); + }; - MPrime.prototype.ireduce = function ireduce(num) { - // Assumes that `num` is less than `P^2` - // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) - var r = num; - var rlen; + Point.prototype.eq = function eq(p) { + return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0); + }; - do { - this.split(r, (this || _global$z).tmp); - r = this.imulK(r); - r = r.iadd((this || _global$z).tmp); - rlen = r.bitLength(); - } while (rlen > (this || _global$z).n); + Point.prototype.neg = function neg(_precompute) { + if (this.inf) return this; + var res = this.curve.point(this.x, this.y.redNeg()); - var cmp = rlen < (this || _global$z).n ? -1 : r.ucmp((this || _global$z).p); + if (_precompute && this.precomputed) { + var pre = this.precomputed; - if (cmp === 0) { - r.words[0] = 0; - r.length = 1; - } else if (cmp > 0) { - r.isub((this || _global$z).p); - } else { - if (r.strip !== undefined) { - // r is BN v4 instance - r.strip(); - } else { - // r is BN v5 instance - r._strip(); + var negate = function (p) { + return p.neg(); + }; + + res.precomputed = { + naf: pre.naf && { + wnd: pre.naf.wnd, + points: pre.naf.points.map(negate) + }, + doubles: pre.doubles && { + step: pre.doubles.step, + points: pre.doubles.points.map(negate) } - } + }; + } - return r; - }; + return res; + }; - MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$z).n, 0, out); - }; + Point.prototype.toJ = function toJ() { + if (this.inf) return this.curve.jpoint(null, null, null); + var res = this.curve.jpoint(this.x, this.y, this.curve.one); + return res; + }; - MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$z).k); - }; + function JPoint(curve, x, y, z) { + Base.BasePoint.call(this, curve, "jacobian"); - function K256() { - MPrime.call(this || _global$z, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + if (x === null && y === null && z === null) { + this.x = this.curve.one; + this.y = this.curve.one; + this.z = new BN(0); + } else { + this.x = new BN(x, 16); + this.y = new BN(y, 16); + this.z = new BN(z, 16); } - inherits(K256, MPrime); + if (!this.x.red) this.x = this.x.toRed(this.curve.red); + if (!this.y.red) this.y = this.y.toRed(this.curve.red); + if (!this.z.red) this.z = this.z.toRed(this.curve.red); + this.zOne = this.z === this.curve.one; + } - K256.prototype.split = function split(input, output) { - // 256 = 9 * 26 + 22 - var mask = 4194303; - var outLen = Math.min(input.length, 9); + inherits(JPoint, Base.BasePoint); - for (var i = 0; i < outLen; i++) { - output.words[i] = input.words[i]; - } + ShortCurve.prototype.jpoint = function jpoint(x, y, z) { + return new JPoint(this, x, y, z); + }; - output.length = outLen; + JPoint.prototype.toP = function toP() { + if (this.isInfinity()) return this.curve.point(null, null); + var zinv = this.z.redInvm(); + var zinv2 = zinv.redSqr(); + var ax = this.x.redMul(zinv2); + var ay = this.y.redMul(zinv2).redMul(zinv); + return this.curve.point(ax, ay); + }; - if (input.length <= 9) { - input.words[0] = 0; - input.length = 1; - return; - } // Shift by 9 limbs + JPoint.prototype.neg = function neg() { + return this.curve.jpoint(this.x, this.y.redNeg(), this.z); + }; + JPoint.prototype.add = function add(p) { + // O + P = P + if (this.isInfinity()) return p; // P + O = P - var prev = input.words[9]; - output.words[output.length++] = prev & mask; + if (p.isInfinity()) return this; // 12M + 4S + 7A - for (i = 10; i < input.length; i++) { - var next = input.words[i] | 0; - input.words[i - 10] = (next & mask) << 4 | prev >>> 22; - prev = next; - } + var pz2 = p.z.redSqr(); + var z2 = this.z.redSqr(); + var u1 = this.x.redMul(pz2); + var u2 = p.x.redMul(z2); + var s1 = this.y.redMul(pz2.redMul(p.z)); + var s2 = p.y.redMul(z2.redMul(this.z)); + var h = u1.redSub(u2); + var r = s1.redSub(s2); - prev >>>= 22; - input.words[i - 10] = prev; + if (h.cmpn(0) === 0) { + if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl(); + } - if (prev === 0 && input.length > 10) { - input.length -= 10; - } else { - input.length -= 9; - } - }; + var h2 = h.redSqr(); + var h3 = h2.redMul(h); + var v = u1.redMul(h2); + var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v); + var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3)); + var nz = this.z.redMul(p.z).redMul(h); + return this.curve.jpoint(nx, ny, nz); + }; - K256.prototype.imulK = function imulK(num) { - // K = 0x1000003d1 = [ 0x40, 0x3d1 ] - num.words[num.length] = 0; - num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + JPoint.prototype.mixedAdd = function mixedAdd(p) { + // O + P = P + if (this.isInfinity()) return p.toJ(); // P + O = P - var lo = 0; + if (p.isInfinity()) return this; // 8M + 3S + 7A - for (var i = 0; i < num.length; i++) { - var w = num.words[i] | 0; - lo += w * 977; - num.words[i] = lo & 67108863; - lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction + var z2 = this.z.redSqr(); + var u1 = this.x; + var u2 = p.x.redMul(z2); + var s1 = this.y; + var s2 = p.y.redMul(z2).redMul(this.z); + var h = u1.redSub(u2); + var r = s1.redSub(s2); + + if (h.cmpn(0) === 0) { + if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl(); + } + var h2 = h.redSqr(); + var h3 = h2.redMul(h); + var v = u1.redMul(h2); + var nx = r.redSqr().redIAdd(h3).redISub(v).redISub(v); + var ny = r.redMul(v.redISub(nx)).redISub(s1.redMul(h3)); + var nz = this.z.redMul(h); + return this.curve.jpoint(nx, ny, nz); + }; - if (num.words[num.length - 1] === 0) { - num.length--; + JPoint.prototype.dblp = function dblp(pow) { + if (pow === 0) return this; + if (this.isInfinity()) return this; + if (!pow) return this.dbl(); + var i; - if (num.words[num.length - 1] === 0) { - num.length--; - } - } + if (this.curve.zeroA || this.curve.threeA) { + var r = this; - return num; - }; + for (i = 0; i < pow; i++) r = r.dbl(); - function P224() { - MPrime.call(this || _global$z, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); - } + return r; + } // 1M + 2S + 1A + N * (4S + 5M + 8A) + // N = 1 => 6M + 6S + 9A - inherits(P224, MPrime); - function P192() { - MPrime.call(this || _global$z, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); - } + var a = this.curve.a; + var tinv = this.curve.tinv; + var jx = this.x; + var jy = this.y; + var jz = this.z; + var jz4 = jz.redSqr().redSqr(); // Reuse results - inherits(P192, MPrime); + var jyd = jy.redAdd(jy); - function P25519() { - // 2 ^ 255 - 19 - MPrime.call(this || _global$z, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + for (i = 0; i < pow; i++) { + var jx2 = jx.redSqr(); + var jyd2 = jyd.redSqr(); + var jyd4 = jyd2.redSqr(); + var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4)); + var t1 = jx.redMul(jyd2); + var nx = c.redSqr().redISub(t1.redAdd(t1)); + var t2 = t1.redISub(nx); + var dny = c.redMul(t2); + dny = dny.redIAdd(dny).redISub(jyd4); + var nz = jyd.redMul(jz); + if (i + 1 < pow) jz4 = jz4.redMul(jyd4); + jx = nx; + jz = nz; + jyd = dny; } - inherits(P25519, MPrime); + return this.curve.jpoint(jx, jyd.redMul(tinv), jz); + }; - P25519.prototype.imulK = function imulK(num) { - // K = 0x13 - var carry = 0; + JPoint.prototype.dbl = function dbl() { + if (this.isInfinity()) return this; + if (this.curve.zeroA) return this._zeroDbl();else if (this.curve.threeA) return this._threeDbl();else return this._dbl(); + }; - for (var i = 0; i < num.length; i++) { - var hi = (num.words[i] | 0) * 19 + carry; - var lo = hi & 67108863; - hi >>>= 26; - num.words[i] = lo; - carry = hi; - } + JPoint.prototype._zeroDbl = function _zeroDbl() { + var nx; + var ny; + var nz; // Z = 1 - if (carry !== 0) { - num.words[num.length++] = carry; - } + if (this.zOne) { + // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html + // #doubling-mdbl-2007-bl + // 1M + 5S + 14A + // XX = X1^2 + var xx = this.x.redSqr(); // YY = Y1^2 - return num; - }; // Exported mostly for testing purposes, use plain name instead + var yy = this.y.redSqr(); // YYYY = YY^2 + var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY) - BN._prime = function prime(name) { - // Cached version of prime - if (primes[name]) return primes[name]; - var prime; + var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); + s = s.redIAdd(s); // M = 3 * XX + a; a = 0 - if (name === "k256") { - prime = new K256(); - } else if (name === "p224") { - prime = new P224(); - } else if (name === "p192") { - prime = new P192(); - } else if (name === "p25519") { - prime = new P25519(); - } else { - throw new Error("Unknown prime " + name); - } + var m = xx.redAdd(xx).redIAdd(xx); // T = M ^ 2 - 2*S - primes[name] = prime; - return prime; - }; // - // Base reduction engine - // + var t = m.redSqr().redISub(s).redISub(s); // 8 * YYYY + var yyyy8 = yyyy.redIAdd(yyyy); + yyyy8 = yyyy8.redIAdd(yyyy8); + yyyy8 = yyyy8.redIAdd(yyyy8); // X3 = T - function Red(m) { - if (typeof m === "string") { - var prime = BN._prime(m); + nx = t; // Y3 = M * (S - T) - 8 * YYYY - (this || _global$z).m = prime.p; - (this || _global$z).prime = prime; - } else { - assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$z).m = m; - (this || _global$z).prime = null; - } - } + ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2*Y1 - Red.prototype._verify1 = function _verify1(a) { - assert(a.negative === 0, "red works only with positives"); - assert(a.red, "red works only with red numbers"); - }; + nz = this.y.redAdd(this.y); + } else { + // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html + // #doubling-dbl-2009-l + // 2M + 5S + 13A + // A = X1^2 + var a = this.x.redSqr(); // B = Y1^2 - Red.prototype._verify2 = function _verify2(a, b) { - assert((a.negative | b.negative) === 0, "red works only with positives"); - assert(a.red && a.red === b.red, "red works only with red numbers"); - }; + var b = this.y.redSqr(); // C = B^2 - Red.prototype.imod = function imod(a) { - if ((this || _global$z).prime) return (this || _global$z).prime.ireduce(a)._forceRed(this || _global$z); - return a.umod((this || _global$z).m)._forceRed(this || _global$z); - }; + var c = b.redSqr(); // D = 2 * ((X1 + B)^2 - A - C) - Red.prototype.neg = function neg(a) { - if (a.isZero()) { - return a.clone(); - } + var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c); + d = d.redIAdd(d); // E = 3 * A - return (this || _global$z).m.sub(a)._forceRed(this || _global$z); - }; + var e = a.redAdd(a).redIAdd(a); // F = E^2 - Red.prototype.add = function add(a, b) { - this._verify2(a, b); + var f = e.redSqr(); // 8 * C - var res = a.add(b); + var c8 = c.redIAdd(c); + c8 = c8.redIAdd(c8); + c8 = c8.redIAdd(c8); // X3 = F - 2 * D - if (res.cmp((this || _global$z).m) >= 0) { - res.isub((this || _global$z).m); - } + nx = f.redISub(d).redISub(d); // Y3 = E * (D - X3) - 8 * C - return res._forceRed(this || _global$z); - }; + ny = e.redMul(d.redISub(nx)).redISub(c8); // Z3 = 2 * Y1 * Z1 - Red.prototype.iadd = function iadd(a, b) { - this._verify2(a, b); + nz = this.y.redMul(this.z); + nz = nz.redIAdd(nz); + } - var res = a.iadd(b); + return this.curve.jpoint(nx, ny, nz); + }; - if (res.cmp((this || _global$z).m) >= 0) { - res.isub((this || _global$z).m); - } + JPoint.prototype._threeDbl = function _threeDbl() { + var nx; + var ny; + var nz; // Z = 1 - return res; - }; + if (this.zOne) { + // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html + // #doubling-mdbl-2007-bl + // 1M + 5S + 15A + // XX = X1^2 + var xx = this.x.redSqr(); // YY = Y1^2 - Red.prototype.sub = function sub(a, b) { - this._verify2(a, b); + var yy = this.y.redSqr(); // YYYY = YY^2 - var res = a.sub(b); + var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY) - if (res.cmpn(0) < 0) { - res.iadd((this || _global$z).m); - } + var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); + s = s.redIAdd(s); // M = 3 * XX + a - return res._forceRed(this || _global$z); - }; + var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); // T = M^2 - 2 * S - Red.prototype.isub = function isub(a, b) { - this._verify2(a, b); + var t = m.redSqr().redISub(s).redISub(s); // X3 = T - var res = a.isub(b); + nx = t; // Y3 = M * (S - T) - 8 * YYYY - if (res.cmpn(0) < 0) { - res.iadd((this || _global$z).m); - } + var yyyy8 = yyyy.redIAdd(yyyy); + yyyy8 = yyyy8.redIAdd(yyyy8); + yyyy8 = yyyy8.redIAdd(yyyy8); + ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2 * Y1 - return res; - }; + nz = this.y.redAdd(this.y); + } else { + // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b + // 3M + 5S + // delta = Z1^2 + var delta = this.z.redSqr(); // gamma = Y1^2 - Red.prototype.shl = function shl(a, num) { - this._verify1(a); + var gamma = this.y.redSqr(); // beta = X1 * gamma - return this.imod(a.ushln(num)); - }; + var beta = this.x.redMul(gamma); // alpha = 3 * (X1 - delta) * (X1 + delta) - Red.prototype.imul = function imul(a, b) { - this._verify2(a, b); + var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta)); + alpha = alpha.redAdd(alpha).redIAdd(alpha); // X3 = alpha^2 - 8 * beta - return this.imod(a.imul(b)); - }; + var beta4 = beta.redIAdd(beta); + beta4 = beta4.redIAdd(beta4); + var beta8 = beta4.redAdd(beta4); + nx = alpha.redSqr().redISub(beta8); // Z3 = (Y1 + Z1)^2 - gamma - delta - Red.prototype.mul = function mul(a, b) { - this._verify2(a, b); + nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2 - return this.imod(a.mul(b)); - }; + var ggamma8 = gamma.redSqr(); + ggamma8 = ggamma8.redIAdd(ggamma8); + ggamma8 = ggamma8.redIAdd(ggamma8); + ggamma8 = ggamma8.redIAdd(ggamma8); + ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8); + } - Red.prototype.isqr = function isqr(a) { - return this.imul(a, a.clone()); - }; + return this.curve.jpoint(nx, ny, nz); + }; - Red.prototype.sqr = function sqr(a) { - return this.mul(a, a); - }; + JPoint.prototype._dbl = function _dbl() { + var a = this.curve.a; // 4M + 6S + 10A - Red.prototype.sqrt = function sqrt(a) { - if (a.isZero()) return a.clone(); + var jx = this.x; + var jy = this.y; + var jz = this.z; + var jz4 = jz.redSqr().redSqr(); + var jx2 = jx.redSqr(); + var jy2 = jy.redSqr(); + var c = jx2.redAdd(jx2).redIAdd(jx2).redIAdd(a.redMul(jz4)); + var jxd4 = jx.redAdd(jx); + jxd4 = jxd4.redIAdd(jxd4); + var t1 = jxd4.redMul(jy2); + var nx = c.redSqr().redISub(t1.redAdd(t1)); + var t2 = t1.redISub(nx); + var jyd8 = jy2.redSqr(); + jyd8 = jyd8.redIAdd(jyd8); + jyd8 = jyd8.redIAdd(jyd8); + jyd8 = jyd8.redIAdd(jyd8); + var ny = c.redMul(t2).redISub(jyd8); + var nz = jy.redAdd(jy).redMul(jz); + return this.curve.jpoint(nx, ny, nz); + }; - var mod3 = (this || _global$z).m.andln(3); + JPoint.prototype.trpl = function trpl() { + if (!this.curve.zeroA) return this.dbl().add(this); // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl + // 5M + 10S + ... + // XX = X1^2 - assert(mod3 % 2 === 1); // Fast case + var xx = this.x.redSqr(); // YY = Y1^2 - if (mod3 === 3) { - var pow = (this || _global$z).m.add(new BN(1)).iushrn(2); + var yy = this.y.redSqr(); // ZZ = Z1^2 - return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) - // - // Find Q and S, that Q * 2 ^ S = (P - 1) + var zz = this.z.redSqr(); // YYYY = YY^2 + var yyyy = yy.redSqr(); // M = 3 * XX + a * ZZ2; a = 0 - var q = (this || _global$z).m.subn(1); + var m = xx.redAdd(xx).redIAdd(xx); // MM = M^2 - var s = 0; + var mm = m.redSqr(); // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM - while (!q.isZero() && q.andln(1) === 0) { - s++; - q.iushrn(1); - } + var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); + e = e.redIAdd(e); + e = e.redAdd(e).redIAdd(e); + e = e.redISub(mm); // EE = E^2 - assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$z); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. + var ee = e.redSqr(); // T = 16*YYYY - var lpow = (this || _global$z).m.subn(1).iushrn(1); + var t = yyyy.redIAdd(yyyy); + t = t.redIAdd(t); + t = t.redIAdd(t); + t = t.redIAdd(t); // U = (M + E)^2 - MM - EE - T - var z = (this || _global$z).m.bitLength(); + var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); // X3 = 4 * (X1 * EE - 4 * YY * U) - z = new BN(2 * z * z).toRed(this || _global$z); + var yyu4 = yy.redMul(u); + yyu4 = yyu4.redIAdd(yyu4); + yyu4 = yyu4.redIAdd(yyu4); + var nx = this.x.redMul(ee).redISub(yyu4); + nx = nx.redIAdd(nx); + nx = nx.redIAdd(nx); // Y3 = 8 * Y1 * (U * (T - U) - E * EE) - while (this.pow(z, lpow).cmp(nOne) !== 0) { - z.redIAdd(nOne); - } + var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee))); + ny = ny.redIAdd(ny); + ny = ny.redIAdd(ny); + ny = ny.redIAdd(ny); // Z3 = (Z1 + E)^2 - ZZ - EE - var c = this.pow(z, q); - var r = this.pow(a, q.addn(1).iushrn(1)); - var t = this.pow(a, q); - var m = s; + var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee); + return this.curve.jpoint(nx, ny, nz); + }; - while (t.cmp(one) !== 0) { - var tmp = t; + JPoint.prototype.mul = function mul(k, kbase) { + k = new BN(k, kbase); + return this.curve._wnafMul(this, k); + }; - for (var i = 0; tmp.cmp(one) !== 0; i++) { - tmp = tmp.redSqr(); - } + JPoint.prototype.eq = function eq(p) { + if (p.type === "affine") return this.eq(p.toJ()); + if (this === p) return true; // x1 * z2^2 == x2 * z1^2 - assert(i < m); - var b = this.pow(c, new BN(1).iushln(m - i - 1)); - r = r.redMul(b); - c = b.redSqr(); - t = t.redMul(c); - m = i; - } + var z2 = this.z.redSqr(); + var pz2 = p.z.redSqr(); + if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false; // y1 * z2^3 == y2 * z1^3 - return r; - }; + var z3 = z2.redMul(this.z); + var pz3 = pz2.redMul(p.z); + return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0; + }; - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$z).m); + JPoint.prototype.eqXToP = function eqXToP(x) { + var zs = this.z.redSqr(); + var rx = x.toRed(this.curve.red).redMul(zs); + if (this.x.cmp(rx) === 0) return true; + var xc = x.clone(); + var t = this.curve.redN.redMul(zs); - if (inv.negative !== 0) { - inv.negative = 0; - return this.imod(inv).redNeg(); - } else { - return this.imod(inv); - } - }; + for (;;) { + xc.iadd(this.curve.n); + if (xc.cmp(this.curve.p) >= 0) return false; + rx.redIAdd(t); + if (this.x.cmp(rx) === 0) return true; + } + }; - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$z); - if (num.cmpn(1) === 0) return a.clone(); - var windowSize = 4; - var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$z); - wnd[1] = a; + JPoint.prototype.inspect = function inspect() { + if (this.isInfinity()) return ""; + return ""; + }; - for (var i = 2; i < wnd.length; i++) { - wnd[i] = this.mul(wnd[i - 1], a); - } + JPoint.prototype.isInfinity = function isInfinity() { + // XXX This code assumes that zero is always zero in red + return this.z.cmpn(0) === 0; + }; - var res = wnd[0]; - var current = 0; - var currentLen = 0; - var start = num.bitLength() % 26; + return exports$R$1; +} - if (start === 0) { - start = 26; - } +var exports$Q$1 = {}, + _dewExec$Q$1 = false; +function dew$Q$1() { + if (_dewExec$Q$1) return exports$Q$1; + _dewExec$Q$1 = true; - for (i = num.length - 1; i >= 0; i--) { - var word = num.words[i]; + var BN = dew$V$1(); - for (var j = start - 1; j >= 0; j--) { - var bit = word >> j & 1; + var inherits = dew$f$2(); - if (res !== wnd[0]) { - res = this.sqr(res); - } + var Base = dew$S$1(); - if (bit === 0 && current === 0) { - currentLen = 0; - continue; - } + var utils = dew$T$1(); - current <<= 1; - current |= bit; - currentLen++; - if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; - res = this.mul(res, wnd[current]); - currentLen = 0; - current = 0; - } + function MontCurve(conf) { + Base.call(this, "mont", conf); + this.a = new BN(conf.a, 16).toRed(this.red); + this.b = new BN(conf.b, 16).toRed(this.red); + this.i4 = new BN(4).toRed(this.red).redInvm(); + this.two = new BN(2).toRed(this.red); + this.a24 = this.i4.redMul(this.a.redAdd(this.two)); + } - start = 26; - } + inherits(MontCurve, Base); + exports$Q$1 = MontCurve; - return res; - }; + MontCurve.prototype.validate = function validate(point) { + var x = point.normalize().x; + var x2 = x.redSqr(); + var rhs = x2.redMul(x).redAdd(x2.redMul(this.a)).redAdd(x); + var y = rhs.redSqrt(); + return y.redSqr().cmp(rhs) === 0; + }; - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$z).m); - return r === num ? r.clone() : r; - }; + function Point(curve, x, z) { + Base.BasePoint.call(this, curve, "projective"); - Red.prototype.convertFrom = function convertFrom(num) { - var res = num.clone(); - res.red = null; - return res; - }; // - // Montgomery method engine - // + if (x === null && z === null) { + this.x = this.curve.one; + this.z = this.curve.zero; + } else { + this.x = new BN(x, 16); + this.z = new BN(z, 16); + if (!this.x.red) this.x = this.x.toRed(this.curve.red); + if (!this.z.red) this.z = this.z.toRed(this.curve.red); + } + } + inherits(Point, Base.BasePoint); - BN.mont = function mont(num) { - return new Mont(num); - }; + MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) { + return this.point(utils.toArray(bytes, enc), 1); + }; - function Mont(m) { - Red.call(this || _global$z, m); - (this || _global$z).shift = (this || _global$z).m.bitLength(); + MontCurve.prototype.point = function point(x, z) { + return new Point(this, x, z); + }; - if ((this || _global$z).shift % 26 !== 0) { - (this || _global$z).shift += 26 - (this || _global$z).shift % 26; - } + MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) { + return Point.fromJSON(this, obj); + }; - (this || _global$z).r = new BN(1).iushln((this || _global$z).shift); - (this || _global$z).r2 = this.imod((this || _global$z).r.sqr()); - (this || _global$z).rinv = (this || _global$z).r._invmp((this || _global$z).m); - (this || _global$z).minv = (this || _global$z).rinv.mul((this || _global$z).r).isubn(1).div((this || _global$z).m); - (this || _global$z).minv = (this || _global$z).minv.umod((this || _global$z).r); - (this || _global$z).minv = (this || _global$z).r.sub((this || _global$z).minv); - } + Point.prototype.precompute = function precompute() {// No-op + }; - inherits(Mont, Red); + Point.prototype._encode = function _encode() { + return this.getX().toArray("be", this.curve.p.byteLength()); + }; - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$z).shift)); - }; + Point.fromJSON = function fromJSON(curve, obj) { + return new Point(curve, obj[0], obj[1] || curve.one); + }; - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$z).rinv)); - r.red = null; - return r; - }; + Point.prototype.inspect = function inspect() { + if (this.isInfinity()) return ""; + return ""; + }; - Mont.prototype.imul = function imul(a, b) { - if (a.isZero() || b.isZero()) { - a.words[0] = 0; - a.length = 1; - return a; - } + Point.prototype.isInfinity = function isInfinity() { + // XXX This code assumes that zero is always zero in red + return this.z.cmpn(0) === 0; + }; - var t = a.imul(b); - var c = t.maskn((this || _global$z).shift).mul((this || _global$z).minv).imaskn((this || _global$z).shift).mul((this || _global$z).m); - var u = t.isub(c).iushrn((this || _global$z).shift); - var res = u; + Point.prototype.dbl = function dbl() { + // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3 + // 2M + 2S + 4A + // A = X1 + Z1 + var a = this.x.redAdd(this.z); // AA = A^2 - if (u.cmp((this || _global$z).m) >= 0) { - res = u.isub((this || _global$z).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$z).m); - } + var aa = a.redSqr(); // B = X1 - Z1 - return res._forceRed(this || _global$z); - }; + var b = this.x.redSub(this.z); // BB = B^2 - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$z); - var t = a.mul(b); - var c = t.maskn((this || _global$z).shift).mul((this || _global$z).minv).imaskn((this || _global$z).shift).mul((this || _global$z).m); - var u = t.isub(c).iushrn((this || _global$z).shift); - var res = u; + var bb = b.redSqr(); // C = AA - BB - if (u.cmp((this || _global$z).m) >= 0) { - res = u.isub((this || _global$z).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$z).m); - } + var c = aa.redSub(bb); // X3 = AA * BB - return res._forceRed(this || _global$z); - }; + var nx = aa.redMul(bb); // Z3 = C * (BB + A24 * C) - Mont.prototype.invm = function invm(a) { - // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$z).m).mul((this || _global$z).r2)); - return res._forceRed(this || _global$z); - }; - })(module$a, exports$1Y); + var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c))); + return this.curve.point(nx, nz); + }; - return module$a.exports; -} + Point.prototype.add = function add() { + throw new Error("Not supported on Montgomery curve"); + }; -var exports$1X = {}, - _dewExec$1W = false; -var module$9 = { - exports: exports$1X -}; + Point.prototype.diffAdd = function diffAdd(p, diff) { + // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3 + // 4M + 2S + 6A + // A = X2 + Z2 + var a = this.x.redAdd(this.z); // B = X2 - Z2 -var _global$y = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + var b = this.x.redSub(this.z); // C = X3 + Z3 -function dew$1W() { - if (_dewExec$1W) return module$9.exports; - _dewExec$1W = true; + var c = p.x.redAdd(p.z); // D = X3 - Z3 - (function (module, exports) { + var d = p.x.redSub(p.z); // DA = D * A - function assert(val, msg) { - if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. + var da = d.redMul(a); // CB = C * B + var cb = c.redMul(b); // X5 = Z1 * (DA + CB)^2 - function inherits(ctor, superCtor) { - ctor.super_ = superCtor; + var nx = diff.z.redMul(da.redAdd(cb).redSqr()); // Z5 = X1 * (DA - CB)^2 - var TempCtor = function () {}; + var nz = diff.x.redMul(da.redISub(cb).redSqr()); + return this.curve.point(nx, nz); + }; - TempCtor.prototype = superCtor.prototype; - ctor.prototype = new TempCtor(); - ctor.prototype.constructor = ctor; - } // BN + Point.prototype.mul = function mul(k) { + var t = k.clone(); + var a = this; // (N / 2) * Q + Q + var b = this.curve.point(null, null); // (N / 2) * Q - function BN(number, base, endian) { - if (BN.isBN(number)) { - return number; - } + var c = this; // Q - (this || _global$y).negative = 0; - (this || _global$y).words = null; - (this || _global$y).length = 0; // Reduction context + for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) bits.push(t.andln(1)); - (this || _global$y).red = null; + for (var i = bits.length - 1; i >= 0; i--) { + if (bits[i] === 0) { + // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q + a = a.diffAdd(b, c); // N * Q = 2 * ((N / 2) * Q + Q)) - if (number !== null) { - if (base === "le" || base === "be") { - endian = base; - base = 10; - } + b = b.dbl(); + } else { + // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q) + b = a.diffAdd(b, c); // N * Q + Q = 2 * ((N / 2) * Q + Q) - this._init(number || 0, base || 10, endian || "be"); + a = a.dbl(); } } - if (typeof module === "object") { - module.exports = BN; - } else { - exports.BN = BN; - } + return b; + }; - BN.BN = BN; - BN.wordSize = 26; - var Buffer; + Point.prototype.mulAdd = function mulAdd() { + throw new Error("Not supported on Montgomery curve"); + }; - try { - if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { - Buffer = window.Buffer; - } else { - Buffer = buffer.Buffer; - } - } catch (e) {} + Point.prototype.jumlAdd = function jumlAdd() { + throw new Error("Not supported on Montgomery curve"); + }; + + Point.prototype.eq = function eq(other) { + return this.getX().cmp(other.getX()) === 0; + }; + + Point.prototype.normalize = function normalize() { + this.x = this.x.redMul(this.z.redInvm()); + this.z = this.curve.one; + return this; + }; - BN.isBN = function isBN(num) { - if (num instanceof BN) { - return true; - } + Point.prototype.getX = function getX() { + // Normalize coordinates + this.normalize(); + return this.x.fromRed(); + }; - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); - }; + return exports$Q$1; +} - BN.max = function max(left, right) { - if (left.cmp(right) > 0) return left; - return right; - }; +var exports$P$1 = {}, + _dewExec$P$1 = false; +function dew$P$1() { + if (_dewExec$P$1) return exports$P$1; + _dewExec$P$1 = true; - BN.min = function min(left, right) { - if (left.cmp(right) < 0) return left; - return right; - }; + var utils = dew$T$1(); - BN.prototype._init = function init(number, base, endian) { - if (typeof number === "number") { - return this._initNumber(number, base, endian); - } + var BN = dew$V$1(); - if (typeof number === "object") { - return this._initArray(number, base, endian); - } + var inherits = dew$f$2(); - if (base === "hex") { - base = 16; - } + var Base = dew$S$1(); - assert(base === (base | 0) && base >= 2 && base <= 36); - number = number.toString().replace(/\s+/g, ""); - var start = 0; + var assert = utils.assert; - if (number[0] === "-") { - start++; - (this || _global$y).negative = 1; - } + function EdwardsCurve(conf) { + // NOTE: Important as we are creating point in Base.call() + this.twisted = (conf.a | 0) !== 1; + this.mOneA = this.twisted && (conf.a | 0) === -1; + this.extended = this.mOneA; + Base.call(this, "edwards", conf); + this.a = new BN(conf.a, 16).umod(this.red.m); + this.a = this.a.toRed(this.red); + this.c = new BN(conf.c, 16).toRed(this.red); + this.c2 = this.c.redSqr(); + this.d = new BN(conf.d, 16).toRed(this.red); + this.dd = this.d.redAdd(this.d); + assert(!this.twisted || this.c.fromRed().cmpn(1) === 0); + this.oneC = (conf.c | 0) === 1; + } - if (start < number.length) { - if (base === 16) { - this._parseHex(number, start, endian); - } else { - this._parseBase(number, base, start); + inherits(EdwardsCurve, Base); + exports$P$1 = EdwardsCurve; - if (endian === "le") { - this._initArray(this.toArray(), base, endian); - } - } - } - }; + EdwardsCurve.prototype._mulA = function _mulA(num) { + if (this.mOneA) return num.redNeg();else return this.a.redMul(num); + }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { - if (number < 0) { - (this || _global$y).negative = 1; - number = -number; - } + EdwardsCurve.prototype._mulC = function _mulC(num) { + if (this.oneC) return num;else return this.c.redMul(num); + }; // Just for compatibility with Short curve - if (number < 67108864) { - (this || _global$y).words = [number & 67108863]; - (this || _global$y).length = 1; - } else if (number < 4503599627370496) { - (this || _global$y).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$y).length = 2; - } else { - assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$y).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$y).length = 3; - } + EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) { + return this.point(x, y, z, t); + }; - if (endian !== "le") return; // Reverse the bytes + EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) { + x = new BN(x, 16); + if (!x.red) x = x.toRed(this.red); + var x2 = x.redSqr(); + var rhs = this.c2.redSub(this.a.redMul(x2)); + var lhs = this.one.redSub(this.c2.redMul(this.d).redMul(x2)); + var y2 = rhs.redMul(lhs.redInvm()); + var y = y2.redSqrt(); + if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error("invalid point"); + var isOdd = y.fromRed().isOdd(); + if (odd && !isOdd || !odd && isOdd) y = y.redNeg(); + return this.point(x, y); + }; - this._initArray(this.toArray(), base, endian); - }; + EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { + y = new BN(y, 16); + if (!y.red) y = y.toRed(this.red); // x^2 = (y^2 - c^2) / (c^2 d y^2 - a) - BN.prototype._initArray = function _initArray(number, base, endian) { - // Perhaps a Uint8Array - assert(typeof number.length === "number"); + var y2 = y.redSqr(); + var lhs = y2.redSub(this.c2); + var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a); + var x2 = lhs.redMul(rhs.redInvm()); - if (number.length <= 0) { - (this || _global$y).words = [0]; - (this || _global$y).length = 1; - return this || _global$y; - } + if (x2.cmp(this.zero) === 0) { + if (odd) throw new Error("invalid point");else return this.point(this.zero, y); + } - (this || _global$y).length = Math.ceil(number.length / 3); - (this || _global$y).words = new Array((this || _global$y).length); + var x = x2.redSqrt(); + if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error("invalid point"); + if (x.fromRed().isOdd() !== odd) x = x.redNeg(); + return this.point(x, y); + }; - for (var i = 0; i < (this || _global$y).length; i++) { - (this || _global$y).words[i] = 0; - } + EdwardsCurve.prototype.validate = function validate(point) { + if (point.isInfinity()) return true; // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2) - var j, w; - var off = 0; + point.normalize(); + var x2 = point.x.redSqr(); + var y2 = point.y.redSqr(); + var lhs = x2.redMul(this.a).redAdd(y2); + var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2))); + return lhs.cmp(rhs) === 0; + }; - if (endian === "be") { - for (i = number.length - 1, j = 0; i >= 0; i -= 3) { - w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$y).words[j] |= w << off & 67108863; - (this || _global$y).words[j + 1] = w >>> 26 - off & 67108863; - off += 24; + function Point(curve, x, y, z, t) { + Base.BasePoint.call(this, curve, "projective"); - if (off >= 26) { - off -= 26; - j++; - } - } - } else if (endian === "le") { - for (i = 0, j = 0; i < number.length; i += 3) { - w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$y).words[j] |= w << off & 67108863; - (this || _global$y).words[j + 1] = w >>> 26 - off & 67108863; - off += 24; + if (x === null && y === null && z === null) { + this.x = this.curve.zero; + this.y = this.curve.one; + this.z = this.curve.one; + this.t = this.curve.zero; + this.zOne = true; + } else { + this.x = new BN(x, 16); + this.y = new BN(y, 16); + this.z = z ? new BN(z, 16) : this.curve.one; + this.t = t && new BN(t, 16); + if (!this.x.red) this.x = this.x.toRed(this.curve.red); + if (!this.y.red) this.y = this.y.toRed(this.curve.red); + if (!this.z.red) this.z = this.z.toRed(this.curve.red); + if (this.t && !this.t.red) this.t = this.t.toRed(this.curve.red); + this.zOne = this.z === this.curve.one; // Use extended coordinates - if (off >= 26) { - off -= 26; - j++; - } - } + if (this.curve.extended && !this.t) { + this.t = this.x.redMul(this.y); + if (!this.zOne) this.t = this.t.redMul(this.z.redInvm()); } + } + } - return this.strip(); - }; + inherits(Point, Base.BasePoint); - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // 'A' - 'F' + EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) { + return Point.fromJSON(this, obj); + }; - if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' - } else if (c >= 97 && c <= 102) { - return c - 87; // '0' - '9' - } else { - return c - 48 & 15; - } - } + EdwardsCurve.prototype.point = function point(x, y, z, t) { + return new Point(this, x, y, z, t); + }; - function parseHexByte(string, lowerBound, index) { - var r = parseHex4Bits(string, index); + Point.fromJSON = function fromJSON(curve, obj) { + return new Point(curve, obj[0], obj[1], obj[2]); + }; - if (index - 1 >= lowerBound) { - r |= parseHex4Bits(string, index - 1) << 4; - } + Point.prototype.inspect = function inspect() { + if (this.isInfinity()) return ""; + return ""; + }; - return r; - } + Point.prototype.isInfinity = function isInfinity() { + // XXX This code assumes that zero is always zero in red + return this.x.cmpn(0) === 0 && (this.y.cmp(this.z) === 0 || this.zOne && this.y.cmp(this.curve.c) === 0); + }; - BN.prototype._parseHex = function _parseHex(number, start, endian) { - // Create possibly bigger array to ensure that it fits the number - (this || _global$y).length = Math.ceil((number.length - start) / 6); - (this || _global$y).words = new Array((this || _global$y).length); + Point.prototype._extDbl = function _extDbl() { + // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html + // #doubling-dbl-2008-hwcd + // 4M + 4S + // A = X1^2 + var a = this.x.redSqr(); // B = Y1^2 - for (var i = 0; i < (this || _global$y).length; i++) { - (this || _global$y).words[i] = 0; - } // 24-bits chunks + var b = this.y.redSqr(); // C = 2 * Z1^2 + var c = this.z.redSqr(); + c = c.redIAdd(c); // D = a * A - var off = 0; - var j = 0; - var w; + var d = this.curve._mulA(a); // E = (X1 + Y1)^2 - A - B - if (endian === "be") { - for (i = number.length - 1; i >= start; i -= 2) { - w = parseHexByte(number, start, i) << off; - (this || _global$y).words[j] |= w & 67108863; - if (off >= 18) { - off -= 18; - j += 1; - (this || _global$y).words[j] |= w >>> 26; - } else { - off += 8; - } - } - } else { - var parseLength = number.length - start; + var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); // G = D + B - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { - w = parseHexByte(number, start, i) << off; - (this || _global$y).words[j] |= w & 67108863; + var g = d.redAdd(b); // F = G - C - if (off >= 18) { - off -= 18; - j += 1; - (this || _global$y).words[j] |= w >>> 26; - } else { - off += 8; - } - } - } + var f = g.redSub(c); // H = D - B - this.strip(); - }; + var h = d.redSub(b); // X3 = E * F - function parseBase(str, start, end, mul) { - var r = 0; - var len = Math.min(str.length, end); + var nx = e.redMul(f); // Y3 = G * H - for (var i = start; i < len; i++) { - var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + var ny = g.redMul(h); // T3 = E * H - if (c >= 49) { - r += c - 49 + 10; // 'A' - } else if (c >= 17) { - r += c - 17 + 10; // '0' - '9' - } else { - r += c; - } - } + var nt = e.redMul(h); // Z3 = F * G - return r; - } + var nz = f.redMul(g); + return this.curve.point(nx, ny, nz, nt); + }; - BN.prototype._parseBase = function _parseBase(number, base, start) { - // Initialize as zero - (this || _global$y).words = [0]; - (this || _global$y).length = 1; // Find length of limb in base + Point.prototype._projDbl = function _projDbl() { + // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html + // #doubling-dbl-2008-bbjlp + // #doubling-dbl-2007-bl + // and others + // Generally 3M + 4S or 2M + 4S + // B = (X1 + Y1)^2 + var b = this.x.redAdd(this.y).redSqr(); // C = X1^2 - for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { - limbLen++; - } + var c = this.x.redSqr(); // D = Y1^2 - limbLen--; - limbPow = limbPow / base | 0; - var total = number.length - start; - var mod = total % limbLen; - var end = Math.min(total, total - mod) + start; - var word = 0; + var d = this.y.redSqr(); + var nx; + var ny; + var nz; + var e; + var h; + var j; - for (var i = start; i < end; i += limbLen) { - word = parseBase(number, i, i + limbLen, base); - this.imuln(limbPow); + if (this.curve.twisted) { + // E = a * C + e = this.curve._mulA(c); // F = E + D - if ((this || _global$y).words[0] + word < 67108864) { - (this || _global$y).words[0] += word; - } else { - this._iaddn(word); - } - } + var f = e.redAdd(d); - if (mod !== 0) { - var pow = 1; - word = parseBase(number, i, number.length, base); + if (this.zOne) { + // X3 = (B - C - D) * (F - 2) + nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); // Y3 = F * (E - D) - for (i = 0; i < mod; i++) { - pow *= base; - } + ny = f.redMul(e.redSub(d)); // Z3 = F^2 - 2 * F - this.imuln(pow); + nz = f.redSqr().redSub(f).redSub(f); + } else { + // H = Z1^2 + h = this.z.redSqr(); // J = F - 2 * H - if ((this || _global$y).words[0] + word < 67108864) { - (this || _global$y).words[0] += word; - } else { - this._iaddn(word); - } - } + j = f.redSub(h).redISub(h); // X3 = (B-C-D)*J - this.strip(); - }; + nx = b.redSub(c).redISub(d).redMul(j); // Y3 = F * (E - D) - BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$y).length); + ny = f.redMul(e.redSub(d)); // Z3 = F * J - for (var i = 0; i < (this || _global$y).length; i++) { - dest.words[i] = (this || _global$y).words[i]; + nz = f.redMul(j); } + } else { + // E = C + D + e = c.redAdd(d); // H = (c * Z1)^2 - dest.length = (this || _global$y).length; - dest.negative = (this || _global$y).negative; - dest.red = (this || _global$y).red; - }; + h = this.curve._mulC(this.z).redSqr(); // J = E - 2 * H - BN.prototype.clone = function clone() { - var r = new BN(null); - this.copy(r); - return r; - }; + j = e.redSub(h).redSub(h); // X3 = c * (B - E) * J - BN.prototype._expand = function _expand(size) { - while ((this || _global$y).length < size) { - (this || _global$y).words[(this || _global$y).length++] = 0; - } + nx = this.curve._mulC(b.redISub(e)).redMul(j); // Y3 = c * E * (C - D) - return this || _global$y; - }; // Remove leading `0` from `this` + ny = this.curve._mulC(e).redMul(c.redISub(d)); // Z3 = E * J + nz = e.redMul(j); + } - BN.prototype.strip = function strip() { - while ((this || _global$y).length > 1 && (this || _global$y).words[(this || _global$y).length - 1] === 0) { - (this || _global$y).length--; - } + return this.curve.point(nx, ny, nz); + }; - return this._normSign(); - }; + Point.prototype.dbl = function dbl() { + if (this.isInfinity()) return this; // Double in extended coordinates - BN.prototype._normSign = function _normSign() { - // -0 = 0 - if ((this || _global$y).length === 1 && (this || _global$y).words[0] === 0) { - (this || _global$y).negative = 0; - } + if (this.curve.extended) return this._extDbl();else return this._projDbl(); + }; - return this || _global$y; - }; + Point.prototype._extAdd = function _extAdd(p) { + // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html + // #addition-add-2008-hwcd-3 + // 8M + // A = (Y1 - X1) * (Y2 - X2) + var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); // B = (Y1 + X1) * (Y2 + X2) - BN.prototype.inspect = function inspect() { - return ((this || _global$y).red ? ""; - }; - /* - var zeros = []; - var groupSizes = []; - var groupBases = []; - var s = ''; - var i = -1; - while (++i < BN.wordSize) { - zeros[i] = s; - s += '0'; - } - groupSizes[0] = 0; - groupSizes[1] = 0; - groupBases[0] = 0; - groupBases[1] = 0; - var base = 2 - 1; - while (++base < 36 + 1) { - var groupSize = 0; - var groupBase = 1; - while (groupBase < (1 << BN.wordSize) / base) { - groupBase *= base; - groupSize += 1; - } - groupSizes[base] = groupSize; - groupBases[base] = groupBase; - } - */ + var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); // C = T1 * k * T2 + var c = this.t.redMul(this.curve.dd).redMul(p.t); // D = Z1 * 2 * Z2 - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; - var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; - var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; + var d = this.z.redMul(p.z.redAdd(p.z)); // E = B - A - BN.prototype.toString = function toString(base, padding) { - base = base || 10; - padding = padding | 0 || 1; - var out; + var e = b.redSub(a); // F = D - C - if (base === 16 || base === "hex") { - out = ""; - var off = 0; - var carry = 0; + var f = d.redSub(c); // G = D + C - for (var i = 0; i < (this || _global$y).length; i++) { - var w = (this || _global$y).words[i]; - var word = ((w << off | carry) & 16777215).toString(16); - carry = w >>> 24 - off & 16777215; + var g = d.redAdd(c); // H = B + A - if (carry !== 0 || i !== (this || _global$y).length - 1) { - out = zeros[6 - word.length] + word + out; - } else { - out = word + out; - } + var h = b.redAdd(a); // X3 = E * F - off += 2; + var nx = e.redMul(f); // Y3 = G * H - if (off >= 26) { - off -= 26; - i--; - } - } + var ny = g.redMul(h); // T3 = E * H - if (carry !== 0) { - out = carry.toString(16) + out; - } + var nt = e.redMul(h); // Z3 = F * G + + var nz = f.redMul(g); + return this.curve.point(nx, ny, nz, nt); + }; + + Point.prototype._projAdd = function _projAdd(p) { + // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html + // #addition-add-2008-bbjlp + // #addition-add-2007-bl + // 10M + 1S + // A = Z1 * Z2 + var a = this.z.redMul(p.z); // B = A^2 - while (out.length % padding !== 0) { - out = "0" + out; - } + var b = a.redSqr(); // C = X1 * X2 - if ((this || _global$y).negative !== 0) { - out = "-" + out; - } + var c = this.x.redMul(p.x); // D = Y1 * Y2 - return out; - } + var d = this.y.redMul(p.y); // E = d * C * D - if (base === (base | 0) && base >= 2 && base <= 36) { - // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); + var e = this.curve.d.redMul(c).redMul(d); // F = B - E - var groupBase = groupBases[base]; - out = ""; - var c = this.clone(); - c.negative = 0; + var f = b.redSub(e); // G = B + E - while (!c.isZero()) { - var r = c.modn(groupBase).toString(base); - c = c.idivn(groupBase); + var g = b.redAdd(e); // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D) - if (!c.isZero()) { - out = zeros[groupSize - r.length] + r + out; - } else { - out = r + out; - } - } + var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d); + var nx = a.redMul(f).redMul(tmp); + var ny; + var nz; - if (this.isZero()) { - out = "0" + out; - } + if (this.curve.twisted) { + // Y3 = A * G * (D - a * C) + ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); // Z3 = F * G - while (out.length % padding !== 0) { - out = "0" + out; - } + nz = f.redMul(g); + } else { + // Y3 = A * G * (D - C) + ny = a.redMul(g).redMul(d.redSub(c)); // Z3 = c * F * G - if ((this || _global$y).negative !== 0) { - out = "-" + out; - } + nz = this.curve._mulC(f).redMul(g); + } - return out; - } + return this.curve.point(nx, ny, nz); + }; - assert(false, "Base should be between 2 and 36"); - }; + Point.prototype.add = function add(p) { + if (this.isInfinity()) return p; + if (p.isInfinity()) return this; + if (this.curve.extended) return this._extAdd(p);else return this._projAdd(p); + }; - BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$y).words[0]; + Point.prototype.mul = function mul(k) { + if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else return this.curve._wnafMul(this, k); + }; - if ((this || _global$y).length === 2) { - ret += (this || _global$y).words[1] * 67108864; - } else if ((this || _global$y).length === 3 && (this || _global$y).words[2] === 1) { - // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$y).words[1] * 67108864; - } else if ((this || _global$y).length > 2) { - assert(false, "Number can only safely store up to 53 bits"); - } + Point.prototype.mulAdd = function mulAdd(k1, p, k2) { + return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, false); + }; - return (this || _global$y).negative !== 0 ? -ret : ret; - }; + Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) { + return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, true); + }; - BN.prototype.toJSON = function toJSON() { - return this.toString(16); - }; + Point.prototype.normalize = function normalize() { + if (this.zOne) return this; // Normalize coordinates - BN.prototype.toBuffer = function toBuffer(endian, length) { - assert(typeof Buffer !== "undefined"); - return this.toArrayLike(Buffer, endian, length); - }; + var zi = this.z.redInvm(); + this.x = this.x.redMul(zi); + this.y = this.y.redMul(zi); + if (this.t) this.t = this.t.redMul(zi); + this.z = this.curve.one; + this.zOne = true; + return this; + }; - BN.prototype.toArray = function toArray(endian, length) { - return this.toArrayLike(Array, endian, length); - }; + Point.prototype.neg = function neg() { + return this.curve.point(this.x.redNeg(), this.y, this.z, this.t && this.t.redNeg()); + }; - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { - var byteLength = this.byteLength(); - var reqLength = length || Math.max(1, byteLength); - assert(byteLength <= reqLength, "byte array longer than desired length"); - assert(reqLength > 0, "Requested array length <= 0"); - this.strip(); - var littleEndian = endian === "le"; - var res = new ArrayType(reqLength); - var b, i; - var q = this.clone(); + Point.prototype.getX = function getX() { + this.normalize(); + return this.x.fromRed(); + }; - if (!littleEndian) { - // Assume big-endian - for (i = 0; i < reqLength - byteLength; i++) { - res[i] = 0; - } + Point.prototype.getY = function getY() { + this.normalize(); + return this.y.fromRed(); + }; - for (i = 0; !q.isZero(); i++) { - b = q.andln(255); - q.iushrn(8); - res[reqLength - i - 1] = b; - } - } else { - for (i = 0; !q.isZero(); i++) { - b = q.andln(255); - q.iushrn(8); - res[i] = b; - } + Point.prototype.eq = function eq(other) { + return this === other || this.getX().cmp(other.getX()) === 0 && this.getY().cmp(other.getY()) === 0; + }; - for (; i < reqLength; i++) { - res[i] = 0; - } - } + Point.prototype.eqXToP = function eqXToP(x) { + var rx = x.toRed(this.curve.red).redMul(this.z); + if (this.x.cmp(rx) === 0) return true; + var xc = x.clone(); + var t = this.curve.redN.redMul(this.z); - return res; - }; + for (;;) { + xc.iadd(this.curve.n); + if (xc.cmp(this.curve.p) >= 0) return false; + rx.redIAdd(t); + if (this.x.cmp(rx) === 0) return true; + } + }; // Compatibility with BaseCurve - if (Math.clz32) { - BN.prototype._countBits = function _countBits(w) { - return 32 - Math.clz32(w); - }; - } else { - BN.prototype._countBits = function _countBits(w) { - var t = w; - var r = 0; - if (t >= 4096) { - r += 13; - t >>>= 13; - } + Point.prototype.toP = Point.prototype.normalize; + Point.prototype.mixedAdd = Point.prototype.add; + return exports$P$1; +} - if (t >= 64) { - r += 7; - t >>>= 7; - } +var exports$O$1 = {}, + _dewExec$O$1 = false; +function dew$O$1() { + if (_dewExec$O$1) return exports$O$1; + _dewExec$O$1 = true; + var curve = exports$O$1; + curve.base = dew$S$1(); + curve.short = dew$R$1(); + curve.mont = dew$Q$1(); + curve.edwards = dew$P$1(); + return exports$O$1; +} - if (t >= 8) { - r += 4; - t >>>= 4; - } +var exports$N$1 = {}, + _dewExec$N$1 = false; +function dew$N$1() { + if (_dewExec$N$1) return exports$N$1; + _dewExec$N$1 = true; - if (t >= 2) { - r += 2; - t >>>= 2; - } + var assert = dew$1t(); - return r + t; - }; - } + var inherits = dew$f$2(); - BN.prototype._zeroBits = function _zeroBits(w) { - // Short-cut - if (w === 0) return 26; - var t = w; - var r = 0; + exports$N$1.inherits = inherits; - if ((t & 8191) === 0) { - r += 13; - t >>>= 13; - } + function isSurrogatePair(msg, i) { + if ((msg.charCodeAt(i) & 64512) !== 55296) { + return false; + } - if ((t & 127) === 0) { - r += 7; - t >>>= 7; - } + if (i < 0 || i + 1 >= msg.length) { + return false; + } - if ((t & 15) === 0) { - r += 4; - t >>>= 4; - } + return (msg.charCodeAt(i + 1) & 64512) === 56320; + } - if ((t & 3) === 0) { - r += 2; - t >>>= 2; - } + function toArray(msg, enc) { + if (Array.isArray(msg)) return msg.slice(); + if (!msg) return []; + var res = []; - if ((t & 1) === 0) { - r++; - } + if (typeof msg === "string") { + if (!enc) { + // Inspired by stringToUtf8ByteArray() in closure-library by Google + // https://github.com/google/closure-library/blob/8598d87242af59aac233270742c8984e2b2bdbe0/closure/goog/crypt/crypt.js#L117-L143 + // Apache License 2.0 + // https://github.com/google/closure-library/blob/master/LICENSE + var p = 0; - return r; - }; // Return number of used bits in a BN + for (var i = 0; i < msg.length; i++) { + var c = msg.charCodeAt(i); + if (c < 128) { + res[p++] = c; + } else if (c < 2048) { + res[p++] = c >> 6 | 192; + res[p++] = c & 63 | 128; + } else if (isSurrogatePair(msg, i)) { + c = 65536 + ((c & 1023) << 10) + (msg.charCodeAt(++i) & 1023); + res[p++] = c >> 18 | 240; + res[p++] = c >> 12 & 63 | 128; + res[p++] = c >> 6 & 63 | 128; + res[p++] = c & 63 | 128; + } else { + res[p++] = c >> 12 | 224; + res[p++] = c >> 6 & 63 | 128; + res[p++] = c & 63 | 128; + } + } + } else if (enc === "hex") { + msg = msg.replace(/[^a-z0-9]+/ig, ""); + if (msg.length % 2 !== 0) msg = "0" + msg; - BN.prototype.bitLength = function bitLength() { - var w = (this || _global$y).words[(this || _global$y).length - 1]; + for (i = 0; i < msg.length; i += 2) res.push(parseInt(msg[i] + msg[i + 1], 16)); + } + } else { + for (i = 0; i < msg.length; i++) res[i] = msg[i] | 0; + } - var hi = this._countBits(w); + return res; + } - return ((this || _global$y).length - 1) * 26 + hi; - }; + exports$N$1.toArray = toArray; - function toBitArray(num) { - var w = new Array(num.bitLength()); + function toHex(msg) { + var res = ""; - for (var bit = 0; bit < w.length; bit++) { - var off = bit / 26 | 0; - var wbit = bit % 26; - w[bit] = (num.words[off] & 1 << wbit) >>> wbit; - } + for (var i = 0; i < msg.length; i++) res += zero2(msg[i].toString(16)); - return w; - } // Number of trailing zero bits + return res; + } + exports$N$1.toHex = toHex; - BN.prototype.zeroBits = function zeroBits() { - if (this.isZero()) return 0; - var r = 0; + function htonl(w) { + var res = w >>> 24 | w >>> 8 & 65280 | w << 8 & 16711680 | (w & 255) << 24; + return res >>> 0; + } - for (var i = 0; i < (this || _global$y).length; i++) { - var b = this._zeroBits((this || _global$y).words[i]); + exports$N$1.htonl = htonl; - r += b; - if (b !== 26) break; - } + function toHex32(msg, endian) { + var res = ""; - return r; - }; + for (var i = 0; i < msg.length; i++) { + var w = msg[i]; + if (endian === "little") w = htonl(w); + res += zero8(w.toString(16)); + } - BN.prototype.byteLength = function byteLength() { - return Math.ceil(this.bitLength() / 8); - }; + return res; + } - BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$y).negative !== 0) { - return this.abs().inotn(width).iaddn(1); - } + exports$N$1.toHex32 = toHex32; - return this.clone(); - }; + function zero2(word) { + if (word.length === 1) return "0" + word;else return word; + } - BN.prototype.fromTwos = function fromTwos(width) { - if (this.testn(width - 1)) { - return this.notn(width).iaddn(1).ineg(); - } + exports$N$1.zero2 = zero2; - return this.clone(); - }; + function zero8(word) { + if (word.length === 7) return "0" + word;else if (word.length === 6) return "00" + word;else if (word.length === 5) return "000" + word;else if (word.length === 4) return "0000" + word;else if (word.length === 3) return "00000" + word;else if (word.length === 2) return "000000" + word;else if (word.length === 1) return "0000000" + word;else return word; + } - BN.prototype.isNeg = function isNeg() { - return (this || _global$y).negative !== 0; - }; // Return negative clone of `this` + exports$N$1.zero8 = zero8; + function join32(msg, start, end, endian) { + var len = end - start; + assert(len % 4 === 0); + var res = new Array(len / 4); - BN.prototype.neg = function neg() { - return this.clone().ineg(); - }; + for (var i = 0, k = start; i < res.length; i++, k += 4) { + var w; + if (endian === "big") w = msg[k] << 24 | msg[k + 1] << 16 | msg[k + 2] << 8 | msg[k + 3];else w = msg[k + 3] << 24 | msg[k + 2] << 16 | msg[k + 1] << 8 | msg[k]; + res[i] = w >>> 0; + } - BN.prototype.ineg = function ineg() { - if (!this.isZero()) { - (this || _global$y).negative ^= 1; - } + return res; + } - return this || _global$y; - }; // Or `num` with `this` in-place + exports$N$1.join32 = join32; + function split32(msg, endian) { + var res = new Array(msg.length * 4); - BN.prototype.iuor = function iuor(num) { - while ((this || _global$y).length < num.length) { - (this || _global$y).words[(this || _global$y).length++] = 0; - } + for (var i = 0, k = 0; i < msg.length; i++, k += 4) { + var m = msg[i]; - for (var i = 0; i < num.length; i++) { - (this || _global$y).words[i] = (this || _global$y).words[i] | num.words[i]; + if (endian === "big") { + res[k] = m >>> 24; + res[k + 1] = m >>> 16 & 255; + res[k + 2] = m >>> 8 & 255; + res[k + 3] = m & 255; + } else { + res[k + 3] = m >>> 24; + res[k + 2] = m >>> 16 & 255; + res[k + 1] = m >>> 8 & 255; + res[k] = m & 255; } + } - return this.strip(); - }; + return res; + } - BN.prototype.ior = function ior(num) { - assert(((this || _global$y).negative | num.negative) === 0); - return this.iuor(num); - }; // Or `num` with `this` + exports$N$1.split32 = split32; + function rotr32(w, b) { + return w >>> b | w << 32 - b; + } - BN.prototype.or = function or(num) { - if ((this || _global$y).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$y); - }; + exports$N$1.rotr32 = rotr32; - BN.prototype.uor = function uor(num) { - if ((this || _global$y).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$y); - }; // And `num` with `this` in-place + function rotl32(w, b) { + return w << b | w >>> 32 - b; + } + exports$N$1.rotl32 = rotl32; - BN.prototype.iuand = function iuand(num) { - // b = min-length(num, this) - var b; + function sum32(a, b) { + return a + b >>> 0; + } - if ((this || _global$y).length > num.length) { - b = num; - } else { - b = this || _global$y; - } + exports$N$1.sum32 = sum32; - for (var i = 0; i < b.length; i++) { - (this || _global$y).words[i] = (this || _global$y).words[i] & num.words[i]; - } + function sum32_3(a, b, c) { + return a + b + c >>> 0; + } - (this || _global$y).length = b.length; - return this.strip(); - }; + exports$N$1.sum32_3 = sum32_3; - BN.prototype.iand = function iand(num) { - assert(((this || _global$y).negative | num.negative) === 0); - return this.iuand(num); - }; // And `num` with `this` + function sum32_4(a, b, c, d) { + return a + b + c + d >>> 0; + } + exports$N$1.sum32_4 = sum32_4; - BN.prototype.and = function and(num) { - if ((this || _global$y).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$y); - }; + function sum32_5(a, b, c, d, e) { + return a + b + c + d + e >>> 0; + } - BN.prototype.uand = function uand(num) { - if ((this || _global$y).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$y); - }; // Xor `num` with `this` in-place + exports$N$1.sum32_5 = sum32_5; + function sum64(buf, pos, ah, al) { + var bh = buf[pos]; + var bl = buf[pos + 1]; + var lo = al + bl >>> 0; + var hi = (lo < al ? 1 : 0) + ah + bh; + buf[pos] = hi >>> 0; + buf[pos + 1] = lo; + } - BN.prototype.iuxor = function iuxor(num) { - // a.length > b.length - var a; - var b; + exports$N$1.sum64 = sum64; - if ((this || _global$y).length > num.length) { - a = this || _global$y; - b = num; - } else { - a = num; - b = this || _global$y; - } + function sum64_hi(ah, al, bh, bl) { + var lo = al + bl >>> 0; + var hi = (lo < al ? 1 : 0) + ah + bh; + return hi >>> 0; + } - for (var i = 0; i < b.length; i++) { - (this || _global$y).words[i] = a.words[i] ^ b.words[i]; - } + exports$N$1.sum64_hi = sum64_hi; - if ((this || _global$y) !== a) { - for (; i < a.length; i++) { - (this || _global$y).words[i] = a.words[i]; - } - } + function sum64_lo(ah, al, bh, bl) { + var lo = al + bl; + return lo >>> 0; + } - (this || _global$y).length = a.length; - return this.strip(); - }; + exports$N$1.sum64_lo = sum64_lo; - BN.prototype.ixor = function ixor(num) { - assert(((this || _global$y).negative | num.negative) === 0); - return this.iuxor(num); - }; // Xor `num` with `this` + function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { + var carry = 0; + var lo = al; + lo = lo + bl >>> 0; + carry += lo < al ? 1 : 0; + lo = lo + cl >>> 0; + carry += lo < cl ? 1 : 0; + lo = lo + dl >>> 0; + carry += lo < dl ? 1 : 0; + var hi = ah + bh + ch + dh + carry; + return hi >>> 0; + } + exports$N$1.sum64_4_hi = sum64_4_hi; - BN.prototype.xor = function xor(num) { - if ((this || _global$y).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$y); - }; + function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { + var lo = al + bl + cl + dl; + return lo >>> 0; + } - BN.prototype.uxor = function uxor(num) { - if ((this || _global$y).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$y); - }; // Not ``this`` with ``width`` bitwidth + exports$N$1.sum64_4_lo = sum64_4_lo; + function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { + var carry = 0; + var lo = al; + lo = lo + bl >>> 0; + carry += lo < al ? 1 : 0; + lo = lo + cl >>> 0; + carry += lo < cl ? 1 : 0; + lo = lo + dl >>> 0; + carry += lo < dl ? 1 : 0; + lo = lo + el >>> 0; + carry += lo < el ? 1 : 0; + var hi = ah + bh + ch + dh + eh + carry; + return hi >>> 0; + } - BN.prototype.inotn = function inotn(width) { - assert(typeof width === "number" && width >= 0); - var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + exports$N$1.sum64_5_hi = sum64_5_hi; - this._expand(bytesNeeded); + function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { + var lo = al + bl + cl + dl + el; + return lo >>> 0; + } - if (bitsLeft > 0) { - bytesNeeded--; - } // Handle complete words + exports$N$1.sum64_5_lo = sum64_5_lo; + function rotr64_hi(ah, al, num) { + var r = al << 32 - num | ah >>> num; + return r >>> 0; + } - for (var i = 0; i < bytesNeeded; i++) { - (this || _global$y).words[i] = ~(this || _global$y).words[i] & 67108863; - } // Handle the residue + exports$N$1.rotr64_hi = rotr64_hi; + function rotr64_lo(ah, al, num) { + var r = ah << 32 - num | al >>> num; + return r >>> 0; + } - if (bitsLeft > 0) { - (this || _global$y).words[i] = ~(this || _global$y).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes + exports$N$1.rotr64_lo = rotr64_lo; + function shr64_hi(ah, al, num) { + return ah >>> num; + } - return this.strip(); - }; + exports$N$1.shr64_hi = shr64_hi; - BN.prototype.notn = function notn(width) { - return this.clone().inotn(width); - }; // Set `bit` of `this` + function shr64_lo(ah, al, num) { + var r = ah << 32 - num | al >>> num; + return r >>> 0; + } + exports$N$1.shr64_lo = shr64_lo; + return exports$N$1; +} - BN.prototype.setn = function setn(bit, val) { - assert(typeof bit === "number" && bit >= 0); - var off = bit / 26 | 0; - var wbit = bit % 26; +var exports$M$1 = {}, + _dewExec$M$1 = false; +function dew$M$1() { + if (_dewExec$M$1) return exports$M$1; + _dewExec$M$1 = true; - this._expand(off + 1); + var utils = dew$N$1(); - if (val) { - (this || _global$y).words[off] = (this || _global$y).words[off] | 1 << wbit; - } else { - (this || _global$y).words[off] = (this || _global$y).words[off] & ~(1 << wbit); - } + var assert = dew$1t(); - return this.strip(); - }; // Add `num` to `this` in-place + function BlockHash() { + this.pending = null; + this.pendingTotal = 0; + this.blockSize = this.constructor.blockSize; + this.outSize = this.constructor.outSize; + this.hmacStrength = this.constructor.hmacStrength; + this.padLength = this.constructor.padLength / 8; + this.endian = "big"; + this._delta8 = this.blockSize / 8; + this._delta32 = this.blockSize / 32; + } + exports$M$1.BlockHash = BlockHash; - BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + BlockHash.prototype.update = function update(msg, enc) { + // Convert message to array, pad it, and join into 32bit blocks + msg = utils.toArray(msg, enc); + if (!this.pending) this.pending = msg;else this.pending = this.pending.concat(msg); + this.pendingTotal += msg.length; // Enough data, try updating - if ((this || _global$y).negative !== 0 && num.negative === 0) { - (this || _global$y).negative = 0; - r = this.isub(num); - (this || _global$y).negative ^= 1; - return this._normSign(); // positive + negative - } else if ((this || _global$y).negative === 0 && num.negative !== 0) { - num.negative = 0; - r = this.isub(num); - num.negative = 1; - return r._normSign(); - } // a.length > b.length + if (this.pending.length >= this._delta8) { + msg = this.pending; // Process pending data in blocks + var r = msg.length % this._delta8; + this.pending = msg.slice(msg.length - r, msg.length); + if (this.pending.length === 0) this.pending = null; + msg = utils.join32(msg, 0, msg.length - r, this.endian); - var a, b; + for (var i = 0; i < msg.length; i += this._delta32) this._update(msg, i, i + this._delta32); + } - if ((this || _global$y).length > num.length) { - a = this || _global$y; - b = num; - } else { - a = num; - b = this || _global$y; - } + return this; + }; - var carry = 0; + BlockHash.prototype.digest = function digest(enc) { + this.update(this._pad()); + assert(this.pending === null); + return this._digest(enc); + }; - for (var i = 0; i < b.length; i++) { - r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$y).words[i] = r & 67108863; - carry = r >>> 26; - } + BlockHash.prototype._pad = function pad() { + var len = this.pendingTotal; + var bytes = this._delta8; + var k = bytes - (len + this.padLength) % bytes; + var res = new Array(k + this.padLength); + res[0] = 128; - for (; carry !== 0 && i < a.length; i++) { - r = (a.words[i] | 0) + carry; - (this || _global$y).words[i] = r & 67108863; - carry = r >>> 26; - } + for (var i = 1; i < k; i++) res[i] = 0; // Append length - (this || _global$y).length = a.length; - if (carry !== 0) { - (this || _global$y).words[(this || _global$y).length] = carry; - (this || _global$y).length++; // Copy the rest of the words - } else if (a !== (this || _global$y)) { - for (; i < a.length; i++) { - (this || _global$y).words[i] = a.words[i]; - } - } + len <<= 3; - return this || _global$y; - }; // Add `num` to `this` + if (this.endian === "big") { + for (var t = 8; t < this.padLength; t++) res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = len >>> 24 & 255; + res[i++] = len >>> 16 & 255; + res[i++] = len >>> 8 & 255; + res[i++] = len & 255; + } else { + res[i++] = len & 255; + res[i++] = len >>> 8 & 255; + res[i++] = len >>> 16 & 255; + res[i++] = len >>> 24 & 255; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; + res[i++] = 0; - BN.prototype.add = function add(num) { - var res; + for (t = 8; t < this.padLength; t++) res[i++] = 0; + } - if (num.negative !== 0 && (this || _global$y).negative === 0) { - num.negative = 0; - res = this.sub(num); - num.negative ^= 1; - return res; - } else if (num.negative === 0 && (this || _global$y).negative !== 0) { - (this || _global$y).negative = 0; - res = num.sub(this || _global$y); - (this || _global$y).negative = 1; - return res; - } + return res; + }; - if ((this || _global$y).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$y); - }; // Subtract `num` from `this` in-place + return exports$M$1; +} +var exports$L$1 = {}, + _dewExec$L$1 = false; +function dew$L$1() { + if (_dewExec$L$1) return exports$L$1; + _dewExec$L$1 = true; + return exports$L$1; +} - BN.prototype.isub = function isub(num) { - // this - (-num) = this + num - if (num.negative !== 0) { - num.negative = 0; - var r = this.iadd(num); - num.negative = 1; - return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$y).negative !== 0) { - (this || _global$y).negative = 0; - this.iadd(num); - (this || _global$y).negative = 1; - return this._normSign(); - } // At this point both numbers are positive +var exports$K$1 = {}, + _dewExec$K$1 = false; +function dew$K$1() { + if (_dewExec$K$1) return exports$K$1; + _dewExec$K$1 = true; + var utils = dew$N$1(); - var cmp = this.cmp(num); // Optimization - zeroify + var common = dew$M$1(); - if (cmp === 0) { - (this || _global$y).negative = 0; - (this || _global$y).length = 1; - (this || _global$y).words[0] = 0; - return this || _global$y; - } // a > b + var rotl32 = utils.rotl32; + var sum32 = utils.sum32; + var sum32_3 = utils.sum32_3; + var sum32_4 = utils.sum32_4; + var BlockHash = common.BlockHash; + function RIPEMD160() { + if (!(this instanceof RIPEMD160)) return new RIPEMD160(); + BlockHash.call(this); + this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]; + this.endian = "little"; + } - var a, b; + utils.inherits(RIPEMD160, BlockHash); + exports$K$1.ripemd160 = RIPEMD160; + RIPEMD160.blockSize = 512; + RIPEMD160.outSize = 160; + RIPEMD160.hmacStrength = 192; + RIPEMD160.padLength = 64; - if (cmp > 0) { - a = this || _global$y; - b = num; - } else { - a = num; - b = this || _global$y; - } + RIPEMD160.prototype._update = function update(msg, start) { + var A = this.h[0]; + var B = this.h[1]; + var C = this.h[2]; + var D = this.h[3]; + var E = this.h[4]; + var Ah = A; + var Bh = B; + var Ch = C; + var Dh = D; + var Eh = E; - var carry = 0; + for (var j = 0; j < 80; j++) { + var T = sum32(rotl32(sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E); + A = E; + E = D; + D = rotl32(C, 10); + C = B; + B = T; + T = sum32(rotl32(sum32_4(Ah, f(79 - j, Bh, Ch, Dh), msg[rh[j] + start], Kh(j)), sh[j]), Eh); + Ah = Eh; + Eh = Dh; + Dh = rotl32(Ch, 10); + Ch = Bh; + Bh = T; + } - for (var i = 0; i < b.length; i++) { - r = (a.words[i] | 0) - (b.words[i] | 0) + carry; - carry = r >> 26; - (this || _global$y).words[i] = r & 67108863; - } + T = sum32_3(this.h[1], C, Dh); + this.h[1] = sum32_3(this.h[2], D, Eh); + this.h[2] = sum32_3(this.h[3], E, Ah); + this.h[3] = sum32_3(this.h[4], A, Bh); + this.h[4] = sum32_3(this.h[0], B, Ch); + this.h[0] = T; + }; - for (; carry !== 0 && i < a.length; i++) { - r = (a.words[i] | 0) + carry; - carry = r >> 26; - (this || _global$y).words[i] = r & 67108863; - } // Copy rest of the words + RIPEMD160.prototype._digest = function digest(enc) { + if (enc === "hex") return utils.toHex32(this.h, "little");else return utils.split32(this.h, "little"); + }; + function f(j, x, y, z) { + if (j <= 15) return x ^ y ^ z;else if (j <= 31) return x & y | ~x & z;else if (j <= 47) return (x | ~y) ^ z;else if (j <= 63) return x & z | y & ~z;else return x ^ (y | ~z); + } - if (carry === 0 && i < a.length && a !== (this || _global$y)) { - for (; i < a.length; i++) { - (this || _global$y).words[i] = a.words[i]; - } - } + function K(j) { + if (j <= 15) return 0;else if (j <= 31) return 1518500249;else if (j <= 47) return 1859775393;else if (j <= 63) return 2400959708;else return 2840853838; + } - (this || _global$y).length = Math.max((this || _global$y).length, i); + function Kh(j) { + if (j <= 15) return 1352829926;else if (j <= 31) return 1548603684;else if (j <= 47) return 1836072691;else if (j <= 63) return 2053994217;else return 0; + } - if (a !== (this || _global$y)) { - (this || _global$y).negative = 1; - } + var r = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]; + var rh = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; + var s = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]; + var sh = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; + return exports$K$1; +} - return this.strip(); - }; // Subtract `num` from `this` +var exports$J$1 = {}, + _dewExec$J$1 = false; +function dew$J$1() { + if (_dewExec$J$1) return exports$J$1; + _dewExec$J$1 = true; + var utils = dew$N$1(); - BN.prototype.sub = function sub(num) { - return this.clone().isub(num); - }; + var assert = dew$1t(); - function smallMulTo(self, num, out) { - out.negative = num.negative ^ self.negative; - var len = self.length + num.length | 0; - out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + function Hmac(hash, key, enc) { + if (!(this instanceof Hmac)) return new Hmac(hash, key, enc); + this.Hash = hash; + this.blockSize = hash.blockSize / 8; + this.outSize = hash.outSize / 8; + this.inner = null; + this.outer = null; - var a = self.words[0] | 0; - var b = num.words[0] | 0; - var r = a * b; - var lo = r & 67108863; - var carry = r / 67108864 | 0; - out.words[0] = lo; + this._init(utils.toArray(key, enc)); + } - for (var k = 1; k < len; k++) { - // Sum all words with the same `i + j = k` and accumulate `ncarry`, - // note that ncarry could be >= 0x3ffffff - var ncarry = carry >>> 26; - var rword = carry & 67108863; - var maxJ = Math.min(k, num.length - 1); + exports$J$1 = Hmac; - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { - var i = k - j | 0; - a = self.words[i] | 0; - b = num.words[j] | 0; - r = a * b + rword; - ncarry += r / 67108864 | 0; - rword = r & 67108863; - } + Hmac.prototype._init = function init(key) { + // Shorten key, if needed + if (key.length > this.blockSize) key = new this.Hash().update(key).digest(); + assert(key.length <= this.blockSize); // Add padding to key - out.words[k] = rword | 0; - carry = ncarry | 0; - } + for (var i = key.length; i < this.blockSize; i++) key.push(0); - if (carry !== 0) { - out.words[k] = carry | 0; - } else { - out.length--; - } + for (i = 0; i < key.length; i++) key[i] ^= 54; - return out.strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need - // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit - // multiplication (like elliptic secp256k1). + this.inner = new this.Hash().update(key); // 0x36 ^ 0x5c = 0x6a + for (i = 0; i < key.length; i++) key[i] ^= 106; - var comb10MulTo = function comb10MulTo(self, num, out) { - var a = self.words; - var b = num.words; - var o = out.words; - var c = 0; - var lo; - var mid; - var hi; - var a0 = a[0] | 0; - var al0 = a0 & 8191; - var ah0 = a0 >>> 13; - var a1 = a[1] | 0; - var al1 = a1 & 8191; - var ah1 = a1 >>> 13; - var a2 = a[2] | 0; - var al2 = a2 & 8191; - var ah2 = a2 >>> 13; - var a3 = a[3] | 0; - var al3 = a3 & 8191; - var ah3 = a3 >>> 13; - var a4 = a[4] | 0; - var al4 = a4 & 8191; - var ah4 = a4 >>> 13; - var a5 = a[5] | 0; - var al5 = a5 & 8191; - var ah5 = a5 >>> 13; - var a6 = a[6] | 0; - var al6 = a6 & 8191; - var ah6 = a6 >>> 13; - var a7 = a[7] | 0; - var al7 = a7 & 8191; - var ah7 = a7 >>> 13; - var a8 = a[8] | 0; - var al8 = a8 & 8191; - var ah8 = a8 >>> 13; - var a9 = a[9] | 0; - var al9 = a9 & 8191; - var ah9 = a9 >>> 13; - var b0 = b[0] | 0; - var bl0 = b0 & 8191; - var bh0 = b0 >>> 13; - var b1 = b[1] | 0; - var bl1 = b1 & 8191; - var bh1 = b1 >>> 13; - var b2 = b[2] | 0; - var bl2 = b2 & 8191; - var bh2 = b2 >>> 13; - var b3 = b[3] | 0; - var bl3 = b3 & 8191; - var bh3 = b3 >>> 13; - var b4 = b[4] | 0; - var bl4 = b4 & 8191; - var bh4 = b4 >>> 13; - var b5 = b[5] | 0; - var bl5 = b5 & 8191; - var bh5 = b5 >>> 13; - var b6 = b[6] | 0; - var bl6 = b6 & 8191; - var bh6 = b6 >>> 13; - var b7 = b[7] | 0; - var bl7 = b7 & 8191; - var bh7 = b7 >>> 13; - var b8 = b[8] | 0; - var bl8 = b8 & 8191; - var bh8 = b8 >>> 13; - var b9 = b[9] | 0; - var bl9 = b9 & 8191; - var bh9 = b9 >>> 13; - out.negative = self.negative ^ num.negative; - out.length = 19; - /* k = 0 */ + this.outer = new this.Hash().update(key); + }; + + Hmac.prototype.update = function update(msg, enc) { + this.inner.update(msg, enc); + return this; + }; + + Hmac.prototype.digest = function digest(enc) { + this.outer.update(this.inner.digest()); + return this.outer.digest(enc); + }; - lo = Math.imul(al0, bl0); - mid = Math.imul(al0, bh0); - mid = mid + Math.imul(ah0, bl0) | 0; - hi = Math.imul(ah0, bh0); - var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; - w0 &= 67108863; - /* k = 1 */ + return exports$J$1; +} - lo = Math.imul(al1, bl0); - mid = Math.imul(al1, bh0); - mid = mid + Math.imul(ah1, bl0) | 0; - hi = Math.imul(ah1, bh0); - lo = lo + Math.imul(al0, bl1) | 0; - mid = mid + Math.imul(al0, bh1) | 0; - mid = mid + Math.imul(ah0, bl1) | 0; - hi = hi + Math.imul(ah0, bh1) | 0; - var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; - w1 &= 67108863; - /* k = 2 */ +var exports$I$1 = {}, + _dewExec$I$1 = false; +function dew$I$1() { + if (_dewExec$I$1) return exports$I$1; + _dewExec$I$1 = true; + var hash = exports$I$1; + hash.utils = dew$N$1(); + hash.common = dew$M$1(); + hash.sha = dew$L$1(); + hash.ripemd = dew$K$1(); + hash.hmac = dew$J$1(); // Proxy hash functions to the main object - lo = Math.imul(al2, bl0); - mid = Math.imul(al2, bh0); - mid = mid + Math.imul(ah2, bl0) | 0; - hi = Math.imul(ah2, bh0); - lo = lo + Math.imul(al1, bl1) | 0; - mid = mid + Math.imul(al1, bh1) | 0; - mid = mid + Math.imul(ah1, bl1) | 0; - hi = hi + Math.imul(ah1, bh1) | 0; - lo = lo + Math.imul(al0, bl2) | 0; - mid = mid + Math.imul(al0, bh2) | 0; - mid = mid + Math.imul(ah0, bl2) | 0; - hi = hi + Math.imul(ah0, bh2) | 0; - var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; - w2 &= 67108863; - /* k = 3 */ + hash.sha1 = hash.sha.sha1; + hash.sha256 = hash.sha.sha256; + hash.sha224 = hash.sha.sha224; + hash.sha384 = hash.sha.sha384; + hash.sha512 = hash.sha.sha512; + hash.ripemd160 = hash.ripemd.ripemd160; + return exports$I$1; +} - lo = Math.imul(al3, bl0); - mid = Math.imul(al3, bh0); - mid = mid + Math.imul(ah3, bl0) | 0; - hi = Math.imul(ah3, bh0); - lo = lo + Math.imul(al2, bl1) | 0; - mid = mid + Math.imul(al2, bh1) | 0; - mid = mid + Math.imul(ah2, bl1) | 0; - hi = hi + Math.imul(ah2, bh1) | 0; - lo = lo + Math.imul(al1, bl2) | 0; - mid = mid + Math.imul(al1, bh2) | 0; - mid = mid + Math.imul(ah1, bl2) | 0; - hi = hi + Math.imul(ah1, bh2) | 0; - lo = lo + Math.imul(al0, bl3) | 0; - mid = mid + Math.imul(al0, bh3) | 0; - mid = mid + Math.imul(ah0, bl3) | 0; - hi = hi + Math.imul(ah0, bh3) | 0; - var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; - w3 &= 67108863; - /* k = 4 */ +var exports$H$1 = {}, + _dewExec$H$1 = false; +function dew$H$1() { + if (_dewExec$H$1) return exports$H$1; + _dewExec$H$1 = true; + exports$H$1 = { + doubles: { + step: 4, + points: [["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a", "f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"], ["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508", "11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"], ["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739", "d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"], ["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640", "4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"], ["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c", "4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"], ["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda", "96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"], ["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa", "5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"], ["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0", "cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"], ["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d", "9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"], ["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d", "e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"], ["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1", "9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"], ["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0", "5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"], ["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047", "10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"], ["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862", "283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"], ["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7", "7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"], ["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd", "56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"], ["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83", "7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"], ["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a", "53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"], ["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8", "bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"], ["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d", "4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"], ["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725", "7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"], ["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754", "4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"], ["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c", "17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"], ["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6", "6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"], ["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39", "c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"], ["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891", "893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"], ["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b", "febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"], ["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03", "2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"], ["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d", "eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"], ["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070", "7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"], ["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4", "e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"], ["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da", "662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"], ["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11", "1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"], ["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e", "efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"], ["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41", "2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"], ["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef", "67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"], ["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8", "db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"], ["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d", "648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"], ["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96", "35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"], ["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd", "ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"], ["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5", "9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"], ["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266", "40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"], ["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71", "34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"], ["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac", "c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"], ["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751", "1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"], ["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e", "493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"], ["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241", "c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"], ["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3", "be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"], ["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f", "4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"], ["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19", "aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"], ["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be", "b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"], ["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9", "6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"], ["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2", "8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"], ["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13", "7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"], ["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c", "ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"], ["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba", "2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"], ["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151", "e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"], ["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073", "d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"], ["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458", "38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"], ["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b", "69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"], ["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366", "d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"], ["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa", "40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"], ["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0", "620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"], ["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787", "7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"], ["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e", "ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]] + }, + naf: { + wnd: 7, + points: [["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9", "388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"], ["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4", "d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"], ["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc", "6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"], ["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe", "cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"], ["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb", "d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"], ["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8", "ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"], ["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e", "581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"], ["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34", "4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"], ["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c", "85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"], ["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5", "321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"], ["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f", "2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"], ["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714", "73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"], ["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729", "a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"], ["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db", "2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"], ["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4", "e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"], ["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5", "b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"], ["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479", "2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"], ["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d", "80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"], ["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f", "1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"], ["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb", "d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"], ["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9", "eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"], ["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963", "758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"], ["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74", "958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"], ["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530", "e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"], ["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b", "5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"], ["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247", "cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"], ["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1", "cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"], ["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120", "4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"], ["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435", "91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"], ["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18", "673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"], ["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8", "59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"], ["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb", "3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"], ["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f", "55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"], ["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143", "efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"], ["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba", "e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"], ["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45", "f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"], ["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a", "744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"], ["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e", "c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"], ["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8", "e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"], ["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c", "30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"], ["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519", "e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"], ["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab", "100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"], ["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca", "ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"], ["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf", "8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"], ["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610", "68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"], ["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4", "f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"], ["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c", "d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"], ["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940", "edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"], ["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980", "a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"], ["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3", "66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"], ["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf", "9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"], ["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63", "4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"], ["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448", "fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"], ["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf", "5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"], ["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5", "8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"], ["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6", "8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"], ["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5", "5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"], ["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99", "f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"], ["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51", "f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"], ["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5", "42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"], ["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5", "204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"], ["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997", "4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"], ["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881", "73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"], ["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5", "39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"], ["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66", "d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"], ["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726", "ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"], ["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede", "6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"], ["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94", "60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"], ["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31", "3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"], ["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51", "b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"], ["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252", "ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"], ["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5", "cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"], ["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b", "6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"], ["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4", "322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"], ["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f", "6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"], ["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889", "2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"], ["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246", "b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"], ["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984", "998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"], ["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a", "b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"], ["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030", "bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"], ["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197", "6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"], ["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593", "c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"], ["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef", "21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"], ["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38", "60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"], ["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a", "49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"], ["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111", "5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"], ["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502", "7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"], ["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea", "be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"], ["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26", "8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"], ["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986", "39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"], ["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e", "62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"], ["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4", "25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"], ["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda", "ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"], ["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859", "cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"], ["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f", "f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"], ["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c", "6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"], ["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942", "fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"], ["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a", "1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"], ["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80", "5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"], ["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d", "438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"], ["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1", "cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"], ["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63", "c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"], ["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352", "6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"], ["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193", "ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"], ["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00", "9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"], ["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58", "ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"], ["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7", "d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"], ["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8", "c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"], ["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e", "67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"], ["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d", "cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"], ["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b", "299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"], ["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f", "f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"], ["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6", "462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"], ["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297", "62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"], ["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a", "7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"], ["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c", "ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"], ["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52", "4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"], ["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb", "bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"], ["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065", "bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"], ["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917", "603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"], ["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9", "cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"], ["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3", "553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"], ["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57", "712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"], ["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66", "ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"], ["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8", "9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"], ["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721", "9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"], ["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180", "4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]] + } + }; + return exports$H$1; +} - lo = Math.imul(al4, bl0); - mid = Math.imul(al4, bh0); - mid = mid + Math.imul(ah4, bl0) | 0; - hi = Math.imul(ah4, bh0); - lo = lo + Math.imul(al3, bl1) | 0; - mid = mid + Math.imul(al3, bh1) | 0; - mid = mid + Math.imul(ah3, bl1) | 0; - hi = hi + Math.imul(ah3, bh1) | 0; - lo = lo + Math.imul(al2, bl2) | 0; - mid = mid + Math.imul(al2, bh2) | 0; - mid = mid + Math.imul(ah2, bl2) | 0; - hi = hi + Math.imul(ah2, bh2) | 0; - lo = lo + Math.imul(al1, bl3) | 0; - mid = mid + Math.imul(al1, bh3) | 0; - mid = mid + Math.imul(ah1, bl3) | 0; - hi = hi + Math.imul(ah1, bh3) | 0; - lo = lo + Math.imul(al0, bl4) | 0; - mid = mid + Math.imul(al0, bh4) | 0; - mid = mid + Math.imul(ah0, bl4) | 0; - hi = hi + Math.imul(ah0, bh4) | 0; - var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; - w4 &= 67108863; - /* k = 5 */ +var exports$G$1 = {}, + _dewExec$G$1 = false; +function dew$G$1() { + if (_dewExec$G$1) return exports$G$1; + _dewExec$G$1 = true; + var curves = exports$G$1; - lo = Math.imul(al5, bl0); - mid = Math.imul(al5, bh0); - mid = mid + Math.imul(ah5, bl0) | 0; - hi = Math.imul(ah5, bh0); - lo = lo + Math.imul(al4, bl1) | 0; - mid = mid + Math.imul(al4, bh1) | 0; - mid = mid + Math.imul(ah4, bl1) | 0; - hi = hi + Math.imul(ah4, bh1) | 0; - lo = lo + Math.imul(al3, bl2) | 0; - mid = mid + Math.imul(al3, bh2) | 0; - mid = mid + Math.imul(ah3, bl2) | 0; - hi = hi + Math.imul(ah3, bh2) | 0; - lo = lo + Math.imul(al2, bl3) | 0; - mid = mid + Math.imul(al2, bh3) | 0; - mid = mid + Math.imul(ah2, bl3) | 0; - hi = hi + Math.imul(ah2, bh3) | 0; - lo = lo + Math.imul(al1, bl4) | 0; - mid = mid + Math.imul(al1, bh4) | 0; - mid = mid + Math.imul(ah1, bl4) | 0; - hi = hi + Math.imul(ah1, bh4) | 0; - lo = lo + Math.imul(al0, bl5) | 0; - mid = mid + Math.imul(al0, bh5) | 0; - mid = mid + Math.imul(ah0, bl5) | 0; - hi = hi + Math.imul(ah0, bh5) | 0; - var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; - w5 &= 67108863; - /* k = 6 */ + var hash = dew$I$1(); - lo = Math.imul(al6, bl0); - mid = Math.imul(al6, bh0); - mid = mid + Math.imul(ah6, bl0) | 0; - hi = Math.imul(ah6, bh0); - lo = lo + Math.imul(al5, bl1) | 0; - mid = mid + Math.imul(al5, bh1) | 0; - mid = mid + Math.imul(ah5, bl1) | 0; - hi = hi + Math.imul(ah5, bh1) | 0; - lo = lo + Math.imul(al4, bl2) | 0; - mid = mid + Math.imul(al4, bh2) | 0; - mid = mid + Math.imul(ah4, bl2) | 0; - hi = hi + Math.imul(ah4, bh2) | 0; - lo = lo + Math.imul(al3, bl3) | 0; - mid = mid + Math.imul(al3, bh3) | 0; - mid = mid + Math.imul(ah3, bl3) | 0; - hi = hi + Math.imul(ah3, bh3) | 0; - lo = lo + Math.imul(al2, bl4) | 0; - mid = mid + Math.imul(al2, bh4) | 0; - mid = mid + Math.imul(ah2, bl4) | 0; - hi = hi + Math.imul(ah2, bh4) | 0; - lo = lo + Math.imul(al1, bl5) | 0; - mid = mid + Math.imul(al1, bh5) | 0; - mid = mid + Math.imul(ah1, bl5) | 0; - hi = hi + Math.imul(ah1, bh5) | 0; - lo = lo + Math.imul(al0, bl6) | 0; - mid = mid + Math.imul(al0, bh6) | 0; - mid = mid + Math.imul(ah0, bl6) | 0; - hi = hi + Math.imul(ah0, bh6) | 0; - var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; - w6 &= 67108863; - /* k = 7 */ + var curve = dew$O$1(); - lo = Math.imul(al7, bl0); - mid = Math.imul(al7, bh0); - mid = mid + Math.imul(ah7, bl0) | 0; - hi = Math.imul(ah7, bh0); - lo = lo + Math.imul(al6, bl1) | 0; - mid = mid + Math.imul(al6, bh1) | 0; - mid = mid + Math.imul(ah6, bl1) | 0; - hi = hi + Math.imul(ah6, bh1) | 0; - lo = lo + Math.imul(al5, bl2) | 0; - mid = mid + Math.imul(al5, bh2) | 0; - mid = mid + Math.imul(ah5, bl2) | 0; - hi = hi + Math.imul(ah5, bh2) | 0; - lo = lo + Math.imul(al4, bl3) | 0; - mid = mid + Math.imul(al4, bh3) | 0; - mid = mid + Math.imul(ah4, bl3) | 0; - hi = hi + Math.imul(ah4, bh3) | 0; - lo = lo + Math.imul(al3, bl4) | 0; - mid = mid + Math.imul(al3, bh4) | 0; - mid = mid + Math.imul(ah3, bl4) | 0; - hi = hi + Math.imul(ah3, bh4) | 0; - lo = lo + Math.imul(al2, bl5) | 0; - mid = mid + Math.imul(al2, bh5) | 0; - mid = mid + Math.imul(ah2, bl5) | 0; - hi = hi + Math.imul(ah2, bh5) | 0; - lo = lo + Math.imul(al1, bl6) | 0; - mid = mid + Math.imul(al1, bh6) | 0; - mid = mid + Math.imul(ah1, bl6) | 0; - hi = hi + Math.imul(ah1, bh6) | 0; - lo = lo + Math.imul(al0, bl7) | 0; - mid = mid + Math.imul(al0, bh7) | 0; - mid = mid + Math.imul(ah0, bl7) | 0; - hi = hi + Math.imul(ah0, bh7) | 0; - var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; - w7 &= 67108863; - /* k = 8 */ + var utils = dew$T$1(); - lo = Math.imul(al8, bl0); - mid = Math.imul(al8, bh0); - mid = mid + Math.imul(ah8, bl0) | 0; - hi = Math.imul(ah8, bh0); - lo = lo + Math.imul(al7, bl1) | 0; - mid = mid + Math.imul(al7, bh1) | 0; - mid = mid + Math.imul(ah7, bl1) | 0; - hi = hi + Math.imul(ah7, bh1) | 0; - lo = lo + Math.imul(al6, bl2) | 0; - mid = mid + Math.imul(al6, bh2) | 0; - mid = mid + Math.imul(ah6, bl2) | 0; - hi = hi + Math.imul(ah6, bh2) | 0; - lo = lo + Math.imul(al5, bl3) | 0; - mid = mid + Math.imul(al5, bh3) | 0; - mid = mid + Math.imul(ah5, bl3) | 0; - hi = hi + Math.imul(ah5, bh3) | 0; - lo = lo + Math.imul(al4, bl4) | 0; - mid = mid + Math.imul(al4, bh4) | 0; - mid = mid + Math.imul(ah4, bl4) | 0; - hi = hi + Math.imul(ah4, bh4) | 0; - lo = lo + Math.imul(al3, bl5) | 0; - mid = mid + Math.imul(al3, bh5) | 0; - mid = mid + Math.imul(ah3, bl5) | 0; - hi = hi + Math.imul(ah3, bh5) | 0; - lo = lo + Math.imul(al2, bl6) | 0; - mid = mid + Math.imul(al2, bh6) | 0; - mid = mid + Math.imul(ah2, bl6) | 0; - hi = hi + Math.imul(ah2, bh6) | 0; - lo = lo + Math.imul(al1, bl7) | 0; - mid = mid + Math.imul(al1, bh7) | 0; - mid = mid + Math.imul(ah1, bl7) | 0; - hi = hi + Math.imul(ah1, bh7) | 0; - lo = lo + Math.imul(al0, bl8) | 0; - mid = mid + Math.imul(al0, bh8) | 0; - mid = mid + Math.imul(ah0, bl8) | 0; - hi = hi + Math.imul(ah0, bh8) | 0; - var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; - w8 &= 67108863; - /* k = 9 */ + var assert = utils.assert; - lo = Math.imul(al9, bl0); - mid = Math.imul(al9, bh0); - mid = mid + Math.imul(ah9, bl0) | 0; - hi = Math.imul(ah9, bh0); - lo = lo + Math.imul(al8, bl1) | 0; - mid = mid + Math.imul(al8, bh1) | 0; - mid = mid + Math.imul(ah8, bl1) | 0; - hi = hi + Math.imul(ah8, bh1) | 0; - lo = lo + Math.imul(al7, bl2) | 0; - mid = mid + Math.imul(al7, bh2) | 0; - mid = mid + Math.imul(ah7, bl2) | 0; - hi = hi + Math.imul(ah7, bh2) | 0; - lo = lo + Math.imul(al6, bl3) | 0; - mid = mid + Math.imul(al6, bh3) | 0; - mid = mid + Math.imul(ah6, bl3) | 0; - hi = hi + Math.imul(ah6, bh3) | 0; - lo = lo + Math.imul(al5, bl4) | 0; - mid = mid + Math.imul(al5, bh4) | 0; - mid = mid + Math.imul(ah5, bl4) | 0; - hi = hi + Math.imul(ah5, bh4) | 0; - lo = lo + Math.imul(al4, bl5) | 0; - mid = mid + Math.imul(al4, bh5) | 0; - mid = mid + Math.imul(ah4, bl5) | 0; - hi = hi + Math.imul(ah4, bh5) | 0; - lo = lo + Math.imul(al3, bl6) | 0; - mid = mid + Math.imul(al3, bh6) | 0; - mid = mid + Math.imul(ah3, bl6) | 0; - hi = hi + Math.imul(ah3, bh6) | 0; - lo = lo + Math.imul(al2, bl7) | 0; - mid = mid + Math.imul(al2, bh7) | 0; - mid = mid + Math.imul(ah2, bl7) | 0; - hi = hi + Math.imul(ah2, bh7) | 0; - lo = lo + Math.imul(al1, bl8) | 0; - mid = mid + Math.imul(al1, bh8) | 0; - mid = mid + Math.imul(ah1, bl8) | 0; - hi = hi + Math.imul(ah1, bh8) | 0; - lo = lo + Math.imul(al0, bl9) | 0; - mid = mid + Math.imul(al0, bh9) | 0; - mid = mid + Math.imul(ah0, bl9) | 0; - hi = hi + Math.imul(ah0, bh9) | 0; - var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; - w9 &= 67108863; - /* k = 10 */ + function PresetCurve(options) { + if (options.type === "short") this.curve = new curve.short(options);else if (options.type === "edwards") this.curve = new curve.edwards(options);else this.curve = new curve.mont(options); + this.g = this.curve.g; + this.n = this.curve.n; + this.hash = options.hash; + assert(this.g.validate(), "Invalid curve"); + assert(this.g.mul(this.n).isInfinity(), "Invalid curve, G*N != O"); + } - lo = Math.imul(al9, bl1); - mid = Math.imul(al9, bh1); - mid = mid + Math.imul(ah9, bl1) | 0; - hi = Math.imul(ah9, bh1); - lo = lo + Math.imul(al8, bl2) | 0; - mid = mid + Math.imul(al8, bh2) | 0; - mid = mid + Math.imul(ah8, bl2) | 0; - hi = hi + Math.imul(ah8, bh2) | 0; - lo = lo + Math.imul(al7, bl3) | 0; - mid = mid + Math.imul(al7, bh3) | 0; - mid = mid + Math.imul(ah7, bl3) | 0; - hi = hi + Math.imul(ah7, bh3) | 0; - lo = lo + Math.imul(al6, bl4) | 0; - mid = mid + Math.imul(al6, bh4) | 0; - mid = mid + Math.imul(ah6, bl4) | 0; - hi = hi + Math.imul(ah6, bh4) | 0; - lo = lo + Math.imul(al5, bl5) | 0; - mid = mid + Math.imul(al5, bh5) | 0; - mid = mid + Math.imul(ah5, bl5) | 0; - hi = hi + Math.imul(ah5, bh5) | 0; - lo = lo + Math.imul(al4, bl6) | 0; - mid = mid + Math.imul(al4, bh6) | 0; - mid = mid + Math.imul(ah4, bl6) | 0; - hi = hi + Math.imul(ah4, bh6) | 0; - lo = lo + Math.imul(al3, bl7) | 0; - mid = mid + Math.imul(al3, bh7) | 0; - mid = mid + Math.imul(ah3, bl7) | 0; - hi = hi + Math.imul(ah3, bh7) | 0; - lo = lo + Math.imul(al2, bl8) | 0; - mid = mid + Math.imul(al2, bh8) | 0; - mid = mid + Math.imul(ah2, bl8) | 0; - hi = hi + Math.imul(ah2, bh8) | 0; - lo = lo + Math.imul(al1, bl9) | 0; - mid = mid + Math.imul(al1, bh9) | 0; - mid = mid + Math.imul(ah1, bl9) | 0; - hi = hi + Math.imul(ah1, bh9) | 0; - var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; - w10 &= 67108863; - /* k = 11 */ + curves.PresetCurve = PresetCurve; - lo = Math.imul(al9, bl2); - mid = Math.imul(al9, bh2); - mid = mid + Math.imul(ah9, bl2) | 0; - hi = Math.imul(ah9, bh2); - lo = lo + Math.imul(al8, bl3) | 0; - mid = mid + Math.imul(al8, bh3) | 0; - mid = mid + Math.imul(ah8, bl3) | 0; - hi = hi + Math.imul(ah8, bh3) | 0; - lo = lo + Math.imul(al7, bl4) | 0; - mid = mid + Math.imul(al7, bh4) | 0; - mid = mid + Math.imul(ah7, bl4) | 0; - hi = hi + Math.imul(ah7, bh4) | 0; - lo = lo + Math.imul(al6, bl5) | 0; - mid = mid + Math.imul(al6, bh5) | 0; - mid = mid + Math.imul(ah6, bl5) | 0; - hi = hi + Math.imul(ah6, bh5) | 0; - lo = lo + Math.imul(al5, bl6) | 0; - mid = mid + Math.imul(al5, bh6) | 0; - mid = mid + Math.imul(ah5, bl6) | 0; - hi = hi + Math.imul(ah5, bh6) | 0; - lo = lo + Math.imul(al4, bl7) | 0; - mid = mid + Math.imul(al4, bh7) | 0; - mid = mid + Math.imul(ah4, bl7) | 0; - hi = hi + Math.imul(ah4, bh7) | 0; - lo = lo + Math.imul(al3, bl8) | 0; - mid = mid + Math.imul(al3, bh8) | 0; - mid = mid + Math.imul(ah3, bl8) | 0; - hi = hi + Math.imul(ah3, bh8) | 0; - lo = lo + Math.imul(al2, bl9) | 0; - mid = mid + Math.imul(al2, bh9) | 0; - mid = mid + Math.imul(ah2, bl9) | 0; - hi = hi + Math.imul(ah2, bh9) | 0; - var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; - w11 &= 67108863; - /* k = 12 */ + function defineCurve(name, options) { + Object.defineProperty(curves, name, { + configurable: true, + enumerable: true, + get: function () { + var curve = new PresetCurve(options); + Object.defineProperty(curves, name, { + configurable: true, + enumerable: true, + value: curve + }); + return curve; + } + }); + } + + defineCurve("p192", { + type: "short", + prime: "p192", + p: "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff", + a: "ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc", + b: "64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1", + n: "ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831", + hash: hash.sha256, + gRed: false, + g: ["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012", "07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"] + }); + defineCurve("p224", { + type: "short", + prime: "p224", + p: "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001", + a: "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe", + b: "b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4", + n: "ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d", + hash: hash.sha256, + gRed: false, + g: ["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21", "bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"] + }); + defineCurve("p256", { + type: "short", + prime: null, + p: "ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff", + a: "ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc", + b: "5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b", + n: "ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551", + hash: hash.sha256, + gRed: false, + g: ["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296", "4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"] + }); + defineCurve("p384", { + type: "short", + prime: null, + p: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff " + "fffffffe ffffffff 00000000 00000000 ffffffff", + a: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff " + "fffffffe ffffffff 00000000 00000000 fffffffc", + b: "b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f " + "5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef", + n: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 " + "f4372ddf 581a0db2 48b0a77a ecec196a ccc52973", + hash: hash.sha384, + gRed: false, + g: ["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 " + "5502f25d bf55296c 3a545e38 72760ab7", "3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 " + "0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"] + }); + defineCurve("p521", { + type: "short", + prime: null, + p: "000001ff ffffffff ffffffff ffffffff ffffffff ffffffff " + "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff " + "ffffffff ffffffff ffffffff ffffffff ffffffff", + a: "000001ff ffffffff ffffffff ffffffff ffffffff ffffffff " + "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff " + "ffffffff ffffffff ffffffff ffffffff fffffffc", + b: "00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b " + "99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd " + "3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00", + n: "000001ff ffffffff ffffffff ffffffff ffffffff ffffffff " + "ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 " + "f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409", + hash: hash.sha512, + gRed: false, + g: ["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 " + "053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 " + "a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66", "00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 " + "579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 " + "3fad0761 353c7086 a272c240 88be9476 9fd16650"] + }); + defineCurve("curve25519", { + type: "mont", + prime: "p25519", + p: "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed", + a: "76d06", + b: "1", + n: "1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed", + hash: hash.sha256, + gRed: false, + g: ["9"] + }); + defineCurve("ed25519", { + type: "edwards", + prime: "p25519", + p: "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed", + a: "-1", + c: "1", + // -121665 * (121666^(-1)) (mod P) + d: "52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3", + n: "1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed", + hash: hash.sha256, + gRed: false, + g: ["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a", // 4/5 + "6666666666666666666666666666666666666666666666666666666666666658"] + }); + var pre; + + try { + pre = dew$H$1(); + } catch (e) { + pre = undefined; + } + + defineCurve("secp256k1", { + type: "short", + prime: "k256", + p: "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f", + a: "0", + b: "7", + n: "ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141", + h: "1", + hash: hash.sha256, + // Precomputed endomorphism + beta: "7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee", + lambda: "5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72", + basis: [{ + a: "3086d221a7d46bcde86c90e49284eb15", + b: "-e4437ed6010e88286f547fa90abfe4c3" + }, { + a: "114ca50f7a8e2f3f657c1108d9d44cfd8", + b: "3086d221a7d46bcde86c90e49284eb15" + }], + gRed: false, + g: ["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", pre] + }); + return exports$G$1; +} - lo = Math.imul(al9, bl3); - mid = Math.imul(al9, bh3); - mid = mid + Math.imul(ah9, bl3) | 0; - hi = Math.imul(ah9, bh3); - lo = lo + Math.imul(al8, bl4) | 0; - mid = mid + Math.imul(al8, bh4) | 0; - mid = mid + Math.imul(ah8, bl4) | 0; - hi = hi + Math.imul(ah8, bh4) | 0; - lo = lo + Math.imul(al7, bl5) | 0; - mid = mid + Math.imul(al7, bh5) | 0; - mid = mid + Math.imul(ah7, bl5) | 0; - hi = hi + Math.imul(ah7, bh5) | 0; - lo = lo + Math.imul(al6, bl6) | 0; - mid = mid + Math.imul(al6, bh6) | 0; - mid = mid + Math.imul(ah6, bl6) | 0; - hi = hi + Math.imul(ah6, bh6) | 0; - lo = lo + Math.imul(al5, bl7) | 0; - mid = mid + Math.imul(al5, bh7) | 0; - mid = mid + Math.imul(ah5, bl7) | 0; - hi = hi + Math.imul(ah5, bh7) | 0; - lo = lo + Math.imul(al4, bl8) | 0; - mid = mid + Math.imul(al4, bh8) | 0; - mid = mid + Math.imul(ah4, bl8) | 0; - hi = hi + Math.imul(ah4, bh8) | 0; - lo = lo + Math.imul(al3, bl9) | 0; - mid = mid + Math.imul(al3, bh9) | 0; - mid = mid + Math.imul(ah3, bl9) | 0; - hi = hi + Math.imul(ah3, bh9) | 0; - var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; - w12 &= 67108863; - /* k = 13 */ +var exports$F$1 = {}, + _dewExec$F$1 = false; +function dew$F$1() { + if (_dewExec$F$1) return exports$F$1; + _dewExec$F$1 = true; - lo = Math.imul(al9, bl4); - mid = Math.imul(al9, bh4); - mid = mid + Math.imul(ah9, bl4) | 0; - hi = Math.imul(ah9, bh4); - lo = lo + Math.imul(al8, bl5) | 0; - mid = mid + Math.imul(al8, bh5) | 0; - mid = mid + Math.imul(ah8, bl5) | 0; - hi = hi + Math.imul(ah8, bh5) | 0; - lo = lo + Math.imul(al7, bl6) | 0; - mid = mid + Math.imul(al7, bh6) | 0; - mid = mid + Math.imul(ah7, bl6) | 0; - hi = hi + Math.imul(ah7, bh6) | 0; - lo = lo + Math.imul(al6, bl7) | 0; - mid = mid + Math.imul(al6, bh7) | 0; - mid = mid + Math.imul(ah6, bl7) | 0; - hi = hi + Math.imul(ah6, bh7) | 0; - lo = lo + Math.imul(al5, bl8) | 0; - mid = mid + Math.imul(al5, bh8) | 0; - mid = mid + Math.imul(ah5, bl8) | 0; - hi = hi + Math.imul(ah5, bh8) | 0; - lo = lo + Math.imul(al4, bl9) | 0; - mid = mid + Math.imul(al4, bh9) | 0; - mid = mid + Math.imul(ah4, bl9) | 0; - hi = hi + Math.imul(ah4, bh9) | 0; - var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; - w13 &= 67108863; - /* k = 14 */ + var hash = dew$I$1(); - lo = Math.imul(al9, bl5); - mid = Math.imul(al9, bh5); - mid = mid + Math.imul(ah9, bl5) | 0; - hi = Math.imul(ah9, bh5); - lo = lo + Math.imul(al8, bl6) | 0; - mid = mid + Math.imul(al8, bh6) | 0; - mid = mid + Math.imul(ah8, bl6) | 0; - hi = hi + Math.imul(ah8, bh6) | 0; - lo = lo + Math.imul(al7, bl7) | 0; - mid = mid + Math.imul(al7, bh7) | 0; - mid = mid + Math.imul(ah7, bl7) | 0; - hi = hi + Math.imul(ah7, bh7) | 0; - lo = lo + Math.imul(al6, bl8) | 0; - mid = mid + Math.imul(al6, bh8) | 0; - mid = mid + Math.imul(ah6, bl8) | 0; - hi = hi + Math.imul(ah6, bh8) | 0; - lo = lo + Math.imul(al5, bl9) | 0; - mid = mid + Math.imul(al5, bh9) | 0; - mid = mid + Math.imul(ah5, bl9) | 0; - hi = hi + Math.imul(ah5, bh9) | 0; - var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; - w14 &= 67108863; - /* k = 15 */ + var utils = dew$U$1(); - lo = Math.imul(al9, bl6); - mid = Math.imul(al9, bh6); - mid = mid + Math.imul(ah9, bl6) | 0; - hi = Math.imul(ah9, bh6); - lo = lo + Math.imul(al8, bl7) | 0; - mid = mid + Math.imul(al8, bh7) | 0; - mid = mid + Math.imul(ah8, bl7) | 0; - hi = hi + Math.imul(ah8, bh7) | 0; - lo = lo + Math.imul(al7, bl8) | 0; - mid = mid + Math.imul(al7, bh8) | 0; - mid = mid + Math.imul(ah7, bl8) | 0; - hi = hi + Math.imul(ah7, bh8) | 0; - lo = lo + Math.imul(al6, bl9) | 0; - mid = mid + Math.imul(al6, bh9) | 0; - mid = mid + Math.imul(ah6, bl9) | 0; - hi = hi + Math.imul(ah6, bh9) | 0; - var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; - w15 &= 67108863; - /* k = 16 */ + var assert = dew$1t(); - lo = Math.imul(al9, bl7); - mid = Math.imul(al9, bh7); - mid = mid + Math.imul(ah9, bl7) | 0; - hi = Math.imul(ah9, bh7); - lo = lo + Math.imul(al8, bl8) | 0; - mid = mid + Math.imul(al8, bh8) | 0; - mid = mid + Math.imul(ah8, bl8) | 0; - hi = hi + Math.imul(ah8, bh8) | 0; - lo = lo + Math.imul(al7, bl9) | 0; - mid = mid + Math.imul(al7, bh9) | 0; - mid = mid + Math.imul(ah7, bl9) | 0; - hi = hi + Math.imul(ah7, bh9) | 0; - var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; - w16 &= 67108863; - /* k = 17 */ + function HmacDRBG(options) { + if (!(this instanceof HmacDRBG)) return new HmacDRBG(options); + this.hash = options.hash; + this.predResist = !!options.predResist; + this.outLen = this.hash.outSize; + this.minEntropy = options.minEntropy || this.hash.hmacStrength; + this._reseed = null; + this.reseedInterval = null; + this.K = null; + this.V = null; + var entropy = utils.toArray(options.entropy, options.entropyEnc || "hex"); + var nonce = utils.toArray(options.nonce, options.nonceEnc || "hex"); + var pers = utils.toArray(options.pers, options.persEnc || "hex"); + assert(entropy.length >= this.minEntropy / 8, "Not enough entropy. Minimum is: " + this.minEntropy + " bits"); - lo = Math.imul(al9, bl8); - mid = Math.imul(al9, bh8); - mid = mid + Math.imul(ah9, bl8) | 0; - hi = Math.imul(ah9, bh8); - lo = lo + Math.imul(al8, bl9) | 0; - mid = mid + Math.imul(al8, bh9) | 0; - mid = mid + Math.imul(ah8, bl9) | 0; - hi = hi + Math.imul(ah8, bh9) | 0; - var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; - w17 &= 67108863; - /* k = 18 */ + this._init(entropy, nonce, pers); + } - lo = Math.imul(al9, bl9); - mid = Math.imul(al9, bh9); - mid = mid + Math.imul(ah9, bl9) | 0; - hi = Math.imul(ah9, bh9); - var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; - c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; - w18 &= 67108863; - o[0] = w0; - o[1] = w1; - o[2] = w2; - o[3] = w3; - o[4] = w4; - o[5] = w5; - o[6] = w6; - o[7] = w7; - o[8] = w8; - o[9] = w9; - o[10] = w10; - o[11] = w11; - o[12] = w12; - o[13] = w13; - o[14] = w14; - o[15] = w15; - o[16] = w16; - o[17] = w17; - o[18] = w18; + exports$F$1 = HmacDRBG; - if (c !== 0) { - o[19] = c; - out.length++; - } + HmacDRBG.prototype._init = function init(entropy, nonce, pers) { + var seed = entropy.concat(nonce).concat(pers); + this.K = new Array(this.outLen / 8); + this.V = new Array(this.outLen / 8); - return out; - }; // Polyfill comb + for (var i = 0; i < this.V.length; i++) { + this.K[i] = 0; + this.V[i] = 1; + } + this._update(seed); - if (!Math.imul) { - comb10MulTo = smallMulTo; + this._reseed = 1; + this.reseedInterval = 281474976710656; // 2^48 + }; + + HmacDRBG.prototype._hmac = function hmac() { + return new hash.hmac(this.hash, this.K); + }; + + HmacDRBG.prototype._update = function update(seed) { + var kmac = this._hmac().update(this.V).update([0]); + + if (seed) kmac = kmac.update(seed); + this.K = kmac.digest(); + this.V = this._hmac().update(this.V).digest(); + if (!seed) return; + this.K = this._hmac().update(this.V).update([1]).update(seed).digest(); + this.V = this._hmac().update(this.V).digest(); + }; + + HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) { + // Optional entropy enc + if (typeof entropyEnc !== "string") { + addEnc = add; + add = entropyEnc; + entropyEnc = null; } - function bigMulTo(self, num, out) { - out.negative = num.negative ^ self.negative; - out.length = self.length + num.length; - var carry = 0; - var hncarry = 0; + entropy = utils.toArray(entropy, entropyEnc); + add = utils.toArray(add, addEnc); + assert(entropy.length >= this.minEntropy / 8, "Not enough entropy. Minimum is: " + this.minEntropy + " bits"); - for (var k = 0; k < out.length - 1; k++) { - // Sum all words with the same `i + j = k` and accumulate `ncarry`, - // note that ncarry could be >= 0x3ffffff - var ncarry = hncarry; - hncarry = 0; - var rword = carry & 67108863; - var maxJ = Math.min(k, num.length - 1); + this._update(entropy.concat(add || [])); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { - var i = k - j; - var a = self.words[i] | 0; - var b = num.words[j] | 0; - var r = a * b; - var lo = r & 67108863; - ncarry = ncarry + (r / 67108864 | 0) | 0; - lo = lo + rword | 0; - rword = lo & 67108863; - ncarry = ncarry + (lo >>> 26) | 0; - hncarry += ncarry >>> 26; - ncarry &= 67108863; - } + this._reseed = 1; + }; - out.words[k] = rword; - carry = ncarry; - ncarry = hncarry; - } + HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { + if (this._reseed > this.reseedInterval) throw new Error("Reseed is required"); // Optional encoding - if (carry !== 0) { - out.words[k] = carry; - } else { - out.length--; - } + if (typeof enc !== "string") { + addEnc = add; + add = enc; + enc = null; + } // Optional additional data - return out.strip(); + + if (add) { + add = utils.toArray(add, addEnc || "hex"); + + this._update(add); } - function jumboMulTo(self, num, out) { - var fftm = new FFTM(); - return fftm.mulp(self, num, out); + var temp = []; + + while (temp.length < len) { + this.V = this._hmac().update(this.V).digest(); + temp = temp.concat(this.V); } - BN.prototype.mulTo = function mulTo(num, out) { - var res; - var len = (this || _global$y).length + num.length; + var res = temp.slice(0, len); - if ((this || _global$y).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$y, num, out); - } else if (len < 63) { - res = smallMulTo(this || _global$y, num, out); - } else if (len < 1024) { - res = bigMulTo(this || _global$y, num, out); - } else { - res = jumboMulTo(this || _global$y, num, out); - } + this._update(add); - return res; - }; // Cooley-Tukey algorithm for FFT - // slightly revisited to rely on looping instead of recursion + this._reseed++; + return utils.encode(res, enc); + }; + return exports$F$1; +} - function FFTM(x, y) { - (this || _global$y).x = x; - (this || _global$y).y = y; - } +var exports$E$1 = {}, + _dewExec$E$1 = false; +function dew$E$1() { + if (_dewExec$E$1) return exports$E$1; + _dewExec$E$1 = true; - FFTM.prototype.makeRBT = function makeRBT(N) { - var t = new Array(N); - var l = BN.prototype._countBits(N) - 1; + var BN = dew$V$1(); - for (var i = 0; i < N; i++) { - t[i] = this.revBin(i, l, N); - } + var utils = dew$T$1(); - return t; - }; // Returns binary-reversed representation of `x` + var assert = utils.assert; + function KeyPair(ec, options) { + this.ec = ec; + this.priv = null; + this.pub = null; // KeyPair(ec, { priv: ..., pub: ... }) - FFTM.prototype.revBin = function revBin(x, l, N) { - if (x === 0 || x === N - 1) return x; - var rb = 0; + if (options.priv) this._importPrivate(options.priv, options.privEnc); + if (options.pub) this._importPublic(options.pub, options.pubEnc); + } - for (var i = 0; i < l; i++) { - rb |= (x & 1) << l - i - 1; - x >>= 1; - } + exports$E$1 = KeyPair; - return rb; - }; // Performs "tweedling" phase, therefore 'emulating' - // behaviour of the recursive algorithm + KeyPair.fromPublic = function fromPublic(ec, pub, enc) { + if (pub instanceof KeyPair) return pub; + return new KeyPair(ec, { + pub: pub, + pubEnc: enc + }); + }; + KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) { + if (priv instanceof KeyPair) return priv; + return new KeyPair(ec, { + priv: priv, + privEnc: enc + }); + }; - FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { - for (var i = 0; i < N; i++) { - rtws[i] = rws[rbt[i]]; - itws[i] = iws[rbt[i]]; - } + KeyPair.prototype.validate = function validate() { + var pub = this.getPublic(); + if (pub.isInfinity()) return { + result: false, + reason: "Invalid public key" + }; + if (!pub.validate()) return { + result: false, + reason: "Public key is not a point" + }; + if (!pub.mul(this.ec.curve.n).isInfinity()) return { + result: false, + reason: "Public key * N != O" + }; + return { + result: true, + reason: null }; + }; - FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { - this.permute(rbt, rws, iws, rtws, itws, N); + KeyPair.prototype.getPublic = function getPublic(compact, enc) { + // compact is optional argument + if (typeof compact === "string") { + enc = compact; + compact = null; + } - for (var s = 1; s < N; s <<= 1) { - var l = s << 1; - var rtwdf = Math.cos(2 * Math.PI / l); - var itwdf = Math.sin(2 * Math.PI / l); + if (!this.pub) this.pub = this.ec.g.mul(this.priv); + if (!enc) return this.pub; + return this.pub.encode(enc, compact); + }; - for (var p = 0; p < N; p += l) { - var rtwdf_ = rtwdf; - var itwdf_ = itwdf; + KeyPair.prototype.getPrivate = function getPrivate(enc) { + if (enc === "hex") return this.priv.toString(16, 2);else return this.priv; + }; - for (var j = 0; j < s; j++) { - var re = rtws[p + j]; - var ie = itws[p + j]; - var ro = rtws[p + j + s]; - var io = itws[p + j + s]; - var rx = rtwdf_ * ro - itwdf_ * io; - io = rtwdf_ * io + itwdf_ * ro; - ro = rx; - rtws[p + j] = re + ro; - itws[p + j] = ie + io; - rtws[p + j + s] = re - ro; - itws[p + j + s] = ie - io; - /* jshint maxdepth : false */ + KeyPair.prototype._importPrivate = function _importPrivate(key, enc) { + this.priv = new BN(key, enc || 16); // Ensure that the priv won't be bigger than n, otherwise we may fail + // in fixed multiplication method - if (j !== l) { - rx = rtwdf * rtwdf_ - itwdf * itwdf_; - itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; - rtwdf_ = rx; - } - } - } + this.priv = this.priv.umod(this.ec.curve.n); + }; + + KeyPair.prototype._importPublic = function _importPublic(key, enc) { + if (key.x || key.y) { + // Montgomery points only have an `x` coordinate. + // Weierstrass/Edwards points on the other hand have both `x` and + // `y` coordinates. + if (this.ec.curve.type === "mont") { + assert(key.x, "Need x coordinate"); + } else if (this.ec.curve.type === "short" || this.ec.curve.type === "edwards") { + assert(key.x && key.y, "Need both x and y coordinate"); } - }; - FFTM.prototype.guessLen13b = function guessLen13b(n, m) { - var N = Math.max(m, n) | 1; - var odd = N & 1; - var i = 0; + this.pub = this.ec.curve.point(key.x, key.y); + return; + } - for (N = N / 2 | 0; N; N = N >>> 1) { - i++; - } + this.pub = this.ec.curve.decodePoint(key, enc); + }; // ECDH + + + KeyPair.prototype.derive = function derive(pub) { + if (!pub.validate()) { + assert(pub.validate(), "public point not validated"); + } + + return pub.mul(this.priv).getX(); + }; // ECDSA + + + KeyPair.prototype.sign = function sign(msg, enc, options) { + return this.ec.sign(msg, this, enc, options); + }; + + KeyPair.prototype.verify = function verify(msg, signature) { + return this.ec.verify(msg, signature, this); + }; + + KeyPair.prototype.inspect = function inspect() { + return ""; + }; + + return exports$E$1; +} + +var exports$D$1 = {}, + _dewExec$D$1 = false; +function dew$D$1() { + if (_dewExec$D$1) return exports$D$1; + _dewExec$D$1 = true; + + var BN = dew$V$1(); + + var utils = dew$T$1(); + + var assert = utils.assert; + + function Signature(options, enc) { + if (options instanceof Signature) return options; + if (this._importDER(options, enc)) return; + assert(options.r && options.s, "Signature without r or s"); + this.r = new BN(options.r, 16); + this.s = new BN(options.s, 16); + if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam; + } - return 1 << i + 1 + odd; - }; + exports$D$1 = Signature; - FFTM.prototype.conjugate = function conjugate(rws, iws, N) { - if (N <= 1) return; + function Position() { + this.place = 0; + } - for (var i = 0; i < N / 2; i++) { - var t = rws[i]; - rws[i] = rws[N - i - 1]; - rws[N - i - 1] = t; - t = iws[i]; - iws[i] = -iws[N - i - 1]; - iws[N - i - 1] = -t; - } - }; + function getLength(buf, p) { + var initial = buf[p.place++]; - FFTM.prototype.normalize13b = function normalize13b(ws, N) { - var carry = 0; + if (!(initial & 128)) { + return initial; + } - for (var i = 0; i < N / 2; i++) { - var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; - ws[i] = w & 67108863; + var octetLen = initial & 15; // Indefinite length or overflow - if (w < 67108864) { - carry = 0; - } else { - carry = w / 67108864 | 0; - } - } + if (octetLen === 0 || octetLen > 4) { + return false; + } - return ws; - }; + var val = 0; - FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { - var carry = 0; + for (var i = 0, off = p.place; i < octetLen; i++, off++) { + val <<= 8; + val |= buf[off]; + val >>>= 0; + } // Leading zeroes - for (var i = 0; i < len; i++) { - carry = carry + (ws[i] | 0); - rws[2 * i] = carry & 8191; - carry = carry >>> 13; - rws[2 * i + 1] = carry & 8191; - carry = carry >>> 13; - } // Pad with zeroes + if (val <= 127) { + return false; + } - for (i = 2 * len; i < N; ++i) { - rws[i] = 0; - } + p.place = off; + return val; + } - assert(carry === 0); - assert((carry & ~8191) === 0); - }; + function rmPadding(buf) { + var i = 0; + var len = buf.length - 1; - FFTM.prototype.stub = function stub(N) { - var ph = new Array(N); + while (!buf[i] && !(buf[i + 1] & 128) && i < len) { + i++; + } - for (var i = 0; i < N; i++) { - ph[i] = 0; - } + if (i === 0) { + return buf; + } - return ph; - }; + return buf.slice(i); + } - FFTM.prototype.mulp = function mulp(x, y, out) { - var N = 2 * this.guessLen13b(x.length, y.length); - var rbt = this.makeRBT(N); + Signature.prototype._importDER = function _importDER(data, enc) { + data = utils.toArray(data, enc); + var p = new Position(); - var _ = this.stub(N); + if (data[p.place++] !== 48) { + return false; + } - var rws = new Array(N); - var rwst = new Array(N); - var iwst = new Array(N); - var nrws = new Array(N); - var nrwst = new Array(N); - var niwst = new Array(N); - var rmws = out.words; - rmws.length = N; - this.convert13b(x.words, x.length, rws, N); - this.convert13b(y.words, y.length, nrws, N); - this.transform(rws, _, rwst, iwst, N, rbt); - this.transform(nrws, _, nrwst, niwst, N, rbt); + var len = getLength(data, p); - for (var i = 0; i < N; i++) { - var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; - iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; - rwst[i] = rx; - } + if (len === false) { + return false; + } - this.conjugate(rwst, iwst, N); - this.transform(rwst, iwst, rmws, _, N, rbt); - this.conjugate(rmws, _, N); - this.normalize13b(rmws, N); - out.negative = x.negative ^ y.negative; - out.length = x.length + y.length; - return out.strip(); - }; // Multiply `this` by `num` + if (len + p.place !== data.length) { + return false; + } + if (data[p.place++] !== 2) { + return false; + } - BN.prototype.mul = function mul(num) { - var out = new BN(null); - out.words = new Array((this || _global$y).length + num.length); - return this.mulTo(num, out); - }; // Multiply employing FFT + var rlen = getLength(data, p); + if (rlen === false) { + return false; + } - BN.prototype.mulf = function mulf(num) { - var out = new BN(null); - out.words = new Array((this || _global$y).length + num.length); - return jumboMulTo(this || _global$y, num, out); - }; // In-place Multiplication + var r = data.slice(p.place, rlen + p.place); + p.place += rlen; + if (data[p.place++] !== 2) { + return false; + } - BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$y); - }; + var slen = getLength(data, p); - BN.prototype.imuln = function imuln(num) { - assert(typeof num === "number"); - assert(num < 67108864); // Carry + if (slen === false) { + return false; + } - var carry = 0; + if (data.length !== slen + p.place) { + return false; + } - for (var i = 0; i < (this || _global$y).length; i++) { - var w = ((this || _global$y).words[i] | 0) * num; - var lo = (w & 67108863) + (carry & 67108863); - carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum + var s = data.slice(p.place, slen + p.place); - carry += lo >>> 26; - (this || _global$y).words[i] = lo & 67108863; + if (r[0] === 0) { + if (r[1] & 128) { + r = r.slice(1); + } else { + // Leading zeroes + return false; } + } - if (carry !== 0) { - (this || _global$y).words[i] = carry; - (this || _global$y).length++; + if (s[0] === 0) { + if (s[1] & 128) { + s = s.slice(1); + } else { + // Leading zeroes + return false; } + } - return this || _global$y; - }; + this.r = new BN(r); + this.s = new BN(s); + this.recoveryParam = null; + return true; + }; - BN.prototype.muln = function muln(num) { - return this.clone().imuln(num); - }; // `this` * `this` + function constructLength(arr, len) { + if (len < 128) { + arr.push(len); + return; + } + var octets = 1 + (Math.log(len) / Math.LN2 >>> 3); + arr.push(octets | 128); - BN.prototype.sqr = function sqr() { - return this.mul(this || _global$y); - }; // `this` * `this` in-place + while (--octets) { + arr.push(len >>> (octets << 3) & 255); + } + arr.push(len); + } - BN.prototype.isqr = function isqr() { - return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) + Signature.prototype.toDER = function toDER(enc) { + var r = this.r.toArray(); + var s = this.s.toArray(); // Pad values + if (r[0] & 128) r = [0].concat(r); // Pad values - BN.prototype.pow = function pow(num) { - var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes + if (s[0] & 128) s = [0].concat(s); + r = rmPadding(r); + s = rmPadding(s); - var res = this || _global$y; + while (!s[0] && !(s[1] & 128)) { + s = s.slice(1); + } - for (var i = 0; i < w.length; i++, res = res.sqr()) { - if (w[i] !== 0) break; - } + var arr = [2]; + constructLength(arr, r.length); + arr = arr.concat(r); + arr.push(2); + constructLength(arr, s.length); + var backHalf = arr.concat(s); + var res = [48]; + constructLength(res, backHalf.length); + res = res.concat(backHalf); + return utils.encode(res, enc); + }; - if (++i < w.length) { - for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { - if (w[i] === 0) continue; - res = res.mul(q); - } - } + return exports$D$1; +} - return res; - }; // Shift-left in-place +var exports$C$1 = {}, + _dewExec$C$1 = false; +function dew$C$1() { + if (_dewExec$C$1) return exports$C$1; + _dewExec$C$1 = true; + var BN = dew$V$1(); - BN.prototype.iushln = function iushln(bits) { - assert(typeof bits === "number" && bits >= 0); - var r = bits % 26; - var s = (bits - r) / 26; - var carryMask = 67108863 >>> 26 - r << 26 - r; - var i; + var HmacDRBG = dew$F$1(); - if (r !== 0) { - var carry = 0; + var utils = dew$T$1(); - for (i = 0; i < (this || _global$y).length; i++) { - var newCarry = (this || _global$y).words[i] & carryMask; - var c = ((this || _global$y).words[i] | 0) - newCarry << r; - (this || _global$y).words[i] = c | carry; - carry = newCarry >>> 26 - r; - } + var curves = dew$G$1(); - if (carry) { - (this || _global$y).words[i] = carry; - (this || _global$y).length++; - } - } + var rand = dew$10$1(); - if (s !== 0) { - for (i = (this || _global$y).length - 1; i >= 0; i--) { - (this || _global$y).words[i + s] = (this || _global$y).words[i]; - } + var assert = utils.assert; - for (i = 0; i < s; i++) { - (this || _global$y).words[i] = 0; - } + var KeyPair = dew$E$1(); - (this || _global$y).length += s; - } + var Signature = dew$D$1(); - return this.strip(); + function EC(options) { + if (!(this instanceof EC)) return new EC(options); // Shortcut `elliptic.ec(curve-name)` + + if (typeof options === "string") { + assert(Object.prototype.hasOwnProperty.call(curves, options), "Unknown curve " + options); + options = curves[options]; + } // Shortcut for `elliptic.ec(elliptic.curves.curveName)` + + + if (options instanceof curves.PresetCurve) options = { + curve: options }; + this.curve = options.curve.curve; + this.n = this.curve.n; + this.nh = this.n.ushrn(1); + this.g = this.curve.g; // Point on curve - BN.prototype.ishln = function ishln(bits) { - // TODO(indutny): implement me - assert((this || _global$y).negative === 0); - return this.iushln(bits); - }; // Shift-right in-place - // NOTE: `hint` is a lowest bit before trailing zeroes - // NOTE: if `extended` is present - it will be filled with destroyed bits + this.g = options.curve.g; + this.g.precompute(options.curve.n.bitLength() + 1); // Hash for function for DRBG + this.hash = options.hash || options.curve.hash; + } - BN.prototype.iushrn = function iushrn(bits, hint, extended) { - assert(typeof bits === "number" && bits >= 0); - var h; + exports$C$1 = EC; - if (hint) { - h = (hint - hint % 26) / 26; - } else { - h = 0; - } + EC.prototype.keyPair = function keyPair(options) { + return new KeyPair(this, options); + }; - var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$y).length); - var mask = 67108863 ^ 67108863 >>> r << r; - var maskedWords = extended; - h -= s; - h = Math.max(0, h); // Extended mode, copy masked part + EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) { + return KeyPair.fromPrivate(this, priv, enc); + }; - if (maskedWords) { - for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$y).words[i]; - } + EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) { + return KeyPair.fromPublic(this, pub, enc); + }; - maskedWords.length = s; - } + EC.prototype.genKeyPair = function genKeyPair(options) { + if (!options) options = {}; // Instantiate Hmac_DRBG - if (s === 0) ; else if ((this || _global$y).length > s) { - (this || _global$y).length -= s; + var drbg = new HmacDRBG({ + hash: this.hash, + pers: options.pers, + persEnc: options.persEnc || "utf8", + entropy: options.entropy || rand(this.hash.hmacStrength), + entropyEnc: options.entropy && options.entropyEnc || "utf8", + nonce: this.n.toArray() + }); + var bytes = this.n.byteLength(); + var ns2 = this.n.sub(new BN(2)); - for (i = 0; i < (this || _global$y).length; i++) { - (this || _global$y).words[i] = (this || _global$y).words[i + s]; - } - } else { - (this || _global$y).words[0] = 0; - (this || _global$y).length = 1; - } + for (;;) { + var priv = new BN(drbg.generate(bytes)); + if (priv.cmp(ns2) > 0) continue; + priv.iaddn(1); + return this.keyFromPrivate(priv); + } + }; - var carry = 0; + EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) { + var delta = msg.byteLength() * 8 - this.n.bitLength(); + if (delta > 0) msg = msg.ushrn(delta); + if (!truncOnly && msg.cmp(this.n) >= 0) return msg.sub(this.n);else return msg; + }; - for (i = (this || _global$y).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$y).words[i] | 0; - (this || _global$y).words[i] = carry << 26 - r | word >>> r; - carry = word & mask; - } // Push carried bits as a mask + EC.prototype.sign = function sign(msg, key, enc, options) { + if (typeof enc === "object") { + options = enc; + enc = null; + } + if (!options) options = {}; + key = this.keyFromPrivate(key, enc); + msg = this._truncateToN(new BN(msg, 16)); // Zero-extend key to provide enough entropy - if (maskedWords && carry !== 0) { - maskedWords.words[maskedWords.length++] = carry; - } + var bytes = this.n.byteLength(); + var bkey = key.getPrivate().toArray("be", bytes); // Zero-extend nonce to have the same byte size as N - if ((this || _global$y).length === 0) { - (this || _global$y).words[0] = 0; - (this || _global$y).length = 1; - } + var nonce = msg.toArray("be", bytes); // Instantiate Hmac_DRBG - return this.strip(); - }; + var drbg = new HmacDRBG({ + hash: this.hash, + entropy: bkey, + nonce: nonce, + pers: options.pers, + persEnc: options.persEnc || "utf8" + }); // Number of bytes to generate - BN.prototype.ishrn = function ishrn(bits, hint, extended) { - // TODO(indutny): implement me - assert((this || _global$y).negative === 0); - return this.iushrn(bits, hint, extended); - }; // Shift-left + var ns1 = this.n.sub(new BN(1)); + for (var iter = 0;; iter++) { + var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength())); + k = this._truncateToN(k, true); + if (k.cmpn(1) <= 0 || k.cmp(ns1) >= 0) continue; + var kp = this.g.mul(k); + if (kp.isInfinity()) continue; + var kpX = kp.getX(); + var r = kpX.umod(this.n); + if (r.cmpn(0) === 0) continue; + var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg)); + s = s.umod(this.n); + if (s.cmpn(0) === 0) continue; + var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0); // Use complement of `s`, if it is > `n / 2` - BN.prototype.shln = function shln(bits) { - return this.clone().ishln(bits); - }; + if (options.canonical && s.cmp(this.nh) > 0) { + s = this.n.sub(s); + recoveryParam ^= 1; + } - BN.prototype.ushln = function ushln(bits) { - return this.clone().iushln(bits); - }; // Shift-right + return new Signature({ + r: r, + s: s, + recoveryParam: recoveryParam + }); + } + }; + EC.prototype.verify = function verify(msg, signature, key, enc) { + msg = this._truncateToN(new BN(msg, 16)); + key = this.keyFromPublic(key, enc); + signature = new Signature(signature, "hex"); // Perform primitive values validation - BN.prototype.shrn = function shrn(bits) { - return this.clone().ishrn(bits); - }; + var r = signature.r; + var s = signature.s; + if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) return false; + if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false; // Validate signature - BN.prototype.ushrn = function ushrn(bits) { - return this.clone().iushrn(bits); - }; // Test if n bit is set + var sinv = s.invm(this.n); + var u1 = sinv.mul(msg).umod(this.n); + var u2 = sinv.mul(r).umod(this.n); + var p; + if (!this.curve._maxwellTrick) { + p = this.g.mulAdd(u1, key.getPublic(), u2); + if (p.isInfinity()) return false; + return p.getX().umod(this.n).cmp(r) === 0; + } // NOTE: Greg Maxwell's trick, inspired by: + // https://git.io/vad3K - BN.prototype.testn = function testn(bit) { - assert(typeof bit === "number" && bit >= 0); - var r = bit % 26; - var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$y).length <= s) return false; // Check bit and return + p = this.g.jmulAdd(u1, key.getPublic(), u2); + if (p.isInfinity()) return false; // Compare `p.x` of Jacobian point with `r`, + // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the + // inverse of `p.z^2` - var w = (this || _global$y).words[s]; - return !!(w & q); - }; // Return only lowers bits of number (in-place) + return p.eqXToP(r); + }; + + EC.prototype.recoverPubKey = function (msg, signature, j, enc) { + assert((3 & j) === j, "The recovery param is more than two bits"); + signature = new Signature(signature, enc); + var n = this.n; + var e = new BN(msg); + var r = signature.r; + var s = signature.s; // A set LSB signifies that the y-coordinate is odd + var isYOdd = j & 1; + var isSecondKey = j >> 1; + if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) throw new Error("Unable to find sencond key candinate"); // 1.1. Let x = r + jn. - BN.prototype.imaskn = function imaskn(bits) { - assert(typeof bits === "number" && bits >= 0); - var r = bits % 26; - var s = (bits - r) / 26; - assert((this || _global$y).negative === 0, "imaskn works only with positive numbers"); + if (isSecondKey) r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);else r = this.curve.pointFromX(r, isYOdd); + var rInv = signature.r.invm(n); + var s1 = n.sub(e).mul(rInv).umod(n); + var s2 = s.mul(rInv).umod(n); // 1.6.1 Compute Q = r^-1 (sR - eG) + // Q = r^-1 (sR + -eG) - if ((this || _global$y).length <= s) { - return this || _global$y; - } + return this.g.mulAdd(s1, r, s2); + }; - if (r !== 0) { - s++; - } + EC.prototype.getKeyRecoveryParam = function (e, signature, Q, enc) { + signature = new Signature(signature, enc); + if (signature.recoveryParam !== null) return signature.recoveryParam; - (this || _global$y).length = Math.min(s, (this || _global$y).length); + for (var i = 0; i < 4; i++) { + var Qprime; - if (r !== 0) { - var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$y).words[(this || _global$y).length - 1] &= mask; + try { + Qprime = this.recoverPubKey(e, signature, i); + } catch (e) { + continue; } - return this.strip(); - }; // Return only lowers bits of number + if (Qprime.eq(Q)) return i; + } + throw new Error("Unable to find valid recovery factor"); + }; - BN.prototype.maskn = function maskn(bits) { - return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` + return exports$C$1; +} +var exports$B$1 = {}, + _dewExec$B$1 = false; +function dew$B$1() { + if (_dewExec$B$1) return exports$B$1; + _dewExec$B$1 = true; - BN.prototype.iaddn = function iaddn(num) { - assert(typeof num === "number"); - assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + var utils = dew$T$1(); - if ((this || _global$y).negative !== 0) { - if ((this || _global$y).length === 1 && ((this || _global$y).words[0] | 0) < num) { - (this || _global$y).words[0] = num - ((this || _global$y).words[0] | 0); - (this || _global$y).negative = 0; - return this || _global$y; - } + var assert = utils.assert; + var parseBytes = utils.parseBytes; + var cachedProperty = utils.cachedProperty; + /** + * @param {EDDSA} eddsa - instance + * @param {Object} params - public/private key parameters + * + * @param {Array} [params.secret] - secret seed bytes + * @param {Point} [params.pub] - public key point (aka `A` in eddsa terms) + * @param {Array} [params.pub] - public key point encoded as bytes + * + */ - (this || _global$y).negative = 0; - this.isubn(num); - (this || _global$y).negative = 1; - return this || _global$y; - } // Add without checks + function KeyPair(eddsa, params) { + this.eddsa = eddsa; + this._secret = parseBytes(params.secret); + if (eddsa.isPoint(params.pub)) this._pub = params.pub;else this._pubBytes = parseBytes(params.pub); + } + KeyPair.fromPublic = function fromPublic(eddsa, pub) { + if (pub instanceof KeyPair) return pub; + return new KeyPair(eddsa, { + pub: pub + }); + }; - return this._iaddn(num); - }; + KeyPair.fromSecret = function fromSecret(eddsa, secret) { + if (secret instanceof KeyPair) return secret; + return new KeyPair(eddsa, { + secret: secret + }); + }; - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$y).words[0] += num; // Carry + KeyPair.prototype.secret = function secret() { + return this._secret; + }; - for (var i = 0; i < (this || _global$y).length && (this || _global$y).words[i] >= 67108864; i++) { - (this || _global$y).words[i] -= 67108864; + cachedProperty(KeyPair, "pubBytes", function pubBytes() { + return this.eddsa.encodePoint(this.pub()); + }); + cachedProperty(KeyPair, "pub", function pub() { + if (this._pubBytes) return this.eddsa.decodePoint(this._pubBytes); + return this.eddsa.g.mul(this.priv()); + }); + cachedProperty(KeyPair, "privBytes", function privBytes() { + var eddsa = this.eddsa; + var hash = this.hash(); + var lastIx = eddsa.encodingLength - 1; + var a = hash.slice(0, eddsa.encodingLength); + a[0] &= 248; + a[lastIx] &= 127; + a[lastIx] |= 64; + return a; + }); + cachedProperty(KeyPair, "priv", function priv() { + return this.eddsa.decodeInt(this.privBytes()); + }); + cachedProperty(KeyPair, "hash", function hash() { + return this.eddsa.hash().update(this.secret()).digest(); + }); + cachedProperty(KeyPair, "messagePrefix", function messagePrefix() { + return this.hash().slice(this.eddsa.encodingLength); + }); - if (i === (this || _global$y).length - 1) { - (this || _global$y).words[i + 1] = 1; - } else { - (this || _global$y).words[i + 1]++; - } - } + KeyPair.prototype.sign = function sign(message) { + assert(this._secret, "KeyPair can only verify"); + return this.eddsa.sign(message, this); + }; - (this || _global$y).length = Math.max((this || _global$y).length, i + 1); - return this || _global$y; - }; // Subtract plain number `num` from `this` + KeyPair.prototype.verify = function verify(message, sig) { + return this.eddsa.verify(message, sig, this); + }; + KeyPair.prototype.getSecret = function getSecret(enc) { + assert(this._secret, "KeyPair is public only"); + return utils.encode(this.secret(), enc); + }; - BN.prototype.isubn = function isubn(num) { - assert(typeof num === "number"); - assert(num < 67108864); - if (num < 0) return this.iaddn(-num); + KeyPair.prototype.getPublic = function getPublic(enc) { + return utils.encode(this.pubBytes(), enc); + }; - if ((this || _global$y).negative !== 0) { - (this || _global$y).negative = 0; - this.iaddn(num); - (this || _global$y).negative = 1; - return this || _global$y; - } + exports$B$1 = KeyPair; + return exports$B$1; +} - (this || _global$y).words[0] -= num; +var exports$A$1 = {}, + _dewExec$A$1 = false; +function dew$A$1() { + if (_dewExec$A$1) return exports$A$1; + _dewExec$A$1 = true; - if ((this || _global$y).length === 1 && (this || _global$y).words[0] < 0) { - (this || _global$y).words[0] = -(this || _global$y).words[0]; - (this || _global$y).negative = 1; - } else { - // Carry - for (var i = 0; i < (this || _global$y).length && (this || _global$y).words[i] < 0; i++) { - (this || _global$y).words[i] += 67108864; - (this || _global$y).words[i + 1] -= 1; - } - } + var BN = dew$V$1(); - return this.strip(); - }; + var utils = dew$T$1(); - BN.prototype.addn = function addn(num) { - return this.clone().iaddn(num); - }; + var assert = utils.assert; + var cachedProperty = utils.cachedProperty; + var parseBytes = utils.parseBytes; + /** + * @param {EDDSA} eddsa - eddsa instance + * @param {Array|Object} sig - + * @param {Array|Point} [sig.R] - R point as Point or bytes + * @param {Array|bn} [sig.S] - S scalar as bn or bytes + * @param {Array} [sig.Rencoded] - R point encoded + * @param {Array} [sig.Sencoded] - S scalar encoded + */ - BN.prototype.subn = function subn(num) { - return this.clone().isubn(num); - }; + function Signature(eddsa, sig) { + this.eddsa = eddsa; + if (typeof sig !== "object") sig = parseBytes(sig); - BN.prototype.iabs = function iabs() { - (this || _global$y).negative = 0; - return this || _global$y; - }; + if (Array.isArray(sig)) { + sig = { + R: sig.slice(0, eddsa.encodingLength), + S: sig.slice(eddsa.encodingLength) + }; + } - BN.prototype.abs = function abs() { - return this.clone().iabs(); - }; + assert(sig.R && sig.S, "Signature without R or S"); + if (eddsa.isPoint(sig.R)) this._R = sig.R; + if (sig.S instanceof BN) this._S = sig.S; + this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded; + this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded; + } - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { - var len = num.length + shift; - var i; + cachedProperty(Signature, "S", function S() { + return this.eddsa.decodeInt(this.Sencoded()); + }); + cachedProperty(Signature, "R", function R() { + return this.eddsa.decodePoint(this.Rencoded()); + }); + cachedProperty(Signature, "Rencoded", function Rencoded() { + return this.eddsa.encodePoint(this.R()); + }); + cachedProperty(Signature, "Sencoded", function Sencoded() { + return this.eddsa.encodeInt(this.S()); + }); - this._expand(len); + Signature.prototype.toBytes = function toBytes() { + return this.Rencoded().concat(this.Sencoded()); + }; - var w; - var carry = 0; + Signature.prototype.toHex = function toHex() { + return utils.encode(this.toBytes(), "hex").toUpperCase(); + }; - for (i = 0; i < num.length; i++) { - w = ((this || _global$y).words[i + shift] | 0) + carry; - var right = (num.words[i] | 0) * mul; - w -= right & 67108863; - carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$y).words[i + shift] = w & 67108863; - } + exports$A$1 = Signature; + return exports$A$1; +} - for (; i < (this || _global$y).length - shift; i++) { - w = ((this || _global$y).words[i + shift] | 0) + carry; - carry = w >> 26; - (this || _global$y).words[i + shift] = w & 67108863; - } +var exports$z$1 = {}, + _dewExec$z$1 = false; +function dew$z$1() { + if (_dewExec$z$1) return exports$z$1; + _dewExec$z$1 = true; - if (carry === 0) return this.strip(); // Subtraction overflow + var hash = dew$I$1(); - assert(carry === -1); - carry = 0; + var curves = dew$G$1(); - for (i = 0; i < (this || _global$y).length; i++) { - w = -((this || _global$y).words[i] | 0) + carry; - carry = w >> 26; - (this || _global$y).words[i] = w & 67108863; - } + var utils = dew$T$1(); - (this || _global$y).negative = 1; - return this.strip(); - }; + var assert = utils.assert; + var parseBytes = utils.parseBytes; - BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$y).length - num.length; - var a = this.clone(); - var b = num; // Normalize + var KeyPair = dew$B$1(); - var bhi = b.words[b.length - 1] | 0; + var Signature = dew$A$1(); - var bhiBits = this._countBits(bhi); + function EDDSA(curve) { + assert(curve === "ed25519", "only tested with ed25519 so far"); + if (!(this instanceof EDDSA)) return new EDDSA(curve); + curve = curves[curve].curve; + this.curve = curve; + this.g = curve.g; + this.g.precompute(curve.n.bitLength() + 1); + this.pointClass = curve.point().constructor; + this.encodingLength = Math.ceil(curve.n.bitLength() / 8); + this.hash = hash.sha512; + } - shift = 26 - bhiBits; + exports$z$1 = EDDSA; + /** + * @param {Array|String} message - message bytes + * @param {Array|String|KeyPair} secret - secret bytes or a keypair + * @returns {Signature} - signature + */ - if (shift !== 0) { - b = b.ushln(shift); - a.iushln(shift); - bhi = b.words[b.length - 1] | 0; - } // Initialize quotient + EDDSA.prototype.sign = function sign(message, secret) { + message = parseBytes(message); + var key = this.keyFromSecret(secret); + var r = this.hashInt(key.messagePrefix(), message); + var R = this.g.mul(r); + var Rencoded = this.encodePoint(R); + var s_ = this.hashInt(Rencoded, key.pubBytes(), message).mul(key.priv()); + var S = r.add(s_).umod(this.curve.n); + return this.makeSignature({ + R: R, + S: S, + Rencoded: Rencoded + }); + }; + /** + * @param {Array} message - message bytes + * @param {Array|String|Signature} sig - sig bytes + * @param {Array|String|Point|KeyPair} pub - public key + * @returns {Boolean} - true if public key matches sig of message + */ - var m = a.length - b.length; - var q; + EDDSA.prototype.verify = function verify(message, sig, pub) { + message = parseBytes(message); + sig = this.makeSignature(sig); + var key = this.keyFromPublic(pub); + var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message); + var SG = this.g.mul(sig.S()); + var RplusAh = sig.R().add(key.pub().mul(h)); + return RplusAh.eq(SG); + }; - if (mode !== "mod") { - q = new BN(null); - q.length = m + 1; - q.words = new Array(q.length); + EDDSA.prototype.hashInt = function hashInt() { + var hash = this.hash(); - for (var i = 0; i < q.length; i++) { - q.words[i] = 0; - } - } + for (var i = 0; i < arguments.length; i++) hash.update(arguments[i]); - var diff = a.clone()._ishlnsubmul(b, 1, m); + return utils.intFromLE(hash.digest()).umod(this.curve.n); + }; - if (diff.negative === 0) { - a = diff; + EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) { + return KeyPair.fromPublic(this, pub); + }; - if (q) { - q.words[m] = 1; - } - } + EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) { + return KeyPair.fromSecret(this, secret); + }; - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + EDDSA.prototype.makeSignature = function makeSignature(sig) { + if (sig instanceof Signature) return sig; + return new Signature(this, sig); + }; + /** + * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2 + * + * EDDSA defines methods for encoding and decoding points and integers. These are + * helper convenience methods, that pass along to utility functions implied + * parameters. + * + */ - qj = Math.min(qj / bhi | 0, 67108863); - a._ishlnsubmul(b, qj, j); + EDDSA.prototype.encodePoint = function encodePoint(point) { + var enc = point.getY().toArray("le", this.encodingLength); + enc[this.encodingLength - 1] |= point.getX().isOdd() ? 128 : 0; + return enc; + }; - while (a.negative !== 0) { - qj--; - a.negative = 0; + EDDSA.prototype.decodePoint = function decodePoint(bytes) { + bytes = utils.parseBytes(bytes); + var lastIx = bytes.length - 1; + var normed = bytes.slice(0, lastIx).concat(bytes[lastIx] & ~128); + var xIsOdd = (bytes[lastIx] & 128) !== 0; + var y = utils.intFromLE(normed); + return this.curve.pointFromY(y, xIsOdd); + }; - a._ishlnsubmul(b, 1, j); + EDDSA.prototype.encodeInt = function encodeInt(num) { + return num.toArray("le", this.encodingLength); + }; - if (!a.isZero()) { - a.negative ^= 1; - } - } + EDDSA.prototype.decodeInt = function decodeInt(bytes) { + return utils.intFromLE(bytes); + }; - if (q) { - q.words[j] = qj; - } - } + EDDSA.prototype.isPoint = function isPoint(val) { + return val instanceof this.pointClass; + }; - if (q) { - q.strip(); - } + return exports$z$1; +} - a.strip(); // Denormalize +var exports$y$1 = {}, + _dewExec$y$1 = false; +function dew$y$1() { + if (_dewExec$y$1) return exports$y$1; + _dewExec$y$1 = true; + var elliptic = exports$y$1; + elliptic.version = _package$1.version; + elliptic.utils = dew$T$1(); + elliptic.rand = dew$10$1(); + elliptic.curve = dew$O$1(); + elliptic.curves = dew$G$1(); // Protocols - if (mode !== "div" && shift !== 0) { - a.iushrn(shift); - } + elliptic.ec = dew$C$1(); + elliptic.eddsa = dew$z$1(); + return exports$y$1; +} - return { - div: q || null, - mod: a - }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, - // to `div` to request div only, or be absent to - // request both div & mod - // 2) `positive` is true if unsigned mod is requested +var exports$x$1 = {}, + _dewExec$x$1 = false; +var module$2$1 = { + exports: exports$x$1 +}; +var _global$5$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - BN.prototype.divmod = function divmod(num, mode, positive) { - assert(!num.isZero()); +function dew$x$1() { + if (_dewExec$x$1) return module$2$1.exports; + _dewExec$x$1 = true; - if (this.isZero()) { - return { - div: new BN(0), - mod: new BN(0) - }; - } + (function (module, exports) { - var div, mod, res; + function assert(val, msg) { + if (!val) throw new Error(msg || "Assertion failed"); + } // Could use `inherits` module, but don't want to move from single file + // architecture yet. - if ((this || _global$y).negative !== 0 && num.negative === 0) { - res = this.neg().divmod(num, mode); - if (mode !== "mod") { - div = res.div.neg(); - } + function inherits(ctor, superCtor) { + ctor.super_ = superCtor; - if (mode !== "div") { - mod = res.mod.neg(); + var TempCtor = function () {}; - if (positive && mod.negative !== 0) { - mod.iadd(num); - } - } + TempCtor.prototype = superCtor.prototype; + ctor.prototype = new TempCtor(); + ctor.prototype.constructor = ctor; + } // BN - return { - div: div, - mod: mod - }; + + function BN(number, base, endian) { + if (BN.isBN(number)) { + return number; } - if ((this || _global$y).negative === 0 && num.negative !== 0) { - res = this.divmod(num.neg(), mode); + (this || _global$5$1).negative = 0; + (this || _global$5$1).words = null; + (this || _global$5$1).length = 0; // Reduction context - if (mode !== "mod") { - div = res.div.neg(); - } + (this || _global$5$1).red = null; - return { - div: div, - mod: res.mod - }; - } + if (number !== null) { + if (base === "le" || base === "be") { + endian = base; + base = 10; + } - if (((this || _global$y).negative & num.negative) !== 0) { - res = this.neg().divmod(num.neg(), mode); + this._init(number || 0, base || 10, endian || "be"); + } + } - if (mode !== "div") { - mod = res.mod.neg(); + if (typeof module === "object") { + module.exports = BN; + } else { + exports.BN = BN; + } - if (positive && mod.negative !== 0) { - mod.isub(num); - } - } + BN.BN = BN; + BN.wordSize = 26; + var Buffer; - return { - div: res.div, - mod: mod - }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + try { + if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { + Buffer = window.Buffer; + } else { + Buffer = e$1$1$1.Buffer; + } + } catch (e) {} + BN.isBN = function isBN(num) { + if (num instanceof BN) { + return true; + } - if (num.length > (this || _global$y).length || this.cmp(num) < 0) { - return { - div: new BN(0), - mod: this || _global$y - }; - } // Very short reduction + return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); + }; + BN.max = function max(left, right) { + if (left.cmp(right) > 0) return left; + return right; + }; - if (num.length === 1) { - if (mode === "div") { - return { - div: this.divn(num.words[0]), - mod: null - }; - } + BN.min = function min(left, right) { + if (left.cmp(right) < 0) return left; + return right; + }; - if (mode === "mod") { - return { - div: null, - mod: new BN(this.modn(num.words[0])) - }; - } + BN.prototype._init = function init(number, base, endian) { + if (typeof number === "number") { + return this._initNumber(number, base, endian); + } - return { - div: this.divn(num.words[0]), - mod: new BN(this.modn(num.words[0])) - }; + if (typeof number === "object") { + return this._initArray(number, base, endian); } - return this._wordDiv(num, mode); - }; // Find `this` / `num` + if (base === "hex") { + base = 16; + } + assert(base === (base | 0) && base >= 2 && base <= 36); + number = number.toString().replace(/\s+/g, ""); + var start = 0; - BN.prototype.div = function div(num) { - return this.divmod(num, "div", false).div; - }; // Find `this` % `num` + if (number[0] === "-") { + start++; + (this || _global$5$1).negative = 1; + } + if (start < number.length) { + if (base === 16) { + this._parseHex(number, start, endian); + } else { + this._parseBase(number, base, start); - BN.prototype.mod = function mod(num) { - return this.divmod(num, "mod", false).mod; + if (endian === "le") { + this._initArray(this.toArray(), base, endian); + } + } + } }; - BN.prototype.umod = function umod(num) { - return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) - + BN.prototype._initNumber = function _initNumber(number, base, endian) { + if (number < 0) { + (this || _global$5$1).negative = 1; + number = -number; + } - BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + if (number < 67108864) { + (this || _global$5$1).words = [number & 67108863]; + (this || _global$5$1).length = 1; + } else if (number < 4503599627370496) { + (this || _global$5$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$5$1).length = 2; + } else { + assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - if (dm.mod.isZero()) return dm.div; - var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; - var half = num.ushrn(1); - var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + (this || _global$5$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$5$1).length = 3; + } - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + if (endian !== "le") return; // Reverse the bytes - return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + this._initArray(this.toArray(), base, endian); }; - BN.prototype.modn = function modn(num) { - assert(num <= 67108863); - var p = (1 << 26) % num; - var acc = 0; + BN.prototype._initArray = function _initArray(number, base, endian) { + // Perhaps a Uint8Array + assert(typeof number.length === "number"); - for (var i = (this || _global$y).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$y).words[i] | 0)) % num; + if (number.length <= 0) { + (this || _global$5$1).words = [0]; + (this || _global$5$1).length = 1; + return this || _global$5$1; } - return acc; - }; // In-place division by number + (this || _global$5$1).length = Math.ceil(number.length / 3); + (this || _global$5$1).words = new Array((this || _global$5$1).length); + for (var i = 0; i < (this || _global$5$1).length; i++) { + (this || _global$5$1).words[i] = 0; + } - BN.prototype.idivn = function idivn(num) { - assert(num <= 67108863); - var carry = 0; + var j, w; + var off = 0; - for (var i = (this || _global$y).length - 1; i >= 0; i--) { - var w = ((this || _global$y).words[i] | 0) + carry * 67108864; - (this || _global$y).words[i] = w / num | 0; - carry = w % num; + if (endian === "be") { + for (i = number.length - 1, j = 0; i >= 0; i -= 3) { + w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; + (this || _global$5$1).words[j] |= w << off & 67108863; + (this || _global$5$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } + } else if (endian === "le") { + for (i = 0, j = 0; i < number.length; i += 3) { + w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; + (this || _global$5$1).words[j] |= w << off & 67108863; + (this || _global$5$1).words[j + 1] = w >>> 26 - off & 67108863; + off += 24; + + if (off >= 26) { + off -= 26; + j++; + } + } } return this.strip(); }; - BN.prototype.divn = function divn(num) { - return this.clone().idivn(num); - }; - - BN.prototype.egcd = function egcd(p) { - assert(p.negative === 0); - assert(!p.isZero()); - var x = this || _global$y; - var y = p.clone(); + function parseHex4Bits(string, index) { + var c = string.charCodeAt(index); // 'A' - 'F' - if (x.negative !== 0) { - x = x.umod(p); + if (c >= 65 && c <= 70) { + return c - 55; // 'a' - 'f' + } else if (c >= 97 && c <= 102) { + return c - 87; // '0' - '9' } else { - x = x.clone(); - } // A * x + B * y = x + return c - 48 & 15; + } + } + function parseHexByte(string, lowerBound, index) { + var r = parseHex4Bits(string, index); - var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + if (index - 1 >= lowerBound) { + r |= parseHex4Bits(string, index - 1) << 4; + } - var C = new BN(0); - var D = new BN(1); - var g = 0; + return r; + } - while (x.isEven() && y.isEven()) { - x.iushrn(1); - y.iushrn(1); - ++g; - } + BN.prototype._parseHex = function _parseHex(number, start, endian) { + // Create possibly bigger array to ensure that it fits the number + (this || _global$5$1).length = Math.ceil((number.length - start) / 6); + (this || _global$5$1).words = new Array((this || _global$5$1).length); - var yp = y.clone(); - var xp = x.clone(); + for (var i = 0; i < (this || _global$5$1).length; i++) { + (this || _global$5$1).words[i] = 0; + } // 24-bits chunks - while (!x.isZero()) { - for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { - x.iushrn(i); + var off = 0; + var j = 0; + var w; - while (i-- > 0) { - if (A.isOdd() || B.isOdd()) { - A.iadd(yp); - B.isub(xp); - } + if (endian === "be") { + for (i = number.length - 1; i >= start; i -= 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$5$1).words[j] |= w & 67108863; - A.iushrn(1); - B.iushrn(1); + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$5$1).words[j] |= w >>> 26; + } else { + off += 8; } } + } else { + var parseLength = number.length - start; - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - - if (j > 0) { - y.iushrn(j); - - while (j-- > 0) { - if (C.isOdd() || D.isOdd()) { - C.iadd(yp); - D.isub(xp); - } + for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { + w = parseHexByte(number, start, i) << off; + (this || _global$5$1).words[j] |= w & 67108863; - C.iushrn(1); - D.iushrn(1); + if (off >= 18) { + off -= 18; + j += 1; + (this || _global$5$1).words[j] |= w >>> 26; + } else { + off += 8; } } + } - if (x.cmp(y) >= 0) { - x.isub(y); - A.isub(C); - B.isub(D); + this.strip(); + }; + + function parseBase(str, start, end, mul) { + var r = 0; + var len = Math.min(str.length, end); + + for (var i = start; i < len; i++) { + var c = str.charCodeAt(i) - 48; + r *= mul; // 'a' + + if (c >= 49) { + r += c - 49 + 10; // 'A' + } else if (c >= 17) { + r += c - 17 + 10; // '0' - '9' } else { - y.isub(x); - C.isub(A); - D.isub(B); + r += c; } } - return { - a: C, - b: D, - gcd: y.iushln(g) - }; - }; // This is reduced incarnation of the binary EEA - // above, designated to invert members of the - // _prime_ fields F(p) at a maximal speed - + return r; + } - BN.prototype._invmp = function _invmp(p) { - assert(p.negative === 0); - assert(!p.isZero()); - var a = this || _global$y; - var b = p.clone(); + BN.prototype._parseBase = function _parseBase(number, base, start) { + // Initialize as zero + (this || _global$5$1).words = [0]; + (this || _global$5$1).length = 1; // Find length of limb in base - if (a.negative !== 0) { - a = a.umod(p); - } else { - a = a.clone(); + for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { + limbLen++; } - var x1 = new BN(1); - var x2 = new BN(0); - var delta = b.clone(); + limbLen--; + limbPow = limbPow / base | 0; + var total = number.length - start; + var mod = total % limbLen; + var end = Math.min(total, total - mod) + start; + var word = 0; - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { - for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); + for (var i = start; i < end; i += limbLen) { + word = parseBase(number, i, i + limbLen, base); + this.imuln(limbPow); - if (i > 0) { - a.iushrn(i); + if ((this || _global$5$1).words[0] + word < 67108864) { + (this || _global$5$1).words[0] += word; + } else { + this._iaddn(word); + } + } - while (i-- > 0) { - if (x1.isOdd()) { - x1.iadd(delta); - } + if (mod !== 0) { + var pow = 1; + word = parseBase(number, i, number.length, base); - x1.iushrn(1); - } + for (i = 0; i < mod; i++) { + pow *= base; } - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); + this.imuln(pow); - if (j > 0) { - b.iushrn(j); + if ((this || _global$5$1).words[0] + word < 67108864) { + (this || _global$5$1).words[0] += word; + } else { + this._iaddn(word); + } + } - while (j-- > 0) { - if (x2.isOdd()) { - x2.iadd(delta); - } + this.strip(); + }; - x2.iushrn(1); - } - } + BN.prototype.copy = function copy(dest) { + dest.words = new Array((this || _global$5$1).length); - if (a.cmp(b) >= 0) { - a.isub(b); - x1.isub(x2); - } else { - b.isub(a); - x2.isub(x1); - } + for (var i = 0; i < (this || _global$5$1).length; i++) { + dest.words[i] = (this || _global$5$1).words[i]; } - var res; + dest.length = (this || _global$5$1).length; + dest.negative = (this || _global$5$1).negative; + dest.red = (this || _global$5$1).red; + }; - if (a.cmpn(1) === 0) { - res = x1; - } else { - res = x2; + BN.prototype.clone = function clone() { + var r = new BN(null); + this.copy(r); + return r; + }; + + BN.prototype._expand = function _expand(size) { + while ((this || _global$5$1).length < size) { + (this || _global$5$1).words[(this || _global$5$1).length++] = 0; } - if (res.cmpn(0) < 0) { - res.iadd(p); + return this || _global$5$1; + }; // Remove leading `0` from `this` + + + BN.prototype.strip = function strip() { + while ((this || _global$5$1).length > 1 && (this || _global$5$1).words[(this || _global$5$1).length - 1] === 0) { + (this || _global$5$1).length--; } - return res; + return this._normSign(); }; - BN.prototype.gcd = function gcd(num) { - if (this.isZero()) return num.abs(); - if (num.isZero()) return this.abs(); - var a = this.clone(); - var b = num.clone(); - a.negative = 0; - b.negative = 0; // Remove common factor of two + BN.prototype._normSign = function _normSign() { + // -0 = 0 + if ((this || _global$5$1).length === 1 && (this || _global$5$1).words[0] === 0) { + (this || _global$5$1).negative = 0; + } - for (var shift = 0; a.isEven() && b.isEven(); shift++) { - a.iushrn(1); - b.iushrn(1); + return this || _global$5$1; + }; + + BN.prototype.inspect = function inspect() { + return ((this || _global$5$1).red ? ""; + }; + /* + var zeros = []; + var groupSizes = []; + var groupBases = []; + var s = ''; + var i = -1; + while (++i < BN.wordSize) { + zeros[i] = s; + s += '0'; + } + groupSizes[0] = 0; + groupSizes[1] = 0; + groupBases[0] = 0; + groupBases[1] = 0; + var base = 2 - 1; + while (++base < 36 + 1) { + var groupSize = 0; + var groupBase = 1; + while (groupBase < (1 << BN.wordSize) / base) { + groupBase *= base; + groupSize += 1; } + groupSizes[base] = groupSize; + groupBases[base] = groupBase; + } + */ - do { - while (a.isEven()) { - a.iushrn(1); - } - while (b.isEven()) { - b.iushrn(1); - } + var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; + var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; + var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - var r = a.cmp(b); + BN.prototype.toString = function toString(base, padding) { + base = base || 10; + padding = padding | 0 || 1; + var out; - if (r < 0) { - // Swap `a` and `b` to make `a` always bigger than `b` - var t = a; - a = b; - b = t; - } else if (r === 0 || b.cmpn(1) === 0) { - break; + if (base === 16 || base === "hex") { + out = ""; + var off = 0; + var carry = 0; + + for (var i = 0; i < (this || _global$5$1).length; i++) { + var w = (this || _global$5$1).words[i]; + var word = ((w << off | carry) & 16777215).toString(16); + carry = w >>> 24 - off & 16777215; + + if (carry !== 0 || i !== (this || _global$5$1).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } + + off += 2; + + if (off >= 26) { + off -= 26; + i--; + } } - a.isub(b); - } while (true); + if (carry !== 0) { + out = carry.toString(16) + out; + } - return b.iushln(shift); - }; // Invert number in the field F(num) + while (out.length % padding !== 0) { + out = "0" + out; + } + if ((this || _global$5$1).negative !== 0) { + out = "-" + out; + } - BN.prototype.invm = function invm(num) { - return this.egcd(num).a.umod(num); - }; + return out; + } - BN.prototype.isEven = function isEven() { - return ((this || _global$y).words[0] & 1) === 0; - }; + if (base === (base | 0) && base >= 2 && base <= 36) { + // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); + var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - BN.prototype.isOdd = function isOdd() { - return ((this || _global$y).words[0] & 1) === 1; - }; // And first word and num + var groupBase = groupBases[base]; + out = ""; + var c = this.clone(); + c.negative = 0; + while (!c.isZero()) { + var r = c.modn(groupBase).toString(base); + c = c.idivn(groupBase); - BN.prototype.andln = function andln(num) { - return (this || _global$y).words[0] & num; - }; // Increment at the bit position in-line + if (!c.isZero()) { + out = zeros[groupSize - r.length] + r + out; + } else { + out = r + out; + } + } + if (this.isZero()) { + out = "0" + out; + } - BN.prototype.bincn = function bincn(bit) { - assert(typeof bit === "number"); - var r = bit % 26; - var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + while (out.length % padding !== 0) { + out = "0" + out; + } - if ((this || _global$y).length <= s) { - this._expand(s + 1); + if ((this || _global$5$1).negative !== 0) { + out = "-" + out; + } - (this || _global$y).words[s] |= q; - return this || _global$y; - } // Add bit and propagate, if needed + return out; + } + assert(false, "Base should be between 2 and 36"); + }; - var carry = q; + BN.prototype.toNumber = function toNumber() { + var ret = (this || _global$5$1).words[0]; - for (var i = s; carry !== 0 && i < (this || _global$y).length; i++) { - var w = (this || _global$y).words[i] | 0; - w += carry; - carry = w >>> 26; - w &= 67108863; - (this || _global$y).words[i] = w; + if ((this || _global$5$1).length === 2) { + ret += (this || _global$5$1).words[1] * 67108864; + } else if ((this || _global$5$1).length === 3 && (this || _global$5$1).words[2] === 1) { + // NOTE: at this stage it is known that the top bit is set + ret += 4503599627370496 + (this || _global$5$1).words[1] * 67108864; + } else if ((this || _global$5$1).length > 2) { + assert(false, "Number can only safely store up to 53 bits"); } - if (carry !== 0) { - (this || _global$y).words[i] = carry; - (this || _global$y).length++; - } + return (this || _global$5$1).negative !== 0 ? -ret : ret; + }; - return this || _global$y; + BN.prototype.toJSON = function toJSON() { + return this.toString(16); }; - BN.prototype.isZero = function isZero() { - return (this || _global$y).length === 1 && (this || _global$y).words[0] === 0; + BN.prototype.toBuffer = function toBuffer(endian, length) { + assert(typeof Buffer !== "undefined"); + return this.toArrayLike(Buffer, endian, length); }; - BN.prototype.cmpn = function cmpn(num) { - var negative = num < 0; - if ((this || _global$y).negative !== 0 && !negative) return -1; - if ((this || _global$y).negative === 0 && negative) return 1; + BN.prototype.toArray = function toArray(endian, length) { + return this.toArrayLike(Array, endian, length); + }; + + BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { + var byteLength = this.byteLength(); + var reqLength = length || Math.max(1, byteLength); + assert(byteLength <= reqLength, "byte array longer than desired length"); + assert(reqLength > 0, "Requested array length <= 0"); this.strip(); - var res; + var littleEndian = endian === "le"; + var res = new ArrayType(reqLength); + var b, i; + var q = this.clone(); - if ((this || _global$y).length > 1) { - res = 1; + if (!littleEndian) { + // Assume big-endian + for (i = 0; i < reqLength - byteLength; i++) { + res[i] = 0; + } + + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[reqLength - i - 1] = b; + } } else { - if (negative) { - num = -num; + for (i = 0; !q.isZero(); i++) { + b = q.andln(255); + q.iushrn(8); + res[i] = b; } - assert(num <= 67108863, "Number is too big"); - var w = (this || _global$y).words[0] | 0; - res = w === num ? 0 : w < num ? -1 : 1; + for (; i < reqLength; i++) { + res[i] = 0; + } } - if ((this || _global$y).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: - // 1 - if `this` > `num` - // 0 - if `this` == `num` - // -1 - if `this` < `num` - + }; - BN.prototype.cmp = function cmp(num) { - if ((this || _global$y).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$y).negative === 0 && num.negative !== 0) return 1; - var res = this.ucmp(num); - if ((this || _global$y).negative !== 0) return -res | 0; - return res; - }; // Unsigned comparison + if (Math.clz32) { + BN.prototype._countBits = function _countBits(w) { + return 32 - Math.clz32(w); + }; + } else { + BN.prototype._countBits = function _countBits(w) { + var t = w; + var r = 0; + if (t >= 4096) { + r += 13; + t >>>= 13; + } - BN.prototype.ucmp = function ucmp(num) { - // At this point both numbers have the same sign - if ((this || _global$y).length > num.length) return 1; - if ((this || _global$y).length < num.length) return -1; - var res = 0; + if (t >= 64) { + r += 7; + t >>>= 7; + } - for (var i = (this || _global$y).length - 1; i >= 0; i--) { - var a = (this || _global$y).words[i] | 0; - var b = num.words[i] | 0; - if (a === b) continue; + if (t >= 8) { + r += 4; + t >>>= 4; + } - if (a < b) { - res = -1; - } else if (a > b) { - res = 1; + if (t >= 2) { + r += 2; + t >>>= 2; } - break; + return r + t; + }; + } + + BN.prototype._zeroBits = function _zeroBits(w) { + // Short-cut + if (w === 0) return 26; + var t = w; + var r = 0; + + if ((t & 8191) === 0) { + r += 13; + t >>>= 13; } - return res; - }; + if ((t & 127) === 0) { + r += 7; + t >>>= 7; + } - BN.prototype.gtn = function gtn(num) { - return this.cmpn(num) === 1; - }; + if ((t & 15) === 0) { + r += 4; + t >>>= 4; + } - BN.prototype.gt = function gt(num) { - return this.cmp(num) === 1; - }; + if ((t & 3) === 0) { + r += 2; + t >>>= 2; + } - BN.prototype.gten = function gten(num) { - return this.cmpn(num) >= 0; - }; + if ((t & 1) === 0) { + r++; + } - BN.prototype.gte = function gte(num) { - return this.cmp(num) >= 0; - }; + return r; + }; // Return number of used bits in a BN - BN.prototype.ltn = function ltn(num) { - return this.cmpn(num) === -1; - }; - BN.prototype.lt = function lt(num) { - return this.cmp(num) === -1; - }; + BN.prototype.bitLength = function bitLength() { + var w = (this || _global$5$1).words[(this || _global$5$1).length - 1]; - BN.prototype.lten = function lten(num) { - return this.cmpn(num) <= 0; - }; + var hi = this._countBits(w); - BN.prototype.lte = function lte(num) { - return this.cmp(num) <= 0; + return ((this || _global$5$1).length - 1) * 26 + hi; }; - BN.prototype.eqn = function eqn(num) { - return this.cmpn(num) === 0; - }; + function toBitArray(num) { + var w = new Array(num.bitLength()); - BN.prototype.eq = function eq(num) { - return this.cmp(num) === 0; - }; // - // A reduce context, could be using montgomery or something better, depending - // on the `m` itself. - // + for (var bit = 0; bit < w.length; bit++) { + var off = bit / 26 | 0; + var wbit = bit % 26; + w[bit] = (num.words[off] & 1 << wbit) >>> wbit; + } + return w; + } // Number of trailing zero bits - BN.red = function red(num) { - return new Red(num); - }; - BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$y).red, "Already a number in reduction context"); - assert((this || _global$y).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$y)._forceRed(ctx); - }; + BN.prototype.zeroBits = function zeroBits() { + if (this.isZero()) return 0; + var r = 0; - BN.prototype.fromRed = function fromRed() { - assert((this || _global$y).red, "fromRed works only with numbers in reduction context"); - return (this || _global$y).red.convertFrom(this || _global$y); - }; + for (var i = 0; i < (this || _global$5$1).length; i++) { + var b = this._zeroBits((this || _global$5$1).words[i]); - BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$y).red = ctx; - return this || _global$y; - }; + r += b; + if (b !== 26) break; + } - BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$y).red, "Already a number in reduction context"); - return this._forceRed(ctx); + return r; }; - BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$y).red, "redAdd works only with red numbers"); - return (this || _global$y).red.add(this || _global$y, num); + BN.prototype.byteLength = function byteLength() { + return Math.ceil(this.bitLength() / 8); }; - BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$y).red, "redIAdd works only with red numbers"); - return (this || _global$y).red.iadd(this || _global$y, num); - }; + BN.prototype.toTwos = function toTwos(width) { + if ((this || _global$5$1).negative !== 0) { + return this.abs().inotn(width).iaddn(1); + } - BN.prototype.redSub = function redSub(num) { - assert((this || _global$y).red, "redSub works only with red numbers"); - return (this || _global$y).red.sub(this || _global$y, num); + return this.clone(); }; - BN.prototype.redISub = function redISub(num) { - assert((this || _global$y).red, "redISub works only with red numbers"); - return (this || _global$y).red.isub(this || _global$y, num); - }; + BN.prototype.fromTwos = function fromTwos(width) { + if (this.testn(width - 1)) { + return this.notn(width).iaddn(1).ineg(); + } - BN.prototype.redShl = function redShl(num) { - assert((this || _global$y).red, "redShl works only with red numbers"); - return (this || _global$y).red.shl(this || _global$y, num); + return this.clone(); }; - BN.prototype.redMul = function redMul(num) { - assert((this || _global$y).red, "redMul works only with red numbers"); + BN.prototype.isNeg = function isNeg() { + return (this || _global$5$1).negative !== 0; + }; // Return negative clone of `this` - (this || _global$y).red._verify2(this || _global$y, num); - return (this || _global$y).red.mul(this || _global$y, num); + BN.prototype.neg = function neg() { + return this.clone().ineg(); }; - BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$y).red, "redMul works only with red numbers"); + BN.prototype.ineg = function ineg() { + if (!this.isZero()) { + (this || _global$5$1).negative ^= 1; + } - (this || _global$y).red._verify2(this || _global$y, num); + return this || _global$5$1; + }; // Or `num` with `this` in-place - return (this || _global$y).red.imul(this || _global$y, num); + + BN.prototype.iuor = function iuor(num) { + while ((this || _global$5$1).length < num.length) { + (this || _global$5$1).words[(this || _global$5$1).length++] = 0; + } + + for (var i = 0; i < num.length; i++) { + (this || _global$5$1).words[i] = (this || _global$5$1).words[i] | num.words[i]; + } + + return this.strip(); }; - BN.prototype.redSqr = function redSqr() { - assert((this || _global$y).red, "redSqr works only with red numbers"); + BN.prototype.ior = function ior(num) { + assert(((this || _global$5$1).negative | num.negative) === 0); + return this.iuor(num); + }; // Or `num` with `this` - (this || _global$y).red._verify1(this || _global$y); - return (this || _global$y).red.sqr(this || _global$y); + BN.prototype.or = function or(num) { + if ((this || _global$5$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$5$1); }; - BN.prototype.redISqr = function redISqr() { - assert((this || _global$y).red, "redISqr works only with red numbers"); + BN.prototype.uor = function uor(num) { + if ((this || _global$5$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$5$1); + }; // And `num` with `this` in-place - (this || _global$y).red._verify1(this || _global$y); - return (this || _global$y).red.isqr(this || _global$y); - }; // Square root over p + BN.prototype.iuand = function iuand(num) { + // b = min-length(num, this) + var b; + if ((this || _global$5$1).length > num.length) { + b = num; + } else { + b = this || _global$5$1; + } - BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$y).red, "redSqrt works only with red numbers"); + for (var i = 0; i < b.length; i++) { + (this || _global$5$1).words[i] = (this || _global$5$1).words[i] & num.words[i]; + } - (this || _global$y).red._verify1(this || _global$y); + (this || _global$5$1).length = b.length; + return this.strip(); + }; - return (this || _global$y).red.sqrt(this || _global$y); + BN.prototype.iand = function iand(num) { + assert(((this || _global$5$1).negative | num.negative) === 0); + return this.iuand(num); + }; // And `num` with `this` + + + BN.prototype.and = function and(num) { + if ((this || _global$5$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$5$1); }; - BN.prototype.redInvm = function redInvm() { - assert((this || _global$y).red, "redInvm works only with red numbers"); + BN.prototype.uand = function uand(num) { + if ((this || _global$5$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$5$1); + }; // Xor `num` with `this` in-place - (this || _global$y).red._verify1(this || _global$y); - return (this || _global$y).red.invm(this || _global$y); - }; // Return negative clone of `this` % `red modulo` + BN.prototype.iuxor = function iuxor(num) { + // a.length > b.length + var a; + var b; + if ((this || _global$5$1).length > num.length) { + a = this || _global$5$1; + b = num; + } else { + a = num; + b = this || _global$5$1; + } - BN.prototype.redNeg = function redNeg() { - assert((this || _global$y).red, "redNeg works only with red numbers"); + for (var i = 0; i < b.length; i++) { + (this || _global$5$1).words[i] = a.words[i] ^ b.words[i]; + } - (this || _global$y).red._verify1(this || _global$y); + if ((this || _global$5$1) !== a) { + for (; i < a.length; i++) { + (this || _global$5$1).words[i] = a.words[i]; + } + } - return (this || _global$y).red.neg(this || _global$y); + (this || _global$5$1).length = a.length; + return this.strip(); }; - BN.prototype.redPow = function redPow(num) { - assert((this || _global$y).red && !num.red, "redPow(normalNum)"); + BN.prototype.ixor = function ixor(num) { + assert(((this || _global$5$1).negative | num.negative) === 0); + return this.iuxor(num); + }; // Xor `num` with `this` - (this || _global$y).red._verify1(this || _global$y); - return (this || _global$y).red.pow(this || _global$y, num); - }; // Prime numbers with efficient reduction + BN.prototype.xor = function xor(num) { + if ((this || _global$5$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$5$1); + }; + BN.prototype.uxor = function uxor(num) { + if ((this || _global$5$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$5$1); + }; // Not ``this`` with ``width`` bitwidth - var primes = { - k256: null, - p224: null, - p192: null, - p25519: null - }; // Pseudo-Mersenne prime - function MPrime(name, p) { - // P = 2 ^ N - K - (this || _global$y).name = name; - (this || _global$y).p = new BN(p, 16); - (this || _global$y).n = (this || _global$y).p.bitLength(); - (this || _global$y).k = new BN(1).iushln((this || _global$y).n).isub((this || _global$y).p); - (this || _global$y).tmp = this._tmp(); - } + BN.prototype.inotn = function inotn(width) { + assert(typeof width === "number" && width >= 0); + var bytesNeeded = Math.ceil(width / 26) | 0; + var bitsLeft = width % 26; // Extend the buffer with leading zeroes - MPrime.prototype._tmp = function _tmp() { - var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$y).n / 13)); - return tmp; - }; + this._expand(bytesNeeded); - MPrime.prototype.ireduce = function ireduce(num) { - // Assumes that `num` is less than `P^2` - // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) - var r = num; - var rlen; + if (bitsLeft > 0) { + bytesNeeded--; + } // Handle complete words - do { - this.split(r, (this || _global$y).tmp); - r = this.imulK(r); - r = r.iadd((this || _global$y).tmp); - rlen = r.bitLength(); - } while (rlen > (this || _global$y).n); - var cmp = rlen < (this || _global$y).n ? -1 : r.ucmp((this || _global$y).p); + for (var i = 0; i < bytesNeeded; i++) { + (this || _global$5$1).words[i] = ~(this || _global$5$1).words[i] & 67108863; + } // Handle the residue - if (cmp === 0) { - r.words[0] = 0; - r.length = 1; - } else if (cmp > 0) { - r.isub((this || _global$y).p); - } else { - if (r.strip !== undefined) { - // r is BN v4 instance - r.strip(); - } else { - // r is BN v5 instance - r._strip(); - } - } - return r; - }; + if (bitsLeft > 0) { + (this || _global$5$1).words[i] = ~(this || _global$5$1).words[i] & 67108863 >> 26 - bitsLeft; + } // And remove leading zeroes + - MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$y).n, 0, out); + return this.strip(); }; - MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$y).k); - }; + BN.prototype.notn = function notn(width) { + return this.clone().inotn(width); + }; // Set `bit` of `this` - function K256() { - MPrime.call(this || _global$y, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); - } - inherits(K256, MPrime); + BN.prototype.setn = function setn(bit, val) { + assert(typeof bit === "number" && bit >= 0); + var off = bit / 26 | 0; + var wbit = bit % 26; - K256.prototype.split = function split(input, output) { - // 256 = 9 * 26 + 22 - var mask = 4194303; - var outLen = Math.min(input.length, 9); + this._expand(off + 1); - for (var i = 0; i < outLen; i++) { - output.words[i] = input.words[i]; + if (val) { + (this || _global$5$1).words[off] = (this || _global$5$1).words[off] | 1 << wbit; + } else { + (this || _global$5$1).words[off] = (this || _global$5$1).words[off] & ~(1 << wbit); } - output.length = outLen; + return this.strip(); + }; // Add `num` to `this` in-place - if (input.length <= 9) { - input.words[0] = 0; - input.length = 1; - return; - } // Shift by 9 limbs + BN.prototype.iadd = function iadd(num) { + var r; // negative + positive - var prev = input.words[9]; - output.words[output.length++] = prev & mask; + if ((this || _global$5$1).negative !== 0 && num.negative === 0) { + (this || _global$5$1).negative = 0; + r = this.isub(num); + (this || _global$5$1).negative ^= 1; + return this._normSign(); // positive + negative + } else if ((this || _global$5$1).negative === 0 && num.negative !== 0) { + num.negative = 0; + r = this.isub(num); + num.negative = 1; + return r._normSign(); + } // a.length > b.length - for (i = 10; i < input.length; i++) { - var next = input.words[i] | 0; - input.words[i - 10] = (next & mask) << 4 | prev >>> 22; - prev = next; - } - prev >>>= 22; - input.words[i - 10] = prev; + var a, b; - if (prev === 0 && input.length > 10) { - input.length -= 10; + if ((this || _global$5$1).length > num.length) { + a = this || _global$5$1; + b = num; } else { - input.length -= 9; + a = num; + b = this || _global$5$1; } - }; - - K256.prototype.imulK = function imulK(num) { - // K = 0x1000003d1 = [ 0x40, 0x3d1 ] - num.words[num.length] = 0; - num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 - var lo = 0; + var carry = 0; - for (var i = 0; i < num.length; i++) { - var w = num.words[i] | 0; - lo += w * 977; - num.words[i] = lo & 67108863; - lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) + (b.words[i] | 0) + carry; + (this || _global$5$1).words[i] = r & 67108863; + carry = r >>> 26; + } + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + (this || _global$5$1).words[i] = r & 67108863; + carry = r >>> 26; + } - if (num.words[num.length - 1] === 0) { - num.length--; + (this || _global$5$1).length = a.length; - if (num.words[num.length - 1] === 0) { - num.length--; + if (carry !== 0) { + (this || _global$5$1).words[(this || _global$5$1).length] = carry; + (this || _global$5$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$5$1)) { + for (; i < a.length; i++) { + (this || _global$5$1).words[i] = a.words[i]; } } - return num; - }; - - function P224() { - MPrime.call(this || _global$y, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); - } + return this || _global$5$1; + }; // Add `num` to `this` - inherits(P224, MPrime); - function P192() { - MPrime.call(this || _global$y, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); - } + BN.prototype.add = function add(num) { + var res; - inherits(P192, MPrime); + if (num.negative !== 0 && (this || _global$5$1).negative === 0) { + num.negative = 0; + res = this.sub(num); + num.negative ^= 1; + return res; + } else if (num.negative === 0 && (this || _global$5$1).negative !== 0) { + (this || _global$5$1).negative = 0; + res = num.sub(this || _global$5$1); + (this || _global$5$1).negative = 1; + return res; + } - function P25519() { - // 2 ^ 255 - 19 - MPrime.call(this || _global$y, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); - } + if ((this || _global$5$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$5$1); + }; // Subtract `num` from `this` in-place - inherits(P25519, MPrime); - P25519.prototype.imulK = function imulK(num) { - // K = 0x13 - var carry = 0; + BN.prototype.isub = function isub(num) { + // this - (-num) = this + num + if (num.negative !== 0) { + num.negative = 0; + var r = this.iadd(num); + num.negative = 1; + return r._normSign(); // -this - num = -(this + num) + } else if ((this || _global$5$1).negative !== 0) { + (this || _global$5$1).negative = 0; + this.iadd(num); + (this || _global$5$1).negative = 1; + return this._normSign(); + } // At this point both numbers are positive - for (var i = 0; i < num.length; i++) { - var hi = (num.words[i] | 0) * 19 + carry; - var lo = hi & 67108863; - hi >>>= 26; - num.words[i] = lo; - carry = hi; - } - if (carry !== 0) { - num.words[num.length++] = carry; - } + var cmp = this.cmp(num); // Optimization - zeroify - return num; - }; // Exported mostly for testing purposes, use plain name instead + if (cmp === 0) { + (this || _global$5$1).negative = 0; + (this || _global$5$1).length = 1; + (this || _global$5$1).words[0] = 0; + return this || _global$5$1; + } // a > b - BN._prime = function prime(name) { - // Cached version of prime - if (primes[name]) return primes[name]; - var prime; + var a, b; - if (name === "k256") { - prime = new K256(); - } else if (name === "p224") { - prime = new P224(); - } else if (name === "p192") { - prime = new P192(); - } else if (name === "p25519") { - prime = new P25519(); + if (cmp > 0) { + a = this || _global$5$1; + b = num; } else { - throw new Error("Unknown prime " + name); + a = num; + b = this || _global$5$1; } - primes[name] = prime; - return prime; - }; // - // Base reduction engine - // - - - function Red(m) { - if (typeof m === "string") { - var prime = BN._prime(m); + var carry = 0; - (this || _global$y).m = prime.p; - (this || _global$y).prime = prime; - } else { - assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$y).m = m; - (this || _global$y).prime = null; + for (var i = 0; i < b.length; i++) { + r = (a.words[i] | 0) - (b.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$5$1).words[i] = r & 67108863; } - } - Red.prototype._verify1 = function _verify1(a) { - assert(a.negative === 0, "red works only with positives"); - assert(a.red, "red works only with red numbers"); - }; - - Red.prototype._verify2 = function _verify2(a, b) { - assert((a.negative | b.negative) === 0, "red works only with positives"); - assert(a.red && a.red === b.red, "red works only with red numbers"); - }; + for (; carry !== 0 && i < a.length; i++) { + r = (a.words[i] | 0) + carry; + carry = r >> 26; + (this || _global$5$1).words[i] = r & 67108863; + } // Copy rest of the words - Red.prototype.imod = function imod(a) { - if ((this || _global$y).prime) return (this || _global$y).prime.ireduce(a)._forceRed(this || _global$y); - return a.umod((this || _global$y).m)._forceRed(this || _global$y); - }; - Red.prototype.neg = function neg(a) { - if (a.isZero()) { - return a.clone(); + if (carry === 0 && i < a.length && a !== (this || _global$5$1)) { + for (; i < a.length; i++) { + (this || _global$5$1).words[i] = a.words[i]; + } } - return (this || _global$y).m.sub(a)._forceRed(this || _global$y); - }; + (this || _global$5$1).length = Math.max((this || _global$5$1).length, i); - Red.prototype.add = function add(a, b) { - this._verify2(a, b); + if (a !== (this || _global$5$1)) { + (this || _global$5$1).negative = 1; + } - var res = a.add(b); + return this.strip(); + }; // Subtract `num` from `this` - if (res.cmp((this || _global$y).m) >= 0) { - res.isub((this || _global$y).m); - } - return res._forceRed(this || _global$y); + BN.prototype.sub = function sub(num) { + return this.clone().isub(num); }; - Red.prototype.iadd = function iadd(a, b) { - this._verify2(a, b); - - var res = a.iadd(b); + function smallMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + var len = self.length + num.length | 0; + out.length = len; + len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) - if (res.cmp((this || _global$y).m) >= 0) { - res.isub((this || _global$y).m); - } + var a = self.words[0] | 0; + var b = num.words[0] | 0; + var r = a * b; + var lo = r & 67108863; + var carry = r / 67108864 | 0; + out.words[0] = lo; - return res; - }; + for (var k = 1; k < len; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = carry >>> 26; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); - Red.prototype.sub = function sub(a, b) { - this._verify2(a, b); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j | 0; + a = self.words[i] | 0; + b = num.words[j] | 0; + r = a * b + rword; + ncarry += r / 67108864 | 0; + rword = r & 67108863; + } - var res = a.sub(b); + out.words[k] = rword | 0; + carry = ncarry | 0; + } - if (res.cmpn(0) < 0) { - res.iadd((this || _global$y).m); + if (carry !== 0) { + out.words[k] = carry | 0; + } else { + out.length--; } - return res._forceRed(this || _global$y); - }; + return out.strip(); + } // TODO(indutny): it may be reasonable to omit it for users who don't need + // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit + // multiplication (like elliptic secp256k1). - Red.prototype.isub = function isub(a, b) { - this._verify2(a, b); - var res = a.isub(b); + var comb10MulTo = function comb10MulTo(self, num, out) { + var a = self.words; + var b = num.words; + var o = out.words; + var c = 0; + var lo; + var mid; + var hi; + var a0 = a[0] | 0; + var al0 = a0 & 8191; + var ah0 = a0 >>> 13; + var a1 = a[1] | 0; + var al1 = a1 & 8191; + var ah1 = a1 >>> 13; + var a2 = a[2] | 0; + var al2 = a2 & 8191; + var ah2 = a2 >>> 13; + var a3 = a[3] | 0; + var al3 = a3 & 8191; + var ah3 = a3 >>> 13; + var a4 = a[4] | 0; + var al4 = a4 & 8191; + var ah4 = a4 >>> 13; + var a5 = a[5] | 0; + var al5 = a5 & 8191; + var ah5 = a5 >>> 13; + var a6 = a[6] | 0; + var al6 = a6 & 8191; + var ah6 = a6 >>> 13; + var a7 = a[7] | 0; + var al7 = a7 & 8191; + var ah7 = a7 >>> 13; + var a8 = a[8] | 0; + var al8 = a8 & 8191; + var ah8 = a8 >>> 13; + var a9 = a[9] | 0; + var al9 = a9 & 8191; + var ah9 = a9 >>> 13; + var b0 = b[0] | 0; + var bl0 = b0 & 8191; + var bh0 = b0 >>> 13; + var b1 = b[1] | 0; + var bl1 = b1 & 8191; + var bh1 = b1 >>> 13; + var b2 = b[2] | 0; + var bl2 = b2 & 8191; + var bh2 = b2 >>> 13; + var b3 = b[3] | 0; + var bl3 = b3 & 8191; + var bh3 = b3 >>> 13; + var b4 = b[4] | 0; + var bl4 = b4 & 8191; + var bh4 = b4 >>> 13; + var b5 = b[5] | 0; + var bl5 = b5 & 8191; + var bh5 = b5 >>> 13; + var b6 = b[6] | 0; + var bl6 = b6 & 8191; + var bh6 = b6 >>> 13; + var b7 = b[7] | 0; + var bl7 = b7 & 8191; + var bh7 = b7 >>> 13; + var b8 = b[8] | 0; + var bl8 = b8 & 8191; + var bh8 = b8 >>> 13; + var b9 = b[9] | 0; + var bl9 = b9 & 8191; + var bh9 = b9 >>> 13; + out.negative = self.negative ^ num.negative; + out.length = 19; + /* k = 0 */ - if (res.cmpn(0) < 0) { - res.iadd((this || _global$y).m); - } + lo = Math.imul(al0, bl0); + mid = Math.imul(al0, bh0); + mid = mid + Math.imul(ah0, bl0) | 0; + hi = Math.imul(ah0, bh0); + var w0 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; + w0 &= 67108863; + /* k = 1 */ - return res; - }; + lo = Math.imul(al1, bl0); + mid = Math.imul(al1, bh0); + mid = mid + Math.imul(ah1, bl0) | 0; + hi = Math.imul(ah1, bh0); + lo = lo + Math.imul(al0, bl1) | 0; + mid = mid + Math.imul(al0, bh1) | 0; + mid = mid + Math.imul(ah0, bl1) | 0; + hi = hi + Math.imul(ah0, bh1) | 0; + var w1 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; + w1 &= 67108863; + /* k = 2 */ - Red.prototype.shl = function shl(a, num) { - this._verify1(a); + lo = Math.imul(al2, bl0); + mid = Math.imul(al2, bh0); + mid = mid + Math.imul(ah2, bl0) | 0; + hi = Math.imul(ah2, bh0); + lo = lo + Math.imul(al1, bl1) | 0; + mid = mid + Math.imul(al1, bh1) | 0; + mid = mid + Math.imul(ah1, bl1) | 0; + hi = hi + Math.imul(ah1, bh1) | 0; + lo = lo + Math.imul(al0, bl2) | 0; + mid = mid + Math.imul(al0, bh2) | 0; + mid = mid + Math.imul(ah0, bl2) | 0; + hi = hi + Math.imul(ah0, bh2) | 0; + var w2 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; + w2 &= 67108863; + /* k = 3 */ - return this.imod(a.ushln(num)); - }; + lo = Math.imul(al3, bl0); + mid = Math.imul(al3, bh0); + mid = mid + Math.imul(ah3, bl0) | 0; + hi = Math.imul(ah3, bh0); + lo = lo + Math.imul(al2, bl1) | 0; + mid = mid + Math.imul(al2, bh1) | 0; + mid = mid + Math.imul(ah2, bl1) | 0; + hi = hi + Math.imul(ah2, bh1) | 0; + lo = lo + Math.imul(al1, bl2) | 0; + mid = mid + Math.imul(al1, bh2) | 0; + mid = mid + Math.imul(ah1, bl2) | 0; + hi = hi + Math.imul(ah1, bh2) | 0; + lo = lo + Math.imul(al0, bl3) | 0; + mid = mid + Math.imul(al0, bh3) | 0; + mid = mid + Math.imul(ah0, bl3) | 0; + hi = hi + Math.imul(ah0, bh3) | 0; + var w3 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; + w3 &= 67108863; + /* k = 4 */ - Red.prototype.imul = function imul(a, b) { - this._verify2(a, b); + lo = Math.imul(al4, bl0); + mid = Math.imul(al4, bh0); + mid = mid + Math.imul(ah4, bl0) | 0; + hi = Math.imul(ah4, bh0); + lo = lo + Math.imul(al3, bl1) | 0; + mid = mid + Math.imul(al3, bh1) | 0; + mid = mid + Math.imul(ah3, bl1) | 0; + hi = hi + Math.imul(ah3, bh1) | 0; + lo = lo + Math.imul(al2, bl2) | 0; + mid = mid + Math.imul(al2, bh2) | 0; + mid = mid + Math.imul(ah2, bl2) | 0; + hi = hi + Math.imul(ah2, bh2) | 0; + lo = lo + Math.imul(al1, bl3) | 0; + mid = mid + Math.imul(al1, bh3) | 0; + mid = mid + Math.imul(ah1, bl3) | 0; + hi = hi + Math.imul(ah1, bh3) | 0; + lo = lo + Math.imul(al0, bl4) | 0; + mid = mid + Math.imul(al0, bh4) | 0; + mid = mid + Math.imul(ah0, bl4) | 0; + hi = hi + Math.imul(ah0, bh4) | 0; + var w4 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; + w4 &= 67108863; + /* k = 5 */ - return this.imod(a.imul(b)); - }; + lo = Math.imul(al5, bl0); + mid = Math.imul(al5, bh0); + mid = mid + Math.imul(ah5, bl0) | 0; + hi = Math.imul(ah5, bh0); + lo = lo + Math.imul(al4, bl1) | 0; + mid = mid + Math.imul(al4, bh1) | 0; + mid = mid + Math.imul(ah4, bl1) | 0; + hi = hi + Math.imul(ah4, bh1) | 0; + lo = lo + Math.imul(al3, bl2) | 0; + mid = mid + Math.imul(al3, bh2) | 0; + mid = mid + Math.imul(ah3, bl2) | 0; + hi = hi + Math.imul(ah3, bh2) | 0; + lo = lo + Math.imul(al2, bl3) | 0; + mid = mid + Math.imul(al2, bh3) | 0; + mid = mid + Math.imul(ah2, bl3) | 0; + hi = hi + Math.imul(ah2, bh3) | 0; + lo = lo + Math.imul(al1, bl4) | 0; + mid = mid + Math.imul(al1, bh4) | 0; + mid = mid + Math.imul(ah1, bl4) | 0; + hi = hi + Math.imul(ah1, bh4) | 0; + lo = lo + Math.imul(al0, bl5) | 0; + mid = mid + Math.imul(al0, bh5) | 0; + mid = mid + Math.imul(ah0, bl5) | 0; + hi = hi + Math.imul(ah0, bh5) | 0; + var w5 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; + w5 &= 67108863; + /* k = 6 */ + + lo = Math.imul(al6, bl0); + mid = Math.imul(al6, bh0); + mid = mid + Math.imul(ah6, bl0) | 0; + hi = Math.imul(ah6, bh0); + lo = lo + Math.imul(al5, bl1) | 0; + mid = mid + Math.imul(al5, bh1) | 0; + mid = mid + Math.imul(ah5, bl1) | 0; + hi = hi + Math.imul(ah5, bh1) | 0; + lo = lo + Math.imul(al4, bl2) | 0; + mid = mid + Math.imul(al4, bh2) | 0; + mid = mid + Math.imul(ah4, bl2) | 0; + hi = hi + Math.imul(ah4, bh2) | 0; + lo = lo + Math.imul(al3, bl3) | 0; + mid = mid + Math.imul(al3, bh3) | 0; + mid = mid + Math.imul(ah3, bl3) | 0; + hi = hi + Math.imul(ah3, bh3) | 0; + lo = lo + Math.imul(al2, bl4) | 0; + mid = mid + Math.imul(al2, bh4) | 0; + mid = mid + Math.imul(ah2, bl4) | 0; + hi = hi + Math.imul(ah2, bh4) | 0; + lo = lo + Math.imul(al1, bl5) | 0; + mid = mid + Math.imul(al1, bh5) | 0; + mid = mid + Math.imul(ah1, bl5) | 0; + hi = hi + Math.imul(ah1, bh5) | 0; + lo = lo + Math.imul(al0, bl6) | 0; + mid = mid + Math.imul(al0, bh6) | 0; + mid = mid + Math.imul(ah0, bl6) | 0; + hi = hi + Math.imul(ah0, bh6) | 0; + var w6 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; + w6 &= 67108863; + /* k = 7 */ - Red.prototype.mul = function mul(a, b) { - this._verify2(a, b); + lo = Math.imul(al7, bl0); + mid = Math.imul(al7, bh0); + mid = mid + Math.imul(ah7, bl0) | 0; + hi = Math.imul(ah7, bh0); + lo = lo + Math.imul(al6, bl1) | 0; + mid = mid + Math.imul(al6, bh1) | 0; + mid = mid + Math.imul(ah6, bl1) | 0; + hi = hi + Math.imul(ah6, bh1) | 0; + lo = lo + Math.imul(al5, bl2) | 0; + mid = mid + Math.imul(al5, bh2) | 0; + mid = mid + Math.imul(ah5, bl2) | 0; + hi = hi + Math.imul(ah5, bh2) | 0; + lo = lo + Math.imul(al4, bl3) | 0; + mid = mid + Math.imul(al4, bh3) | 0; + mid = mid + Math.imul(ah4, bl3) | 0; + hi = hi + Math.imul(ah4, bh3) | 0; + lo = lo + Math.imul(al3, bl4) | 0; + mid = mid + Math.imul(al3, bh4) | 0; + mid = mid + Math.imul(ah3, bl4) | 0; + hi = hi + Math.imul(ah3, bh4) | 0; + lo = lo + Math.imul(al2, bl5) | 0; + mid = mid + Math.imul(al2, bh5) | 0; + mid = mid + Math.imul(ah2, bl5) | 0; + hi = hi + Math.imul(ah2, bh5) | 0; + lo = lo + Math.imul(al1, bl6) | 0; + mid = mid + Math.imul(al1, bh6) | 0; + mid = mid + Math.imul(ah1, bl6) | 0; + hi = hi + Math.imul(ah1, bh6) | 0; + lo = lo + Math.imul(al0, bl7) | 0; + mid = mid + Math.imul(al0, bh7) | 0; + mid = mid + Math.imul(ah0, bl7) | 0; + hi = hi + Math.imul(ah0, bh7) | 0; + var w7 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; + w7 &= 67108863; + /* k = 8 */ - return this.imod(a.mul(b)); - }; + lo = Math.imul(al8, bl0); + mid = Math.imul(al8, bh0); + mid = mid + Math.imul(ah8, bl0) | 0; + hi = Math.imul(ah8, bh0); + lo = lo + Math.imul(al7, bl1) | 0; + mid = mid + Math.imul(al7, bh1) | 0; + mid = mid + Math.imul(ah7, bl1) | 0; + hi = hi + Math.imul(ah7, bh1) | 0; + lo = lo + Math.imul(al6, bl2) | 0; + mid = mid + Math.imul(al6, bh2) | 0; + mid = mid + Math.imul(ah6, bl2) | 0; + hi = hi + Math.imul(ah6, bh2) | 0; + lo = lo + Math.imul(al5, bl3) | 0; + mid = mid + Math.imul(al5, bh3) | 0; + mid = mid + Math.imul(ah5, bl3) | 0; + hi = hi + Math.imul(ah5, bh3) | 0; + lo = lo + Math.imul(al4, bl4) | 0; + mid = mid + Math.imul(al4, bh4) | 0; + mid = mid + Math.imul(ah4, bl4) | 0; + hi = hi + Math.imul(ah4, bh4) | 0; + lo = lo + Math.imul(al3, bl5) | 0; + mid = mid + Math.imul(al3, bh5) | 0; + mid = mid + Math.imul(ah3, bl5) | 0; + hi = hi + Math.imul(ah3, bh5) | 0; + lo = lo + Math.imul(al2, bl6) | 0; + mid = mid + Math.imul(al2, bh6) | 0; + mid = mid + Math.imul(ah2, bl6) | 0; + hi = hi + Math.imul(ah2, bh6) | 0; + lo = lo + Math.imul(al1, bl7) | 0; + mid = mid + Math.imul(al1, bh7) | 0; + mid = mid + Math.imul(ah1, bl7) | 0; + hi = hi + Math.imul(ah1, bh7) | 0; + lo = lo + Math.imul(al0, bl8) | 0; + mid = mid + Math.imul(al0, bh8) | 0; + mid = mid + Math.imul(ah0, bl8) | 0; + hi = hi + Math.imul(ah0, bh8) | 0; + var w8 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; + w8 &= 67108863; + /* k = 9 */ - Red.prototype.isqr = function isqr(a) { - return this.imul(a, a.clone()); - }; + lo = Math.imul(al9, bl0); + mid = Math.imul(al9, bh0); + mid = mid + Math.imul(ah9, bl0) | 0; + hi = Math.imul(ah9, bh0); + lo = lo + Math.imul(al8, bl1) | 0; + mid = mid + Math.imul(al8, bh1) | 0; + mid = mid + Math.imul(ah8, bl1) | 0; + hi = hi + Math.imul(ah8, bh1) | 0; + lo = lo + Math.imul(al7, bl2) | 0; + mid = mid + Math.imul(al7, bh2) | 0; + mid = mid + Math.imul(ah7, bl2) | 0; + hi = hi + Math.imul(ah7, bh2) | 0; + lo = lo + Math.imul(al6, bl3) | 0; + mid = mid + Math.imul(al6, bh3) | 0; + mid = mid + Math.imul(ah6, bl3) | 0; + hi = hi + Math.imul(ah6, bh3) | 0; + lo = lo + Math.imul(al5, bl4) | 0; + mid = mid + Math.imul(al5, bh4) | 0; + mid = mid + Math.imul(ah5, bl4) | 0; + hi = hi + Math.imul(ah5, bh4) | 0; + lo = lo + Math.imul(al4, bl5) | 0; + mid = mid + Math.imul(al4, bh5) | 0; + mid = mid + Math.imul(ah4, bl5) | 0; + hi = hi + Math.imul(ah4, bh5) | 0; + lo = lo + Math.imul(al3, bl6) | 0; + mid = mid + Math.imul(al3, bh6) | 0; + mid = mid + Math.imul(ah3, bl6) | 0; + hi = hi + Math.imul(ah3, bh6) | 0; + lo = lo + Math.imul(al2, bl7) | 0; + mid = mid + Math.imul(al2, bh7) | 0; + mid = mid + Math.imul(ah2, bl7) | 0; + hi = hi + Math.imul(ah2, bh7) | 0; + lo = lo + Math.imul(al1, bl8) | 0; + mid = mid + Math.imul(al1, bh8) | 0; + mid = mid + Math.imul(ah1, bl8) | 0; + hi = hi + Math.imul(ah1, bh8) | 0; + lo = lo + Math.imul(al0, bl9) | 0; + mid = mid + Math.imul(al0, bh9) | 0; + mid = mid + Math.imul(ah0, bl9) | 0; + hi = hi + Math.imul(ah0, bh9) | 0; + var w9 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; + w9 &= 67108863; + /* k = 10 */ - Red.prototype.sqr = function sqr(a) { - return this.mul(a, a); - }; + lo = Math.imul(al9, bl1); + mid = Math.imul(al9, bh1); + mid = mid + Math.imul(ah9, bl1) | 0; + hi = Math.imul(ah9, bh1); + lo = lo + Math.imul(al8, bl2) | 0; + mid = mid + Math.imul(al8, bh2) | 0; + mid = mid + Math.imul(ah8, bl2) | 0; + hi = hi + Math.imul(ah8, bh2) | 0; + lo = lo + Math.imul(al7, bl3) | 0; + mid = mid + Math.imul(al7, bh3) | 0; + mid = mid + Math.imul(ah7, bl3) | 0; + hi = hi + Math.imul(ah7, bh3) | 0; + lo = lo + Math.imul(al6, bl4) | 0; + mid = mid + Math.imul(al6, bh4) | 0; + mid = mid + Math.imul(ah6, bl4) | 0; + hi = hi + Math.imul(ah6, bh4) | 0; + lo = lo + Math.imul(al5, bl5) | 0; + mid = mid + Math.imul(al5, bh5) | 0; + mid = mid + Math.imul(ah5, bl5) | 0; + hi = hi + Math.imul(ah5, bh5) | 0; + lo = lo + Math.imul(al4, bl6) | 0; + mid = mid + Math.imul(al4, bh6) | 0; + mid = mid + Math.imul(ah4, bl6) | 0; + hi = hi + Math.imul(ah4, bh6) | 0; + lo = lo + Math.imul(al3, bl7) | 0; + mid = mid + Math.imul(al3, bh7) | 0; + mid = mid + Math.imul(ah3, bl7) | 0; + hi = hi + Math.imul(ah3, bh7) | 0; + lo = lo + Math.imul(al2, bl8) | 0; + mid = mid + Math.imul(al2, bh8) | 0; + mid = mid + Math.imul(ah2, bl8) | 0; + hi = hi + Math.imul(ah2, bh8) | 0; + lo = lo + Math.imul(al1, bl9) | 0; + mid = mid + Math.imul(al1, bh9) | 0; + mid = mid + Math.imul(ah1, bl9) | 0; + hi = hi + Math.imul(ah1, bh9) | 0; + var w10 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; + w10 &= 67108863; + /* k = 11 */ - Red.prototype.sqrt = function sqrt(a) { - if (a.isZero()) return a.clone(); + lo = Math.imul(al9, bl2); + mid = Math.imul(al9, bh2); + mid = mid + Math.imul(ah9, bl2) | 0; + hi = Math.imul(ah9, bh2); + lo = lo + Math.imul(al8, bl3) | 0; + mid = mid + Math.imul(al8, bh3) | 0; + mid = mid + Math.imul(ah8, bl3) | 0; + hi = hi + Math.imul(ah8, bh3) | 0; + lo = lo + Math.imul(al7, bl4) | 0; + mid = mid + Math.imul(al7, bh4) | 0; + mid = mid + Math.imul(ah7, bl4) | 0; + hi = hi + Math.imul(ah7, bh4) | 0; + lo = lo + Math.imul(al6, bl5) | 0; + mid = mid + Math.imul(al6, bh5) | 0; + mid = mid + Math.imul(ah6, bl5) | 0; + hi = hi + Math.imul(ah6, bh5) | 0; + lo = lo + Math.imul(al5, bl6) | 0; + mid = mid + Math.imul(al5, bh6) | 0; + mid = mid + Math.imul(ah5, bl6) | 0; + hi = hi + Math.imul(ah5, bh6) | 0; + lo = lo + Math.imul(al4, bl7) | 0; + mid = mid + Math.imul(al4, bh7) | 0; + mid = mid + Math.imul(ah4, bl7) | 0; + hi = hi + Math.imul(ah4, bh7) | 0; + lo = lo + Math.imul(al3, bl8) | 0; + mid = mid + Math.imul(al3, bh8) | 0; + mid = mid + Math.imul(ah3, bl8) | 0; + hi = hi + Math.imul(ah3, bh8) | 0; + lo = lo + Math.imul(al2, bl9) | 0; + mid = mid + Math.imul(al2, bh9) | 0; + mid = mid + Math.imul(ah2, bl9) | 0; + hi = hi + Math.imul(ah2, bh9) | 0; + var w11 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; + w11 &= 67108863; + /* k = 12 */ - var mod3 = (this || _global$y).m.andln(3); + lo = Math.imul(al9, bl3); + mid = Math.imul(al9, bh3); + mid = mid + Math.imul(ah9, bl3) | 0; + hi = Math.imul(ah9, bh3); + lo = lo + Math.imul(al8, bl4) | 0; + mid = mid + Math.imul(al8, bh4) | 0; + mid = mid + Math.imul(ah8, bl4) | 0; + hi = hi + Math.imul(ah8, bh4) | 0; + lo = lo + Math.imul(al7, bl5) | 0; + mid = mid + Math.imul(al7, bh5) | 0; + mid = mid + Math.imul(ah7, bl5) | 0; + hi = hi + Math.imul(ah7, bh5) | 0; + lo = lo + Math.imul(al6, bl6) | 0; + mid = mid + Math.imul(al6, bh6) | 0; + mid = mid + Math.imul(ah6, bl6) | 0; + hi = hi + Math.imul(ah6, bh6) | 0; + lo = lo + Math.imul(al5, bl7) | 0; + mid = mid + Math.imul(al5, bh7) | 0; + mid = mid + Math.imul(ah5, bl7) | 0; + hi = hi + Math.imul(ah5, bh7) | 0; + lo = lo + Math.imul(al4, bl8) | 0; + mid = mid + Math.imul(al4, bh8) | 0; + mid = mid + Math.imul(ah4, bl8) | 0; + hi = hi + Math.imul(ah4, bh8) | 0; + lo = lo + Math.imul(al3, bl9) | 0; + mid = mid + Math.imul(al3, bh9) | 0; + mid = mid + Math.imul(ah3, bl9) | 0; + hi = hi + Math.imul(ah3, bh9) | 0; + var w12 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; + w12 &= 67108863; + /* k = 13 */ - assert(mod3 % 2 === 1); // Fast case + lo = Math.imul(al9, bl4); + mid = Math.imul(al9, bh4); + mid = mid + Math.imul(ah9, bl4) | 0; + hi = Math.imul(ah9, bh4); + lo = lo + Math.imul(al8, bl5) | 0; + mid = mid + Math.imul(al8, bh5) | 0; + mid = mid + Math.imul(ah8, bl5) | 0; + hi = hi + Math.imul(ah8, bh5) | 0; + lo = lo + Math.imul(al7, bl6) | 0; + mid = mid + Math.imul(al7, bh6) | 0; + mid = mid + Math.imul(ah7, bl6) | 0; + hi = hi + Math.imul(ah7, bh6) | 0; + lo = lo + Math.imul(al6, bl7) | 0; + mid = mid + Math.imul(al6, bh7) | 0; + mid = mid + Math.imul(ah6, bl7) | 0; + hi = hi + Math.imul(ah6, bh7) | 0; + lo = lo + Math.imul(al5, bl8) | 0; + mid = mid + Math.imul(al5, bh8) | 0; + mid = mid + Math.imul(ah5, bl8) | 0; + hi = hi + Math.imul(ah5, bh8) | 0; + lo = lo + Math.imul(al4, bl9) | 0; + mid = mid + Math.imul(al4, bh9) | 0; + mid = mid + Math.imul(ah4, bl9) | 0; + hi = hi + Math.imul(ah4, bh9) | 0; + var w13 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; + w13 &= 67108863; + /* k = 14 */ - if (mod3 === 3) { - var pow = (this || _global$y).m.add(new BN(1)).iushrn(2); + lo = Math.imul(al9, bl5); + mid = Math.imul(al9, bh5); + mid = mid + Math.imul(ah9, bl5) | 0; + hi = Math.imul(ah9, bh5); + lo = lo + Math.imul(al8, bl6) | 0; + mid = mid + Math.imul(al8, bh6) | 0; + mid = mid + Math.imul(ah8, bl6) | 0; + hi = hi + Math.imul(ah8, bh6) | 0; + lo = lo + Math.imul(al7, bl7) | 0; + mid = mid + Math.imul(al7, bh7) | 0; + mid = mid + Math.imul(ah7, bl7) | 0; + hi = hi + Math.imul(ah7, bh7) | 0; + lo = lo + Math.imul(al6, bl8) | 0; + mid = mid + Math.imul(al6, bh8) | 0; + mid = mid + Math.imul(ah6, bl8) | 0; + hi = hi + Math.imul(ah6, bh8) | 0; + lo = lo + Math.imul(al5, bl9) | 0; + mid = mid + Math.imul(al5, bh9) | 0; + mid = mid + Math.imul(ah5, bl9) | 0; + hi = hi + Math.imul(ah5, bh9) | 0; + var w14 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; + w14 &= 67108863; + /* k = 15 */ - return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) - // - // Find Q and S, that Q * 2 ^ S = (P - 1) + lo = Math.imul(al9, bl6); + mid = Math.imul(al9, bh6); + mid = mid + Math.imul(ah9, bl6) | 0; + hi = Math.imul(ah9, bh6); + lo = lo + Math.imul(al8, bl7) | 0; + mid = mid + Math.imul(al8, bh7) | 0; + mid = mid + Math.imul(ah8, bl7) | 0; + hi = hi + Math.imul(ah8, bh7) | 0; + lo = lo + Math.imul(al7, bl8) | 0; + mid = mid + Math.imul(al7, bh8) | 0; + mid = mid + Math.imul(ah7, bl8) | 0; + hi = hi + Math.imul(ah7, bh8) | 0; + lo = lo + Math.imul(al6, bl9) | 0; + mid = mid + Math.imul(al6, bh9) | 0; + mid = mid + Math.imul(ah6, bl9) | 0; + hi = hi + Math.imul(ah6, bh9) | 0; + var w15 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; + w15 &= 67108863; + /* k = 16 */ + lo = Math.imul(al9, bl7); + mid = Math.imul(al9, bh7); + mid = mid + Math.imul(ah9, bl7) | 0; + hi = Math.imul(ah9, bh7); + lo = lo + Math.imul(al8, bl8) | 0; + mid = mid + Math.imul(al8, bh8) | 0; + mid = mid + Math.imul(ah8, bl8) | 0; + hi = hi + Math.imul(ah8, bh8) | 0; + lo = lo + Math.imul(al7, bl9) | 0; + mid = mid + Math.imul(al7, bh9) | 0; + mid = mid + Math.imul(ah7, bl9) | 0; + hi = hi + Math.imul(ah7, bh9) | 0; + var w16 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; + w16 &= 67108863; + /* k = 17 */ - var q = (this || _global$y).m.subn(1); + lo = Math.imul(al9, bl8); + mid = Math.imul(al9, bh8); + mid = mid + Math.imul(ah9, bl8) | 0; + hi = Math.imul(ah9, bh8); + lo = lo + Math.imul(al8, bl9) | 0; + mid = mid + Math.imul(al8, bh9) | 0; + mid = mid + Math.imul(ah8, bl9) | 0; + hi = hi + Math.imul(ah8, bh9) | 0; + var w17 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; + w17 &= 67108863; + /* k = 18 */ - var s = 0; + lo = Math.imul(al9, bl9); + mid = Math.imul(al9, bh9); + mid = mid + Math.imul(ah9, bl9) | 0; + hi = Math.imul(ah9, bh9); + var w18 = (c + lo | 0) + ((mid & 8191) << 13) | 0; + c = (hi + (mid >>> 13) | 0) + (w18 >>> 26) | 0; + w18 &= 67108863; + o[0] = w0; + o[1] = w1; + o[2] = w2; + o[3] = w3; + o[4] = w4; + o[5] = w5; + o[6] = w6; + o[7] = w7; + o[8] = w8; + o[9] = w9; + o[10] = w10; + o[11] = w11; + o[12] = w12; + o[13] = w13; + o[14] = w14; + o[15] = w15; + o[16] = w16; + o[17] = w17; + o[18] = w18; - while (!q.isZero() && q.andln(1) === 0) { - s++; - q.iushrn(1); + if (c !== 0) { + o[19] = c; + out.length++; } - assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$y); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. - - var lpow = (this || _global$y).m.subn(1).iushrn(1); - - var z = (this || _global$y).m.bitLength(); + return out; + }; // Polyfill comb - z = new BN(2 * z * z).toRed(this || _global$y); - while (this.pow(z, lpow).cmp(nOne) !== 0) { - z.redIAdd(nOne); - } + if (!Math.imul) { + comb10MulTo = smallMulTo; + } - var c = this.pow(z, q); - var r = this.pow(a, q.addn(1).iushrn(1)); - var t = this.pow(a, q); - var m = s; + function bigMulTo(self, num, out) { + out.negative = num.negative ^ self.negative; + out.length = self.length + num.length; + var carry = 0; + var hncarry = 0; - while (t.cmp(one) !== 0) { - var tmp = t; + for (var k = 0; k < out.length - 1; k++) { + // Sum all words with the same `i + j = k` and accumulate `ncarry`, + // note that ncarry could be >= 0x3ffffff + var ncarry = hncarry; + hncarry = 0; + var rword = carry & 67108863; + var maxJ = Math.min(k, num.length - 1); - for (var i = 0; tmp.cmp(one) !== 0; i++) { - tmp = tmp.redSqr(); + for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { + var i = k - j; + var a = self.words[i] | 0; + var b = num.words[j] | 0; + var r = a * b; + var lo = r & 67108863; + ncarry = ncarry + (r / 67108864 | 0) | 0; + lo = lo + rword | 0; + rword = lo & 67108863; + ncarry = ncarry + (lo >>> 26) | 0; + hncarry += ncarry >>> 26; + ncarry &= 67108863; } - assert(i < m); - var b = this.pow(c, new BN(1).iushln(m - i - 1)); - r = r.redMul(b); - c = b.redSqr(); - t = t.redMul(c); - m = i; + out.words[k] = rword; + carry = ncarry; + ncarry = hncarry; } - return r; - }; - - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$y).m); - - if (inv.negative !== 0) { - inv.negative = 0; - return this.imod(inv).redNeg(); + if (carry !== 0) { + out.words[k] = carry; } else { - return this.imod(inv); + out.length--; } - }; - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$y); - if (num.cmpn(1) === 0) return a.clone(); - var windowSize = 4; - var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$y); - wnd[1] = a; + return out.strip(); + } - for (var i = 2; i < wnd.length; i++) { - wnd[i] = this.mul(wnd[i - 1], a); - } + function jumboMulTo(self, num, out) { + var fftm = new FFTM(); + return fftm.mulp(self, num, out); + } - var res = wnd[0]; - var current = 0; - var currentLen = 0; - var start = num.bitLength() % 26; + BN.prototype.mulTo = function mulTo(num, out) { + var res; + var len = (this || _global$5$1).length + num.length; - if (start === 0) { - start = 26; + if ((this || _global$5$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$5$1, num, out); + } else if (len < 63) { + res = smallMulTo(this || _global$5$1, num, out); + } else if (len < 1024) { + res = bigMulTo(this || _global$5$1, num, out); + } else { + res = jumboMulTo(this || _global$5$1, num, out); } - for (i = num.length - 1; i >= 0; i--) { - var word = num.words[i]; - - for (var j = start - 1; j >= 0; j--) { - var bit = word >> j & 1; + return res; + }; // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion - if (res !== wnd[0]) { - res = this.sqr(res); - } - if (bit === 0 && current === 0) { - currentLen = 0; - continue; - } + function FFTM(x, y) { + (this || _global$5$1).x = x; + (this || _global$5$1).y = y; + } - current <<= 1; - current |= bit; - currentLen++; - if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; - res = this.mul(res, wnd[current]); - currentLen = 0; - current = 0; - } + FFTM.prototype.makeRBT = function makeRBT(N) { + var t = new Array(N); + var l = BN.prototype._countBits(N) - 1; - start = 26; + for (var i = 0; i < N; i++) { + t[i] = this.revBin(i, l, N); } - return res; - }; + return t; + }; // Returns binary-reversed representation of `x` - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$y).m); - return r === num ? r.clone() : r; - }; - Red.prototype.convertFrom = function convertFrom(num) { - var res = num.clone(); - res.red = null; - return res; - }; // - // Montgomery method engine - // + FFTM.prototype.revBin = function revBin(x, l, N) { + if (x === 0 || x === N - 1) return x; + var rb = 0; + for (var i = 0; i < l; i++) { + rb |= (x & 1) << l - i - 1; + x >>= 1; + } - BN.mont = function mont(num) { - return new Mont(num); - }; + return rb; + }; // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm - function Mont(m) { - Red.call(this || _global$y, m); - (this || _global$y).shift = (this || _global$y).m.bitLength(); - if ((this || _global$y).shift % 26 !== 0) { - (this || _global$y).shift += 26 - (this || _global$y).shift % 26; + FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { + for (var i = 0; i < N; i++) { + rtws[i] = rws[rbt[i]]; + itws[i] = iws[rbt[i]]; } + }; - (this || _global$y).r = new BN(1).iushln((this || _global$y).shift); - (this || _global$y).r2 = this.imod((this || _global$y).r.sqr()); - (this || _global$y).rinv = (this || _global$y).r._invmp((this || _global$y).m); - (this || _global$y).minv = (this || _global$y).rinv.mul((this || _global$y).r).isubn(1).div((this || _global$y).m); - (this || _global$y).minv = (this || _global$y).minv.umod((this || _global$y).r); - (this || _global$y).minv = (this || _global$y).r.sub((this || _global$y).minv); - } + FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { + this.permute(rbt, rws, iws, rtws, itws, N); - inherits(Mont, Red); + for (var s = 1; s < N; s <<= 1) { + var l = s << 1; + var rtwdf = Math.cos(2 * Math.PI / l); + var itwdf = Math.sin(2 * Math.PI / l); - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$y).shift)); - }; + for (var p = 0; p < N; p += l) { + var rtwdf_ = rtwdf; + var itwdf_ = itwdf; - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$y).rinv)); - r.red = null; - return r; - }; + for (var j = 0; j < s; j++) { + var re = rtws[p + j]; + var ie = itws[p + j]; + var ro = rtws[p + j + s]; + var io = itws[p + j + s]; + var rx = rtwdf_ * ro - itwdf_ * io; + io = rtwdf_ * io + itwdf_ * ro; + ro = rx; + rtws[p + j] = re + ro; + itws[p + j] = ie + io; + rtws[p + j + s] = re - ro; + itws[p + j + s] = ie - io; + /* jshint maxdepth : false */ - Mont.prototype.imul = function imul(a, b) { - if (a.isZero() || b.isZero()) { - a.words[0] = 0; - a.length = 1; - return a; + if (j !== l) { + rx = rtwdf * rtwdf_ - itwdf * itwdf_; + itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; + rtwdf_ = rx; + } + } + } } + }; - var t = a.imul(b); - var c = t.maskn((this || _global$y).shift).mul((this || _global$y).minv).imaskn((this || _global$y).shift).mul((this || _global$y).m); - var u = t.isub(c).iushrn((this || _global$y).shift); - var res = u; + FFTM.prototype.guessLen13b = function guessLen13b(n, m) { + var N = Math.max(m, n) | 1; + var odd = N & 1; + var i = 0; - if (u.cmp((this || _global$y).m) >= 0) { - res = u.isub((this || _global$y).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$y).m); + for (N = N / 2 | 0; N; N = N >>> 1) { + i++; } - return res._forceRed(this || _global$y); + return 1 << i + 1 + odd; }; - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$y); - var t = a.mul(b); - var c = t.maskn((this || _global$y).shift).mul((this || _global$y).minv).imaskn((this || _global$y).shift).mul((this || _global$y).m); - var u = t.isub(c).iushrn((this || _global$y).shift); - var res = u; + FFTM.prototype.conjugate = function conjugate(rws, iws, N) { + if (N <= 1) return; - if (u.cmp((this || _global$y).m) >= 0) { - res = u.isub((this || _global$y).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$y).m); + for (var i = 0; i < N / 2; i++) { + var t = rws[i]; + rws[i] = rws[N - i - 1]; + rws[N - i - 1] = t; + t = iws[i]; + iws[i] = -iws[N - i - 1]; + iws[N - i - 1] = -t; } - - return res._forceRed(this || _global$y); }; - Mont.prototype.invm = function invm(a) { - // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$y).m).mul((this || _global$y).r2)); - return res._forceRed(this || _global$y); - }; - })(module$9, exports$1X); - - return module$9.exports; -} - -var exports$1W = {}, - _dewExec$1V = false; -function dew$1V() { - if (_dewExec$1V) return exports$1W; - _dewExec$1V = true; - exports$1W = exports$1W = dew$3$2(); - exports$1W.Stream = exports$1W; - exports$1W.Readable = exports$1W; - exports$1W.Writable = dew$8$2(); - exports$1W.Duplex = dew$7$2(); - exports$1W.Transform = dew$2$2(); - exports$1W.PassThrough = dew$1$2(); - exports$1W.finished = dew$6$2(); - exports$1W.pipeline = dew$2B(); - return exports$1W; -} - -var exports$1U = {}, - _dewExec$1T = false; -function dew$1T() { - if (_dewExec$1T) return exports$1U; - _dewExec$1T = true; - - /*! safe-buffer. MIT License. Feross Aboukhadijeh */ - - /* eslint-disable node/no-deprecated-api */ - var buffer = e$1$1$1; - var Buffer = buffer.Buffer; // alternative to using Object.keys for old browsers + FFTM.prototype.normalize13b = function normalize13b(ws, N) { + var carry = 0; - function copyProps(src, dst) { - for (var key in src) { - dst[key] = src[key]; - } - } + for (var i = 0; i < N / 2; i++) { + var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; + ws[i] = w & 67108863; - if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - exports$1U = buffer; - } else { - // Copy properties from require('buffer') - copyProps(buffer, exports$1U); - exports$1U.Buffer = SafeBuffer; - } + if (w < 67108864) { + carry = 0; + } else { + carry = w / 67108864 | 0; + } + } - function SafeBuffer(arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length); - } + return ws; + }; - SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer + FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { + var carry = 0; - copyProps(Buffer, SafeBuffer); + for (var i = 0; i < len; i++) { + carry = carry + (ws[i] | 0); + rws[2 * i] = carry & 8191; + carry = carry >>> 13; + rws[2 * i + 1] = carry & 8191; + carry = carry >>> 13; + } // Pad with zeroes - SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === "number") { - throw new TypeError("Argument must not be a number"); - } - return Buffer(arg, encodingOrOffset, length); - }; + for (i = 2 * len; i < N; ++i) { + rws[i] = 0; + } - SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } + assert(carry === 0); + assert((carry & ~8191) === 0); + }; - var buf = Buffer(size); + FFTM.prototype.stub = function stub(N) { + var ph = new Array(N); - if (fill !== undefined) { - if (typeof encoding === "string") { - buf.fill(fill, encoding); - } else { - buf.fill(fill); + for (var i = 0; i < N; i++) { + ph[i] = 0; } - } else { - buf.fill(0); - } - return buf; - }; + return ph; + }; - SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } + FFTM.prototype.mulp = function mulp(x, y, out) { + var N = 2 * this.guessLen13b(x.length, y.length); + var rbt = this.makeRBT(N); - return Buffer(size); - }; + var _ = this.stub(N); - SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } + var rws = new Array(N); + var rwst = new Array(N); + var iwst = new Array(N); + var nrws = new Array(N); + var nrwst = new Array(N); + var niwst = new Array(N); + var rmws = out.words; + rmws.length = N; + this.convert13b(x.words, x.length, rws, N); + this.convert13b(y.words, y.length, nrws, N); + this.transform(rws, _, rwst, iwst, N, rbt); + this.transform(nrws, _, nrwst, niwst, N, rbt); - return buffer.SlowBuffer(size); - }; + for (var i = 0; i < N; i++) { + var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; + iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; + rwst[i] = rx; + } - return exports$1U; -} + this.conjugate(rwst, iwst, N); + this.transform(rwst, iwst, rmws, _, N, rbt); + this.conjugate(rmws, _, N); + this.normalize13b(rmws, N); + out.negative = x.negative ^ y.negative; + out.length = x.length + y.length; + return out.strip(); + }; // Multiply `this` by `num` -var exports$1T = {}, - _dewExec$1S = false; -var _global$w = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + BN.prototype.mul = function mul(num) { + var out = new BN(null); + out.words = new Array((this || _global$5$1).length + num.length); + return this.mulTo(num, out); + }; // Multiply employing FFT -function dew$1S() { - if (_dewExec$1S) return exports$1T; - _dewExec$1S = true; - var process = T$9; - // limit of Crypto.getRandomValues() - // https://developer.mozilla.org/en-US/docs/Web/API/Crypto/getRandomValues - var MAX_BYTES = 65536; // Node supports requesting up to this number of bytes - // https://github.com/nodejs/node/blob/master/lib/internal/crypto/random.js#L48 - var MAX_UINT32 = 4294967295; + BN.prototype.mulf = function mulf(num) { + var out = new BN(null); + out.words = new Array((this || _global$5$1).length + num.length); + return jumboMulTo(this || _global$5$1, num, out); + }; // In-place Multiplication - function oldBrowser() { - throw new Error("Secure random number generation is not supported by this browser.\nUse Chrome, Firefox or Internet Explorer 11"); - } - var Buffer = dew$1T().Buffer; + BN.prototype.imul = function imul(num) { + return this.clone().mulTo(num, this || _global$5$1); + }; - var crypto = _global$w.crypto || _global$w.msCrypto; + BN.prototype.imuln = function imuln(num) { + assert(typeof num === "number"); + assert(num < 67108864); // Carry - if (crypto && crypto.getRandomValues) { - exports$1T = randomBytes; - } else { - exports$1T = oldBrowser; - } + var carry = 0; - function randomBytes(size, cb) { - // phantomjs needs to throw - if (size > MAX_UINT32) throw new RangeError("requested too many random bytes"); - var bytes = Buffer.allocUnsafe(size); + for (var i = 0; i < (this || _global$5$1).length; i++) { + var w = ((this || _global$5$1).words[i] | 0) * num; + var lo = (w & 67108863) + (carry & 67108863); + carry >>= 26; + carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - if (size > 0) { - // getRandomValues fails on IE if size == 0 - if (size > MAX_BYTES) { - // this is the max bytes crypto.getRandomValues - // can do at once see https://developer.mozilla.org/en-US/docs/Web/API/window.crypto.getRandomValues - for (var generated = 0; generated < size; generated += MAX_BYTES) { - // buffer.slice automatically checks if the end is past the end of - // the buffer so we don't have to here - crypto.getRandomValues(bytes.slice(generated, generated + MAX_BYTES)); - } - } else { - crypto.getRandomValues(bytes); + carry += lo >>> 26; + (this || _global$5$1).words[i] = lo & 67108863; } - } - - if (typeof cb === "function") { - return process.nextTick(function () { - cb(null, bytes); - }); - } - - return bytes; - } - return exports$1T; -} + if (carry !== 0) { + (this || _global$5$1).words[i] = carry; + (this || _global$5$1).length++; + } -var exports$1S = {}, - _dewExec$1R = false; -function dew$1R() { - if (_dewExec$1R) return exports$1S; - _dewExec$1R = true; + return this || _global$5$1; + }; - var Buffer = dew$1T().Buffer; + BN.prototype.muln = function muln(num) { + return this.clone().imuln(num); + }; // `this` * `this` - var Transform = dew$1V().Transform; - var inherits = dew$f$2(); + BN.prototype.sqr = function sqr() { + return this.mul(this || _global$5$1); + }; // `this` * `this` in-place - function throwIfNotStringOrBuffer(val, prefix) { - if (!Buffer.isBuffer(val) && typeof val !== "string") { - throw new TypeError(prefix + " must be a string or a buffer"); - } - } - function HashBase(blockSize) { - Transform.call(this); - this._block = Buffer.allocUnsafe(blockSize); - this._blockSize = blockSize; - this._blockOffset = 0; - this._length = [0, 0, 0, 0]; - this._finalized = false; - } + BN.prototype.isqr = function isqr() { + return this.imul(this.clone()); + }; // Math.pow(`this`, `num`) - inherits(HashBase, Transform); - HashBase.prototype._transform = function (chunk, encoding, callback) { - var error = null; + BN.prototype.pow = function pow(num) { + var w = toBitArray(num); + if (w.length === 0) return new BN(1); // Skip leading zeroes - try { - this.update(chunk, encoding); - } catch (err) { - error = err; - } + var res = this || _global$5$1; - callback(error); - }; + for (var i = 0; i < w.length; i++, res = res.sqr()) { + if (w[i] !== 0) break; + } - HashBase.prototype._flush = function (callback) { - var error = null; + if (++i < w.length) { + for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { + if (w[i] === 0) continue; + res = res.mul(q); + } + } - try { - this.push(this.digest()); - } catch (err) { - error = err; - } + return res; + }; // Shift-left in-place - callback(error); - }; - HashBase.prototype.update = function (data, encoding) { - throwIfNotStringOrBuffer(data, "Data"); - if (this._finalized) throw new Error("Digest already called"); - if (!Buffer.isBuffer(data)) data = Buffer.from(data, encoding); // consume data + BN.prototype.iushln = function iushln(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + var carryMask = 67108863 >>> 26 - r << 26 - r; + var i; - var block = this._block; - var offset = 0; + if (r !== 0) { + var carry = 0; - while (this._blockOffset + data.length - offset >= this._blockSize) { - for (var i = this._blockOffset; i < this._blockSize;) block[i++] = data[offset++]; + for (i = 0; i < (this || _global$5$1).length; i++) { + var newCarry = (this || _global$5$1).words[i] & carryMask; + var c = ((this || _global$5$1).words[i] | 0) - newCarry << r; + (this || _global$5$1).words[i] = c | carry; + carry = newCarry >>> 26 - r; + } - this._update(); + if (carry) { + (this || _global$5$1).words[i] = carry; + (this || _global$5$1).length++; + } + } - this._blockOffset = 0; - } + if (s !== 0) { + for (i = (this || _global$5$1).length - 1; i >= 0; i--) { + (this || _global$5$1).words[i + s] = (this || _global$5$1).words[i]; + } - while (offset < data.length) block[this._blockOffset++] = data[offset++]; // update length + for (i = 0; i < s; i++) { + (this || _global$5$1).words[i] = 0; + } + (this || _global$5$1).length += s; + } - for (var j = 0, carry = data.length * 8; carry > 0; ++j) { - this._length[j] += carry; - carry = this._length[j] / 4294967296 | 0; - if (carry > 0) this._length[j] -= 4294967296 * carry; - } + return this.strip(); + }; - return this; - }; + BN.prototype.ishln = function ishln(bits) { + // TODO(indutny): implement me + assert((this || _global$5$1).negative === 0); + return this.iushln(bits); + }; // Shift-right in-place + // NOTE: `hint` is a lowest bit before trailing zeroes + // NOTE: if `extended` is present - it will be filled with destroyed bits - HashBase.prototype._update = function () { - throw new Error("_update is not implemented"); - }; - HashBase.prototype.digest = function (encoding) { - if (this._finalized) throw new Error("Digest already called"); - this._finalized = true; + BN.prototype.iushrn = function iushrn(bits, hint, extended) { + assert(typeof bits === "number" && bits >= 0); + var h; - var digest = this._digest(); + if (hint) { + h = (hint - hint % 26) / 26; + } else { + h = 0; + } - if (encoding !== undefined) digest = digest.toString(encoding); // reset state + var r = bits % 26; + var s = Math.min((bits - r) / 26, (this || _global$5$1).length); + var mask = 67108863 ^ 67108863 >>> r << r; + var maskedWords = extended; + h -= s; + h = Math.max(0, h); // Extended mode, copy masked part - this._block.fill(0); + if (maskedWords) { + for (var i = 0; i < s; i++) { + maskedWords.words[i] = (this || _global$5$1).words[i]; + } - this._blockOffset = 0; + maskedWords.length = s; + } - for (var i = 0; i < 4; ++i) this._length[i] = 0; + if (s === 0) ; else if ((this || _global$5$1).length > s) { + (this || _global$5$1).length -= s; - return digest; - }; + for (i = 0; i < (this || _global$5$1).length; i++) { + (this || _global$5$1).words[i] = (this || _global$5$1).words[i + s]; + } + } else { + (this || _global$5$1).words[0] = 0; + (this || _global$5$1).length = 1; + } - HashBase.prototype._digest = function () { - throw new Error("_digest is not implemented"); - }; + var carry = 0; - exports$1S = HashBase; - return exports$1S; -} + for (i = (this || _global$5$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$5$1).words[i] | 0; + (this || _global$5$1).words[i] = carry << 26 - r | word >>> r; + carry = word & mask; + } // Push carried bits as a mask -var exports$1R = {}, - _dewExec$1Q = false; -function dew$1Q() { - if (_dewExec$1Q) return exports$1R; - _dewExec$1Q = true; - var inherits = dew$f$2(); + if (maskedWords && carry !== 0) { + maskedWords.words[maskedWords.length++] = carry; + } - var HashBase = dew$1R(); + if ((this || _global$5$1).length === 0) { + (this || _global$5$1).words[0] = 0; + (this || _global$5$1).length = 1; + } - var Buffer = dew$1T().Buffer; + return this.strip(); + }; - var ARRAY16 = new Array(16); + BN.prototype.ishrn = function ishrn(bits, hint, extended) { + // TODO(indutny): implement me + assert((this || _global$5$1).negative === 0); + return this.iushrn(bits, hint, extended); + }; // Shift-left - function MD5() { - HashBase.call(this, 64); // state - this._a = 1732584193; - this._b = 4023233417; - this._c = 2562383102; - this._d = 271733878; - } + BN.prototype.shln = function shln(bits) { + return this.clone().ishln(bits); + }; - inherits(MD5, HashBase); + BN.prototype.ushln = function ushln(bits) { + return this.clone().iushln(bits); + }; // Shift-right - MD5.prototype._update = function () { - var M = ARRAY16; - for (var i = 0; i < 16; ++i) M[i] = this._block.readInt32LE(i * 4); + BN.prototype.shrn = function shrn(bits) { + return this.clone().ishrn(bits); + }; - var a = this._a; - var b = this._b; - var c = this._c; - var d = this._d; - a = fnF(a, b, c, d, M[0], 3614090360, 7); - d = fnF(d, a, b, c, M[1], 3905402710, 12); - c = fnF(c, d, a, b, M[2], 606105819, 17); - b = fnF(b, c, d, a, M[3], 3250441966, 22); - a = fnF(a, b, c, d, M[4], 4118548399, 7); - d = fnF(d, a, b, c, M[5], 1200080426, 12); - c = fnF(c, d, a, b, M[6], 2821735955, 17); - b = fnF(b, c, d, a, M[7], 4249261313, 22); - a = fnF(a, b, c, d, M[8], 1770035416, 7); - d = fnF(d, a, b, c, M[9], 2336552879, 12); - c = fnF(c, d, a, b, M[10], 4294925233, 17); - b = fnF(b, c, d, a, M[11], 2304563134, 22); - a = fnF(a, b, c, d, M[12], 1804603682, 7); - d = fnF(d, a, b, c, M[13], 4254626195, 12); - c = fnF(c, d, a, b, M[14], 2792965006, 17); - b = fnF(b, c, d, a, M[15], 1236535329, 22); - a = fnG(a, b, c, d, M[1], 4129170786, 5); - d = fnG(d, a, b, c, M[6], 3225465664, 9); - c = fnG(c, d, a, b, M[11], 643717713, 14); - b = fnG(b, c, d, a, M[0], 3921069994, 20); - a = fnG(a, b, c, d, M[5], 3593408605, 5); - d = fnG(d, a, b, c, M[10], 38016083, 9); - c = fnG(c, d, a, b, M[15], 3634488961, 14); - b = fnG(b, c, d, a, M[4], 3889429448, 20); - a = fnG(a, b, c, d, M[9], 568446438, 5); - d = fnG(d, a, b, c, M[14], 3275163606, 9); - c = fnG(c, d, a, b, M[3], 4107603335, 14); - b = fnG(b, c, d, a, M[8], 1163531501, 20); - a = fnG(a, b, c, d, M[13], 2850285829, 5); - d = fnG(d, a, b, c, M[2], 4243563512, 9); - c = fnG(c, d, a, b, M[7], 1735328473, 14); - b = fnG(b, c, d, a, M[12], 2368359562, 20); - a = fnH(a, b, c, d, M[5], 4294588738, 4); - d = fnH(d, a, b, c, M[8], 2272392833, 11); - c = fnH(c, d, a, b, M[11], 1839030562, 16); - b = fnH(b, c, d, a, M[14], 4259657740, 23); - a = fnH(a, b, c, d, M[1], 2763975236, 4); - d = fnH(d, a, b, c, M[4], 1272893353, 11); - c = fnH(c, d, a, b, M[7], 4139469664, 16); - b = fnH(b, c, d, a, M[10], 3200236656, 23); - a = fnH(a, b, c, d, M[13], 681279174, 4); - d = fnH(d, a, b, c, M[0], 3936430074, 11); - c = fnH(c, d, a, b, M[3], 3572445317, 16); - b = fnH(b, c, d, a, M[6], 76029189, 23); - a = fnH(a, b, c, d, M[9], 3654602809, 4); - d = fnH(d, a, b, c, M[12], 3873151461, 11); - c = fnH(c, d, a, b, M[15], 530742520, 16); - b = fnH(b, c, d, a, M[2], 3299628645, 23); - a = fnI(a, b, c, d, M[0], 4096336452, 6); - d = fnI(d, a, b, c, M[7], 1126891415, 10); - c = fnI(c, d, a, b, M[14], 2878612391, 15); - b = fnI(b, c, d, a, M[5], 4237533241, 21); - a = fnI(a, b, c, d, M[12], 1700485571, 6); - d = fnI(d, a, b, c, M[3], 2399980690, 10); - c = fnI(c, d, a, b, M[10], 4293915773, 15); - b = fnI(b, c, d, a, M[1], 2240044497, 21); - a = fnI(a, b, c, d, M[8], 1873313359, 6); - d = fnI(d, a, b, c, M[15], 4264355552, 10); - c = fnI(c, d, a, b, M[6], 2734768916, 15); - b = fnI(b, c, d, a, M[13], 1309151649, 21); - a = fnI(a, b, c, d, M[4], 4149444226, 6); - d = fnI(d, a, b, c, M[11], 3174756917, 10); - c = fnI(c, d, a, b, M[2], 718787259, 15); - b = fnI(b, c, d, a, M[9], 3951481745, 21); - this._a = this._a + a | 0; - this._b = this._b + b | 0; - this._c = this._c + c | 0; - this._d = this._d + d | 0; - }; + BN.prototype.ushrn = function ushrn(bits) { + return this.clone().iushrn(bits); + }; // Test if n bit is set - MD5.prototype._digest = function () { - // create padding and handle blocks - this._block[this._blockOffset++] = 128; - if (this._blockOffset > 56) { - this._block.fill(0, this._blockOffset, 64); + BN.prototype.testn = function testn(bit) { + assert(typeof bit === "number" && bit >= 0); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words - this._update(); + if ((this || _global$5$1).length <= s) return false; // Check bit and return - this._blockOffset = 0; - } + var w = (this || _global$5$1).words[s]; + return !!(w & q); + }; // Return only lowers bits of number (in-place) - this._block.fill(0, this._blockOffset, 56); - this._block.writeUInt32LE(this._length[0], 56); + BN.prototype.imaskn = function imaskn(bits) { + assert(typeof bits === "number" && bits >= 0); + var r = bits % 26; + var s = (bits - r) / 26; + assert((this || _global$5$1).negative === 0, "imaskn works only with positive numbers"); - this._block.writeUInt32LE(this._length[1], 60); + if ((this || _global$5$1).length <= s) { + return this || _global$5$1; + } - this._update(); // produce result + if (r !== 0) { + s++; + } + (this || _global$5$1).length = Math.min(s, (this || _global$5$1).length); - var buffer = Buffer.allocUnsafe(16); - buffer.writeInt32LE(this._a, 0); - buffer.writeInt32LE(this._b, 4); - buffer.writeInt32LE(this._c, 8); - buffer.writeInt32LE(this._d, 12); - return buffer; - }; + if (r !== 0) { + var mask = 67108863 ^ 67108863 >>> r << r; + (this || _global$5$1).words[(this || _global$5$1).length - 1] &= mask; + } - function rotl(x, n) { - return x << n | x >>> 32 - n; - } + return this.strip(); + }; // Return only lowers bits of number - function fnF(a, b, c, d, m, k, s) { - return rotl(a + (b & c | ~b & d) + m + k | 0, s) + b | 0; - } - function fnG(a, b, c, d, m, k, s) { - return rotl(a + (b & d | c & ~d) + m + k | 0, s) + b | 0; - } + BN.prototype.maskn = function maskn(bits) { + return this.clone().imaskn(bits); + }; // Add plain number `num` to `this` - function fnH(a, b, c, d, m, k, s) { - return rotl(a + (b ^ c ^ d) + m + k | 0, s) + b | 0; - } - function fnI(a, b, c, d, m, k, s) { - return rotl(a + (c ^ (b | ~d)) + m + k | 0, s) + b | 0; - } + BN.prototype.iaddn = function iaddn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.isubn(-num); // Possible sign change - exports$1R = MD5; - return exports$1R; -} + if ((this || _global$5$1).negative !== 0) { + if ((this || _global$5$1).length === 1 && ((this || _global$5$1).words[0] | 0) < num) { + (this || _global$5$1).words[0] = num - ((this || _global$5$1).words[0] | 0); + (this || _global$5$1).negative = 0; + return this || _global$5$1; + } -var exports$1Q = {}, - _dewExec$1P = false; -function dew$1P() { - if (_dewExec$1P) return exports$1Q; - _dewExec$1P = true; - var Buffer = e$1$1$1.Buffer; + (this || _global$5$1).negative = 0; + this.isubn(num); + (this || _global$5$1).negative = 1; + return this || _global$5$1; + } // Add without checks - var inherits = dew$f$2(); - var HashBase = dew$1R(); + return this._iaddn(num); + }; - var ARRAY16 = new Array(16); - var zl = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]; - var zr = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; - var sl = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]; - var sr = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; - var hl = [0, 1518500249, 1859775393, 2400959708, 2840853838]; - var hr = [1352829926, 1548603684, 1836072691, 2053994217, 0]; + BN.prototype._iaddn = function _iaddn(num) { + (this || _global$5$1).words[0] += num; // Carry - function RIPEMD160() { - HashBase.call(this, 64); // state + for (var i = 0; i < (this || _global$5$1).length && (this || _global$5$1).words[i] >= 67108864; i++) { + (this || _global$5$1).words[i] -= 67108864; - this._a = 1732584193; - this._b = 4023233417; - this._c = 2562383102; - this._d = 271733878; - this._e = 3285377520; - } + if (i === (this || _global$5$1).length - 1) { + (this || _global$5$1).words[i + 1] = 1; + } else { + (this || _global$5$1).words[i + 1]++; + } + } - inherits(RIPEMD160, HashBase); + (this || _global$5$1).length = Math.max((this || _global$5$1).length, i + 1); + return this || _global$5$1; + }; // Subtract plain number `num` from `this` - RIPEMD160.prototype._update = function () { - var words = ARRAY16; - for (var j = 0; j < 16; ++j) words[j] = this._block.readInt32LE(j * 4); + BN.prototype.isubn = function isubn(num) { + assert(typeof num === "number"); + assert(num < 67108864); + if (num < 0) return this.iaddn(-num); - var al = this._a | 0; - var bl = this._b | 0; - var cl = this._c | 0; - var dl = this._d | 0; - var el = this._e | 0; - var ar = this._a | 0; - var br = this._b | 0; - var cr = this._c | 0; - var dr = this._d | 0; - var er = this._e | 0; // computation + if ((this || _global$5$1).negative !== 0) { + (this || _global$5$1).negative = 0; + this.iaddn(num); + (this || _global$5$1).negative = 1; + return this || _global$5$1; + } - for (var i = 0; i < 80; i += 1) { - var tl; - var tr; + (this || _global$5$1).words[0] -= num; - if (i < 16) { - tl = fn1(al, bl, cl, dl, el, words[zl[i]], hl[0], sl[i]); - tr = fn5(ar, br, cr, dr, er, words[zr[i]], hr[0], sr[i]); - } else if (i < 32) { - tl = fn2(al, bl, cl, dl, el, words[zl[i]], hl[1], sl[i]); - tr = fn4(ar, br, cr, dr, er, words[zr[i]], hr[1], sr[i]); - } else if (i < 48) { - tl = fn3(al, bl, cl, dl, el, words[zl[i]], hl[2], sl[i]); - tr = fn3(ar, br, cr, dr, er, words[zr[i]], hr[2], sr[i]); - } else if (i < 64) { - tl = fn4(al, bl, cl, dl, el, words[zl[i]], hl[3], sl[i]); - tr = fn2(ar, br, cr, dr, er, words[zr[i]], hr[3], sr[i]); + if ((this || _global$5$1).length === 1 && (this || _global$5$1).words[0] < 0) { + (this || _global$5$1).words[0] = -(this || _global$5$1).words[0]; + (this || _global$5$1).negative = 1; } else { - // if (i<80) { - tl = fn5(al, bl, cl, dl, el, words[zl[i]], hl[4], sl[i]); - tr = fn1(ar, br, cr, dr, er, words[zr[i]], hr[4], sr[i]); + // Carry + for (var i = 0; i < (this || _global$5$1).length && (this || _global$5$1).words[i] < 0; i++) { + (this || _global$5$1).words[i] += 67108864; + (this || _global$5$1).words[i + 1] -= 1; + } } - al = el; - el = dl; - dl = rotl(cl, 10); - cl = bl; - bl = tl; - ar = er; - er = dr; - dr = rotl(cr, 10); - cr = br; - br = tr; - } // update state + return this.strip(); + }; + BN.prototype.addn = function addn(num) { + return this.clone().iaddn(num); + }; - var t = this._b + cl + dr | 0; - this._b = this._c + dl + er | 0; - this._c = this._d + el + ar | 0; - this._d = this._e + al + br | 0; - this._e = this._a + bl + cr | 0; - this._a = t; - }; + BN.prototype.subn = function subn(num) { + return this.clone().isubn(num); + }; - RIPEMD160.prototype._digest = function () { - // create padding and handle blocks - this._block[this._blockOffset++] = 128; + BN.prototype.iabs = function iabs() { + (this || _global$5$1).negative = 0; + return this || _global$5$1; + }; - if (this._blockOffset > 56) { - this._block.fill(0, this._blockOffset, 64); + BN.prototype.abs = function abs() { + return this.clone().iabs(); + }; - this._update(); + BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { + var len = num.length + shift; + var i; - this._blockOffset = 0; - } + this._expand(len); - this._block.fill(0, this._blockOffset, 56); + var w; + var carry = 0; - this._block.writeUInt32LE(this._length[0], 56); + for (i = 0; i < num.length; i++) { + w = ((this || _global$5$1).words[i + shift] | 0) + carry; + var right = (num.words[i] | 0) * mul; + w -= right & 67108863; + carry = (w >> 26) - (right / 67108864 | 0); + (this || _global$5$1).words[i + shift] = w & 67108863; + } - this._block.writeUInt32LE(this._length[1], 60); + for (; i < (this || _global$5$1).length - shift; i++) { + w = ((this || _global$5$1).words[i + shift] | 0) + carry; + carry = w >> 26; + (this || _global$5$1).words[i + shift] = w & 67108863; + } - this._update(); // produce result + if (carry === 0) return this.strip(); // Subtraction overflow + assert(carry === -1); + carry = 0; - var buffer = Buffer.alloc ? Buffer.alloc(20) : new Buffer(20); - buffer.writeInt32LE(this._a, 0); - buffer.writeInt32LE(this._b, 4); - buffer.writeInt32LE(this._c, 8); - buffer.writeInt32LE(this._d, 12); - buffer.writeInt32LE(this._e, 16); - return buffer; - }; + for (i = 0; i < (this || _global$5$1).length; i++) { + w = -((this || _global$5$1).words[i] | 0) + carry; + carry = w >> 26; + (this || _global$5$1).words[i] = w & 67108863; + } - function rotl(x, n) { - return x << n | x >>> 32 - n; - } + (this || _global$5$1).negative = 1; + return this.strip(); + }; - function fn1(a, b, c, d, e, m, k, s) { - return rotl(a + (b ^ c ^ d) + m + k | 0, s) + e | 0; - } + BN.prototype._wordDiv = function _wordDiv(num, mode) { + var shift = (this || _global$5$1).length - num.length; + var a = this.clone(); + var b = num; // Normalize - function fn2(a, b, c, d, e, m, k, s) { - return rotl(a + (b & c | ~b & d) + m + k | 0, s) + e | 0; - } + var bhi = b.words[b.length - 1] | 0; - function fn3(a, b, c, d, e, m, k, s) { - return rotl(a + ((b | ~c) ^ d) + m + k | 0, s) + e | 0; - } + var bhiBits = this._countBits(bhi); - function fn4(a, b, c, d, e, m, k, s) { - return rotl(a + (b & d | c & ~d) + m + k | 0, s) + e | 0; - } + shift = 26 - bhiBits; - function fn5(a, b, c, d, e, m, k, s) { - return rotl(a + (b ^ (c | ~d)) + m + k | 0, s) + e | 0; - } + if (shift !== 0) { + b = b.ushln(shift); + a.iushln(shift); + bhi = b.words[b.length - 1] | 0; + } // Initialize quotient - exports$1Q = RIPEMD160; - return exports$1Q; -} -var exports$1P = {}, - _dewExec$1O = false; + var m = a.length - b.length; + var q; -var _global$v = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + if (mode !== "mod") { + q = new BN(null); + q.length = m + 1; + q.words = new Array(q.length); -function dew$1O() { - if (_dewExec$1O) return exports$1P; - _dewExec$1O = true; + for (var i = 0; i < q.length; i++) { + q.words[i] = 0; + } + } - var Buffer = dew$1T().Buffer; // prototype class for hash functions + var diff = a.clone()._ishlnsubmul(b, 1, m); + + if (diff.negative === 0) { + a = diff; + if (q) { + q.words[m] = 1; + } + } - function Hash(blockSize, finalSize) { - (this || _global$v)._block = Buffer.alloc(blockSize); - (this || _global$v)._finalSize = finalSize; - (this || _global$v)._blockSize = blockSize; - (this || _global$v)._len = 0; - } + for (var j = m - 1; j >= 0; j--) { + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) - Hash.prototype.update = function (data, enc) { - if (typeof data === "string") { - enc = enc || "utf8"; - data = Buffer.from(data, enc); - } + qj = Math.min(qj / bhi | 0, 67108863); - var block = (this || _global$v)._block; - var blockSize = (this || _global$v)._blockSize; - var length = data.length; - var accum = (this || _global$v)._len; + a._ishlnsubmul(b, qj, j); + + while (a.negative !== 0) { + qj--; + a.negative = 0; + + a._ishlnsubmul(b, 1, j); + + if (!a.isZero()) { + a.negative ^= 1; + } + } - for (var offset = 0; offset < length;) { - var assigned = accum % blockSize; - var remainder = Math.min(length - offset, blockSize - assigned); + if (q) { + q.words[j] = qj; + } + } - for (var i = 0; i < remainder; i++) { - block[assigned + i] = data[offset + i]; + if (q) { + q.strip(); } - accum += remainder; - offset += remainder; + a.strip(); // Denormalize - if (accum % blockSize === 0) { - this._update(block); + if (mode !== "div" && shift !== 0) { + a.iushrn(shift); } - } - (this || _global$v)._len += length; - return this || _global$v; - }; + return { + div: q || null, + mod: a + }; + }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + // to `div` to request div only, or be absent to + // request both div & mod + // 2) `positive` is true if unsigned mod is requested - Hash.prototype.digest = function (enc) { - var rem = (this || _global$v)._len % (this || _global$v)._blockSize; - (this || _global$v)._block[rem] = 128; // zero (rem + 1) trailing bits, where (rem + 1) is the smallest - // non-negative solution to the equation (length + 1 + (rem + 1)) === finalSize mod blockSize - (this || _global$v)._block.fill(0, rem + 1); + BN.prototype.divmod = function divmod(num, mode, positive) { + assert(!num.isZero()); - if (rem >= (this || _global$v)._finalSize) { - this._update((this || _global$v)._block); + if (this.isZero()) { + return { + div: new BN(0), + mod: new BN(0) + }; + } - (this || _global$v)._block.fill(0); - } + var div, mod, res; - var bits = (this || _global$v)._len * 8; // uint32 + if ((this || _global$5$1).negative !== 0 && num.negative === 0) { + res = this.neg().divmod(num, mode); - if (bits <= 4294967295) { - (this || _global$v)._block.writeUInt32BE(bits, (this || _global$v)._blockSize - 4); // uint64 + if (mode !== "mod") { + div = res.div.neg(); + } - } else { - var lowBits = (bits & 4294967295) >>> 0; - var highBits = (bits - lowBits) / 4294967296; + if (mode !== "div") { + mod = res.mod.neg(); - (this || _global$v)._block.writeUInt32BE(highBits, (this || _global$v)._blockSize - 8); + if (positive && mod.negative !== 0) { + mod.iadd(num); + } + } - (this || _global$v)._block.writeUInt32BE(lowBits, (this || _global$v)._blockSize - 4); - } + return { + div: div, + mod: mod + }; + } - this._update((this || _global$v)._block); + if ((this || _global$5$1).negative === 0 && num.negative !== 0) { + res = this.divmod(num.neg(), mode); - var hash = this._hash(); + if (mode !== "mod") { + div = res.div.neg(); + } - return enc ? hash.toString(enc) : hash; - }; + return { + div: div, + mod: res.mod + }; + } - Hash.prototype._update = function () { - throw new Error("_update must be implemented by subclass"); - }; + if (((this || _global$5$1).negative & num.negative) !== 0) { + res = this.neg().divmod(num.neg(), mode); - exports$1P = Hash; - return exports$1P; -} + if (mode !== "div") { + mod = res.mod.neg(); -var exports$1O = {}, - _dewExec$1N = false; + if (positive && mod.negative !== 0) { + mod.isub(num); + } + } -var _global$u = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + return { + div: res.div, + mod: mod + }; + } // Both numbers are positive at this point + // Strip both numbers to approximate shift value -function dew$1N() { - if (_dewExec$1N) return exports$1O; - _dewExec$1N = true; - /* - * A JavaScript implementation of the Secure Hash Algorithm, SHA-0, as defined - * in FIPS PUB 180-1 - * This source code is derived from sha1.js of the same repository. - * The difference between SHA-0 and SHA-1 is just a bitwise rotate left - * operation was added. - */ - var inherits = dew$f$2(); + if (num.length > (this || _global$5$1).length || this.cmp(num) < 0) { + return { + div: new BN(0), + mod: this || _global$5$1 + }; + } // Very short reduction - var Hash = dew$1O(); - var Buffer = dew$1T().Buffer; + if (num.length === 1) { + if (mode === "div") { + return { + div: this.divn(num.words[0]), + mod: null + }; + } - var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; - var W = new Array(80); + if (mode === "mod") { + return { + div: null, + mod: new BN(this.modn(num.words[0])) + }; + } - function Sha() { - this.init(); - (this || _global$u)._w = W; - Hash.call(this || _global$u, 64, 56); - } + return { + div: this.divn(num.words[0]), + mod: new BN(this.modn(num.words[0])) + }; + } - inherits(Sha, Hash); + return this._wordDiv(num, mode); + }; // Find `this` / `num` - Sha.prototype.init = function () { - (this || _global$u)._a = 1732584193; - (this || _global$u)._b = 4023233417; - (this || _global$u)._c = 2562383102; - (this || _global$u)._d = 271733878; - (this || _global$u)._e = 3285377520; - return this || _global$u; - }; - function rotl5(num) { - return num << 5 | num >>> 27; - } + BN.prototype.div = function div(num) { + return this.divmod(num, "div", false).div; + }; // Find `this` % `num` - function rotl30(num) { - return num << 30 | num >>> 2; - } - function ft(s, b, c, d) { - if (s === 0) return b & c | ~b & d; - if (s === 2) return b & c | b & d | c & d; - return b ^ c ^ d; - } + BN.prototype.mod = function mod(num) { + return this.divmod(num, "mod", false).mod; + }; - Sha.prototype._update = function (M) { - var W = (this || _global$u)._w; - var a = (this || _global$u)._a | 0; - var b = (this || _global$u)._b | 0; - var c = (this || _global$u)._c | 0; - var d = (this || _global$u)._d | 0; - var e = (this || _global$u)._e | 0; + BN.prototype.umod = function umod(num) { + return this.divmod(num, "mod", true).mod; + }; // Find Round(`this` / `num`) - for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); - for (; i < 80; ++i) W[i] = W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]; + BN.prototype.divRound = function divRound(num) { + var dm = this.divmod(num); // Fast case - exact division - for (var j = 0; j < 80; ++j) { - var s = ~~(j / 20); - var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; - e = d; - d = c; - c = rotl30(b); - b = a; - a = t; - } + if (dm.mod.isZero()) return dm.div; + var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; + var half = num.ushrn(1); + var r2 = num.andln(1); + var cmp = mod.cmp(half); // Round down - (this || _global$u)._a = a + (this || _global$u)._a | 0; - (this || _global$u)._b = b + (this || _global$u)._b | 0; - (this || _global$u)._c = c + (this || _global$u)._c | 0; - (this || _global$u)._d = d + (this || _global$u)._d | 0; - (this || _global$u)._e = e + (this || _global$u)._e | 0; - }; + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up - Sha.prototype._hash = function () { - var H = Buffer.allocUnsafe(20); - H.writeInt32BE((this || _global$u)._a | 0, 0); - H.writeInt32BE((this || _global$u)._b | 0, 4); - H.writeInt32BE((this || _global$u)._c | 0, 8); - H.writeInt32BE((this || _global$u)._d | 0, 12); - H.writeInt32BE((this || _global$u)._e | 0, 16); - return H; - }; + return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); + }; - exports$1O = Sha; - return exports$1O; -} + BN.prototype.modn = function modn(num) { + assert(num <= 67108863); + var p = (1 << 26) % num; + var acc = 0; -var exports$1N = {}, - _dewExec$1M = false; + for (var i = (this || _global$5$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$5$1).words[i] | 0)) % num; + } -var _global$t = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + return acc; + }; // In-place division by number -function dew$1M() { - if (_dewExec$1M) return exports$1N; - _dewExec$1M = true; - /* - * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined - * in FIPS PUB 180-1 - * Version 2.1a Copyright Paul Johnston 2000 - 2002. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * Distributed under the BSD License - * See http://pajhome.org.uk/crypt/md5 for details. - */ - var inherits = dew$f$2(); + BN.prototype.idivn = function idivn(num) { + assert(num <= 67108863); + var carry = 0; - var Hash = dew$1O(); + for (var i = (this || _global$5$1).length - 1; i >= 0; i--) { + var w = ((this || _global$5$1).words[i] | 0) + carry * 67108864; + (this || _global$5$1).words[i] = w / num | 0; + carry = w % num; + } - var Buffer = dew$1T().Buffer; + return this.strip(); + }; - var K = [1518500249, 1859775393, 2400959708 | 0, 3395469782 | 0]; - var W = new Array(80); + BN.prototype.divn = function divn(num) { + return this.clone().idivn(num); + }; - function Sha1() { - this.init(); - (this || _global$t)._w = W; - Hash.call(this || _global$t, 64, 56); - } + BN.prototype.egcd = function egcd(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var x = this || _global$5$1; + var y = p.clone(); - inherits(Sha1, Hash); + if (x.negative !== 0) { + x = x.umod(p); + } else { + x = x.clone(); + } // A * x + B * y = x - Sha1.prototype.init = function () { - (this || _global$t)._a = 1732584193; - (this || _global$t)._b = 4023233417; - (this || _global$t)._c = 2562383102; - (this || _global$t)._d = 271733878; - (this || _global$t)._e = 3285377520; - return this || _global$t; - }; - function rotl1(num) { - return num << 1 | num >>> 31; - } + var A = new BN(1); + var B = new BN(0); // C * x + D * y = y - function rotl5(num) { - return num << 5 | num >>> 27; - } + var C = new BN(0); + var D = new BN(1); + var g = 0; - function rotl30(num) { - return num << 30 | num >>> 2; - } + while (x.isEven() && y.isEven()) { + x.iushrn(1); + y.iushrn(1); + ++g; + } - function ft(s, b, c, d) { - if (s === 0) return b & c | ~b & d; - if (s === 2) return b & c | b & d | c & d; - return b ^ c ^ d; - } + var yp = y.clone(); + var xp = x.clone(); - Sha1.prototype._update = function (M) { - var W = (this || _global$t)._w; - var a = (this || _global$t)._a | 0; - var b = (this || _global$t)._b | 0; - var c = (this || _global$t)._c | 0; - var d = (this || _global$t)._d | 0; - var e = (this || _global$t)._e | 0; + while (!x.isZero()) { + for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + if (i > 0) { + x.iushrn(i); - for (; i < 80; ++i) W[i] = rotl1(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16]); + while (i-- > 0) { + if (A.isOdd() || B.isOdd()) { + A.iadd(yp); + B.isub(xp); + } - for (var j = 0; j < 80; ++j) { - var s = ~~(j / 20); - var t = rotl5(a) + ft(s, b, c, d) + e + W[j] + K[s] | 0; - e = d; - d = c; - c = rotl30(b); - b = a; - a = t; - } + A.iushrn(1); + B.iushrn(1); + } + } - (this || _global$t)._a = a + (this || _global$t)._a | 0; - (this || _global$t)._b = b + (this || _global$t)._b | 0; - (this || _global$t)._c = c + (this || _global$t)._c | 0; - (this || _global$t)._d = d + (this || _global$t)._d | 0; - (this || _global$t)._e = e + (this || _global$t)._e | 0; - }; + for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - Sha1.prototype._hash = function () { - var H = Buffer.allocUnsafe(20); - H.writeInt32BE((this || _global$t)._a | 0, 0); - H.writeInt32BE((this || _global$t)._b | 0, 4); - H.writeInt32BE((this || _global$t)._c | 0, 8); - H.writeInt32BE((this || _global$t)._d | 0, 12); - H.writeInt32BE((this || _global$t)._e | 0, 16); - return H; - }; + if (j > 0) { + y.iushrn(j); - exports$1N = Sha1; - return exports$1N; -} + while (j-- > 0) { + if (C.isOdd() || D.isOdd()) { + C.iadd(yp); + D.isub(xp); + } -var exports$1M = {}, - _dewExec$1L = false; + C.iushrn(1); + D.iushrn(1); + } + } -var _global$s = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + if (x.cmp(y) >= 0) { + x.isub(y); + A.isub(C); + B.isub(D); + } else { + y.isub(x); + C.isub(A); + D.isub(B); + } + } -function dew$1L() { - if (_dewExec$1L) return exports$1M; - _dewExec$1L = true; + return { + a: C, + b: D, + gcd: y.iushln(g) + }; + }; // This is reduced incarnation of the binary EEA + // above, designated to invert members of the + // _prime_ fields F(p) at a maximal speed - /** - * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined - * in FIPS 180-2 - * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * - */ - var inherits = dew$f$2(); - var Hash = dew$1O(); + BN.prototype._invmp = function _invmp(p) { + assert(p.negative === 0); + assert(!p.isZero()); + var a = this || _global$5$1; + var b = p.clone(); - var Buffer = dew$1T().Buffer; + if (a.negative !== 0) { + a = a.umod(p); + } else { + a = a.clone(); + } - var K = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298]; - var W = new Array(64); + var x1 = new BN(1); + var x2 = new BN(0); + var delta = b.clone(); - function Sha256() { - this.init(); - (this || _global$s)._w = W; // new Array(64) + while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { + for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - Hash.call(this || _global$s, 64, 56); - } + if (i > 0) { + a.iushrn(i); - inherits(Sha256, Hash); + while (i-- > 0) { + if (x1.isOdd()) { + x1.iadd(delta); + } - Sha256.prototype.init = function () { - (this || _global$s)._a = 1779033703; - (this || _global$s)._b = 3144134277; - (this || _global$s)._c = 1013904242; - (this || _global$s)._d = 2773480762; - (this || _global$s)._e = 1359893119; - (this || _global$s)._f = 2600822924; - (this || _global$s)._g = 528734635; - (this || _global$s)._h = 1541459225; - return this || _global$s; - }; + x1.iushrn(1); + } + } - function ch(x, y, z) { - return z ^ x & (y ^ z); - } + for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - function maj(x, y, z) { - return x & y | z & (x | y); - } + if (j > 0) { + b.iushrn(j); - function sigma0(x) { - return (x >>> 2 | x << 30) ^ (x >>> 13 | x << 19) ^ (x >>> 22 | x << 10); - } + while (j-- > 0) { + if (x2.isOdd()) { + x2.iadd(delta); + } - function sigma1(x) { - return (x >>> 6 | x << 26) ^ (x >>> 11 | x << 21) ^ (x >>> 25 | x << 7); - } + x2.iushrn(1); + } + } - function gamma0(x) { - return (x >>> 7 | x << 25) ^ (x >>> 18 | x << 14) ^ x >>> 3; - } + if (a.cmp(b) >= 0) { + a.isub(b); + x1.isub(x2); + } else { + b.isub(a); + x2.isub(x1); + } + } - function gamma1(x) { - return (x >>> 17 | x << 15) ^ (x >>> 19 | x << 13) ^ x >>> 10; - } + var res; - Sha256.prototype._update = function (M) { - var W = (this || _global$s)._w; - var a = (this || _global$s)._a | 0; - var b = (this || _global$s)._b | 0; - var c = (this || _global$s)._c | 0; - var d = (this || _global$s)._d | 0; - var e = (this || _global$s)._e | 0; - var f = (this || _global$s)._f | 0; - var g = (this || _global$s)._g | 0; - var h = (this || _global$s)._h | 0; + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } - for (var i = 0; i < 16; ++i) W[i] = M.readInt32BE(i * 4); + if (res.cmpn(0) < 0) { + res.iadd(p); + } - for (; i < 64; ++i) W[i] = gamma1(W[i - 2]) + W[i - 7] + gamma0(W[i - 15]) + W[i - 16] | 0; + return res; + }; - for (var j = 0; j < 64; ++j) { - var T1 = h + sigma1(e) + ch(e, f, g) + K[j] + W[j] | 0; - var T2 = sigma0(a) + maj(a, b, c) | 0; - h = g; - g = f; - f = e; - e = d + T1 | 0; - d = c; - c = b; - b = a; - a = T1 + T2 | 0; - } + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two - (this || _global$s)._a = a + (this || _global$s)._a | 0; - (this || _global$s)._b = b + (this || _global$s)._b | 0; - (this || _global$s)._c = c + (this || _global$s)._c | 0; - (this || _global$s)._d = d + (this || _global$s)._d | 0; - (this || _global$s)._e = e + (this || _global$s)._e | 0; - (this || _global$s)._f = f + (this || _global$s)._f | 0; - (this || _global$s)._g = g + (this || _global$s)._g | 0; - (this || _global$s)._h = h + (this || _global$s)._h | 0; - }; + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } - Sha256.prototype._hash = function () { - var H = Buffer.allocUnsafe(32); - H.writeInt32BE((this || _global$s)._a, 0); - H.writeInt32BE((this || _global$s)._b, 4); - H.writeInt32BE((this || _global$s)._c, 8); - H.writeInt32BE((this || _global$s)._d, 12); - H.writeInt32BE((this || _global$s)._e, 16); - H.writeInt32BE((this || _global$s)._f, 20); - H.writeInt32BE((this || _global$s)._g, 24); - H.writeInt32BE((this || _global$s)._h, 28); - return H; - }; + do { + while (a.isEven()) { + a.iushrn(1); + } - exports$1M = Sha256; - return exports$1M; -} + while (b.isEven()) { + b.iushrn(1); + } -var exports$1L = {}, - _dewExec$1K = false; + var r = a.cmp(b); -var _global$r = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } -function dew$1K() { - if (_dewExec$1K) return exports$1L; - _dewExec$1K = true; + a.isub(b); + } while (true); - /** - * A JavaScript implementation of the Secure Hash Algorithm, SHA-256, as defined - * in FIPS 180-2 - * Version 2.2-beta Copyright Angel Marin, Paul Johnston 2000 - 2009. - * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet - * - */ - var inherits = dew$f$2(); + return b.iushln(shift); + }; // Invert number in the field F(num) - var Sha256 = dew$1L(); - var Hash = dew$1O(); + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; - var Buffer = dew$1T().Buffer; + BN.prototype.isEven = function isEven() { + return ((this || _global$5$1).words[0] & 1) === 0; + }; - var W = new Array(64); + BN.prototype.isOdd = function isOdd() { + return ((this || _global$5$1).words[0] & 1) === 1; + }; // And first word and num - function Sha224() { - this.init(); - (this || _global$r)._w = W; // new Array(64) - Hash.call(this || _global$r, 64, 56); - } + BN.prototype.andln = function andln(num) { + return (this || _global$5$1).words[0] & num; + }; // Increment at the bit position in-line - inherits(Sha224, Sha256); - Sha224.prototype.init = function () { - (this || _global$r)._a = 3238371032; - (this || _global$r)._b = 914150663; - (this || _global$r)._c = 812702999; - (this || _global$r)._d = 4144912697; - (this || _global$r)._e = 4290775857; - (this || _global$r)._f = 1750603025; - (this || _global$r)._g = 1694076839; - (this || _global$r)._h = 3204075428; - return this || _global$r; - }; + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words - Sha224.prototype._hash = function () { - var H = Buffer.allocUnsafe(28); - H.writeInt32BE((this || _global$r)._a, 0); - H.writeInt32BE((this || _global$r)._b, 4); - H.writeInt32BE((this || _global$r)._c, 8); - H.writeInt32BE((this || _global$r)._d, 12); - H.writeInt32BE((this || _global$r)._e, 16); - H.writeInt32BE((this || _global$r)._f, 20); - H.writeInt32BE((this || _global$r)._g, 24); - return H; - }; + if ((this || _global$5$1).length <= s) { + this._expand(s + 1); - exports$1L = Sha224; - return exports$1L; -} + (this || _global$5$1).words[s] |= q; + return this || _global$5$1; + } // Add bit and propagate, if needed -var exports$1K = {}, - _dewExec$1J = false; -var _global$q = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + var carry = q; -function dew$1J() { - if (_dewExec$1J) return exports$1K; - _dewExec$1J = true; + for (var i = s; carry !== 0 && i < (this || _global$5$1).length; i++) { + var w = (this || _global$5$1).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$5$1).words[i] = w; + } - var inherits = dew$f$2(); + if (carry !== 0) { + (this || _global$5$1).words[i] = carry; + (this || _global$5$1).length++; + } - var Hash = dew$1O(); + return this || _global$5$1; + }; - var Buffer = dew$1T().Buffer; + BN.prototype.isZero = function isZero() { + return (this || _global$5$1).length === 1 && (this || _global$5$1).words[0] === 0; + }; - var K = [1116352408, 3609767458, 1899447441, 602891725, 3049323471, 3964484399, 3921009573, 2173295548, 961987163, 4081628472, 1508970993, 3053834265, 2453635748, 2937671579, 2870763221, 3664609560, 3624381080, 2734883394, 310598401, 1164996542, 607225278, 1323610764, 1426881987, 3590304994, 1925078388, 4068182383, 2162078206, 991336113, 2614888103, 633803317, 3248222580, 3479774868, 3835390401, 2666613458, 4022224774, 944711139, 264347078, 2341262773, 604807628, 2007800933, 770255983, 1495990901, 1249150122, 1856431235, 1555081692, 3175218132, 1996064986, 2198950837, 2554220882, 3999719339, 2821834349, 766784016, 2952996808, 2566594879, 3210313671, 3203337956, 3336571891, 1034457026, 3584528711, 2466948901, 113926993, 3758326383, 338241895, 168717936, 666307205, 1188179964, 773529912, 1546045734, 1294757372, 1522805485, 1396182291, 2643833823, 1695183700, 2343527390, 1986661051, 1014477480, 2177026350, 1206759142, 2456956037, 344077627, 2730485921, 1290863460, 2820302411, 3158454273, 3259730800, 3505952657, 3345764771, 106217008, 3516065817, 3606008344, 3600352804, 1432725776, 4094571909, 1467031594, 275423344, 851169720, 430227734, 3100823752, 506948616, 1363258195, 659060556, 3750685593, 883997877, 3785050280, 958139571, 3318307427, 1322822218, 3812723403, 1537002063, 2003034995, 1747873779, 3602036899, 1955562222, 1575990012, 2024104815, 1125592928, 2227730452, 2716904306, 2361852424, 442776044, 2428436474, 593698344, 2756734187, 3733110249, 3204031479, 2999351573, 3329325298, 3815920427, 3391569614, 3928383900, 3515267271, 566280711, 3940187606, 3454069534, 4118630271, 4000239992, 116418474, 1914138554, 174292421, 2731055270, 289380356, 3203993006, 460393269, 320620315, 685471733, 587496836, 852142971, 1086792851, 1017036298, 365543100, 1126000580, 2618297676, 1288033470, 3409855158, 1501505948, 4234509866, 1607167915, 987167468, 1816402316, 1246189591]; - var W = new Array(160); + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$5$1).negative !== 0 && !negative) return -1; + if ((this || _global$5$1).negative === 0 && negative) return 1; + this.strip(); + var res; - function Sha512() { - this.init(); - (this || _global$q)._w = W; - Hash.call(this || _global$q, 128, 112); - } + if ((this || _global$5$1).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } - inherits(Sha512, Hash); + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$5$1).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } - Sha512.prototype.init = function () { - (this || _global$q)._ah = 1779033703; - (this || _global$q)._bh = 3144134277; - (this || _global$q)._ch = 1013904242; - (this || _global$q)._dh = 2773480762; - (this || _global$q)._eh = 1359893119; - (this || _global$q)._fh = 2600822924; - (this || _global$q)._gh = 528734635; - (this || _global$q)._hh = 1541459225; - (this || _global$q)._al = 4089235720; - (this || _global$q)._bl = 2227873595; - (this || _global$q)._cl = 4271175723; - (this || _global$q)._dl = 1595750129; - (this || _global$q)._el = 2917565137; - (this || _global$q)._fl = 725511199; - (this || _global$q)._gl = 4215389547; - (this || _global$q)._hl = 327033209; - return this || _global$q; - }; + if ((this || _global$5$1).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` - function Ch(x, y, z) { - return z ^ x & (y ^ z); - } - function maj(x, y, z) { - return x & y | z & (x | y); - } + BN.prototype.cmp = function cmp(num) { + if ((this || _global$5$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$5$1).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$5$1).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison - function sigma0(x, xl) { - return (x >>> 28 | xl << 4) ^ (xl >>> 2 | x << 30) ^ (xl >>> 7 | x << 25); - } - function sigma1(x, xl) { - return (x >>> 14 | xl << 18) ^ (x >>> 18 | xl << 14) ^ (xl >>> 9 | x << 23); - } + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$5$1).length > num.length) return 1; + if ((this || _global$5$1).length < num.length) return -1; + var res = 0; - function Gamma0(x, xl) { - return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ x >>> 7; - } + for (var i = (this || _global$5$1).length - 1; i >= 0; i--) { + var a = (this || _global$5$1).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; - function Gamma0l(x, xl) { - return (x >>> 1 | xl << 31) ^ (x >>> 8 | xl << 24) ^ (x >>> 7 | xl << 25); - } + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } - function Gamma1(x, xl) { - return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ x >>> 6; - } + break; + } - function Gamma1l(x, xl) { - return (x >>> 19 | xl << 13) ^ (xl >>> 29 | x << 3) ^ (x >>> 6 | xl << 26); - } + return res; + }; - function getCarry(a, b) { - return a >>> 0 < b >>> 0 ? 1 : 0; - } + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; - Sha512.prototype._update = function (M) { - var W = (this || _global$q)._w; - var ah = (this || _global$q)._ah | 0; - var bh = (this || _global$q)._bh | 0; - var ch = (this || _global$q)._ch | 0; - var dh = (this || _global$q)._dh | 0; - var eh = (this || _global$q)._eh | 0; - var fh = (this || _global$q)._fh | 0; - var gh = (this || _global$q)._gh | 0; - var hh = (this || _global$q)._hh | 0; - var al = (this || _global$q)._al | 0; - var bl = (this || _global$q)._bl | 0; - var cl = (this || _global$q)._cl | 0; - var dl = (this || _global$q)._dl | 0; - var el = (this || _global$q)._el | 0; - var fl = (this || _global$q)._fl | 0; - var gl = (this || _global$q)._gl | 0; - var hl = (this || _global$q)._hl | 0; + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; - for (var i = 0; i < 32; i += 2) { - W[i] = M.readInt32BE(i * 4); - W[i + 1] = M.readInt32BE(i * 4 + 4); - } + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; - for (; i < 160; i += 2) { - var xh = W[i - 15 * 2]; - var xl = W[i - 15 * 2 + 1]; - var gamma0 = Gamma0(xh, xl); - var gamma0l = Gamma0l(xl, xh); - xh = W[i - 2 * 2]; - xl = W[i - 2 * 2 + 1]; - var gamma1 = Gamma1(xh, xl); - var gamma1l = Gamma1l(xl, xh); // W[i] = gamma0 + W[i - 7] + gamma1 + W[i - 16] + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; - var Wi7h = W[i - 7 * 2]; - var Wi7l = W[i - 7 * 2 + 1]; - var Wi16h = W[i - 16 * 2]; - var Wi16l = W[i - 16 * 2 + 1]; - var Wil = gamma0l + Wi7l | 0; - var Wih = gamma0 + Wi7h + getCarry(Wil, gamma0l) | 0; - Wil = Wil + gamma1l | 0; - Wih = Wih + gamma1 + getCarry(Wil, gamma1l) | 0; - Wil = Wil + Wi16l | 0; - Wih = Wih + Wi16h + getCarry(Wil, Wi16l) | 0; - W[i] = Wih; - W[i + 1] = Wil; - } + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; - for (var j = 0; j < 160; j += 2) { - Wih = W[j]; - Wil = W[j + 1]; - var majh = maj(ah, bh, ch); - var majl = maj(al, bl, cl); - var sigma0h = sigma0(ah, al); - var sigma0l = sigma0(al, ah); - var sigma1h = sigma1(eh, el); - var sigma1l = sigma1(el, eh); // t1 = h + sigma1 + ch + K[j] + W[j] + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; - var Kih = K[j]; - var Kil = K[j + 1]; - var chh = Ch(eh, fh, gh); - var chl = Ch(el, fl, gl); - var t1l = hl + sigma1l | 0; - var t1h = hh + sigma1h + getCarry(t1l, hl) | 0; - t1l = t1l + chl | 0; - t1h = t1h + chh + getCarry(t1l, chl) | 0; - t1l = t1l + Kil | 0; - t1h = t1h + Kih + getCarry(t1l, Kil) | 0; - t1l = t1l + Wil | 0; - t1h = t1h + Wih + getCarry(t1l, Wil) | 0; // t2 = sigma0 + maj + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; - var t2l = sigma0l + majl | 0; - var t2h = sigma0h + majh + getCarry(t2l, sigma0l) | 0; - hh = gh; - hl = gl; - gh = fh; - gl = fl; - fh = eh; - fl = el; - el = dl + t1l | 0; - eh = dh + t1h + getCarry(el, dl) | 0; - dh = ch; - dl = cl; - ch = bh; - cl = bl; - bh = ah; - bl = al; - al = t1l + t2l | 0; - ah = t1h + t2h + getCarry(al, t1l) | 0; - } + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; - (this || _global$q)._al = (this || _global$q)._al + al | 0; - (this || _global$q)._bl = (this || _global$q)._bl + bl | 0; - (this || _global$q)._cl = (this || _global$q)._cl + cl | 0; - (this || _global$q)._dl = (this || _global$q)._dl + dl | 0; - (this || _global$q)._el = (this || _global$q)._el + el | 0; - (this || _global$q)._fl = (this || _global$q)._fl + fl | 0; - (this || _global$q)._gl = (this || _global$q)._gl + gl | 0; - (this || _global$q)._hl = (this || _global$q)._hl + hl | 0; - (this || _global$q)._ah = (this || _global$q)._ah + ah + getCarry((this || _global$q)._al, al) | 0; - (this || _global$q)._bh = (this || _global$q)._bh + bh + getCarry((this || _global$q)._bl, bl) | 0; - (this || _global$q)._ch = (this || _global$q)._ch + ch + getCarry((this || _global$q)._cl, cl) | 0; - (this || _global$q)._dh = (this || _global$q)._dh + dh + getCarry((this || _global$q)._dl, dl) | 0; - (this || _global$q)._eh = (this || _global$q)._eh + eh + getCarry((this || _global$q)._el, el) | 0; - (this || _global$q)._fh = (this || _global$q)._fh + fh + getCarry((this || _global$q)._fl, fl) | 0; - (this || _global$q)._gh = (this || _global$q)._gh + gh + getCarry((this || _global$q)._gl, gl) | 0; - (this || _global$q)._hh = (this || _global$q)._hh + hh + getCarry((this || _global$q)._hl, hl) | 0; - }; + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; - Sha512.prototype._hash = function () { - var H = Buffer.allocUnsafe(64); + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // - function writeInt64BE(h, l, offset) { - H.writeInt32BE(h, offset); - H.writeInt32BE(l, offset + 4); - } - writeInt64BE((this || _global$q)._ah, (this || _global$q)._al, 0); - writeInt64BE((this || _global$q)._bh, (this || _global$q)._bl, 8); - writeInt64BE((this || _global$q)._ch, (this || _global$q)._cl, 16); - writeInt64BE((this || _global$q)._dh, (this || _global$q)._dl, 24); - writeInt64BE((this || _global$q)._eh, (this || _global$q)._el, 32); - writeInt64BE((this || _global$q)._fh, (this || _global$q)._fl, 40); - writeInt64BE((this || _global$q)._gh, (this || _global$q)._gl, 48); - writeInt64BE((this || _global$q)._hh, (this || _global$q)._hl, 56); - return H; - }; + BN.red = function red(num) { + return new Red(num); + }; - exports$1K = Sha512; - return exports$1K; -} + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$5$1).red, "Already a number in reduction context"); + assert((this || _global$5$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$5$1)._forceRed(ctx); + }; -var exports$1J = {}, - _dewExec$1I = false; + BN.prototype.fromRed = function fromRed() { + assert((this || _global$5$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$5$1).red.convertFrom(this || _global$5$1); + }; -var _global$p = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$5$1).red = ctx; + return this || _global$5$1; + }; -function dew$1I() { - if (_dewExec$1I) return exports$1J; - _dewExec$1I = true; + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$5$1).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; - var inherits = dew$f$2(); + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$5$1).red, "redAdd works only with red numbers"); + return (this || _global$5$1).red.add(this || _global$5$1, num); + }; - var SHA512 = dew$1J(); + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$5$1).red, "redIAdd works only with red numbers"); + return (this || _global$5$1).red.iadd(this || _global$5$1, num); + }; - var Hash = dew$1O(); + BN.prototype.redSub = function redSub(num) { + assert((this || _global$5$1).red, "redSub works only with red numbers"); + return (this || _global$5$1).red.sub(this || _global$5$1, num); + }; - var Buffer = dew$1T().Buffer; + BN.prototype.redISub = function redISub(num) { + assert((this || _global$5$1).red, "redISub works only with red numbers"); + return (this || _global$5$1).red.isub(this || _global$5$1, num); + }; - var W = new Array(160); + BN.prototype.redShl = function redShl(num) { + assert((this || _global$5$1).red, "redShl works only with red numbers"); + return (this || _global$5$1).red.shl(this || _global$5$1, num); + }; - function Sha384() { - this.init(); - (this || _global$p)._w = W; - Hash.call(this || _global$p, 128, 112); - } + BN.prototype.redMul = function redMul(num) { + assert((this || _global$5$1).red, "redMul works only with red numbers"); - inherits(Sha384, SHA512); + (this || _global$5$1).red._verify2(this || _global$5$1, num); - Sha384.prototype.init = function () { - (this || _global$p)._ah = 3418070365; - (this || _global$p)._bh = 1654270250; - (this || _global$p)._ch = 2438529370; - (this || _global$p)._dh = 355462360; - (this || _global$p)._eh = 1731405415; - (this || _global$p)._fh = 2394180231; - (this || _global$p)._gh = 3675008525; - (this || _global$p)._hh = 1203062813; - (this || _global$p)._al = 3238371032; - (this || _global$p)._bl = 914150663; - (this || _global$p)._cl = 812702999; - (this || _global$p)._dl = 4144912697; - (this || _global$p)._el = 4290775857; - (this || _global$p)._fl = 1750603025; - (this || _global$p)._gl = 1694076839; - (this || _global$p)._hl = 3204075428; - return this || _global$p; - }; + return (this || _global$5$1).red.mul(this || _global$5$1, num); + }; - Sha384.prototype._hash = function () { - var H = Buffer.allocUnsafe(48); + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$5$1).red, "redMul works only with red numbers"); - function writeInt64BE(h, l, offset) { - H.writeInt32BE(h, offset); - H.writeInt32BE(l, offset + 4); - } + (this || _global$5$1).red._verify2(this || _global$5$1, num); - writeInt64BE((this || _global$p)._ah, (this || _global$p)._al, 0); - writeInt64BE((this || _global$p)._bh, (this || _global$p)._bl, 8); - writeInt64BE((this || _global$p)._ch, (this || _global$p)._cl, 16); - writeInt64BE((this || _global$p)._dh, (this || _global$p)._dl, 24); - writeInt64BE((this || _global$p)._eh, (this || _global$p)._el, 32); - writeInt64BE((this || _global$p)._fh, (this || _global$p)._fl, 40); - return H; - }; + return (this || _global$5$1).red.imul(this || _global$5$1, num); + }; - exports$1J = Sha384; - return exports$1J; -} + BN.prototype.redSqr = function redSqr() { + assert((this || _global$5$1).red, "redSqr works only with red numbers"); -var exports$1I = {}, - _dewExec$1H = false; -var module$7 = { - exports: exports$1I -}; -function dew$1H() { - if (_dewExec$1H) return module$7.exports; - _dewExec$1H = true; + (this || _global$5$1).red._verify1(this || _global$5$1); - var exports = module$7.exports = function SHA(algorithm) { - algorithm = algorithm.toLowerCase(); - var Algorithm = exports[algorithm]; - if (!Algorithm) throw new Error(algorithm + " is not supported (we accept pull requests)"); - return new Algorithm(); - }; + return (this || _global$5$1).red.sqr(this || _global$5$1); + }; - exports.sha = dew$1N(); - exports.sha1 = dew$1M(); - exports.sha224 = dew$1K(); - exports.sha256 = dew$1L(); - exports.sha384 = dew$1I(); - exports.sha512 = dew$1J(); - return module$7.exports; -} + BN.prototype.redISqr = function redISqr() { + assert((this || _global$5$1).red, "redISqr works only with red numbers"); -var e$g=y$o.EventEmitter;var e$1$1={};const t$c={};function n$q(e,n,r){r||(r=Error);class o extends r{constructor(e,t,r){super(function(e,t,r){return "string"==typeof n?n:n(e,t,r)}(e,t,r));}}o.prototype.name=r.name,o.prototype.code=e,t$c[e]=o;}function r$h(e,t){if(Array.isArray(e)){const n=e.length;return e=e.map(e=>String(e)),n>2?`one of ${t} ${e.slice(0,n-1).join(", ")}, or `+e[n-1]:2===n?`one of ${t} ${e[0]} or ${e[1]}`:`of ${t} ${e[0]}`}return `of ${t} ${String(e)}`}n$q("ERR_INVALID_OPT_VALUE",(function(e,t){return 'The value "'+t+'" is invalid for option "'+e+'"'}),TypeError),n$q("ERR_INVALID_ARG_TYPE",(function(e,t,n){let o;var E;let u;if("string"==typeof t&&(E="not ",t.substr(0,E.length)===E)?(o="must not be",t=t.replace(/^not /,"")):o="must be",function(e,t,n){return (void 0===n||n>e.length)&&(n=e.length),e.substring(n-t.length,n)===t}(e," argument"))u=`The ${e} ${o} ${r$h(t,"type")}`;else {u=`The "${e}" ${function(e,t,n){return "number"!=typeof n&&(n=0),!(n+t.length>e.length)&&-1!==e.indexOf(t,n)}(e,".")?"property":"argument"} ${o} ${r$h(t,"type")}`;}return u+=`. Received type ${typeof n}`,u}),TypeError),n$q("ERR_STREAM_PUSH_AFTER_EOF","stream.push() after EOF"),n$q("ERR_METHOD_NOT_IMPLEMENTED",(function(e){return "The "+e+" method is not implemented"})),n$q("ERR_STREAM_PREMATURE_CLOSE","Premature close"),n$q("ERR_STREAM_DESTROYED",(function(e){return "Cannot call "+e+" after a stream was destroyed"})),n$q("ERR_MULTIPLE_CALLBACK","Callback called multiple times"),n$q("ERR_STREAM_CANNOT_PIPE","Cannot pipe, not readable"),n$q("ERR_STREAM_WRITE_AFTER_END","write after end"),n$q("ERR_STREAM_NULL_VALUES","May not write null values to stream",TypeError),n$q("ERR_UNKNOWN_ENCODING",(function(e){return "Unknown encoding: "+e}),TypeError),n$q("ERR_STREAM_UNSHIFT_AFTER_END_EVENT","stream.unshift() after end event"),e$1$1.codes=t$c;var r$1$1=function(){throw new Error("Readable.from is not available in the browser")};var r$2$1="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function e$2$1(e){try{if(!r$2$1.localStorage)return !1}catch(r){return !1}var t=r$2$1.localStorage[e];return null!=t&&"true"===String(t).toLowerCase()}var t$1$1=function(t,n){if(e$2$1("noDeprecation"))return t;var o=!1;return function(){if(!o){if(e$2$1("throwDeprecation"))throw new Error(n);e$2$1("traceDeprecation")?console.trace(n):console.warn(n),o=!0;}return t.apply(this||r$2$1,arguments)}};function u$p(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r);}return n}function f$v(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function h$l(e,t){for(var n=0;n0?this.tail.next=t:this.head=t,this.tail=t,++this.length;}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length;}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0;}},{key:"join",value:function(e){if(0===this.length)return "";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return c$n.alloc(0);for(var t,n,r,i=c$n.allocUnsafe(e>>>0),a=this.head,o=0;a;)t=a.data,n=i,r=o,void c$n.prototype.copy.call(t,n,r),o+=a.data.length,a=a.next;return i}},{key:"consume",value:function(e,t){var n;return ei.length?i.length:e;if(a===i.length?r+=i:r+=i.slice(0,e),0==(e-=a)){a===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(a));break}++n;}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=c$n.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),0==(e-=a)){a===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(a));break}++r;}return this.length-=r,t}},{key:p$s,value:function(e,t){return b$j(this,function(e){for(var t=1;t0)if("string"==typeof t||o.objectMode||Object.getPrototypeOf(t)===c.prototype||(t=function(e){return c.from(e)}(t)),r)o.endEmitted?x(e,new P):q(e,o,t,!0);else if(o.ended)x(e,new O);else {if(o.destroyed)return !1;o.reading=!1,o.decoder&&!n?(t=o.decoder.write(t),o.objectMode||0!==t.length?q(e,o,t,!1):N(e,o)):q(e,o,t,!1);}else r||(o.reading=!1,N(e,o));return !o.ended&&(o.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function B(e){var t=e._readableState;p("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(p("emitReadable",t.flowing),t.emittedReadable=!0,u.nextTick(I,e));}function I(e){var t=e._readableState;p("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,J(e);}function N(e,t){t.readingMore||(t.readingMore=!0,u.nextTick(U,e,t));}function U(e,t){for(;!t.reading&&!t.ended&&(t.length0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume();}function K(e){p("readable nexttick read 0"),e.read(0);}function z(e,t){p("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),J(e),t.flowing&&!t.reading&&e.read(0);}function J(e){var t=e._readableState;for(p("flow",t.flowing);t.flowing&&null!==e.read(););}function Q(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n;}function X(e){var t=e._readableState;p("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,u.nextTick(Z,t,e));}function Z(e,t){if(p("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy();}}function $(e,t){for(var n=0,r=e.length;n=t.highWaterMark:t.length>0)||t.ended))return p("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?X(this):B(this),null;if(0===(e=W(e,t))&&t.ended)return 0===t.length&&X(this),null;var r,i=t.needReadable;return p("need readable",i),(0===t.length||t.length-e0?Q(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&X(this)),null!==r&&this.emit("data",r),r},C.prototype._read=function(e){x(this,new T("_read()"));},C.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e);}r.pipesCount+=1,p("pipe count=%d opts=%j",r.pipesCount,t);var i=(!t||!1!==t.end)&&e!==u.stdout&&e!==u.stderr?o:g;function a(t,i){p("onunpipe"),t===n&&i&&!1===i.hasUnpiped&&(i.hasUnpiped=!0,p("cleanup"),e.removeListener("close",c),e.removeListener("finish",b),e.removeListener("drain",s),e.removeListener("error",h),e.removeListener("unpipe",a),n.removeListener("end",o),n.removeListener("end",g),n.removeListener("data",d),l=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||s());}function o(){p("onend"),e.end();}r.endEmitted?u.nextTick(i):n.once("end",i),e.on("unpipe",a);var s=function(e){return function(){var t=e._readableState;p("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&f(e,"data")&&(t.flowing=!0,J(e));}}(n);e.on("drain",s);var l=!1;function d(t){p("ondata");var i=e.write(t);p("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==$(r.pipes,e))&&!l&&(p("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause());}function h(t){p("onerror",t),g(),e.removeListener("error",h),0===f(e,"error")&&x(e,t);}function c(){e.removeListener("finish",b),g();}function b(){p("onfinish"),e.removeListener("close",c),g();}function g(){p("unpipe"),n.unpipe(e);}return n.on("data",d),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n);}(e,"error",h),e.once("close",c),e.once("finish",b),e.emit("pipe",n),r.flowing||(p("pipe resume"),n.resume()),e},C.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,p("on readable",r.length,r.reading),r.length?B(this):r.reading||u.nextTick(K,this))),n},C.prototype.addListener=C.prototype.on,C.prototype.removeListener=function(e,t){var n=h.prototype.removeListener.call(this,e,t);return "readable"===e&&u.nextTick(H,this),n},C.prototype.removeAllListeners=function(e){var t=h.prototype.removeAllListeners.apply(this,arguments);return "readable"!==e&&void 0!==e||u.nextTick(H,this),t},C.prototype.resume=function(){var e=this._readableState;return e.flowing||(p("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,u.nextTick(z,e,t));}(this,e)),e.paused=!1,this},C.prototype.pause=function(){return p("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(p("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},C.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(p("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e);}t.push(null);})),e.on("data",(function(i){(p("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()));})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a-1))throw new M(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(P.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(P.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),P.prototype._write=function(e,t,n){n(new w("_write()"));},P.prototype._writev=null,P.prototype.end=function(e,t,n){var i=this._writableState;return "function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,t,n){t.ending=!0,q(e,t),n&&(t.finished?r.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1;}(this,i,n),this},Object.defineProperty(P.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(P.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e);}}),P.prototype.destroy=b.destroy,P.prototype._undestroy=b.undestroy,P.prototype._destroy=function(e,t){t(e);},z$9}var Z$3={},$$3=!1;function ee$1(){if($$3)return Z$3;$$3=!0;var e=T$9,t=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};Z$3=d;var n=K$8(),r=X$4();t$2$2(d,n);for(var a=t(r.prototype),s=0;s0?this.tail.next=t:this.head=t,this.tail=t,++this.length;}},{key:"unshift",value:function(e){var t={data:e,next:this.head};0===this.length&&(this.tail=t),this.head=t,++this.length;}},{key:"shift",value:function(){if(0!==this.length){var e=this.head.data;return 1===this.length?this.head=this.tail=null:this.head=this.head.next,--this.length,e}}},{key:"clear",value:function(){this.head=this.tail=null,this.length=0;}},{key:"join",value:function(e){if(0===this.length)return "";for(var t=this.head,n=""+t.data;t=t.next;)n+=e+t.data;return n}},{key:"concat",value:function(e){if(0===this.length)return b$1$1.alloc(0);for(var t,n,r,i=b$1$1.allocUnsafe(e>>>0),a=this.head,o=0;a;)t=a.data,n=i,r=o,void b$1$1.prototype.copy.call(t,n,r),o+=a.data.length,a=a.next;return i}},{key:"consume",value:function(e,t){var n;return ei.length?i.length:e;if(a===i.length?r+=i:r+=i.slice(0,e),0==(e-=a)){a===i.length?(++n,t.next?this.head=t.next:this.head=this.tail=null):(this.head=t,t.data=i.slice(a));break}++n;}return this.length-=n,r}},{key:"_getBuffer",value:function(e){var t=b$1$1.allocUnsafe(e),n=this.head,r=1;for(n.data.copy(t),e-=n.data.length;n=n.next;){var i=n.data,a=e>i.length?i.length:e;if(i.copy(t,t.length-e,0,a),0==(e-=a)){a===i.length?(++r,n.next?this.head=n.next:this.head=this.tail=null):(this.head=n,n.data=i.slice(a));break}++r;}return this.length-=r,t}},{key:g$1$1,value:function(e,t){return p$1$1(this,function(e){for(var t=1;t0)if("string"==typeof t||o.objectMode||Object.getPrototypeOf(t)===c.prototype||(t=function(e){return c.from(e)}(t)),r)o.endEmitted?P(e,new x):W(e,o,t,!0);else if(o.ended)P(e,new O);else {if(o.destroyed)return !1;o.reading=!1,o.decoder&&!n?(t=o.decoder.write(t),o.objectMode||0!==t.length?W(e,o,t,!1):N(e,o)):W(e,o,t,!1);}else r||(o.reading=!1,N(e,o));return !o.ended&&(o.lengtht.highWaterMark&&(t.highWaterMark=function(e){return e>=1073741824?e=1073741824:(e--,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e++),e}(e)),e<=t.length?e:t.ended?t.length:(t.needReadable=!0,0))}function q(e){var t=e._readableState;p("emitReadable",t.needReadable,t.emittedReadable),t.needReadable=!1,t.emittedReadable||(p("emitReadable",t.flowing),t.emittedReadable=!0,u.nextTick(I,e));}function I(e){var t=e._readableState;p("emitReadable_",t.destroyed,t.length,t.ended),t.destroyed||!t.length&&!t.ended||(e.emit("readable"),t.emittedReadable=!1),t.needReadable=!t.flowing&&!t.ended&&t.length<=t.highWaterMark,J(e);}function N(e,t){t.readingMore||(t.readingMore=!0,u.nextTick(G,e,t));}function G(e,t){for(;!t.reading&&!t.ended&&(t.length0,t.resumeScheduled&&!t.paused?t.flowing=!0:e.listenerCount("data")>0&&e.resume();}function K(e){p("readable nexttick read 0"),e.read(0);}function z(e,t){p("resume",t.reading),t.reading||e.read(0),t.resumeScheduled=!1,e.emit("resume"),J(e),t.flowing&&!t.reading&&e.read(0);}function J(e){var t=e._readableState;for(p("flow",t.flowing);t.flowing&&null!==e.read(););}function Q(e,t){return 0===t.length?null:(t.objectMode?n=t.buffer.shift():!e||e>=t.length?(n=t.decoder?t.buffer.join(""):1===t.buffer.length?t.buffer.first():t.buffer.concat(t.length),t.buffer.clear()):n=t.buffer.consume(e,t.decoder),n);var n;}function X(e){var t=e._readableState;p("endReadable",t.endEmitted),t.endEmitted||(t.ended=!0,u.nextTick($,t,e));}function $(e,t){if(p("endReadableNT",e.endEmitted,e.length),!e.endEmitted&&0===e.length&&(e.endEmitted=!0,t.readable=!1,t.emit("end"),e.autoDestroy)){var n=t._writableState;(!n||n.autoDestroy&&n.finished)&&t.destroy();}}function ee(e,t){for(var n=0,r=e.length;n=t.highWaterMark:t.length>0)||t.ended))return p("read: emitReadable",t.length,t.ended),0===t.length&&t.ended?X(this):q(this),null;if(0===(e=B(e,t))&&t.ended)return 0===t.length&&X(this),null;var r,i=t.needReadable;return p("need readable",i),(0===t.length||t.length-e0?Q(e,t):null)?(t.needReadable=t.length<=t.highWaterMark,e=0):(t.length-=e,t.awaitDrain=0),0===t.length&&(t.ended||(t.needReadable=!0),n!==e&&t.ended&&X(this)),null!==r&&this.emit("data",r),r},C.prototype._read=function(e){P(this,new T("_read()"));},C.prototype.pipe=function(e,t){var n=this,r=this._readableState;switch(r.pipesCount){case 0:r.pipes=e;break;case 1:r.pipes=[r.pipes,e];break;default:r.pipes.push(e);}r.pipesCount+=1,p("pipe count=%d opts=%j",r.pipesCount,t);var i=(!t||!1!==t.end)&&e!==u.stdout&&e!==u.stderr?o:g;function a(t,i){p("onunpipe"),t===n&&i&&!1===i.hasUnpiped&&(i.hasUnpiped=!0,p("cleanup"),e.removeListener("close",c),e.removeListener("finish",b),e.removeListener("drain",s),e.removeListener("error",h),e.removeListener("unpipe",a),n.removeListener("end",o),n.removeListener("end",g),n.removeListener("data",d),l=!0,!r.awaitDrain||e._writableState&&!e._writableState.needDrain||s());}function o(){p("onend"),e.end();}r.endEmitted?u.nextTick(i):n.once("end",i),e.on("unpipe",a);var s=function(e){return function(){var t=e._readableState;p("pipeOnDrain",t.awaitDrain),t.awaitDrain&&t.awaitDrain--,0===t.awaitDrain&&f(e,"data")&&(t.flowing=!0,J(e));}}(n);e.on("drain",s);var l=!1;function d(t){p("ondata");var i=e.write(t);p("dest.write",i),!1===i&&((1===r.pipesCount&&r.pipes===e||r.pipesCount>1&&-1!==ee(r.pipes,e))&&!l&&(p("false write response, pause",r.awaitDrain),r.awaitDrain++),n.pause());}function h(t){p("onerror",t),g(),e.removeListener("error",h),0===f(e,"error")&&P(e,t);}function c(){e.removeListener("finish",b),g();}function b(){p("onfinish"),e.removeListener("close",c),g();}function g(){p("unpipe"),n.unpipe(e);}return n.on("data",d),function(e,t,n){if("function"==typeof e.prependListener)return e.prependListener(t,n);e._events&&e._events[t]?Array.isArray(e._events[t])?e._events[t].unshift(n):e._events[t]=[n,e._events[t]]:e.on(t,n);}(e,"error",h),e.once("close",c),e.once("finish",b),e.emit("pipe",n),r.flowing||(p("pipe resume"),n.resume()),e},C.prototype.unpipe=function(e){var t=this._readableState,n={hasUnpiped:!1};if(0===t.pipesCount)return this;if(1===t.pipesCount)return e&&e!==t.pipes||(e||(e=t.pipes),t.pipes=null,t.pipesCount=0,t.flowing=!1,e&&e.emit("unpipe",this,n)),this;if(!e){var r=t.pipes,i=t.pipesCount;t.pipes=null,t.pipesCount=0,t.flowing=!1;for(var a=0;a0,!1!==r.flowing&&this.resume()):"readable"===e&&(r.endEmitted||r.readableListening||(r.readableListening=r.needReadable=!0,r.flowing=!1,r.emittedReadable=!1,p("on readable",r.length,r.reading),r.length?q(this):r.reading||u.nextTick(K,this))),n},C.prototype.addListener=C.prototype.on,C.prototype.removeListener=function(e,t){var n=h.prototype.removeListener.call(this,e,t);return "readable"===e&&u.nextTick(Y,this),n},C.prototype.removeAllListeners=function(e){var t=h.prototype.removeAllListeners.apply(this,arguments);return "readable"!==e&&void 0!==e||u.nextTick(Y,this),t},C.prototype.resume=function(){var e=this._readableState;return e.flowing||(p("resume"),e.flowing=!e.readableListening,function(e,t){t.resumeScheduled||(t.resumeScheduled=!0,u.nextTick(z,e,t));}(this,e)),e.paused=!1,this},C.prototype.pause=function(){return p("call pause flowing=%j",this._readableState.flowing),!1!==this._readableState.flowing&&(p("pause"),this._readableState.flowing=!1,this.emit("pause")),this._readableState.paused=!0,this},C.prototype.wrap=function(e){var t=this,n=this._readableState,r=!1;for(var i in e.on("end",(function(){if(p("wrapped end"),n.decoder&&!n.ended){var e=n.decoder.end();e&&e.length&&t.push(e);}t.push(null);})),e.on("data",(function(i){(p("wrapped data"),n.decoder&&(i=n.decoder.write(i)),n.objectMode&&null==i)||(n.objectMode||i&&i.length)&&(t.push(i)||(r=!0,e.pause()));})),e)void 0===this[i]&&"function"==typeof e[i]&&(this[i]=function(t){return function(){return e[t].apply(e,arguments)}}(i));for(var a=0;a-1))throw new M(e);return this._writableState.defaultEncoding=e,this},Object.defineProperty(x.prototype,"writableBuffer",{enumerable:!1,get:function(){return this._writableState&&this._writableState.getBuffer()}}),Object.defineProperty(x.prototype,"writableHighWaterMark",{enumerable:!1,get:function(){return this._writableState.highWaterMark}}),x.prototype._write=function(e,t,n){n(new w("_write()"));},x.prototype._writev=null,x.prototype.end=function(e,t,n){var i=this._writableState;return "function"==typeof e?(n=e,e=null,t=null):"function"==typeof t&&(n=t,t=null),null!=e&&this.write(e,t),i.corked&&(i.corked=1,this.uncork()),i.ending||function(e,t,n){t.ending=!0,W(e,t),n&&(t.finished?r.nextTick(n):e.once("finish",n));t.ended=!0,e.writable=!1;}(this,i,n),this},Object.defineProperty(x.prototype,"writableLength",{enumerable:!1,get:function(){return this._writableState.length}}),Object.defineProperty(x.prototype,"destroyed",{enumerable:!1,get:function(){return void 0!==this._writableState&&this._writableState.destroyed},set:function(e){this._writableState&&(this._writableState.destroyed=e);}}),x.prototype.destroy=b.destroy,x.prototype._undestroy=b.undestroy,x.prototype._destroy=function(e,t){t(e);},Y$1$1}var Q$1$1={},X$1$1=!1;function Z$1$1(){if(X$1$1)return Q$1$1;X$1$1=!0;var e=T$9,t=Object.keys||function(e){var t=[];for(var n in e)t.push(n);return t};Q$1$1=d;var n=G$1$1(),r=J$1$1();t$2$2(d,n);for(var a=t(r.prototype),s=0;s0,(function(r){o||(o=r),r&&i.forEach(a$1$1),e||(i.forEach(a$1$1),f(o));}))}));return n.reduce(c$2$1)}; + (this || _global$5$1).red._verify1(this || _global$5$1); -var l$r,d$n="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;l$r=p$r;var f$u=y$o.EventEmitter;function p$r(){f$u.call(this||d$n);}t$2$2(p$r,f$u),p$r.Readable=t$2$1,p$r.Writable=t$4$1,p$r.Duplex=t$5$1,p$r.Transform=p$2$1,p$r.PassThrough=s$1$1,p$r.finished=n$1$1,p$r.pipeline=v$2$1,p$r.Stream=p$r,p$r.prototype.pipe=function(e,r){var t=this||d$n;function o(r){e.writable&&!1===e.write(r)&&t.pause&&t.pause();}function i(){t.readable&&t.resume&&t.resume();}t.on("data",o),e.on("drain",i),e._isStdio||r&&!1===r.end||(t.on("end",a),t.on("close",s));var n=!1;function a(){n||(n=!0,e.end());}function s(){n||(n=!0,"function"==typeof e.destroy&&e.destroy());}function m(e){if(l(),0===f$u.listenerCount(this||d$n,"error"))throw e}function l(){t.removeListener("data",o),e.removeListener("drain",i),t.removeListener("end",a),t.removeListener("close",s),t.removeListener("error",m),e.removeListener("error",m),t.removeListener("end",l),t.removeListener("close",l),e.removeListener("close",l);}return t.on("error",m),e.on("error",m),t.on("end",l),t.on("close",l),e.on("close",l),e.emit("pipe",t),e};var b$i=l$r;b$i.Readable;b$i.Writable;b$i.Duplex;b$i.Transform;b$i.PassThrough;b$i.finished;b$i.pipeline;b$i.Stream; + return (this || _global$5$1).red.isqr(this || _global$5$1); + }; // Square root over p -var exports$1H = {}, - _dewExec$1G = false; -var _global$o = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$5$1).red, "redSqrt works only with red numbers"); -function dew$1G() { - if (_dewExec$1G) return exports$1H; - _dewExec$1G = true; + (this || _global$5$1).red._verify1(this || _global$5$1); - var Buffer = dew$1T().Buffer; + return (this || _global$5$1).red.sqrt(this || _global$5$1); + }; - var Transform = b$i.Transform; - var StringDecoder = e$1$2.StringDecoder; + BN.prototype.redInvm = function redInvm() { + assert((this || _global$5$1).red, "redInvm works only with red numbers"); - var inherits = dew$f$2(); + (this || _global$5$1).red._verify1(this || _global$5$1); - function CipherBase(hashMode) { - Transform.call(this || _global$o); - (this || _global$o).hashMode = typeof hashMode === "string"; + return (this || _global$5$1).red.invm(this || _global$5$1); + }; // Return negative clone of `this` % `red modulo` - if ((this || _global$o).hashMode) { - (this || _global$o)[hashMode] = (this || _global$o)._finalOrDigest; - } else { - (this || _global$o).final = (this || _global$o)._finalOrDigest; - } - if ((this || _global$o)._final) { - (this || _global$o).__final = (this || _global$o)._final; - (this || _global$o)._final = null; - } + BN.prototype.redNeg = function redNeg() { + assert((this || _global$5$1).red, "redNeg works only with red numbers"); - (this || _global$o)._decoder = null; - (this || _global$o)._encoding = null; - } + (this || _global$5$1).red._verify1(this || _global$5$1); - inherits(CipherBase, Transform); + return (this || _global$5$1).red.neg(this || _global$5$1); + }; - CipherBase.prototype.update = function (data, inputEnc, outputEnc) { - if (typeof data === "string") { - data = Buffer.from(data, inputEnc); - } + BN.prototype.redPow = function redPow(num) { + assert((this || _global$5$1).red && !num.red, "redPow(normalNum)"); - var outData = this._update(data); + (this || _global$5$1).red._verify1(this || _global$5$1); - if ((this || _global$o).hashMode) return this || _global$o; + return (this || _global$5$1).red.pow(this || _global$5$1, num); + }; // Prime numbers with efficient reduction - if (outputEnc) { - outData = this._toString(outData, outputEnc); - } - return outData; - }; + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime - CipherBase.prototype.setAutoPadding = function () {}; + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$5$1).name = name; + (this || _global$5$1).p = new BN(p, 16); + (this || _global$5$1).n = (this || _global$5$1).p.bitLength(); + (this || _global$5$1).k = new BN(1).iushln((this || _global$5$1).n).isub((this || _global$5$1).p); + (this || _global$5$1).tmp = this._tmp(); + } - CipherBase.prototype.getAuthTag = function () { - throw new Error("trying to get auth tag in unsupported state"); - }; + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$5$1).n / 13)); + return tmp; + }; - CipherBase.prototype.setAuthTag = function () { - throw new Error("trying to set auth tag in unsupported state"); - }; + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; - CipherBase.prototype.setAAD = function () { - throw new Error("trying to set aad in unsupported state"); - }; + do { + this.split(r, (this || _global$5$1).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$5$1).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$5$1).n); - CipherBase.prototype._transform = function (data, _, next) { - var err; + var cmp = rlen < (this || _global$5$1).n ? -1 : r.ucmp((this || _global$5$1).p); - try { - if ((this || _global$o).hashMode) { - this._update(data); + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$5$1).p); } else { - this.push(this._update(data)); + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } } - } catch (e) { - err = e; - } finally { - next(err); - } - }; - CipherBase.prototype._flush = function (done) { - var err; + return r; + }; - try { - this.push(this.__final()); - } catch (e) { - err = e; + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$5$1).n, 0, out); + }; + + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$5$1).k); + }; + + function K256() { + MPrime.call(this || _global$5$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - done(err); - }; + inherits(K256, MPrime); - CipherBase.prototype._finalOrDigest = function (outputEnc) { - var outData = this.__final() || Buffer.alloc(0); + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); - if (outputEnc) { - outData = this._toString(outData, outputEnc, true); - } + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } - return outData; - }; + output.length = outLen; - CipherBase.prototype._toString = function (value, enc, fin) { - if (!(this || _global$o)._decoder) { - (this || _global$o)._decoder = new StringDecoder(enc); - (this || _global$o)._encoding = enc; - } + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs - if ((this || _global$o)._encoding !== enc) throw new Error("can't switch encodings"); - var out = (this || _global$o)._decoder.write(value); + var prev = input.words[9]; + output.words[output.length++] = prev & mask; - if (fin) { - out += (this || _global$o)._decoder.end(); - } + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } - return out; - }; + prev >>>= 22; + input.words[i - 10] = prev; - exports$1H = CipherBase; - return exports$1H; -} + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; -var exports$1G = {}, - _dewExec$1F = false; -function dew$1F() { - if (_dewExec$1F) return exports$1G; - _dewExec$1F = true; + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 - var inherits = dew$f$2(); + var lo = 0; - var MD5 = dew$1Q(); + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction - var RIPEMD160 = dew$1P(); - var sha = dew$1H(); + if (num.words[num.length - 1] === 0) { + num.length--; - var Base = dew$1G(); + if (num.words[num.length - 1] === 0) { + num.length--; + } + } - function Hash(hash) { - Base.call(this, "digest"); - this._hash = hash; - } + return num; + }; - inherits(Hash, Base); + function P224() { + MPrime.call(this || _global$5$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } - Hash.prototype._update = function (data) { - this._hash.update(data); - }; + inherits(P224, MPrime); - Hash.prototype._final = function () { - return this._hash.digest(); - }; + function P192() { + MPrime.call(this || _global$5$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } - exports$1G = function createHash(alg) { - alg = alg.toLowerCase(); - if (alg === "md5") return new MD5(); - if (alg === "rmd160" || alg === "ripemd160") return new RIPEMD160(); - return new Hash(sha(alg)); - }; + inherits(P192, MPrime); - return exports$1G; -} + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$5$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } -var exports$1F = {}, - _dewExec$1E = false; -function dew$1E() { - if (_dewExec$1E) return exports$1F; - _dewExec$1E = true; + inherits(P25519, MPrime); - var inherits = dew$f$2(); + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; - var Buffer = dew$1T().Buffer; + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } - var Base = dew$1G(); + if (carry !== 0) { + num.words[num.length++] = carry; + } - var ZEROS = Buffer.alloc(128); - var blocksize = 64; + return num; + }; // Exported mostly for testing purposes, use plain name instead - function Hmac(alg, key) { - Base.call(this, "digest"); - if (typeof key === "string") { - key = Buffer.from(key); - } + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; - this._alg = alg; - this._key = key; + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } - if (key.length > blocksize) { - key = alg(key); - } else if (key.length < blocksize) { - key = Buffer.concat([key, ZEROS], blocksize); - } + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // - var ipad = this._ipad = Buffer.allocUnsafe(blocksize); - var opad = this._opad = Buffer.allocUnsafe(blocksize); - for (var i = 0; i < blocksize; i++) { - ipad[i] = key[i] ^ 54; - opad[i] = key[i] ^ 92; + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); + + (this || _global$5$1).m = prime.p; + (this || _global$5$1).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$5$1).m = m; + (this || _global$5$1).prime = null; + } } - this._hash = [ipad]; - } + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; - inherits(Hmac, Base); + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; - Hmac.prototype._update = function (data) { - this._hash.push(data); - }; + Red.prototype.imod = function imod(a) { + if ((this || _global$5$1).prime) return (this || _global$5$1).prime.ireduce(a)._forceRed(this || _global$5$1); + return a.umod((this || _global$5$1).m)._forceRed(this || _global$5$1); + }; - Hmac.prototype._final = function () { - var h = this._alg(Buffer.concat(this._hash)); + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); + } - return this._alg(Buffer.concat([this._opad, h])); - }; + return (this || _global$5$1).m.sub(a)._forceRed(this || _global$5$1); + }; - exports$1F = Hmac; - return exports$1F; -} + Red.prototype.add = function add(a, b) { + this._verify2(a, b); -var exports$1E = {}, - _dewExec$1D = false; -function dew$1D() { - if (_dewExec$1D) return exports$1E; - _dewExec$1D = true; + var res = a.add(b); - var MD5 = dew$1Q(); + if (res.cmp((this || _global$5$1).m) >= 0) { + res.isub((this || _global$5$1).m); + } - exports$1E = function (buffer) { - return new MD5().update(buffer).digest(); - }; + return res._forceRed(this || _global$5$1); + }; - return exports$1E; -} + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); -var exports$1D = {}, - _dewExec$1C = false; -function dew$1C() { - if (_dewExec$1C) return exports$1D; - _dewExec$1C = true; + var res = a.iadd(b); - var inherits = dew$f$2(); + if (res.cmp((this || _global$5$1).m) >= 0) { + res.isub((this || _global$5$1).m); + } - var Legacy = dew$1E(); + return res; + }; - var Base = dew$1G(); + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); - var Buffer = dew$1T().Buffer; + var res = a.sub(b); - var md5 = dew$1D(); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$5$1).m); + } - var RIPEMD160 = dew$1P(); + return res._forceRed(this || _global$5$1); + }; - var sha = dew$1H(); + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); - var ZEROS = Buffer.alloc(128); + var res = a.isub(b); - function Hmac(alg, key) { - Base.call(this, "digest"); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$5$1).m); + } - if (typeof key === "string") { - key = Buffer.from(key); - } + return res; + }; - var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; - this._alg = alg; - this._key = key; + Red.prototype.shl = function shl(a, num) { + this._verify1(a); - if (key.length > blocksize) { - var hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); - key = hash.update(key).digest(); - } else if (key.length < blocksize) { - key = Buffer.concat([key, ZEROS], blocksize); - } + return this.imod(a.ushln(num)); + }; - var ipad = this._ipad = Buffer.allocUnsafe(blocksize); - var opad = this._opad = Buffer.allocUnsafe(blocksize); + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); - for (var i = 0; i < blocksize; i++) { - ipad[i] = key[i] ^ 54; - opad[i] = key[i] ^ 92; - } + return this.imod(a.imul(b)); + }; - this._hash = alg === "rmd160" ? new RIPEMD160() : sha(alg); + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); - this._hash.update(ipad); - } + return this.imod(a.mul(b)); + }; + + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); + }; + + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); + }; - inherits(Hmac, Base); + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); - Hmac.prototype._update = function (data) { - this._hash.update(data); - }; + var mod3 = (this || _global$5$1).m.andln(3); - Hmac.prototype._final = function () { - var h = this._hash.digest(); + assert(mod3 % 2 === 1); // Fast case - var hash = this._alg === "rmd160" ? new RIPEMD160() : sha(this._alg); - return hash.update(this._opad).update(h).digest(); - }; + if (mod3 === 3) { + var pow = (this || _global$5$1).m.add(new BN(1)).iushrn(2); - exports$1D = function createHmac(alg, key) { - alg = alg.toLowerCase(); + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) - if (alg === "rmd160" || alg === "ripemd160") { - return new Hmac("rmd160", key); - } - if (alg === "md5") { - return new Legacy(md5, key); - } + var q = (this || _global$5$1).m.subn(1); - return new Hmac(alg, key); - }; + var s = 0; - return exports$1D; -} + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } -var _algorithms = { - "sha224WithRSAEncryption": { - "sign": "rsa", - "hash": "sha224", - "id": "302d300d06096086480165030402040500041c" - }, - "RSA-SHA224": { - "sign": "ecdsa/rsa", - "hash": "sha224", - "id": "302d300d06096086480165030402040500041c" - }, - "sha256WithRSAEncryption": { - "sign": "rsa", - "hash": "sha256", - "id": "3031300d060960864801650304020105000420" - }, - "RSA-SHA256": { - "sign": "ecdsa/rsa", - "hash": "sha256", - "id": "3031300d060960864801650304020105000420" - }, - "sha384WithRSAEncryption": { - "sign": "rsa", - "hash": "sha384", - "id": "3041300d060960864801650304020205000430" - }, - "RSA-SHA384": { - "sign": "ecdsa/rsa", - "hash": "sha384", - "id": "3041300d060960864801650304020205000430" - }, - "sha512WithRSAEncryption": { - "sign": "rsa", - "hash": "sha512", - "id": "3051300d060960864801650304020305000440" - }, - "RSA-SHA512": { - "sign": "ecdsa/rsa", - "hash": "sha512", - "id": "3051300d060960864801650304020305000440" - }, - "RSA-SHA1": { - "sign": "rsa", - "hash": "sha1", - "id": "3021300906052b0e03021a05000414" - }, - "ecdsa-with-SHA1": { - "sign": "ecdsa", - "hash": "sha1", - "id": "" - }, - "sha256": { - "sign": "ecdsa", - "hash": "sha256", - "id": "" - }, - "sha224": { - "sign": "ecdsa", - "hash": "sha224", - "id": "" - }, - "sha384": { - "sign": "ecdsa", - "hash": "sha384", - "id": "" - }, - "sha512": { - "sign": "ecdsa", - "hash": "sha512", - "id": "" - }, - "DSA-SHA": { - "sign": "dsa", - "hash": "sha1", - "id": "" - }, - "DSA-SHA1": { - "sign": "dsa", - "hash": "sha1", - "id": "" - }, - "DSA": { - "sign": "dsa", - "hash": "sha1", - "id": "" - }, - "DSA-WITH-SHA224": { - "sign": "dsa", - "hash": "sha224", - "id": "" - }, - "DSA-SHA224": { - "sign": "dsa", - "hash": "sha224", - "id": "" - }, - "DSA-WITH-SHA256": { - "sign": "dsa", - "hash": "sha256", - "id": "" - }, - "DSA-SHA256": { - "sign": "dsa", - "hash": "sha256", - "id": "" - }, - "DSA-WITH-SHA384": { - "sign": "dsa", - "hash": "sha384", - "id": "" - }, - "DSA-SHA384": { - "sign": "dsa", - "hash": "sha384", - "id": "" - }, - "DSA-WITH-SHA512": { - "sign": "dsa", - "hash": "sha512", - "id": "" - }, - "DSA-SHA512": { - "sign": "dsa", - "hash": "sha512", - "id": "" - }, - "DSA-RIPEMD160": { - "sign": "dsa", - "hash": "rmd160", - "id": "" - }, - "ripemd160WithRSA": { - "sign": "rsa", - "hash": "rmd160", - "id": "3021300906052b2403020105000414" - }, - "RSA-RIPEMD160": { - "sign": "rsa", - "hash": "rmd160", - "id": "3021300906052b2403020105000414" - }, - "md5WithRSAEncryption": { - "sign": "rsa", - "hash": "md5", - "id": "3020300c06082a864886f70d020505000410" - }, - "RSA-MD5": { - "sign": "rsa", - "hash": "md5", - "id": "3020300c06082a864886f70d020505000410" - } -}; + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$5$1); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. -var exports$1C = {}, - _dewExec$1B = false; -function dew$1B() { - if (_dewExec$1B) return exports$1C; - _dewExec$1B = true; - exports$1C = _algorithms; - return exports$1C; -} + var lpow = (this || _global$5$1).m.subn(1).iushrn(1); -var exports$1B = {}, - _dewExec$1A = false; -function dew$1A() { - if (_dewExec$1A) return exports$1B; - _dewExec$1A = true; - var MAX_ALLOC = Math.pow(2, 30) - 1; // default in iojs + var z = (this || _global$5$1).m.bitLength(); - exports$1B = function (iterations, keylen) { - if (typeof iterations !== "number") { - throw new TypeError("Iterations not a number"); - } + z = new BN(2 * z * z).toRed(this || _global$5$1); - if (iterations < 0) { - throw new TypeError("Bad iterations"); - } + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } - if (typeof keylen !== "number") { - throw new TypeError("Key length not a number"); - } + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; - if (keylen < 0 || keylen > MAX_ALLOC || keylen !== keylen) { - /* eslint no-self-compare: 0 */ - throw new TypeError("Bad key length"); - } - }; + while (t.cmp(one) !== 0) { + var tmp = t; - return exports$1B; -} + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } -var exports$1A = {}, - _dewExec$1z = false; + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } -var _global$n = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + return r; + }; -function dew$1z() { - if (_dewExec$1z) return exports$1A; - _dewExec$1z = true; - var process = T$9; - var defaultEncoding; - /* istanbul ignore next */ + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$5$1).m); - if (_global$n.process && _global$n.process.browser) { - defaultEncoding = "utf-8"; - } else if (_global$n.process && _global$n.process.version) { - var pVersionMajor = parseInt(process.version.split(".")[0].slice(1), 10); - defaultEncoding = pVersionMajor >= 6 ? "utf-8" : "binary"; - } else { - defaultEncoding = "utf-8"; - } + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; - exports$1A = defaultEncoding; - return exports$1A; -} + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$5$1); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$5$1); + wnd[1] = a; -var exports$1z = {}, - _dewExec$1y = false; -function dew$1y() { - if (_dewExec$1y) return exports$1z; - _dewExec$1y = true; + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } - var Buffer = dew$1T().Buffer; + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; - exports$1z = function (thing, encoding, name) { - if (Buffer.isBuffer(thing)) { - return thing; - } else if (typeof thing === "string") { - return Buffer.from(thing, encoding); - } else if (ArrayBuffer.isView(thing)) { - return Buffer.from(thing.buffer); - } else { - throw new TypeError(name + " must be a string, a Buffer, a typed array or a DataView"); - } - }; + if (start === 0) { + start = 26; + } - return exports$1z; -} + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; -var exports$1y = {}, - _dewExec$1x = false; + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; -var _global$m = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + if (res !== wnd[0]) { + res = this.sqr(res); + } -function dew$1x() { - if (_dewExec$1x) return exports$1y; - _dewExec$1x = true; + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } - var md5 = dew$1D(); + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } - var RIPEMD160 = dew$1P(); + start = 26; + } - var sha = dew$1H(); + return res; + }; - var Buffer = dew$1T().Buffer; + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$5$1).m); + return r === num ? r.clone() : r; + }; - var checkParameters = dew$1A(); + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // - var defaultEncoding = dew$1z(); - var toBuffer = dew$1y(); + BN.mont = function mont(num) { + return new Mont(num); + }; - var ZEROS = Buffer.alloc(128); - var sizes = { - md5: 16, - sha1: 20, - sha224: 28, - sha256: 32, - sha384: 48, - sha512: 64, - rmd160: 20, - ripemd160: 20 - }; + function Mont(m) { + Red.call(this || _global$5$1, m); + (this || _global$5$1).shift = (this || _global$5$1).m.bitLength(); - function Hmac(alg, key, saltLen) { - var hash = getDigest(alg); - var blocksize = alg === "sha512" || alg === "sha384" ? 128 : 64; + if ((this || _global$5$1).shift % 26 !== 0) { + (this || _global$5$1).shift += 26 - (this || _global$5$1).shift % 26; + } - if (key.length > blocksize) { - key = hash(key); - } else if (key.length < blocksize) { - key = Buffer.concat([key, ZEROS], blocksize); + (this || _global$5$1).r = new BN(1).iushln((this || _global$5$1).shift); + (this || _global$5$1).r2 = this.imod((this || _global$5$1).r.sqr()); + (this || _global$5$1).rinv = (this || _global$5$1).r._invmp((this || _global$5$1).m); + (this || _global$5$1).minv = (this || _global$5$1).rinv.mul((this || _global$5$1).r).isubn(1).div((this || _global$5$1).m); + (this || _global$5$1).minv = (this || _global$5$1).minv.umod((this || _global$5$1).r); + (this || _global$5$1).minv = (this || _global$5$1).r.sub((this || _global$5$1).minv); } - var ipad = Buffer.allocUnsafe(blocksize + sizes[alg]); - var opad = Buffer.allocUnsafe(blocksize + sizes[alg]); + inherits(Mont, Red); - for (var i = 0; i < blocksize; i++) { - ipad[i] = key[i] ^ 54; - opad[i] = key[i] ^ 92; - } + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$5$1).shift)); + }; - var ipad1 = Buffer.allocUnsafe(blocksize + saltLen + 4); - ipad.copy(ipad1, 0, 0, blocksize); - (this || _global$m).ipad1 = ipad1; - (this || _global$m).ipad2 = ipad; - (this || _global$m).opad = opad; - (this || _global$m).alg = alg; - (this || _global$m).blocksize = blocksize; - (this || _global$m).hash = hash; - (this || _global$m).size = sizes[alg]; - } + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$5$1).rinv)); + r.red = null; + return r; + }; - Hmac.prototype.run = function (data, ipad) { - data.copy(ipad, (this || _global$m).blocksize); - var h = this.hash(ipad); - h.copy((this || _global$m).opad, (this || _global$m).blocksize); - return this.hash((this || _global$m).opad); - }; + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } - function getDigest(alg) { - function shaFunc(data) { - return sha(alg).update(data).digest(); - } + var t = a.imul(b); + var c = t.maskn((this || _global$5$1).shift).mul((this || _global$5$1).minv).imaskn((this || _global$5$1).shift).mul((this || _global$5$1).m); + var u = t.isub(c).iushrn((this || _global$5$1).shift); + var res = u; - function rmd160Func(data) { - return new RIPEMD160().update(data).digest(); - } + if (u.cmp((this || _global$5$1).m) >= 0) { + res = u.isub((this || _global$5$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$5$1).m); + } - if (alg === "rmd160" || alg === "ripemd160") return rmd160Func; - if (alg === "md5") return md5; - return shaFunc; - } + return res._forceRed(this || _global$5$1); + }; - function pbkdf2(password, salt, iterations, keylen, digest) { - checkParameters(iterations, keylen); - password = toBuffer(password, defaultEncoding, "Password"); - salt = toBuffer(salt, defaultEncoding, "Salt"); - digest = digest || "sha1"; - var hmac = new Hmac(digest, password, salt.length); - var DK = Buffer.allocUnsafe(keylen); - var block1 = Buffer.allocUnsafe(salt.length + 4); - salt.copy(block1, 0, 0, salt.length); - var destPos = 0; - var hLen = sizes[digest]; - var l = Math.ceil(keylen / hLen); + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$5$1); + var t = a.mul(b); + var c = t.maskn((this || _global$5$1).shift).mul((this || _global$5$1).minv).imaskn((this || _global$5$1).shift).mul((this || _global$5$1).m); + var u = t.isub(c).iushrn((this || _global$5$1).shift); + var res = u; - for (var i = 1; i <= l; i++) { - block1.writeUInt32BE(i, salt.length); - var T = hmac.run(block1, hmac.ipad1); - var U = T; + if (u.cmp((this || _global$5$1).m) >= 0) { + res = u.isub((this || _global$5$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$5$1).m); + } - for (var j = 1; j < iterations; j++) { - U = hmac.run(U, hmac.ipad2); + return res._forceRed(this || _global$5$1); + }; - for (var k = 0; k < hLen; k++) T[k] ^= U[k]; - } + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$5$1).m).mul((this || _global$5$1).r2)); + return res._forceRed(this || _global$5$1); + }; + })(module$2$1, exports$x$1); - T.copy(DK, destPos); - destPos += hLen; - } + return module$2$1.exports; +} - return DK; +var exports$w$1 = {}, + _dewExec$w$1 = false; +function dew$w$1() { + if (_dewExec$w$1) return exports$w$1; + _dewExec$w$1 = true; + var process = T$9; + var buffer = e$1$1$1; + var Buffer = buffer.Buffer; + var safer = {}; + var key; + + for (key in buffer) { + if (!buffer.hasOwnProperty(key)) continue; + if (key === "SlowBuffer" || key === "Buffer") continue; + safer[key] = buffer[key]; } - exports$1y = pbkdf2; - return exports$1y; -} - -var exports$1x = {}, - _dewExec$1w = false; + var Safer = safer.Buffer = {}; -var _global$l = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + for (key in Buffer) { + if (!Buffer.hasOwnProperty(key)) continue; + if (key === "allocUnsafe" || key === "allocUnsafeSlow") continue; + Safer[key] = Buffer[key]; + } -function dew$1w() { - if (_dewExec$1w) return exports$1x; - _dewExec$1w = true; + safer.Buffer.prototype = Buffer.prototype; - var Buffer = dew$1T().Buffer; + if (!Safer.from || Safer.from === Uint8Array.from) { + Safer.from = function (value, encodingOrOffset, length) { + if (typeof value === "number") { + throw new TypeError("The \"value\" argument must not be of type number. Received type " + typeof value); + } - var checkParameters = dew$1A(); + if (value && typeof value.length === "undefined") { + throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value); + } - var defaultEncoding = dew$1z(); + return Buffer(value, encodingOrOffset, length); + }; + } - var sync = dew$1x(); + if (!Safer.alloc) { + Safer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("The \"size\" argument must be of type number. Received type " + typeof size); + } - var toBuffer = dew$1y(); + if (size < 0 || size >= 2 * (1 << 30)) { + throw new RangeError("The value \"" + size + "\" is invalid for option \"size\""); + } - var ZERO_BUF; - var subtle = _global$l.crypto && _global$l.crypto.subtle; - var toBrowser = { - sha: "SHA-1", - "sha-1": "SHA-1", - sha1: "SHA-1", - sha256: "SHA-256", - "sha-256": "SHA-256", - sha384: "SHA-384", - "sha-384": "SHA-384", - "sha-512": "SHA-512", - sha512: "SHA-512" - }; - var checks = []; + var buf = Buffer(size); - function checkNative(algo) { - if (_global$l.process && !_global$l.process.browser) { - return Promise.resolve(false); - } + if (!fill || fill.length === 0) { + buf.fill(0); + } else if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } - if (!subtle || !subtle.importKey || !subtle.deriveBits) { - return Promise.resolve(false); - } + return buf; + }; + } - if (checks[algo] !== undefined) { - return checks[algo]; + if (!safer.kStringMaxLength) { + try { + safer.kStringMaxLength = process.binding("buffer").kStringMaxLength; + } catch (e) {// we can't determine kStringMaxLength in environments where process.binding + // is unsupported, so let's not set it } - - ZERO_BUF = ZERO_BUF || Buffer.alloc(8); - var prom = browserPbkdf2(ZERO_BUF, ZERO_BUF, 10, 128, algo).then(function () { - return true; - }).catch(function () { - return false; - }); - checks[algo] = prom; - return prom; } - var nextTick; - - function getNextTick() { - if (nextTick) { - return nextTick; - } + if (!safer.constants) { + safer.constants = { + MAX_LENGTH: safer.kMaxLength + }; - if (_global$l.process && _global$l.process.nextTick) { - nextTick = _global$l.process.nextTick; - } else if (_global$l.queueMicrotask) { - nextTick = _global$l.queueMicrotask; - } else if (_global$l.setImmediate) { - nextTick = _global$l.setImmediate; - } else { - nextTick = _global$l.setTimeout; + if (safer.kStringMaxLength) { + safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength; } - - return nextTick; } - function browserPbkdf2(password, salt, iterations, length, algo) { - return subtle.importKey("raw", password, { - name: "PBKDF2" - }, false, ["deriveBits"]).then(function (key) { - return subtle.deriveBits({ - name: "PBKDF2", - salt: salt, - iterations: iterations, - hash: { - name: algo - } - }, key, length << 3); - }).then(function (res) { - return Buffer.from(res); - }); - } + exports$w$1 = safer; + return exports$w$1; +} - function resolvePromise(promise, callback) { - promise.then(function (out) { - getNextTick()(function () { - callback(null, out); - }); - }, function (e) { - getNextTick()(function () { - callback(e); - }); - }); - } +var exports$v$1 = {}, + _dewExec$v$1 = false; +function dew$v$1() { + if (_dewExec$v$1) return exports$v$1; + _dewExec$v$1 = true; - exports$1x = function (password, salt, iterations, keylen, digest, callback) { - if (typeof digest === "function") { - callback = digest; - digest = undefined; - } + const inherits = dew$f$2(); - digest = digest || "sha1"; - var algo = toBrowser[digest.toLowerCase()]; + function Reporter(options) { + this._reporterState = { + obj: null, + path: [], + options: options || {}, + errors: [] + }; + } - if (!algo || typeof _global$l.Promise !== "function") { - getNextTick()(function () { - var out; + exports$v$1.Reporter = Reporter; - try { - out = sync(password, salt, iterations, keylen, digest); - } catch (e) { - return callback(e); - } + Reporter.prototype.isError = function isError(obj) { + return obj instanceof ReporterError; + }; - callback(null, out); - }); - return; - } + Reporter.prototype.save = function save() { + const state = this._reporterState; + return { + obj: state.obj, + pathLen: state.path.length + }; + }; - checkParameters(iterations, keylen); - password = toBuffer(password, defaultEncoding, "Password"); - salt = toBuffer(salt, defaultEncoding, "Salt"); - if (typeof callback !== "function") throw new Error("No callback provided to pbkdf2"); - resolvePromise(checkNative(algo).then(function (resp) { - if (resp) return browserPbkdf2(password, salt, iterations, keylen, algo); - return sync(password, salt, iterations, keylen, digest); - }), callback); + Reporter.prototype.restore = function restore(data) { + const state = this._reporterState; + state.obj = data.obj; + state.path = state.path.slice(0, data.pathLen); }; - return exports$1x; -} + Reporter.prototype.enterKey = function enterKey(key) { + return this._reporterState.path.push(key); + }; -var exports$1w = {}, - _dewExec$1v = false; -function dew$1v() { - if (_dewExec$1v) return exports$1w; - _dewExec$1v = true; - exports$1w.pbkdf2 = dew$1w(); - exports$1w.pbkdf2Sync = dew$1x(); - return exports$1w; -} + Reporter.prototype.exitKey = function exitKey(index) { + const state = this._reporterState; + state.path = state.path.slice(0, index - 1); + }; -var exports$1v = {}, - _dewExec$1u = false; -function dew$1u() { - if (_dewExec$1u) return exports$1v; - _dewExec$1u = true; + Reporter.prototype.leaveKey = function leaveKey(index, key, value) { + const state = this._reporterState; + this.exitKey(index); + if (state.obj !== null) state.obj[key] = value; + }; - exports$1v.readUInt32BE = function readUInt32BE(bytes, off) { - var res = bytes[0 + off] << 24 | bytes[1 + off] << 16 | bytes[2 + off] << 8 | bytes[3 + off]; - return res >>> 0; + Reporter.prototype.path = function path() { + return this._reporterState.path.join("/"); }; - exports$1v.writeUInt32BE = function writeUInt32BE(bytes, value, off) { - bytes[0 + off] = value >>> 24; - bytes[1 + off] = value >>> 16 & 255; - bytes[2 + off] = value >>> 8 & 255; - bytes[3 + off] = value & 255; + Reporter.prototype.enterObject = function enterObject() { + const state = this._reporterState; + const prev = state.obj; + state.obj = {}; + return prev; }; - exports$1v.ip = function ip(inL, inR, out, off) { - var outL = 0; - var outR = 0; + Reporter.prototype.leaveObject = function leaveObject(prev) { + const state = this._reporterState; + const now = state.obj; + state.obj = prev; + return now; + }; - for (var i = 6; i >= 0; i -= 2) { - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inR >>> j + i & 1; - } + Reporter.prototype.error = function error(msg) { + let err; + const state = this._reporterState; + const inherited = msg instanceof ReporterError; - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inL >>> j + i & 1; - } + if (inherited) { + err = msg; + } else { + err = new ReporterError(state.path.map(function (elem) { + return "[" + JSON.stringify(elem) + "]"; + }).join(""), msg.message || msg, msg.stack); } - for (var i = 6; i >= 0; i -= 2) { - for (var j = 1; j <= 25; j += 8) { - outR <<= 1; - outR |= inR >>> j + i & 1; - } - - for (var j = 1; j <= 25; j += 8) { - outR <<= 1; - outR |= inL >>> j + i & 1; - } - } + if (!state.options.partial) throw err; + if (!inherited) state.errors.push(err); + return err; + }; - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; + Reporter.prototype.wrapResult = function wrapResult(result) { + const state = this._reporterState; + if (!state.options.partial) return result; + return { + result: this.isError(result) ? null : result, + errors: state.errors + }; }; - exports$1v.rip = function rip(inL, inR, out, off) { - var outL = 0; - var outR = 0; + function ReporterError(path, msg) { + this.path = path; + this.rethrow(msg); + } - for (var i = 0; i < 4; i++) { - for (var j = 24; j >= 0; j -= 8) { - outL <<= 1; - outL |= inR >>> j + i & 1; - outL <<= 1; - outL |= inL >>> j + i & 1; - } - } + inherits(ReporterError, Error); - for (var i = 4; i < 8; i++) { - for (var j = 24; j >= 0; j -= 8) { - outR <<= 1; - outR |= inR >>> j + i & 1; - outR <<= 1; - outR |= inL >>> j + i & 1; + ReporterError.prototype.rethrow = function rethrow(msg) { + this.message = msg + " at: " + (this.path || "(shallow)"); + if (Error.captureStackTrace) Error.captureStackTrace(this, ReporterError); + + if (!this.stack) { + try { + // IE only adds stack when thrown + throw new Error(this.message); + } catch (e) { + this.stack = e.stack; } } - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; + return this; }; - exports$1v.pc1 = function pc1(inL, inR, out, off) { - var outL = 0; - var outR = 0; // 7, 15, 23, 31, 39, 47, 55, 63 - // 6, 14, 22, 30, 39, 47, 55, 63 - // 5, 13, 21, 29, 39, 47, 55, 63 - // 4, 12, 20, 28 + return exports$v$1; +} - for (var i = 7; i >= 5; i--) { - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inR >> j + i & 1; - } +var exports$u$1 = {}, + _dewExec$u$1 = false; +function dew$u$1() { + if (_dewExec$u$1) return exports$u$1; + _dewExec$u$1 = true; - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inL >> j + i & 1; - } - } + const inherits = dew$f$2(); - for (var j = 0; j <= 24; j += 8) { - outL <<= 1; - outL |= inR >> j + i & 1; - } // 1, 9, 17, 25, 33, 41, 49, 57 - // 2, 10, 18, 26, 34, 42, 50, 58 - // 3, 11, 19, 27, 35, 43, 51, 59 - // 36, 44, 52, 60 + const Reporter = dew$v$1().Reporter; + const Buffer = dew$w$1().Buffer; - for (var i = 1; i <= 3; i++) { - for (var j = 0; j <= 24; j += 8) { - outR <<= 1; - outR |= inR >> j + i & 1; - } + function DecoderBuffer(base, options) { + Reporter.call(this, options); - for (var j = 0; j <= 24; j += 8) { - outR <<= 1; - outR |= inL >> j + i & 1; - } + if (!Buffer.isBuffer(base)) { + this.error("Input not Buffer"); + return; } - for (var j = 0; j <= 24; j += 8) { - outR <<= 1; - outR |= inL >> j + i & 1; - } + this.base = base; + this.offset = 0; + this.length = base.length; + } - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; - }; + inherits(DecoderBuffer, Reporter); + exports$u$1.DecoderBuffer = DecoderBuffer; - exports$1v.r28shl = function r28shl(num, shift) { - return num << shift & 268435455 | num >>> 28 - shift; - }; + DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) { + if (data instanceof DecoderBuffer) { + return true; + } // Or accept compatible API - var pc2table = [// inL => outL - 14, 11, 17, 4, 27, 23, 25, 0, 13, 22, 7, 18, 5, 9, 16, 24, 2, 20, 12, 21, 1, 8, 15, 26, // inR => outR - 15, 4, 25, 19, 9, 1, 26, 16, 5, 11, 23, 8, 12, 7, 17, 0, 22, 3, 10, 14, 6, 20, 27, 24]; - exports$1v.pc2 = function pc2(inL, inR, out, off) { - var outL = 0; - var outR = 0; - var len = pc2table.length >>> 1; + const isCompatible = typeof data === "object" && Buffer.isBuffer(data.base) && data.constructor.name === "DecoderBuffer" && typeof data.offset === "number" && typeof data.length === "number" && typeof data.save === "function" && typeof data.restore === "function" && typeof data.isEmpty === "function" && typeof data.readUInt8 === "function" && typeof data.skip === "function" && typeof data.raw === "function"; + return isCompatible; + }; - for (var i = 0; i < len; i++) { - outL <<= 1; - outL |= inL >>> pc2table[i] & 1; - } + DecoderBuffer.prototype.save = function save() { + return { + offset: this.offset, + reporter: Reporter.prototype.save.call(this) + }; + }; - for (var i = len; i < pc2table.length; i++) { - outR <<= 1; - outR |= inR >>> pc2table[i] & 1; - } + DecoderBuffer.prototype.restore = function restore(save) { + // Return skipped data + const res = new DecoderBuffer(this.base); + res.offset = save.offset; + res.length = this.offset; + this.offset = save.offset; + Reporter.prototype.restore.call(this, save.reporter); + return res; + }; - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; + DecoderBuffer.prototype.isEmpty = function isEmpty() { + return this.offset === this.length; }; - exports$1v.expand = function expand(r, out, off) { - var outL = 0; - var outR = 0; - outL = (r & 1) << 5 | r >>> 27; + DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) { + if (this.offset + 1 <= this.length) return this.base.readUInt8(this.offset++, true);else return this.error(fail || "DecoderBuffer overrun"); + }; - for (var i = 23; i >= 15; i -= 4) { - outL <<= 6; - outL |= r >>> i & 63; - } + DecoderBuffer.prototype.skip = function skip(bytes, fail) { + if (!(this.offset + bytes <= this.length)) return this.error(fail || "DecoderBuffer overrun"); + const res = new DecoderBuffer(this.base); // Share reporter state - for (var i = 11; i >= 3; i -= 4) { - outR |= r >>> i & 63; - outR <<= 6; - } + res._reporterState = this._reporterState; + res.offset = this.offset; + res.length = this.offset + bytes; + this.offset += bytes; + return res; + }; - outR |= (r & 31) << 1 | r >>> 31; - out[off + 0] = outL >>> 0; - out[off + 1] = outR >>> 0; + DecoderBuffer.prototype.raw = function raw(save) { + return this.base.slice(save ? save.offset : this.offset, this.length); }; - var sTable = [14, 0, 4, 15, 13, 7, 1, 4, 2, 14, 15, 2, 11, 13, 8, 1, 3, 10, 10, 6, 6, 12, 12, 11, 5, 9, 9, 5, 0, 3, 7, 8, 4, 15, 1, 12, 14, 8, 8, 2, 13, 4, 6, 9, 2, 1, 11, 7, 15, 5, 12, 11, 9, 3, 7, 14, 3, 10, 10, 0, 5, 6, 0, 13, 15, 3, 1, 13, 8, 4, 14, 7, 6, 15, 11, 2, 3, 8, 4, 14, 9, 12, 7, 0, 2, 1, 13, 10, 12, 6, 0, 9, 5, 11, 10, 5, 0, 13, 14, 8, 7, 10, 11, 1, 10, 3, 4, 15, 13, 4, 1, 2, 5, 11, 8, 6, 12, 7, 6, 12, 9, 0, 3, 5, 2, 14, 15, 9, 10, 13, 0, 7, 9, 0, 14, 9, 6, 3, 3, 4, 15, 6, 5, 10, 1, 2, 13, 8, 12, 5, 7, 14, 11, 12, 4, 11, 2, 15, 8, 1, 13, 1, 6, 10, 4, 13, 9, 0, 8, 6, 15, 9, 3, 8, 0, 7, 11, 4, 1, 15, 2, 14, 12, 3, 5, 11, 10, 5, 14, 2, 7, 12, 7, 13, 13, 8, 14, 11, 3, 5, 0, 6, 6, 15, 9, 0, 10, 3, 1, 4, 2, 7, 8, 2, 5, 12, 11, 1, 12, 10, 4, 14, 15, 9, 10, 3, 6, 15, 9, 0, 0, 6, 12, 10, 11, 1, 7, 13, 13, 8, 15, 9, 1, 4, 3, 5, 14, 11, 5, 12, 2, 7, 8, 2, 4, 14, 2, 14, 12, 11, 4, 2, 1, 12, 7, 4, 10, 7, 11, 13, 6, 1, 8, 5, 5, 0, 3, 15, 15, 10, 13, 3, 0, 9, 14, 8, 9, 6, 4, 11, 2, 8, 1, 12, 11, 7, 10, 1, 13, 14, 7, 2, 8, 13, 15, 6, 9, 15, 12, 0, 5, 9, 6, 10, 3, 4, 0, 5, 14, 3, 12, 10, 1, 15, 10, 4, 15, 2, 9, 7, 2, 12, 6, 9, 8, 5, 0, 6, 13, 1, 3, 13, 4, 14, 14, 0, 7, 11, 5, 3, 11, 8, 9, 4, 14, 3, 15, 2, 5, 12, 2, 9, 8, 5, 12, 15, 3, 10, 7, 11, 0, 14, 4, 1, 10, 7, 1, 6, 13, 0, 11, 8, 6, 13, 4, 13, 11, 0, 2, 11, 14, 7, 15, 4, 0, 9, 8, 1, 13, 10, 3, 14, 12, 3, 9, 5, 7, 12, 5, 2, 10, 15, 6, 8, 1, 6, 1, 6, 4, 11, 11, 13, 13, 8, 12, 1, 3, 4, 7, 10, 14, 7, 10, 9, 15, 5, 6, 0, 8, 15, 0, 14, 5, 2, 9, 3, 2, 12, 13, 1, 2, 15, 8, 13, 4, 8, 6, 10, 15, 3, 11, 7, 1, 4, 10, 12, 9, 5, 3, 6, 14, 11, 5, 0, 0, 14, 12, 9, 7, 2, 7, 2, 11, 1, 4, 14, 1, 7, 9, 4, 12, 10, 14, 8, 2, 13, 0, 15, 6, 12, 10, 9, 13, 0, 15, 3, 3, 5, 5, 6, 8, 11]; + function EncoderBuffer(value, reporter) { + if (Array.isArray(value)) { + this.length = 0; + this.value = value.map(function (item) { + if (!EncoderBuffer.isEncoderBuffer(item)) item = new EncoderBuffer(item, reporter); + this.length += item.length; + return item; + }, this); + } else if (typeof value === "number") { + if (!(0 <= value && value <= 255)) return reporter.error("non-byte EncoderBuffer value"); + this.value = value; + this.length = 1; + } else if (typeof value === "string") { + this.value = value; + this.length = Buffer.byteLength(value); + } else if (Buffer.isBuffer(value)) { + this.value = value; + this.length = value.length; + } else { + return reporter.error("Unsupported type: " + typeof value); + } + } - exports$1v.substitute = function substitute(inL, inR) { - var out = 0; + exports$u$1.EncoderBuffer = EncoderBuffer; - for (var i = 0; i < 4; i++) { - var b = inL >>> 18 - i * 6 & 63; - var sb = sTable[i * 64 + b]; - out <<= 4; - out |= sb; - } + EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) { + if (data instanceof EncoderBuffer) { + return true; + } // Or accept compatible API - for (var i = 0; i < 4; i++) { - var b = inR >>> 18 - i * 6 & 63; - var sb = sTable[4 * 64 + i * 64 + b]; - out <<= 4; - out |= sb; - } - return out >>> 0; + const isCompatible = typeof data === "object" && data.constructor.name === "EncoderBuffer" && typeof data.length === "number" && typeof data.join === "function"; + return isCompatible; }; - var permuteTable = [16, 25, 12, 11, 3, 20, 4, 15, 31, 17, 9, 6, 27, 14, 1, 22, 30, 24, 8, 18, 0, 5, 29, 23, 13, 19, 2, 26, 10, 21, 28, 7]; - - exports$1v.permute = function permute(num) { - var out = 0; + EncoderBuffer.prototype.join = function join(out, offset) { + if (!out) out = Buffer.alloc(this.length); + if (!offset) offset = 0; + if (this.length === 0) return out; - for (var i = 0; i < permuteTable.length; i++) { - out <<= 1; - out |= num >>> permuteTable[i] & 1; + if (Array.isArray(this.value)) { + this.value.forEach(function (item) { + item.join(out, offset); + offset += item.length; + }); + } else { + if (typeof this.value === "number") out[offset] = this.value;else if (typeof this.value === "string") out.write(this.value, offset);else if (Buffer.isBuffer(this.value)) this.value.copy(out, offset); + offset += this.length; } - return out >>> 0; + return out; }; - exports$1v.padSplit = function padSplit(num, size, group) { - var str = num.toString(2); - - while (str.length < size) str = "0" + str; + return exports$u$1; +} - var out = []; +var exports$t$1 = {}, + _dewExec$t$1 = false; +function dew$t$1() { + if (_dewExec$t$1) return exports$t$1; + _dewExec$t$1 = true; - for (var i = 0; i < size; i += group) out.push(str.slice(i, i + group)); + const Reporter = dew$v$1().Reporter; - return out.join(" "); - }; + const EncoderBuffer = dew$u$1().EncoderBuffer; - return exports$1v; -} + const DecoderBuffer = dew$u$1().DecoderBuffer; -var exports$1u = {}, - _dewExec$1t = false; -function dew$1t() { - if (_dewExec$1t) return exports$1u; - _dewExec$1t = true; - exports$1u = assert; + const assert = dew$1t(); // Supported tags - function assert(val, msg) { - if (!val) throw new Error(msg || "Assertion failed"); - } - assert.equal = function assertEqual(l, r, msg) { - if (l != r) throw new Error(msg || "Assertion failed: " + l + " != " + r); - }; + const tags = ["seq", "seqof", "set", "setof", "objid", "bool", "gentime", "utctime", "null_", "enum", "int", "objDesc", "bitstr", "bmpstr", "charstr", "genstr", "graphstr", "ia5str", "iso646str", "numstr", "octstr", "printstr", "t61str", "unistr", "utf8str", "videostr"]; // Public methods list - return exports$1u; -} + const methods = ["key", "obj", "use", "optional", "explicit", "implicit", "def", "choice", "any", "contains"].concat(tags); // Overrided methods list -var exports$1t = {}, - _dewExec$1s = false; -function dew$1s() { - if (_dewExec$1s) return exports$1t; - _dewExec$1s = true; + const overrided = ["_peekTag", "_decodeTag", "_use", "_decodeStr", "_decodeObjid", "_decodeTime", "_decodeNull", "_decodeInt", "_decodeBool", "_decodeList", "_encodeComposite", "_encodeStr", "_encodeObjid", "_encodeTime", "_encodeNull", "_encodeInt", "_encodeBool"]; - var assert = dew$1t(); + function Node(enc, parent, name) { + const state = {}; + this._baseState = state; + state.name = name; + state.enc = enc; + state.parent = parent || null; + state.children = null; // State - function Cipher(options) { - this.options = options; - this.type = this.options.type; - this.blockSize = 8; + state.tag = null; + state.args = null; + state.reverseArgs = null; + state.choice = null; + state.optional = false; + state.any = false; + state.obj = false; + state.use = null; + state.useDecoder = null; + state.key = null; + state["default"] = null; + state.explicit = null; + state.implicit = null; + state.contains = null; // Should create new instance on each method - this._init(); + if (!state.parent) { + state.children = []; - this.buffer = new Array(this.blockSize); - this.bufferOff = 0; + this._wrap(); + } } - exports$1t = Cipher; + exports$t$1 = Node; + const stateProps = ["enc", "parent", "children", "tag", "args", "reverseArgs", "choice", "optional", "any", "obj", "use", "alteredUse", "key", "default", "explicit", "implicit", "contains"]; - Cipher.prototype._init = function _init() {// Might be overrided + Node.prototype.clone = function clone() { + const state = this._baseState; + const cstate = {}; + stateProps.forEach(function (prop) { + cstate[prop] = state[prop]; + }); + const res = new this.constructor(cstate.parent); + res._baseState = cstate; + return res; }; - Cipher.prototype.update = function update(data) { - if (data.length === 0) return []; - if (this.type === "decrypt") return this._updateDecrypt(data);else return this._updateEncrypt(data); + Node.prototype._wrap = function wrap() { + const state = this._baseState; + methods.forEach(function (method) { + this[method] = function _wrappedMethod() { + const clone = new this.constructor(this); + state.children.push(clone); + return clone[method].apply(clone, arguments); + }; + }, this); }; - Cipher.prototype._buffer = function _buffer(data, off) { - // Append data to buffer - var min = Math.min(this.buffer.length - this.bufferOff, data.length - off); - - for (var i = 0; i < min; i++) this.buffer[this.bufferOff + i] = data[off + i]; - - this.bufferOff += min; // Shift next + Node.prototype._init = function init(body) { + const state = this._baseState; + assert(state.parent === null); + body.call(this); // Filter children - return min; + state.children = state.children.filter(function (child) { + return child._baseState.parent === this; + }, this); + assert.equal(state.children.length, 1, "Root node can have only one child"); }; - Cipher.prototype._flushBuffer = function _flushBuffer(out, off) { - this._update(this.buffer, 0, out, off); + Node.prototype._useArgs = function useArgs(args) { + const state = this._baseState; // Filter children and args - this.bufferOff = 0; - return this.blockSize; - }; + const children = args.filter(function (arg) { + return arg instanceof this.constructor; + }, this); + args = args.filter(function (arg) { + return !(arg instanceof this.constructor); + }, this); - Cipher.prototype._updateEncrypt = function _updateEncrypt(data) { - var inputOff = 0; - var outputOff = 0; - var count = (this.bufferOff + data.length) / this.blockSize | 0; - var out = new Array(count * this.blockSize); + if (children.length !== 0) { + assert(state.children === null); + state.children = children; // Replace parent to maintain backward link - if (this.bufferOff !== 0) { - inputOff += this._buffer(data, inputOff); - if (this.bufferOff === this.buffer.length) outputOff += this._flushBuffer(out, outputOff); - } // Write blocks + children.forEach(function (child) { + child._baseState.parent = this; + }, this); + } + if (args.length !== 0) { + assert(state.args === null); + state.args = args; + state.reverseArgs = args.map(function (arg) { + if (typeof arg !== "object" || arg.constructor !== Object) return arg; + const res = {}; + Object.keys(arg).forEach(function (key) { + if (key == (key | 0)) key |= 0; + const value = arg[key]; + res[value] = key; + }); + return res; + }); + } + }; // + // Overrided methods + // - var max = data.length - (data.length - inputOff) % this.blockSize; - for (; inputOff < max; inputOff += this.blockSize) { - this._update(data, inputOff, out, outputOff); + overrided.forEach(function (method) { + Node.prototype[method] = function _overrided() { + const state = this._baseState; + throw new Error(method + " not implemented for encoding: " + state.enc); + }; + }); // + // Public methods + // - outputOff += this.blockSize; - } // Queue rest + tags.forEach(function (tag) { + Node.prototype[tag] = function _tagMethod() { + const state = this._baseState; + const args = Array.prototype.slice.call(arguments); + assert(state.tag === null); + state.tag = tag; + this._useArgs(args); - for (; inputOff < data.length; inputOff++, this.bufferOff++) this.buffer[this.bufferOff] = data[inputOff]; + return this; + }; + }); - return out; + Node.prototype.use = function use(item) { + assert(item); + const state = this._baseState; + assert(state.use === null); + state.use = item; + return this; }; - Cipher.prototype._updateDecrypt = function _updateDecrypt(data) { - var inputOff = 0; - var outputOff = 0; - var count = Math.ceil((this.bufferOff + data.length) / this.blockSize) - 1; - var out = new Array(count * this.blockSize); // TODO(indutny): optimize it, this is far from optimal - - for (; count > 0; count--) { - inputOff += this._buffer(data, inputOff); - outputOff += this._flushBuffer(out, outputOff); - } // Buffer rest of the input + Node.prototype.optional = function optional() { + const state = this._baseState; + state.optional = true; + return this; + }; + Node.prototype.def = function def(val) { + const state = this._baseState; + assert(state["default"] === null); + state["default"] = val; + state.optional = true; + return this; + }; - inputOff += this._buffer(data, inputOff); - return out; + Node.prototype.explicit = function explicit(num) { + const state = this._baseState; + assert(state.explicit === null && state.implicit === null); + state.explicit = num; + return this; }; - Cipher.prototype.final = function final(buffer) { - var first; - if (buffer) first = this.update(buffer); - var last; - if (this.type === "encrypt") last = this._finalEncrypt();else last = this._finalDecrypt(); - if (first) return first.concat(last);else return last; + Node.prototype.implicit = function implicit(num) { + const state = this._baseState; + assert(state.explicit === null && state.implicit === null); + state.implicit = num; + return this; }; - Cipher.prototype._pad = function _pad(buffer, off) { - if (off === 0) return false; + Node.prototype.obj = function obj() { + const state = this._baseState; + const args = Array.prototype.slice.call(arguments); + state.obj = true; + if (args.length !== 0) this._useArgs(args); + return this; + }; - while (off < buffer.length) buffer[off++] = 0; + Node.prototype.key = function key(newKey) { + const state = this._baseState; + assert(state.key === null); + state.key = newKey; + return this; + }; - return true; + Node.prototype.any = function any() { + const state = this._baseState; + state.any = true; + return this; }; - Cipher.prototype._finalEncrypt = function _finalEncrypt() { - if (!this._pad(this.buffer, this.bufferOff)) return []; - var out = new Array(this.blockSize); + Node.prototype.choice = function choice(obj) { + const state = this._baseState; + assert(state.choice === null); + state.choice = obj; - this._update(this.buffer, 0, out, 0); + this._useArgs(Object.keys(obj).map(function (key) { + return obj[key]; + })); - return out; + return this; }; - Cipher.prototype._unpad = function _unpad(buffer) { - return buffer; - }; + Node.prototype.contains = function contains(item) { + const state = this._baseState; + assert(state.use === null); + state.contains = item; + return this; + }; // + // Decoding + // - Cipher.prototype._finalDecrypt = function _finalDecrypt() { - assert.equal(this.bufferOff, this.blockSize, "Not enough data to decrypt"); - var out = new Array(this.blockSize); - this._flushBuffer(out, 0); + Node.prototype._decode = function decode(input, options) { + const state = this._baseState; // Decode root node - return this._unpad(out); - }; + if (state.parent === null) return input.wrapResult(state.children[0]._decode(input, options)); + let result = state["default"]; + let present = true; + let prevKey = null; + if (state.key !== null) prevKey = input.enterKey(state.key); // Check if tag is there - return exports$1t; -} + if (state.optional) { + let tag = null; + if (state.explicit !== null) tag = state.explicit;else if (state.implicit !== null) tag = state.implicit;else if (state.tag !== null) tag = state.tag; -var exports$1s = {}, - _dewExec$1r = false; -function dew$1r() { - if (_dewExec$1r) return exports$1s; - _dewExec$1r = true; + if (tag === null && !state.any) { + // Trial and Error + const save = input.save(); - var assert = dew$1t(); + try { + if (state.choice === null) this._decodeGeneric(state.tag, input, options);else this._decodeChoice(input, options); + present = true; + } catch (e) { + present = false; + } - var inherits = dew$f$2(); + input.restore(save); + } else { + present = this._peekTag(input, tag, state.any); + if (input.isError(present)) return present; + } + } // Push object on stack - var utils = dew$1u(); - var Cipher = dew$1s(); + let prevObj; + if (state.obj && present) prevObj = input.enterObject(); - function DESState() { - this.tmp = new Array(2); - this.keys = null; - } + if (present) { + // Unwrap explicit values + if (state.explicit !== null) { + const explicit = this._decodeTag(input, state.explicit); - function DES(options) { - Cipher.call(this, options); - var state = new DESState(); - this._desState = state; - this.deriveKeys(state, options.key); - } + if (input.isError(explicit)) return explicit; + input = explicit; + } - inherits(DES, Cipher); - exports$1s = DES; + const start = input.offset; // Unwrap implicit and normal values - DES.create = function create(options) { - return new DES(options); - }; + if (state.use === null && state.choice === null) { + let save; + if (state.any) save = input.save(); - var shiftTable = [1, 1, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 1]; + const body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any); - DES.prototype.deriveKeys = function deriveKeys(state, key) { - state.keys = new Array(16 * 2); - assert.equal(key.length, this.blockSize, "Invalid key length"); - var kL = utils.readUInt32BE(key, 0); - var kR = utils.readUInt32BE(key, 4); - utils.pc1(kL, kR, state.tmp, 0); - kL = state.tmp[0]; - kR = state.tmp[1]; + if (input.isError(body)) return body; + if (state.any) result = input.raw(save);else input = body; + } - for (var i = 0; i < state.keys.length; i += 2) { - var shift = shiftTable[i >>> 1]; - kL = utils.r28shl(kL, shift); - kR = utils.r28shl(kR, shift); - utils.pc2(kL, kR, state.keys, i); - } - }; + if (options && options.track && state.tag !== null) options.track(input.path(), start, input.length, "tagged"); + if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, "content"); // Select proper method for tag - DES.prototype._update = function _update(inp, inOff, out, outOff) { - var state = this._desState; - var l = utils.readUInt32BE(inp, inOff); - var r = utils.readUInt32BE(inp, inOff + 4); // Initial Permutation + if (state.any) ; else if (state.choice === null) { + result = this._decodeGeneric(state.tag, input, options); + } else { + result = this._decodeChoice(input, options); + } - utils.ip(l, r, state.tmp, 0); - l = state.tmp[0]; - r = state.tmp[1]; - if (this.type === "encrypt") this._encrypt(state, l, r, state.tmp, 0);else this._decrypt(state, l, r, state.tmp, 0); - l = state.tmp[0]; - r = state.tmp[1]; - utils.writeUInt32BE(out, l, outOff); - utils.writeUInt32BE(out, r, outOff + 4); - }; + if (input.isError(result)) return result; // Decode children - DES.prototype._pad = function _pad(buffer, off) { - var value = buffer.length - off; + if (!state.any && state.choice === null && state.children !== null) { + state.children.forEach(function decodeChildren(child) { + // NOTE: We are ignoring errors here, to let parser continue with other + // parts of encoded data + child._decode(input, options); + }); + } // Decode contained/encoded by schema, only in bit or octet strings - for (var i = off; i < buffer.length; i++) buffer[i] = value; - return true; - }; + if (state.contains && (state.tag === "octstr" || state.tag === "bitstr")) { + const data = new DecoderBuffer(result); + result = this._getUse(state.contains, input._reporterState.obj)._decode(data, options); + } + } // Pop object - DES.prototype._unpad = function _unpad(buffer) { - var pad = buffer[buffer.length - 1]; - for (var i = buffer.length - pad; i < buffer.length; i++) assert.equal(buffer[i], pad); + if (state.obj && present) result = input.leaveObject(prevObj); // Set key - return buffer.slice(0, buffer.length - pad); + if (state.key !== null && (result !== null || present === true)) input.leaveKey(prevKey, state.key, result);else if (prevKey !== null) input.exitKey(prevKey); + return result; }; - DES.prototype._encrypt = function _encrypt(state, lStart, rStart, out, off) { - var l = lStart; - var r = rStart; // Apply f() x16 times + Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) { + const state = this._baseState; + if (tag === "seq" || tag === "set") return null; + if (tag === "seqof" || tag === "setof") return this._decodeList(input, tag, state.args[0], options);else if (/str$/.test(tag)) return this._decodeStr(input, tag, options);else if (tag === "objid" && state.args) return this._decodeObjid(input, state.args[0], state.args[1], options);else if (tag === "objid") return this._decodeObjid(input, null, null, options);else if (tag === "gentime" || tag === "utctime") return this._decodeTime(input, tag, options);else if (tag === "null_") return this._decodeNull(input, options);else if (tag === "bool") return this._decodeBool(input, options);else if (tag === "objDesc") return this._decodeStr(input, tag, options);else if (tag === "int" || tag === "enum") return this._decodeInt(input, state.args && state.args[0], options); - for (var i = 0; i < state.keys.length; i += 2) { - var keyL = state.keys[i]; - var keyR = state.keys[i + 1]; // f(r, k) + if (state.use !== null) { + return this._getUse(state.use, input._reporterState.obj)._decode(input, options); + } else { + return input.error("unknown tag: " + tag); + } + }; - utils.expand(r, state.tmp, 0); - keyL ^= state.tmp[0]; - keyR ^= state.tmp[1]; - var s = utils.substitute(keyL, keyR); - var f = utils.permute(s); - var t = r; - r = (l ^ f) >>> 0; - l = t; - } // Reverse Initial Permutation + Node.prototype._getUse = function _getUse(entity, obj) { + const state = this._baseState; // Create altered use decoder if implicit is set + + state.useDecoder = this._use(entity, obj); + assert(state.useDecoder._baseState.parent === null); + state.useDecoder = state.useDecoder._baseState.children[0]; + if (state.implicit !== state.useDecoder._baseState.implicit) { + state.useDecoder = state.useDecoder.clone(); + state.useDecoder._baseState.implicit = state.implicit; + } - utils.rip(r, l, out, off); + return state.useDecoder; }; - DES.prototype._decrypt = function _decrypt(state, lStart, rStart, out, off) { - var l = rStart; - var r = lStart; // Apply f() x16 times + Node.prototype._decodeChoice = function decodeChoice(input, options) { + const state = this._baseState; + let result = null; + let match = false; + Object.keys(state.choice).some(function (key) { + const save = input.save(); + const node = state.choice[key]; - for (var i = state.keys.length - 2; i >= 0; i -= 2) { - var keyL = state.keys[i]; - var keyR = state.keys[i + 1]; // f(r, k) + try { + const value = node._decode(input, options); - utils.expand(l, state.tmp, 0); - keyL ^= state.tmp[0]; - keyR ^= state.tmp[1]; - var s = utils.substitute(keyL, keyR); - var f = utils.permute(s); - var t = l; - l = (r ^ f) >>> 0; - r = t; - } // Reverse Initial Permutation + if (input.isError(value)) return false; + result = { + type: key, + value: value + }; + match = true; + } catch (e) { + input.restore(save); + return false; + } + + return true; + }, this); + if (!match) return input.error("Choice not matched"); + return result; + }; // + // Encoding + // + + + Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) { + return new EncoderBuffer(data, this.reporter); + }; + Node.prototype._encode = function encode(data, reporter, parent) { + const state = this._baseState; + if (state["default"] !== null && state["default"] === data) return; - utils.rip(l, r, out, off); - }; + const result = this._encodeValue(data, reporter, parent); - return exports$1s; -} + if (result === undefined) return; + if (this._skipDefault(result, reporter, parent)) return; + return result; + }; -var exports$1r = {}, - _dewExec$1q = false; -function dew$1q() { - if (_dewExec$1q) return exports$1r; - _dewExec$1q = true; + Node.prototype._encodeValue = function encode(data, reporter, parent) { + const state = this._baseState; // Decode root node - var assert = dew$1t(); + if (state.parent === null) return state.children[0]._encode(data, reporter || new Reporter()); + let result = null; // Set reporter to share it with a child class - var inherits = dew$f$2(); + this.reporter = reporter; // Check if data is there - var proto = {}; + if (state.optional && data === undefined) { + if (state["default"] !== null) data = state["default"];else return; + } // Encode children first - function CBCState(iv) { - assert.equal(iv.length, 8, "Invalid IV length"); - this.iv = new Array(8); - for (var i = 0; i < this.iv.length; i++) this.iv[i] = iv[i]; - } + let content = null; + let primitive = false; - function instantiate(Base) { - function CBC(options) { - Base.call(this, options); + if (state.any) { + // Anything that was given is translated to buffer + result = this._createEncoderBuffer(data); + } else if (state.choice) { + result = this._encodeChoice(data, reporter); + } else if (state.contains) { + content = this._getUse(state.contains, parent)._encode(data, reporter); + primitive = true; + } else if (state.children) { + content = state.children.map(function (child) { + if (child._baseState.tag === "null_") return child._encode(null, reporter, data); + if (child._baseState.key === null) return reporter.error("Child should have a key"); + const prevKey = reporter.enterKey(child._baseState.key); + if (typeof data !== "object") return reporter.error("Child expected, but input is not object"); - this._cbcInit(); - } + const res = child._encode(data[child._baseState.key], reporter, data); - inherits(CBC, Base); - var keys = Object.keys(proto); + reporter.leaveKey(prevKey); + return res; + }, this).filter(function (child) { + return child; + }); + content = this._createEncoderBuffer(content); + } else { + if (state.tag === "seqof" || state.tag === "setof") { + // TODO(indutny): this should be thrown on DSL level + if (!(state.args && state.args.length === 1)) return reporter.error("Too many args for : " + state.tag); + if (!Array.isArray(data)) return reporter.error("seqof/setof, but data is not Array"); + const child = this.clone(); + child._baseState.implicit = null; + content = this._createEncoderBuffer(data.map(function (item) { + const state = this._baseState; + return this._getUse(state.args[0], data)._encode(item, reporter); + }, child)); + } else if (state.use !== null) { + result = this._getUse(state.use, parent)._encode(data, reporter); + } else { + content = this._encodePrimitive(state.tag, data); + primitive = true; + } + } // Encode data itself - for (var i = 0; i < keys.length; i++) { - var key = keys[i]; - CBC.prototype[key] = proto[key]; - } - CBC.create = function create(options) { - return new CBC(options); - }; + if (!state.any && state.choice === null) { + const tag = state.implicit !== null ? state.implicit : state.tag; + const cls = state.implicit === null ? "universal" : "context"; - return CBC; - } + if (tag === null) { + if (state.use === null) reporter.error("Tag could be omitted only for .use()"); + } else { + if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content); + } + } // Wrap in explicit - exports$1r.instantiate = instantiate; - proto._cbcInit = function _cbcInit() { - var state = new CBCState(this.options.iv); - this._cbcState = state; + if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, "context", result); + return result; }; - proto._update = function _update(inp, inOff, out, outOff) { - var state = this._cbcState; - var superProto = this.constructor.super_.prototype; - var iv = state.iv; + Node.prototype._encodeChoice = function encodeChoice(data, reporter) { + const state = this._baseState; + const node = state.choice[data.type]; - if (this.type === "encrypt") { - for (var i = 0; i < this.blockSize; i++) iv[i] ^= inp[inOff + i]; + if (!node) { + assert(false, data.type + " not found in " + JSON.stringify(Object.keys(state.choice))); + } - superProto._update.call(this, iv, 0, out, outOff); + return node._encode(data.value, reporter); + }; - for (var i = 0; i < this.blockSize; i++) iv[i] = out[outOff + i]; - } else { - superProto._update.call(this, inp, inOff, out, outOff); + Node.prototype._encodePrimitive = function encodePrimitive(tag, data) { + const state = this._baseState; + if (/str$/.test(tag)) return this._encodeStr(data, tag);else if (tag === "objid" && state.args) return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);else if (tag === "objid") return this._encodeObjid(data, null, null);else if (tag === "gentime" || tag === "utctime") return this._encodeTime(data, tag);else if (tag === "null_") return this._encodeNull();else if (tag === "int" || tag === "enum") return this._encodeInt(data, state.args && state.reverseArgs[0]);else if (tag === "bool") return this._encodeBool(data);else if (tag === "objDesc") return this._encodeStr(data, tag);else throw new Error("Unsupported tag: " + tag); + }; - for (var i = 0; i < this.blockSize; i++) out[outOff + i] ^= iv[i]; + Node.prototype._isNumstr = function isNumstr(str) { + return /^[0-9 ]*$/.test(str); + }; - for (var i = 0; i < this.blockSize; i++) iv[i] = inp[inOff + i]; - } + Node.prototype._isPrintstr = function isPrintstr(str) { + return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str); }; - return exports$1r; + return exports$t$1; } -var exports$1q = {}, - _dewExec$1p = false; -function dew$1p() { - if (_dewExec$1p) return exports$1q; - _dewExec$1p = true; +var exports$s$1 = {}, + _dewExec$s$1 = false; +function dew$s$1() { + if (_dewExec$s$1) return exports$s$1; + _dewExec$s$1 = true; - var assert = dew$1t(); + // Helper + function reverse(map) { + const res = {}; + Object.keys(map).forEach(function (key) { + // Convert key to integer if it is stringified + if ((key | 0) == key) key = key | 0; + const value = map[key]; + res[value] = key; + }); + return res; + } - var inherits = dew$f$2(); + exports$s$1.tagClass = { + 0: "universal", + 1: "application", + 2: "context", + 3: "private" + }; + exports$s$1.tagClassByName = reverse(exports$s$1.tagClass); + exports$s$1.tag = { + 0: "end", + 1: "bool", + 2: "int", + 3: "bitstr", + 4: "octstr", + 5: "null_", + 6: "objid", + 7: "objDesc", + 8: "external", + 9: "real", + 10: "enum", + 11: "embed", + 12: "utf8str", + 13: "relativeOid", + 16: "seq", + 17: "set", + 18: "numstr", + 19: "printstr", + 20: "t61str", + 21: "videostr", + 22: "ia5str", + 23: "utctime", + 24: "gentime", + 25: "graphstr", + 26: "iso646str", + 27: "genstr", + 28: "unistr", + 29: "charstr", + 30: "bmpstr" + }; + exports$s$1.tagByName = reverse(exports$s$1.tag); + return exports$s$1; +} - var Cipher = dew$1s(); +var exports$r$1 = {}, + _dewExec$r$1 = false; +function dew$r$1() { + if (_dewExec$r$1) return exports$r$1; + _dewExec$r$1 = true; - var DES = dew$1r(); + const inherits = dew$f$2(); - function EDEState(type, key) { - assert.equal(key.length, 24, "Invalid key length"); - var k1 = key.slice(0, 8); - var k2 = key.slice(8, 16); - var k3 = key.slice(16, 24); + const Buffer = dew$w$1().Buffer; - if (type === "encrypt") { - this.ciphers = [DES.create({ - type: "encrypt", - key: k1 - }), DES.create({ - type: "decrypt", - key: k2 - }), DES.create({ - type: "encrypt", - key: k3 - })]; - } else { - this.ciphers = [DES.create({ - type: "decrypt", - key: k3 - }), DES.create({ - type: "encrypt", - key: k2 - }), DES.create({ - type: "decrypt", - key: k1 - })]; - } - } + const Node = dew$t$1(); // Import DER constants - function EDE(options) { - Cipher.call(this, options); - var state = new EDEState(this.type, this.options.key); - this._edeState = state; - } - inherits(EDE, Cipher); - exports$1q = EDE; + const der = dew$s$1(); - EDE.create = function create(options) { - return new EDE(options); - }; + function DEREncoder(entity) { + this.enc = "der"; + this.name = entity.name; + this.entity = entity; // Construct base tree - EDE.prototype._update = function _update(inp, inOff, out, outOff) { - var state = this._edeState; + this.tree = new DERNode(); - state.ciphers[0]._update(inp, inOff, out, outOff); + this.tree._init(entity.body); + } - state.ciphers[1]._update(out, outOff, out, outOff); + exports$r$1 = DEREncoder; - state.ciphers[2]._update(out, outOff, out, outOff); - }; + DEREncoder.prototype.encode = function encode(data, reporter) { + return this.tree._encode(data, reporter).join(); + }; // Tree methods - EDE.prototype._pad = DES.prototype._pad; - EDE.prototype._unpad = DES.prototype._unpad; - return exports$1q; -} -var exports$1p = {}, - _dewExec$1o = false; -function dew$1o() { - if (_dewExec$1o) return exports$1p; - _dewExec$1o = true; - exports$1p.utils = dew$1u(); - exports$1p.Cipher = dew$1s(); - exports$1p.DES = dew$1r(); - exports$1p.CBC = dew$1q(); - exports$1p.EDE = dew$1p(); - return exports$1p; -} + function DERNode(parent) { + Node.call(this, "der", parent); + } -var exports$1o = {}, - _dewExec$1n = false; + inherits(DERNode, Node); -var _global$k = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) { + const encodedTag = encodeTag(tag, primitive, cls, this.reporter); // Short form -function dew$1n() { - if (_dewExec$1n) return exports$1o; - _dewExec$1n = true; + if (content.length < 128) { + const header = Buffer.alloc(2); + header[0] = encodedTag; + header[1] = content.length; + return this._createEncoderBuffer([header, content]); + } // Long form + // Count octets required to store length - var CipherBase = dew$1G(); - var des = dew$1o(); + let lenOctets = 1; - var inherits = dew$f$2(); + for (let i = content.length; i >= 256; i >>= 8) lenOctets++; - var Buffer = dew$1T().Buffer; + const header = Buffer.alloc(1 + 1 + lenOctets); + header[0] = encodedTag; + header[1] = 128 | lenOctets; - var modes = { - "des-ede3-cbc": des.CBC.instantiate(des.EDE), - "des-ede3": des.EDE, - "des-ede-cbc": des.CBC.instantiate(des.EDE), - "des-ede": des.EDE, - "des-cbc": des.CBC.instantiate(des.DES), - "des-ecb": des.DES + for (let i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8) header[i] = j & 255; + + return this._createEncoderBuffer([header, content]); }; - modes.des = modes["des-cbc"]; - modes.des3 = modes["des-ede3-cbc"]; - exports$1o = DES; - inherits(DES, CipherBase); - function DES(opts) { - CipherBase.call(this || _global$k); - var modeName = opts.mode.toLowerCase(); - var mode = modes[modeName]; - var type; + DERNode.prototype._encodeStr = function encodeStr(str, tag) { + if (tag === "bitstr") { + return this._createEncoderBuffer([str.unused | 0, str.data]); + } else if (tag === "bmpstr") { + const buf = Buffer.alloc(str.length * 2); - if (opts.decrypt) { - type = "decrypt"; - } else { - type = "encrypt"; - } + for (let i = 0; i < str.length; i++) { + buf.writeUInt16BE(str.charCodeAt(i), i * 2); + } - var key = opts.key; + return this._createEncoderBuffer(buf); + } else if (tag === "numstr") { + if (!this._isNumstr(str)) { + return this.reporter.error("Encoding of string type: numstr supports " + "only digits and space"); + } - if (!Buffer.isBuffer(key)) { - key = Buffer.from(key); - } + return this._createEncoderBuffer(str); + } else if (tag === "printstr") { + if (!this._isPrintstr(str)) { + return this.reporter.error("Encoding of string type: printstr supports " + "only latin upper and lower case letters, " + "digits, space, apostrophe, left and rigth " + "parenthesis, plus sign, comma, hyphen, " + "dot, slash, colon, equal sign, " + "question mark"); + } - if (modeName === "des-ede" || modeName === "des-ede-cbc") { - key = Buffer.concat([key, key.slice(0, 8)]); + return this._createEncoderBuffer(str); + } else if (/str$/.test(tag)) { + return this._createEncoderBuffer(str); + } else if (tag === "objDesc") { + return this._createEncoderBuffer(str); + } else { + return this.reporter.error("Encoding of string type: " + tag + " unsupported"); } + }; - var iv = opts.iv; - - if (!Buffer.isBuffer(iv)) { - iv = Buffer.from(iv); - } + DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) { + if (typeof id === "string") { + if (!values) return this.reporter.error("string objid given, but no values map found"); + if (!values.hasOwnProperty(id)) return this.reporter.error("objid not found in values map"); + id = values[id].split(/[\s.]+/g); - (this || _global$k)._des = mode.create({ - key: key, - iv: iv, - type: type - }); - } + for (let i = 0; i < id.length; i++) id[i] |= 0; + } else if (Array.isArray(id)) { + id = id.slice(); - DES.prototype._update = function (data) { - return Buffer.from((this || _global$k)._des.update(data)); - }; + for (let i = 0; i < id.length; i++) id[i] |= 0; + } - DES.prototype._final = function () { - return Buffer.from((this || _global$k)._des.final()); - }; + if (!Array.isArray(id)) { + return this.reporter.error("objid() should be either array or string, " + "got: " + JSON.stringify(id)); + } - return exports$1o; -} + if (!relative) { + if (id[1] >= 40) return this.reporter.error("Second objid identifier OOB"); + id.splice(0, 2, id[0] * 40 + id[1]); + } // Count number of octets -var exports$1n = {}, - _dewExec$1m = false; -function dew$1m() { - if (_dewExec$1m) return exports$1n; - _dewExec$1m = true; - exports$1n.encrypt = function (self, block) { - return self._cipher.encryptBlock(block); - }; + let size = 0; - exports$1n.decrypt = function (self, block) { - return self._cipher.decryptBlock(block); - }; + for (let i = 0; i < id.length; i++) { + let ident = id[i]; - return exports$1n; -} + for (size++; ident >= 128; ident >>= 7) size++; + } -var exports$1m = {}, - _dewExec$1l = false; -function dew$1l() { - if (_dewExec$1l) return exports$1m; - _dewExec$1l = true; - var Buffer = e$1$1$1.Buffer; + const objid = Buffer.alloc(size); + let offset = objid.length - 1; - exports$1m = function xor(a, b) { - var length = Math.min(a.length, b.length); - var buffer = new Buffer(length); + for (let i = id.length - 1; i >= 0; i--) { + let ident = id[i]; + objid[offset--] = ident & 127; - for (var i = 0; i < length; ++i) { - buffer[i] = a[i] ^ b[i]; + while ((ident >>= 7) > 0) objid[offset--] = 128 | ident & 127; } - return buffer; + return this._createEncoderBuffer(objid); }; - return exports$1m; -} + function two(num) { + if (num < 10) return "0" + num;else return num; + } -var exports$1l = {}, - _dewExec$1k = false; -function dew$1k() { - if (_dewExec$1k) return exports$1l; - _dewExec$1k = true; + DERNode.prototype._encodeTime = function encodeTime(time, tag) { + let str; + const date = new Date(time); - var xor = dew$1l(); + if (tag === "gentime") { + str = [two(date.getUTCFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), "Z"].join(""); + } else if (tag === "utctime") { + str = [two(date.getUTCFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), "Z"].join(""); + } else { + this.reporter.error("Encoding " + tag + " time is not supported yet"); + } - exports$1l.encrypt = function (self, block) { - var data = xor(block, self._prev); - self._prev = self._cipher.encryptBlock(data); - return self._prev; + return this._encodeStr(str, "octstr"); }; - exports$1l.decrypt = function (self, block) { - var pad = self._prev; - self._prev = block; - - var out = self._cipher.decryptBlock(block); - - return xor(out, pad); + DERNode.prototype._encodeNull = function encodeNull() { + return this._createEncoderBuffer(""); }; - return exports$1l; -} - -var exports$1k = {}, - _dewExec$1j = false; -function dew$1j() { - if (_dewExec$1j) return exports$1k; - _dewExec$1j = true; + DERNode.prototype._encodeInt = function encodeInt(num, values) { + if (typeof num === "string") { + if (!values) return this.reporter.error("String int or enum given, but no values map"); - var Buffer = dew$1T().Buffer; + if (!values.hasOwnProperty(num)) { + return this.reporter.error("Values map doesn't contain: " + JSON.stringify(num)); + } - var xor = dew$1l(); + num = values[num]; + } // Bignum, assume big endian - function encryptStart(self, data, decrypt) { - var len = data.length; - var out = xor(data, self._cache); - self._cache = self._cache.slice(len); - self._prev = Buffer.concat([self._prev, decrypt ? data : out]); - return out; - } - exports$1k.encrypt = function (self, data, decrypt) { - var out = Buffer.allocUnsafe(0); - var len; + if (typeof num !== "number" && !Buffer.isBuffer(num)) { + const numArray = num.toArray(); - while (data.length) { - if (self._cache.length === 0) { - self._cache = self._cipher.encryptBlock(self._prev); - self._prev = Buffer.allocUnsafe(0); + if (!num.sign && numArray[0] & 128) { + numArray.unshift(0); } - if (self._cache.length <= data.length) { - len = self._cache.length; - out = Buffer.concat([out, encryptStart(self, data.slice(0, len), decrypt)]); - data = data.slice(len); - } else { - out = Buffer.concat([out, encryptStart(self, data, decrypt)]); - break; - } + num = Buffer.from(numArray); } - return out; - }; - - return exports$1k; -} - -var exports$1j = {}, - _dewExec$1i = false; -function dew$1i() { - if (_dewExec$1i) return exports$1j; - _dewExec$1i = true; + if (Buffer.isBuffer(num)) { + let size = num.length; + if (num.length === 0) size++; + const out = Buffer.alloc(size); + num.copy(out); + if (num.length === 0) out[0] = 0; + return this._createEncoderBuffer(out); + } - var Buffer = dew$1T().Buffer; + if (num < 128) return this._createEncoderBuffer(num); + if (num < 256) return this._createEncoderBuffer([0, num]); + let size = 1; - function encryptByte(self, byteParam, decrypt) { - var pad = self._cipher.encryptBlock(self._prev); + for (let i = num; i >= 256; i >>= 8) size++; - var out = pad[0] ^ byteParam; - self._prev = Buffer.concat([self._prev.slice(1), Buffer.from([decrypt ? byteParam : out])]); - return out; - } + const out = new Array(size); - exports$1j.encrypt = function (self, chunk, decrypt) { - var len = chunk.length; - var out = Buffer.allocUnsafe(len); - var i = -1; + for (let i = out.length - 1; i >= 0; i--) { + out[i] = num & 255; + num >>= 8; + } - while (++i < len) { - out[i] = encryptByte(self, chunk[i], decrypt); + if (out[0] & 128) { + out.unshift(0); } - return out; + return this._createEncoderBuffer(Buffer.from(out)); }; - return exports$1j; -} + DERNode.prototype._encodeBool = function encodeBool(value) { + return this._createEncoderBuffer(value ? 255 : 0); + }; -var exports$1i = {}, - _dewExec$1h = false; -function dew$1h() { - if (_dewExec$1h) return exports$1i; - _dewExec$1h = true; + DERNode.prototype._use = function use(entity, obj) { + if (typeof entity === "function") entity = entity(obj); + return entity._getEncoder("der").tree; + }; - var Buffer = dew$1T().Buffer; + DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) { + const state = this._baseState; + let i; + if (state["default"] === null) return false; + const data = dataBuffer.join(); + if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state["default"], reporter, parent).join(); + if (data.length !== state.defaultBuffer.length) return false; - function encryptByte(self, byteParam, decrypt) { - var pad; - var i = -1; - var len = 8; - var out = 0; - var bit, value; + for (i = 0; i < data.length; i++) if (data[i] !== state.defaultBuffer[i]) return false; - while (++i < len) { - pad = self._cipher.encryptBlock(self._prev); - bit = byteParam & 1 << 7 - i ? 128 : 0; - value = pad[0] ^ bit; - out += (value & 128) >> i % 8; - self._prev = shiftIn(self._prev, decrypt ? bit : value); - } + return true; + }; // Utility methods - return out; + + function encodeTag(tag, primitive, cls, reporter) { + let res; + if (tag === "seqof") tag = "seq";else if (tag === "setof") tag = "set"; + if (der.tagByName.hasOwnProperty(tag)) res = der.tagByName[tag];else if (typeof tag === "number" && (tag | 0) === tag) res = tag;else return reporter.error("Unknown tag: " + tag); + if (res >= 31) return reporter.error("Multi-octet tag encoding unsupported"); + if (!primitive) res |= 32; + res |= der.tagClassByName[cls || "universal"] << 6; + return res; } - function shiftIn(buffer, value) { - var len = buffer.length; - var i = -1; - var out = Buffer.allocUnsafe(buffer.length); - buffer = Buffer.concat([buffer, Buffer.from([value])]); + return exports$r$1; +} - while (++i < len) { - out[i] = buffer[i] << 1 | buffer[i + 1] >> 7; - } +var exports$q$1 = {}, + _dewExec$q$1 = false; +function dew$q$1() { + if (_dewExec$q$1) return exports$q$1; + _dewExec$q$1 = true; - return out; + const inherits = dew$f$2(); + + const DEREncoder = dew$r$1(); + + function PEMEncoder(entity) { + DEREncoder.call(this, entity); + this.enc = "pem"; } - exports$1i.encrypt = function (self, chunk, decrypt) { - var len = chunk.length; - var out = Buffer.allocUnsafe(len); - var i = -1; + inherits(PEMEncoder, DEREncoder); + exports$q$1 = PEMEncoder; - while (++i < len) { - out[i] = encryptByte(self, chunk[i], decrypt); - } + PEMEncoder.prototype.encode = function encode(data, options) { + const buf = DEREncoder.prototype.encode.call(this, data); + const p = buf.toString("base64"); + const out = ["-----BEGIN " + options.label + "-----"]; - return out; + for (let i = 0; i < p.length; i += 64) out.push(p.slice(i, i + 64)); + + out.push("-----END " + options.label + "-----"); + return out.join("\n"); }; - return exports$1i; + return exports$q$1; } -var exports$1h = {}, - _dewExec$1g = false; -function dew$1g() { - if (_dewExec$1g) return exports$1h; - _dewExec$1g = true; - var Buffer = e$1$1$1.Buffer; +var exports$p$1 = {}, + _dewExec$p$1 = false; +function dew$p$1() { + if (_dewExec$p$1) return exports$p$1; + _dewExec$p$1 = true; + const encoders = exports$p$1; + encoders.der = dew$r$1(); + encoders.pem = dew$q$1(); + return exports$p$1; +} - var xor = dew$1l(); +var exports$o$1 = {}, + _dewExec$o$1 = false; +function dew$o$1() { + if (_dewExec$o$1) return exports$o$1; + _dewExec$o$1 = true; - function getBlock(self) { - self._prev = self._cipher.encryptBlock(self._prev); - return self._prev; - } + const inherits = dew$f$2(); - exports$1h.encrypt = function (self, chunk) { - while (self._cache.length < chunk.length) { - self._cache = Buffer.concat([self._cache, getBlock(self)]); - } + const bignum = dew$x$1(); - var pad = self._cache.slice(0, chunk.length); + const DecoderBuffer = dew$u$1().DecoderBuffer; - self._cache = self._cache.slice(chunk.length); - return xor(chunk, pad); - }; + const Node = dew$t$1(); // Import DER constants - return exports$1h; -} -var exports$1g = {}, - _dewExec$1f = false; -function dew$1f() { - if (_dewExec$1f) return exports$1g; - _dewExec$1f = true; + const der = dew$s$1(); - function incr32(iv) { - var len = iv.length; - var item; + function DERDecoder(entity) { + this.enc = "der"; + this.name = entity.name; + this.entity = entity; // Construct base tree - while (len--) { - item = iv.readUInt8(len); + this.tree = new DERNode(); - if (item === 255) { - iv.writeUInt8(0, len); - } else { - item++; - iv.writeUInt8(item, len); - break; - } - } + this.tree._init(entity.body); } - exports$1g = incr32; - return exports$1g; -} + exports$o$1 = DERDecoder; -var exports$1f = {}, - _dewExec$1e = false; -function dew$1e() { - if (_dewExec$1e) return exports$1f; - _dewExec$1e = true; + DERDecoder.prototype.decode = function decode(data, options) { + if (!DecoderBuffer.isDecoderBuffer(data)) { + data = new DecoderBuffer(data, options); + } - var xor = dew$1l(); + return this.tree._decode(data, options); + }; // Tree methods - var Buffer = dew$1T().Buffer; - var incr32 = dew$1f(); + function DERNode(parent) { + Node.call(this, "der", parent); + } - function getBlock(self) { - var out = self._cipher.encryptBlockRaw(self._prev); + inherits(DERNode, Node); - incr32(self._prev); - return out; - } + DERNode.prototype._peekTag = function peekTag(buffer, tag, any) { + if (buffer.isEmpty()) return false; + const state = buffer.save(); + const decodedTag = derDecodeTag(buffer, "Failed to peek tag: \"" + tag + "\""); + if (buffer.isError(decodedTag)) return decodedTag; + buffer.restore(state); + return decodedTag.tag === tag || decodedTag.tagStr === tag || decodedTag.tagStr + "of" === tag || any; + }; - var blockSize = 16; + DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) { + const decodedTag = derDecodeTag(buffer, "Failed to decode tag of \"" + tag + "\""); + if (buffer.isError(decodedTag)) return decodedTag; + let len = derDecodeLen(buffer, decodedTag.primitive, "Failed to get length of \"" + tag + "\""); // Failure - exports$1f.encrypt = function (self, chunk) { - var chunkNum = Math.ceil(chunk.length / blockSize); - var start = self._cache.length; - self._cache = Buffer.concat([self._cache, Buffer.allocUnsafe(chunkNum * blockSize)]); + if (buffer.isError(len)) return len; - for (var i = 0; i < chunkNum; i++) { - var out = getBlock(self); - var offset = start + i * blockSize; + if (!any && decodedTag.tag !== tag && decodedTag.tagStr !== tag && decodedTag.tagStr + "of" !== tag) { + return buffer.error("Failed to match tag: \"" + tag + "\""); + } - self._cache.writeUInt32BE(out[0], offset + 0); + if (decodedTag.primitive || len !== null) return buffer.skip(len, "Failed to match body of: \"" + tag + "\""); // Indefinite length... find END tag - self._cache.writeUInt32BE(out[1], offset + 4); + const state = buffer.save(); - self._cache.writeUInt32BE(out[2], offset + 8); + const res = this._skipUntilEnd(buffer, "Failed to skip indefinite length body: \"" + this.tag + "\""); - self._cache.writeUInt32BE(out[3], offset + 12); - } + if (buffer.isError(res)) return res; + len = buffer.offset - state.offset; + buffer.restore(state); + return buffer.skip(len, "Failed to match body of: \"" + tag + "\""); + }; - var pad = self._cache.slice(0, chunk.length); + DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) { + for (;;) { + const tag = derDecodeTag(buffer, fail); + if (buffer.isError(tag)) return tag; + const len = derDecodeLen(buffer, tag.primitive, fail); + if (buffer.isError(len)) return len; + let res; + if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail); // Failure - self._cache = self._cache.slice(chunk.length); - return xor(chunk, pad); + if (buffer.isError(res)) return res; + if (tag.tagStr === "end") break; + } }; - return exports$1f; -} + DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, options) { + const result = []; -var _list = { - "aes-128-ecb": { - "cipher": "AES", - "key": 128, - "iv": 0, - "mode": "ECB", - "type": "block" - }, - "aes-192-ecb": { - "cipher": "AES", - "key": 192, - "iv": 0, - "mode": "ECB", - "type": "block" - }, - "aes-256-ecb": { - "cipher": "AES", - "key": 256, - "iv": 0, - "mode": "ECB", - "type": "block" - }, - "aes-128-cbc": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes-192-cbc": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes-256-cbc": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes128": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes192": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes256": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CBC", - "type": "block" - }, - "aes-128-cfb": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB", - "type": "stream" - }, - "aes-192-cfb": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB", - "type": "stream" - }, - "aes-256-cfb": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB", - "type": "stream" - }, - "aes-128-cfb8": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB8", - "type": "stream" - }, - "aes-192-cfb8": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB8", - "type": "stream" - }, - "aes-256-cfb8": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB8", - "type": "stream" - }, - "aes-128-cfb1": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CFB1", - "type": "stream" - }, - "aes-192-cfb1": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CFB1", - "type": "stream" - }, - "aes-256-cfb1": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CFB1", - "type": "stream" - }, - "aes-128-ofb": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "OFB", - "type": "stream" - }, - "aes-192-ofb": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "OFB", - "type": "stream" - }, - "aes-256-ofb": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "OFB", - "type": "stream" - }, - "aes-128-ctr": { - "cipher": "AES", - "key": 128, - "iv": 16, - "mode": "CTR", - "type": "stream" - }, - "aes-192-ctr": { - "cipher": "AES", - "key": 192, - "iv": 16, - "mode": "CTR", - "type": "stream" - }, - "aes-256-ctr": { - "cipher": "AES", - "key": 256, - "iv": 16, - "mode": "CTR", - "type": "stream" - }, - "aes-128-gcm": { - "cipher": "AES", - "key": 128, - "iv": 12, - "mode": "GCM", - "type": "auth" - }, - "aes-192-gcm": { - "cipher": "AES", - "key": 192, - "iv": 12, - "mode": "GCM", - "type": "auth" - }, - "aes-256-gcm": { - "cipher": "AES", - "key": 256, - "iv": 12, - "mode": "GCM", - "type": "auth" - } -}; + while (!buffer.isEmpty()) { + const possibleEnd = this._peekTag(buffer, "end"); -var exports$1e = {}, - _dewExec$1d = false; -function dew$1d() { - if (_dewExec$1d) return exports$1e; - _dewExec$1d = true; - var modeModules = { - ECB: dew$1m(), - CBC: dew$1k(), - CFB: dew$1j(), - CFB8: dew$1i(), - CFB1: dew$1h(), - OFB: dew$1g(), - CTR: dew$1e(), - GCM: dew$1e() - }; - var modes = _list; + if (buffer.isError(possibleEnd)) return possibleEnd; + const res = decoder.decode(buffer, "der", options); + if (buffer.isError(res) && possibleEnd) break; + result.push(res); + } - for (var key in modes) { - modes[key].module = modeModules[modes[key].mode]; - } + return result; + }; - exports$1e = modes; - return exports$1e; -} + DERNode.prototype._decodeStr = function decodeStr(buffer, tag) { + if (tag === "bitstr") { + const unused = buffer.readUInt8(); + if (buffer.isError(unused)) return unused; + return { + unused: unused, + data: buffer.raw() + }; + } else if (tag === "bmpstr") { + const raw = buffer.raw(); + if (raw.length % 2 === 1) return buffer.error("Decoding of string type: bmpstr length mismatch"); + let str = ""; -var exports$1d = {}, - _dewExec$1c = false; + for (let i = 0; i < raw.length / 2; i++) { + str += String.fromCharCode(raw.readUInt16BE(i * 2)); + } -var _global$j = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + return str; + } else if (tag === "numstr") { + const numstr = buffer.raw().toString("ascii"); -function dew$1c() { - if (_dewExec$1c) return exports$1d; - _dewExec$1c = true; + if (!this._isNumstr(numstr)) { + return buffer.error("Decoding of string type: " + "numstr unsupported characters"); + } - // based on the aes implimentation in triple sec - // https://github.com/keybase/triplesec - // which is in turn based on the one from crypto-js - // https://code.google.com/p/crypto-js/ - var Buffer = dew$1T().Buffer; + return numstr; + } else if (tag === "octstr") { + return buffer.raw(); + } else if (tag === "objDesc") { + return buffer.raw(); + } else if (tag === "printstr") { + const printstr = buffer.raw().toString("ascii"); - function asUInt32Array(buf) { - if (!Buffer.isBuffer(buf)) buf = Buffer.from(buf); - var len = buf.length / 4 | 0; - var out = new Array(len); + if (!this._isPrintstr(printstr)) { + return buffer.error("Decoding of string type: " + "printstr unsupported characters"); + } - for (var i = 0; i < len; i++) { - out[i] = buf.readUInt32BE(i * 4); + return printstr; + } else if (/str$/.test(tag)) { + return buffer.raw().toString(); + } else { + return buffer.error("Decoding of string type: " + tag + " unsupported"); } + }; - return out; - } + DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) { + let result; + const identifiers = []; + let ident = 0; + let subident = 0; - function scrubVec(v) { - for (var i = 0; i < v.length; v++) { - v[i] = 0; + while (!buffer.isEmpty()) { + subident = buffer.readUInt8(); + ident <<= 7; + ident |= subident & 127; + + if ((subident & 128) === 0) { + identifiers.push(ident); + ident = 0; + } } - } - function cryptBlock(M, keySchedule, SUB_MIX, SBOX, nRounds) { - var SUB_MIX0 = SUB_MIX[0]; - var SUB_MIX1 = SUB_MIX[1]; - var SUB_MIX2 = SUB_MIX[2]; - var SUB_MIX3 = SUB_MIX[3]; - var s0 = M[0] ^ keySchedule[0]; - var s1 = M[1] ^ keySchedule[1]; - var s2 = M[2] ^ keySchedule[2]; - var s3 = M[3] ^ keySchedule[3]; - var t0, t1, t2, t3; - var ksRow = 4; + if (subident & 128) identifiers.push(ident); + const first = identifiers[0] / 40 | 0; + const second = identifiers[0] % 40; + if (relative) result = identifiers;else result = [first, second].concat(identifiers.slice(1)); - for (var round = 1; round < nRounds; round++) { - t0 = SUB_MIX0[s0 >>> 24] ^ SUB_MIX1[s1 >>> 16 & 255] ^ SUB_MIX2[s2 >>> 8 & 255] ^ SUB_MIX3[s3 & 255] ^ keySchedule[ksRow++]; - t1 = SUB_MIX0[s1 >>> 24] ^ SUB_MIX1[s2 >>> 16 & 255] ^ SUB_MIX2[s3 >>> 8 & 255] ^ SUB_MIX3[s0 & 255] ^ keySchedule[ksRow++]; - t2 = SUB_MIX0[s2 >>> 24] ^ SUB_MIX1[s3 >>> 16 & 255] ^ SUB_MIX2[s0 >>> 8 & 255] ^ SUB_MIX3[s1 & 255] ^ keySchedule[ksRow++]; - t3 = SUB_MIX0[s3 >>> 24] ^ SUB_MIX1[s0 >>> 16 & 255] ^ SUB_MIX2[s1 >>> 8 & 255] ^ SUB_MIX3[s2 & 255] ^ keySchedule[ksRow++]; - s0 = t0; - s1 = t1; - s2 = t2; - s3 = t3; + if (values) { + let tmp = values[result.join(" ")]; + if (tmp === undefined) tmp = values[result.join(".")]; + if (tmp !== undefined) result = tmp; } - t0 = (SBOX[s0 >>> 24] << 24 | SBOX[s1 >>> 16 & 255] << 16 | SBOX[s2 >>> 8 & 255] << 8 | SBOX[s3 & 255]) ^ keySchedule[ksRow++]; - t1 = (SBOX[s1 >>> 24] << 24 | SBOX[s2 >>> 16 & 255] << 16 | SBOX[s3 >>> 8 & 255] << 8 | SBOX[s0 & 255]) ^ keySchedule[ksRow++]; - t2 = (SBOX[s2 >>> 24] << 24 | SBOX[s3 >>> 16 & 255] << 16 | SBOX[s0 >>> 8 & 255] << 8 | SBOX[s1 & 255]) ^ keySchedule[ksRow++]; - t3 = (SBOX[s3 >>> 24] << 24 | SBOX[s0 >>> 16 & 255] << 16 | SBOX[s1 >>> 8 & 255] << 8 | SBOX[s2 & 255]) ^ keySchedule[ksRow++]; - t0 = t0 >>> 0; - t1 = t1 >>> 0; - t2 = t2 >>> 0; - t3 = t3 >>> 0; - return [t0, t1, t2, t3]; - } // AES constants + return result; + }; + DERNode.prototype._decodeTime = function decodeTime(buffer, tag) { + const str = buffer.raw().toString(); + let year; + let mon; + let day; + let hour; + let min; + let sec; - var RCON = [0, 1, 2, 4, 8, 16, 32, 64, 128, 27, 54]; + if (tag === "gentime") { + year = str.slice(0, 4) | 0; + mon = str.slice(4, 6) | 0; + day = str.slice(6, 8) | 0; + hour = str.slice(8, 10) | 0; + min = str.slice(10, 12) | 0; + sec = str.slice(12, 14) | 0; + } else if (tag === "utctime") { + year = str.slice(0, 2) | 0; + mon = str.slice(2, 4) | 0; + day = str.slice(4, 6) | 0; + hour = str.slice(6, 8) | 0; + min = str.slice(8, 10) | 0; + sec = str.slice(10, 12) | 0; + if (year < 70) year = 2000 + year;else year = 1900 + year; + } else { + return buffer.error("Decoding " + tag + " time is not supported yet"); + } - var G = function () { - // Compute double table - var d = new Array(256); + return Date.UTC(year, mon - 1, day, hour, min, sec, 0); + }; - for (var j = 0; j < 256; j++) { - if (j < 128) { - d[j] = j << 1; - } else { - d[j] = j << 1 ^ 283; - } - } + DERNode.prototype._decodeNull = function decodeNull() { + return null; + }; - var SBOX = []; - var INV_SBOX = []; - var SUB_MIX = [[], [], [], []]; - var INV_SUB_MIX = [[], [], [], []]; // Walk GF(2^8) + DERNode.prototype._decodeBool = function decodeBool(buffer) { + const res = buffer.readUInt8(); + if (buffer.isError(res)) return res;else return res !== 0; + }; - var x = 0; - var xi = 0; + DERNode.prototype._decodeInt = function decodeInt(buffer, values) { + // Bigint, return as it is (assume big endian) + const raw = buffer.raw(); + let res = new bignum(raw); + if (values) res = values[res.toString(10)] || res; + return res; + }; - for (var i = 0; i < 256; ++i) { - // Compute sbox - var sx = xi ^ xi << 1 ^ xi << 2 ^ xi << 3 ^ xi << 4; - sx = sx >>> 8 ^ sx & 255 ^ 99; - SBOX[x] = sx; - INV_SBOX[sx] = x; // Compute multiplication + DERNode.prototype._use = function use(entity, obj) { + if (typeof entity === "function") entity = entity(obj); + return entity._getDecoder("der").tree; + }; // Utility methods - var x2 = d[x]; - var x4 = d[x2]; - var x8 = d[x4]; // Compute sub bytes, mix columns tables - var t = d[sx] * 257 ^ sx * 16843008; - SUB_MIX[0][x] = t << 24 | t >>> 8; - SUB_MIX[1][x] = t << 16 | t >>> 16; - SUB_MIX[2][x] = t << 8 | t >>> 24; - SUB_MIX[3][x] = t; // Compute inv sub bytes, inv mix columns tables + function derDecodeTag(buf, fail) { + let tag = buf.readUInt8(fail); + if (buf.isError(tag)) return tag; + const cls = der.tagClass[tag >> 6]; + const primitive = (tag & 32) === 0; // Multi-octet tag - load - t = x8 * 16843009 ^ x4 * 65537 ^ x2 * 257 ^ x * 16843008; - INV_SUB_MIX[0][sx] = t << 24 | t >>> 8; - INV_SUB_MIX[1][sx] = t << 16 | t >>> 16; - INV_SUB_MIX[2][sx] = t << 8 | t >>> 24; - INV_SUB_MIX[3][sx] = t; + if ((tag & 31) === 31) { + let oct = tag; + tag = 0; - if (x === 0) { - x = xi = 1; - } else { - x = x2 ^ d[d[d[x8 ^ x2]]]; - xi ^= d[d[xi]]; + while ((oct & 128) === 128) { + oct = buf.readUInt8(fail); + if (buf.isError(oct)) return oct; + tag <<= 7; + tag |= oct & 127; } + } else { + tag &= 31; } + const tagStr = der.tag[tag]; return { - SBOX: SBOX, - INV_SBOX: INV_SBOX, - SUB_MIX: SUB_MIX, - INV_SUB_MIX: INV_SUB_MIX + cls: cls, + primitive: primitive, + tag: tag, + tagStr: tagStr }; - }(); + } - function AES(key) { - (this || _global$j)._key = asUInt32Array(key); + function derDecodeLen(buf, primitive, fail) { + let len = buf.readUInt8(fail); + if (buf.isError(len)) return len; // Indefinite form - this._reset(); - } + if (!primitive && len === 128) return null; // Definite form - AES.blockSize = 4 * 4; - AES.keySize = 256 / 8; - AES.prototype.blockSize = AES.blockSize; - AES.prototype.keySize = AES.keySize; + if ((len & 128) === 0) { + // Short form + return len; + } // Long form - AES.prototype._reset = function () { - var keyWords = (this || _global$j)._key; - var keySize = keyWords.length; - var nRounds = keySize + 6; - var ksRows = (nRounds + 1) * 4; - var keySchedule = []; - for (var k = 0; k < keySize; k++) { - keySchedule[k] = keyWords[k]; + const num = len & 127; + if (num > 4) return buf.error("length octect is too long"); + len = 0; + + for (let i = 0; i < num; i++) { + len <<= 8; + const j = buf.readUInt8(fail); + if (buf.isError(j)) return j; + len |= j; } - for (k = keySize; k < ksRows; k++) { - var t = keySchedule[k - 1]; + return len; + } - if (k % keySize === 0) { - t = t << 8 | t >>> 24; - t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; - t ^= RCON[k / keySize | 0] << 24; - } else if (keySize > 6 && k % keySize === 4) { - t = G.SBOX[t >>> 24] << 24 | G.SBOX[t >>> 16 & 255] << 16 | G.SBOX[t >>> 8 & 255] << 8 | G.SBOX[t & 255]; - } + return exports$o$1; +} - keySchedule[k] = keySchedule[k - keySize] ^ t; - } +var exports$n$1 = {}, + _dewExec$n$1 = false; +function dew$n$1() { + if (_dewExec$n$1) return exports$n$1; + _dewExec$n$1 = true; - var invKeySchedule = []; + const inherits = dew$f$2(); - for (var ik = 0; ik < ksRows; ik++) { - var ksR = ksRows - ik; - var tt = keySchedule[ksR - (ik % 4 ? 0 : 4)]; + const Buffer = dew$w$1().Buffer; - if (ik < 4 || ksR <= 4) { - invKeySchedule[ik] = tt; + const DERDecoder = dew$o$1(); + + function PEMDecoder(entity) { + DERDecoder.call(this, entity); + this.enc = "pem"; + } + + inherits(PEMDecoder, DERDecoder); + exports$n$1 = PEMDecoder; + + PEMDecoder.prototype.decode = function decode(data, options) { + const lines = data.toString().split(/[\r\n]+/g); + const label = options.label.toUpperCase(); + const re = /^-----(BEGIN|END) ([^-]+)-----$/; + let start = -1; + let end = -1; + + for (let i = 0; i < lines.length; i++) { + const match = lines[i].match(re); + if (match === null) continue; + if (match[2] !== label) continue; + + if (start === -1) { + if (match[1] !== "BEGIN") break; + start = i; } else { - invKeySchedule[ik] = G.INV_SUB_MIX[0][G.SBOX[tt >>> 24]] ^ G.INV_SUB_MIX[1][G.SBOX[tt >>> 16 & 255]] ^ G.INV_SUB_MIX[2][G.SBOX[tt >>> 8 & 255]] ^ G.INV_SUB_MIX[3][G.SBOX[tt & 255]]; + if (match[1] !== "END") break; + end = i; + break; } } - (this || _global$j)._nRounds = nRounds; - (this || _global$j)._keySchedule = keySchedule; - (this || _global$j)._invKeySchedule = invKeySchedule; - }; + if (start === -1 || end === -1) throw new Error("PEM section not found for: " + label); + const base64 = lines.slice(start + 1, end).join(""); // Remove excessive symbols - AES.prototype.encryptBlockRaw = function (M) { - M = asUInt32Array(M); - return cryptBlock(M, (this || _global$j)._keySchedule, G.SUB_MIX, G.SBOX, (this || _global$j)._nRounds); + base64.replace(/[^a-z0-9+/=]+/gi, ""); + const input = Buffer.from(base64, "base64"); + return DERDecoder.prototype.decode.call(this, input, options); }; - AES.prototype.encryptBlock = function (M) { - var out = this.encryptBlockRaw(M); - var buf = Buffer.allocUnsafe(16); - buf.writeUInt32BE(out[0], 0); - buf.writeUInt32BE(out[1], 4); - buf.writeUInt32BE(out[2], 8); - buf.writeUInt32BE(out[3], 12); - return buf; - }; + return exports$n$1; +} - AES.prototype.decryptBlock = function (M) { - M = asUInt32Array(M); // swap +var exports$m$1 = {}, + _dewExec$m$1 = false; +function dew$m$1() { + if (_dewExec$m$1) return exports$m$1; + _dewExec$m$1 = true; + const decoders = exports$m$1; + decoders.der = dew$o$1(); + decoders.pem = dew$n$1(); + return exports$m$1; +} - var m1 = M[1]; - M[1] = M[3]; - M[3] = m1; - var out = cryptBlock(M, (this || _global$j)._invKeySchedule, G.INV_SUB_MIX, G.INV_SBOX, (this || _global$j)._nRounds); - var buf = Buffer.allocUnsafe(16); - buf.writeUInt32BE(out[0], 0); - buf.writeUInt32BE(out[3], 4); - buf.writeUInt32BE(out[2], 8); - buf.writeUInt32BE(out[1], 12); - return buf; - }; +var exports$l$1 = {}, + _dewExec$l$1 = false; +function dew$l$1() { + if (_dewExec$l$1) return exports$l$1; + _dewExec$l$1 = true; - AES.prototype.scrub = function () { - scrubVec((this || _global$j)._keySchedule); - scrubVec((this || _global$j)._invKeySchedule); - scrubVec((this || _global$j)._key); + const encoders = dew$p$1(); + + const decoders = dew$m$1(); + + const inherits = dew$f$2(); + + const api = exports$l$1; + + api.define = function define(name, body) { + return new Entity(name, body); }; - exports$1d.AES = AES; - return exports$1d; -} + function Entity(name, body) { + this.name = name; + this.body = body; + this.decoders = {}; + this.encoders = {}; + } -var exports$1c = {}, - _dewExec$1b = false; + Entity.prototype._createNamed = function createNamed(Base) { + const name = this.name; -var _global$i = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + function Generated(entity) { + this._initNamed(entity, name); + } -function dew$1b() { - if (_dewExec$1b) return exports$1c; - _dewExec$1b = true; + inherits(Generated, Base); - var Buffer = dew$1T().Buffer; + Generated.prototype._initNamed = function _initNamed(entity, name) { + Base.call(this, entity, name); + }; - var ZEROES = Buffer.alloc(16, 0); + return new Generated(this); + }; - function toArray(buf) { - return [buf.readUInt32BE(0), buf.readUInt32BE(4), buf.readUInt32BE(8), buf.readUInt32BE(12)]; - } + Entity.prototype._getDecoder = function _getDecoder(enc) { + enc = enc || "der"; // Lazily create decoder - function fromArray(out) { - var buf = Buffer.allocUnsafe(16); - buf.writeUInt32BE(out[0] >>> 0, 0); - buf.writeUInt32BE(out[1] >>> 0, 4); - buf.writeUInt32BE(out[2] >>> 0, 8); - buf.writeUInt32BE(out[3] >>> 0, 12); - return buf; - } + if (!this.decoders.hasOwnProperty(enc)) this.decoders[enc] = this._createNamed(decoders[enc]); + return this.decoders[enc]; + }; - function GHASH(key) { - (this || _global$i).h = key; - (this || _global$i).state = Buffer.alloc(16, 0); - (this || _global$i).cache = Buffer.allocUnsafe(0); - } // from http://bitwiseshiftleft.github.io/sjcl/doc/symbols/src/core_gcm.js.html - // by Juho Vähä-Herttua + Entity.prototype.decode = function decode(data, enc, options) { + return this._getDecoder(enc).decode(data, options); + }; + Entity.prototype._getEncoder = function _getEncoder(enc) { + enc = enc || "der"; // Lazily create encoder - GHASH.prototype.ghash = function (block) { - var i = -1; + if (!this.encoders.hasOwnProperty(enc)) this.encoders[enc] = this._createNamed(encoders[enc]); + return this.encoders[enc]; + }; - while (++i < block.length) { - (this || _global$i).state[i] ^= block[i]; - } + Entity.prototype.encode = function encode(data, enc, + /* internal */ + reporter) { + return this._getEncoder(enc).encode(data, reporter); + }; - this._multiply(); + return exports$l$1; +} + +var exports$k$1 = {}, + _dewExec$k$1 = false; +function dew$k$1() { + if (_dewExec$k$1) return exports$k$1; + _dewExec$k$1 = true; + const base = exports$k$1; + base.Reporter = dew$v$1().Reporter; + base.DecoderBuffer = dew$u$1().DecoderBuffer; + base.EncoderBuffer = dew$u$1().EncoderBuffer; + base.Node = dew$t$1(); + return exports$k$1; +} + +var exports$j$1 = {}, + _dewExec$j$1 = false; +function dew$j$1() { + if (_dewExec$j$1) return exports$j$1; + _dewExec$j$1 = true; + const constants = exports$j$1; // Helper + + constants._reverse = function reverse(map) { + const res = {}; + Object.keys(map).forEach(function (key) { + // Convert key to integer if it is stringified + if ((key | 0) == key) key = key | 0; + const value = map[key]; + res[value] = key; + }); + return res; }; - GHASH.prototype._multiply = function () { - var Vi = toArray((this || _global$i).h); - var Zi = [0, 0, 0, 0]; - var j, xi, lsbVi; - var i = -1; + constants.der = dew$s$1(); + return exports$j$1; +} - while (++i < 128) { - xi = ((this || _global$i).state[~~(i / 8)] & 1 << 7 - i % 8) !== 0; +var exports$i$1 = {}, + _dewExec$i$1 = false; +function dew$i$1() { + if (_dewExec$i$1) return exports$i$1; + _dewExec$i$1 = true; + const asn1 = exports$i$1; + asn1.bignum = dew$x$1(); + asn1.define = dew$l$1().define; + asn1.base = dew$k$1(); + asn1.constants = dew$j$1(); + asn1.decoders = dew$m$1(); + asn1.encoders = dew$p$1(); + return exports$i$1; +} + +var exports$h$1 = {}, + _dewExec$h$1 = false; +function dew$h$1() { + if (_dewExec$h$1) return exports$h$1; + _dewExec$h$1 = true; + + var asn = dew$i$1(); + + var Time = asn.define("Time", function () { + this.choice({ + utcTime: this.utctime(), + generalTime: this.gentime() + }); + }); + var AttributeTypeValue = asn.define("AttributeTypeValue", function () { + this.seq().obj(this.key("type").objid(), this.key("value").any()); + }); + var AlgorithmIdentifier = asn.define("AlgorithmIdentifier", function () { + this.seq().obj(this.key("algorithm").objid(), this.key("parameters").optional(), this.key("curve").objid().optional()); + }); + var SubjectPublicKeyInfo = asn.define("SubjectPublicKeyInfo", function () { + this.seq().obj(this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPublicKey").bitstr()); + }); + var RelativeDistinguishedName = asn.define("RelativeDistinguishedName", function () { + this.setof(AttributeTypeValue); + }); + var RDNSequence = asn.define("RDNSequence", function () { + this.seqof(RelativeDistinguishedName); + }); + var Name = asn.define("Name", function () { + this.choice({ + rdnSequence: this.use(RDNSequence) + }); + }); + var Validity = asn.define("Validity", function () { + this.seq().obj(this.key("notBefore").use(Time), this.key("notAfter").use(Time)); + }); + var Extension = asn.define("Extension", function () { + this.seq().obj(this.key("extnID").objid(), this.key("critical").bool().def(false), this.key("extnValue").octstr()); + }); + var TBSCertificate = asn.define("TBSCertificate", function () { + this.seq().obj(this.key("version").explicit(0).int().optional(), this.key("serialNumber").int(), this.key("signature").use(AlgorithmIdentifier), this.key("issuer").use(Name), this.key("validity").use(Validity), this.key("subject").use(Name), this.key("subjectPublicKeyInfo").use(SubjectPublicKeyInfo), this.key("issuerUniqueID").implicit(1).bitstr().optional(), this.key("subjectUniqueID").implicit(2).bitstr().optional(), this.key("extensions").explicit(3).seqof(Extension).optional()); + }); + var X509Certificate = asn.define("X509Certificate", function () { + this.seq().obj(this.key("tbsCertificate").use(TBSCertificate), this.key("signatureAlgorithm").use(AlgorithmIdentifier), this.key("signatureValue").bitstr()); + }); + exports$h$1 = X509Certificate; + return exports$h$1; +} - if (xi) { - // Z_i+1 = Z_i ^ V_i - Zi[0] ^= Vi[0]; - Zi[1] ^= Vi[1]; - Zi[2] ^= Vi[2]; - Zi[3] ^= Vi[3]; - } // Store the value of LSB(V_i) +var exports$g$1 = {}, + _dewExec$g$1 = false; +function dew$g$1() { + if (_dewExec$g$1) return exports$g$1; + _dewExec$g$1 = true; + var asn1 = dew$i$1(); - lsbVi = (Vi[3] & 1) !== 0; // V_i+1 = V_i >> 1 + exports$g$1.certificate = dew$h$1(); + var RSAPrivateKey = asn1.define("RSAPrivateKey", function () { + this.seq().obj(this.key("version").int(), this.key("modulus").int(), this.key("publicExponent").int(), this.key("privateExponent").int(), this.key("prime1").int(), this.key("prime2").int(), this.key("exponent1").int(), this.key("exponent2").int(), this.key("coefficient").int()); + }); + exports$g$1.RSAPrivateKey = RSAPrivateKey; + var RSAPublicKey = asn1.define("RSAPublicKey", function () { + this.seq().obj(this.key("modulus").int(), this.key("publicExponent").int()); + }); + exports$g$1.RSAPublicKey = RSAPublicKey; + var PublicKey = asn1.define("SubjectPublicKeyInfo", function () { + this.seq().obj(this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPublicKey").bitstr()); + }); + exports$g$1.PublicKey = PublicKey; + var AlgorithmIdentifier = asn1.define("AlgorithmIdentifier", function () { + this.seq().obj(this.key("algorithm").objid(), this.key("none").null_().optional(), this.key("curve").objid().optional(), this.key("params").seq().obj(this.key("p").int(), this.key("q").int(), this.key("g").int()).optional()); + }); + var PrivateKeyInfo = asn1.define("PrivateKeyInfo", function () { + this.seq().obj(this.key("version").int(), this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPrivateKey").octstr()); + }); + exports$g$1.PrivateKey = PrivateKeyInfo; + var EncryptedPrivateKeyInfo = asn1.define("EncryptedPrivateKeyInfo", function () { + this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(), this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(), this.key("kdeparams").seq().obj(this.key("salt").octstr(), this.key("iters").int())), this.key("cipher").seq().obj(this.key("algo").objid(), this.key("iv").octstr()))), this.key("subjectPrivateKey").octstr()); + }); + exports$g$1.EncryptedPrivateKey = EncryptedPrivateKeyInfo; + var DSAPrivateKey = asn1.define("DSAPrivateKey", function () { + this.seq().obj(this.key("version").int(), this.key("p").int(), this.key("q").int(), this.key("g").int(), this.key("pub_key").int(), this.key("priv_key").int()); + }); + exports$g$1.DSAPrivateKey = DSAPrivateKey; + exports$g$1.DSAparam = asn1.define("DSAparam", function () { + this.int(); + }); + var ECPrivateKey = asn1.define("ECPrivateKey", function () { + this.seq().obj(this.key("version").int(), this.key("privateKey").octstr(), this.key("parameters").optional().explicit(0).use(ECParameters), this.key("publicKey").optional().explicit(1).bitstr()); + }); + exports$g$1.ECPrivateKey = ECPrivateKey; + var ECParameters = asn1.define("ECParameters", function () { + this.choice({ + namedCurve: this.objid() + }); + }); + exports$g$1.signature = asn1.define("signature", function () { + this.seq().obj(this.key("r").int(), this.key("s").int()); + }); + return exports$g$1; +} - for (j = 3; j > 0; j--) { - Vi[j] = Vi[j] >>> 1 | (Vi[j - 1] & 1) << 31; - } +var _aesid$1 = {"2.16.840.1.101.3.4.1.1": "aes-128-ecb", +"2.16.840.1.101.3.4.1.2": "aes-128-cbc", +"2.16.840.1.101.3.4.1.3": "aes-128-ofb", +"2.16.840.1.101.3.4.1.4": "aes-128-cfb", +"2.16.840.1.101.3.4.1.21": "aes-192-ecb", +"2.16.840.1.101.3.4.1.22": "aes-192-cbc", +"2.16.840.1.101.3.4.1.23": "aes-192-ofb", +"2.16.840.1.101.3.4.1.24": "aes-192-cfb", +"2.16.840.1.101.3.4.1.41": "aes-256-ecb", +"2.16.840.1.101.3.4.1.42": "aes-256-cbc", +"2.16.840.1.101.3.4.1.43": "aes-256-ofb", +"2.16.840.1.101.3.4.1.44": "aes-256-cfb" +}; - Vi[0] = Vi[0] >>> 1; // If LSB(V_i) is 1, V_i+1 = (V_i >> 1) ^ R +var exports$f$1 = {}, + _dewExec$f$1 = false; +function dew$f$1() { + if (_dewExec$f$1) return exports$f$1; + _dewExec$f$1 = true; + // adapted from https://github.com/apatil/pemstrip + var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m; + var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m; + var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m; - if (lsbVi) { - Vi[0] = Vi[0] ^ 225 << 24; - } - } + var evp = dew$18$1(); - (this || _global$i).state = fromArray(Zi); - }; + var ciphers = dew$15$1(); - GHASH.prototype.update = function (buf) { - (this || _global$i).cache = Buffer.concat([(this || _global$i).cache, buf]); - var chunk; + var Buffer = dew$1T().Buffer; - while ((this || _global$i).cache.length >= 16) { - chunk = (this || _global$i).cache.slice(0, 16); - (this || _global$i).cache = (this || _global$i).cache.slice(16); - this.ghash(chunk); - } - }; + exports$f$1 = function (okey, password) { + var key = okey.toString(); + var match = key.match(findProc); + var decrypted; - GHASH.prototype.final = function (abl, bl) { - if ((this || _global$i).cache.length) { - this.ghash(Buffer.concat([(this || _global$i).cache, ZEROES], 16)); + if (!match) { + var match2 = key.match(fullRegex); + decrypted = Buffer.from(match2[2].replace(/[\r\n]/g, ""), "base64"); + } else { + var suite = "aes" + match[1]; + var iv = Buffer.from(match[2], "hex"); + var cipherText = Buffer.from(match[3].replace(/[\r\n]/g, ""), "base64"); + var cipherKey = evp(password, iv.slice(0, 8), parseInt(match[1], 10)).key; + var out = []; + var cipher = ciphers.createDecipheriv(suite, cipherKey, iv); + out.push(cipher.update(cipherText)); + out.push(cipher.final()); + decrypted = Buffer.concat(out); } - this.ghash(fromArray([0, abl, 0, bl])); - return (this || _global$i).state; + var tag = key.match(startRegex)[1]; + return { + tag: tag, + data: decrypted + }; }; - exports$1c = GHASH; - return exports$1c; + return exports$f$1; } -var exports$1b = {}, - _dewExec$1a = false; - -var _global$h = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$1a() { - if (_dewExec$1a) return exports$1b; - _dewExec$1a = true; - - var aes = dew$1c(); - - var Buffer = dew$1T().Buffer; +var exports$e$1 = {}, + _dewExec$e$1 = false; +function dew$e$1() { + if (_dewExec$e$1) return exports$e$1; + _dewExec$e$1 = true; - var Transform = dew$1G(); + var asn1 = dew$g$1(); - var inherits = dew$f$2(); + var aesid = _aesid$1; - var GHASH = dew$1b(); + var fixProc = dew$f$1(); - var xor = dew$1l(); + var ciphers = dew$15$1(); - var incr32 = dew$1f(); + var compat = dew$1v(); - function xorTest(a, b) { - var out = 0; - if (a.length !== b.length) out++; - var len = Math.min(a.length, b.length); + var Buffer = dew$1T().Buffer; - for (var i = 0; i < len; ++i) { - out += a[i] ^ b[i]; - } + exports$e$1 = parseKeys; - return out; - } + function parseKeys(buffer) { + var password; - function calcIv(self, iv, ck) { - if (iv.length === 12) { - self._finID = Buffer.concat([iv, Buffer.from([0, 0, 0, 1])]); - return Buffer.concat([iv, Buffer.from([0, 0, 0, 2])]); + if (typeof buffer === "object" && !Buffer.isBuffer(buffer)) { + password = buffer.passphrase; + buffer = buffer.key; } - var ghash = new GHASH(ck); - var len = iv.length; - var toPad = len % 16; - ghash.update(iv); - - if (toPad) { - toPad = 16 - toPad; - ghash.update(Buffer.alloc(toPad, 0)); + if (typeof buffer === "string") { + buffer = Buffer.from(buffer); } - ghash.update(Buffer.alloc(8, 0)); - var ivBits = len * 8; - var tail = Buffer.alloc(8); - tail.writeUIntBE(ivBits, 0, 8); - ghash.update(tail); - self._finID = ghash.state; - var out = Buffer.from(self._finID); - incr32(out); - return out; - } - - function StreamCipher(mode, key, iv, decrypt) { - Transform.call(this || _global$h); - var h = Buffer.alloc(4, 0); - (this || _global$h)._cipher = new aes.AES(key); - - var ck = (this || _global$h)._cipher.encryptBlock(h); - - (this || _global$h)._ghash = new GHASH(ck); - iv = calcIv(this || _global$h, iv, ck); - (this || _global$h)._prev = Buffer.from(iv); - (this || _global$h)._cache = Buffer.allocUnsafe(0); - (this || _global$h)._secCache = Buffer.allocUnsafe(0); - (this || _global$h)._decrypt = decrypt; - (this || _global$h)._alen = 0; - (this || _global$h)._len = 0; - (this || _global$h)._mode = mode; - (this || _global$h)._authTag = null; - (this || _global$h)._called = false; - } - - inherits(StreamCipher, Transform); - - StreamCipher.prototype._update = function (chunk) { - if (!(this || _global$h)._called && (this || _global$h)._alen) { - var rump = 16 - (this || _global$h)._alen % 16; - - if (rump < 16) { - rump = Buffer.alloc(rump, 0); - - (this || _global$h)._ghash.update(rump); - } - } + var stripped = fixProc(buffer, password); + var type = stripped.tag; + var data = stripped.data; + var subtype, ndata; - (this || _global$h)._called = true; + switch (type) { + case "CERTIFICATE": + ndata = asn1.certificate.decode(data, "der").tbsCertificate.subjectPublicKeyInfo; + // falls through - var out = (this || _global$h)._mode.encrypt(this || _global$h, chunk); + case "PUBLIC KEY": + if (!ndata) { + ndata = asn1.PublicKey.decode(data, "der"); + } - if ((this || _global$h)._decrypt) { - (this || _global$h)._ghash.update(chunk); - } else { - (this || _global$h)._ghash.update(out); - } + subtype = ndata.algorithm.algorithm.join("."); - (this || _global$h)._len += chunk.length; - return out; - }; + switch (subtype) { + case "1.2.840.113549.1.1.1": + return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, "der"); - StreamCipher.prototype._final = function () { - if ((this || _global$h)._decrypt && !(this || _global$h)._authTag) throw new Error("Unsupported state or unable to authenticate data"); - var tag = xor((this || _global$h)._ghash.final((this || _global$h)._alen * 8, (this || _global$h)._len * 8), (this || _global$h)._cipher.encryptBlock((this || _global$h)._finID)); - if ((this || _global$h)._decrypt && xorTest(tag, (this || _global$h)._authTag)) throw new Error("Unsupported state or unable to authenticate data"); - (this || _global$h)._authTag = tag; + case "1.2.840.10045.2.1": + ndata.subjectPrivateKey = ndata.subjectPublicKey; + return { + type: "ec", + data: ndata + }; - (this || _global$h)._cipher.scrub(); - }; + case "1.2.840.10040.4.1": + ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, "der"); + return { + type: "dsa", + data: ndata.algorithm.params + }; - StreamCipher.prototype.getAuthTag = function getAuthTag() { - if ((this || _global$h)._decrypt || !Buffer.isBuffer((this || _global$h)._authTag)) throw new Error("Attempting to get auth tag in unsupported state"); - return (this || _global$h)._authTag; - }; + default: + throw new Error("unknown key id " + subtype); + } - StreamCipher.prototype.setAuthTag = function setAuthTag(tag) { - if (!(this || _global$h)._decrypt) throw new Error("Attempting to set auth tag in unsupported state"); - (this || _global$h)._authTag = tag; - }; + // throw new Error('unknown key type ' + type) - StreamCipher.prototype.setAAD = function setAAD(buf) { - if ((this || _global$h)._called) throw new Error("Attempting to set AAD in unsupported state"); + case "ENCRYPTED PRIVATE KEY": + data = asn1.EncryptedPrivateKey.decode(data, "der"); + data = decrypt(data, password); + // falls through - (this || _global$h)._ghash.update(buf); + case "PRIVATE KEY": + ndata = asn1.PrivateKey.decode(data, "der"); + subtype = ndata.algorithm.algorithm.join("."); - (this || _global$h)._alen += buf.length; - }; + switch (subtype) { + case "1.2.840.113549.1.1.1": + return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, "der"); - exports$1b = StreamCipher; - return exports$1b; -} + case "1.2.840.10045.2.1": + return { + curve: ndata.algorithm.curve, + privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, "der").privateKey + }; -var exports$1a = {}, - _dewExec$19 = false; + case "1.2.840.10040.4.1": + ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, "der"); + return { + type: "dsa", + params: ndata.algorithm.params + }; -var _global$g = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + default: + throw new Error("unknown key id " + subtype); + } -function dew$19() { - if (_dewExec$19) return exports$1a; - _dewExec$19 = true; + // throw new Error('unknown key type ' + type) - var aes = dew$1c(); + case "RSA PUBLIC KEY": + return asn1.RSAPublicKey.decode(data, "der"); - var Buffer = dew$1T().Buffer; + case "RSA PRIVATE KEY": + return asn1.RSAPrivateKey.decode(data, "der"); - var Transform = dew$1G(); + case "DSA PRIVATE KEY": + return { + type: "dsa", + params: asn1.DSAPrivateKey.decode(data, "der") + }; - var inherits = dew$f$2(); + case "EC PRIVATE KEY": + data = asn1.ECPrivateKey.decode(data, "der"); + return { + curve: data.parameters.value, + privateKey: data.privateKey + }; - function StreamCipher(mode, key, iv, decrypt) { - Transform.call(this || _global$g); - (this || _global$g)._cipher = new aes.AES(key); - (this || _global$g)._prev = Buffer.from(iv); - (this || _global$g)._cache = Buffer.allocUnsafe(0); - (this || _global$g)._secCache = Buffer.allocUnsafe(0); - (this || _global$g)._decrypt = decrypt; - (this || _global$g)._mode = mode; + default: + throw new Error("unknown key type " + type); + } } - inherits(StreamCipher, Transform); - - StreamCipher.prototype._update = function (chunk) { - return (this || _global$g)._mode.encrypt(this || _global$g, chunk, (this || _global$g)._decrypt); - }; + parseKeys.signature = asn1.signature; - StreamCipher.prototype._final = function () { - (this || _global$g)._cipher.scrub(); - }; + function decrypt(data, password) { + var salt = data.algorithm.decrypt.kde.kdeparams.salt; + var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10); + var algo = aesid[data.algorithm.decrypt.cipher.algo.join(".")]; + var iv = data.algorithm.decrypt.cipher.iv; + var cipherText = data.subjectPrivateKey; + var keylen = parseInt(algo.split("-")[1], 10) / 8; + var key = compat.pbkdf2Sync(password, salt, iters, keylen, "sha1"); + var cipher = ciphers.createDecipheriv(algo, key, iv); + var out = []; + out.push(cipher.update(cipherText)); + out.push(cipher.final()); + return Buffer.concat(out); + } - exports$1a = StreamCipher; - return exports$1a; + return exports$e$1; } -var exports$19 = {}, - _dewExec$18 = false; -function dew$18() { - if (_dewExec$18) return exports$19; - _dewExec$18 = true; +var _curves$1 = { + "1.3.132.0.10": "secp256k1", + "1.3.132.0.33": "p224", + "1.2.840.10045.3.1.1": "p192", + "1.2.840.10045.3.1.7": "p256", + "1.3.132.0.34": "p384", + "1.3.132.0.35": "p521" +}; + +var exports$d$1 = {}, + _dewExec$d$1 = false; +function dew$d$1() { + if (_dewExec$d$1) return exports$d$1; + _dewExec$d$1 = true; + // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js var Buffer = dew$1T().Buffer; - var MD5 = dew$1Q(); - /* eslint-disable camelcase */ + var createHmac = dew$1C(); + var crt = dew$W$1(); - function EVP_BytesToKey(password, salt, keyBits, ivLen) { - if (!Buffer.isBuffer(password)) password = Buffer.from(password, "binary"); + var EC = dew$y$1().ec; - if (salt) { - if (!Buffer.isBuffer(salt)) salt = Buffer.from(salt, "binary"); - if (salt.length !== 8) throw new RangeError("salt should be Buffer with 8 byte length"); - } + var BN = dew$X$1(); - var keyLen = keyBits / 8; - var key = Buffer.alloc(keyLen); - var iv = Buffer.alloc(ivLen || 0); - var tmp = Buffer.alloc(0); + var parseKeys = dew$e$1(); - while (keyLen > 0 || ivLen > 0) { - var hash = new MD5(); - hash.update(tmp); - hash.update(password); - if (salt) hash.update(salt); - tmp = hash.digest(); - var used = 0; + var curves = _curves$1; - if (keyLen > 0) { - var keyStart = key.length - keyLen; - used = Math.min(keyLen, tmp.length); - tmp.copy(key, keyStart, 0, used); - keyLen -= used; - } + function sign(hash, key, hashType, signType, tag) { + var priv = parseKeys(key); - if (used < tmp.length && ivLen > 0) { - var ivStart = iv.length - ivLen; - var length = Math.min(ivLen, tmp.length - used); - tmp.copy(iv, ivStart, used, used + length); - ivLen -= length; - } + if (priv.curve) { + // rsa keys can be interpreted as ecdsa ones in openssl + if (signType !== "ecdsa" && signType !== "ecdsa/rsa") throw new Error("wrong private key type"); + return ecSign(hash, priv); + } else if (priv.type === "dsa") { + if (signType !== "dsa") throw new Error("wrong private key type"); + return dsaSign(hash, priv, hashType); + } else { + if (signType !== "rsa" && signType !== "ecdsa/rsa") throw new Error("wrong private key type"); } - tmp.fill(0); - return { - key: key, - iv: iv - }; - } - - exports$19 = EVP_BytesToKey; - return exports$19; -} - -var exports$18 = {}, - _dewExec$17 = false; - -var _global$f = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$17() { - if (_dewExec$17) return exports$18; - _dewExec$17 = true; - - var MODES = dew$1d(); - - var AuthCipher = dew$1a(); - - var Buffer = dew$1T().Buffer; - - var StreamCipher = dew$19(); - - var Transform = dew$1G(); + hash = Buffer.concat([tag, hash]); + var len = priv.modulus.byteLength(); + var pad = [0, 1]; - var aes = dew$1c(); + while (hash.length + pad.length + 1 < len) pad.push(255); - var ebtk = dew$18(); + pad.push(0); + var i = -1; - var inherits = dew$f$2(); + while (++i < hash.length) pad.push(hash[i]); - function Cipher(mode, key, iv) { - Transform.call(this || _global$f); - (this || _global$f)._cache = new Splitter(); - (this || _global$f)._cipher = new aes.AES(key); - (this || _global$f)._prev = Buffer.from(iv); - (this || _global$f)._mode = mode; - (this || _global$f)._autopadding = true; + var out = crt(pad, priv); + return out; } - inherits(Cipher, Transform); + function ecSign(hash, priv) { + var curveId = curves[priv.curve.join(".")]; + if (!curveId) throw new Error("unknown curve " + priv.curve.join(".")); + var curve = new EC(curveId); + var key = curve.keyFromPrivate(priv.privateKey); + var out = key.sign(hash); + return Buffer.from(out.toDER()); + } - Cipher.prototype._update = function (data) { - (this || _global$f)._cache.add(data); + function dsaSign(hash, priv, algo) { + var x = priv.params.priv_key; + var p = priv.params.p; + var q = priv.params.q; + var g = priv.params.g; + var r = new BN(0); + var k; + var H = bits2int(hash, q).mod(q); + var s = false; + var kv = getKey(x, q, hash, algo); - var chunk; - var thing; - var out = []; + while (s === false) { + k = makeKey(q, kv, algo); + r = makeR(g, k, p, q); + s = k.invm(q).imul(H.add(x.mul(r))).mod(q); - while (chunk = (this || _global$f)._cache.get()) { - thing = (this || _global$f)._mode.encrypt(this || _global$f, chunk); - out.push(thing); + if (s.cmpn(0) === 0) { + s = false; + r = new BN(0); + } } - return Buffer.concat(out); - }; - - var PADDING = Buffer.alloc(16, 16); - - Cipher.prototype._final = function () { - var chunk = (this || _global$f)._cache.flush(); - - if ((this || _global$f)._autopadding) { - chunk = (this || _global$f)._mode.encrypt(this || _global$f, chunk); + return toDER(r, s); + } - (this || _global$f)._cipher.scrub(); + function toDER(r, s) { + r = r.toArray(); + s = s.toArray(); // Pad values - return chunk; - } + if (r[0] & 128) r = [0].concat(r); + if (s[0] & 128) s = [0].concat(s); + var total = r.length + s.length + 4; + var res = [48, total, 2, r.length]; + res = res.concat(r, [2, s.length], s); + return Buffer.from(res); + } - if (!chunk.equals(PADDING)) { - (this || _global$f)._cipher.scrub(); + function getKey(x, q, hash, algo) { + x = Buffer.from(x.toArray()); - throw new Error("data not multiple of block length"); + if (x.length < q.byteLength()) { + var zeros = Buffer.alloc(q.byteLength() - x.length); + x = Buffer.concat([zeros, x]); } - }; - Cipher.prototype.setAutoPadding = function (setTo) { - (this || _global$f)._autopadding = !!setTo; - return this || _global$f; - }; + var hlen = hash.length; + var hbits = bits2octets(hash, q); + var v = Buffer.alloc(hlen); + v.fill(1); + var k = Buffer.alloc(hlen); + k = createHmac(algo, k).update(v).update(Buffer.from([0])).update(x).update(hbits).digest(); + v = createHmac(algo, k).update(v).digest(); + k = createHmac(algo, k).update(v).update(Buffer.from([1])).update(x).update(hbits).digest(); + v = createHmac(algo, k).update(v).digest(); + return { + k: k, + v: v + }; + } - function Splitter() { - (this || _global$f).cache = Buffer.allocUnsafe(0); + function bits2int(obits, q) { + var bits = new BN(obits); + var shift = (obits.length << 3) - q.bitLength(); + if (shift > 0) bits.ishrn(shift); + return bits; } - Splitter.prototype.add = function (data) { - (this || _global$f).cache = Buffer.concat([(this || _global$f).cache, data]); - }; - - Splitter.prototype.get = function () { - if ((this || _global$f).cache.length > 15) { - var out = (this || _global$f).cache.slice(0, 16); + function bits2octets(bits, q) { + bits = bits2int(bits, q); + bits = bits.mod(q); + var out = Buffer.from(bits.toArray()); - (this || _global$f).cache = (this || _global$f).cache.slice(16); - return out; + if (out.length < q.byteLength()) { + var zeros = Buffer.alloc(q.byteLength() - out.length); + out = Buffer.concat([zeros, out]); } - return null; - }; - - Splitter.prototype.flush = function () { - var len = 16 - (this || _global$f).cache.length; - var padBuff = Buffer.allocUnsafe(len); - var i = -1; + return out; + } - while (++i < len) { - padBuff.writeUInt8(len, i); - } + function makeKey(q, kv, algo) { + var t; + var k; - return Buffer.concat([(this || _global$f).cache, padBuff]); - }; + do { + t = Buffer.alloc(0); - function createCipheriv(suite, password, iv) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - if (typeof password === "string") password = Buffer.from(password); - if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); - if (typeof iv === "string") iv = Buffer.from(iv); - if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); + while (t.length * 8 < q.bitLength()) { + kv.v = createHmac(algo, kv.k).update(kv.v).digest(); + t = Buffer.concat([t, kv.v]); + } - if (config.type === "stream") { - return new StreamCipher(config.module, password, iv); - } else if (config.type === "auth") { - return new AuthCipher(config.module, password, iv); - } + k = bits2int(t, q); + kv.k = createHmac(algo, kv.k).update(kv.v).update(Buffer.from([0])).digest(); + kv.v = createHmac(algo, kv.k).update(kv.v).digest(); + } while (k.cmp(q) !== -1); - return new Cipher(config.module, password, iv); + return k; } - function createCipher(suite, password) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - var keys = ebtk(password, false, config.key, config.iv); - return createCipheriv(suite, keys.key, keys.iv); + function makeR(g, k, p, q) { + return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q); } - exports$18.createCipheriv = createCipheriv; - exports$18.createCipher = createCipher; - return exports$18; + exports$d$1 = sign; + exports$d$1.getKey = getKey; + exports$d$1.makeKey = makeKey; + return exports$d$1; } -var exports$17 = {}, - _dewExec$16 = false; - -var _global$e = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$16() { - if (_dewExec$16) return exports$17; - _dewExec$16 = true; - - var AuthCipher = dew$1a(); +var exports$c$1 = {}, + _dewExec$c$1 = false; +function dew$c$1() { + if (_dewExec$c$1) return exports$c$1; + _dewExec$c$1 = true; + // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js var Buffer = dew$1T().Buffer; - var MODES = dew$1d(); - - var StreamCipher = dew$19(); + var BN = dew$X$1(); - var Transform = dew$1G(); + var EC = dew$y$1().ec; - var aes = dew$1c(); + var parseKeys = dew$e$1(); - var ebtk = dew$18(); + var curves = _curves$1; - var inherits = dew$f$2(); + function verify(sig, hash, key, signType, tag) { + var pub = parseKeys(key); - function Decipher(mode, key, iv) { - Transform.call(this || _global$e); - (this || _global$e)._cache = new Splitter(); - (this || _global$e)._last = void 0; - (this || _global$e)._cipher = new aes.AES(key); - (this || _global$e)._prev = Buffer.from(iv); - (this || _global$e)._mode = mode; - (this || _global$e)._autopadding = true; - } + if (pub.type === "ec") { + // rsa keys can be interpreted as ecdsa ones in openssl + if (signType !== "ecdsa" && signType !== "ecdsa/rsa") throw new Error("wrong public key type"); + return ecVerify(sig, hash, pub); + } else if (pub.type === "dsa") { + if (signType !== "dsa") throw new Error("wrong public key type"); + return dsaVerify(sig, hash, pub); + } else { + if (signType !== "rsa" && signType !== "ecdsa/rsa") throw new Error("wrong public key type"); + } - inherits(Decipher, Transform); + hash = Buffer.concat([tag, hash]); + var len = pub.modulus.byteLength(); + var pad = [1]; + var padNum = 0; - Decipher.prototype._update = function (data) { - (this || _global$e)._cache.add(data); + while (hash.length + pad.length + 2 < len) { + pad.push(255); + padNum++; + } - var chunk; - var thing; - var out = []; + pad.push(0); + var i = -1; - while (chunk = (this || _global$e)._cache.get((this || _global$e)._autopadding)) { - thing = (this || _global$e)._mode.decrypt(this || _global$e, chunk); - out.push(thing); + while (++i < hash.length) { + pad.push(hash[i]); } - return Buffer.concat(out); - }; - - Decipher.prototype._final = function () { - var chunk = (this || _global$e)._cache.flush(); + pad = Buffer.from(pad); + var red = BN.mont(pub.modulus); + sig = new BN(sig).toRed(red); + sig = sig.redPow(new BN(pub.publicExponent)); + sig = Buffer.from(sig.fromRed().toArray()); + var out = padNum < 8 ? 1 : 0; + len = Math.min(sig.length, pad.length); + if (sig.length !== pad.length) out = 1; + i = -1; - if ((this || _global$e)._autopadding) { - return unpad((this || _global$e)._mode.decrypt(this || _global$e, chunk)); - } else if (chunk) { - throw new Error("data not multiple of block length"); - } - }; + while (++i < len) out |= sig[i] ^ pad[i]; - Decipher.prototype.setAutoPadding = function (setTo) { - (this || _global$e)._autopadding = !!setTo; - return this || _global$e; - }; + return out === 0; + } - function Splitter() { - (this || _global$e).cache = Buffer.allocUnsafe(0); + function ecVerify(sig, hash, pub) { + var curveId = curves[pub.data.algorithm.curve.join(".")]; + if (!curveId) throw new Error("unknown curve " + pub.data.algorithm.curve.join(".")); + var curve = new EC(curveId); + var pubkey = pub.data.subjectPrivateKey.data; + return curve.verify(hash, sig, pubkey); } - Splitter.prototype.add = function (data) { - (this || _global$e).cache = Buffer.concat([(this || _global$e).cache, data]); - }; + function dsaVerify(sig, hash, pub) { + var p = pub.data.p; + var q = pub.data.q; + var g = pub.data.g; + var y = pub.data.pub_key; + var unpacked = parseKeys.signature.decode(sig, "der"); + var s = unpacked.s; + var r = unpacked.r; + checkValue(s, q); + checkValue(r, q); + var montp = BN.mont(p); + var w = s.invm(q); + var v = g.toRed(montp).redPow(new BN(hash).mul(w).mod(q)).fromRed().mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed()).mod(p).mod(q); + return v.cmp(r) === 0; + } - Splitter.prototype.get = function (autoPadding) { - var out; + function checkValue(b, q) { + if (b.cmpn(0) <= 0) throw new Error("invalid sig"); + if (b.cmp(q) >= q) throw new Error("invalid sig"); + } - if (autoPadding) { - if ((this || _global$e).cache.length > 16) { - out = (this || _global$e).cache.slice(0, 16); - (this || _global$e).cache = (this || _global$e).cache.slice(16); - return out; - } - } else { - if ((this || _global$e).cache.length >= 16) { - out = (this || _global$e).cache.slice(0, 16); - (this || _global$e).cache = (this || _global$e).cache.slice(16); - return out; - } - } + exports$c$1 = verify; + return exports$c$1; +} - return null; - }; +var exports$b$1 = {}, + _dewExec$b$1 = false; - Splitter.prototype.flush = function () { - if ((this || _global$e).cache.length) return (this || _global$e).cache; - }; +var _global$4$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function unpad(last) { - var padded = last[15]; +function dew$b$1() { + if (_dewExec$b$1) return exports$b$1; + _dewExec$b$1 = true; - if (padded < 1 || padded > 16) { - throw new Error("unable to decrypt data"); - } + var Buffer = dew$1T().Buffer; - var i = -1; + var createHash = dew$1F(); - while (++i < padded) { - if (last[i + (16 - padded)] !== padded) { - throw new Error("unable to decrypt data"); - } - } + var stream = dew$1V(); - if (padded === 16) return; - return last.slice(0, 16 - padded); - } + var inherits = dew$f$2(); - function createDecipheriv(suite, password, iv) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - if (typeof iv === "string") iv = Buffer.from(iv); - if (config.mode !== "GCM" && iv.length !== config.iv) throw new TypeError("invalid iv length " + iv.length); - if (typeof password === "string") password = Buffer.from(password); - if (password.length !== config.key / 8) throw new TypeError("invalid key length " + password.length); + var sign = dew$d$1(); - if (config.type === "stream") { - return new StreamCipher(config.module, password, iv, true); - } else if (config.type === "auth") { - return new AuthCipher(config.module, password, iv, true); - } + var verify = dew$c$1(); - return new Decipher(config.module, password, iv); - } + var algorithms = _algorithms; + Object.keys(algorithms).forEach(function (key) { + algorithms[key].id = Buffer.from(algorithms[key].id, "hex"); + algorithms[key.toLowerCase()] = algorithms[key]; + }); - function createDecipher(suite, password) { - var config = MODES[suite.toLowerCase()]; - if (!config) throw new TypeError("invalid suite type"); - var keys = ebtk(password, false, config.key, config.iv); - return createDecipheriv(suite, keys.key, keys.iv); + function Sign(algorithm) { + stream.Writable.call(this || _global$4$1); + var data = algorithms[algorithm]; + if (!data) throw new Error("Unknown message digest"); + (this || _global$4$1)._hashType = data.hash; + (this || _global$4$1)._hash = createHash(data.hash); + (this || _global$4$1)._tag = data.id; + (this || _global$4$1)._signType = data.sign; } - exports$17.createDecipher = createDecipher; - exports$17.createDecipheriv = createDecipheriv; - return exports$17; -} - -var exports$16 = {}, - _dewExec$15 = false; -function dew$15() { - if (_dewExec$15) return exports$16; - _dewExec$15 = true; - - var ciphers = dew$17(); + inherits(Sign, stream.Writable); - var deciphers = dew$16(); + Sign.prototype._write = function _write(data, _, done) { + (this || _global$4$1)._hash.update(data); - var modes = _list; + done(); + }; - function getCiphers() { - return Object.keys(modes); - } + Sign.prototype.update = function update(data, enc) { + if (typeof data === "string") data = Buffer.from(data, enc); - exports$16.createCipher = exports$16.Cipher = ciphers.createCipher; - exports$16.createCipheriv = exports$16.Cipheriv = ciphers.createCipheriv; - exports$16.createDecipher = exports$16.Decipher = deciphers.createDecipher; - exports$16.createDecipheriv = exports$16.Decipheriv = deciphers.createDecipheriv; - exports$16.listCiphers = exports$16.getCiphers = getCiphers; - return exports$16; -} + (this || _global$4$1)._hash.update(data); -var exports$15 = {}, - _dewExec$14 = false; -function dew$14() { - if (_dewExec$14) return exports$15; - _dewExec$14 = true; - exports$15["des-ecb"] = { - key: 8, - iv: 0 - }; - exports$15["des-cbc"] = exports$15.des = { - key: 8, - iv: 8 - }; - exports$15["des-ede3-cbc"] = exports$15.des3 = { - key: 24, - iv: 8 - }; - exports$15["des-ede3"] = { - key: 24, - iv: 0 - }; - exports$15["des-ede-cbc"] = { - key: 16, - iv: 8 - }; - exports$15["des-ede"] = { - key: 16, - iv: 0 + return this || _global$4$1; }; - return exports$15; -} -var exports$14 = {}, - _dewExec$13 = false; -function dew$13() { - if (_dewExec$13) return exports$14; - _dewExec$13 = true; + Sign.prototype.sign = function signMethod(key, enc) { + this.end(); - var DES = dew$1n(); + var hash = (this || _global$4$1)._hash.digest(); - var aes = dew$15(); + var sig = sign(hash, key, (this || _global$4$1)._hashType, (this || _global$4$1)._signType, (this || _global$4$1)._tag); + return enc ? sig.toString(enc) : sig; + }; - var aesModes = dew$1d(); + function Verify(algorithm) { + stream.Writable.call(this || _global$4$1); + var data = algorithms[algorithm]; + if (!data) throw new Error("Unknown message digest"); + (this || _global$4$1)._hash = createHash(data.hash); + (this || _global$4$1)._tag = data.id; + (this || _global$4$1)._signType = data.sign; + } - var desModes = dew$14(); + inherits(Verify, stream.Writable); - var ebtk = dew$18(); + Verify.prototype._write = function _write(data, _, done) { + (this || _global$4$1)._hash.update(data); - function createCipher(suite, password) { - suite = suite.toLowerCase(); - var keyLen, ivLen; + done(); + }; - if (aesModes[suite]) { - keyLen = aesModes[suite].key; - ivLen = aesModes[suite].iv; - } else if (desModes[suite]) { - keyLen = desModes[suite].key * 8; - ivLen = desModes[suite].iv; - } else { - throw new TypeError("invalid suite type"); - } + Verify.prototype.update = function update(data, enc) { + if (typeof data === "string") data = Buffer.from(data, enc); - var keys = ebtk(password, false, keyLen, ivLen); - return createCipheriv(suite, keys.key, keys.iv); - } + (this || _global$4$1)._hash.update(data); - function createDecipher(suite, password) { - suite = suite.toLowerCase(); - var keyLen, ivLen; + return this || _global$4$1; + }; - if (aesModes[suite]) { - keyLen = aesModes[suite].key; - ivLen = aesModes[suite].iv; - } else if (desModes[suite]) { - keyLen = desModes[suite].key * 8; - ivLen = desModes[suite].iv; - } else { - throw new TypeError("invalid suite type"); - } + Verify.prototype.verify = function verifyMethod(key, sig, enc) { + if (typeof sig === "string") sig = Buffer.from(sig, enc); + this.end(); - var keys = ebtk(password, false, keyLen, ivLen); - return createDecipheriv(suite, keys.key, keys.iv); - } + var hash = (this || _global$4$1)._hash.digest(); - function createCipheriv(suite, key, iv) { - suite = suite.toLowerCase(); - if (aesModes[suite]) return aes.createCipheriv(suite, key, iv); - if (desModes[suite]) return new DES({ - key: key, - iv: iv, - mode: suite - }); - throw new TypeError("invalid suite type"); - } + return verify(sig, hash, key, (this || _global$4$1)._signType, (this || _global$4$1)._tag); + }; - function createDecipheriv(suite, key, iv) { - suite = suite.toLowerCase(); - if (aesModes[suite]) return aes.createDecipheriv(suite, key, iv); - if (desModes[suite]) return new DES({ - key: key, - iv: iv, - mode: suite, - decrypt: true - }); - throw new TypeError("invalid suite type"); + function createSign(algorithm) { + return new Sign(algorithm); } - function getCiphers() { - return Object.keys(desModes).concat(aes.getCiphers()); + function createVerify(algorithm) { + return new Verify(algorithm); } - exports$14.createCipher = exports$14.Cipher = createCipher; - exports$14.createCipheriv = exports$14.Cipheriv = createCipheriv; - exports$14.createDecipher = exports$14.Decipher = createDecipher; - exports$14.createDecipheriv = exports$14.Decipheriv = createDecipheriv; - exports$14.listCiphers = exports$14.getCiphers = getCiphers; - return exports$14; + exports$b$1 = { + Sign: createSign, + Verify: createVerify, + createSign: createSign, + createVerify: createVerify + }; + return exports$b$1; } -var exports$13 = {}, - _dewExec$12 = false; -var module$6 = { - exports: exports$13 +var exports$a$1 = {}, + _dewExec$a$1 = false; +var module$1$1 = { + exports: exports$a$1 }; -var _global$d = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$3$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$12() { - if (_dewExec$12) return module$6.exports; - _dewExec$12 = true; +function dew$a$1() { + if (_dewExec$a$1) return module$1$1.exports; + _dewExec$a$1 = true; (function (module, exports) { @@ -19314,11 +53059,11 @@ function dew$12() { return number; } - (this || _global$d).negative = 0; - (this || _global$d).words = null; - (this || _global$d).length = 0; // Reduction context + (this || _global$3$1).negative = 0; + (this || _global$3$1).words = null; + (this || _global$3$1).length = 0; // Reduction context - (this || _global$d).red = null; + (this || _global$3$1).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -19385,7 +53130,7 @@ function dew$12() { if (number[0] === "-") { start++; - (this || _global$d).negative = 1; + (this || _global$3$1).negative = 1; } if (start < number.length) { @@ -19403,21 +53148,21 @@ function dew$12() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$d).negative = 1; + (this || _global$3$1).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$d).words = [number & 67108863]; - (this || _global$d).length = 1; + (this || _global$3$1).words = [number & 67108863]; + (this || _global$3$1).length = 1; } else if (number < 4503599627370496) { - (this || _global$d).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$d).length = 2; + (this || _global$3$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$3$1).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$d).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$d).length = 3; + (this || _global$3$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$3$1).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -19430,16 +53175,16 @@ function dew$12() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$d).words = [0]; - (this || _global$d).length = 1; - return this || _global$d; + (this || _global$3$1).words = [0]; + (this || _global$3$1).length = 1; + return this || _global$3$1; } - (this || _global$d).length = Math.ceil(number.length / 3); - (this || _global$d).words = new Array((this || _global$d).length); + (this || _global$3$1).length = Math.ceil(number.length / 3); + (this || _global$3$1).words = new Array((this || _global$3$1).length); - for (var i = 0; i < (this || _global$d).length; i++) { - (this || _global$d).words[i] = 0; + for (var i = 0; i < (this || _global$3$1).length; i++) { + (this || _global$3$1).words[i] = 0; } var j, w; @@ -19448,8 +53193,8 @@ function dew$12() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$d).words[j] |= w << off & 67108863; - (this || _global$d).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$3$1).words[j] |= w << off & 67108863; + (this || _global$3$1).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -19460,8 +53205,8 @@ function dew$12() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$d).words[j] |= w << off & 67108863; - (this || _global$d).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$3$1).words[j] |= w << off & 67108863; + (this || _global$3$1).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -19498,11 +53243,11 @@ function dew$12() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$d).length = Math.ceil((number.length - start) / 6); - (this || _global$d).words = new Array((this || _global$d).length); + (this || _global$3$1).length = Math.ceil((number.length - start) / 6); + (this || _global$3$1).words = new Array((this || _global$3$1).length); - for (var i = 0; i < (this || _global$d).length; i++) { - (this || _global$d).words[i] = 0; + for (var i = 0; i < (this || _global$3$1).length; i++) { + (this || _global$3$1).words[i] = 0; } // 24-bits chunks @@ -19513,12 +53258,12 @@ function dew$12() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$d).words[j] |= w & 67108863; + (this || _global$3$1).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$d).words[j] |= w >>> 26; + (this || _global$3$1).words[j] |= w >>> 26; } else { off += 8; } @@ -19528,12 +53273,12 @@ function dew$12() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$d).words[j] |= w & 67108863; + (this || _global$3$1).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$d).words[j] |= w >>> 26; + (this || _global$3$1).words[j] |= w >>> 26; } else { off += 8; } @@ -19565,8 +53310,8 @@ function dew$12() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$d).words = [0]; - (this || _global$d).length = 1; // Find length of limb in base + (this || _global$3$1).words = [0]; + (this || _global$3$1).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -19583,8 +53328,8 @@ function dew$12() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$d).words[0] + word < 67108864) { - (this || _global$d).words[0] += word; + if ((this || _global$3$1).words[0] + word < 67108864) { + (this || _global$3$1).words[0] += word; } else { this._iaddn(word); } @@ -19600,8 +53345,8 @@ function dew$12() { this.imuln(pow); - if ((this || _global$d).words[0] + word < 67108864) { - (this || _global$d).words[0] += word; + if ((this || _global$3$1).words[0] + word < 67108864) { + (this || _global$3$1).words[0] += word; } else { this._iaddn(word); } @@ -19611,15 +53356,15 @@ function dew$12() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$d).length); + dest.words = new Array((this || _global$3$1).length); - for (var i = 0; i < (this || _global$d).length; i++) { - dest.words[i] = (this || _global$d).words[i]; + for (var i = 0; i < (this || _global$3$1).length; i++) { + dest.words[i] = (this || _global$3$1).words[i]; } - dest.length = (this || _global$d).length; - dest.negative = (this || _global$d).negative; - dest.red = (this || _global$d).red; + dest.length = (this || _global$3$1).length; + dest.negative = (this || _global$3$1).negative; + dest.red = (this || _global$3$1).red; }; BN.prototype.clone = function clone() { @@ -19629,17 +53374,17 @@ function dew$12() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$d).length < size) { - (this || _global$d).words[(this || _global$d).length++] = 0; + while ((this || _global$3$1).length < size) { + (this || _global$3$1).words[(this || _global$3$1).length++] = 0; } - return this || _global$d; + return this || _global$3$1; }; // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$d).length > 1 && (this || _global$d).words[(this || _global$d).length - 1] === 0) { - (this || _global$d).length--; + while ((this || _global$3$1).length > 1 && (this || _global$3$1).words[(this || _global$3$1).length - 1] === 0) { + (this || _global$3$1).length--; } return this._normSign(); @@ -19647,15 +53392,15 @@ function dew$12() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$d).length === 1 && (this || _global$d).words[0] === 0) { - (this || _global$d).negative = 0; + if ((this || _global$3$1).length === 1 && (this || _global$3$1).words[0] === 0) { + (this || _global$3$1).negative = 0; } - return this || _global$d; + return this || _global$3$1; }; BN.prototype.inspect = function inspect() { - return ((this || _global$d).red ? ""; + return ((this || _global$3$1).red ? ""; }; /* var zeros = []; @@ -19699,12 +53444,12 @@ function dew$12() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$d).length; i++) { - var w = (this || _global$d).words[i]; + for (var i = 0; i < (this || _global$3$1).length; i++) { + var w = (this || _global$3$1).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$d).length - 1) { + if (carry !== 0 || i !== (this || _global$3$1).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -19726,7 +53471,7 @@ function dew$12() { out = "0" + out; } - if ((this || _global$d).negative !== 0) { + if ((this || _global$3$1).negative !== 0) { out = "-" + out; } @@ -19761,7 +53506,7 @@ function dew$12() { out = "0" + out; } - if ((this || _global$d).negative !== 0) { + if ((this || _global$3$1).negative !== 0) { out = "-" + out; } @@ -19772,18 +53517,18 @@ function dew$12() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$d).words[0]; + var ret = (this || _global$3$1).words[0]; - if ((this || _global$d).length === 2) { - ret += (this || _global$d).words[1] * 67108864; - } else if ((this || _global$d).length === 3 && (this || _global$d).words[2] === 1) { + if ((this || _global$3$1).length === 2) { + ret += (this || _global$3$1).words[1] * 67108864; + } else if ((this || _global$3$1).length === 3 && (this || _global$3$1).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$d).words[1] * 67108864; - } else if ((this || _global$d).length > 2) { + ret += 4503599627370496 + (this || _global$3$1).words[1] * 67108864; + } else if ((this || _global$3$1).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$d).negative !== 0 ? -ret : ret; + return (this || _global$3$1).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -19904,11 +53649,11 @@ function dew$12() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$d).words[(this || _global$d).length - 1]; + var w = (this || _global$3$1).words[(this || _global$3$1).length - 1]; var hi = this._countBits(w); - return ((this || _global$d).length - 1) * 26 + hi; + return ((this || _global$3$1).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -19928,8 +53673,8 @@ function dew$12() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$d).length; i++) { - var b = this._zeroBits((this || _global$d).words[i]); + for (var i = 0; i < (this || _global$3$1).length; i++) { + var b = this._zeroBits((this || _global$3$1).words[i]); r += b; if (b !== 26) break; @@ -19943,7 +53688,7 @@ function dew$12() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$d).negative !== 0) { + if ((this || _global$3$1).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -19959,7 +53704,7 @@ function dew$12() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$d).negative !== 0; + return (this || _global$3$1).negative !== 0; }; // Return negative clone of `this` @@ -19969,39 +53714,39 @@ function dew$12() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$d).negative ^= 1; + (this || _global$3$1).negative ^= 1; } - return this || _global$d; + return this || _global$3$1; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$d).length < num.length) { - (this || _global$d).words[(this || _global$d).length++] = 0; + while ((this || _global$3$1).length < num.length) { + (this || _global$3$1).words[(this || _global$3$1).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$d).words[i] = (this || _global$d).words[i] | num.words[i]; + (this || _global$3$1).words[i] = (this || _global$3$1).words[i] | num.words[i]; } return this.strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$d).negative | num.negative) === 0); + assert(((this || _global$3$1).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$d).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$3$1); }; BN.prototype.uor = function uor(num) { - if ((this || _global$d).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$3$1); }; // And `num` with `this` in-place @@ -20009,34 +53754,34 @@ function dew$12() { // b = min-length(num, this) var b; - if ((this || _global$d).length > num.length) { + if ((this || _global$3$1).length > num.length) { b = num; } else { - b = this || _global$d; + b = this || _global$3$1; } for (var i = 0; i < b.length; i++) { - (this || _global$d).words[i] = (this || _global$d).words[i] & num.words[i]; + (this || _global$3$1).words[i] = (this || _global$3$1).words[i] & num.words[i]; } - (this || _global$d).length = b.length; + (this || _global$3$1).length = b.length; return this.strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$d).negative | num.negative) === 0); + assert(((this || _global$3$1).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$d).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$3$1); }; BN.prototype.uand = function uand(num) { - if ((this || _global$d).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$3$1); }; // Xor `num` with `this` in-place @@ -20045,42 +53790,42 @@ function dew$12() { var a; var b; - if ((this || _global$d).length > num.length) { - a = this || _global$d; + if ((this || _global$3$1).length > num.length) { + a = this || _global$3$1; b = num; } else { a = num; - b = this || _global$d; + b = this || _global$3$1; } for (var i = 0; i < b.length; i++) { - (this || _global$d).words[i] = a.words[i] ^ b.words[i]; + (this || _global$3$1).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$d) !== a) { + if ((this || _global$3$1) !== a) { for (; i < a.length; i++) { - (this || _global$d).words[i] = a.words[i]; + (this || _global$3$1).words[i] = a.words[i]; } } - (this || _global$d).length = a.length; + (this || _global$3$1).length = a.length; return this.strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$d).negative | num.negative) === 0); + assert(((this || _global$3$1).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$d).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$3$1); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$d).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$3$1); }; // Not ``this`` with ``width`` bitwidth @@ -20097,12 +53842,12 @@ function dew$12() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$d).words[i] = ~(this || _global$d).words[i] & 67108863; + (this || _global$3$1).words[i] = ~(this || _global$3$1).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$d).words[i] = ~(this || _global$d).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$3$1).words[i] = ~(this || _global$3$1).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -20122,9 +53867,9 @@ function dew$12() { this._expand(off + 1); if (val) { - (this || _global$d).words[off] = (this || _global$d).words[off] | 1 << wbit; + (this || _global$3$1).words[off] = (this || _global$3$1).words[off] | 1 << wbit; } else { - (this || _global$d).words[off] = (this || _global$d).words[off] & ~(1 << wbit); + (this || _global$3$1).words[off] = (this || _global$3$1).words[off] & ~(1 << wbit); } return this.strip(); @@ -20134,12 +53879,12 @@ function dew$12() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$d).negative !== 0 && num.negative === 0) { - (this || _global$d).negative = 0; + if ((this || _global$3$1).negative !== 0 && num.negative === 0) { + (this || _global$3$1).negative = 0; r = this.isub(num); - (this || _global$d).negative ^= 1; + (this || _global$3$1).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$d).negative === 0 && num.negative !== 0) { + } else if ((this || _global$3$1).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -20149,60 +53894,60 @@ function dew$12() { var a, b; - if ((this || _global$d).length > num.length) { - a = this || _global$d; + if ((this || _global$3$1).length > num.length) { + a = this || _global$3$1; b = num; } else { a = num; - b = this || _global$d; + b = this || _global$3$1; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$d).words[i] = r & 67108863; + (this || _global$3$1).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$d).words[i] = r & 67108863; + (this || _global$3$1).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$d).length = a.length; + (this || _global$3$1).length = a.length; if (carry !== 0) { - (this || _global$d).words[(this || _global$d).length] = carry; - (this || _global$d).length++; // Copy the rest of the words - } else if (a !== (this || _global$d)) { + (this || _global$3$1).words[(this || _global$3$1).length] = carry; + (this || _global$3$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$3$1)) { for (; i < a.length; i++) { - (this || _global$d).words[i] = a.words[i]; + (this || _global$3$1).words[i] = a.words[i]; } } - return this || _global$d; + return this || _global$3$1; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$d).negative === 0) { + if (num.negative !== 0 && (this || _global$3$1).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$d).negative !== 0) { - (this || _global$d).negative = 0; - res = num.sub(this || _global$d); - (this || _global$d).negative = 1; + } else if (num.negative === 0 && (this || _global$3$1).negative !== 0) { + (this || _global$3$1).negative = 0; + res = num.sub(this || _global$3$1); + (this || _global$3$1).negative = 1; return res; } - if ((this || _global$d).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$d); + if ((this || _global$3$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$3$1); }; // Subtract `num` from `this` in-place @@ -20213,10 +53958,10 @@ function dew$12() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$d).negative !== 0) { - (this || _global$d).negative = 0; + } else if ((this || _global$3$1).negative !== 0) { + (this || _global$3$1).negative = 0; this.iadd(num); - (this || _global$d).negative = 1; + (this || _global$3$1).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -20224,21 +53969,21 @@ function dew$12() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$d).negative = 0; - (this || _global$d).length = 1; - (this || _global$d).words[0] = 0; - return this || _global$d; + (this || _global$3$1).negative = 0; + (this || _global$3$1).length = 1; + (this || _global$3$1).words[0] = 0; + return this || _global$3$1; } // a > b var a, b; if (cmp > 0) { - a = this || _global$d; + a = this || _global$3$1; b = num; } else { a = num; - b = this || _global$d; + b = this || _global$3$1; } var carry = 0; @@ -20246,26 +53991,26 @@ function dew$12() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$d).words[i] = r & 67108863; + (this || _global$3$1).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$d).words[i] = r & 67108863; + (this || _global$3$1).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$d)) { + if (carry === 0 && i < a.length && a !== (this || _global$3$1)) { for (; i < a.length; i++) { - (this || _global$d).words[i] = a.words[i]; + (this || _global$3$1).words[i] = a.words[i]; } } - (this || _global$d).length = Math.max((this || _global$d).length, i); + (this || _global$3$1).length = Math.max((this || _global$3$1).length, i); - if (a !== (this || _global$d)) { - (this || _global$d).negative = 1; + if (a !== (this || _global$3$1)) { + (this || _global$3$1).negative = 1; } return this.strip(); @@ -20968,16 +54713,16 @@ function dew$12() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$d).length + num.length; + var len = (this || _global$3$1).length + num.length; - if ((this || _global$d).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$d, num, out); + if ((this || _global$3$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$3$1, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$d, num, out); + res = smallMulTo(this || _global$3$1, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$d, num, out); + res = bigMulTo(this || _global$3$1, num, out); } else { - res = jumboMulTo(this || _global$d, num, out); + res = jumboMulTo(this || _global$3$1, num, out); } return res; @@ -20986,8 +54731,8 @@ function dew$12() { function FFTM(x, y) { - (this || _global$d).x = x; - (this || _global$d).y = y; + (this || _global$3$1).x = x; + (this || _global$3$1).y = y; } FFTM.prototype.makeRBT = function makeRBT(N) { @@ -21168,20 +54913,20 @@ function dew$12() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$d).length + num.length); + out.words = new Array((this || _global$3$1).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$d).length + num.length); - return jumboMulTo(this || _global$d, num, out); + out.words = new Array((this || _global$3$1).length + num.length); + return jumboMulTo(this || _global$3$1, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$d); + return this.clone().mulTo(num, this || _global$3$1); }; BN.prototype.imuln = function imuln(num) { @@ -21190,22 +54935,22 @@ function dew$12() { var carry = 0; - for (var i = 0; i < (this || _global$d).length; i++) { - var w = ((this || _global$d).words[i] | 0) * num; + for (var i = 0; i < (this || _global$3$1).length; i++) { + var w = ((this || _global$3$1).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$d).words[i] = lo & 67108863; + (this || _global$3$1).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$d).words[i] = carry; - (this || _global$d).length++; + (this || _global$3$1).words[i] = carry; + (this || _global$3$1).length++; } - return this || _global$d; + return this || _global$3$1; }; BN.prototype.muln = function muln(num) { @@ -21214,7 +54959,7 @@ function dew$12() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$d); + return this.mul(this || _global$3$1); }; // `this` * `this` in-place @@ -21227,7 +54972,7 @@ function dew$12() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$d; + var res = this || _global$3$1; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -21254,29 +54999,29 @@ function dew$12() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$d).length; i++) { - var newCarry = (this || _global$d).words[i] & carryMask; - var c = ((this || _global$d).words[i] | 0) - newCarry << r; - (this || _global$d).words[i] = c | carry; + for (i = 0; i < (this || _global$3$1).length; i++) { + var newCarry = (this || _global$3$1).words[i] & carryMask; + var c = ((this || _global$3$1).words[i] | 0) - newCarry << r; + (this || _global$3$1).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$d).words[i] = carry; - (this || _global$d).length++; + (this || _global$3$1).words[i] = carry; + (this || _global$3$1).length++; } } if (s !== 0) { - for (i = (this || _global$d).length - 1; i >= 0; i--) { - (this || _global$d).words[i + s] = (this || _global$d).words[i]; + for (i = (this || _global$3$1).length - 1; i >= 0; i--) { + (this || _global$3$1).words[i + s] = (this || _global$3$1).words[i]; } for (i = 0; i < s; i++) { - (this || _global$d).words[i] = 0; + (this || _global$3$1).words[i] = 0; } - (this || _global$d).length += s; + (this || _global$3$1).length += s; } return this.strip(); @@ -21284,7 +55029,7 @@ function dew$12() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$d).negative === 0); + assert((this || _global$3$1).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -21302,7 +55047,7 @@ function dew$12() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$d).length); + var s = Math.min((bits - r) / 26, (this || _global$3$1).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -21310,28 +55055,28 @@ function dew$12() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$d).words[i]; + maskedWords.words[i] = (this || _global$3$1).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$d).length > s) { - (this || _global$d).length -= s; + if (s === 0) ; else if ((this || _global$3$1).length > s) { + (this || _global$3$1).length -= s; - for (i = 0; i < (this || _global$d).length; i++) { - (this || _global$d).words[i] = (this || _global$d).words[i + s]; + for (i = 0; i < (this || _global$3$1).length; i++) { + (this || _global$3$1).words[i] = (this || _global$3$1).words[i + s]; } } else { - (this || _global$d).words[0] = 0; - (this || _global$d).length = 1; + (this || _global$3$1).words[0] = 0; + (this || _global$3$1).length = 1; } var carry = 0; - for (i = (this || _global$d).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$d).words[i] | 0; - (this || _global$d).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$3$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$3$1).words[i] | 0; + (this || _global$3$1).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -21340,9 +55085,9 @@ function dew$12() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$d).length === 0) { - (this || _global$d).words[0] = 0; - (this || _global$d).length = 1; + if ((this || _global$3$1).length === 0) { + (this || _global$3$1).words[0] = 0; + (this || _global$3$1).length = 1; } return this.strip(); @@ -21350,7 +55095,7 @@ function dew$12() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$d).negative === 0); + assert((this || _global$3$1).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -21379,9 +55124,9 @@ function dew$12() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$d).length <= s) return false; // Check bit and return + if ((this || _global$3$1).length <= s) return false; // Check bit and return - var w = (this || _global$d).words[s]; + var w = (this || _global$3$1).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -21390,21 +55135,21 @@ function dew$12() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$d).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$3$1).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$d).length <= s) { - return this || _global$d; + if ((this || _global$3$1).length <= s) { + return this || _global$3$1; } if (r !== 0) { s++; } - (this || _global$d).length = Math.min(s, (this || _global$d).length); + (this || _global$3$1).length = Math.min(s, (this || _global$3$1).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$d).words[(this || _global$d).length - 1] &= mask; + (this || _global$3$1).words[(this || _global$3$1).length - 1] &= mask; } return this.strip(); @@ -21421,17 +55166,17 @@ function dew$12() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$d).negative !== 0) { - if ((this || _global$d).length === 1 && ((this || _global$d).words[0] | 0) < num) { - (this || _global$d).words[0] = num - ((this || _global$d).words[0] | 0); - (this || _global$d).negative = 0; - return this || _global$d; + if ((this || _global$3$1).negative !== 0) { + if ((this || _global$3$1).length === 1 && ((this || _global$3$1).words[0] | 0) < num) { + (this || _global$3$1).words[0] = num - ((this || _global$3$1).words[0] | 0); + (this || _global$3$1).negative = 0; + return this || _global$3$1; } - (this || _global$d).negative = 0; + (this || _global$3$1).negative = 0; this.isubn(num); - (this || _global$d).negative = 1; - return this || _global$d; + (this || _global$3$1).negative = 1; + return this || _global$3$1; } // Add without checks @@ -21439,20 +55184,20 @@ function dew$12() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$d).words[0] += num; // Carry + (this || _global$3$1).words[0] += num; // Carry - for (var i = 0; i < (this || _global$d).length && (this || _global$d).words[i] >= 67108864; i++) { - (this || _global$d).words[i] -= 67108864; + for (var i = 0; i < (this || _global$3$1).length && (this || _global$3$1).words[i] >= 67108864; i++) { + (this || _global$3$1).words[i] -= 67108864; - if (i === (this || _global$d).length - 1) { - (this || _global$d).words[i + 1] = 1; + if (i === (this || _global$3$1).length - 1) { + (this || _global$3$1).words[i + 1] = 1; } else { - (this || _global$d).words[i + 1]++; + (this || _global$3$1).words[i + 1]++; } } - (this || _global$d).length = Math.max((this || _global$d).length, i + 1); - return this || _global$d; + (this || _global$3$1).length = Math.max((this || _global$3$1).length, i + 1); + return this || _global$3$1; }; // Subtract plain number `num` from `this` @@ -21461,23 +55206,23 @@ function dew$12() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$d).negative !== 0) { - (this || _global$d).negative = 0; + if ((this || _global$3$1).negative !== 0) { + (this || _global$3$1).negative = 0; this.iaddn(num); - (this || _global$d).negative = 1; - return this || _global$d; + (this || _global$3$1).negative = 1; + return this || _global$3$1; } - (this || _global$d).words[0] -= num; + (this || _global$3$1).words[0] -= num; - if ((this || _global$d).length === 1 && (this || _global$d).words[0] < 0) { - (this || _global$d).words[0] = -(this || _global$d).words[0]; - (this || _global$d).negative = 1; + if ((this || _global$3$1).length === 1 && (this || _global$3$1).words[0] < 0) { + (this || _global$3$1).words[0] = -(this || _global$3$1).words[0]; + (this || _global$3$1).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$d).length && (this || _global$d).words[i] < 0; i++) { - (this || _global$d).words[i] += 67108864; - (this || _global$d).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$3$1).length && (this || _global$3$1).words[i] < 0; i++) { + (this || _global$3$1).words[i] += 67108864; + (this || _global$3$1).words[i + 1] -= 1; } } @@ -21493,8 +55238,8 @@ function dew$12() { }; BN.prototype.iabs = function iabs() { - (this || _global$d).negative = 0; - return this || _global$d; + (this || _global$3$1).negative = 0; + return this || _global$3$1; }; BN.prototype.abs = function abs() { @@ -21511,17 +55256,17 @@ function dew$12() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$d).words[i + shift] | 0) + carry; + w = ((this || _global$3$1).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$d).words[i + shift] = w & 67108863; + (this || _global$3$1).words[i + shift] = w & 67108863; } - for (; i < (this || _global$d).length - shift; i++) { - w = ((this || _global$d).words[i + shift] | 0) + carry; + for (; i < (this || _global$3$1).length - shift; i++) { + w = ((this || _global$3$1).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$d).words[i + shift] = w & 67108863; + (this || _global$3$1).words[i + shift] = w & 67108863; } if (carry === 0) return this.strip(); // Subtraction overflow @@ -21529,18 +55274,18 @@ function dew$12() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$d).length; i++) { - w = -((this || _global$d).words[i] | 0) + carry; + for (i = 0; i < (this || _global$3$1).length; i++) { + w = -((this || _global$3$1).words[i] | 0) + carry; carry = w >> 26; - (this || _global$d).words[i] = w & 67108863; + (this || _global$3$1).words[i] = w & 67108863; } - (this || _global$d).negative = 1; + (this || _global$3$1).negative = 1; return this.strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$d).length - num.length; + var shift = (this || _global$3$1).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -21636,7 +55381,7 @@ function dew$12() { var div, mod, res; - if ((this || _global$d).negative !== 0 && num.negative === 0) { + if ((this || _global$3$1).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -21657,7 +55402,7 @@ function dew$12() { }; } - if ((this || _global$d).negative === 0 && num.negative !== 0) { + if ((this || _global$3$1).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -21670,7 +55415,7 @@ function dew$12() { }; } - if (((this || _global$d).negative & num.negative) !== 0) { + if (((this || _global$3$1).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -21689,10 +55434,10 @@ function dew$12() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$d).length || this.cmp(num) < 0) { + if (num.length > (this || _global$3$1).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$d + mod: this || _global$3$1 }; } // Very short reduction @@ -21755,8 +55500,8 @@ function dew$12() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$d).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$d).words[i] | 0)) % num; + for (var i = (this || _global$3$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$3$1).words[i] | 0)) % num; } return acc; @@ -21767,9 +55512,9 @@ function dew$12() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$d).length - 1; i >= 0; i--) { - var w = ((this || _global$d).words[i] | 0) + carry * 67108864; - (this || _global$d).words[i] = w / num | 0; + for (var i = (this || _global$3$1).length - 1; i >= 0; i--) { + var w = ((this || _global$3$1).words[i] | 0) + carry * 67108864; + (this || _global$3$1).words[i] = w / num | 0; carry = w % num; } @@ -21783,7 +55528,7 @@ function dew$12() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$d; + var x = this || _global$3$1; var y = p.clone(); if (x.negative !== 0) { @@ -21866,7 +55611,7 @@ function dew$12() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$d; + var a = this || _global$3$1; var b = p.clone(); if (a.negative !== 0) { @@ -21977,16 +55722,16 @@ function dew$12() { }; BN.prototype.isEven = function isEven() { - return ((this || _global$d).words[0] & 1) === 0; + return ((this || _global$3$1).words[0] & 1) === 0; }; BN.prototype.isOdd = function isOdd() { - return ((this || _global$d).words[0] & 1) === 1; + return ((this || _global$3$1).words[0] & 1) === 1; }; // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$d).words[0] & num; + return (this || _global$3$1).words[0] & num; }; // Increment at the bit position in-line @@ -21996,44 +55741,44 @@ function dew$12() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$d).length <= s) { + if ((this || _global$3$1).length <= s) { this._expand(s + 1); - (this || _global$d).words[s] |= q; - return this || _global$d; + (this || _global$3$1).words[s] |= q; + return this || _global$3$1; } // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$d).length; i++) { - var w = (this || _global$d).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$3$1).length; i++) { + var w = (this || _global$3$1).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$d).words[i] = w; + (this || _global$3$1).words[i] = w; } if (carry !== 0) { - (this || _global$d).words[i] = carry; - (this || _global$d).length++; + (this || _global$3$1).words[i] = carry; + (this || _global$3$1).length++; } - return this || _global$d; + return this || _global$3$1; }; BN.prototype.isZero = function isZero() { - return (this || _global$d).length === 1 && (this || _global$d).words[0] === 0; + return (this || _global$3$1).length === 1 && (this || _global$3$1).words[0] === 0; }; BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$d).negative !== 0 && !negative) return -1; - if ((this || _global$d).negative === 0 && negative) return 1; + if ((this || _global$3$1).negative !== 0 && !negative) return -1; + if ((this || _global$3$1).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$d).length > 1) { + if ((this || _global$3$1).length > 1) { res = 1; } else { if (negative) { @@ -22041,11 +55786,11 @@ function dew$12() { } assert(num <= 67108863, "Number is too big"); - var w = (this || _global$d).words[0] | 0; + var w = (this || _global$3$1).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$d).negative !== 0) return -res | 0; + if ((this || _global$3$1).negative !== 0) return -res | 0; return res; }; // Compare two numbers and return: // 1 - if `this` > `num` @@ -22054,22 +55799,22 @@ function dew$12() { BN.prototype.cmp = function cmp(num) { - if ((this || _global$d).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$d).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$3$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$3$1).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$d).negative !== 0) return -res | 0; + if ((this || _global$3$1).negative !== 0) return -res | 0; return res; }; // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$d).length > num.length) return 1; - if ((this || _global$d).length < num.length) return -1; + if ((this || _global$3$1).length > num.length) return 1; + if ((this || _global$3$1).length < num.length) return -1; var res = 0; - for (var i = (this || _global$d).length - 1; i >= 0; i--) { - var a = (this || _global$d).words[i] | 0; + for (var i = (this || _global$3$1).length - 1; i >= 0; i--) { + var a = (this || _global$3$1).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; @@ -22134,115 +55879,115 @@ function dew$12() { }; BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$d).red, "Already a number in reduction context"); - assert((this || _global$d).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$d)._forceRed(ctx); + assert(!(this || _global$3$1).red, "Already a number in reduction context"); + assert((this || _global$3$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$3$1)._forceRed(ctx); }; BN.prototype.fromRed = function fromRed() { - assert((this || _global$d).red, "fromRed works only with numbers in reduction context"); - return (this || _global$d).red.convertFrom(this || _global$d); + assert((this || _global$3$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$3$1).red.convertFrom(this || _global$3$1); }; BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$d).red = ctx; - return this || _global$d; + (this || _global$3$1).red = ctx; + return this || _global$3$1; }; BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$d).red, "Already a number in reduction context"); + assert(!(this || _global$3$1).red, "Already a number in reduction context"); return this._forceRed(ctx); }; BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$d).red, "redAdd works only with red numbers"); - return (this || _global$d).red.add(this || _global$d, num); + assert((this || _global$3$1).red, "redAdd works only with red numbers"); + return (this || _global$3$1).red.add(this || _global$3$1, num); }; BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$d).red, "redIAdd works only with red numbers"); - return (this || _global$d).red.iadd(this || _global$d, num); + assert((this || _global$3$1).red, "redIAdd works only with red numbers"); + return (this || _global$3$1).red.iadd(this || _global$3$1, num); }; BN.prototype.redSub = function redSub(num) { - assert((this || _global$d).red, "redSub works only with red numbers"); - return (this || _global$d).red.sub(this || _global$d, num); + assert((this || _global$3$1).red, "redSub works only with red numbers"); + return (this || _global$3$1).red.sub(this || _global$3$1, num); }; BN.prototype.redISub = function redISub(num) { - assert((this || _global$d).red, "redISub works only with red numbers"); - return (this || _global$d).red.isub(this || _global$d, num); + assert((this || _global$3$1).red, "redISub works only with red numbers"); + return (this || _global$3$1).red.isub(this || _global$3$1, num); }; BN.prototype.redShl = function redShl(num) { - assert((this || _global$d).red, "redShl works only with red numbers"); - return (this || _global$d).red.shl(this || _global$d, num); + assert((this || _global$3$1).red, "redShl works only with red numbers"); + return (this || _global$3$1).red.shl(this || _global$3$1, num); }; BN.prototype.redMul = function redMul(num) { - assert((this || _global$d).red, "redMul works only with red numbers"); + assert((this || _global$3$1).red, "redMul works only with red numbers"); - (this || _global$d).red._verify2(this || _global$d, num); + (this || _global$3$1).red._verify2(this || _global$3$1, num); - return (this || _global$d).red.mul(this || _global$d, num); + return (this || _global$3$1).red.mul(this || _global$3$1, num); }; BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$d).red, "redMul works only with red numbers"); + assert((this || _global$3$1).red, "redMul works only with red numbers"); - (this || _global$d).red._verify2(this || _global$d, num); + (this || _global$3$1).red._verify2(this || _global$3$1, num); - return (this || _global$d).red.imul(this || _global$d, num); + return (this || _global$3$1).red.imul(this || _global$3$1, num); }; BN.prototype.redSqr = function redSqr() { - assert((this || _global$d).red, "redSqr works only with red numbers"); + assert((this || _global$3$1).red, "redSqr works only with red numbers"); - (this || _global$d).red._verify1(this || _global$d); + (this || _global$3$1).red._verify1(this || _global$3$1); - return (this || _global$d).red.sqr(this || _global$d); + return (this || _global$3$1).red.sqr(this || _global$3$1); }; BN.prototype.redISqr = function redISqr() { - assert((this || _global$d).red, "redISqr works only with red numbers"); + assert((this || _global$3$1).red, "redISqr works only with red numbers"); - (this || _global$d).red._verify1(this || _global$d); + (this || _global$3$1).red._verify1(this || _global$3$1); - return (this || _global$d).red.isqr(this || _global$d); + return (this || _global$3$1).red.isqr(this || _global$3$1); }; // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$d).red, "redSqrt works only with red numbers"); + assert((this || _global$3$1).red, "redSqrt works only with red numbers"); - (this || _global$d).red._verify1(this || _global$d); + (this || _global$3$1).red._verify1(this || _global$3$1); - return (this || _global$d).red.sqrt(this || _global$d); + return (this || _global$3$1).red.sqrt(this || _global$3$1); }; BN.prototype.redInvm = function redInvm() { - assert((this || _global$d).red, "redInvm works only with red numbers"); + assert((this || _global$3$1).red, "redInvm works only with red numbers"); - (this || _global$d).red._verify1(this || _global$d); + (this || _global$3$1).red._verify1(this || _global$3$1); - return (this || _global$d).red.invm(this || _global$d); + return (this || _global$3$1).red.invm(this || _global$3$1); }; // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$d).red, "redNeg works only with red numbers"); + assert((this || _global$3$1).red, "redNeg works only with red numbers"); - (this || _global$d).red._verify1(this || _global$d); + (this || _global$3$1).red._verify1(this || _global$3$1); - return (this || _global$d).red.neg(this || _global$d); + return (this || _global$3$1).red.neg(this || _global$3$1); }; BN.prototype.redPow = function redPow(num) { - assert((this || _global$d).red && !num.red, "redPow(normalNum)"); + assert((this || _global$3$1).red && !num.red, "redPow(normalNum)"); - (this || _global$d).red._verify1(this || _global$d); + (this || _global$3$1).red._verify1(this || _global$3$1); - return (this || _global$d).red.pow(this || _global$d, num); + return (this || _global$3$1).red.pow(this || _global$3$1, num); }; // Prime numbers with efficient reduction @@ -22255,16 +56000,16 @@ function dew$12() { function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$d).name = name; - (this || _global$d).p = new BN(p, 16); - (this || _global$d).n = (this || _global$d).p.bitLength(); - (this || _global$d).k = new BN(1).iushln((this || _global$d).n).isub((this || _global$d).p); - (this || _global$d).tmp = this._tmp(); + (this || _global$3$1).name = name; + (this || _global$3$1).p = new BN(p, 16); + (this || _global$3$1).n = (this || _global$3$1).p.bitLength(); + (this || _global$3$1).k = new BN(1).iushln((this || _global$3$1).n).isub((this || _global$3$1).p); + (this || _global$3$1).tmp = this._tmp(); } MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$d).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$3$1).n / 13)); return tmp; }; @@ -22275,19 +56020,19 @@ function dew$12() { var rlen; do { - this.split(r, (this || _global$d).tmp); + this.split(r, (this || _global$3$1).tmp); r = this.imulK(r); - r = r.iadd((this || _global$d).tmp); + r = r.iadd((this || _global$3$1).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$d).n); + } while (rlen > (this || _global$3$1).n); - var cmp = rlen < (this || _global$d).n ? -1 : r.ucmp((this || _global$d).p); + var cmp = rlen < (this || _global$3$1).n ? -1 : r.ucmp((this || _global$3$1).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$d).p); + r.isub((this || _global$3$1).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -22302,15 +56047,15 @@ function dew$12() { }; MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$d).n, 0, out); + input.iushrn((this || _global$3$1).n, 0, out); }; MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$d).k); + return num.imul((this || _global$3$1).k); }; function K256() { - MPrime.call(this || _global$d, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$3$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } inherits(K256, MPrime); @@ -22380,20 +56125,20 @@ function dew$12() { }; function P224() { - MPrime.call(this || _global$d, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$3$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } inherits(P224, MPrime); function P192() { - MPrime.call(this || _global$d, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$3$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } inherits(P192, MPrime); function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$d, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$3$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } inherits(P25519, MPrime); @@ -22446,12 +56191,12 @@ function dew$12() { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$d).m = prime.p; - (this || _global$d).prime = prime; + (this || _global$3$1).m = prime.p; + (this || _global$3$1).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$d).m = m; - (this || _global$d).prime = null; + (this || _global$3$1).m = m; + (this || _global$3$1).prime = null; } } @@ -22466,8 +56211,8 @@ function dew$12() { }; Red.prototype.imod = function imod(a) { - if ((this || _global$d).prime) return (this || _global$d).prime.ireduce(a)._forceRed(this || _global$d); - return a.umod((this || _global$d).m)._forceRed(this || _global$d); + if ((this || _global$3$1).prime) return (this || _global$3$1).prime.ireduce(a)._forceRed(this || _global$3$1); + return a.umod((this || _global$3$1).m)._forceRed(this || _global$3$1); }; Red.prototype.neg = function neg(a) { @@ -22475,7 +56220,7 @@ function dew$12() { return a.clone(); } - return (this || _global$d).m.sub(a)._forceRed(this || _global$d); + return (this || _global$3$1).m.sub(a)._forceRed(this || _global$3$1); }; Red.prototype.add = function add(a, b) { @@ -22483,11 +56228,11 @@ function dew$12() { var res = a.add(b); - if (res.cmp((this || _global$d).m) >= 0) { - res.isub((this || _global$d).m); + if (res.cmp((this || _global$3$1).m) >= 0) { + res.isub((this || _global$3$1).m); } - return res._forceRed(this || _global$d); + return res._forceRed(this || _global$3$1); }; Red.prototype.iadd = function iadd(a, b) { @@ -22495,8 +56240,8 @@ function dew$12() { var res = a.iadd(b); - if (res.cmp((this || _global$d).m) >= 0) { - res.isub((this || _global$d).m); + if (res.cmp((this || _global$3$1).m) >= 0) { + res.isub((this || _global$3$1).m); } return res; @@ -22508,10 +56253,10 @@ function dew$12() { var res = a.sub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$d).m); + res.iadd((this || _global$3$1).m); } - return res._forceRed(this || _global$d); + return res._forceRed(this || _global$3$1); }; Red.prototype.isub = function isub(a, b) { @@ -22520,7 +56265,7 @@ function dew$12() { var res = a.isub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$d).m); + res.iadd((this || _global$3$1).m); } return res; @@ -22555,12 +56300,12 @@ function dew$12() { Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$d).m.andln(3); + var mod3 = (this || _global$3$1).m.andln(3); assert(mod3 % 2 === 1); // Fast case if (mod3 === 3) { - var pow = (this || _global$d).m.add(new BN(1)).iushrn(2); + var pow = (this || _global$3$1).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); } // Tonelli-Shanks algorithm (Totally unoptimized and slow) @@ -22568,7 +56313,7 @@ function dew$12() { // Find Q and S, that Q * 2 ^ S = (P - 1) - var q = (this || _global$d).m.subn(1); + var q = (this || _global$3$1).m.subn(1); var s = 0; @@ -22578,15 +56323,15 @@ function dew$12() { } assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$d); + var one = new BN(1).toRed(this || _global$3$1); var nOne = one.redNeg(); // Find quadratic non-residue // NOTE: Max is such because of generalized Riemann hypothesis. - var lpow = (this || _global$d).m.subn(1).iushrn(1); + var lpow = (this || _global$3$1).m.subn(1).iushrn(1); - var z = (this || _global$d).m.bitLength(); + var z = (this || _global$3$1).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$d); + z = new BN(2 * z * z).toRed(this || _global$3$1); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); @@ -22616,7 +56361,7 @@ function dew$12() { }; Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$d).m); + var inv = a._invmp((this || _global$3$1).m); if (inv.negative !== 0) { inv.negative = 0; @@ -22627,11 +56372,11 @@ function dew$12() { }; Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$d); + if (num.isZero()) return new BN(1).toRed(this || _global$3$1); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$d); + wnd[0] = new BN(1).toRed(this || _global$3$1); wnd[1] = a; for (var i = 2; i < wnd.length; i++) { @@ -22678,7 +56423,7 @@ function dew$12() { }; Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$d).m); + var r = num.umod((this || _global$3$1).m); return r === num ? r.clone() : r; }; @@ -22696,29 +56441,29 @@ function dew$12() { }; function Mont(m) { - Red.call(this || _global$d, m); - (this || _global$d).shift = (this || _global$d).m.bitLength(); + Red.call(this || _global$3$1, m); + (this || _global$3$1).shift = (this || _global$3$1).m.bitLength(); - if ((this || _global$d).shift % 26 !== 0) { - (this || _global$d).shift += 26 - (this || _global$d).shift % 26; + if ((this || _global$3$1).shift % 26 !== 0) { + (this || _global$3$1).shift += 26 - (this || _global$3$1).shift % 26; } - (this || _global$d).r = new BN(1).iushln((this || _global$d).shift); - (this || _global$d).r2 = this.imod((this || _global$d).r.sqr()); - (this || _global$d).rinv = (this || _global$d).r._invmp((this || _global$d).m); - (this || _global$d).minv = (this || _global$d).rinv.mul((this || _global$d).r).isubn(1).div((this || _global$d).m); - (this || _global$d).minv = (this || _global$d).minv.umod((this || _global$d).r); - (this || _global$d).minv = (this || _global$d).r.sub((this || _global$d).minv); + (this || _global$3$1).r = new BN(1).iushln((this || _global$3$1).shift); + (this || _global$3$1).r2 = this.imod((this || _global$3$1).r.sqr()); + (this || _global$3$1).rinv = (this || _global$3$1).r._invmp((this || _global$3$1).m); + (this || _global$3$1).minv = (this || _global$3$1).rinv.mul((this || _global$3$1).r).isubn(1).div((this || _global$3$1).m); + (this || _global$3$1).minv = (this || _global$3$1).minv.umod((this || _global$3$1).r); + (this || _global$3$1).minv = (this || _global$3$1).r.sub((this || _global$3$1).minv); } inherits(Mont, Red); Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$d).shift)); + return this.imod(num.ushln((this || _global$3$1).shift)); }; Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$d).rinv)); + var r = this.imod(num.mul((this || _global$3$1).rinv)); r.red = null; return r; }; @@ -22731,56 +56476,264 @@ function dew$12() { } var t = a.imul(b); - var c = t.maskn((this || _global$d).shift).mul((this || _global$d).minv).imaskn((this || _global$d).shift).mul((this || _global$d).m); - var u = t.isub(c).iushrn((this || _global$d).shift); + var c = t.maskn((this || _global$3$1).shift).mul((this || _global$3$1).minv).imaskn((this || _global$3$1).shift).mul((this || _global$3$1).m); + var u = t.isub(c).iushrn((this || _global$3$1).shift); var res = u; - if (u.cmp((this || _global$d).m) >= 0) { - res = u.isub((this || _global$d).m); + if (u.cmp((this || _global$3$1).m) >= 0) { + res = u.isub((this || _global$3$1).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$d).m); + res = u.iadd((this || _global$3$1).m); } - return res._forceRed(this || _global$d); + return res._forceRed(this || _global$3$1); }; Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$d); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$3$1); var t = a.mul(b); - var c = t.maskn((this || _global$d).shift).mul((this || _global$d).minv).imaskn((this || _global$d).shift).mul((this || _global$d).m); - var u = t.isub(c).iushrn((this || _global$d).shift); + var c = t.maskn((this || _global$3$1).shift).mul((this || _global$3$1).minv).imaskn((this || _global$3$1).shift).mul((this || _global$3$1).m); + var u = t.isub(c).iushrn((this || _global$3$1).shift); var res = u; - if (u.cmp((this || _global$d).m) >= 0) { - res = u.isub((this || _global$d).m); + if (u.cmp((this || _global$3$1).m) >= 0) { + res = u.isub((this || _global$3$1).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$d).m); + res = u.iadd((this || _global$3$1).m); } - return res._forceRed(this || _global$d); + return res._forceRed(this || _global$3$1); }; Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$d).m).mul((this || _global$d).r2)); - return res._forceRed(this || _global$d); + var res = this.imod(a._invmp((this || _global$3$1).m).mul((this || _global$3$1).r2)); + return res._forceRed(this || _global$3$1); }; - })(module$6, exports$13); + })(module$1$1, exports$a$1); - return module$6.exports; + return module$1$1.exports; } -var exports$12$1 = {}, - _dewExec$11$1 = false; -var module$5 = { - exports: exports$12$1 +var exports$9$1 = {}, + _dewExec$9$1 = false; + +var _global$2$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$9$1() { + if (_dewExec$9$1) return exports$9$1; + _dewExec$9$1 = true; + var Buffer = e$1$1$1.Buffer; + + var elliptic = dew$y$1(); + + var BN = dew$a$1(); + + exports$9$1 = function createECDH(curve) { + return new ECDH(curve); + }; + + var aliases = { + secp256k1: { + name: "secp256k1", + byteLength: 32 + }, + secp224r1: { + name: "p224", + byteLength: 28 + }, + prime256v1: { + name: "p256", + byteLength: 32 + }, + prime192v1: { + name: "p192", + byteLength: 24 + }, + ed25519: { + name: "ed25519", + byteLength: 32 + }, + secp384r1: { + name: "p384", + byteLength: 48 + }, + secp521r1: { + name: "p521", + byteLength: 66 + } + }; + aliases.p224 = aliases.secp224r1; + aliases.p256 = aliases.secp256r1 = aliases.prime256v1; + aliases.p192 = aliases.secp192r1 = aliases.prime192v1; + aliases.p384 = aliases.secp384r1; + aliases.p521 = aliases.secp521r1; + + function ECDH(curve) { + (this || _global$2$1).curveType = aliases[curve]; + + if (!(this || _global$2$1).curveType) { + (this || _global$2$1).curveType = { + name: curve + }; + } + + (this || _global$2$1).curve = new elliptic.ec((this || _global$2$1).curveType.name); // eslint-disable-line new-cap + + (this || _global$2$1).keys = void 0; + } + + ECDH.prototype.generateKeys = function (enc, format) { + (this || _global$2$1).keys = (this || _global$2$1).curve.genKeyPair(); + return this.getPublicKey(enc, format); + }; + + ECDH.prototype.computeSecret = function (other, inenc, enc) { + inenc = inenc || "utf8"; + + if (!Buffer.isBuffer(other)) { + other = new Buffer(other, inenc); + } + + var otherPub = (this || _global$2$1).curve.keyFromPublic(other).getPublic(); + + var out = otherPub.mul((this || _global$2$1).keys.getPrivate()).getX(); + return formatReturnValue(out, enc, (this || _global$2$1).curveType.byteLength); + }; + + ECDH.prototype.getPublicKey = function (enc, format) { + var key = (this || _global$2$1).keys.getPublic(format === "compressed", true); + + if (format === "hybrid") { + if (key[key.length - 1] % 2) { + key[0] = 7; + } else { + key[0] = 6; + } + } + + return formatReturnValue(key, enc); + }; + + ECDH.prototype.getPrivateKey = function (enc) { + return formatReturnValue((this || _global$2$1).keys.getPrivate(), enc); + }; + + ECDH.prototype.setPublicKey = function (pub, enc) { + enc = enc || "utf8"; + + if (!Buffer.isBuffer(pub)) { + pub = new Buffer(pub, enc); + } + + (this || _global$2$1).keys._importPublic(pub); + + return this || _global$2$1; + }; + + ECDH.prototype.setPrivateKey = function (priv, enc) { + enc = enc || "utf8"; + + if (!Buffer.isBuffer(priv)) { + priv = new Buffer(priv, enc); + } + + var _priv = new BN(priv); + + _priv = _priv.toString(16); + (this || _global$2$1).keys = (this || _global$2$1).curve.genKeyPair(); + + (this || _global$2$1).keys._importPrivate(_priv); + + return this || _global$2$1; + }; + + function formatReturnValue(bn, enc, len) { + if (!Array.isArray(bn)) { + bn = bn.toArray(); + } + + var buf = new Buffer(bn); + + if (len && buf.length < len) { + var zeros = new Buffer(len - buf.length); + zeros.fill(0); + buf = Buffer.concat([zeros, buf]); + } + + if (!enc) { + return buf; + } else { + return buf.toString(enc); + } + } + + return exports$9$1; +} + +var exports$8$1 = {}, + _dewExec$8$1 = false; +function dew$8$1() { + if (_dewExec$8$1) return exports$8$1; + _dewExec$8$1 = true; + + var createHash = dew$1F(); + + var Buffer = dew$1T().Buffer; + + exports$8$1 = function (seed, len) { + var t = Buffer.alloc(0); + var i = 0; + var c; + + while (t.length < len) { + c = i2ops(i++); + t = Buffer.concat([t, createHash("sha1").update(seed).update(c).digest()]); + } + + return t.slice(0, len); + }; + + function i2ops(c) { + var out = Buffer.allocUnsafe(4); + out.writeUInt32BE(c, 0); + return out; + } + + return exports$8$1; +} + +var exports$7$1 = {}, + _dewExec$7$1 = false; +function dew$7$1() { + if (_dewExec$7$1) return exports$7$1; + _dewExec$7$1 = true; + + exports$7$1 = function xor(a, b) { + var len = a.length; + var i = -1; + + while (++i < len) { + a[i] ^= b[i]; + } + + return a; + }; + + return exports$7$1; +} + +var exports$6$1 = {}, + _dewExec$6$1 = false; +var module$8 = { + exports: exports$6$1 }; -var _global$c = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$1$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$11$1() { - if (_dewExec$11$1) return module$5.exports; - _dewExec$11$1 = true; +function dew$6$1() { + if (_dewExec$6$1) return module$8.exports; + _dewExec$6$1 = true; (function (module, exports) { @@ -22806,11 +56759,11 @@ function dew$11$1() { return number; } - (this || _global$c).negative = 0; - (this || _global$c).words = null; - (this || _global$c).length = 0; // Reduction context + (this || _global$1$1).negative = 0; + (this || _global$1$1).words = null; + (this || _global$1$1).length = 0; // Reduction context - (this || _global$c).red = null; + (this || _global$1$1).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -22877,7 +56830,7 @@ function dew$11$1() { if (number[0] === "-") { start++; - (this || _global$c).negative = 1; + (this || _global$1$1).negative = 1; } if (start < number.length) { @@ -22895,21 +56848,21 @@ function dew$11$1() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$c).negative = 1; + (this || _global$1$1).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$c).words = [number & 67108863]; - (this || _global$c).length = 1; + (this || _global$1$1).words = [number & 67108863]; + (this || _global$1$1).length = 1; } else if (number < 4503599627370496) { - (this || _global$c).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$c).length = 2; + (this || _global$1$1).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$1$1).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$c).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$c).length = 3; + (this || _global$1$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$1$1).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -22922,16 +56875,16 @@ function dew$11$1() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$c).words = [0]; - (this || _global$c).length = 1; - return this || _global$c; + (this || _global$1$1).words = [0]; + (this || _global$1$1).length = 1; + return this || _global$1$1; } - (this || _global$c).length = Math.ceil(number.length / 3); - (this || _global$c).words = new Array((this || _global$c).length); + (this || _global$1$1).length = Math.ceil(number.length / 3); + (this || _global$1$1).words = new Array((this || _global$1$1).length); - for (var i = 0; i < (this || _global$c).length; i++) { - (this || _global$c).words[i] = 0; + for (var i = 0; i < (this || _global$1$1).length; i++) { + (this || _global$1$1).words[i] = 0; } var j, w; @@ -22940,8 +56893,8 @@ function dew$11$1() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$c).words[j] |= w << off & 67108863; - (this || _global$c).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$1$1).words[j] |= w << off & 67108863; + (this || _global$1$1).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -22952,8 +56905,8 @@ function dew$11$1() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$c).words[j] |= w << off & 67108863; - (this || _global$c).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$1$1).words[j] |= w << off & 67108863; + (this || _global$1$1).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -22990,11 +56943,11 @@ function dew$11$1() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$c).length = Math.ceil((number.length - start) / 6); - (this || _global$c).words = new Array((this || _global$c).length); + (this || _global$1$1).length = Math.ceil((number.length - start) / 6); + (this || _global$1$1).words = new Array((this || _global$1$1).length); - for (var i = 0; i < (this || _global$c).length; i++) { - (this || _global$c).words[i] = 0; + for (var i = 0; i < (this || _global$1$1).length; i++) { + (this || _global$1$1).words[i] = 0; } // 24-bits chunks @@ -23005,12 +56958,12 @@ function dew$11$1() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$c).words[j] |= w & 67108863; + (this || _global$1$1).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$c).words[j] |= w >>> 26; + (this || _global$1$1).words[j] |= w >>> 26; } else { off += 8; } @@ -23020,12 +56973,12 @@ function dew$11$1() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$c).words[j] |= w & 67108863; + (this || _global$1$1).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$c).words[j] |= w >>> 26; + (this || _global$1$1).words[j] |= w >>> 26; } else { off += 8; } @@ -23057,8 +57010,8 @@ function dew$11$1() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$c).words = [0]; - (this || _global$c).length = 1; // Find length of limb in base + (this || _global$1$1).words = [0]; + (this || _global$1$1).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -23075,8 +57028,8 @@ function dew$11$1() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$c).words[0] + word < 67108864) { - (this || _global$c).words[0] += word; + if ((this || _global$1$1).words[0] + word < 67108864) { + (this || _global$1$1).words[0] += word; } else { this._iaddn(word); } @@ -23092,8 +57045,8 @@ function dew$11$1() { this.imuln(pow); - if ((this || _global$c).words[0] + word < 67108864) { - (this || _global$c).words[0] += word; + if ((this || _global$1$1).words[0] + word < 67108864) { + (this || _global$1$1).words[0] += word; } else { this._iaddn(word); } @@ -23103,15 +57056,15 @@ function dew$11$1() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$c).length); + dest.words = new Array((this || _global$1$1).length); - for (var i = 0; i < (this || _global$c).length; i++) { - dest.words[i] = (this || _global$c).words[i]; + for (var i = 0; i < (this || _global$1$1).length; i++) { + dest.words[i] = (this || _global$1$1).words[i]; } - dest.length = (this || _global$c).length; - dest.negative = (this || _global$c).negative; - dest.red = (this || _global$c).red; + dest.length = (this || _global$1$1).length; + dest.negative = (this || _global$1$1).negative; + dest.red = (this || _global$1$1).red; }; BN.prototype.clone = function clone() { @@ -23121,17 +57074,17 @@ function dew$11$1() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$c).length < size) { - (this || _global$c).words[(this || _global$c).length++] = 0; + while ((this || _global$1$1).length < size) { + (this || _global$1$1).words[(this || _global$1$1).length++] = 0; } - return this || _global$c; + return this || _global$1$1; }; // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$c).length > 1 && (this || _global$c).words[(this || _global$c).length - 1] === 0) { - (this || _global$c).length--; + while ((this || _global$1$1).length > 1 && (this || _global$1$1).words[(this || _global$1$1).length - 1] === 0) { + (this || _global$1$1).length--; } return this._normSign(); @@ -23139,15 +57092,15 @@ function dew$11$1() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$c).length === 1 && (this || _global$c).words[0] === 0) { - (this || _global$c).negative = 0; + if ((this || _global$1$1).length === 1 && (this || _global$1$1).words[0] === 0) { + (this || _global$1$1).negative = 0; } - return this || _global$c; + return this || _global$1$1; }; BN.prototype.inspect = function inspect() { - return ((this || _global$c).red ? ""; + return ((this || _global$1$1).red ? ""; }; /* var zeros = []; @@ -23191,12 +57144,12 @@ function dew$11$1() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$c).length; i++) { - var w = (this || _global$c).words[i]; + for (var i = 0; i < (this || _global$1$1).length; i++) { + var w = (this || _global$1$1).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$c).length - 1) { + if (carry !== 0 || i !== (this || _global$1$1).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -23218,7 +57171,7 @@ function dew$11$1() { out = "0" + out; } - if ((this || _global$c).negative !== 0) { + if ((this || _global$1$1).negative !== 0) { out = "-" + out; } @@ -23253,7 +57206,7 @@ function dew$11$1() { out = "0" + out; } - if ((this || _global$c).negative !== 0) { + if ((this || _global$1$1).negative !== 0) { out = "-" + out; } @@ -23264,18 +57217,18 @@ function dew$11$1() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$c).words[0]; + var ret = (this || _global$1$1).words[0]; - if ((this || _global$c).length === 2) { - ret += (this || _global$c).words[1] * 67108864; - } else if ((this || _global$c).length === 3 && (this || _global$c).words[2] === 1) { + if ((this || _global$1$1).length === 2) { + ret += (this || _global$1$1).words[1] * 67108864; + } else if ((this || _global$1$1).length === 3 && (this || _global$1$1).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$c).words[1] * 67108864; - } else if ((this || _global$c).length > 2) { + ret += 4503599627370496 + (this || _global$1$1).words[1] * 67108864; + } else if ((this || _global$1$1).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$c).negative !== 0 ? -ret : ret; + return (this || _global$1$1).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -23396,11 +57349,11 @@ function dew$11$1() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$c).words[(this || _global$c).length - 1]; + var w = (this || _global$1$1).words[(this || _global$1$1).length - 1]; var hi = this._countBits(w); - return ((this || _global$c).length - 1) * 26 + hi; + return ((this || _global$1$1).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -23420,8 +57373,8 @@ function dew$11$1() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$c).length; i++) { - var b = this._zeroBits((this || _global$c).words[i]); + for (var i = 0; i < (this || _global$1$1).length; i++) { + var b = this._zeroBits((this || _global$1$1).words[i]); r += b; if (b !== 26) break; @@ -23435,7 +57388,7 @@ function dew$11$1() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$c).negative !== 0) { + if ((this || _global$1$1).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -23451,7 +57404,7 @@ function dew$11$1() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$c).negative !== 0; + return (this || _global$1$1).negative !== 0; }; // Return negative clone of `this` @@ -23461,39 +57414,39 @@ function dew$11$1() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$c).negative ^= 1; + (this || _global$1$1).negative ^= 1; } - return this || _global$c; + return this || _global$1$1; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$c).length < num.length) { - (this || _global$c).words[(this || _global$c).length++] = 0; + while ((this || _global$1$1).length < num.length) { + (this || _global$1$1).words[(this || _global$1$1).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$c).words[i] = (this || _global$c).words[i] | num.words[i]; + (this || _global$1$1).words[i] = (this || _global$1$1).words[i] | num.words[i]; } return this.strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$c).negative | num.negative) === 0); + assert(((this || _global$1$1).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$c).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$1$1); }; BN.prototype.uor = function uor(num) { - if ((this || _global$c).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$1$1); }; // And `num` with `this` in-place @@ -23501,34 +57454,34 @@ function dew$11$1() { // b = min-length(num, this) var b; - if ((this || _global$c).length > num.length) { + if ((this || _global$1$1).length > num.length) { b = num; } else { - b = this || _global$c; + b = this || _global$1$1; } for (var i = 0; i < b.length; i++) { - (this || _global$c).words[i] = (this || _global$c).words[i] & num.words[i]; + (this || _global$1$1).words[i] = (this || _global$1$1).words[i] & num.words[i]; } - (this || _global$c).length = b.length; + (this || _global$1$1).length = b.length; return this.strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$c).negative | num.negative) === 0); + assert(((this || _global$1$1).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$c).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$1$1); }; BN.prototype.uand = function uand(num) { - if ((this || _global$c).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$1$1); }; // Xor `num` with `this` in-place @@ -23537,42 +57490,42 @@ function dew$11$1() { var a; var b; - if ((this || _global$c).length > num.length) { - a = this || _global$c; + if ((this || _global$1$1).length > num.length) { + a = this || _global$1$1; b = num; } else { a = num; - b = this || _global$c; + b = this || _global$1$1; } for (var i = 0; i < b.length; i++) { - (this || _global$c).words[i] = a.words[i] ^ b.words[i]; + (this || _global$1$1).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$c) !== a) { + if ((this || _global$1$1) !== a) { for (; i < a.length; i++) { - (this || _global$c).words[i] = a.words[i]; + (this || _global$1$1).words[i] = a.words[i]; } } - (this || _global$c).length = a.length; + (this || _global$1$1).length = a.length; return this.strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$c).negative | num.negative) === 0); + assert(((this || _global$1$1).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$c).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$1$1); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$c).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$1$1); }; // Not ``this`` with ``width`` bitwidth @@ -23589,12 +57542,12 @@ function dew$11$1() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$c).words[i] = ~(this || _global$c).words[i] & 67108863; + (this || _global$1$1).words[i] = ~(this || _global$1$1).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$c).words[i] = ~(this || _global$c).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$1$1).words[i] = ~(this || _global$1$1).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -23614,9 +57567,9 @@ function dew$11$1() { this._expand(off + 1); if (val) { - (this || _global$c).words[off] = (this || _global$c).words[off] | 1 << wbit; + (this || _global$1$1).words[off] = (this || _global$1$1).words[off] | 1 << wbit; } else { - (this || _global$c).words[off] = (this || _global$c).words[off] & ~(1 << wbit); + (this || _global$1$1).words[off] = (this || _global$1$1).words[off] & ~(1 << wbit); } return this.strip(); @@ -23626,12 +57579,12 @@ function dew$11$1() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$c).negative !== 0 && num.negative === 0) { - (this || _global$c).negative = 0; + if ((this || _global$1$1).negative !== 0 && num.negative === 0) { + (this || _global$1$1).negative = 0; r = this.isub(num); - (this || _global$c).negative ^= 1; + (this || _global$1$1).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$c).negative === 0 && num.negative !== 0) { + } else if ((this || _global$1$1).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -23641,60 +57594,60 @@ function dew$11$1() { var a, b; - if ((this || _global$c).length > num.length) { - a = this || _global$c; + if ((this || _global$1$1).length > num.length) { + a = this || _global$1$1; b = num; } else { a = num; - b = this || _global$c; + b = this || _global$1$1; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$c).words[i] = r & 67108863; + (this || _global$1$1).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$c).words[i] = r & 67108863; + (this || _global$1$1).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$c).length = a.length; + (this || _global$1$1).length = a.length; if (carry !== 0) { - (this || _global$c).words[(this || _global$c).length] = carry; - (this || _global$c).length++; // Copy the rest of the words - } else if (a !== (this || _global$c)) { + (this || _global$1$1).words[(this || _global$1$1).length] = carry; + (this || _global$1$1).length++; // Copy the rest of the words + } else if (a !== (this || _global$1$1)) { for (; i < a.length; i++) { - (this || _global$c).words[i] = a.words[i]; + (this || _global$1$1).words[i] = a.words[i]; } } - return this || _global$c; + return this || _global$1$1; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$c).negative === 0) { + if (num.negative !== 0 && (this || _global$1$1).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$c).negative !== 0) { - (this || _global$c).negative = 0; - res = num.sub(this || _global$c); - (this || _global$c).negative = 1; + } else if (num.negative === 0 && (this || _global$1$1).negative !== 0) { + (this || _global$1$1).negative = 0; + res = num.sub(this || _global$1$1); + (this || _global$1$1).negative = 1; return res; } - if ((this || _global$c).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$c); + if ((this || _global$1$1).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$1$1); }; // Subtract `num` from `this` in-place @@ -23705,10 +57658,10 @@ function dew$11$1() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$c).negative !== 0) { - (this || _global$c).negative = 0; + } else if ((this || _global$1$1).negative !== 0) { + (this || _global$1$1).negative = 0; this.iadd(num); - (this || _global$c).negative = 1; + (this || _global$1$1).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -23716,21 +57669,21 @@ function dew$11$1() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$c).negative = 0; - (this || _global$c).length = 1; - (this || _global$c).words[0] = 0; - return this || _global$c; + (this || _global$1$1).negative = 0; + (this || _global$1$1).length = 1; + (this || _global$1$1).words[0] = 0; + return this || _global$1$1; } // a > b var a, b; if (cmp > 0) { - a = this || _global$c; + a = this || _global$1$1; b = num; } else { a = num; - b = this || _global$c; + b = this || _global$1$1; } var carry = 0; @@ -23738,26 +57691,26 @@ function dew$11$1() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$c).words[i] = r & 67108863; + (this || _global$1$1).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$c).words[i] = r & 67108863; + (this || _global$1$1).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$c)) { + if (carry === 0 && i < a.length && a !== (this || _global$1$1)) { for (; i < a.length; i++) { - (this || _global$c).words[i] = a.words[i]; + (this || _global$1$1).words[i] = a.words[i]; } } - (this || _global$c).length = Math.max((this || _global$c).length, i); + (this || _global$1$1).length = Math.max((this || _global$1$1).length, i); - if (a !== (this || _global$c)) { - (this || _global$c).negative = 1; + if (a !== (this || _global$1$1)) { + (this || _global$1$1).negative = 1; } return this.strip(); @@ -24460,16 +58413,16 @@ function dew$11$1() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$c).length + num.length; + var len = (this || _global$1$1).length + num.length; - if ((this || _global$c).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$c, num, out); + if ((this || _global$1$1).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$1$1, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$c, num, out); + res = smallMulTo(this || _global$1$1, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$c, num, out); + res = bigMulTo(this || _global$1$1, num, out); } else { - res = jumboMulTo(this || _global$c, num, out); + res = jumboMulTo(this || _global$1$1, num, out); } return res; @@ -24478,8 +58431,8 @@ function dew$11$1() { function FFTM(x, y) { - (this || _global$c).x = x; - (this || _global$c).y = y; + (this || _global$1$1).x = x; + (this || _global$1$1).y = y; } FFTM.prototype.makeRBT = function makeRBT(N) { @@ -24660,20 +58613,20 @@ function dew$11$1() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$c).length + num.length); + out.words = new Array((this || _global$1$1).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$c).length + num.length); - return jumboMulTo(this || _global$c, num, out); + out.words = new Array((this || _global$1$1).length + num.length); + return jumboMulTo(this || _global$1$1, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$c); + return this.clone().mulTo(num, this || _global$1$1); }; BN.prototype.imuln = function imuln(num) { @@ -24682,22 +58635,22 @@ function dew$11$1() { var carry = 0; - for (var i = 0; i < (this || _global$c).length; i++) { - var w = ((this || _global$c).words[i] | 0) * num; + for (var i = 0; i < (this || _global$1$1).length; i++) { + var w = ((this || _global$1$1).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$c).words[i] = lo & 67108863; + (this || _global$1$1).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$c).words[i] = carry; - (this || _global$c).length++; + (this || _global$1$1).words[i] = carry; + (this || _global$1$1).length++; } - return this || _global$c; + return this || _global$1$1; }; BN.prototype.muln = function muln(num) { @@ -24706,7 +58659,7 @@ function dew$11$1() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$c); + return this.mul(this || _global$1$1); }; // `this` * `this` in-place @@ -24719,7 +58672,7 @@ function dew$11$1() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$c; + var res = this || _global$1$1; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -24746,29 +58699,29 @@ function dew$11$1() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$c).length; i++) { - var newCarry = (this || _global$c).words[i] & carryMask; - var c = ((this || _global$c).words[i] | 0) - newCarry << r; - (this || _global$c).words[i] = c | carry; + for (i = 0; i < (this || _global$1$1).length; i++) { + var newCarry = (this || _global$1$1).words[i] & carryMask; + var c = ((this || _global$1$1).words[i] | 0) - newCarry << r; + (this || _global$1$1).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$c).words[i] = carry; - (this || _global$c).length++; + (this || _global$1$1).words[i] = carry; + (this || _global$1$1).length++; } } if (s !== 0) { - for (i = (this || _global$c).length - 1; i >= 0; i--) { - (this || _global$c).words[i + s] = (this || _global$c).words[i]; + for (i = (this || _global$1$1).length - 1; i >= 0; i--) { + (this || _global$1$1).words[i + s] = (this || _global$1$1).words[i]; } for (i = 0; i < s; i++) { - (this || _global$c).words[i] = 0; + (this || _global$1$1).words[i] = 0; } - (this || _global$c).length += s; + (this || _global$1$1).length += s; } return this.strip(); @@ -24776,7 +58729,7 @@ function dew$11$1() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$c).negative === 0); + assert((this || _global$1$1).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -24794,7 +58747,7 @@ function dew$11$1() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$c).length); + var s = Math.min((bits - r) / 26, (this || _global$1$1).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -24802,28 +58755,28 @@ function dew$11$1() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$c).words[i]; + maskedWords.words[i] = (this || _global$1$1).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$c).length > s) { - (this || _global$c).length -= s; + if (s === 0) ; else if ((this || _global$1$1).length > s) { + (this || _global$1$1).length -= s; - for (i = 0; i < (this || _global$c).length; i++) { - (this || _global$c).words[i] = (this || _global$c).words[i + s]; + for (i = 0; i < (this || _global$1$1).length; i++) { + (this || _global$1$1).words[i] = (this || _global$1$1).words[i + s]; } } else { - (this || _global$c).words[0] = 0; - (this || _global$c).length = 1; + (this || _global$1$1).words[0] = 0; + (this || _global$1$1).length = 1; } var carry = 0; - for (i = (this || _global$c).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$c).words[i] | 0; - (this || _global$c).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$1$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$1$1).words[i] | 0; + (this || _global$1$1).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -24832,9 +58785,9 @@ function dew$11$1() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$c).length === 0) { - (this || _global$c).words[0] = 0; - (this || _global$c).length = 1; + if ((this || _global$1$1).length === 0) { + (this || _global$1$1).words[0] = 0; + (this || _global$1$1).length = 1; } return this.strip(); @@ -24842,7 +58795,7 @@ function dew$11$1() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$c).negative === 0); + assert((this || _global$1$1).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -24871,9 +58824,9 @@ function dew$11$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$c).length <= s) return false; // Check bit and return + if ((this || _global$1$1).length <= s) return false; // Check bit and return - var w = (this || _global$c).words[s]; + var w = (this || _global$1$1).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -24882,21 +58835,21 @@ function dew$11$1() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$c).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$1$1).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$c).length <= s) { - return this || _global$c; + if ((this || _global$1$1).length <= s) { + return this || _global$1$1; } if (r !== 0) { s++; } - (this || _global$c).length = Math.min(s, (this || _global$c).length); + (this || _global$1$1).length = Math.min(s, (this || _global$1$1).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$c).words[(this || _global$c).length - 1] &= mask; + (this || _global$1$1).words[(this || _global$1$1).length - 1] &= mask; } return this.strip(); @@ -24913,17 +58866,17 @@ function dew$11$1() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$c).negative !== 0) { - if ((this || _global$c).length === 1 && ((this || _global$c).words[0] | 0) < num) { - (this || _global$c).words[0] = num - ((this || _global$c).words[0] | 0); - (this || _global$c).negative = 0; - return this || _global$c; + if ((this || _global$1$1).negative !== 0) { + if ((this || _global$1$1).length === 1 && ((this || _global$1$1).words[0] | 0) < num) { + (this || _global$1$1).words[0] = num - ((this || _global$1$1).words[0] | 0); + (this || _global$1$1).negative = 0; + return this || _global$1$1; } - (this || _global$c).negative = 0; + (this || _global$1$1).negative = 0; this.isubn(num); - (this || _global$c).negative = 1; - return this || _global$c; + (this || _global$1$1).negative = 1; + return this || _global$1$1; } // Add without checks @@ -24931,20 +58884,20 @@ function dew$11$1() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$c).words[0] += num; // Carry + (this || _global$1$1).words[0] += num; // Carry - for (var i = 0; i < (this || _global$c).length && (this || _global$c).words[i] >= 67108864; i++) { - (this || _global$c).words[i] -= 67108864; + for (var i = 0; i < (this || _global$1$1).length && (this || _global$1$1).words[i] >= 67108864; i++) { + (this || _global$1$1).words[i] -= 67108864; - if (i === (this || _global$c).length - 1) { - (this || _global$c).words[i + 1] = 1; + if (i === (this || _global$1$1).length - 1) { + (this || _global$1$1).words[i + 1] = 1; } else { - (this || _global$c).words[i + 1]++; + (this || _global$1$1).words[i + 1]++; } } - (this || _global$c).length = Math.max((this || _global$c).length, i + 1); - return this || _global$c; + (this || _global$1$1).length = Math.max((this || _global$1$1).length, i + 1); + return this || _global$1$1; }; // Subtract plain number `num` from `this` @@ -24953,23 +58906,23 @@ function dew$11$1() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$c).negative !== 0) { - (this || _global$c).negative = 0; + if ((this || _global$1$1).negative !== 0) { + (this || _global$1$1).negative = 0; this.iaddn(num); - (this || _global$c).negative = 1; - return this || _global$c; + (this || _global$1$1).negative = 1; + return this || _global$1$1; } - (this || _global$c).words[0] -= num; + (this || _global$1$1).words[0] -= num; - if ((this || _global$c).length === 1 && (this || _global$c).words[0] < 0) { - (this || _global$c).words[0] = -(this || _global$c).words[0]; - (this || _global$c).negative = 1; + if ((this || _global$1$1).length === 1 && (this || _global$1$1).words[0] < 0) { + (this || _global$1$1).words[0] = -(this || _global$1$1).words[0]; + (this || _global$1$1).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$c).length && (this || _global$c).words[i] < 0; i++) { - (this || _global$c).words[i] += 67108864; - (this || _global$c).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$1$1).length && (this || _global$1$1).words[i] < 0; i++) { + (this || _global$1$1).words[i] += 67108864; + (this || _global$1$1).words[i + 1] -= 1; } } @@ -24985,8 +58938,8 @@ function dew$11$1() { }; BN.prototype.iabs = function iabs() { - (this || _global$c).negative = 0; - return this || _global$c; + (this || _global$1$1).negative = 0; + return this || _global$1$1; }; BN.prototype.abs = function abs() { @@ -25003,17 +58956,17 @@ function dew$11$1() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$c).words[i + shift] | 0) + carry; + w = ((this || _global$1$1).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$c).words[i + shift] = w & 67108863; + (this || _global$1$1).words[i + shift] = w & 67108863; } - for (; i < (this || _global$c).length - shift; i++) { - w = ((this || _global$c).words[i + shift] | 0) + carry; + for (; i < (this || _global$1$1).length - shift; i++) { + w = ((this || _global$1$1).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$c).words[i + shift] = w & 67108863; + (this || _global$1$1).words[i + shift] = w & 67108863; } if (carry === 0) return this.strip(); // Subtraction overflow @@ -25021,18 +58974,18 @@ function dew$11$1() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$c).length; i++) { - w = -((this || _global$c).words[i] | 0) + carry; + for (i = 0; i < (this || _global$1$1).length; i++) { + w = -((this || _global$1$1).words[i] | 0) + carry; carry = w >> 26; - (this || _global$c).words[i] = w & 67108863; + (this || _global$1$1).words[i] = w & 67108863; } - (this || _global$c).negative = 1; + (this || _global$1$1).negative = 1; return this.strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$c).length - num.length; + var shift = (this || _global$1$1).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -25128,7 +59081,7 @@ function dew$11$1() { var div, mod, res; - if ((this || _global$c).negative !== 0 && num.negative === 0) { + if ((this || _global$1$1).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -25149,7 +59102,7 @@ function dew$11$1() { }; } - if ((this || _global$c).negative === 0 && num.negative !== 0) { + if ((this || _global$1$1).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -25162,7 +59115,7 @@ function dew$11$1() { }; } - if (((this || _global$c).negative & num.negative) !== 0) { + if (((this || _global$1$1).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -25181,10 +59134,10 @@ function dew$11$1() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$c).length || this.cmp(num) < 0) { + if (num.length > (this || _global$1$1).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$c + mod: this || _global$1$1 }; } // Very short reduction @@ -25247,8 +59200,8 @@ function dew$11$1() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$c).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$c).words[i] | 0)) % num; + for (var i = (this || _global$1$1).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$1$1).words[i] | 0)) % num; } return acc; @@ -25259,9 +59212,9 @@ function dew$11$1() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$c).length - 1; i >= 0; i--) { - var w = ((this || _global$c).words[i] | 0) + carry * 67108864; - (this || _global$c).words[i] = w / num | 0; + for (var i = (this || _global$1$1).length - 1; i >= 0; i--) { + var w = ((this || _global$1$1).words[i] | 0) + carry * 67108864; + (this || _global$1$1).words[i] = w / num | 0; carry = w % num; } @@ -25275,7 +59228,7 @@ function dew$11$1() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$c; + var x = this || _global$1$1; var y = p.clone(); if (x.negative !== 0) { @@ -25358,7 +59311,7 @@ function dew$11$1() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$c; + var a = this || _global$1$1; var b = p.clone(); if (a.negative !== 0) { @@ -25411,882 +59364,1456 @@ function dew$11$1() { var res; - if (a.cmpn(1) === 0) { - res = x1; - } else { - res = x2; - } + if (a.cmpn(1) === 0) { + res = x1; + } else { + res = x2; + } + + if (res.cmpn(0) < 0) { + res.iadd(p); + } + + return res; + }; + + BN.prototype.gcd = function gcd(num) { + if (this.isZero()) return num.abs(); + if (num.isZero()) return this.abs(); + var a = this.clone(); + var b = num.clone(); + a.negative = 0; + b.negative = 0; // Remove common factor of two + + for (var shift = 0; a.isEven() && b.isEven(); shift++) { + a.iushrn(1); + b.iushrn(1); + } + + do { + while (a.isEven()) { + a.iushrn(1); + } + + while (b.isEven()) { + b.iushrn(1); + } + + var r = a.cmp(b); + + if (r < 0) { + // Swap `a` and `b` to make `a` always bigger than `b` + var t = a; + a = b; + b = t; + } else if (r === 0 || b.cmpn(1) === 0) { + break; + } + + a.isub(b); + } while (true); + + return b.iushln(shift); + }; // Invert number in the field F(num) + + + BN.prototype.invm = function invm(num) { + return this.egcd(num).a.umod(num); + }; + + BN.prototype.isEven = function isEven() { + return ((this || _global$1$1).words[0] & 1) === 0; + }; + + BN.prototype.isOdd = function isOdd() { + return ((this || _global$1$1).words[0] & 1) === 1; + }; // And first word and num + + + BN.prototype.andln = function andln(num) { + return (this || _global$1$1).words[0] & num; + }; // Increment at the bit position in-line + + + BN.prototype.bincn = function bincn(bit) { + assert(typeof bit === "number"); + var r = bit % 26; + var s = (bit - r) / 26; + var q = 1 << r; // Fast case: bit is much higher than all existing words + + if ((this || _global$1$1).length <= s) { + this._expand(s + 1); + + (this || _global$1$1).words[s] |= q; + return this || _global$1$1; + } // Add bit and propagate, if needed + + + var carry = q; + + for (var i = s; carry !== 0 && i < (this || _global$1$1).length; i++) { + var w = (this || _global$1$1).words[i] | 0; + w += carry; + carry = w >>> 26; + w &= 67108863; + (this || _global$1$1).words[i] = w; + } + + if (carry !== 0) { + (this || _global$1$1).words[i] = carry; + (this || _global$1$1).length++; + } + + return this || _global$1$1; + }; + + BN.prototype.isZero = function isZero() { + return (this || _global$1$1).length === 1 && (this || _global$1$1).words[0] === 0; + }; + + BN.prototype.cmpn = function cmpn(num) { + var negative = num < 0; + if ((this || _global$1$1).negative !== 0 && !negative) return -1; + if ((this || _global$1$1).negative === 0 && negative) return 1; + this.strip(); + var res; + + if ((this || _global$1$1).length > 1) { + res = 1; + } else { + if (negative) { + num = -num; + } + + assert(num <= 67108863, "Number is too big"); + var w = (this || _global$1$1).words[0] | 0; + res = w === num ? 0 : w < num ? -1 : 1; + } + + if ((this || _global$1$1).negative !== 0) return -res | 0; + return res; + }; // Compare two numbers and return: + // 1 - if `this` > `num` + // 0 - if `this` == `num` + // -1 - if `this` < `num` + + + BN.prototype.cmp = function cmp(num) { + if ((this || _global$1$1).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$1$1).negative === 0 && num.negative !== 0) return 1; + var res = this.ucmp(num); + if ((this || _global$1$1).negative !== 0) return -res | 0; + return res; + }; // Unsigned comparison + + + BN.prototype.ucmp = function ucmp(num) { + // At this point both numbers have the same sign + if ((this || _global$1$1).length > num.length) return 1; + if ((this || _global$1$1).length < num.length) return -1; + var res = 0; + + for (var i = (this || _global$1$1).length - 1; i >= 0; i--) { + var a = (this || _global$1$1).words[i] | 0; + var b = num.words[i] | 0; + if (a === b) continue; + + if (a < b) { + res = -1; + } else if (a > b) { + res = 1; + } + + break; + } + + return res; + }; + + BN.prototype.gtn = function gtn(num) { + return this.cmpn(num) === 1; + }; + + BN.prototype.gt = function gt(num) { + return this.cmp(num) === 1; + }; + + BN.prototype.gten = function gten(num) { + return this.cmpn(num) >= 0; + }; + + BN.prototype.gte = function gte(num) { + return this.cmp(num) >= 0; + }; + + BN.prototype.ltn = function ltn(num) { + return this.cmpn(num) === -1; + }; + + BN.prototype.lt = function lt(num) { + return this.cmp(num) === -1; + }; + + BN.prototype.lten = function lten(num) { + return this.cmpn(num) <= 0; + }; + + BN.prototype.lte = function lte(num) { + return this.cmp(num) <= 0; + }; + + BN.prototype.eqn = function eqn(num) { + return this.cmpn(num) === 0; + }; + + BN.prototype.eq = function eq(num) { + return this.cmp(num) === 0; + }; // + // A reduce context, could be using montgomery or something better, depending + // on the `m` itself. + // + + + BN.red = function red(num) { + return new Red(num); + }; + + BN.prototype.toRed = function toRed(ctx) { + assert(!(this || _global$1$1).red, "Already a number in reduction context"); + assert((this || _global$1$1).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$1$1)._forceRed(ctx); + }; + + BN.prototype.fromRed = function fromRed() { + assert((this || _global$1$1).red, "fromRed works only with numbers in reduction context"); + return (this || _global$1$1).red.convertFrom(this || _global$1$1); + }; + + BN.prototype._forceRed = function _forceRed(ctx) { + (this || _global$1$1).red = ctx; + return this || _global$1$1; + }; + + BN.prototype.forceRed = function forceRed(ctx) { + assert(!(this || _global$1$1).red, "Already a number in reduction context"); + return this._forceRed(ctx); + }; + + BN.prototype.redAdd = function redAdd(num) { + assert((this || _global$1$1).red, "redAdd works only with red numbers"); + return (this || _global$1$1).red.add(this || _global$1$1, num); + }; + + BN.prototype.redIAdd = function redIAdd(num) { + assert((this || _global$1$1).red, "redIAdd works only with red numbers"); + return (this || _global$1$1).red.iadd(this || _global$1$1, num); + }; + + BN.prototype.redSub = function redSub(num) { + assert((this || _global$1$1).red, "redSub works only with red numbers"); + return (this || _global$1$1).red.sub(this || _global$1$1, num); + }; + + BN.prototype.redISub = function redISub(num) { + assert((this || _global$1$1).red, "redISub works only with red numbers"); + return (this || _global$1$1).red.isub(this || _global$1$1, num); + }; + + BN.prototype.redShl = function redShl(num) { + assert((this || _global$1$1).red, "redShl works only with red numbers"); + return (this || _global$1$1).red.shl(this || _global$1$1, num); + }; + + BN.prototype.redMul = function redMul(num) { + assert((this || _global$1$1).red, "redMul works only with red numbers"); + + (this || _global$1$1).red._verify2(this || _global$1$1, num); + + return (this || _global$1$1).red.mul(this || _global$1$1, num); + }; + + BN.prototype.redIMul = function redIMul(num) { + assert((this || _global$1$1).red, "redMul works only with red numbers"); + + (this || _global$1$1).red._verify2(this || _global$1$1, num); + + return (this || _global$1$1).red.imul(this || _global$1$1, num); + }; + + BN.prototype.redSqr = function redSqr() { + assert((this || _global$1$1).red, "redSqr works only with red numbers"); + + (this || _global$1$1).red._verify1(this || _global$1$1); + + return (this || _global$1$1).red.sqr(this || _global$1$1); + }; + + BN.prototype.redISqr = function redISqr() { + assert((this || _global$1$1).red, "redISqr works only with red numbers"); + + (this || _global$1$1).red._verify1(this || _global$1$1); + + return (this || _global$1$1).red.isqr(this || _global$1$1); + }; // Square root over p + + + BN.prototype.redSqrt = function redSqrt() { + assert((this || _global$1$1).red, "redSqrt works only with red numbers"); + + (this || _global$1$1).red._verify1(this || _global$1$1); + + return (this || _global$1$1).red.sqrt(this || _global$1$1); + }; + + BN.prototype.redInvm = function redInvm() { + assert((this || _global$1$1).red, "redInvm works only with red numbers"); + + (this || _global$1$1).red._verify1(this || _global$1$1); + + return (this || _global$1$1).red.invm(this || _global$1$1); + }; // Return negative clone of `this` % `red modulo` + + + BN.prototype.redNeg = function redNeg() { + assert((this || _global$1$1).red, "redNeg works only with red numbers"); + + (this || _global$1$1).red._verify1(this || _global$1$1); + + return (this || _global$1$1).red.neg(this || _global$1$1); + }; + + BN.prototype.redPow = function redPow(num) { + assert((this || _global$1$1).red && !num.red, "redPow(normalNum)"); + + (this || _global$1$1).red._verify1(this || _global$1$1); + + return (this || _global$1$1).red.pow(this || _global$1$1, num); + }; // Prime numbers with efficient reduction + + + var primes = { + k256: null, + p224: null, + p192: null, + p25519: null + }; // Pseudo-Mersenne prime + + function MPrime(name, p) { + // P = 2 ^ N - K + (this || _global$1$1).name = name; + (this || _global$1$1).p = new BN(p, 16); + (this || _global$1$1).n = (this || _global$1$1).p.bitLength(); + (this || _global$1$1).k = new BN(1).iushln((this || _global$1$1).n).isub((this || _global$1$1).p); + (this || _global$1$1).tmp = this._tmp(); + } + + MPrime.prototype._tmp = function _tmp() { + var tmp = new BN(null); + tmp.words = new Array(Math.ceil((this || _global$1$1).n / 13)); + return tmp; + }; + + MPrime.prototype.ireduce = function ireduce(num) { + // Assumes that `num` is less than `P^2` + // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) + var r = num; + var rlen; + + do { + this.split(r, (this || _global$1$1).tmp); + r = this.imulK(r); + r = r.iadd((this || _global$1$1).tmp); + rlen = r.bitLength(); + } while (rlen > (this || _global$1$1).n); + + var cmp = rlen < (this || _global$1$1).n ? -1 : r.ucmp((this || _global$1$1).p); + + if (cmp === 0) { + r.words[0] = 0; + r.length = 1; + } else if (cmp > 0) { + r.isub((this || _global$1$1).p); + } else { + if (r.strip !== undefined) { + // r is BN v4 instance + r.strip(); + } else { + // r is BN v5 instance + r._strip(); + } + } + + return r; + }; + + MPrime.prototype.split = function split(input, out) { + input.iushrn((this || _global$1$1).n, 0, out); + }; + + MPrime.prototype.imulK = function imulK(num) { + return num.imul((this || _global$1$1).k); + }; + + function K256() { + MPrime.call(this || _global$1$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + } + + inherits(K256, MPrime); + + K256.prototype.split = function split(input, output) { + // 256 = 9 * 26 + 22 + var mask = 4194303; + var outLen = Math.min(input.length, 9); + + for (var i = 0; i < outLen; i++) { + output.words[i] = input.words[i]; + } + + output.length = outLen; + + if (input.length <= 9) { + input.words[0] = 0; + input.length = 1; + return; + } // Shift by 9 limbs + + + var prev = input.words[9]; + output.words[output.length++] = prev & mask; + + for (i = 10; i < input.length; i++) { + var next = input.words[i] | 0; + input.words[i - 10] = (next & mask) << 4 | prev >>> 22; + prev = next; + } + + prev >>>= 22; + input.words[i - 10] = prev; + + if (prev === 0 && input.length > 10) { + input.length -= 10; + } else { + input.length -= 9; + } + }; + + K256.prototype.imulK = function imulK(num) { + // K = 0x1000003d1 = [ 0x40, 0x3d1 ] + num.words[num.length] = 0; + num.words[num.length + 1] = 0; + num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + + var lo = 0; + + for (var i = 0; i < num.length; i++) { + var w = num.words[i] | 0; + lo += w * 977; + num.words[i] = lo & 67108863; + lo = w * 64 + (lo / 67108864 | 0); + } // Fast length reduction + + + if (num.words[num.length - 1] === 0) { + num.length--; - if (res.cmpn(0) < 0) { - res.iadd(p); + if (num.words[num.length - 1] === 0) { + num.length--; + } } - return res; + return num; }; - BN.prototype.gcd = function gcd(num) { - if (this.isZero()) return num.abs(); - if (num.isZero()) return this.abs(); - var a = this.clone(); - var b = num.clone(); - a.negative = 0; - b.negative = 0; // Remove common factor of two - - for (var shift = 0; a.isEven() && b.isEven(); shift++) { - a.iushrn(1); - b.iushrn(1); - } + function P224() { + MPrime.call(this || _global$1$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + } - do { - while (a.isEven()) { - a.iushrn(1); - } + inherits(P224, MPrime); - while (b.isEven()) { - b.iushrn(1); - } + function P192() { + MPrime.call(this || _global$1$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + } - var r = a.cmp(b); + inherits(P192, MPrime); - if (r < 0) { - // Swap `a` and `b` to make `a` always bigger than `b` - var t = a; - a = b; - b = t; - } else if (r === 0 || b.cmpn(1) === 0) { - break; - } + function P25519() { + // 2 ^ 255 - 19 + MPrime.call(this || _global$1$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + } - a.isub(b); - } while (true); + inherits(P25519, MPrime); - return b.iushln(shift); - }; // Invert number in the field F(num) + P25519.prototype.imulK = function imulK(num) { + // K = 0x13 + var carry = 0; + for (var i = 0; i < num.length; i++) { + var hi = (num.words[i] | 0) * 19 + carry; + var lo = hi & 67108863; + hi >>>= 26; + num.words[i] = lo; + carry = hi; + } - BN.prototype.invm = function invm(num) { - return this.egcd(num).a.umod(num); - }; + if (carry !== 0) { + num.words[num.length++] = carry; + } - BN.prototype.isEven = function isEven() { - return ((this || _global$c).words[0] & 1) === 0; - }; + return num; + }; // Exported mostly for testing purposes, use plain name instead - BN.prototype.isOdd = function isOdd() { - return ((this || _global$c).words[0] & 1) === 1; - }; // And first word and num + BN._prime = function prime(name) { + // Cached version of prime + if (primes[name]) return primes[name]; + var prime; - BN.prototype.andln = function andln(num) { - return (this || _global$c).words[0] & num; - }; // Increment at the bit position in-line + if (name === "k256") { + prime = new K256(); + } else if (name === "p224") { + prime = new P224(); + } else if (name === "p192") { + prime = new P192(); + } else if (name === "p25519") { + prime = new P25519(); + } else { + throw new Error("Unknown prime " + name); + } + primes[name] = prime; + return prime; + }; // + // Base reduction engine + // - BN.prototype.bincn = function bincn(bit) { - assert(typeof bit === "number"); - var r = bit % 26; - var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$c).length <= s) { - this._expand(s + 1); + function Red(m) { + if (typeof m === "string") { + var prime = BN._prime(m); - (this || _global$c).words[s] |= q; - return this || _global$c; - } // Add bit and propagate, if needed + (this || _global$1$1).m = prime.p; + (this || _global$1$1).prime = prime; + } else { + assert(m.gtn(1), "modulus must be greater than 1"); + (this || _global$1$1).m = m; + (this || _global$1$1).prime = null; + } + } + Red.prototype._verify1 = function _verify1(a) { + assert(a.negative === 0, "red works only with positives"); + assert(a.red, "red works only with red numbers"); + }; - var carry = q; + Red.prototype._verify2 = function _verify2(a, b) { + assert((a.negative | b.negative) === 0, "red works only with positives"); + assert(a.red && a.red === b.red, "red works only with red numbers"); + }; - for (var i = s; carry !== 0 && i < (this || _global$c).length; i++) { - var w = (this || _global$c).words[i] | 0; - w += carry; - carry = w >>> 26; - w &= 67108863; - (this || _global$c).words[i] = w; - } + Red.prototype.imod = function imod(a) { + if ((this || _global$1$1).prime) return (this || _global$1$1).prime.ireduce(a)._forceRed(this || _global$1$1); + return a.umod((this || _global$1$1).m)._forceRed(this || _global$1$1); + }; - if (carry !== 0) { - (this || _global$c).words[i] = carry; - (this || _global$c).length++; + Red.prototype.neg = function neg(a) { + if (a.isZero()) { + return a.clone(); } - return this || _global$c; + return (this || _global$1$1).m.sub(a)._forceRed(this || _global$1$1); }; - BN.prototype.isZero = function isZero() { - return (this || _global$c).length === 1 && (this || _global$c).words[0] === 0; + Red.prototype.add = function add(a, b) { + this._verify2(a, b); + + var res = a.add(b); + + if (res.cmp((this || _global$1$1).m) >= 0) { + res.isub((this || _global$1$1).m); + } + + return res._forceRed(this || _global$1$1); }; - BN.prototype.cmpn = function cmpn(num) { - var negative = num < 0; - if ((this || _global$c).negative !== 0 && !negative) return -1; - if ((this || _global$c).negative === 0 && negative) return 1; - this.strip(); - var res; + Red.prototype.iadd = function iadd(a, b) { + this._verify2(a, b); - if ((this || _global$c).length > 1) { - res = 1; - } else { - if (negative) { - num = -num; - } + var res = a.iadd(b); - assert(num <= 67108863, "Number is too big"); - var w = (this || _global$c).words[0] | 0; - res = w === num ? 0 : w < num ? -1 : 1; + if (res.cmp((this || _global$1$1).m) >= 0) { + res.isub((this || _global$1$1).m); } - if ((this || _global$c).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: - // 1 - if `this` > `num` - // 0 - if `this` == `num` - // -1 - if `this` < `num` + }; + Red.prototype.sub = function sub(a, b) { + this._verify2(a, b); - BN.prototype.cmp = function cmp(num) { - if ((this || _global$c).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$c).negative === 0 && num.negative !== 0) return 1; - var res = this.ucmp(num); - if ((this || _global$c).negative !== 0) return -res | 0; - return res; - }; // Unsigned comparison + var res = a.sub(b); + if (res.cmpn(0) < 0) { + res.iadd((this || _global$1$1).m); + } - BN.prototype.ucmp = function ucmp(num) { - // At this point both numbers have the same sign - if ((this || _global$c).length > num.length) return 1; - if ((this || _global$c).length < num.length) return -1; - var res = 0; + return res._forceRed(this || _global$1$1); + }; - for (var i = (this || _global$c).length - 1; i >= 0; i--) { - var a = (this || _global$c).words[i] | 0; - var b = num.words[i] | 0; - if (a === b) continue; + Red.prototype.isub = function isub(a, b) { + this._verify2(a, b); - if (a < b) { - res = -1; - } else if (a > b) { - res = 1; - } + var res = a.isub(b); - break; + if (res.cmpn(0) < 0) { + res.iadd((this || _global$1$1).m); } return res; }; - BN.prototype.gtn = function gtn(num) { - return this.cmpn(num) === 1; - }; + Red.prototype.shl = function shl(a, num) { + this._verify1(a); - BN.prototype.gt = function gt(num) { - return this.cmp(num) === 1; + return this.imod(a.ushln(num)); }; - BN.prototype.gten = function gten(num) { - return this.cmpn(num) >= 0; - }; + Red.prototype.imul = function imul(a, b) { + this._verify2(a, b); - BN.prototype.gte = function gte(num) { - return this.cmp(num) >= 0; + return this.imod(a.imul(b)); }; - BN.prototype.ltn = function ltn(num) { - return this.cmpn(num) === -1; - }; + Red.prototype.mul = function mul(a, b) { + this._verify2(a, b); - BN.prototype.lt = function lt(num) { - return this.cmp(num) === -1; + return this.imod(a.mul(b)); }; - BN.prototype.lten = function lten(num) { - return this.cmpn(num) <= 0; + Red.prototype.isqr = function isqr(a) { + return this.imul(a, a.clone()); }; - BN.prototype.lte = function lte(num) { - return this.cmp(num) <= 0; + Red.prototype.sqr = function sqr(a) { + return this.mul(a, a); }; - BN.prototype.eqn = function eqn(num) { - return this.cmpn(num) === 0; - }; + Red.prototype.sqrt = function sqrt(a) { + if (a.isZero()) return a.clone(); - BN.prototype.eq = function eq(num) { - return this.cmp(num) === 0; - }; // - // A reduce context, could be using montgomery or something better, depending - // on the `m` itself. - // + var mod3 = (this || _global$1$1).m.andln(3); + assert(mod3 % 2 === 1); // Fast case - BN.red = function red(num) { - return new Red(num); - }; + if (mod3 === 3) { + var pow = (this || _global$1$1).m.add(new BN(1)).iushrn(2); - BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$c).red, "Already a number in reduction context"); - assert((this || _global$c).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$c)._forceRed(ctx); - }; + return this.pow(a, pow); + } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + // + // Find Q and S, that Q * 2 ^ S = (P - 1) - BN.prototype.fromRed = function fromRed() { - assert((this || _global$c).red, "fromRed works only with numbers in reduction context"); - return (this || _global$c).red.convertFrom(this || _global$c); - }; - BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$c).red = ctx; - return this || _global$c; - }; + var q = (this || _global$1$1).m.subn(1); - BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$c).red, "Already a number in reduction context"); - return this._forceRed(ctx); - }; + var s = 0; - BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$c).red, "redAdd works only with red numbers"); - return (this || _global$c).red.add(this || _global$c, num); - }; + while (!q.isZero() && q.andln(1) === 0) { + s++; + q.iushrn(1); + } - BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$c).red, "redIAdd works only with red numbers"); - return (this || _global$c).red.iadd(this || _global$c, num); - }; + assert(!q.isZero()); + var one = new BN(1).toRed(this || _global$1$1); + var nOne = one.redNeg(); // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. - BN.prototype.redSub = function redSub(num) { - assert((this || _global$c).red, "redSub works only with red numbers"); - return (this || _global$c).red.sub(this || _global$c, num); - }; + var lpow = (this || _global$1$1).m.subn(1).iushrn(1); - BN.prototype.redISub = function redISub(num) { - assert((this || _global$c).red, "redISub works only with red numbers"); - return (this || _global$c).red.isub(this || _global$c, num); - }; + var z = (this || _global$1$1).m.bitLength(); - BN.prototype.redShl = function redShl(num) { - assert((this || _global$c).red, "redShl works only with red numbers"); - return (this || _global$c).red.shl(this || _global$c, num); - }; + z = new BN(2 * z * z).toRed(this || _global$1$1); - BN.prototype.redMul = function redMul(num) { - assert((this || _global$c).red, "redMul works only with red numbers"); + while (this.pow(z, lpow).cmp(nOne) !== 0) { + z.redIAdd(nOne); + } - (this || _global$c).red._verify2(this || _global$c, num); + var c = this.pow(z, q); + var r = this.pow(a, q.addn(1).iushrn(1)); + var t = this.pow(a, q); + var m = s; - return (this || _global$c).red.mul(this || _global$c, num); - }; + while (t.cmp(one) !== 0) { + var tmp = t; - BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$c).red, "redMul works only with red numbers"); + for (var i = 0; tmp.cmp(one) !== 0; i++) { + tmp = tmp.redSqr(); + } - (this || _global$c).red._verify2(this || _global$c, num); + assert(i < m); + var b = this.pow(c, new BN(1).iushln(m - i - 1)); + r = r.redMul(b); + c = b.redSqr(); + t = t.redMul(c); + m = i; + } - return (this || _global$c).red.imul(this || _global$c, num); + return r; }; - BN.prototype.redSqr = function redSqr() { - assert((this || _global$c).red, "redSqr works only with red numbers"); - - (this || _global$c).red._verify1(this || _global$c); + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$1$1).m); - return (this || _global$c).red.sqr(this || _global$c); + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } }; - BN.prototype.redISqr = function redISqr() { - assert((this || _global$c).red, "redISqr works only with red numbers"); - - (this || _global$c).red._verify1(this || _global$c); - - return (this || _global$c).red.isqr(this || _global$c); - }; // Square root over p + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$1$1); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$1$1); + wnd[1] = a; + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } - BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$c).red, "redSqrt works only with red numbers"); + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; - (this || _global$c).red._verify1(this || _global$c); + if (start === 0) { + start = 26; + } - return (this || _global$c).red.sqrt(this || _global$c); - }; + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; - BN.prototype.redInvm = function redInvm() { - assert((this || _global$c).red, "redInvm works only with red numbers"); + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; - (this || _global$c).red._verify1(this || _global$c); + if (res !== wnd[0]) { + res = this.sqr(res); + } - return (this || _global$c).red.invm(this || _global$c); - }; // Return negative clone of `this` % `red modulo` + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } - BN.prototype.redNeg = function redNeg() { - assert((this || _global$c).red, "redNeg works only with red numbers"); + start = 26; + } - (this || _global$c).red._verify1(this || _global$c); + return res; + }; - return (this || _global$c).red.neg(this || _global$c); + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$1$1).m); + return r === num ? r.clone() : r; }; - BN.prototype.redPow = function redPow(num) { - assert((this || _global$c).red && !num.red, "redPow(normalNum)"); + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // - (this || _global$c).red._verify1(this || _global$c); - return (this || _global$c).red.pow(this || _global$c, num); - }; // Prime numbers with efficient reduction + BN.mont = function mont(num) { + return new Mont(num); + }; + function Mont(m) { + Red.call(this || _global$1$1, m); + (this || _global$1$1).shift = (this || _global$1$1).m.bitLength(); - var primes = { - k256: null, - p224: null, - p192: null, - p25519: null - }; // Pseudo-Mersenne prime + if ((this || _global$1$1).shift % 26 !== 0) { + (this || _global$1$1).shift += 26 - (this || _global$1$1).shift % 26; + } - function MPrime(name, p) { - // P = 2 ^ N - K - (this || _global$c).name = name; - (this || _global$c).p = new BN(p, 16); - (this || _global$c).n = (this || _global$c).p.bitLength(); - (this || _global$c).k = new BN(1).iushln((this || _global$c).n).isub((this || _global$c).p); - (this || _global$c).tmp = this._tmp(); + (this || _global$1$1).r = new BN(1).iushln((this || _global$1$1).shift); + (this || _global$1$1).r2 = this.imod((this || _global$1$1).r.sqr()); + (this || _global$1$1).rinv = (this || _global$1$1).r._invmp((this || _global$1$1).m); + (this || _global$1$1).minv = (this || _global$1$1).rinv.mul((this || _global$1$1).r).isubn(1).div((this || _global$1$1).m); + (this || _global$1$1).minv = (this || _global$1$1).minv.umod((this || _global$1$1).r); + (this || _global$1$1).minv = (this || _global$1$1).r.sub((this || _global$1$1).minv); } - MPrime.prototype._tmp = function _tmp() { - var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$c).n / 13)); - return tmp; + inherits(Mont, Red); + + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$1$1).shift)); }; - MPrime.prototype.ireduce = function ireduce(num) { - // Assumes that `num` is less than `P^2` - // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) - var r = num; - var rlen; + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$1$1).rinv)); + r.red = null; + return r; + }; + + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + + var t = a.imul(b); + var c = t.maskn((this || _global$1$1).shift).mul((this || _global$1$1).minv).imaskn((this || _global$1$1).shift).mul((this || _global$1$1).m); + var u = t.isub(c).iushrn((this || _global$1$1).shift); + var res = u; + + if (u.cmp((this || _global$1$1).m) >= 0) { + res = u.isub((this || _global$1$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$1$1).m); + } - do { - this.split(r, (this || _global$c).tmp); - r = this.imulK(r); - r = r.iadd((this || _global$c).tmp); - rlen = r.bitLength(); - } while (rlen > (this || _global$c).n); + return res._forceRed(this || _global$1$1); + }; - var cmp = rlen < (this || _global$c).n ? -1 : r.ucmp((this || _global$c).p); + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$1$1); + var t = a.mul(b); + var c = t.maskn((this || _global$1$1).shift).mul((this || _global$1$1).minv).imaskn((this || _global$1$1).shift).mul((this || _global$1$1).m); + var u = t.isub(c).iushrn((this || _global$1$1).shift); + var res = u; - if (cmp === 0) { - r.words[0] = 0; - r.length = 1; - } else if (cmp > 0) { - r.isub((this || _global$c).p); - } else { - if (r.strip !== undefined) { - // r is BN v4 instance - r.strip(); - } else { - // r is BN v5 instance - r._strip(); - } + if (u.cmp((this || _global$1$1).m) >= 0) { + res = u.isub((this || _global$1$1).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$1$1).m); } - return r; + return res._forceRed(this || _global$1$1); }; - MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$c).n, 0, out); + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$1$1).m).mul((this || _global$1$1).r2)); + return res._forceRed(this || _global$1$1); }; + })(module$8, exports$6$1); - MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$c).k); - }; + return module$8.exports; +} - function K256() { - MPrime.call(this || _global$c, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); - } +var exports$5$1 = {}, + _dewExec$5$1 = false; +function dew$5$1() { + if (_dewExec$5$1) return exports$5$1; + _dewExec$5$1 = true; - inherits(K256, MPrime); + var BN = dew$6$1(); - K256.prototype.split = function split(input, output) { - // 256 = 9 * 26 + 22 - var mask = 4194303; - var outLen = Math.min(input.length, 9); + var Buffer = dew$1T().Buffer; - for (var i = 0; i < outLen; i++) { - output.words[i] = input.words[i]; - } + function withPublic(paddedMsg, key) { + return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray()); + } - output.length = outLen; + exports$5$1 = withPublic; + return exports$5$1; +} - if (input.length <= 9) { - input.words[0] = 0; - input.length = 1; - return; - } // Shift by 9 limbs +var exports$4$1 = {}, + _dewExec$4$1 = false; +function dew$4$1() { + if (_dewExec$4$1) return exports$4$1; + _dewExec$4$1 = true; + var parseKeys = dew$e$1(); - var prev = input.words[9]; - output.words[output.length++] = prev & mask; + var randomBytes = dew$1S(); - for (i = 10; i < input.length; i++) { - var next = input.words[i] | 0; - input.words[i - 10] = (next & mask) << 4 | prev >>> 22; - prev = next; - } + var createHash = dew$1F(); - prev >>>= 22; - input.words[i - 10] = prev; + var mgf = dew$8$1(); - if (prev === 0 && input.length > 10) { - input.length -= 10; - } else { - input.length -= 9; - } - }; + var xor = dew$7$1(); - K256.prototype.imulK = function imulK(num) { - // K = 0x1000003d1 = [ 0x40, 0x3d1 ] - num.words[num.length] = 0; - num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + var BN = dew$6$1(); - var lo = 0; + var withPublic = dew$5$1(); - for (var i = 0; i < num.length; i++) { - var w = num.words[i] | 0; - lo += w * 977; - num.words[i] = lo & 67108863; - lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction + var crt = dew$W$1(); + var Buffer = dew$1T().Buffer; - if (num.words[num.length - 1] === 0) { - num.length--; + exports$4$1 = function publicEncrypt(publicKey, msg, reverse) { + var padding; - if (num.words[num.length - 1] === 0) { - num.length--; - } + if (publicKey.padding) { + padding = publicKey.padding; + } else if (reverse) { + padding = 1; + } else { + padding = 4; + } + + var key = parseKeys(publicKey); + var paddedMsg; + + if (padding === 4) { + paddedMsg = oaep(key, msg); + } else if (padding === 1) { + paddedMsg = pkcs1(key, msg, reverse); + } else if (padding === 3) { + paddedMsg = new BN(msg); + + if (paddedMsg.cmp(key.modulus) >= 0) { + throw new Error("data too long for modulus"); } + } else { + throw new Error("unknown padding"); + } - return num; - }; + if (reverse) { + return crt(paddedMsg, key); + } else { + return withPublic(paddedMsg, key); + } + }; - function P224() { - MPrime.call(this || _global$c, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + function oaep(key, msg) { + var k = key.modulus.byteLength(); + var mLen = msg.length; + var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); + var hLen = iHash.length; + var hLen2 = 2 * hLen; + + if (mLen > k - hLen2 - 2) { + throw new Error("message too long"); } - inherits(P224, MPrime); + var ps = Buffer.alloc(k - mLen - hLen2 - 2); + var dblen = k - hLen - 1; + var seed = randomBytes(hLen); + var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen)); + var maskedSeed = xor(seed, mgf(maskedDb, hLen)); + return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k)); + } - function P192() { - MPrime.call(this || _global$c, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + function pkcs1(key, msg, reverse) { + var mLen = msg.length; + var k = key.modulus.byteLength(); + + if (mLen > k - 11) { + throw new Error("message too long"); } - inherits(P192, MPrime); + var ps; - function P25519() { - // 2 ^ 255 - 19 - MPrime.call(this || _global$c, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + if (reverse) { + ps = Buffer.alloc(k - mLen - 3, 255); + } else { + ps = nonZero(k - mLen - 3); } - inherits(P25519, MPrime); + return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k)); + } - P25519.prototype.imulK = function imulK(num) { - // K = 0x13 - var carry = 0; + function nonZero(len) { + var out = Buffer.allocUnsafe(len); + var i = 0; + var cache = randomBytes(len * 2); + var cur = 0; + var num; - for (var i = 0; i < num.length; i++) { - var hi = (num.words[i] | 0) * 19 + carry; - var lo = hi & 67108863; - hi >>>= 26; - num.words[i] = lo; - carry = hi; + while (i < len) { + if (cur === cache.length) { + cache = randomBytes(len * 2); + cur = 0; } - if (carry !== 0) { - num.words[num.length++] = carry; + num = cache[cur++]; + + if (num) { + out[i++] = num; } + } - return num; - }; // Exported mostly for testing purposes, use plain name instead + return out; + } + return exports$4$1; +} - BN._prime = function prime(name) { - // Cached version of prime - if (primes[name]) return primes[name]; - var prime; +var exports$3$1 = {}, + _dewExec$3$1 = false; +function dew$3$1() { + if (_dewExec$3$1) return exports$3$1; + _dewExec$3$1 = true; - if (name === "k256") { - prime = new K256(); - } else if (name === "p224") { - prime = new P224(); - } else if (name === "p192") { - prime = new P192(); - } else if (name === "p25519") { - prime = new P25519(); - } else { - throw new Error("Unknown prime " + name); - } + var parseKeys = dew$e$1(); - primes[name] = prime; - return prime; - }; // - // Base reduction engine - // + var mgf = dew$8$1(); + + var xor = dew$7$1(); + var BN = dew$6$1(); - function Red(m) { - if (typeof m === "string") { - var prime = BN._prime(m); + var crt = dew$W$1(); - (this || _global$c).m = prime.p; - (this || _global$c).prime = prime; - } else { - assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$c).m = m; - (this || _global$c).prime = null; - } - } + var createHash = dew$1F(); - Red.prototype._verify1 = function _verify1(a) { - assert(a.negative === 0, "red works only with positives"); - assert(a.red, "red works only with red numbers"); - }; + var withPublic = dew$5$1(); - Red.prototype._verify2 = function _verify2(a, b) { - assert((a.negative | b.negative) === 0, "red works only with positives"); - assert(a.red && a.red === b.red, "red works only with red numbers"); - }; + var Buffer = dew$1T().Buffer; - Red.prototype.imod = function imod(a) { - if ((this || _global$c).prime) return (this || _global$c).prime.ireduce(a)._forceRed(this || _global$c); - return a.umod((this || _global$c).m)._forceRed(this || _global$c); - }; + exports$3$1 = function privateDecrypt(privateKey, enc, reverse) { + var padding; - Red.prototype.neg = function neg(a) { - if (a.isZero()) { - return a.clone(); - } + if (privateKey.padding) { + padding = privateKey.padding; + } else if (reverse) { + padding = 1; + } else { + padding = 4; + } - return (this || _global$c).m.sub(a)._forceRed(this || _global$c); - }; + var key = parseKeys(privateKey); + var k = key.modulus.byteLength(); - Red.prototype.add = function add(a, b) { - this._verify2(a, b); + if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) { + throw new Error("decryption error"); + } - var res = a.add(b); + var msg; - if (res.cmp((this || _global$c).m) >= 0) { - res.isub((this || _global$c).m); - } + if (reverse) { + msg = withPublic(new BN(enc), key); + } else { + msg = crt(enc, key); + } - return res._forceRed(this || _global$c); - }; + var zBuffer = Buffer.alloc(k - msg.length); + msg = Buffer.concat([zBuffer, msg], k); - Red.prototype.iadd = function iadd(a, b) { - this._verify2(a, b); + if (padding === 4) { + return oaep(key, msg); + } else if (padding === 1) { + return pkcs1(key, msg, reverse); + } else if (padding === 3) { + return msg; + } else { + throw new Error("unknown padding"); + } + }; - var res = a.iadd(b); + function oaep(key, msg) { + var k = key.modulus.byteLength(); + var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); + var hLen = iHash.length; - if (res.cmp((this || _global$c).m) >= 0) { - res.isub((this || _global$c).m); - } + if (msg[0] !== 0) { + throw new Error("decryption error"); + } - return res; - }; + var maskedSeed = msg.slice(1, hLen + 1); + var maskedDb = msg.slice(hLen + 1); + var seed = xor(maskedSeed, mgf(maskedDb, hLen)); + var db = xor(maskedDb, mgf(seed, k - hLen - 1)); - Red.prototype.sub = function sub(a, b) { - this._verify2(a, b); + if (compare(iHash, db.slice(0, hLen))) { + throw new Error("decryption error"); + } - var res = a.sub(b); + var i = hLen; - if (res.cmpn(0) < 0) { - res.iadd((this || _global$c).m); - } + while (db[i] === 0) { + i++; + } - return res._forceRed(this || _global$c); - }; + if (db[i++] !== 1) { + throw new Error("decryption error"); + } - Red.prototype.isub = function isub(a, b) { - this._verify2(a, b); + return db.slice(i); + } - var res = a.isub(b); + function pkcs1(key, msg, reverse) { + var p1 = msg.slice(0, 2); + var i = 2; + var status = 0; - if (res.cmpn(0) < 0) { - res.iadd((this || _global$c).m); + while (msg[i++] !== 0) { + if (i >= msg.length) { + status++; + break; } + } - return res; - }; + var ps = msg.slice(2, i - 1); - Red.prototype.shl = function shl(a, num) { - this._verify1(a); + if (p1.toString("hex") !== "0002" && !reverse || p1.toString("hex") !== "0001" && reverse) { + status++; + } - return this.imod(a.ushln(num)); - }; + if (ps.length < 8) { + status++; + } - Red.prototype.imul = function imul(a, b) { - this._verify2(a, b); + if (status) { + throw new Error("decryption error"); + } - return this.imod(a.imul(b)); - }; + return msg.slice(i); + } - Red.prototype.mul = function mul(a, b) { - this._verify2(a, b); + function compare(a, b) { + a = Buffer.from(a); + b = Buffer.from(b); + var dif = 0; + var len = a.length; - return this.imod(a.mul(b)); - }; + if (a.length !== b.length) { + dif++; + len = Math.min(a.length, b.length); + } - Red.prototype.isqr = function isqr(a) { - return this.imul(a, a.clone()); - }; + var i = -1; - Red.prototype.sqr = function sqr(a) { - return this.mul(a, a); - }; + while (++i < len) { + dif += a[i] ^ b[i]; + } - Red.prototype.sqrt = function sqrt(a) { - if (a.isZero()) return a.clone(); + return dif; + } - var mod3 = (this || _global$c).m.andln(3); + return exports$3$1; +} - assert(mod3 % 2 === 1); // Fast case +var exports$2$1 = {}, + _dewExec$2$1 = false; +function dew$2$1() { + if (_dewExec$2$1) return exports$2$1; + _dewExec$2$1 = true; + exports$2$1.publicEncrypt = dew$4$1(); + exports$2$1.privateDecrypt = dew$3$1(); - if (mod3 === 3) { - var pow = (this || _global$c).m.add(new BN(1)).iushrn(2); + exports$2$1.privateEncrypt = function privateEncrypt(key, buf) { + return exports$2$1.publicEncrypt(key, buf, true); + }; - return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) - // - // Find Q and S, that Q * 2 ^ S = (P - 1) + exports$2$1.publicDecrypt = function publicDecrypt(key, buf) { + return exports$2$1.privateDecrypt(key, buf, true); + }; + return exports$2$1; +} - var q = (this || _global$c).m.subn(1); +var exports$1$1 = {}, + _dewExec$1$1 = false; - var s = 0; +var _global$x = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - while (!q.isZero() && q.andln(1) === 0) { - s++; - q.iushrn(1); - } +function dew$1$1() { + if (_dewExec$1$1) return exports$1$1; + _dewExec$1$1 = true; + var process = T$9; - assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$c); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. + function oldBrowser() { + throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11"); + } - var lpow = (this || _global$c).m.subn(1).iushrn(1); + var safeBuffer = dew$1T(); - var z = (this || _global$c).m.bitLength(); + var randombytes = dew$1S(); - z = new BN(2 * z * z).toRed(this || _global$c); + var Buffer = safeBuffer.Buffer; + var kBufferMaxLength = safeBuffer.kMaxLength; + var crypto = _global$x.crypto || _global$x.msCrypto; + var kMaxUint32 = Math.pow(2, 32) - 1; - while (this.pow(z, lpow).cmp(nOne) !== 0) { - z.redIAdd(nOne); - } + function assertOffset(offset, length) { + if (typeof offset !== "number" || offset !== offset) { + // eslint-disable-line no-self-compare + throw new TypeError("offset must be a number"); + } - var c = this.pow(z, q); - var r = this.pow(a, q.addn(1).iushrn(1)); - var t = this.pow(a, q); - var m = s; + if (offset > kMaxUint32 || offset < 0) { + throw new TypeError("offset must be a uint32"); + } - while (t.cmp(one) !== 0) { - var tmp = t; + if (offset > kBufferMaxLength || offset > length) { + throw new RangeError("offset out of range"); + } + } - for (var i = 0; tmp.cmp(one) !== 0; i++) { - tmp = tmp.redSqr(); - } + function assertSize(size, offset, length) { + if (typeof size !== "number" || size !== size) { + // eslint-disable-line no-self-compare + throw new TypeError("size must be a number"); + } - assert(i < m); - var b = this.pow(c, new BN(1).iushln(m - i - 1)); - r = r.redMul(b); - c = b.redSqr(); - t = t.redMul(c); - m = i; - } + if (size > kMaxUint32 || size < 0) { + throw new TypeError("size must be a uint32"); + } - return r; - }; + if (size + offset > length || size > kBufferMaxLength) { + throw new RangeError("buffer too small"); + } + } - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$c).m); + if (crypto && crypto.getRandomValues || !process.browser) { + exports$1$1.randomFill = randomFill; + exports$1$1.randomFillSync = randomFillSync; + } else { + exports$1$1.randomFill = oldBrowser; + exports$1$1.randomFillSync = oldBrowser; + } - if (inv.negative !== 0) { - inv.negative = 0; - return this.imod(inv).redNeg(); - } else { - return this.imod(inv); - } - }; + function randomFill(buf, offset, size, cb) { + if (!Buffer.isBuffer(buf) && !(buf instanceof _global$x.Uint8Array)) { + throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); + } - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$c); - if (num.cmpn(1) === 0) return a.clone(); - var windowSize = 4; - var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$c); - wnd[1] = a; + if (typeof offset === "function") { + cb = offset; + offset = 0; + size = buf.length; + } else if (typeof size === "function") { + cb = size; + size = buf.length - offset; + } else if (typeof cb !== "function") { + throw new TypeError("\"cb\" argument must be a function"); + } - for (var i = 2; i < wnd.length; i++) { - wnd[i] = this.mul(wnd[i - 1], a); - } + assertOffset(offset, buf.length); + assertSize(size, offset, buf.length); + return actualFill(buf, offset, size, cb); + } - var res = wnd[0]; - var current = 0; - var currentLen = 0; - var start = num.bitLength() % 26; + function actualFill(buf, offset, size, cb) { + if (process.browser) { + var ourBuf = buf.buffer; + var uint = new Uint8Array(ourBuf, offset, size); + crypto.getRandomValues(uint); - if (start === 0) { - start = 26; + if (cb) { + process.nextTick(function () { + cb(null, buf); + }); + return; } - for (i = num.length - 1; i >= 0; i--) { - var word = num.words[i]; + return buf; + } - for (var j = start - 1; j >= 0; j--) { - var bit = word >> j & 1; + if (cb) { + randombytes(size, function (err, bytes) { + if (err) { + return cb(err); + } - if (res !== wnd[0]) { - res = this.sqr(res); - } + bytes.copy(buf, offset); + cb(null, buf); + }); + return; + } - if (bit === 0 && current === 0) { - currentLen = 0; - continue; - } + var bytes = randombytes(size); + bytes.copy(buf, offset); + return buf; + } - current <<= 1; - current |= bit; - currentLen++; - if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; - res = this.mul(res, wnd[current]); - currentLen = 0; - current = 0; - } + function randomFillSync(buf, offset, size) { + if (typeof offset === "undefined") { + offset = 0; + } - start = 26; - } + if (!Buffer.isBuffer(buf) && !(buf instanceof _global$x.Uint8Array)) { + throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); + } - return res; - }; + assertOffset(offset, buf.length); + if (size === undefined) size = buf.length - offset; + assertSize(size, offset, buf.length); + return actualFill(buf, offset, size); + } - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$c).m); - return r === num ? r.clone() : r; - }; + return exports$1$1; +} - Red.prototype.convertFrom = function convertFrom(num) { - var res = num.clone(); - res.red = null; - return res; - }; // - // Montgomery method engine - // +var exports$1V = {}, + _dewExec$1U = false; +function dew$1U() { + if (_dewExec$1U) return exports$1V; + _dewExec$1U = true; + exports$1V.randomBytes = exports$1V.rng = exports$1V.pseudoRandomBytes = exports$1V.prng = dew$1S(); + exports$1V.createHash = exports$1V.Hash = dew$1F(); + exports$1V.createHmac = exports$1V.Hmac = dew$1C(); + var algos = dew$1B(); - BN.mont = function mont(num) { - return new Mont(num); - }; + var algoKeys = Object.keys(algos); + var hashes = ["sha1", "sha224", "sha256", "sha384", "sha512", "md5", "rmd160"].concat(algoKeys); - function Mont(m) { - Red.call(this || _global$c, m); - (this || _global$c).shift = (this || _global$c).m.bitLength(); + exports$1V.getHashes = function () { + return hashes; + }; - if ((this || _global$c).shift % 26 !== 0) { - (this || _global$c).shift += 26 - (this || _global$c).shift % 26; - } + var p = dew$1v(); - (this || _global$c).r = new BN(1).iushln((this || _global$c).shift); - (this || _global$c).r2 = this.imod((this || _global$c).r.sqr()); - (this || _global$c).rinv = (this || _global$c).r._invmp((this || _global$c).m); - (this || _global$c).minv = (this || _global$c).rinv.mul((this || _global$c).r).isubn(1).div((this || _global$c).m); - (this || _global$c).minv = (this || _global$c).minv.umod((this || _global$c).r); - (this || _global$c).minv = (this || _global$c).r.sub((this || _global$c).minv); - } + exports$1V.pbkdf2 = p.pbkdf2; + exports$1V.pbkdf2Sync = p.pbkdf2Sync; - inherits(Mont, Red); + var aes = dew$13$1(); - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$c).shift)); - }; + exports$1V.Cipher = aes.Cipher; + exports$1V.createCipher = aes.createCipher; + exports$1V.Cipheriv = aes.Cipheriv; + exports$1V.createCipheriv = aes.createCipheriv; + exports$1V.Decipher = aes.Decipher; + exports$1V.createDecipher = aes.createDecipher; + exports$1V.Decipheriv = aes.Decipheriv; + exports$1V.createDecipheriv = aes.createDecipheriv; + exports$1V.getCiphers = aes.getCiphers; + exports$1V.listCiphers = aes.listCiphers; - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$c).rinv)); - r.red = null; - return r; - }; + var dh = dew$Y$1(); - Mont.prototype.imul = function imul(a, b) { - if (a.isZero() || b.isZero()) { - a.words[0] = 0; - a.length = 1; - return a; - } + exports$1V.DiffieHellmanGroup = dh.DiffieHellmanGroup; + exports$1V.createDiffieHellmanGroup = dh.createDiffieHellmanGroup; + exports$1V.getDiffieHellman = dh.getDiffieHellman; + exports$1V.createDiffieHellman = dh.createDiffieHellman; + exports$1V.DiffieHellman = dh.DiffieHellman; - var t = a.imul(b); - var c = t.maskn((this || _global$c).shift).mul((this || _global$c).minv).imaskn((this || _global$c).shift).mul((this || _global$c).m); - var u = t.isub(c).iushrn((this || _global$c).shift); - var res = u; + var sign = dew$b$1(); - if (u.cmp((this || _global$c).m) >= 0) { - res = u.isub((this || _global$c).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$c).m); - } + exports$1V.createSign = sign.createSign; + exports$1V.Sign = sign.Sign; + exports$1V.createVerify = sign.createVerify; + exports$1V.Verify = sign.Verify; + exports$1V.createECDH = dew$9$1(); - return res._forceRed(this || _global$c); - }; + var publicEncrypt = dew$2$1(); - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$c); - var t = a.mul(b); - var c = t.maskn((this || _global$c).shift).mul((this || _global$c).minv).imaskn((this || _global$c).shift).mul((this || _global$c).m); - var u = t.isub(c).iushrn((this || _global$c).shift); - var res = u; + exports$1V.publicEncrypt = publicEncrypt.publicEncrypt; + exports$1V.privateEncrypt = publicEncrypt.privateEncrypt; + exports$1V.publicDecrypt = publicEncrypt.publicDecrypt; + exports$1V.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api. + // ;[ + // 'createCredentials' + // ].forEach(function (name) { + // exports[name] = function () { + // throw new Error([ + // 'sorry, ' + name + ' is not implemented yet', + // 'we accept pull requests', + // 'https://github.com/crypto-browserify/crypto-browserify' + // ].join('\n')) + // } + // }) - if (u.cmp((this || _global$c).m) >= 0) { - res = u.isub((this || _global$c).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$c).m); - } + var rf = dew$1$1(); - return res._forceRed(this || _global$c); - }; + exports$1V.randomFill = rf.randomFill; + exports$1V.randomFillSync = rf.randomFillSync; - Mont.prototype.invm = function invm(a) { - // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$c).m).mul((this || _global$c).r2)); - return res._forceRed(this || _global$c); - }; - })(module$5, exports$12$1); + exports$1V.createCredentials = function () { + throw new Error(["sorry, createCredentials is not implemented yet", "we accept pull requests", "https://github.com/crypto-browserify/crypto-browserify"].join("\n")); + }; - return module$5.exports; + exports$1V.constants = { + "DH_CHECK_P_NOT_SAFE_PRIME": 2, + "DH_CHECK_P_NOT_PRIME": 1, + "DH_UNABLE_TO_CHECK_GENERATOR": 4, + "DH_NOT_SUITABLE_GENERATOR": 8, + "NPN_ENABLED": 1, + "ALPN_ENABLED": 1, + "RSA_PKCS1_PADDING": 1, + "RSA_SSLV23_PADDING": 2, + "RSA_NO_PADDING": 3, + "RSA_PKCS1_OAEP_PADDING": 4, + "RSA_X931_PADDING": 5, + "RSA_PKCS1_PSS_PADDING": 6, + "POINT_CONVERSION_COMPRESSED": 2, + "POINT_CONVERSION_UNCOMPRESSED": 4, + "POINT_CONVERSION_HYBRID": 6 + }; + return exports$1V; } -var _global$b="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,exports$11$1={},indexOf=function(e,t){if(e.indexOf)return e.indexOf(t);for(var n=0;n4294967295)throw new RangeError("requested too many random bytes");var o=t.allocUnsafe(e);if(e>0)if(e>65536)for(var a=0;a=this._blockSize;){for(var s=this._blockOffset;s0;++f)this._length[f]+=n,(n=this._length[f]/4294967296|0)>0&&(this._length[f]-=4294967296*n);return this},s.prototype._update=function(){throw new Error("_update is not implemented")},s.prototype.digest=function(t){if(this._finalized)throw new Error("Digest already called");this._finalized=!0;var i=this._digest();void 0!==t&&(i=i.toString(t)),this._block.fill(0),this._blockOffset=0;for(var r=0;r<4;++r)this._length[r]=0;return i},s.prototype._digest=function(){throw new Error("_digest is not implemented")};var f$1=s;var h=t$2$2,r=f$1,_=u$q.Buffer,e$1=new Array(16);function n$1(){r.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878;}function o$2(t,i){return t<>>32-i}function f$2(t,i,s,h,r,_,e){return o$2(t+(i&s|~i&h)+r+_|0,e)+i|0}function c(t,i,s,h,r,_,e){return o$2(t+(i&h|s&~h)+r+_|0,e)+i|0}function a$1(t,i,s,h,r,_,e){return o$2(t+(i^s^h)+r+_|0,e)+i|0}function l(t,i,s,h,r,_,e){return o$2(t+(s^(i|~h))+r+_|0,e)+i|0}h(n$1,r),n$1.prototype._update=function(){for(var t=e$1,i=0;i<16;++i)t[i]=this._block.readInt32LE(4*i);var s=this._a,h=this._b,r=this._c,_=this._d;s=f$2(s,h,r,_,t[0],3614090360,7),_=f$2(_,s,h,r,t[1],3905402710,12),r=f$2(r,_,s,h,t[2],606105819,17),h=f$2(h,r,_,s,t[3],3250441966,22),s=f$2(s,h,r,_,t[4],4118548399,7),_=f$2(_,s,h,r,t[5],1200080426,12),r=f$2(r,_,s,h,t[6],2821735955,17),h=f$2(h,r,_,s,t[7],4249261313,22),s=f$2(s,h,r,_,t[8],1770035416,7),_=f$2(_,s,h,r,t[9],2336552879,12),r=f$2(r,_,s,h,t[10],4294925233,17),h=f$2(h,r,_,s,t[11],2304563134,22),s=f$2(s,h,r,_,t[12],1804603682,7),_=f$2(_,s,h,r,t[13],4254626195,12),r=f$2(r,_,s,h,t[14],2792965006,17),s=c(s,h=f$2(h,r,_,s,t[15],1236535329,22),r,_,t[1],4129170786,5),_=c(_,s,h,r,t[6],3225465664,9),r=c(r,_,s,h,t[11],643717713,14),h=c(h,r,_,s,t[0],3921069994,20),s=c(s,h,r,_,t[5],3593408605,5),_=c(_,s,h,r,t[10],38016083,9),r=c(r,_,s,h,t[15],3634488961,14),h=c(h,r,_,s,t[4],3889429448,20),s=c(s,h,r,_,t[9],568446438,5),_=c(_,s,h,r,t[14],3275163606,9),r=c(r,_,s,h,t[3],4107603335,14),h=c(h,r,_,s,t[8],1163531501,20),s=c(s,h,r,_,t[13],2850285829,5),_=c(_,s,h,r,t[2],4243563512,9),r=c(r,_,s,h,t[7],1735328473,14),s=a$1(s,h=c(h,r,_,s,t[12],2368359562,20),r,_,t[5],4294588738,4),_=a$1(_,s,h,r,t[8],2272392833,11),r=a$1(r,_,s,h,t[11],1839030562,16),h=a$1(h,r,_,s,t[14],4259657740,23),s=a$1(s,h,r,_,t[1],2763975236,4),_=a$1(_,s,h,r,t[4],1272893353,11),r=a$1(r,_,s,h,t[7],4139469664,16),h=a$1(h,r,_,s,t[10],3200236656,23),s=a$1(s,h,r,_,t[13],681279174,4),_=a$1(_,s,h,r,t[0],3936430074,11),r=a$1(r,_,s,h,t[3],3572445317,16),h=a$1(h,r,_,s,t[6],76029189,23),s=a$1(s,h,r,_,t[9],3654602809,4),_=a$1(_,s,h,r,t[12],3873151461,11),r=a$1(r,_,s,h,t[15],530742520,16),s=l(s,h=a$1(h,r,_,s,t[2],3299628645,23),r,_,t[0],4096336452,6),_=l(_,s,h,r,t[7],1126891415,10),r=l(r,_,s,h,t[14],2878612391,15),h=l(h,r,_,s,t[5],4237533241,21),s=l(s,h,r,_,t[12],1700485571,6),_=l(_,s,h,r,t[3],2399980690,10),r=l(r,_,s,h,t[10],4293915773,15),h=l(h,r,_,s,t[1],2240044497,21),s=l(s,h,r,_,t[8],1873313359,6),_=l(_,s,h,r,t[15],4264355552,10),r=l(r,_,s,h,t[6],2734768916,15),h=l(h,r,_,s,t[13],1309151649,21),s=l(s,h,r,_,t[4],4149444226,6),_=l(_,s,h,r,t[11],3174756917,10),r=l(r,_,s,h,t[2],718787259,15),h=l(h,r,_,s,t[9],3951481745,21),this._a=this._a+s|0,this._b=this._b+h|0,this._c=this._c+r|0,this._d=this._d+_|0;},n$1.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var t=_.allocUnsafe(16);return t.writeInt32LE(this._a,0),t.writeInt32LE(this._b,4),t.writeInt32LE(this._c,8),t.writeInt32LE(this._d,12),t};var u=n$1;var h$1=e$1$1$1.Buffer,_$1=t$2$2,r$1=f$1,e$2=new Array(16),n$2=[0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,7,4,13,1,10,6,15,3,12,0,9,5,2,14,11,8,3,10,14,4,9,15,8,1,2,7,0,6,13,11,5,12,1,9,11,10,0,8,12,4,13,3,7,15,14,5,6,2,4,0,5,9,7,12,2,10,14,1,3,8,11,6,15,13],o$3=[5,14,7,0,9,2,11,4,13,6,15,8,1,10,3,12,6,11,3,7,0,13,5,10,14,15,8,12,4,9,1,2,15,5,1,3,7,14,6,9,11,8,12,2,10,0,4,13,8,6,4,1,3,11,15,0,5,12,2,13,9,7,10,14,12,15,10,4,1,5,8,7,6,2,13,14,0,3,9,11],f$3=[11,14,15,12,5,8,7,9,11,13,14,15,6,7,9,8,7,6,8,13,11,9,7,15,7,12,15,9,11,7,13,12,11,13,6,7,14,9,13,15,14,8,13,6,5,12,7,5,11,12,14,15,14,15,9,8,9,14,5,6,8,6,5,12,9,15,5,11,6,8,13,12,5,12,13,14,11,8,5,6],c$1=[8,9,9,11,13,15,15,5,7,7,8,11,14,14,12,6,9,13,15,7,12,8,9,11,7,7,12,7,6,15,13,11,9,7,15,11,8,6,6,14,12,13,5,14,13,13,7,5,15,5,8,11,14,14,6,14,6,9,12,9,12,5,15,8,8,5,12,9,12,5,14,6,8,13,6,5,15,13,11,11],a$2=[0,1518500249,1859775393,2400959708,2840853838],l$1=[1352829926,1548603684,1836072691,2053994217,0];function u$1(){r$1.call(this,64),this._a=1732584193,this._b=4023233417,this._c=2562383102,this._d=271733878,this._e=3285377520;}function b(t,i){return t<>>32-i}function d(t,i,s,h,_,r,e,n){return b(t+(i^s^h)+r+e|0,n)+_|0}function k(t,i,s,h,_,r,e,n){return b(t+(i&s|~i&h)+r+e|0,n)+_|0}function p(t,i,s,h,_,r,e,n){return b(t+((i|~s)^h)+r+e|0,n)+_|0}function w(t,i,s,h,_,r,e,n){return b(t+(i&h|s&~h)+r+e|0,n)+_|0}function E(t,i,s,h,_,r,e,n){return b(t+(i^(s|~h))+r+e|0,n)+_|0}_$1(u$1,r$1),u$1.prototype._update=function(){for(var t=e$2,i=0;i<16;++i)t[i]=this._block.readInt32LE(4*i);for(var s=0|this._a,h=0|this._b,_=0|this._c,r=0|this._d,u=0|this._e,I=0|this._a,L=0|this._b,v=0|this._c,m=0|this._d,O=0|this._e,g=0;g<80;g+=1){var y,U;g<16?(y=d(s,h,_,r,u,t[n$2[g]],a$2[0],f$3[g]),U=E(I,L,v,m,O,t[o$3[g]],l$1[0],c$1[g])):g<32?(y=k(s,h,_,r,u,t[n$2[g]],a$2[1],f$3[g]),U=w(I,L,v,m,O,t[o$3[g]],l$1[1],c$1[g])):g<48?(y=p(s,h,_,r,u,t[n$2[g]],a$2[2],f$3[g]),U=p(I,L,v,m,O,t[o$3[g]],l$1[2],c$1[g])):g<64?(y=w(s,h,_,r,u,t[n$2[g]],a$2[3],f$3[g]),U=k(I,L,v,m,O,t[o$3[g]],l$1[3],c$1[g])):(y=E(s,h,_,r,u,t[n$2[g]],a$2[4],f$3[g]),U=d(I,L,v,m,O,t[o$3[g]],l$1[4],c$1[g])),s=u,u=r,r=b(_,10),_=h,h=y,I=O,O=m,m=b(v,10),v=L,L=U;}var x=this._b+_+m|0;this._b=this._c+r+O|0,this._c=this._d+u+I|0,this._d=this._e+s+L|0,this._e=this._a+h+v|0,this._a=x;},u$1.prototype._digest=function(){this._block[this._blockOffset++]=128,this._blockOffset>56&&(this._block.fill(0,this._blockOffset,64),this._update(),this._blockOffset=0),this._block.fill(0,this._blockOffset,56),this._block.writeUInt32LE(this._length[0],56),this._block.writeUInt32LE(this._length[1],60),this._update();var t=h$1.alloc?h$1.alloc(20):new h$1(20);return t.writeInt32LE(this._a,0),t.writeInt32LE(this._b,4),t.writeInt32LE(this._c,8),t.writeInt32LE(this._d,12),t.writeInt32LE(this._e,16),t};var I=u$1;var s$1="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,h$2=u$q.Buffer;function e$3(t,i){(this||s$1)._block=h$2.alloc(t),(this||s$1)._finalSize=i,(this||s$1)._blockSize=t,(this||s$1)._len=0;}e$3.prototype.update=function(t,i){"string"==typeof t&&(i=i||"utf8",t=h$2.from(t,i));for(var e=(this||s$1)._block,_=(this||s$1)._blockSize,n=t.length,r=(this||s$1)._len,o=0;o=(this||s$1)._finalSize&&(this._update((this||s$1)._block),(this||s$1)._block.fill(0));var h=8*(this||s$1)._len;if(h<=4294967295)(this||s$1)._block.writeUInt32BE(h,(this||s$1)._blockSize-4);else {var e=(4294967295&h)>>>0,_=(h-e)/4294967296;(this||s$1)._block.writeUInt32BE(_,(this||s$1)._blockSize-8),(this||s$1)._block.writeUInt32BE(e,(this||s$1)._blockSize-4);}this._update((this||s$1)._block);var n=this._hash();return t?n.toString(t):n},e$3.prototype._update=function(){throw new Error("_update must be implemented by subclass")};var _$2=e$3,n$3="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,r$2=t$2$2,o$4=_$2,f$4=u$q.Buffer,l$2=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298],a$3=new Array(64);function u$2(){this.init(),(this||n$3)._w=a$3,o$4.call(this||n$3,64,56);}function c$2(t,i,s){return s^t&(i^s)}function b$1(t,i,s){return t&i|s&(t|i)}function p$1(t){return (t>>>2|t<<30)^(t>>>13|t<<19)^(t>>>22|t<<10)}function d$1(t){return (t>>>6|t<<26)^(t>>>11|t<<21)^(t>>>25|t<<7)}function k$1(t){return (t>>>7|t<<25)^(t>>>18|t<<14)^t>>>3}r$2(u$2,o$4),u$2.prototype.init=function(){return (this||n$3)._a=1779033703,(this||n$3)._b=3144134277,(this||n$3)._c=1013904242,(this||n$3)._d=2773480762,(this||n$3)._e=1359893119,(this||n$3)._f=2600822924,(this||n$3)._g=528734635,(this||n$3)._h=1541459225,this||n$3},u$2.prototype._update=function(t){for(var i,s=(this||n$3)._w,h=0|(this||n$3)._a,e=0|(this||n$3)._b,_=0|(this||n$3)._c,r=0|(this||n$3)._d,o=0|(this||n$3)._e,f=0|(this||n$3)._f,a=0|(this||n$3)._g,u=0|(this||n$3)._h,w=0;w<16;++w)s[w]=t.readInt32BE(4*w);for(;w<64;++w)s[w]=0|(((i=s[w-2])>>>17|i<<15)^(i>>>19|i<<13)^i>>>10)+s[w-7]+k$1(s[w-15])+s[w-16];for(var g=0;g<64;++g){var B=u+d$1(o)+c$2(o,f,a)+l$2[g]+s[g]|0,v=p$1(h)+b$1(h,e,_)|0;u=a,a=f,f=o,o=r+B|0,r=_,_=e,e=h,h=B+v|0;}(this||n$3)._a=h+(this||n$3)._a|0,(this||n$3)._b=e+(this||n$3)._b|0,(this||n$3)._c=_+(this||n$3)._c|0,(this||n$3)._d=r+(this||n$3)._d|0,(this||n$3)._e=o+(this||n$3)._e|0,(this||n$3)._f=f+(this||n$3)._f|0,(this||n$3)._g=a+(this||n$3)._g|0,(this||n$3)._h=u+(this||n$3)._h|0;},u$2.prototype._hash=function(){var t=f$4.allocUnsafe(32);return t.writeInt32BE((this||n$3)._a,0),t.writeInt32BE((this||n$3)._b,4),t.writeInt32BE((this||n$3)._c,8),t.writeInt32BE((this||n$3)._d,12),t.writeInt32BE((this||n$3)._e,16),t.writeInt32BE((this||n$3)._f,20),t.writeInt32BE((this||n$3)._g,24),t.writeInt32BE((this||n$3)._h,28),t};var w$1=u$2;var _$3="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,e$4=t$2$2,n$4=_$2,r$3=u$q.Buffer,l$3=[1518500249,1859775393,-1894007588,-899497514],o$5=new Array(80);function f$5(){this.init(),(this||_$3)._w=o$5,n$4.call(this||_$3,64,56);}function a$4(t){return t<<30|t>>>2}function u$3(t,i,h,s){return 0===t?i&h|~i&s:2===t?i&h|i&s|h&s:i^h^s}e$4(f$5,n$4),f$5.prototype.init=function(){return (this||_$3)._a=1732584193,(this||_$3)._b=4023233417,(this||_$3)._c=2562383102,(this||_$3)._d=271733878,(this||_$3)._e=3285377520,this||_$3},f$5.prototype._update=function(t){for(var i,h=(this||_$3)._w,s=0|(this||_$3)._a,e=0|(this||_$3)._b,n=0|(this||_$3)._c,r=0|(this||_$3)._d,o=0|(this||_$3)._e,f=0;f<16;++f)h[f]=t.readInt32BE(4*f);for(;f<80;++f)h[f]=h[f-3]^h[f-8]^h[f-14]^h[f-16];for(var c=0;c<80;++c){var d=~~(c/20),p=0|((i=s)<<5|i>>>27)+u$3(d,e,n,r)+o+h[c]+l$3[d];o=r,r=n,n=a$4(e),e=s,s=p;}(this||_$3)._a=s+(this||_$3)._a|0,(this||_$3)._b=e+(this||_$3)._b|0,(this||_$3)._c=n+(this||_$3)._c|0,(this||_$3)._d=r+(this||_$3)._d|0,(this||_$3)._e=o+(this||_$3)._e|0;},f$5.prototype._hash=function(){var t=r$3.allocUnsafe(20);return t.writeInt32BE(0|(this||_$3)._a,0),t.writeInt32BE(0|(this||_$3)._b,4),t.writeInt32BE(0|(this||_$3)._c,8),t.writeInt32BE(0|(this||_$3)._d,12),t.writeInt32BE(0|(this||_$3)._e,16),t};var c$3=f$5,d$2="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,p$2=t$2$2,b$2=_$2,w$2=u$q.Buffer,g=[1518500249,1859775393,-1894007588,-899497514],B=new Array(80);function y(){this.init(),(this||d$2)._w=B,b$2.call(this||d$2,64,56);}function E$1(t){return t<<5|t>>>27}function I$1(t){return t<<30|t>>>2}function v(t,i,h,s){return 0===t?i&h|~i&s:2===t?i&h|i&s|h&s:i^h^s}p$2(y,b$2),y.prototype.init=function(){return (this||d$2)._a=1732584193,(this||d$2)._b=4023233417,(this||d$2)._c=2562383102,(this||d$2)._d=271733878,(this||d$2)._e=3285377520,this||d$2},y.prototype._update=function(t){for(var i,h=(this||d$2)._w,s=0|(this||d$2)._a,_=0|(this||d$2)._b,e=0|(this||d$2)._c,n=0|(this||d$2)._d,r=0|(this||d$2)._e,l=0;l<16;++l)h[l]=t.readInt32BE(4*l);for(;l<80;++l)h[l]=(i=h[l-3]^h[l-8]^h[l-14]^h[l-16])<<1|i>>>31;for(var o=0;o<80;++o){var f=~~(o/20),a=E$1(s)+v(f,_,e,n)+r+h[o]+g[f]|0;r=n,n=e,e=I$1(_),_=s,s=a;}(this||d$2)._a=s+(this||d$2)._a|0,(this||d$2)._b=_+(this||d$2)._b|0,(this||d$2)._c=e+(this||d$2)._c|0,(this||d$2)._d=n+(this||d$2)._d|0,(this||d$2)._e=r+(this||d$2)._e|0;},y.prototype._hash=function(){var t=w$2.allocUnsafe(20);return t.writeInt32BE(0|(this||d$2)._a,0),t.writeInt32BE(0|(this||d$2)._b,4),t.writeInt32BE(0|(this||d$2)._c,8),t.writeInt32BE(0|(this||d$2)._d,12),t.writeInt32BE(0|(this||d$2)._e,16),t};var T=y,m="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,A=t$2$2,U=w$1,x=_$2,j=u$q.Buffer,q=new Array(64);function C(){this.init(),(this||m)._w=q,x.call(this||m,64,56);}A(C,U),C.prototype.init=function(){return (this||m)._a=3238371032,(this||m)._b=914150663,(this||m)._c=812702999,(this||m)._d=4144912697,(this||m)._e=4290775857,(this||m)._f=1750603025,(this||m)._g=1694076839,(this||m)._h=3204075428,this||m},C.prototype._hash=function(){var t=j.allocUnsafe(28);return t.writeInt32BE((this||m)._a,0),t.writeInt32BE((this||m)._b,4),t.writeInt32BE((this||m)._c,8),t.writeInt32BE((this||m)._d,12),t.writeInt32BE((this||m)._e,16),t.writeInt32BE((this||m)._f,20),t.writeInt32BE((this||m)._g,24),t};var L=C,k$2="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,z=t$2$2,D=_$2,F=u$q.Buffer,G=[1116352408,3609767458,1899447441,602891725,3049323471,3964484399,3921009573,2173295548,961987163,4081628472,1508970993,3053834265,2453635748,2937671579,2870763221,3664609560,3624381080,2734883394,310598401,1164996542,607225278,1323610764,1426881987,3590304994,1925078388,4068182383,2162078206,991336113,2614888103,633803317,3248222580,3479774868,3835390401,2666613458,4022224774,944711139,264347078,2341262773,604807628,2007800933,770255983,1495990901,1249150122,1856431235,1555081692,3175218132,1996064986,2198950837,2554220882,3999719339,2821834349,766784016,2952996808,2566594879,3210313671,3203337956,3336571891,1034457026,3584528711,2466948901,113926993,3758326383,338241895,168717936,666307205,1188179964,773529912,1546045734,1294757372,1522805485,1396182291,2643833823,1695183700,2343527390,1986661051,1014477480,2177026350,1206759142,2456956037,344077627,2730485921,1290863460,2820302411,3158454273,3259730800,3505952657,3345764771,106217008,3516065817,3606008344,3600352804,1432725776,4094571909,1467031594,275423344,851169720,430227734,3100823752,506948616,1363258195,659060556,3750685593,883997877,3785050280,958139571,3318307427,1322822218,3812723403,1537002063,2003034995,1747873779,3602036899,1955562222,1575990012,2024104815,1125592928,2227730452,2716904306,2361852424,442776044,2428436474,593698344,2756734187,3733110249,3204031479,2999351573,3329325298,3815920427,3391569614,3928383900,3515267271,566280711,3940187606,3454069534,4118630271,4000239992,116418474,1914138554,174292421,2731055270,289380356,3203993006,460393269,320620315,685471733,587496836,852142971,1086792851,1017036298,365543100,1126000580,2618297676,1288033470,3409855158,1501505948,4234509866,1607167915,987167468,1816402316,1246189591],H=new Array(160);function J(){this.init(),(this||k$2)._w=H,D.call(this||k$2,128,112);}function K(t,i,h){return h^t&(i^h)}function M(t,i,h){return t&i|h&(t|i)}function N(t,i){return (t>>>28|i<<4)^(i>>>2|t<<30)^(i>>>7|t<<25)}function O(t,i){return (t>>>14|i<<18)^(t>>>18|i<<14)^(i>>>9|t<<23)}function P(t,i){return (t>>>1|i<<31)^(t>>>8|i<<24)^t>>>7}function Q(t,i){return (t>>>1|i<<31)^(t>>>8|i<<24)^(t>>>7|i<<25)}function R(t,i){return (t>>>19|i<<13)^(i>>>29|t<<3)^t>>>6}function S(t,i){return (t>>>19|i<<13)^(i>>>29|t<<3)^(t>>>6|i<<26)}function V(t,i){return t>>>0>>0?1:0}z(J,D),J.prototype.init=function(){return (this||k$2)._ah=1779033703,(this||k$2)._bh=3144134277,(this||k$2)._ch=1013904242,(this||k$2)._dh=2773480762,(this||k$2)._eh=1359893119,(this||k$2)._fh=2600822924,(this||k$2)._gh=528734635,(this||k$2)._hh=1541459225,(this||k$2)._al=4089235720,(this||k$2)._bl=2227873595,(this||k$2)._cl=4271175723,(this||k$2)._dl=1595750129,(this||k$2)._el=2917565137,(this||k$2)._fl=725511199,(this||k$2)._gl=4215389547,(this||k$2)._hl=327033209,this||k$2},J.prototype._update=function(t){for(var i=(this||k$2)._w,h=0|(this||k$2)._ah,s=0|(this||k$2)._bh,_=0|(this||k$2)._ch,e=0|(this||k$2)._dh,n=0|(this||k$2)._eh,r=0|(this||k$2)._fh,l=0|(this||k$2)._gh,o=0|(this||k$2)._hh,f=0|(this||k$2)._al,a=0|(this||k$2)._bl,u=0|(this||k$2)._cl,c=0|(this||k$2)._dl,d=0|(this||k$2)._el,p=0|(this||k$2)._fl,b=0|(this||k$2)._gl,w=0|(this||k$2)._hl,g=0;g<32;g+=2)i[g]=t.readInt32BE(4*g),i[g+1]=t.readInt32BE(4*g+4);for(;g<160;g+=2){var B=i[g-30],y=i[g-30+1],E=P(B,y),I=Q(y,B),v=R(B=i[g-4],y=i[g-4+1]),T=S(y,B),m=i[g-14],A=i[g-14+1],U=i[g-32],x=i[g-32+1],j=I+A|0,q=E+m+V(j,I)|0;q=(q=q+v+V(j=j+T|0,T)|0)+U+V(j=j+x|0,x)|0,i[g]=q,i[g+1]=j;}for(var C=0;C<160;C+=2){q=i[C],j=i[C+1];var L=M(h,s,_),z=M(f,a,u),D=N(h,f),F=N(f,h),H=O(n,d),J=O(d,n),W=G[C],X=G[C+1],Y=K(n,r,l),Z=K(d,p,b),$=w+J|0,tt=o+H+V($,w)|0;tt=(tt=(tt=tt+Y+V($=$+Z|0,Z)|0)+W+V($=$+X|0,X)|0)+q+V($=$+j|0,j)|0;var it=F+z|0,ht=D+L+V(it,F)|0;o=l,w=b,l=r,b=p,r=n,p=d,n=e+tt+V(d=c+$|0,c)|0,e=_,c=u,_=s,u=a,s=h,a=f,h=tt+ht+V(f=$+it|0,$)|0;}(this||k$2)._al=(this||k$2)._al+f|0,(this||k$2)._bl=(this||k$2)._bl+a|0,(this||k$2)._cl=(this||k$2)._cl+u|0,(this||k$2)._dl=(this||k$2)._dl+c|0,(this||k$2)._el=(this||k$2)._el+d|0,(this||k$2)._fl=(this||k$2)._fl+p|0,(this||k$2)._gl=(this||k$2)._gl+b|0,(this||k$2)._hl=(this||k$2)._hl+w|0,(this||k$2)._ah=(this||k$2)._ah+h+V((this||k$2)._al,f)|0,(this||k$2)._bh=(this||k$2)._bh+s+V((this||k$2)._bl,a)|0,(this||k$2)._ch=(this||k$2)._ch+_+V((this||k$2)._cl,u)|0,(this||k$2)._dh=(this||k$2)._dh+e+V((this||k$2)._dl,c)|0,(this||k$2)._eh=(this||k$2)._eh+n+V((this||k$2)._el,d)|0,(this||k$2)._fh=(this||k$2)._fh+r+V((this||k$2)._fl,p)|0,(this||k$2)._gh=(this||k$2)._gh+l+V((this||k$2)._gl,b)|0,(this||k$2)._hh=(this||k$2)._hh+o+V((this||k$2)._hl,w)|0;},J.prototype._hash=function(){var t=F.allocUnsafe(64);function i(i,h,s){t.writeInt32BE(i,s),t.writeInt32BE(h,s+4);}return i((this||k$2)._ah,(this||k$2)._al,0),i((this||k$2)._bh,(this||k$2)._bl,8),i((this||k$2)._ch,(this||k$2)._cl,16),i((this||k$2)._dh,(this||k$2)._dl,24),i((this||k$2)._eh,(this||k$2)._el,32),i((this||k$2)._fh,(this||k$2)._fl,40),i((this||k$2)._gh,(this||k$2)._gl,48),i((this||k$2)._hh,(this||k$2)._hl,56),t};var W=J,X="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,Y=t$2$2,Z=W,$=_$2,tt=u$q.Buffer,it=new Array(160);function ht(){this.init(),(this||X)._w=it,$.call(this||X,128,112);}Y(ht,Z),ht.prototype.init=function(){return (this||X)._ah=3418070365,(this||X)._bh=1654270250,(this||X)._ch=2438529370,(this||X)._dh=355462360,(this||X)._eh=1731405415,(this||X)._fh=2394180231,(this||X)._gh=3675008525,(this||X)._hh=1203062813,(this||X)._al=3238371032,(this||X)._bl=914150663,(this||X)._cl=812702999,(this||X)._dl=4144912697,(this||X)._el=4290775857,(this||X)._fl=1750603025,(this||X)._gl=1694076839,(this||X)._hl=3204075428,this||X},ht.prototype._hash=function(){var t=tt.allocUnsafe(48);function i(i,h,s){t.writeInt32BE(i,s),t.writeInt32BE(h,s+4);}return i((this||X)._ah,(this||X)._al,0),i((this||X)._bh,(this||X)._bl,8),i((this||X)._ch,(this||X)._cl,16),i((this||X)._dh,(this||X)._dl,24),i((this||X)._eh,(this||X)._el,32),i((this||X)._fh,(this||X)._fl,40),t};var st,_t=ht,et={exports:st={}};(st=et.exports=function(t){t=t.toLowerCase();var i=st[t];if(!i)throw new Error(t+" is not supported (we accept pull requests)");return new i}).sha=c$3,st.sha1=T,st.sha224=L,st.sha256=w$1,st.sha384=_t,st.sha512=W;var nt=et.exports;var e$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,n$5=u$q.Buffer,s$2=b$i.Transform,h$3=e$1$2.StringDecoder;function a$5(t){s$2.call(this||e$5),(this||e$5).hashMode="string"==typeof t,(this||e$5).hashMode?(this||e$5)[t]=(this||e$5)._finalOrDigest:(this||e$5).final=(this||e$5)._finalOrDigest,(this||e$5)._final&&((this||e$5).__final=(this||e$5)._final,(this||e$5)._final=null),(this||e$5)._decoder=null,(this||e$5)._encoding=null;}t$2$2(a$5,s$2),a$5.prototype.update=function(t,i,r){"string"==typeof t&&(t=n$5.from(t,i));var o=this._update(t);return (this||e$5).hashMode?this||e$5:(r&&(o=this._toString(o,r)),o)},a$5.prototype.setAutoPadding=function(){},a$5.prototype.getAuthTag=function(){throw new Error("trying to get auth tag in unsupported state")},a$5.prototype.setAuthTag=function(){throw new Error("trying to set auth tag in unsupported state")},a$5.prototype.setAAD=function(){throw new Error("trying to set aad in unsupported state")},a$5.prototype._transform=function(t,i,r){var o;try{(this||e$5).hashMode?this._update(t):this.push(this._update(t));}catch(t){o=t;}finally{r(o);}},a$5.prototype._flush=function(t){var i;try{this.push(this.__final());}catch(t){i=t;}t(i);},a$5.prototype._finalOrDigest=function(t){var i=this.__final()||n$5.alloc(0);return t&&(i=this._toString(i,t,!0)),i},a$5.prototype._toString=function(t,i,r){if((this||e$5)._decoder||((this||e$5)._decoder=new h$3(i),(this||e$5)._encoding=i),(this||e$5)._encoding!==i)throw new Error("can't switch encodings");var o=(this||e$5)._decoder.write(t);return r&&(o+=(this||e$5)._decoder.end()),o};var f$6=a$5;var m$1=u,n$6=I,p$3=nt,s$3=f$6;function a$6(t){s$3.call(this,"digest"),this._hash=t;}t$2$2(a$6,s$3),a$6.prototype._update=function(t){this._hash.update(t);},a$6.prototype._final=function(){return this._hash.digest()};var h$4=function(t){return "md5"===(t=t.toLowerCase())?new m$1:"rmd160"===t||"ripemd160"===t?new n$6:new a$6(p$3(t))};var e$6=u,r$4=function(t){return (new e$6).update(t).digest()};var o$6=t$2$2,h$5=u$q.Buffer,n$7=f$6,p$4=h$5.alloc(128);function f$7(t,a){n$7.call(this,"digest"),"string"==typeof a&&(a=h$5.from(a)),this._alg=t,this._key=a,a.length>64?a=t(a):a.length<64&&(a=h$5.concat([a,p$4],64));for(var e=this._ipad=h$5.allocUnsafe(64),i=this._opad=h$5.allocUnsafe(64),r=0;r<64;r++)e[r]=54^a[r],i[r]=92^a[r];this._hash=[e];}o$6(f$7,n$7),f$7.prototype._update=function(t){this._hash.push(t);},f$7.prototype._final=function(){var t=this._alg(h$5.concat(this._hash));return this._alg(h$5.concat([this._opad,t]))};var l$4=t$2$2,d$3=f$7,c$4=f$6,_$4=u$q.Buffer,m$2=r$4,u$4=I,g$1=nt,v$1=_$4.alloc(128);function y$1(t,a){c$4.call(this,"digest"),"string"==typeof a&&(a=_$4.from(a));var e="sha512"===t||"sha384"===t?128:64;(this._alg=t,this._key=a,a.length>e)?a=("rmd160"===t?new u$4:g$1(t)).update(a).digest():a.lengtha$7||n!=n)throw new TypeError("Bad key length")},c$5=T$9;c$5.browser?u$5="utf-8":u$5=parseInt(c$5.version.split(".")[0].slice(1),10)>=6?"utf-8":"binary";var l$5=u$5,p$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,d$4=r$4,m$3=I,y$2=nt,b$3=h$6,v$2=l$5,w$4=u$q.Buffer,g$2=w$4.alloc(128),B$1={md5:16,sha1:20,sha224:28,sha256:32,sha384:48,sha512:64,rmd160:20,ripemd160:20};function T$1(r,e,t){var n=function(r){function e(e){return y$2(r).update(e).digest()}return "rmd160"===r||"ripemd160"===r?function(r){return (new m$3).update(r).digest()}:"md5"===r?d$4:e}(r),o="sha512"===r||"sha384"===r?128:64;e.length>o?e=n(e):e.length0;i--)e+=this._buffer(t,e),r+=this._flushBuffer(n,r);return e+=this._buffer(t,e),n},u$6.prototype.final=function(t){var e,r;return t&&(e=this.update(t)),r="encrypt"===this.type?this._finalEncrypt():this._finalDecrypt(),e?e.concat(r):r},u$6.prototype._pad=function(t,e){if(0===e)return !1;for(;e>>1];r=c$6.r28shl(r,f),i=c$6.r28shl(i,f),c$6.pc2(r,i,t.keys,n);}},v$3.prototype._update=function(t,e,r,i){var n=this._desState,f=c$6.readUInt32BE(t,e),o=c$6.readUInt32BE(t,e+4);c$6.ip(f,o,n.tmp,0),f=n.tmp[0],o=n.tmp[1],"encrypt"===this.type?this._encrypt(n,f,o,n.tmp,0):this._decrypt(n,f,o,n.tmp,0),f=n.tmp[0],o=n.tmp[1],c$6.writeUInt32BE(r,f,i),c$6.writeUInt32BE(r,o,i+4);},v$3.prototype._pad=function(t,e){for(var r=t.length-e,i=e;i>>0,f=h;}c$6.rip(o,f,i,n);},v$3.prototype._decrypt=function(t,e,r,i,n){for(var f=r,o=e,p=t.keys.length-2;p>=0;p-=2){var u=t.keys[p],s=t.keys[p+1];c$6.expand(f,t.tmp,0),u^=t.tmp[0],s^=t.tmp[1];var a=c$6.substitute(u,s),h=f;f=(o^c$6.permute(a))>>>0,o=h;}c$6.rip(f,o,i,n);};var _$5=s$6,b$4={},k$4=o$7,g$3=t$2$2,m$4={};function S$2(t){k$4.equal(t.length,8,"Invalid IV length"),this.iv=new Array(8);for(var e=0;e>p%8,e._prev=k$5(e._prev,r?t:a);return n}function k$5(e,c){var r=e.length,t=-1,a=m$5.allocUnsafe(e.length);for(e=m$5.concat([e,m$5.from([c])]);++t>7;return a}l$8.encrypt=function(e,c,r){for(var t=c.length,a=m$5.allocUnsafe(t),p=-1;++p>>24]^l[_>>>16&255]^f[d>>>8&255]^u[255&y]^e[B++],h=c[_>>>24]^l[d>>>16&255]^f[y>>>8&255]^u[255&p]^e[B++],o=c[d>>>24]^l[y>>>16&255]^f[p>>>8&255]^u[255&_]^e[B++],s=c[y>>>24]^l[p>>>16&255]^f[_>>>8&255]^u[255&d]^e[B++],p=a,_=h,d=o,y=s;return a=(r[p>>>24]<<24|r[_>>>16&255]<<16|r[d>>>8&255]<<8|r[255&y])^e[B++],h=(r[_>>>24]<<24|r[d>>>16&255]<<16|r[y>>>8&255]<<8|r[255&p])^e[B++],o=(r[d>>>24]<<24|r[y>>>16&255]<<16|r[p>>>8&255]<<8|r[255&_])^e[B++],s=(r[y>>>24]<<24|r[p>>>16&255]<<16|r[_>>>8&255]<<8|r[255&d])^e[B++],[a>>>=0,h>>>=0,o>>>=0,s>>>=0]}var f$d=[0,1,2,4,8,16,32,64,128,27,54],u$8=function(){for(var t=new Array(256),e=0;e<256;e++)t[e]=e<128?e<<1:e<<1^283;for(var i=[],r=[],n=[[],[],[],[]],a=[[],[],[],[]],h=0,o=0,s=0;s<256;++s){var c=o^o<<1^o<<2^o<<3^o<<4;c=c>>>8^255&c^99,i[h]=c,r[c]=h;var l=t[h],f=t[l],u=t[f],p=257*t[c]^16843008*c;n[0][h]=p<<24|p>>>8,n[1][h]=p<<16|p>>>16,n[2][h]=p<<8|p>>>24,n[3][h]=p,p=16843009*u^65537*f^257*l^16843008*h,a[0][c]=p<<24|p>>>8,a[1][c]=p<<16|p>>>16,a[2][c]=p<<8|p>>>24,a[3][c]=p,0===h?h=o=1:(h=l^t[t[t[u^l]]],o^=t[t[o]]);}return {SBOX:i,INV_SBOX:r,SUB_MIX:n,INV_SUB_MIX:a}}();function p$9(t){(this||a$b)._key=s$8(t),this._reset();}p$9.blockSize=16,p$9.keySize=32,p$9.prototype.blockSize=p$9.blockSize,p$9.prototype.keySize=p$9.keySize,p$9.prototype._reset=function(){for(var t=(this||a$b)._key,e=t.length,i=e+6,r=4*(i+1),n=[],h=0;h>>24,o=u$8.SBOX[o>>>24]<<24|u$8.SBOX[o>>>16&255]<<16|u$8.SBOX[o>>>8&255]<<8|u$8.SBOX[255&o],o^=f$d[h/e|0]<<24):e>6&&h%e==4&&(o=u$8.SBOX[o>>>24]<<24|u$8.SBOX[o>>>16&255]<<16|u$8.SBOX[o>>>8&255]<<8|u$8.SBOX[255&o]),n[h]=n[h-e]^o;}for(var s=[],c=0;c>>24]]^u$8.INV_SUB_MIX[1][u$8.SBOX[p>>>16&255]]^u$8.INV_SUB_MIX[2][u$8.SBOX[p>>>8&255]]^u$8.INV_SUB_MIX[3][u$8.SBOX[255&p]];}(this||a$b)._nRounds=i,(this||a$b)._keySchedule=n,(this||a$b)._invKeySchedule=s;},p$9.prototype.encryptBlockRaw=function(t){return l$9(t=s$8(t),(this||a$b)._keySchedule,u$8.SUB_MIX,u$8.SBOX,(this||a$b)._nRounds)},p$9.prototype.encryptBlock=function(t){var e=this.encryptBlockRaw(t),i=o$b.allocUnsafe(16);return i.writeUInt32BE(e[0],0),i.writeUInt32BE(e[1],4),i.writeUInt32BE(e[2],8),i.writeUInt32BE(e[3],12),i},p$9.prototype.decryptBlock=function(t){var e=(t=s$8(t))[1];t[1]=t[3],t[3]=e;var i=l$9(t,(this||a$b)._invKeySchedule,u$8.INV_SUB_MIX,u$8.INV_SBOX,(this||a$b)._nRounds),r=o$b.allocUnsafe(16);return r.writeUInt32BE(i[0],0),r.writeUInt32BE(i[3],4),r.writeUInt32BE(i[2],8),r.writeUInt32BE(i[1],12),r},p$9.prototype.scrub=function(){c$8((this||a$b)._keySchedule),c$8((this||a$b)._invKeySchedule),c$8((this||a$b)._key);},h$9.AES=p$9;var _$7="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,d$8=u$q.Buffer,y$5=d$8.alloc(16,0);function B$4(t){var e=d$8.allocUnsafe(16);return e.writeUInt32BE(t[0]>>>0,0),e.writeUInt32BE(t[1]>>>0,4),e.writeUInt32BE(t[2]>>>0,8),e.writeUInt32BE(t[3]>>>0,12),e}function g$5(t){(this||_$7).h=t,(this||_$7).state=d$8.alloc(16,0),(this||_$7).cache=d$8.allocUnsafe(0);}g$5.prototype.ghash=function(t){for(var e=-1;++e0;e--)r[e]=r[e]>>>1|(1&r[e-1])<<31;r[0]=r[0]>>>1,i&&(r[0]=r[0]^225<<24);}(this||_$7).state=B$4(n);},g$5.prototype.update=function(t){var e;for((this||_$7).cache=d$8.concat([(this||_$7).cache,t]);(this||_$7).cache.length>=16;)e=(this||_$7).cache.slice(0,16),(this||_$7).cache=(this||_$7).cache.slice(16),this.ghash(e);},g$5.prototype.final=function(t,e){return (this||_$7).cache.length&&this.ghash(d$8.concat([(this||_$7).cache,y$5],16)),this.ghash(B$4([0,t,0,e])),(this||_$7).state};var S$4=g$5,v$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,I$5=h$9,U$4=u$q.Buffer,w$7=f$6,m$6=S$4,E$5=f$b,b$6=t$1;function X$1(t,e,i,r){w$7.call(this||v$5);var n=U$4.alloc(4,0);(this||v$5)._cipher=new I$5.AES(e);var a=(this||v$5)._cipher.encryptBlock(n);(this||v$5)._ghash=new m$6(a),i=function(t,e,i){if(12===e.length)return t._finID=U$4.concat([e,U$4.from([0,0,0,1])]),U$4.concat([e,U$4.from([0,0,0,2])]);var r=new m$6(i),n=e.length,a=n%16;r.update(e),a&&(a=16-a,r.update(U$4.alloc(a,0))),r.update(U$4.alloc(8,0));var h=8*n,o=U$4.alloc(8);o.writeUIntBE(h,0,8),r.update(o),t._finID=r.state;var s=U$4.from(t._finID);return b$6(s),s}(this||v$5,i,a),(this||v$5)._prev=U$4.from(i),(this||v$5)._cache=U$4.allocUnsafe(0),(this||v$5)._secCache=U$4.allocUnsafe(0),(this||v$5)._decrypt=r,(this||v$5)._alen=0,(this||v$5)._len=0,(this||v$5)._mode=t,(this||v$5)._authTag=null,(this||v$5)._called=!1;}t$2$2(X$1,w$7),X$1.prototype._update=function(t){if(!(this||v$5)._called&&(this||v$5)._alen){var e=16-(this||v$5)._alen%16;e<16&&(e=U$4.alloc(e,0),(this||v$5)._ghash.update(e));}(this||v$5)._called=!0;var i=(this||v$5)._mode.encrypt(this||v$5,t);return (this||v$5)._decrypt?(this||v$5)._ghash.update(t):(this||v$5)._ghash.update(i),(this||v$5)._len+=t.length,i},X$1.prototype._final=function(){if((this||v$5)._decrypt&&!(this||v$5)._authTag)throw new Error("Unsupported state or unable to authenticate data");var t=E$5((this||v$5)._ghash.final(8*(this||v$5)._alen,8*(this||v$5)._len),(this||v$5)._cipher.encryptBlock((this||v$5)._finID));if((this||v$5)._decrypt&&function(t,e){var i=0;t.length!==e.length&&i++;for(var r=Math.min(t.length,e.length),n=0;n0||l>0;){var u=new f$e;u.update(h),u.update(r),e&&u.update(e),h=u.digest();var g=0;if(n>0){var m=o.length-n;g=Math.min(n,h.length),h.copy(o,m,0,g),n-=g;}if(g0){var p=i.length-l,v=Math.min(l,h.length-g);h.copy(i,p,g,g+v),l-=v;}}return h.fill(0),{key:o,iv:i}};var c$9="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,s$9={},f$f=k$6,p$a=u$q.Buffer,u$9=M$2,l$a=V$1,d$9=f$6,y$6=h$9,m$7=a$c;function g$6(t,e,r){d$9.call(this||c$9),(this||c$9)._cache=new v$6,(this||c$9)._last=void 0,(this||c$9)._cipher=new y$6.AES(e),(this||c$9)._prev=p$a.from(r),(this||c$9)._mode=t,(this||c$9)._autopadding=!0;}function v$6(){(this||c$9).cache=p$a.allocUnsafe(0);}function w$8(t,e,r){var i=u$9[t.toLowerCase()];if(!i)throw new TypeError("invalid suite type");if("string"==typeof r&&(r=p$a.from(r)),"GCM"!==i.mode&&r.length!==i.iv)throw new TypeError("invalid iv length "+r.length);if("string"==typeof e&&(e=p$a.from(e)),e.length!==i.key/8)throw new TypeError("invalid key length "+e.length);return "stream"===i.type?new l$a(i.module,e,r,!0):"auth"===i.type?new f$f(i.module,e,r,!0):new g$6(i.module,e,r)}t$2$2(g$6,d$9),g$6.prototype._update=function(t){var e,r;(this||c$9)._cache.add(t);for(var i=[];e=(this||c$9)._cache.get((this||c$9)._autopadding);)r=(this||c$9)._mode.decrypt(this||c$9,e),i.push(r);return p$a.concat(i)},g$6.prototype._final=function(){var t=(this||c$9)._cache.flush();if((this||c$9)._autopadding)return function(t){var e=t[15];if(e<1||e>16)throw new Error("unable to decrypt data");var r=-1;for(;++r16)return e=(this||c$9).cache.slice(0,16),(this||c$9).cache=(this||c$9).cache.slice(16),e}else if((this||c$9).cache.length>=16)return e=(this||c$9).cache.slice(0,16),(this||c$9).cache=(this||c$9).cache.slice(16),e;return null},v$6.prototype.flush=function(){if((this||c$9).cache.length)return (this||c$9).cache},s$9.createDecipher=function(t,e){var r=u$9[t.toLowerCase()];if(!r)throw new TypeError("invalid suite type");var i=m$7(e,!1,r.key,r.iv);return w$8(t,i.key,i.iv)},s$9.createDecipheriv=w$8;var c$a="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,s$a={},f$g=M$2,p$b=k$6,l$b=u$q.Buffer,u$a=V$1,d$a=f$6,m$8=h$9,y$7=a$c;function v$7(t,e,r){d$a.call(this||c$a),(this||c$a)._cache=new g$7,(this||c$a)._cipher=new m$8.AES(e),(this||c$a)._prev=l$b.from(r),(this||c$a)._mode=t,(this||c$a)._autopadding=!0;}t$2$2(v$7,d$a),v$7.prototype._update=function(t){var e,r;(this||c$a)._cache.add(t);for(var i=[];e=(this||c$a)._cache.get();)r=(this||c$a)._mode.encrypt(this||c$a,e),i.push(r);return l$b.concat(i)};var _$8=l$b.alloc(16,16);function g$7(){(this||c$a).cache=l$b.allocUnsafe(0);}function w$9(t,e,r){var i=f$g[t.toLowerCase()];if(!i)throw new TypeError("invalid suite type");if("string"==typeof e&&(e=l$b.from(e)),e.length!==i.key/8)throw new TypeError("invalid key length "+e.length);if("string"==typeof r&&(r=l$b.from(r)),"GCM"!==i.mode&&r.length!==i.iv)throw new TypeError("invalid iv length "+r.length);return "stream"===i.type?new u$a(i.module,e,r):"auth"===i.type?new p$b(i.module,e,r):new v$7(i.module,e,r)}v$7.prototype._final=function(){var t=(this||c$a)._cache.flush();if((this||c$a)._autopadding)return t=(this||c$a)._mode.encrypt(this||c$a,t),(this||c$a)._cipher.scrub(),t;if(!t.equals(_$8))throw (this||c$a)._cipher.scrub(),new Error("data not multiple of block length")},v$7.prototype.setAutoPadding=function(t){return (this||c$a)._autopadding=!!t,this||c$a},g$7.prototype.add=function(t){(this||c$a).cache=l$b.concat([(this||c$a).cache,t]);},g$7.prototype.get=function(){if((this||c$a).cache.length>15){var t=(this||c$a).cache.slice(0,16);return (this||c$a).cache=(this||c$a).cache.slice(16),t}return null},g$7.prototype.flush=function(){for(var t=16-(this||c$a).cache.length,e=l$b.allocUnsafe(t),r=-1;++r=49&&o<=54?o-49+10:o>=17&&o<=22?o-17+10:15&o;}return h}function a(t,i,r,h){for(var n=0,e=Math.min(t.length,r),o=i;o=49?s-49+10:s>=17?s-17+10:s;}return n}o.isBN=function(t){return t instanceof o||null!==t&&"object"==typeof t&&t.constructor.wordSize===o.wordSize&&Array.isArray(t.words)},o.max=function(t,i){return t.cmp(i)>0?t:i},o.min=function(t,i){return t.cmp(i)<0?t:i},o.prototype._init=function(t,r,h){if("number"==typeof t)return this._initNumber(t,r,h);if("object"==typeof t)return this._initArray(t,r,h);"hex"===r&&(r=16),n(r===(0|r)&&r>=2&&r<=36);var e=0;"-"===(t=t.toString().replace(/\s+/g,""))[0]&&e++,16===r?this._parseHex(t,e):this._parseBase(t,r,e),"-"===t[0]&&((this||i$3).negative=1),this.strip(),"le"===h&&this._initArray(this.toArray(),r,h);},o.prototype._initNumber=function(t,r,h){t<0&&((this||i$3).negative=1,t=-t),t<67108864?((this||i$3).words=[67108863&t],(this||i$3).length=1):t<4503599627370496?((this||i$3).words=[67108863&t,t/67108864&67108863],(this||i$3).length=2):(n(t<9007199254740992),(this||i$3).words=[67108863&t,t/67108864&67108863,1],(this||i$3).length=3),"le"===h&&this._initArray(this.toArray(),r,h);},o.prototype._initArray=function(t,r,h){if(n("number"==typeof t.length),t.length<=0)return (this||i$3).words=[0],(this||i$3).length=1,this||i$3;(this||i$3).length=Math.ceil(t.length/3),(this||i$3).words=new Array((this||i$3).length);for(var e=0;e<(this||i$3).length;e++)(this||i$3).words[e]=0;var o,s,u=0;if("be"===h)for(e=t.length-1,o=0;e>=0;e-=3)s=t[e]|t[e-1]<<8|t[e-2]<<16,(this||i$3).words[o]|=s<>>26-u&67108863,(u+=24)>=26&&(u-=26,o++);else if("le"===h)for(e=0,o=0;e>>26-u&67108863,(u+=24)>=26&&(u-=26,o++);return this.strip()},o.prototype._parseHex=function(t,r){(this||i$3).length=Math.ceil((t.length-r)/6),(this||i$3).words=new Array((this||i$3).length);for(var h=0;h<(this||i$3).length;h++)(this||i$3).words[h]=0;var n,e,o=0;for(h=t.length-6,n=0;h>=r;h-=6)e=u(t,h,h+6),(this||i$3).words[n]|=e<>>26-o&4194303,(o+=24)>=26&&(o-=26,n++);h+6!==r&&(e=u(t,r,h+6),(this||i$3).words[n]|=e<>>26-o&4194303),this.strip();},o.prototype._parseBase=function(t,r,h){(this||i$3).words=[0],(this||i$3).length=1;for(var n=0,e=1;e<=67108863;e*=r)n++;n--,e=e/r|0;for(var o=t.length-h,s=o%n,u=Math.min(o,o-s)+h,l=0,m=h;m1&&0===(this||i$3).words[(this||i$3).length-1];)(this||i$3).length--;return this._normSign()},o.prototype._normSign=function(){return 1===(this||i$3).length&&0===(this||i$3).words[0]&&((this||i$3).negative=0),this||i$3},o.prototype.inspect=function(){return ((this||i$3).red?""};var l=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],m=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],f=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];function d(t,i,r){r.negative=i.negative^t.negative;var h=t.length+i.length|0;r.length=h,h=h-1|0;var n=0|t.words[0],e=0|i.words[0],o=n*e,s=67108863&o,u=o/67108864|0;r.words[0]=s;for(var a=1;a>>26,m=67108863&u,f=Math.min(a,i.length-1),d=Math.max(0,a-t.length+1);d<=f;d++){var p=a-d|0;l+=(o=(n=0|t.words[p])*(e=0|i.words[d])+m)/67108864|0,m=67108863&o;}r.words[a]=0|m,u=0|l;}return 0!==u?r.words[a]=0|u:r.length--,r.strip()}o.prototype.toString=function(t,r){var h;if(r=0|r||1,16===(t=t||10)||"hex"===t){h="";for(var e=0,o=0,s=0;s<(this||i$3).length;s++){var u=(this||i$3).words[s],a=(16777215&(u<>>24-e&16777215)||s!==(this||i$3).length-1?l[6-a.length]+a+h:a+h,(e+=2)>=26&&(e-=26,s--);}for(0!==o&&(h=o.toString(16)+h);h.length%r!=0;)h="0"+h;return 0!==(this||i$3).negative&&(h="-"+h),h}if(t===(0|t)&&t>=2&&t<=36){var d=m[t],p=f[t];h="";var M=this.clone();for(M.negative=0;!M.isZero();){var v=M.modn(p).toString(t);h=(M=M.idivn(p)).isZero()?v+h:l[d-v.length]+v+h;}for(this.isZero()&&(h="0"+h);h.length%r!=0;)h="0"+h;return 0!==(this||i$3).negative&&(h="-"+h),h}n(!1,"Base should be between 2 and 36");},o.prototype.toNumber=function(){var t=(this||i$3).words[0];return 2===(this||i$3).length?t+=67108864*(this||i$3).words[1]:3===(this||i$3).length&&1===(this||i$3).words[2]?t+=4503599627370496+67108864*(this||i$3).words[1]:(this||i$3).length>2&&n(!1,"Number can only safely store up to 53 bits"),0!==(this||i$3).negative?-t:t},o.prototype.toJSON=function(){return this.toString(16)},o.prototype.toBuffer=function(t,i){return n(void 0!==s),this.toArrayLike(s,t,i)},o.prototype.toArray=function(t,i){return this.toArrayLike(Array,t,i)},o.prototype.toArrayLike=function(t,i,r){var h=this.byteLength(),e=r||Math.max(1,h);n(h<=e,"byte array longer than desired length"),n(e>0,"Requested array length <= 0"),this.strip();var o,s,u="le"===i,a=new t(e),l=this.clone();if(u){for(s=0;!l.isZero();s++)o=l.andln(255),l.iushrn(8),a[s]=o;for(;s=4096&&(r+=13,i>>>=13),i>=64&&(r+=7,i>>>=7),i>=8&&(r+=4,i>>>=4),i>=2&&(r+=2,i>>>=2),r+i},o.prototype._zeroBits=function(t){if(0===t)return 26;var i=t,r=0;return 0==(8191&i)&&(r+=13,i>>>=13),0==(127&i)&&(r+=7,i>>>=7),0==(15&i)&&(r+=4,i>>>=4),0==(3&i)&&(r+=2,i>>>=2),0==(1&i)&&r++,r},o.prototype.bitLength=function(){var t=(this||i$3).words[(this||i$3).length-1],r=this._countBits(t);return 26*((this||i$3).length-1)+r},o.prototype.zeroBits=function(){if(this.isZero())return 0;for(var t=0,r=0;r<(this||i$3).length;r++){var h=this._zeroBits((this||i$3).words[r]);if(t+=h,26!==h)break}return t},o.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},o.prototype.toTwos=function(t){return 0!==(this||i$3).negative?this.abs().inotn(t).iaddn(1):this.clone()},o.prototype.fromTwos=function(t){return this.testn(t-1)?this.notn(t).iaddn(1).ineg():this.clone()},o.prototype.isNeg=function(){return 0!==(this||i$3).negative},o.prototype.neg=function(){return this.clone().ineg()},o.prototype.ineg=function(){return this.isZero()||((this||i$3).negative^=1),this||i$3},o.prototype.iuor=function(t){for(;(this||i$3).lengtht.length?this.clone().ior(t):t.clone().ior(this||i$3)},o.prototype.uor=function(t){return (this||i$3).length>t.length?this.clone().iuor(t):t.clone().iuor(this||i$3)},o.prototype.iuand=function(t){var r;r=(this||i$3).length>t.length?t:this||i$3;for(var h=0;ht.length?this.clone().iand(t):t.clone().iand(this||i$3)},o.prototype.uand=function(t){return (this||i$3).length>t.length?this.clone().iuand(t):t.clone().iuand(this||i$3)},o.prototype.iuxor=function(t){var r,h;(this||i$3).length>t.length?(r=this||i$3,h=t):(r=t,h=this||i$3);for(var n=0;nt.length?this.clone().ixor(t):t.clone().ixor(this||i$3)},o.prototype.uxor=function(t){return (this||i$3).length>t.length?this.clone().iuxor(t):t.clone().iuxor(this||i$3)},o.prototype.inotn=function(t){n("number"==typeof t&&t>=0);var r=0|Math.ceil(t/26),h=t%26;this._expand(r),h>0&&r--;for(var e=0;e0&&((this||i$3).words[e]=~(this||i$3).words[e]&67108863>>26-h),this.strip()},o.prototype.notn=function(t){return this.clone().inotn(t)},o.prototype.setn=function(t,r){n("number"==typeof t&&t>=0);var h=t/26|0,e=t%26;return this._expand(h+1),(this||i$3).words[h]=r?(this||i$3).words[h]|1<t.length?(h=this||i$3,n=t):(h=t,n=this||i$3);for(var e=0,o=0;o>>26;for(;0!==e&&o>>26;if((this||i$3).length=h.length,0!==e)(this||i$3).words[(this||i$3).length]=e,(this||i$3).length++;else if(h!==(this||i$3))for(;ot.length?this.clone().iadd(t):t.clone().iadd(this||i$3)},o.prototype.isub=function(t){if(0!==t.negative){t.negative=0;var r=this.iadd(t);return t.negative=1,r._normSign()}if(0!==(this||i$3).negative)return (this||i$3).negative=0,this.iadd(t),(this||i$3).negative=1,this._normSign();var h,n,e=this.cmp(t);if(0===e)return (this||i$3).negative=0,(this||i$3).length=1,(this||i$3).words[0]=0,this||i$3;e>0?(h=this||i$3,n=t):(h=t,n=this||i$3);for(var o=0,s=0;s>26,(this||i$3).words[s]=67108863&r;for(;0!==o&&s>26,(this||i$3).words[s]=67108863&r;if(0===o&&s>>13,d=0|o[1],p=8191&d,M=d>>>13,v=0|o[2],g=8191&v,c=v>>>13,w=0|o[3],y=8191&w,b=w>>>13,_=0|o[4],k=8191&_,A=_>>>13,x=0|o[5],S=8191&x,Z=x>>>13,R=0|o[6],q=8191&R,B=R>>>13,N=0|o[7],L=8191&N,I=N>>>13,T=0|o[8],z=8191&T,E=T>>>13,O=0|o[9],j=8191&O,K=O>>>13,P=0|s[0],F=8191&P,C=P>>>13,D=0|s[1],H=8191&D,J=D>>>13,U=0|s[2],G=8191&U,Q=U>>>13,V=0|s[3],W=8191&V,X=V>>>13,Y=0|s[4],$=8191&Y,tt=Y>>>13,it=0|s[5],rt=8191&it,ht=it>>>13,nt=0|s[6],et=8191&nt,ot=nt>>>13,st=0|s[7],ut=8191&st,at=st>>>13,lt=0|s[8],mt=8191<,ft=lt>>>13,dt=0|s[9],pt=8191&dt,Mt=dt>>>13;r.negative=t.negative^i.negative,r.length=19;var vt=(a+(h=Math.imul(m,F))|0)+((8191&(n=(n=Math.imul(m,C))+Math.imul(f,F)|0))<<13)|0;a=((e=Math.imul(f,C))+(n>>>13)|0)+(vt>>>26)|0,vt&=67108863,h=Math.imul(p,F),n=(n=Math.imul(p,C))+Math.imul(M,F)|0,e=Math.imul(M,C);var gt=(a+(h=h+Math.imul(m,H)|0)|0)+((8191&(n=(n=n+Math.imul(m,J)|0)+Math.imul(f,H)|0))<<13)|0;a=((e=e+Math.imul(f,J)|0)+(n>>>13)|0)+(gt>>>26)|0,gt&=67108863,h=Math.imul(g,F),n=(n=Math.imul(g,C))+Math.imul(c,F)|0,e=Math.imul(c,C),h=h+Math.imul(p,H)|0,n=(n=n+Math.imul(p,J)|0)+Math.imul(M,H)|0,e=e+Math.imul(M,J)|0;var ct=(a+(h=h+Math.imul(m,G)|0)|0)+((8191&(n=(n=n+Math.imul(m,Q)|0)+Math.imul(f,G)|0))<<13)|0;a=((e=e+Math.imul(f,Q)|0)+(n>>>13)|0)+(ct>>>26)|0,ct&=67108863,h=Math.imul(y,F),n=(n=Math.imul(y,C))+Math.imul(b,F)|0,e=Math.imul(b,C),h=h+Math.imul(g,H)|0,n=(n=n+Math.imul(g,J)|0)+Math.imul(c,H)|0,e=e+Math.imul(c,J)|0,h=h+Math.imul(p,G)|0,n=(n=n+Math.imul(p,Q)|0)+Math.imul(M,G)|0,e=e+Math.imul(M,Q)|0;var wt=(a+(h=h+Math.imul(m,W)|0)|0)+((8191&(n=(n=n+Math.imul(m,X)|0)+Math.imul(f,W)|0))<<13)|0;a=((e=e+Math.imul(f,X)|0)+(n>>>13)|0)+(wt>>>26)|0,wt&=67108863,h=Math.imul(k,F),n=(n=Math.imul(k,C))+Math.imul(A,F)|0,e=Math.imul(A,C),h=h+Math.imul(y,H)|0,n=(n=n+Math.imul(y,J)|0)+Math.imul(b,H)|0,e=e+Math.imul(b,J)|0,h=h+Math.imul(g,G)|0,n=(n=n+Math.imul(g,Q)|0)+Math.imul(c,G)|0,e=e+Math.imul(c,Q)|0,h=h+Math.imul(p,W)|0,n=(n=n+Math.imul(p,X)|0)+Math.imul(M,W)|0,e=e+Math.imul(M,X)|0;var yt=(a+(h=h+Math.imul(m,$)|0)|0)+((8191&(n=(n=n+Math.imul(m,tt)|0)+Math.imul(f,$)|0))<<13)|0;a=((e=e+Math.imul(f,tt)|0)+(n>>>13)|0)+(yt>>>26)|0,yt&=67108863,h=Math.imul(S,F),n=(n=Math.imul(S,C))+Math.imul(Z,F)|0,e=Math.imul(Z,C),h=h+Math.imul(k,H)|0,n=(n=n+Math.imul(k,J)|0)+Math.imul(A,H)|0,e=e+Math.imul(A,J)|0,h=h+Math.imul(y,G)|0,n=(n=n+Math.imul(y,Q)|0)+Math.imul(b,G)|0,e=e+Math.imul(b,Q)|0,h=h+Math.imul(g,W)|0,n=(n=n+Math.imul(g,X)|0)+Math.imul(c,W)|0,e=e+Math.imul(c,X)|0,h=h+Math.imul(p,$)|0,n=(n=n+Math.imul(p,tt)|0)+Math.imul(M,$)|0,e=e+Math.imul(M,tt)|0;var bt=(a+(h=h+Math.imul(m,rt)|0)|0)+((8191&(n=(n=n+Math.imul(m,ht)|0)+Math.imul(f,rt)|0))<<13)|0;a=((e=e+Math.imul(f,ht)|0)+(n>>>13)|0)+(bt>>>26)|0,bt&=67108863,h=Math.imul(q,F),n=(n=Math.imul(q,C))+Math.imul(B,F)|0,e=Math.imul(B,C),h=h+Math.imul(S,H)|0,n=(n=n+Math.imul(S,J)|0)+Math.imul(Z,H)|0,e=e+Math.imul(Z,J)|0,h=h+Math.imul(k,G)|0,n=(n=n+Math.imul(k,Q)|0)+Math.imul(A,G)|0,e=e+Math.imul(A,Q)|0,h=h+Math.imul(y,W)|0,n=(n=n+Math.imul(y,X)|0)+Math.imul(b,W)|0,e=e+Math.imul(b,X)|0,h=h+Math.imul(g,$)|0,n=(n=n+Math.imul(g,tt)|0)+Math.imul(c,$)|0,e=e+Math.imul(c,tt)|0,h=h+Math.imul(p,rt)|0,n=(n=n+Math.imul(p,ht)|0)+Math.imul(M,rt)|0,e=e+Math.imul(M,ht)|0;var _t=(a+(h=h+Math.imul(m,et)|0)|0)+((8191&(n=(n=n+Math.imul(m,ot)|0)+Math.imul(f,et)|0))<<13)|0;a=((e=e+Math.imul(f,ot)|0)+(n>>>13)|0)+(_t>>>26)|0,_t&=67108863,h=Math.imul(L,F),n=(n=Math.imul(L,C))+Math.imul(I,F)|0,e=Math.imul(I,C),h=h+Math.imul(q,H)|0,n=(n=n+Math.imul(q,J)|0)+Math.imul(B,H)|0,e=e+Math.imul(B,J)|0,h=h+Math.imul(S,G)|0,n=(n=n+Math.imul(S,Q)|0)+Math.imul(Z,G)|0,e=e+Math.imul(Z,Q)|0,h=h+Math.imul(k,W)|0,n=(n=n+Math.imul(k,X)|0)+Math.imul(A,W)|0,e=e+Math.imul(A,X)|0,h=h+Math.imul(y,$)|0,n=(n=n+Math.imul(y,tt)|0)+Math.imul(b,$)|0,e=e+Math.imul(b,tt)|0,h=h+Math.imul(g,rt)|0,n=(n=n+Math.imul(g,ht)|0)+Math.imul(c,rt)|0,e=e+Math.imul(c,ht)|0,h=h+Math.imul(p,et)|0,n=(n=n+Math.imul(p,ot)|0)+Math.imul(M,et)|0,e=e+Math.imul(M,ot)|0;var kt=(a+(h=h+Math.imul(m,ut)|0)|0)+((8191&(n=(n=n+Math.imul(m,at)|0)+Math.imul(f,ut)|0))<<13)|0;a=((e=e+Math.imul(f,at)|0)+(n>>>13)|0)+(kt>>>26)|0,kt&=67108863,h=Math.imul(z,F),n=(n=Math.imul(z,C))+Math.imul(E,F)|0,e=Math.imul(E,C),h=h+Math.imul(L,H)|0,n=(n=n+Math.imul(L,J)|0)+Math.imul(I,H)|0,e=e+Math.imul(I,J)|0,h=h+Math.imul(q,G)|0,n=(n=n+Math.imul(q,Q)|0)+Math.imul(B,G)|0,e=e+Math.imul(B,Q)|0,h=h+Math.imul(S,W)|0,n=(n=n+Math.imul(S,X)|0)+Math.imul(Z,W)|0,e=e+Math.imul(Z,X)|0,h=h+Math.imul(k,$)|0,n=(n=n+Math.imul(k,tt)|0)+Math.imul(A,$)|0,e=e+Math.imul(A,tt)|0,h=h+Math.imul(y,rt)|0,n=(n=n+Math.imul(y,ht)|0)+Math.imul(b,rt)|0,e=e+Math.imul(b,ht)|0,h=h+Math.imul(g,et)|0,n=(n=n+Math.imul(g,ot)|0)+Math.imul(c,et)|0,e=e+Math.imul(c,ot)|0,h=h+Math.imul(p,ut)|0,n=(n=n+Math.imul(p,at)|0)+Math.imul(M,ut)|0,e=e+Math.imul(M,at)|0;var At=(a+(h=h+Math.imul(m,mt)|0)|0)+((8191&(n=(n=n+Math.imul(m,ft)|0)+Math.imul(f,mt)|0))<<13)|0;a=((e=e+Math.imul(f,ft)|0)+(n>>>13)|0)+(At>>>26)|0,At&=67108863,h=Math.imul(j,F),n=(n=Math.imul(j,C))+Math.imul(K,F)|0,e=Math.imul(K,C),h=h+Math.imul(z,H)|0,n=(n=n+Math.imul(z,J)|0)+Math.imul(E,H)|0,e=e+Math.imul(E,J)|0,h=h+Math.imul(L,G)|0,n=(n=n+Math.imul(L,Q)|0)+Math.imul(I,G)|0,e=e+Math.imul(I,Q)|0,h=h+Math.imul(q,W)|0,n=(n=n+Math.imul(q,X)|0)+Math.imul(B,W)|0,e=e+Math.imul(B,X)|0,h=h+Math.imul(S,$)|0,n=(n=n+Math.imul(S,tt)|0)+Math.imul(Z,$)|0,e=e+Math.imul(Z,tt)|0,h=h+Math.imul(k,rt)|0,n=(n=n+Math.imul(k,ht)|0)+Math.imul(A,rt)|0,e=e+Math.imul(A,ht)|0,h=h+Math.imul(y,et)|0,n=(n=n+Math.imul(y,ot)|0)+Math.imul(b,et)|0,e=e+Math.imul(b,ot)|0,h=h+Math.imul(g,ut)|0,n=(n=n+Math.imul(g,at)|0)+Math.imul(c,ut)|0,e=e+Math.imul(c,at)|0,h=h+Math.imul(p,mt)|0,n=(n=n+Math.imul(p,ft)|0)+Math.imul(M,mt)|0,e=e+Math.imul(M,ft)|0;var xt=(a+(h=h+Math.imul(m,pt)|0)|0)+((8191&(n=(n=n+Math.imul(m,Mt)|0)+Math.imul(f,pt)|0))<<13)|0;a=((e=e+Math.imul(f,Mt)|0)+(n>>>13)|0)+(xt>>>26)|0,xt&=67108863,h=Math.imul(j,H),n=(n=Math.imul(j,J))+Math.imul(K,H)|0,e=Math.imul(K,J),h=h+Math.imul(z,G)|0,n=(n=n+Math.imul(z,Q)|0)+Math.imul(E,G)|0,e=e+Math.imul(E,Q)|0,h=h+Math.imul(L,W)|0,n=(n=n+Math.imul(L,X)|0)+Math.imul(I,W)|0,e=e+Math.imul(I,X)|0,h=h+Math.imul(q,$)|0,n=(n=n+Math.imul(q,tt)|0)+Math.imul(B,$)|0,e=e+Math.imul(B,tt)|0,h=h+Math.imul(S,rt)|0,n=(n=n+Math.imul(S,ht)|0)+Math.imul(Z,rt)|0,e=e+Math.imul(Z,ht)|0,h=h+Math.imul(k,et)|0,n=(n=n+Math.imul(k,ot)|0)+Math.imul(A,et)|0,e=e+Math.imul(A,ot)|0,h=h+Math.imul(y,ut)|0,n=(n=n+Math.imul(y,at)|0)+Math.imul(b,ut)|0,e=e+Math.imul(b,at)|0,h=h+Math.imul(g,mt)|0,n=(n=n+Math.imul(g,ft)|0)+Math.imul(c,mt)|0,e=e+Math.imul(c,ft)|0;var St=(a+(h=h+Math.imul(p,pt)|0)|0)+((8191&(n=(n=n+Math.imul(p,Mt)|0)+Math.imul(M,pt)|0))<<13)|0;a=((e=e+Math.imul(M,Mt)|0)+(n>>>13)|0)+(St>>>26)|0,St&=67108863,h=Math.imul(j,G),n=(n=Math.imul(j,Q))+Math.imul(K,G)|0,e=Math.imul(K,Q),h=h+Math.imul(z,W)|0,n=(n=n+Math.imul(z,X)|0)+Math.imul(E,W)|0,e=e+Math.imul(E,X)|0,h=h+Math.imul(L,$)|0,n=(n=n+Math.imul(L,tt)|0)+Math.imul(I,$)|0,e=e+Math.imul(I,tt)|0,h=h+Math.imul(q,rt)|0,n=(n=n+Math.imul(q,ht)|0)+Math.imul(B,rt)|0,e=e+Math.imul(B,ht)|0,h=h+Math.imul(S,et)|0,n=(n=n+Math.imul(S,ot)|0)+Math.imul(Z,et)|0,e=e+Math.imul(Z,ot)|0,h=h+Math.imul(k,ut)|0,n=(n=n+Math.imul(k,at)|0)+Math.imul(A,ut)|0,e=e+Math.imul(A,at)|0,h=h+Math.imul(y,mt)|0,n=(n=n+Math.imul(y,ft)|0)+Math.imul(b,mt)|0,e=e+Math.imul(b,ft)|0;var Zt=(a+(h=h+Math.imul(g,pt)|0)|0)+((8191&(n=(n=n+Math.imul(g,Mt)|0)+Math.imul(c,pt)|0))<<13)|0;a=((e=e+Math.imul(c,Mt)|0)+(n>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,h=Math.imul(j,W),n=(n=Math.imul(j,X))+Math.imul(K,W)|0,e=Math.imul(K,X),h=h+Math.imul(z,$)|0,n=(n=n+Math.imul(z,tt)|0)+Math.imul(E,$)|0,e=e+Math.imul(E,tt)|0,h=h+Math.imul(L,rt)|0,n=(n=n+Math.imul(L,ht)|0)+Math.imul(I,rt)|0,e=e+Math.imul(I,ht)|0,h=h+Math.imul(q,et)|0,n=(n=n+Math.imul(q,ot)|0)+Math.imul(B,et)|0,e=e+Math.imul(B,ot)|0,h=h+Math.imul(S,ut)|0,n=(n=n+Math.imul(S,at)|0)+Math.imul(Z,ut)|0,e=e+Math.imul(Z,at)|0,h=h+Math.imul(k,mt)|0,n=(n=n+Math.imul(k,ft)|0)+Math.imul(A,mt)|0,e=e+Math.imul(A,ft)|0;var Rt=(a+(h=h+Math.imul(y,pt)|0)|0)+((8191&(n=(n=n+Math.imul(y,Mt)|0)+Math.imul(b,pt)|0))<<13)|0;a=((e=e+Math.imul(b,Mt)|0)+(n>>>13)|0)+(Rt>>>26)|0,Rt&=67108863,h=Math.imul(j,$),n=(n=Math.imul(j,tt))+Math.imul(K,$)|0,e=Math.imul(K,tt),h=h+Math.imul(z,rt)|0,n=(n=n+Math.imul(z,ht)|0)+Math.imul(E,rt)|0,e=e+Math.imul(E,ht)|0,h=h+Math.imul(L,et)|0,n=(n=n+Math.imul(L,ot)|0)+Math.imul(I,et)|0,e=e+Math.imul(I,ot)|0,h=h+Math.imul(q,ut)|0,n=(n=n+Math.imul(q,at)|0)+Math.imul(B,ut)|0,e=e+Math.imul(B,at)|0,h=h+Math.imul(S,mt)|0,n=(n=n+Math.imul(S,ft)|0)+Math.imul(Z,mt)|0,e=e+Math.imul(Z,ft)|0;var qt=(a+(h=h+Math.imul(k,pt)|0)|0)+((8191&(n=(n=n+Math.imul(k,Mt)|0)+Math.imul(A,pt)|0))<<13)|0;a=((e=e+Math.imul(A,Mt)|0)+(n>>>13)|0)+(qt>>>26)|0,qt&=67108863,h=Math.imul(j,rt),n=(n=Math.imul(j,ht))+Math.imul(K,rt)|0,e=Math.imul(K,ht),h=h+Math.imul(z,et)|0,n=(n=n+Math.imul(z,ot)|0)+Math.imul(E,et)|0,e=e+Math.imul(E,ot)|0,h=h+Math.imul(L,ut)|0,n=(n=n+Math.imul(L,at)|0)+Math.imul(I,ut)|0,e=e+Math.imul(I,at)|0,h=h+Math.imul(q,mt)|0,n=(n=n+Math.imul(q,ft)|0)+Math.imul(B,mt)|0,e=e+Math.imul(B,ft)|0;var Bt=(a+(h=h+Math.imul(S,pt)|0)|0)+((8191&(n=(n=n+Math.imul(S,Mt)|0)+Math.imul(Z,pt)|0))<<13)|0;a=((e=e+Math.imul(Z,Mt)|0)+(n>>>13)|0)+(Bt>>>26)|0,Bt&=67108863,h=Math.imul(j,et),n=(n=Math.imul(j,ot))+Math.imul(K,et)|0,e=Math.imul(K,ot),h=h+Math.imul(z,ut)|0,n=(n=n+Math.imul(z,at)|0)+Math.imul(E,ut)|0,e=e+Math.imul(E,at)|0,h=h+Math.imul(L,mt)|0,n=(n=n+Math.imul(L,ft)|0)+Math.imul(I,mt)|0,e=e+Math.imul(I,ft)|0;var Nt=(a+(h=h+Math.imul(q,pt)|0)|0)+((8191&(n=(n=n+Math.imul(q,Mt)|0)+Math.imul(B,pt)|0))<<13)|0;a=((e=e+Math.imul(B,Mt)|0)+(n>>>13)|0)+(Nt>>>26)|0,Nt&=67108863,h=Math.imul(j,ut),n=(n=Math.imul(j,at))+Math.imul(K,ut)|0,e=Math.imul(K,at),h=h+Math.imul(z,mt)|0,n=(n=n+Math.imul(z,ft)|0)+Math.imul(E,mt)|0,e=e+Math.imul(E,ft)|0;var Lt=(a+(h=h+Math.imul(L,pt)|0)|0)+((8191&(n=(n=n+Math.imul(L,Mt)|0)+Math.imul(I,pt)|0))<<13)|0;a=((e=e+Math.imul(I,Mt)|0)+(n>>>13)|0)+(Lt>>>26)|0,Lt&=67108863,h=Math.imul(j,mt),n=(n=Math.imul(j,ft))+Math.imul(K,mt)|0,e=Math.imul(K,ft);var It=(a+(h=h+Math.imul(z,pt)|0)|0)+((8191&(n=(n=n+Math.imul(z,Mt)|0)+Math.imul(E,pt)|0))<<13)|0;a=((e=e+Math.imul(E,Mt)|0)+(n>>>13)|0)+(It>>>26)|0,It&=67108863;var Tt=(a+(h=Math.imul(j,pt))|0)+((8191&(n=(n=Math.imul(j,Mt))+Math.imul(K,pt)|0))<<13)|0;return a=((e=Math.imul(K,Mt))+(n>>>13)|0)+(Tt>>>26)|0,Tt&=67108863,u[0]=vt,u[1]=gt,u[2]=ct,u[3]=wt,u[4]=yt,u[5]=bt,u[6]=_t,u[7]=kt,u[8]=At,u[9]=xt,u[10]=St,u[11]=Zt,u[12]=Rt,u[13]=qt,u[14]=Bt,u[15]=Nt,u[16]=Lt,u[17]=It,u[18]=Tt,0!==a&&(u[19]=a,r.length++),r};function M(t,i,r){return (new v).mulp(t,i,r)}function v(t,r){(this||i$3).x=t,(this||i$3).y=r;}Math.imul||(p=d),o.prototype.mulTo=function(t,r){var h=(this||i$3).length+t.length;return 10===(this||i$3).length&&10===t.length?p(this||i$3,t,r):h<63?d(this||i$3,t,r):h<1024?function(t,i,r){r.negative=i.negative^t.negative,r.length=t.length+i.length;for(var h=0,n=0,e=0;e>>26)|0)>>>26,o&=67108863;}r.words[e]=s,h=o,o=n;}return 0!==h?r.words[e]=h:r.length--,r.strip()}(this||i$3,t,r):M(this||i$3,t,r)},v.prototype.makeRBT=function(t){for(var i=new Array(t),r=o.prototype._countBits(t)-1,h=0;h>=1;return h},v.prototype.permute=function(t,i,r,h,n,e){for(var o=0;o>>=1)n++;return 1<>>=13,r[2*o+1]=8191&e,e>>>=13;for(o=2*i;o>=26,r+=e/67108864|0,r+=o>>>26,(this||i$3).words[h]=67108863&o;}return 0!==r&&((this||i$3).words[h]=r,(this||i$3).length++),this||i$3},o.prototype.muln=function(t){return this.clone().imuln(t)},o.prototype.sqr=function(){return this.mul(this||i$3)},o.prototype.isqr=function(){return this.imul(this.clone())},o.prototype.pow=function(t){var r=function(t){for(var i=new Array(t.bitLength()),r=0;r>>n;}return i}(t);if(0===r.length)return new o(1);for(var h=this||i$3,n=0;n=0);var r,h=t%26,e=(t-h)/26,o=67108863>>>26-h<<26-h;if(0!==h){var s=0;for(r=0;r<(this||i$3).length;r++){var u=(this||i$3).words[r]&o,a=(0|(this||i$3).words[r])-u<>>26-h;}s&&((this||i$3).words[r]=s,(this||i$3).length++);}if(0!==e){for(r=(this||i$3).length-1;r>=0;r--)(this||i$3).words[r+e]=(this||i$3).words[r];for(r=0;r=0),e=r?(r-r%26)/26:0;var o=t%26,s=Math.min((t-o)/26,(this||i$3).length),u=67108863^67108863>>>o<s)for((this||i$3).length-=s,l=0;l<(this||i$3).length;l++)(this||i$3).words[l]=(this||i$3).words[l+s];else (this||i$3).words[0]=0,(this||i$3).length=1;var m=0;for(l=(this||i$3).length-1;l>=0&&(0!==m||l>=e);l--){var f=0|(this||i$3).words[l];(this||i$3).words[l]=m<<26-o|f>>>o,m=f&u;}return a&&0!==m&&(a.words[a.length++]=m),0===(this||i$3).length&&((this||i$3).words[0]=0,(this||i$3).length=1),this.strip()},o.prototype.ishrn=function(t,r,h){return n(0===(this||i$3).negative),this.iushrn(t,r,h)},o.prototype.shln=function(t){return this.clone().ishln(t)},o.prototype.ushln=function(t){return this.clone().iushln(t)},o.prototype.shrn=function(t){return this.clone().ishrn(t)},o.prototype.ushrn=function(t){return this.clone().iushrn(t)},o.prototype.testn=function(t){n("number"==typeof t&&t>=0);var r=t%26,h=(t-r)/26,e=1<=0);var r=t%26,h=(t-r)/26;if(n(0===(this||i$3).negative,"imaskn works only with positive numbers"),(this||i$3).length<=h)return this||i$3;if(0!==r&&h++,(this||i$3).length=Math.min(h,(this||i$3).length),0!==r){var e=67108863^67108863>>>r<=67108864;r++)(this||i$3).words[r]-=67108864,r===(this||i$3).length-1?(this||i$3).words[r+1]=1:(this||i$3).words[r+1]++;return (this||i$3).length=Math.max((this||i$3).length,r+1),this||i$3},o.prototype.isubn=function(t){if(n("number"==typeof t),n(t<67108864),t<0)return this.iaddn(-t);if(0!==(this||i$3).negative)return (this||i$3).negative=0,this.iaddn(t),(this||i$3).negative=1,this||i$3;if((this||i$3).words[0]-=t,1===(this||i$3).length&&(this||i$3).words[0]<0)(this||i$3).words[0]=-(this||i$3).words[0],(this||i$3).negative=1;else for(var r=0;r<(this||i$3).length&&(this||i$3).words[r]<0;r++)(this||i$3).words[r]+=67108864,(this||i$3).words[r+1]-=1;return this.strip()},o.prototype.addn=function(t){return this.clone().iaddn(t)},o.prototype.subn=function(t){return this.clone().isubn(t)},o.prototype.iabs=function(){return (this||i$3).negative=0,this||i$3},o.prototype.abs=function(){return this.clone().iabs()},o.prototype._ishlnsubmul=function(t,r,h){var e,o,s=t.length+h;this._expand(s);var u=0;for(e=0;e>26)-(a/67108864|0),(this||i$3).words[e+h]=67108863&o;}for(;e<(this||i$3).length-h;e++)u=(o=(0|(this||i$3).words[e+h])+u)>>26,(this||i$3).words[e+h]=67108863&o;if(0===u)return this.strip();for(n(-1===u),u=0,e=0;e<(this||i$3).length;e++)u=(o=-(0|(this||i$3).words[e])+u)>>26,(this||i$3).words[e]=67108863&o;return (this||i$3).negative=1,this.strip()},o.prototype._wordDiv=function(t,r){var h=((this||i$3).length,t.length),n=this.clone(),e=t,s=0|e.words[e.length-1];0!==(h=26-this._countBits(s))&&(e=e.ushln(h),n.iushln(h),s=0|e.words[e.length-1]);var u,a=n.length-e.length;if("mod"!==r){(u=new o(null)).length=a+1,u.words=new Array(u.length);for(var l=0;l=0;f--){var d=67108864*(0|n.words[e.length+f])+(0|n.words[e.length+f-1]);for(d=Math.min(d/s|0,67108863),n._ishlnsubmul(e,d,f);0!==n.negative;)d--,n.negative=0,n._ishlnsubmul(e,1,f),n.isZero()||(n.negative^=1);u&&(u.words[f]=d);}return u&&u.strip(),n.strip(),"div"!==r&&0!==h&&n.iushrn(h),{div:u||null,mod:n}},o.prototype.divmod=function(t,r,h){return n(!t.isZero()),this.isZero()?{div:new o(0),mod:new o(0)}:0!==(this||i$3).negative&&0===t.negative?(u=this.neg().divmod(t,r),"mod"!==r&&(e=u.div.neg()),"div"!==r&&(s=u.mod.neg(),h&&0!==s.negative&&s.iadd(t)),{div:e,mod:s}):0===(this||i$3).negative&&0!==t.negative?(u=this.divmod(t.neg(),r),"mod"!==r&&(e=u.div.neg()),{div:e,mod:u.mod}):0!=((this||i$3).negative&t.negative)?(u=this.neg().divmod(t.neg(),r),"div"!==r&&(s=u.mod.neg(),h&&0!==s.negative&&s.isub(t)),{div:u.div,mod:s}):t.length>(this||i$3).length||this.cmp(t)<0?{div:new o(0),mod:this||i$3}:1===t.length?"div"===r?{div:this.divn(t.words[0]),mod:null}:"mod"===r?{div:null,mod:new o(this.modn(t.words[0]))}:{div:this.divn(t.words[0]),mod:new o(this.modn(t.words[0]))}:this._wordDiv(t,r);var e,s,u;},o.prototype.div=function(t){return this.divmod(t,"div",!1).div},o.prototype.mod=function(t){return this.divmod(t,"mod",!1).mod},o.prototype.umod=function(t){return this.divmod(t,"mod",!0).mod},o.prototype.divRound=function(t){var i=this.divmod(t);if(i.mod.isZero())return i.div;var r=0!==i.div.negative?i.mod.isub(t):i.mod,h=t.ushrn(1),n=t.andln(1),e=r.cmp(h);return e<0||1===n&&0===e?i.div:0!==i.div.negative?i.div.isubn(1):i.div.iaddn(1)},o.prototype.modn=function(t){n(t<=67108863);for(var r=(1<<26)%t,h=0,e=(this||i$3).length-1;e>=0;e--)h=(r*h+(0|(this||i$3).words[e]))%t;return h},o.prototype.idivn=function(t){n(t<=67108863);for(var r=0,h=(this||i$3).length-1;h>=0;h--){var e=(0|(this||i$3).words[h])+67108864*r;(this||i$3).words[h]=e/t|0,r=e%t;}return this.strip()},o.prototype.divn=function(t){return this.clone().idivn(t)},o.prototype.egcd=function(t){n(0===t.negative),n(!t.isZero());var r=this||i$3,h=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var e=new o(1),s=new o(0),u=new o(0),a=new o(1),l=0;r.isEven()&&h.isEven();)r.iushrn(1),h.iushrn(1),++l;for(var m=h.clone(),f=r.clone();!r.isZero();){for(var d=0,p=1;0==(r.words[0]&p)&&d<26;++d,p<<=1);if(d>0)for(r.iushrn(d);d-- >0;)(e.isOdd()||s.isOdd())&&(e.iadd(m),s.isub(f)),e.iushrn(1),s.iushrn(1);for(var M=0,v=1;0==(h.words[0]&v)&&M<26;++M,v<<=1);if(M>0)for(h.iushrn(M);M-- >0;)(u.isOdd()||a.isOdd())&&(u.iadd(m),a.isub(f)),u.iushrn(1),a.iushrn(1);r.cmp(h)>=0?(r.isub(h),e.isub(u),s.isub(a)):(h.isub(r),u.isub(e),a.isub(s));}return {a:u,b:a,gcd:h.iushln(l)}},o.prototype._invmp=function(t){n(0===t.negative),n(!t.isZero());var r=this||i$3,h=t.clone();r=0!==r.negative?r.umod(t):r.clone();for(var e,s=new o(1),u=new o(0),a=h.clone();r.cmpn(1)>0&&h.cmpn(1)>0;){for(var l=0,m=1;0==(r.words[0]&m)&&l<26;++l,m<<=1);if(l>0)for(r.iushrn(l);l-- >0;)s.isOdd()&&s.iadd(a),s.iushrn(1);for(var f=0,d=1;0==(h.words[0]&d)&&f<26;++f,d<<=1);if(f>0)for(h.iushrn(f);f-- >0;)u.isOdd()&&u.iadd(a),u.iushrn(1);r.cmp(h)>=0?(r.isub(h),s.isub(u)):(h.isub(r),u.isub(s));}return (e=0===r.cmpn(1)?s:u).cmpn(0)<0&&e.iadd(t),e},o.prototype.gcd=function(t){if(this.isZero())return t.abs();if(t.isZero())return this.abs();var i=this.clone(),r=t.clone();i.negative=0,r.negative=0;for(var h=0;i.isEven()&&r.isEven();h++)i.iushrn(1),r.iushrn(1);for(;;){for(;i.isEven();)i.iushrn(1);for(;r.isEven();)r.iushrn(1);var n=i.cmp(r);if(n<0){var e=i;i=r,r=e;}else if(0===n||0===r.cmpn(1))break;i.isub(r);}return r.iushln(h)},o.prototype.invm=function(t){return this.egcd(t).a.umod(t)},o.prototype.isEven=function(){return 0==(1&(this||i$3).words[0])},o.prototype.isOdd=function(){return 1==(1&(this||i$3).words[0])},o.prototype.andln=function(t){return (this||i$3).words[0]&t},o.prototype.bincn=function(t){n("number"==typeof t);var r=t%26,h=(t-r)/26,e=1<>>26,u&=67108863,(this||i$3).words[s]=u;}return 0!==o&&((this||i$3).words[s]=o,(this||i$3).length++),this||i$3},o.prototype.isZero=function(){return 1===(this||i$3).length&&0===(this||i$3).words[0]},o.prototype.cmpn=function(t){var r,h=t<0;if(0!==(this||i$3).negative&&!h)return -1;if(0===(this||i$3).negative&&h)return 1;if(this.strip(),(this||i$3).length>1)r=1;else {h&&(t=-t),n(t<=67108863,"Number is too big");var e=0|(this||i$3).words[0];r=e===t?0:et.length)return 1;if((this||i$3).length=0;h--){var n=0|(this||i$3).words[h],e=0|t.words[h];if(n!==e){ne&&(r=1);break}}return r},o.prototype.gtn=function(t){return 1===this.cmpn(t)},o.prototype.gt=function(t){return 1===this.cmp(t)},o.prototype.gten=function(t){return this.cmpn(t)>=0},o.prototype.gte=function(t){return this.cmp(t)>=0},o.prototype.ltn=function(t){return -1===this.cmpn(t)},o.prototype.lt=function(t){return -1===this.cmp(t)},o.prototype.lten=function(t){return this.cmpn(t)<=0},o.prototype.lte=function(t){return this.cmp(t)<=0},o.prototype.eqn=function(t){return 0===this.cmpn(t)},o.prototype.eq=function(t){return 0===this.cmp(t)},o.red=function(t){return new k(t)},o.prototype.toRed=function(t){return n(!(this||i$3).red,"Already a number in reduction context"),n(0===(this||i$3).negative,"red works only with positives"),t.convertTo(this||i$3)._forceRed(t)},o.prototype.fromRed=function(){return n((this||i$3).red,"fromRed works only with numbers in reduction context"),(this||i$3).red.convertFrom(this||i$3)},o.prototype._forceRed=function(t){return (this||i$3).red=t,this||i$3},o.prototype.forceRed=function(t){return n(!(this||i$3).red,"Already a number in reduction context"),this._forceRed(t)},o.prototype.redAdd=function(t){return n((this||i$3).red,"redAdd works only with red numbers"),(this||i$3).red.add(this||i$3,t)},o.prototype.redIAdd=function(t){return n((this||i$3).red,"redIAdd works only with red numbers"),(this||i$3).red.iadd(this||i$3,t)},o.prototype.redSub=function(t){return n((this||i$3).red,"redSub works only with red numbers"),(this||i$3).red.sub(this||i$3,t)},o.prototype.redISub=function(t){return n((this||i$3).red,"redISub works only with red numbers"),(this||i$3).red.isub(this||i$3,t)},o.prototype.redShl=function(t){return n((this||i$3).red,"redShl works only with red numbers"),(this||i$3).red.shl(this||i$3,t)},o.prototype.redMul=function(t){return n((this||i$3).red,"redMul works only with red numbers"),(this||i$3).red._verify2(this||i$3,t),(this||i$3).red.mul(this||i$3,t)},o.prototype.redIMul=function(t){return n((this||i$3).red,"redMul works only with red numbers"),(this||i$3).red._verify2(this||i$3,t),(this||i$3).red.imul(this||i$3,t)},o.prototype.redSqr=function(){return n((this||i$3).red,"redSqr works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.sqr(this||i$3)},o.prototype.redISqr=function(){return n((this||i$3).red,"redISqr works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.isqr(this||i$3)},o.prototype.redSqrt=function(){return n((this||i$3).red,"redSqrt works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.sqrt(this||i$3)},o.prototype.redInvm=function(){return n((this||i$3).red,"redInvm works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.invm(this||i$3)},o.prototype.redNeg=function(){return n((this||i$3).red,"redNeg works only with red numbers"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.neg(this||i$3)},o.prototype.redPow=function(t){return n((this||i$3).red&&!t.red,"redPow(normalNum)"),(this||i$3).red._verify1(this||i$3),(this||i$3).red.pow(this||i$3,t)};var g={k256:null,p224:null,p192:null,p25519:null};function c(t,r){(this||i$3).name=t,(this||i$3).p=new o(r,16),(this||i$3).n=(this||i$3).p.bitLength(),(this||i$3).k=new o(1).iushln((this||i$3).n).isub((this||i$3).p),(this||i$3).tmp=this._tmp();}function w(){c.call(this||i$3,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f");}function y(){c.call(this||i$3,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001");}function b(){c.call(this||i$3,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff");}function _(){c.call(this||i$3,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed");}function k(t){if("string"==typeof t){var r=o._prime(t);(this||i$3).m=r.p,(this||i$3).prime=r;}else n(t.gtn(1),"modulus must be greater than 1"),(this||i$3).m=t,(this||i$3).prime=null;}function A(t){k.call(this||i$3,t),(this||i$3).shift=(this||i$3).m.bitLength(),(this||i$3).shift%26!=0&&((this||i$3).shift+=26-(this||i$3).shift%26),(this||i$3).r=new o(1).iushln((this||i$3).shift),(this||i$3).r2=this.imod((this||i$3).r.sqr()),(this||i$3).rinv=(this||i$3).r._invmp((this||i$3).m),(this||i$3).minv=(this||i$3).rinv.mul((this||i$3).r).isubn(1).div((this||i$3).m),(this||i$3).minv=(this||i$3).minv.umod((this||i$3).r),(this||i$3).minv=(this||i$3).r.sub((this||i$3).minv);}c.prototype._tmp=function(){var t=new o(null);return t.words=new Array(Math.ceil((this||i$3).n/13)),t},c.prototype.ireduce=function(t){var r,h=t;do{this.split(h,(this||i$3).tmp),r=(h=(h=this.imulK(h)).iadd((this||i$3).tmp)).bitLength();}while(r>(this||i$3).n);var n=r<(this||i$3).n?-1:h.ucmp((this||i$3).p);return 0===n?(h.words[0]=0,h.length=1):n>0?h.isub((this||i$3).p):h.strip(),h},c.prototype.split=function(t,r){t.iushrn((this||i$3).n,0,r);},c.prototype.imulK=function(t){return t.imul((this||i$3).k)},e(w,c),w.prototype.split=function(t,i){for(var r=Math.min(t.length,9),h=0;h>>22,n=e;}n>>>=22,t.words[h-10]=n,0===n&&t.length>10?t.length-=10:t.length-=9;},w.prototype.imulK=function(t){t.words[t.length]=0,t.words[t.length+1]=0,t.length+=2;for(var i=0,r=0;r>>=26,t.words[r]=n,i=h;}return 0!==i&&(t.words[t.length++]=i),t},o._prime=function(t){if(g[t])return g[t];var i;if("k256"===t)i=new w;else if("p224"===t)i=new y;else if("p192"===t)i=new b;else {if("p25519"!==t)throw new Error("Unknown prime "+t);i=new _;}return g[t]=i,i},k.prototype._verify1=function(t){n(0===t.negative,"red works only with positives"),n(t.red,"red works only with red numbers");},k.prototype._verify2=function(t,i){n(0==(t.negative|i.negative),"red works only with positives"),n(t.red&&t.red===i.red,"red works only with red numbers");},k.prototype.imod=function(t){return (this||i$3).prime?(this||i$3).prime.ireduce(t)._forceRed(this||i$3):t.umod((this||i$3).m)._forceRed(this||i$3)},k.prototype.neg=function(t){return t.isZero()?t.clone():(this||i$3).m.sub(t)._forceRed(this||i$3)},k.prototype.add=function(t,r){this._verify2(t,r);var h=t.add(r);return h.cmp((this||i$3).m)>=0&&h.isub((this||i$3).m),h._forceRed(this||i$3)},k.prototype.iadd=function(t,r){this._verify2(t,r);var h=t.iadd(r);return h.cmp((this||i$3).m)>=0&&h.isub((this||i$3).m),h},k.prototype.sub=function(t,r){this._verify2(t,r);var h=t.sub(r);return h.cmpn(0)<0&&h.iadd((this||i$3).m),h._forceRed(this||i$3)},k.prototype.isub=function(t,r){this._verify2(t,r);var h=t.isub(r);return h.cmpn(0)<0&&h.iadd((this||i$3).m),h},k.prototype.shl=function(t,i){return this._verify1(t),this.imod(t.ushln(i))},k.prototype.imul=function(t,i){return this._verify2(t,i),this.imod(t.imul(i))},k.prototype.mul=function(t,i){return this._verify2(t,i),this.imod(t.mul(i))},k.prototype.isqr=function(t){return this.imul(t,t.clone())},k.prototype.sqr=function(t){return this.mul(t,t)},k.prototype.sqrt=function(t){if(t.isZero())return t.clone();var r=(this||i$3).m.andln(3);if(n(r%2==1),3===r){var h=(this||i$3).m.add(new o(1)).iushrn(2);return this.pow(t,h)}for(var e=(this||i$3).m.subn(1),s=0;!e.isZero()&&0===e.andln(1);)s++,e.iushrn(1);n(!e.isZero());var u=new o(1).toRed(this||i$3),a=u.redNeg(),l=(this||i$3).m.subn(1).iushrn(1),m=(this||i$3).m.bitLength();for(m=new o(2*m*m).toRed(this||i$3);0!==this.pow(m,l).cmp(a);)m.redIAdd(a);for(var f=this.pow(m,e),d=this.pow(t,e.addn(1).iushrn(1)),p=this.pow(t,e),M=s;0!==p.cmp(u);){for(var v=p,g=0;0!==v.cmp(u);g++)v=v.redSqr();n(g=0;n--){for(var l=r.words[n],m=a-1;m>=0;m--){var f=l>>m&1;e!==h[0]&&(e=this.sqr(e)),0!==f||0!==s?(s<<=1,s|=f,(4===++u||0===n&&0===m)&&(e=this.mul(e,h[s]),u=0,s=0)):u=0;}a=26;}return e},k.prototype.convertTo=function(t){var r=t.umod((this||i$3).m);return r===t?r.clone():r},k.prototype.convertFrom=function(t){var i=t.clone();return i.red=null,i},o.mont=function(t){return new A(t)},e(A,k),A.prototype.convertTo=function(t){return this.imod(t.ushln((this||i$3).shift))},A.prototype.convertFrom=function(t){var r=this.imod(t.mul((this||i$3).rinv));return r.red=null,r},A.prototype.imul=function(t,r){if(t.isZero()||r.isZero())return t.words[0]=0,t.length=1,t;var h=t.imul(r),n=h.maskn((this||i$3).shift).mul((this||i$3).minv).imaskn((this||i$3).shift).mul((this||i$3).m),e=h.isub(n).iushrn((this||i$3).shift),o=e;return e.cmp((this||i$3).m)>=0?o=e.isub((this||i$3).m):e.cmpn(0)<0&&(o=e.iadd((this||i$3).m)),o._forceRed(this||i$3)},A.prototype.mul=function(t,r){if(t.isZero()||r.isZero())return new o(0)._forceRed(this||i$3);var h=t.mul(r),n=h.maskn((this||i$3).shift).mul((this||i$3).minv).imaskn((this||i$3).shift).mul((this||i$3).m),e=h.isub(n).iushrn((this||i$3).shift),s=e;return e.cmp((this||i$3).m)>=0?s=e.isub((this||i$3).m):e.cmpn(0)<0&&(s=e.iadd((this||i$3).m)),s._forceRed(this||i$3)},A.prototype.invm=function(t){return this.imod(t._invmp((this||i$3).m).mul((this||i$3).r2))._forceRed(this||i$3)};}(h$a,r$7);var n$c=h$a.exports;var t$5,e$a,r$8=Object.freeze({}),n$d="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function o$d(t){(this||n$d).rand=t;}if((t$5=function(t){return e$a||(e$a=new o$d(null)),e$a.generate(t)}).Rand=o$d,o$d.prototype.generate=function(t){return this._rand(t)},o$d.prototype._rand=function(t){if((this||n$d).rand.getBytes)return (this||n$d).rand.getBytes(t);for(var e=new Uint8Array(t),r=0;r=0);return a},d$b.prototype._randrange=function(r,e){var n=e.sub(r);return r.add(this._randbelow(n))},d$b.prototype.test=function(r,e,n){var t=r.bitLength(),a=o$e.mont(r),d=new o$e(1).toRed(a);e||(e=Math.max(1,t/48|0));for(var i=r.subn(1),f=0;!i.testn(f);f++);for(var u=r.shrn(f),p=i.toRed(a);e>0;e--){var c=this._randrange(new o$e(2),i);n&&n(c);var s=c.toRed(a).redPow(u);if(0!==s.cmp(d)&&0!==s.cmp(p)){for(var m=1;m0;e--){var p=this._randrange(new o$e(2),d),c=r.gcd(p);if(0!==c.cmpn(1))return c;var s=p.toRed(t).redPow(f);if(0!==s.cmp(a)&&0!==s.cmp(u)){for(var m=1;mf;)c.ishrn(1);if(c.isEven()&&c.iadd(i$5),c.testn(1)||c.iadd(o$f),e.cmp(o$f)){if(!e.cmp(p$e))for(;c.mod(s$c).cmp(m$9);)c.iadd(h$b);}else for(;c.mod(t$7).cmp(u$b);)c.iadd(h$b);if(_$9(a=c.shrn(1))&&_$9(c)&&g$8(a)&&g$8(c)&&n$f.test(a)&&n$f.test(c))return c}}var y$9,P$2=b$7,B$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,K$2=e$1$1$1.Buffer,R$1=n$c,S$5=new i$4,x$2=new R$1(24),C$2=new R$1(11),D$2=new R$1(10),G$1=new R$1(3),H$2=new R$1(7),T$3=P$2,j$1=a;function E$6(f,e){return e=e||"utf8",K$2.isBuffer(f)||(f=new K$2(f,e)),(this||B$5)._pub=new R$1(f),this||B$5}function L$1(f,e){return e=e||"utf8",K$2.isBuffer(f)||(f=new K$2(f,e)),(this||B$5)._priv=new R$1(f),this||B$5}y$9=k$7;var M$4={};function k$7(f,e,c){this.setGenerator(e),(this||B$5).__prime=new R$1(f),(this||B$5)._prime=R$1.mont((this||B$5).__prime),(this||B$5)._primeLen=f.length,(this||B$5)._pub=void 0,(this||B$5)._priv=void 0,(this||B$5)._primeCode=void 0,c?((this||B$5).setPublicKey=E$6,(this||B$5).setPrivateKey=L$1):(this||B$5)._primeCode=8;}function A$5(f,e){var c=new K$2(f.toArray());return e?c.toString(e):c}Object.defineProperty(k$7.prototype,"verifyError",{enumerable:!0,get:function(){return "number"!=typeof(this||B$5)._primeCode&&((this||B$5)._primeCode=function(f,e){var c=e.toString("hex"),a=[c,f.toString(16)].join("_");if(a in M$4)return M$4[a];var b,d=0;if(f.isEven()||!T$3.simpleSieve||!T$3.fermatTest(f)||!S$5.test(f))return d+=1,d+="02"===c||"05"===c?8:4,M$4[a]=d,d;switch(S$5.test(f.shrn(1))||(d+=2),c){case"02":f.mod(x$2).cmp(C$2)&&(d+=8);break;case"05":(b=f.mod(D$2)).cmp(G$1)&&b.cmp(H$2)&&(d+=8);break;default:d+=4;}return M$4[a]=d,d}((this||B$5).__prime,(this||B$5).__gen)),(this||B$5)._primeCode}}),k$7.prototype.generateKeys=function(){return (this||B$5)._priv||((this||B$5)._priv=new R$1(j$1((this||B$5)._primeLen))),(this||B$5)._pub=(this||B$5)._gen.toRed((this||B$5)._prime).redPow((this||B$5)._priv).fromRed(),this.getPublicKey()},k$7.prototype.computeSecret=function(f){var e=(f=(f=new R$1(f)).toRed((this||B$5)._prime)).redPow((this||B$5)._priv).fromRed(),c=new K$2(e.toArray()),a=this.getPrime();if(c.length=0||!r.umod(e.prime1)||!r.umod(e.prime2);)r=new n$g(d$d(o));return r}m$a=t$8,t$8.getr=i$6;var l$d=m$a;var r$a={},e$b=r$a;function t$9(r){return 1===r.length?"0"+r:r}function n$h(r){for(var e="",n=0;n>8,f=255&o;u?t.push(u,f):t.push(f);}return t},e$b.zero2=t$9,e$b.toHex=n$h,e$b.encode=function(r,e){return "hex"===e?n$h(r):r};var n$i={},a$g=n$i,i$7=n$c,o$g=o$7,c$d=r$a;a$g.assert=o$g,a$g.toArray=c$d.toArray,a$g.zero2=c$d.zero2,a$g.toHex=c$d.toHex,a$g.encode=c$d.encode,a$g.getNAF=function(r,t,e){var n=new Array(Math.max(r.bitLength(),e)+1);n.fill(0);for(var a=1<(a>>1)-1?(a>>1)-s:s,i.isubn(c)):c=0,n[o]=c,i.iushrn(1);}return n},a$g.getJSF=function(r,t){var e=[[],[]];r=r.clone(),t=t.clone();for(var n=0,a=0;r.cmpn(-n)>0||t.cmpn(-a)>0;){var i,o,c,s=r.andln(3)+n&3,l=t.andln(3)+a&3;if(3===s&&(s=-1),3===l&&(l=-1),0==(1&s))i=0;else i=3!==(c=r.andln(7)+n&7)&&5!==c||2!==l?s:-s;if(e[0].push(i),0==(1&l))o=0;else o=3!==(c=t.andln(7)+a&7)&&5!==c||2!==s?l:-l;e[1].push(o),2*n===i+1&&(n=1-n),2*a===o+1&&(a=1-a),r.iushrn(1),t.iushrn(1);}return e},a$g.cachedProperty=function(r,t,e){var n="_"+t;r.prototype[t]=function(){return void 0!==this[n]?this[n]:this[n]=e.call(this)};},a$g.parseBytes=function(r){return "string"==typeof r?a$g.toArray(r,"hex"):r},a$g.intFromLE=function(r){return new i$7(r,"hex","le")};var s$d,l$e=n$c,u$d=n$i,h$c=u$d.assert;function p$f(r,t){if(r instanceof p$f)return r;this._importDER(r,t)||(h$c(r.r&&r.s,"Signature without r or s"),this.r=new l$e(r.r,16),this.s=new l$e(r.s,16),void 0===r.recoveryParam?this.recoveryParam=null:this.recoveryParam=r.recoveryParam);}function f$j(){this.place=0;}function v$a(r,t){var e=r[t.place++];if(!(128&e))return e;for(var n=15&e,a=0,i=0,o=t.place;i>>3);for(r.push(128|e);--e;)r.push(t>>>(e<<3)&255);r.push(t);}s$d=p$f,p$f.prototype._importDER=function(r,t){r=u$d.toArray(r,t);var e=new f$j;if(48!==r[e.place++])return !1;if(v$a(r,e)+e.place!==r.length)return !1;if(2!==r[e.place++])return !1;var n=v$a(r,e),a=r.slice(e.place,n+e.place);if(e.place+=n,2!==r[e.place++])return !1;var i=v$a(r,e);if(r.length!==i+e.place)return !1;var o=r.slice(e.place,i+e.place);return 0===a[0]&&128&a[1]&&(a=a.slice(1)),0===o[0]&&128&o[1]&&(o=o.slice(1)),this.r=new l$e(a),this.s=new l$e(o),this.recoveryParam=null,!0},p$f.prototype.toDER=function(r){var t=this.r.toArray(),e=this.s.toArray();for(128&t[0]&&(t=[0].concat(t)),128&e[0]&&(e=[0].concat(e)),t=m$b(t),e=m$b(e);!(e[0]||128&e[1]);)e=e.slice(1);var n=[2];y$a(n,t.length),(n=n.concat(t)).push(2),y$a(n,e.length);var a=n.concat(e),i=[48];return y$a(i,a.length),i=i.concat(a),u$d.encode(i,r)};var d$e=s$d;var r$b={},i$8=o$7,e$c=t$2$2;function h$d(t,n){return 55296==(64512&t.charCodeAt(n))&&(!(n<0||n+1>=t.length)&&56320==(64512&t.charCodeAt(n+1)))}function o$h(t){return (t>>>24|t>>>8&65280|t<<8&16711680|(255&t)<<24)>>>0}function u$e(t){return 1===t.length?"0"+t:t}function s$e(t){return 7===t.length?"0"+t:6===t.length?"00"+t:5===t.length?"000"+t:4===t.length?"0000"+t:3===t.length?"00000"+t:2===t.length?"000000"+t:1===t.length?"0000000"+t:t}r$b.inherits=e$c,r$b.toArray=function(t,n){if(Array.isArray(t))return t.slice();if(!t)return [];var r=[];if("string"==typeof t)if(n){if("hex"===n)for((t=t.replace(/[^a-z0-9]+/gi,"")).length%2!=0&&(t="0"+t),e=0;e>6|192,r[i++]=63&o|128):h$d(t,e)?(o=65536+((1023&o)<<10)+(1023&t.charCodeAt(++e)),r[i++]=o>>18|240,r[i++]=o>>12&63|128,r[i++]=o>>6&63|128,r[i++]=63&o|128):(r[i++]=o>>12|224,r[i++]=o>>6&63|128,r[i++]=63&o|128);}else for(e=0;e>>0;}return o},r$b.split32=function(t,n){for(var r=new Array(4*t.length),i=0,e=0;i>>24,r[e+1]=h>>>16&255,r[e+2]=h>>>8&255,r[e+3]=255&h):(r[e+3]=h>>>24,r[e+2]=h>>>16&255,r[e+1]=h>>>8&255,r[e]=255&h);}return r},r$b.rotr32=function(t,n){return t>>>n|t<<32-n},r$b.rotl32=function(t,n){return t<>>32-n},r$b.sum32=function(t,n){return t+n>>>0},r$b.sum32_3=function(t,n,r){return t+n+r>>>0},r$b.sum32_4=function(t,n,r,i){return t+n+r+i>>>0},r$b.sum32_5=function(t,n,r,i,e){return t+n+r+i+e>>>0},r$b.sum64=function(t,n,r,i){var e=t[n],h=i+t[n+1]>>>0,o=(h>>0,t[n+1]=h;},r$b.sum64_hi=function(t,n,r,i){return (n+i>>>0>>0},r$b.sum64_lo=function(t,n,r,i){return n+i>>>0},r$b.sum64_4_hi=function(t,n,r,i,e,h,o,u){var s=0,a=n;return s+=(a=a+i>>>0)>>0)>>0)>>0},r$b.sum64_4_lo=function(t,n,r,i,e,h,o,u){return n+i+h+u>>>0},r$b.sum64_5_hi=function(t,n,r,i,e,h,o,u,s,a){var l=0,g=n;return l+=(g=g+i>>>0)>>0)>>0)>>0)>>0},r$b.sum64_5_lo=function(t,n,r,i,e,h,o,u,s,a){return n+i+h+u+a>>>0},r$b.rotr64_hi=function(t,n,r){return (n<<32-r|t>>>r)>>>0},r$b.rotr64_lo=function(t,n,r){return (t<<32-r|n>>>r)>>>0},r$b.shr64_hi=function(t,n,r){return t>>>r},r$b.shr64_lo=function(t,n,r){return (t<<32-r|n>>>r)>>>0};var a$h={},l$f=r$b,g$9=o$7;function c$e(){this.pending=null,this.pendingTotal=0,this.blockSize=this.constructor.blockSize,this.outSize=this.constructor.outSize,this.hmacStrength=this.constructor.hmacStrength,this.padLength=this.constructor.padLength/8,this.endian="big",this._delta8=this.blockSize/8,this._delta32=this.blockSize/32;}a$h.BlockHash=c$e,c$e.prototype.update=function(t,n){if(t=l$f.toArray(t,n),this.pending?this.pending=this.pending.concat(t):this.pending=t,this.pendingTotal+=t.length,this.pending.length>=this._delta8){var r=(t=this.pending).length%this._delta8;this.pending=t.slice(t.length-r,t.length),0===this.pending.length&&(this.pending=null),t=l$f.join32(t,0,t.length-r,this.endian);for(var i=0;i>>24&255,i[e++]=t>>>16&255,i[e++]=t>>>8&255,i[e++]=255&t;}else for(i[e++]=255&t,i[e++]=t>>>8&255,i[e++]=t>>>16&255,i[e++]=t>>>24&255,i[e++]=0,i[e++]=0,i[e++]=0,i[e++]=0,h=8;h>>3},s$g.g1_256=function(t){return n$k(t,17)^n$k(t,19)^t>>>10};var u$g,a$j=r$b,c$g=a$h,f$l=s$g,_$b=o$7,g$b=a$j.sum32,m$d=a$j.sum32_4,p$h=a$j.sum32_5,l$h=f$l.ch32,v$c=f$l.maj32,d$g=f$l.s0_256,k$9=f$l.s1_256,b$9=f$l.g0_256,j$3=f$l.g1_256,x$4=c$g.BlockHash,y$c=[1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298];function S$7(){if(!(this instanceof S$7))return new S$7;x$4.call(this),this.h=[1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225],this.k=y$c,this.W=new Array(64);}a$j.inherits(S$7,x$4),u$g=S$7,S$7.blockSize=512,S$7.outSize=256,S$7.hmacStrength=192,S$7.padLength=64,S$7.prototype._update=function(t,h){for(var i=this.W,s=0;s<16;s++)i[s]=t[h+s];for(;sthis.blockSize&&(t=(new this.Hash).update(t).digest()),T$4(t.length<=this.blockSize);for(var h=t.length;h=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._init(e,i,s);}s$h=o$l,o$l.prototype._init=function(t,e,i){var s=t.concat(e).concat(i);this.K=new Array(this.outLen/8),this.V=new Array(this.outLen/8);for(var h=0;h=this.minEntropy/8,"Not enough entropy. Minimum is: "+this.minEntropy+" bits"),this._update(t.concat(i||[])),this._reseed=1;},o$l.prototype.generate=function(t,e,i,s){if(this._reseed>this.reseedInterval)throw new Error("Reseed is required");"string"!=typeof e&&(s=i,i=e,e=null),i&&(i=r$f.toArray(i,s||"hex"),this._update(i));for(var h=[];h.length0?this.redN=null:(this._maxwellTrick=!0,this.redN=this.n.toRed(this.red));}function p$j(e,f){this.curve=e,this.type=f,this.precomputed=null;}b$b=h$f,h$f.prototype.point=function(){throw new Error("Not implemented")},h$f.prototype.validate=function(){throw new Error("Not implemented")},h$f.prototype._fixedNafMul=function(e,f){u$i(e.precomputed);var d=e._getDoubles(),c=s$i(f,1,this._bitLength),t=(1<=r;f--)b=(b<<1)+c[f];a.push(b);}for(var i=this.jpoint(null,null,null),n=this.jpoint(null,null,null),o=t;o>0;o--){for(r=0;r=0;b--){for(f=0;b>=0&&0===a[b];b--)f++;if(b>=0&&f++,r=r.dblp(f),b<0)break;var i=a[b];u$i(0!==i),r="affine"===e.type?i>0?r.mixedAdd(t[i-1>>1]):r.mixedAdd(t[-i-1>>1].neg()):i>0?r.add(t[i-1>>1]):r.add(t[-i-1>>1].neg());}return "affine"===e.type?r.toP():r},h$f.prototype._wnafMulAdd=function(e,f,d,c,t){for(var a=this._wnafT1,r=this._wnafT2,b=this._wnafT3,i=0,n=0;n=1;n-=2){var h=n-1,p=n;if(1===a[h]&&1===a[p]){var l=[f[h],null,null,f[p]];0===f[h].y.cmp(f[p].y)?(l[1]=f[h].add(f[p]),l[2]=f[h].toJ().mixedAdd(f[p].neg())):0===f[h].y.cmp(f[p].y.redNeg())?(l[1]=f[h].toJ().mixedAdd(f[p]),l[2]=f[h].add(f[p].neg())):(l[1]=f[h].toJ().mixedAdd(f[p]),l[2]=f[h].toJ().mixedAdd(f[p].neg()));var v=[-3,-1,-5,-7,0,7,5,1,3],y=o$m(d[h],d[p]);i=Math.max(y[0].length,i),b[h]=new Array(i),b[p]=new Array(i);for(var m=0;m=0;n--){for(var w=0;n>=0;){var M=!0;for(m=0;m=0&&w++,A=A.dblp(w),n<0)break;for(m=0;m0?x=r[m][_-1>>1]:_<0&&(x=r[m][-_-1>>1].neg()),A="affine"===x.type?A.mixedAdd(x):A.add(x));}}for(n=0;n=Math.ceil((e.bitLength()+1)/f.step)},p$j.prototype._getDoubles=function(e,f){if(this.precomputed&&this.precomputed.doubles)return this.precomputed.doubles;for(var d=[this],c=this,t=0;t=0&&(a=f,r=d),c.negative&&(c=c.neg(),t=t.neg()),a.negative&&(a=a.neg(),r=r.neg()),[{a:c,b:t},{a,b:r}]},A$8.prototype._endoSplit=function(e){var f=this.endo.basis,d=f[0],c=f[1],t=c.b.mul(e).divRound(this.n),a=d.b.neg().mul(e).divRound(this.n),r=t.mul(d.a),b=a.mul(c.a),i=t.mul(d.b),n=a.mul(c.b);return {k1:e.sub(r).sub(b),k2:i.add(n).neg()}},A$8.prototype.pointFromX=function(e,f){(e=new y$e(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr().redMul(e).redIAdd(e.redMul(this.a)).redIAdd(this.b),c=d.redSqrt();if(0!==c.redSqr().redSub(d).cmp(this.zero))throw new Error("invalid point");var t=c.fromRed().isOdd();return (f&&!t||!f&&t)&&(c=c.redNeg()),this.point(e,c)},A$8.prototype.validate=function(e){if(e.inf)return !0;var f=e.x,d=e.y,c=this.a.redMul(f),t=f.redSqr().redMul(f).redIAdd(c).redIAdd(this.b);return 0===d.redSqr().redISub(t).cmpn(0)},A$8.prototype._endoWnafMulAdd=function(e,f,d){for(var c=this._endoWnafT1,t=this._endoWnafT2,a=0;a":""},I$8.prototype.isInfinity=function(){return this.inf},I$8.prototype.add=function(e){if(this.inf)return e;if(e.inf)return this;if(this.eq(e))return this.dbl();if(this.neg().eq(e))return this.curve.point(null,null);if(0===this.x.cmp(e.x))return this.curve.point(null,null);var f=this.y.redSub(e.y);0!==f.cmpn(0)&&(f=f.redMul(this.x.redSub(e.x).redInvm()));var d=f.redSqr().redISub(this.x).redISub(e.x),c=f.redMul(this.x.redSub(d)).redISub(this.y);return this.curve.point(d,c)},I$8.prototype.dbl=function(){if(this.inf)return this;var e=this.y.redAdd(this.y);if(0===e.cmpn(0))return this.curve.point(null,null);var f=this.curve.a,d=this.x.redSqr(),c=e.redInvm(),t=d.redAdd(d).redIAdd(d).redIAdd(f).redMul(c),a=t.redSqr().redISub(this.x.redAdd(this.x)),r=t.redMul(this.x.redSub(a)).redISub(this.y);return this.curve.point(a,r)},I$8.prototype.getX=function(){return this.x.fromRed()},I$8.prototype.getY=function(){return this.y.fromRed()},I$8.prototype.mul=function(e){return e=new y$e(e,16),this.isInfinity()?this:this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve.endo?this.curve._endoWnafMulAdd([this],[e]):this.curve._wnafMul(this,e)},I$8.prototype.mulAdd=function(e,f,d){var c=[this,f],t=[e,d];return this.curve.endo?this.curve._endoWnafMulAdd(c,t):this.curve._wnafMulAdd(1,c,t,2)},I$8.prototype.jmulAdd=function(e,f,d){var c=[this,f],t=[e,d];return this.curve.endo?this.curve._endoWnafMulAdd(c,t,!0):this.curve._wnafMulAdd(1,c,t,2,!0)},I$8.prototype.eq=function(e){return this===e||this.inf===e.inf&&(this.inf||0===this.x.cmp(e.x)&&0===this.y.cmp(e.y))},I$8.prototype.neg=function(e){if(this.inf)return this;var f=this.curve.point(this.x,this.y.redNeg());if(e&&this.precomputed){var d=this.precomputed,c=function(e){return e.neg()};f.precomputed={naf:d.naf&&{wnd:d.naf.wnd,points:d.naf.points.map(c)},doubles:d.doubles&&{step:d.doubles.step,points:d.doubles.points.map(c)}};}return f},I$8.prototype.toJ=function(){return this.inf?this.curve.jpoint(null,null,null):this.curve.jpoint(this.x,this.y,this.curve.one)},m$f(w$e,S$9.BasePoint),A$8.prototype.jpoint=function(e,f,d){return new w$e(this,e,f,d)},w$e.prototype.toP=function(){if(this.isInfinity())return this.curve.point(null,null);var e=this.z.redInvm(),f=e.redSqr(),d=this.x.redMul(f),c=this.y.redMul(f).redMul(e);return this.curve.point(d,c)},w$e.prototype.neg=function(){return this.curve.jpoint(this.x,this.y.redNeg(),this.z)},w$e.prototype.add=function(e){if(this.isInfinity())return e;if(e.isInfinity())return this;var f=e.z.redSqr(),d=this.z.redSqr(),c=this.x.redMul(f),t=e.x.redMul(d),a=this.y.redMul(f.redMul(e.z)),r=e.y.redMul(d.redMul(this.z)),b=c.redSub(t),i=a.redSub(r);if(0===b.cmpn(0))return 0!==i.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var n=b.redSqr(),s=n.redMul(b),o=c.redMul(n),u=i.redSqr().redIAdd(s).redISub(o).redISub(o),h=i.redMul(o.redISub(u)).redISub(a.redMul(s)),p=this.z.redMul(e.z).redMul(b);return this.curve.jpoint(u,h,p)},w$e.prototype.mixedAdd=function(e){if(this.isInfinity())return e.toJ();if(e.isInfinity())return this;var f=this.z.redSqr(),d=this.x,c=e.x.redMul(f),t=this.y,a=e.y.redMul(f).redMul(this.z),r=d.redSub(c),b=t.redSub(a);if(0===r.cmpn(0))return 0!==b.cmpn(0)?this.curve.jpoint(null,null,null):this.dbl();var i=r.redSqr(),n=i.redMul(r),s=d.redMul(i),o=b.redSqr().redIAdd(n).redISub(s).redISub(s),u=b.redMul(s.redISub(o)).redISub(t.redMul(n)),h=this.z.redMul(r);return this.curve.jpoint(o,u,h)},w$e.prototype.dblp=function(e){if(0===e)return this;if(this.isInfinity())return this;if(!e)return this.dbl();if(this.curve.zeroA||this.curve.threeA){for(var f=this,d=0;d=0)return !1;if(d.redIAdd(t),0===this.x.cmp(d))return !0}},w$e.prototype.inspect=function(){return this.isInfinity()?"":""},w$e.prototype.isInfinity=function(){return 0===this.z.cmpn(0)};var M$6,x$6=l$j,_$d=n$c,z$6=t$2$2,q$4=v$e,R$3=n$i;function P$4(e){q$4.call(this,"mont",e),this.a=new _$d(e.a,16).toRed(this.red),this.b=new _$d(e.b,16).toRed(this.red),this.i4=new _$d(4).toRed(this.red).redInvm(),this.two=new _$d(2).toRed(this.red),this.a24=this.i4.redMul(this.a.redAdd(this.two));}function j$5(e,f,d){q$4.BasePoint.call(this,e,"projective"),null===f&&null===d?(this.x=this.curve.one,this.z=this.curve.zero):(this.x=new _$d(f,16),this.z=new _$d(d,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)));}z$6(P$4,q$4),M$6=P$4,P$4.prototype.validate=function(e){var f=e.normalize().x,d=f.redSqr(),c=d.redMul(f).redAdd(d.redMul(this.a)).redAdd(f);return 0===c.redSqrt().redSqr().cmp(c)},z$6(j$5,q$4.BasePoint),P$4.prototype.decodePoint=function(e,f){return this.point(R$3.toArray(e,f),1)},P$4.prototype.point=function(e,f){return new j$5(this,e,f)},P$4.prototype.pointFromJSON=function(e){return j$5.fromJSON(this,e)},j$5.prototype.precompute=function(){},j$5.prototype._encode=function(){return this.getX().toArray("be",this.curve.p.byteLength())},j$5.fromJSON=function(e,f){return new j$5(e,f[0],f[1]||e.one)},j$5.prototype.inspect=function(){return this.isInfinity()?"":""},j$5.prototype.isInfinity=function(){return 0===this.z.cmpn(0)},j$5.prototype.dbl=function(){var e=this.x.redAdd(this.z).redSqr(),f=this.x.redSub(this.z).redSqr(),d=e.redSub(f),c=e.redMul(f),t=d.redMul(f.redAdd(this.curve.a24.redMul(d)));return this.curve.point(c,t)},j$5.prototype.add=function(){throw new Error("Not supported on Montgomery curve")},j$5.prototype.diffAdd=function(e,f){var d=this.x.redAdd(this.z),c=this.x.redSub(this.z),t=e.x.redAdd(e.z),a=e.x.redSub(e.z).redMul(d),r=t.redMul(c),b=f.z.redMul(a.redAdd(r).redSqr()),i=f.x.redMul(a.redISub(r).redSqr());return this.curve.point(b,i)},j$5.prototype.mul=function(e){for(var f=e.clone(),d=this,c=this.curve.point(null,null),t=[];0!==f.cmpn(0);f.iushrn(1))t.push(f.andln(1));for(var a=t.length-1;a>=0;a--)0===t[a]?(d=d.diffAdd(c,this),c=c.dbl()):(c=d.diffAdd(c,this),d=d.dbl());return c},j$5.prototype.mulAdd=function(){throw new Error("Not supported on Montgomery curve")},j$5.prototype.jumlAdd=function(){throw new Error("Not supported on Montgomery curve")},j$5.prototype.eq=function(e){return 0===this.getX().cmp(e.getX())},j$5.prototype.normalize=function(){return this.x=this.x.redMul(this.z.redInvm()),this.z=this.curve.one,this},j$5.prototype.getX=function(){return this.normalize(),this.x.fromRed()};var N$4,E$8=M$6,k$b=n$c,O$5=t$2$2,L$4=v$e,B$8=n$i.assert;function F$5(e){this.twisted=1!=(0|e.a),this.mOneA=this.twisted&&-1==(0|e.a),this.extended=this.mOneA,L$4.call(this,"edwards",e),this.a=new k$b(e.a,16).umod(this.red.m),this.a=this.a.toRed(this.red),this.c=new k$b(e.c,16).toRed(this.red),this.c2=this.c.redSqr(),this.d=new k$b(e.d,16).toRed(this.red),this.dd=this.d.redAdd(this.d),B$8(!this.twisted||0===this.c.fromRed().cmpn(1)),this.oneC=1==(0|e.c);}function C$5(e,f,d,c,t){L$4.BasePoint.call(this,e,"projective"),null===f&&null===d&&null===c?(this.x=this.curve.zero,this.y=this.curve.one,this.z=this.curve.one,this.t=this.curve.zero,this.zOne=!0):(this.x=new k$b(f,16),this.y=new k$b(d,16),this.z=c?new k$b(c,16):this.curve.one,this.t=t&&new k$b(t,16),this.x.red||(this.x=this.x.toRed(this.curve.red)),this.y.red||(this.y=this.y.toRed(this.curve.red)),this.z.red||(this.z=this.z.toRed(this.curve.red)),this.t&&!this.t.red&&(this.t=this.t.toRed(this.curve.red)),this.zOne=this.z===this.curve.one,this.curve.extended&&!this.t&&(this.t=this.x.redMul(this.y),this.zOne||(this.t=this.t.redMul(this.z.redInvm()))));}O$5(F$5,L$4),N$4=F$5,F$5.prototype._mulA=function(e){return this.mOneA?e.redNeg():this.a.redMul(e)},F$5.prototype._mulC=function(e){return this.oneC?e:this.c.redMul(e)},F$5.prototype.jpoint=function(e,f,d,c){return this.point(e,f,d,c)},F$5.prototype.pointFromX=function(e,f){(e=new k$b(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr(),c=this.c2.redSub(this.a.redMul(d)),t=this.one.redSub(this.c2.redMul(this.d).redMul(d)),a=c.redMul(t.redInvm()),r=a.redSqrt();if(0!==r.redSqr().redSub(a).cmp(this.zero))throw new Error("invalid point");var b=r.fromRed().isOdd();return (f&&!b||!f&&b)&&(r=r.redNeg()),this.point(e,r)},F$5.prototype.pointFromY=function(e,f){(e=new k$b(e,16)).red||(e=e.toRed(this.red));var d=e.redSqr(),c=d.redSub(this.c2),t=d.redMul(this.d).redMul(this.c2).redSub(this.a),a=c.redMul(t.redInvm());if(0===a.cmp(this.zero)){if(f)throw new Error("invalid point");return this.point(this.zero,e)}var r=a.redSqrt();if(0!==r.redSqr().redSub(a).cmp(this.zero))throw new Error("invalid point");return r.fromRed().isOdd()!==f&&(r=r.redNeg()),this.point(r,e)},F$5.prototype.validate=function(e){if(e.isInfinity())return !0;e.normalize();var f=e.x.redSqr(),d=e.y.redSqr(),c=f.redMul(this.a).redAdd(d),t=this.c2.redMul(this.one.redAdd(this.d.redMul(f).redMul(d)));return 0===c.cmp(t)},O$5(C$5,L$4.BasePoint),F$5.prototype.pointFromJSON=function(e){return C$5.fromJSON(this,e)},F$5.prototype.point=function(e,f,d,c){return new C$5(this,e,f,d,c)},C$5.fromJSON=function(e,f){return new C$5(e,f[0],f[1],f[2])},C$5.prototype.inspect=function(){return this.isInfinity()?"":""},C$5.prototype.isInfinity=function(){return 0===this.x.cmpn(0)&&(0===this.y.cmp(this.z)||this.zOne&&0===this.y.cmp(this.curve.c))},C$5.prototype._extDbl=function(){var e=this.x.redSqr(),f=this.y.redSqr(),d=this.z.redSqr();d=d.redIAdd(d);var c=this.curve._mulA(e),t=this.x.redAdd(this.y).redSqr().redISub(e).redISub(f),a=c.redAdd(f),r=a.redSub(d),b=c.redSub(f),i=t.redMul(r),n=a.redMul(b),s=t.redMul(b),o=r.redMul(a);return this.curve.point(i,n,o,s)},C$5.prototype._projDbl=function(){var e,f,d,c=this.x.redAdd(this.y).redSqr(),t=this.x.redSqr(),a=this.y.redSqr();if(this.curve.twisted){var r=(n=this.curve._mulA(t)).redAdd(a);if(this.zOne)e=c.redSub(t).redSub(a).redMul(r.redSub(this.curve.two)),f=r.redMul(n.redSub(a)),d=r.redSqr().redSub(r).redSub(r);else {var b=this.z.redSqr(),i=r.redSub(b).redISub(b);e=c.redSub(t).redISub(a).redMul(i),f=r.redMul(n.redSub(a)),d=r.redMul(i);}}else {var n=t.redAdd(a);b=this.curve._mulC(this.z).redSqr(),i=n.redSub(b).redSub(b);e=this.curve._mulC(c.redISub(n)).redMul(i),f=this.curve._mulC(n).redMul(t.redISub(a)),d=n.redMul(i);}return this.curve.point(e,f,d)},C$5.prototype.dbl=function(){return this.isInfinity()?this:this.curve.extended?this._extDbl():this._projDbl()},C$5.prototype._extAdd=function(e){var f=this.y.redSub(this.x).redMul(e.y.redSub(e.x)),d=this.y.redAdd(this.x).redMul(e.y.redAdd(e.x)),c=this.t.redMul(this.curve.dd).redMul(e.t),t=this.z.redMul(e.z.redAdd(e.z)),a=d.redSub(f),r=t.redSub(c),b=t.redAdd(c),i=d.redAdd(f),n=a.redMul(r),s=b.redMul(i),o=a.redMul(i),u=r.redMul(b);return this.curve.point(n,s,u,o)},C$5.prototype._projAdd=function(e){var f,d,c=this.z.redMul(e.z),t=c.redSqr(),a=this.x.redMul(e.x),r=this.y.redMul(e.y),b=this.curve.d.redMul(a).redMul(r),i=t.redSub(b),n=t.redAdd(b),s=this.x.redAdd(this.y).redMul(e.x.redAdd(e.y)).redISub(a).redISub(r),o=c.redMul(i).redMul(s);return this.curve.twisted?(f=c.redMul(n).redMul(r.redSub(this.curve._mulA(a))),d=i.redMul(n)):(f=c.redMul(n).redMul(r.redSub(a)),d=this.curve._mulC(i).redMul(n)),this.curve.point(o,f,d)},C$5.prototype.add=function(e){return this.isInfinity()?e:e.isInfinity()?this:this.curve.extended?this._extAdd(e):this._projAdd(e)},C$5.prototype.mul=function(e){return this._hasDoubles(e)?this.curve._fixedNafMul(this,e):this.curve._wnafMul(this,e)},C$5.prototype.mulAdd=function(e,f,d){return this.curve._wnafMulAdd(1,[this,f],[e,d],2,!1)},C$5.prototype.jmulAdd=function(e,f,d){return this.curve._wnafMulAdd(1,[this,f],[e,d],2,!0)},C$5.prototype.normalize=function(){if(this.zOne)return this;var e=this.z.redInvm();return this.x=this.x.redMul(e),this.y=this.y.redMul(e),this.t&&(this.t=this.t.redMul(e)),this.z=this.curve.one,this.zOne=!0,this},C$5.prototype.neg=function(){return this.curve.point(this.x.redNeg(),this.y,this.z,this.t&&this.t.redNeg())},C$5.prototype.getX=function(){return this.normalize(),this.x.fromRed()},C$5.prototype.getY=function(){return this.normalize(),this.y.fromRed()},C$5.prototype.eq=function(e){return this===e||0===this.getX().cmp(e.getX())&&0===this.getY().cmp(e.getY())},C$5.prototype.eqXToP=function(e){var f=e.toRed(this.curve.red).redMul(this.z);if(0===this.x.cmp(f))return !0;for(var d=e.clone(),c=this.curve.redN.redMul(this.z);;){if(d.iadd(this.curve.n),d.cmp(this.curve.p)>=0)return !1;if(f.redIAdd(c),0===this.x.cmp(f))return !0}},C$5.prototype.toP=C$5.prototype.normalize,C$5.prototype.mixedAdd=C$5.prototype.add;var T$5=N$4,J$3={},X$3=J$3;X$3.base=v$e,X$3.short=x$6,X$3.mont=E$8,X$3.edwards=T$5;var D$4,Y$2={doubles:{step:4,points:[["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a","f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"],["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508","11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"],["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739","d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"],["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640","4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"],["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c","4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"],["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda","96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"],["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa","5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"],["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0","cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"],["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d","9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"],["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d","e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"],["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1","9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"],["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0","5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"],["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047","10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"],["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862","283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"],["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7","7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"],["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd","56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"],["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83","7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"],["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a","53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"],["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8","bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"],["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d","4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"],["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725","7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"],["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754","4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"],["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c","17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"],["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6","6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"],["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39","c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"],["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891","893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"],["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b","febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"],["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03","2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"],["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d","eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"],["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070","7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"],["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4","e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"],["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da","662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"],["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11","1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"],["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e","efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"],["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41","2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"],["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef","67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"],["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8","db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"],["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d","648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"],["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96","35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"],["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd","ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"],["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5","9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"],["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266","40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"],["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71","34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"],["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac","c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"],["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751","1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"],["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e","493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"],["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241","c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"],["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3","be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"],["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f","4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"],["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19","aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"],["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be","b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"],["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9","6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"],["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2","8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"],["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13","7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"],["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c","ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"],["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba","2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"],["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151","e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"],["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073","d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"],["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458","38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"],["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b","69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"],["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366","d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"],["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa","40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"],["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0","620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"],["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787","7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"],["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e","ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]]},naf:{wnd:7,points:[["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9","388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"],["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4","d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"],["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc","6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"],["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe","cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"],["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb","d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"],["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8","ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"],["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e","581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"],["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34","4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"],["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c","85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"],["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5","321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"],["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f","2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"],["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714","73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"],["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729","a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"],["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db","2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"],["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4","e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"],["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5","b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"],["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479","2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"],["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d","80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"],["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f","1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"],["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb","d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"],["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9","eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"],["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963","758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"],["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74","958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"],["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530","e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"],["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b","5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"],["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247","cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"],["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1","cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"],["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120","4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"],["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435","91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"],["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18","673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"],["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8","59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"],["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb","3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"],["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f","55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"],["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143","efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"],["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba","e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"],["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45","f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"],["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a","744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"],["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e","c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"],["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8","e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"],["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c","30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"],["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519","e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"],["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab","100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"],["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca","ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"],["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf","8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"],["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610","68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"],["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4","f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"],["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c","d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"],["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940","edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"],["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980","a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"],["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3","66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"],["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf","9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"],["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63","4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"],["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448","fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"],["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf","5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"],["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5","8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"],["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6","8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"],["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5","5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"],["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99","f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"],["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51","f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"],["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5","42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"],["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5","204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"],["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997","4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"],["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881","73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"],["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5","39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"],["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66","d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"],["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726","ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"],["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede","6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"],["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94","60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"],["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31","3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"],["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51","b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"],["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252","ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"],["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5","cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"],["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b","6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"],["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4","322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"],["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f","6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"],["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889","2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"],["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246","b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"],["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984","998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"],["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a","b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"],["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030","bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"],["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197","6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"],["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593","c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"],["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef","21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"],["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38","60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"],["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a","49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"],["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111","5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"],["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502","7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"],["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea","be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"],["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26","8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"],["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986","39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"],["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e","62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"],["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4","25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"],["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda","ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"],["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859","cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"],["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f","f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"],["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c","6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"],["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942","fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"],["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a","1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"],["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80","5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"],["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d","438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"],["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1","cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"],["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63","c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"],["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352","6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"],["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193","ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"],["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00","9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"],["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58","ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"],["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7","d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"],["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8","c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"],["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e","67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"],["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d","cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"],["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b","299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"],["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f","f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"],["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6","462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"],["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297","62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"],["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a","7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"],["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c","ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"],["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52","4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"],["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb","bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"],["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065","bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"],["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917","603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"],["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9","cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"],["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3","553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"],["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57","712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"],["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66","ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"],["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8","9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"],["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721","9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"],["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180","4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]]}},W$3={},K$4=W$3,U$6=X$2,G$3=J$3,H$5=n$i.assert;function Q$2(e){"short"===e.type?this.curve=new G$3.short(e):"edwards"===e.type?this.curve=new G$3.edwards(e):this.curve=new G$3.mont(e),this.g=this.curve.g,this.n=this.curve.n,this.hash=e.hash,H$5(this.g.validate(),"Invalid curve"),H$5(this.g.mul(this.n).isInfinity(),"Invalid curve, G*N != O");}function V$3(e,f){Object.defineProperty(K$4,e,{configurable:!0,enumerable:!0,get:function(){var d=new Q$2(f);return Object.defineProperty(K$4,e,{configurable:!0,enumerable:!0,value:d}),d}});}K$4.PresetCurve=Q$2,V$3("p192",{type:"short",prime:"p192",p:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff",a:"ffffffff ffffffff ffffffff fffffffe ffffffff fffffffc",b:"64210519 e59c80e7 0fa7e9ab 72243049 feb8deec c146b9b1",n:"ffffffff ffffffff ffffffff 99def836 146bc9b1 b4d22831",hash:U$6.sha256,gRed:!1,g:["188da80e b03090f6 7cbf20eb 43a18800 f4ff0afd 82ff1012","07192b95 ffc8da78 631011ed 6b24cdd5 73f977a1 1e794811"]}),V$3("p224",{type:"short",prime:"p224",p:"ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001",a:"ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff fffffffe",b:"b4050a85 0c04b3ab f5413256 5044b0b7 d7bfd8ba 270b3943 2355ffb4",n:"ffffffff ffffffff ffffffff ffff16a2 e0b8f03e 13dd2945 5c5c2a3d",hash:U$6.sha256,gRed:!1,g:["b70e0cbd 6bb4bf7f 321390b9 4a03c1d3 56c21122 343280d6 115c1d21","bd376388 b5f723fb 4c22dfe6 cd4375a0 5a074764 44d58199 85007e34"]}),V$3("p256",{type:"short",prime:null,p:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff ffffffff",a:"ffffffff 00000001 00000000 00000000 00000000 ffffffff ffffffff fffffffc",b:"5ac635d8 aa3a93e7 b3ebbd55 769886bc 651d06b0 cc53b0f6 3bce3c3e 27d2604b",n:"ffffffff 00000000 ffffffff ffffffff bce6faad a7179e84 f3b9cac2 fc632551",hash:U$6.sha256,gRed:!1,g:["6b17d1f2 e12c4247 f8bce6e5 63a440f2 77037d81 2deb33a0 f4a13945 d898c296","4fe342e2 fe1a7f9b 8ee7eb4a 7c0f9e16 2bce3357 6b315ece cbb64068 37bf51f5"]}),V$3("p384",{type:"short",prime:null,p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 ffffffff",a:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe ffffffff 00000000 00000000 fffffffc",b:"b3312fa7 e23ee7e4 988e056b e3f82d19 181d9c6e fe814112 0314088f 5013875a c656398d 8a2ed19d 2a85c8ed d3ec2aef",n:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff c7634d81 f4372ddf 581a0db2 48b0a77a ecec196a ccc52973",hash:U$6.sha384,gRed:!1,g:["aa87ca22 be8b0537 8eb1c71e f320ad74 6e1d3b62 8ba79b98 59f741e0 82542a38 5502f25d bf55296c 3a545e38 72760ab7","3617de4a 96262c6f 5d9e98bf 9292dc29 f8f41dbd 289a147c e9da3113 b5f0b8c0 0a60b1ce 1d7e819d 7a431d7c 90ea0e5f"]}),V$3("p521",{type:"short",prime:null,p:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff",a:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffc",b:"00000051 953eb961 8e1c9a1f 929a21a0 b68540ee a2da725b 99b315f3 b8b48991 8ef109e1 56193951 ec7e937b 1652c0bd 3bb1bf07 3573df88 3d2c34f1 ef451fd4 6b503f00",n:"000001ff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffa 51868783 bf2f966b 7fcc0148 f709a5d0 3bb5c9b8 899c47ae bb6fb71e 91386409",hash:U$6.sha512,gRed:!1,g:["000000c6 858e06b7 0404e9cd 9e3ecb66 2395b442 9c648139 053fb521 f828af60 6b4d3dba a14b5e77 efe75928 fe1dc127 a2ffa8de 3348b3c1 856a429b f97e7e31 c2e5bd66","00000118 39296a78 9a3bc004 5c8a5fb4 2c7d1bd9 98f54449 579b4468 17afbd17 273e662c 97ee7299 5ef42640 c550b901 3fad0761 353c7086 a272c240 88be9476 9fd16650"]}),V$3("curve25519",{type:"mont",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"76d06",b:"1",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:U$6.sha256,gRed:!1,g:["9"]}),V$3("ed25519",{type:"edwards",prime:"p25519",p:"7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed",a:"-1",c:"1",d:"52036cee2b6ffe73 8cc740797779e898 00700a4d4141d8ab 75eb4dca135978a3",n:"1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed",hash:U$6.sha256,gRed:!1,g:["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a","6666666666666666666666666666666666666666666666666666666666666658"]});try{D$4=Y$2;}catch(e){D$4=void 0;}V$3("secp256k1",{type:"short",prime:"k256",p:"ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f",a:"0",b:"7",n:"ffffffff ffffffff ffffffff fffffffe baaedce6 af48a03b bfd25e8c d0364141",h:"1",hash:U$6.sha256,beta:"7ae96a2b657c07106e64479eac3434e99cf0497512f58995c1396c28719501ee",lambda:"5363ad4cc05c30e0a5261c028812645a122e22ea20816678df02967c1b23bd72",basis:[{a:"3086d221a7d46bcde86c90e49284eb15",b:"-e4437ed6010e88286f547fa90abfe4c3"},{a:"114ca50f7a8e2f3f657c1108d9d44cfd8",b:"3086d221a7d46bcde86c90e49284eb15"}],gRed:!1,g:["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798","483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8",D$4]});var Z$1,$$1=n$c,ee=n$i.assert;function fe(e,f){this.ec=e,this.priv=null,this.pub=null,f.priv&&this._importPrivate(f.priv,f.privEnc),f.pub&&this._importPublic(f.pub,f.pubEnc);}Z$1=fe,fe.fromPublic=function(e,f,d){return f instanceof fe?f:new fe(e,{pub:f,pubEnc:d})},fe.fromPrivate=function(e,f,d){return f instanceof fe?f:new fe(e,{priv:f,privEnc:d})},fe.prototype.validate=function(){var e=this.getPublic();return e.isInfinity()?{result:!1,reason:"Invalid public key"}:e.validate()?e.mul(this.ec.curve.n).isInfinity()?{result:!0,reason:null}:{result:!1,reason:"Public key * N != O"}:{result:!1,reason:"Public key is not a point"}},fe.prototype.getPublic=function(e,f){return "string"==typeof e&&(f=e,e=null),this.pub||(this.pub=this.ec.g.mul(this.priv)),f?this.pub.encode(f,e):this.pub},fe.prototype.getPrivate=function(e){return "hex"===e?this.priv.toString(16,2):this.priv},fe.prototype._importPrivate=function(e,f){this.priv=new $$1(e,f||16),this.priv=this.priv.umod(this.ec.curve.n);},fe.prototype._importPublic=function(e,f){if(e.x||e.y)return "mont"===this.ec.curve.type?ee(e.x,"Need x coordinate"):"short"!==this.ec.curve.type&&"edwards"!==this.ec.curve.type||ee(e.x&&e.y,"Need both x and y coordinate"),this.pub=this.ec.curve.point(e.x,e.y),void 0;this.pub=this.ec.curve.decodePoint(e,f);},fe.prototype.derive=function(e){return e.mul(this.priv).getX()},fe.prototype.sign=function(e,f,d){return this.ec.sign(e,this,f,d)},fe.prototype.verify=function(e,f){return this.ec.verify(e,f,this)},fe.prototype.inspect=function(){return ""};var de,ce=Z$1,te=n$c,ae=a$l,re=W$3,be=f$i,ie=n$i.assert,ne=ce,se=d$e;function oe(e){if(!(this instanceof oe))return new oe(e);"string"==typeof e&&(ie(re.hasOwnProperty(e),"Unknown curve "+e),e=re[e]),e instanceof re.PresetCurve&&(e={curve:e}),this.curve=e.curve.curve,this.n=this.curve.n,this.nh=this.n.ushrn(1),this.g=this.curve.g,this.g=e.curve.g,this.g.precompute(e.curve.n.bitLength()+1),this.hash=e.hash||e.curve.hash;}de=oe,oe.prototype.keyPair=function(e){return new ne(this,e)},oe.prototype.keyFromPrivate=function(e,f){return ne.fromPrivate(this,e,f)},oe.prototype.keyFromPublic=function(e,f){return ne.fromPublic(this,e,f)},oe.prototype.genKeyPair=function(e){e||(e={});for(var f=new ae({hash:this.hash,pers:e.pers,persEnc:e.persEnc||"utf8",entropy:e.entropy||be(this.hash.hmacStrength),entropyEnc:e.entropy&&e.entropyEnc||"utf8",nonce:this.n.toArray()}),d=this.n.byteLength(),c=this.n.sub(new te(2));;){var t=new te(f.generate(d));if(!(t.cmp(c)>0))return t.iaddn(1),this.keyFromPrivate(t);}},oe.prototype._truncateToN=function(e,f){var d=8*e.byteLength()-this.n.bitLength();return d>0&&(e=e.ushrn(d)),!f&&e.cmp(this.n)>=0?e.sub(this.n):e},oe.prototype.sign=function(e,f,d,c){"object"==typeof d&&(c=d,d=null),c||(c={}),f=this.keyFromPrivate(f,d),e=this._truncateToN(new te(e,16));for(var t=this.n.byteLength(),a=f.getPrivate().toArray("be",t),r=e.toArray("be",t),b=new ae({hash:this.hash,entropy:a,nonce:r,pers:c.pers,persEnc:c.persEnc||"utf8"}),i=this.n.sub(new te(1)),n=0;;n++){var s=c.k?c.k(n):new te(b.generate(this.n.byteLength()));if(!((s=this._truncateToN(s,!0)).cmpn(1)<=0||s.cmp(i)>=0)){var o=this.g.mul(s);if(!o.isInfinity()){var u=o.getX(),h=u.umod(this.n);if(0!==h.cmpn(0)){var p=s.invm(this.n).mul(h.mul(f.getPrivate()).iadd(e));if(0!==(p=p.umod(this.n)).cmpn(0)){var l=(o.getY().isOdd()?1:0)|(0!==u.cmp(h)?2:0);return c.canonical&&p.cmp(this.nh)>0&&(p=this.n.sub(p),l^=1),new se({r:h,s:p,recoveryParam:l})}}}}}},oe.prototype.verify=function(e,f,d,c){e=this._truncateToN(new te(e,16)),d=this.keyFromPublic(d,c);var t=(f=new se(f,"hex")).r,a=f.s;if(t.cmpn(1)<0||t.cmp(this.n)>=0)return !1;if(a.cmpn(1)<0||a.cmp(this.n)>=0)return !1;var r,b=a.invm(this.n),i=b.mul(e).umod(this.n),n=b.mul(t).umod(this.n);return this.curve._maxwellTrick?!(r=this.g.jmulAdd(i,d.getPublic(),n)).isInfinity()&&r.eqXToP(t):!(r=this.g.mulAdd(i,d.getPublic(),n)).isInfinity()&&0===r.getX().umod(this.n).cmp(t)},oe.prototype.recoverPubKey=function(e,f,d,c){ie((3&d)===d,"The recovery param is more than two bits"),f=new se(f,c);var t=this.n,a=new te(e),r=f.r,b=f.s,i=1&d,n=d>>1;if(r.cmp(this.curve.p.umod(this.curve.n))>=0&&n)throw new Error("Unable to find sencond key candinate");r=n?this.curve.pointFromX(r.add(this.curve.n),i):this.curve.pointFromX(r,i);var s=f.r.invm(t),o=t.sub(a).mul(s).umod(t),u=b.mul(s).umod(t);return this.g.mulAdd(o,r,u)},oe.prototype.getKeyRecoveryParam=function(e,f,d,c){if(null!==(f=new se(f,c)).recoveryParam)return f.recoveryParam;for(var t=0;t<4;t++){var a;try{a=this.recoverPubKey(e,f,t);}catch(e){continue}if(a.eq(d))return t}throw new Error("Unable to find valid recovery factor")};var ue=de,he=n$i,pe=he.assert,le=he.parseBytes,ve=he.cachedProperty;function ye(e,f){this.eddsa=e,this._secret=le(f.secret),e.isPoint(f.pub)?this._pub=f.pub:this._pubBytes=le(f.pub);}ye.fromPublic=function(e,f){return f instanceof ye?f:new ye(e,{pub:f})},ye.fromSecret=function(e,f){return f instanceof ye?f:new ye(e,{secret:f})},ye.prototype.secret=function(){return this._secret},ve(ye,"pubBytes",(function(){return this.eddsa.encodePoint(this.pub())})),ve(ye,"pub",(function(){return this._pubBytes?this.eddsa.decodePoint(this._pubBytes):this.eddsa.g.mul(this.priv())})),ve(ye,"privBytes",(function(){var e=this.eddsa,f=this.hash(),d=e.encodingLength-1,c=f.slice(0,e.encodingLength);return c[0]&=248,c[d]&=127,c[d]|=64,c})),ve(ye,"priv",(function(){return this.eddsa.decodeInt(this.privBytes())})),ve(ye,"hash",(function(){return this.eddsa.hash().update(this.secret()).digest()})),ve(ye,"messagePrefix",(function(){return this.hash().slice(this.eddsa.encodingLength)})),ye.prototype.sign=function(e){return pe(this._secret,"KeyPair can only verify"),this.eddsa.sign(e,this)},ye.prototype.verify=function(e,f){return this.eddsa.verify(e,f,this)},ye.prototype.getSecret=function(e){return pe(this._secret,"KeyPair is public only"),he.encode(this.secret(),e)},ye.prototype.getPublic=function(e){return he.encode(this.pubBytes(),e)};var me=ye,Se=n$c,ge=n$i,Ae=ge.assert,Ie=ge.cachedProperty,we=ge.parseBytes;function Me(e,f){this.eddsa=e,"object"!=typeof f&&(f=we(f)),Array.isArray(f)&&(f={R:f.slice(0,e.encodingLength),S:f.slice(e.encodingLength)}),Ae(f.R&&f.S,"Signature without R or S"),e.isPoint(f.R)&&(this._R=f.R),f.S instanceof Se&&(this._S=f.S),this._Rencoded=Array.isArray(f.R)?f.R:f.Rencoded,this._Sencoded=Array.isArray(f.S)?f.S:f.Sencoded;}Ie(Me,"S",(function(){return this.eddsa.decodeInt(this.Sencoded())})),Ie(Me,"R",(function(){return this.eddsa.decodePoint(this.Rencoded())})),Ie(Me,"Rencoded",(function(){return this.eddsa.encodePoint(this.R())})),Ie(Me,"Sencoded",(function(){return this.eddsa.encodeInt(this.S())})),Me.prototype.toBytes=function(){return this.Rencoded().concat(this.Sencoded())},Me.prototype.toHex=function(){return ge.encode(this.toBytes(),"hex").toUpperCase()};var xe,_e=Me,ze=X$2,qe=W$3,Re=n$i,Pe=Re.assert,je=Re.parseBytes,Ne=me,Ee=_e;function ke(e){if(Pe("ed25519"===e,"only tested with ed25519 so far"),!(this instanceof ke))return new ke(e);e=qe[e].curve;this.curve=e,this.g=e.g,this.g.precompute(e.n.bitLength()+1),this.pointClass=e.point().constructor,this.encodingLength=Math.ceil(e.n.bitLength()/8),this.hash=ze.sha512;}xe=ke,ke.prototype.sign=function(e,f){e=je(e);var d=this.keyFromSecret(f),c=this.hashInt(d.messagePrefix(),e),t=this.g.mul(c),a=this.encodePoint(t),r=this.hashInt(a,d.pubBytes(),e).mul(d.priv()),b=c.add(r).umod(this.curve.n);return this.makeSignature({R:t,S:b,Rencoded:a})},ke.prototype.verify=function(e,f,d){e=je(e),f=this.makeSignature(f);var c=this.keyFromPublic(d),t=this.hashInt(f.Rencoded(),c.pubBytes(),e),a=this.g.mul(f.S());return f.R().add(c.pub().mul(t)).eq(a)},ke.prototype.hashInt=function(){for(var e=this.hash(),f=0;f","MIT",{url:"https://github.com/indutny/elliptic/issues"},"https://github.com/indutny/elliptic",{brfs:"^1.4.3",coveralls:"^3.0.8",grunt:"^1.0.4","grunt-browserify":"^5.0.0","grunt-cli":"^1.2.0","grunt-contrib-connect":"^1.0.0","grunt-contrib-copy":"^1.0.0","grunt-contrib-uglify":"^1.0.1","grunt-mocha-istanbul":"^3.0.1","grunt-saucelabs":"^9.0.1",istanbul:"^0.4.2",jscs:"^3.0.7",jshint:"^2.10.3",mocha:"^6.2.2"},{"bn.js":"^4.4.0",brorand:"^1.0.1","hash.js":"^1.0.0","hmac-drbg":"^1.0.0",inherits:"^2.0.1","minimalistic-assert":"^1.0.0","minimalistic-crypto-utils":"^1.0.0"}][1],Be.utils=n$i,Be.rand=f$i,Be.curve=J$3,Be.curves=W$3,Be.ec=ue,Be.eddsa=Oe; -var o$n={},s$j=!1,a$m="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;var u$j="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,c$i={},f$n=t$2$2;function l$k(e){(this||u$j)._reporterState={obj:null,path:[],options:e||{},errors:[]};}function h$g(e,t){(this||u$j).path=e,this.rethrow(t);}c$i.Reporter=l$k,l$k.prototype.isError=function(e){return e instanceof h$g},l$k.prototype.save=function(){var e=(this||u$j)._reporterState;return {obj:e.obj,pathLen:e.path.length}},l$k.prototype.restore=function(e){var t=(this||u$j)._reporterState;t.obj=e.obj,t.path=t.path.slice(0,e.pathLen);},l$k.prototype.enterKey=function(e){return (this||u$j)._reporterState.path.push(e)},l$k.prototype.exitKey=function(e){var t=(this||u$j)._reporterState;t.path=t.path.slice(0,e-1);},l$k.prototype.leaveKey=function(e,t,r){var n=(this||u$j)._reporterState;this.exitKey(e),null!==n.obj&&(n.obj[t]=r);},l$k.prototype.path=function(){return (this||u$j)._reporterState.path.join("/")},l$k.prototype.enterObject=function(){var e=(this||u$j)._reporterState,t=e.obj;return e.obj={},t},l$k.prototype.leaveObject=function(e){var t=(this||u$j)._reporterState,r=t.obj;return t.obj=e,r},l$k.prototype.error=function(e){var t,r=(this||u$j)._reporterState,n=e instanceof h$g;if(t=n?e:new h$g(r.path.map((function(e){return "["+JSON.stringify(e)+"]"})).join(""),e.message||e,e.stack),!r.options.partial)throw t;return n||r.errors.push(t),t},l$k.prototype.wrapResult=function(e){var t=(this||u$j)._reporterState;return t.options.partial?{result:this.isError(e)?null:e,errors:t.errors}:e},f$n(h$g,Error),h$g.prototype.rethrow=function(e){if((this||u$j).message=e+" at: "+((this||u$j).path||"(shallow)"),Error.captureStackTrace&&Error.captureStackTrace(this||u$j,h$g),!(this||u$j).stack)try{throw new Error((this||u$j).message)}catch(e){(this||u$j).stack=e.stack;}return this||u$j};var p$k={},d$i=!1,g$e="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function y$f(){if(d$i)return p$k;d$i=!0;var e=t$2$2,r=E$9().Reporter,i=e$1$1$1.Buffer;function o(e,t){if(r.call(this||g$e,t),!i.isBuffer(e))return this.error("Input not Buffer"),void 0;(this||g$e).base=e,(this||g$e).offset=0,(this||g$e).length=e.length;}function s(e,t){if(Array.isArray(e))(this||g$e).length=0,(this||g$e).value=e.map((function(e){return e instanceof s||(e=new s(e,t)),(this||g$e).length+=e.length,e}),this||g$e);else if("number"==typeof e){if(!(0<=e&&e<=255))return t.error("non-byte EncoderBuffer value");(this||g$e).value=e,(this||g$e).length=1;}else if("string"==typeof e)(this||g$e).value=e,(this||g$e).length=i.byteLength(e);else {if(!i.isBuffer(e))return t.error("Unsupported type: "+typeof e);(this||g$e).value=e,(this||g$e).length=e.length;}}return e(o,r),p$k.DecoderBuffer=o,o.prototype.save=function(){return {offset:(this||g$e).offset,reporter:r.prototype.save.call(this||g$e)}},o.prototype.restore=function(e){var t=new o((this||g$e).base);return t.offset=e.offset,t.length=(this||g$e).offset,(this||g$e).offset=e.offset,r.prototype.restore.call(this||g$e,e.reporter),t},o.prototype.isEmpty=function(){return (this||g$e).offset===(this||g$e).length},o.prototype.readUInt8=function(e){return (this||g$e).offset+1<=(this||g$e).length?(this||g$e).base.readUInt8((this||g$e).offset++,!0):this.error(e||"DecoderBuffer overrun")},o.prototype.skip=function(e,t){if(!((this||g$e).offset+e<=(this||g$e).length))return this.error(t||"DecoderBuffer overrun");var r=new o((this||g$e).base);return r._reporterState=(this||g$e)._reporterState,r.offset=(this||g$e).offset,r.length=(this||g$e).offset+e,(this||g$e).offset+=e,r},o.prototype.raw=function(e){return (this||g$e).base.slice(e?e.offset:(this||g$e).offset,(this||g$e).length)},p$k.EncoderBuffer=s,s.prototype.join=function(e,t){return e||(e=new i((this||g$e).length)),t||(t=0),0===(this||g$e).length||(Array.isArray((this||g$e).value)?(this||g$e).value.forEach((function(r){r.join(e,t),t+=r.length;})):("number"==typeof(this||g$e).value?e[t]=(this||g$e).value:"string"==typeof(this||g$e).value?e.write((this||g$e).value,t):i.isBuffer((this||g$e).value)&&(this||g$e).value.copy(e,t),t+=(this||g$e).length)),e},p$k}var _$e={},v$f=!1,b$c="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;var m$g={},S$a=!1;function E$9(){if(S$a)return m$g;S$a=!0;var e=m$g;return e.Reporter=c$i.Reporter,e.DecoderBuffer=y$f().DecoderBuffer,e.EncoderBuffer=y$f().EncoderBuffer,e.Node=function(){if(v$f)return _$e;v$f=!0;var e=E$9().Reporter,t=E$9().EncoderBuffer,r=E$9().DecoderBuffer,n=o$7,o=["seq","seqof","set","setof","objid","bool","gentime","utctime","null_","enum","int","objDesc","bitstr","bmpstr","charstr","genstr","graphstr","ia5str","iso646str","numstr","octstr","printstr","t61str","unistr","utf8str","videostr"],s=["key","obj","use","optional","explicit","implicit","def","choice","any","contains"].concat(o);function a(e,t){var r={};(this||b$c)._baseState=r,r.enc=e,r.parent=t||null,r.children=null,r.tag=null,r.args=null,r.reverseArgs=null,r.choice=null,r.optional=!1,r.any=!1,r.obj=!1,r.use=null,r.useDecoder=null,r.key=null,r.default=null,r.explicit=null,r.implicit=null,r.contains=null,r.parent||(r.children=[],this._wrap());}_$e=a;var u=["enc","parent","children","tag","args","reverseArgs","choice","optional","any","obj","use","alteredUse","key","default","explicit","implicit","contains"];return a.prototype.clone=function(){var e=(this||b$c)._baseState,t={};u.forEach((function(r){t[r]=e[r];}));var r=new(this||b$c).constructor(t.parent);return r._baseState=t,r},a.prototype._wrap=function(){var e=(this||b$c)._baseState;s.forEach((function(t){(this||b$c)[t]=function(){var r=new(this||b$c).constructor(this||b$c);return e.children.push(r),r[t].apply(r,arguments)};}),this||b$c);},a.prototype._init=function(e){var t=(this||b$c)._baseState;n(null===t.parent),e.call(this||b$c),t.children=t.children.filter((function(e){return e._baseState.parent===(this||b$c)}),this||b$c),n.equal(t.children.length,1,"Root node can have only one child");},a.prototype._useArgs=function(e){var t=(this||b$c)._baseState,r=e.filter((function(e){return e instanceof(this||b$c).constructor}),this||b$c);e=e.filter((function(e){return !(e instanceof(this||b$c).constructor)}),this||b$c),0!==r.length&&(n(null===t.children),t.children=r,r.forEach((function(e){e._baseState.parent=this||b$c;}),this||b$c)),0!==e.length&&(n(null===t.args),t.args=e,t.reverseArgs=e.map((function(e){if("object"!=typeof e||e.constructor!==Object)return e;var t={};return Object.keys(e).forEach((function(r){r==(0|r)&&(r|=0);var n=e[r];t[n]=r;})),t})));},["_peekTag","_decodeTag","_use","_decodeStr","_decodeObjid","_decodeTime","_decodeNull","_decodeInt","_decodeBool","_decodeList","_encodeComposite","_encodeStr","_encodeObjid","_encodeTime","_encodeNull","_encodeInt","_encodeBool"].forEach((function(e){a.prototype[e]=function(){var t=(this||b$c)._baseState;throw new Error(e+" not implemented for encoding: "+t.enc)};})),o.forEach((function(e){a.prototype[e]=function(){var t=(this||b$c)._baseState,r=Array.prototype.slice.call(arguments);return n(null===t.tag),t.tag=e,this._useArgs(r),this||b$c};})),a.prototype.use=function(e){n(e);var t=(this||b$c)._baseState;return n(null===t.use),t.use=e,this||b$c},a.prototype.optional=function(){return (this||b$c)._baseState.optional=!0,this||b$c},a.prototype.def=function(e){var t=(this||b$c)._baseState;return n(null===t.default),t.default=e,t.optional=!0,this||b$c},a.prototype.explicit=function(e){var t=(this||b$c)._baseState;return n(null===t.explicit&&null===t.implicit),t.explicit=e,this||b$c},a.prototype.implicit=function(e){var t=(this||b$c)._baseState;return n(null===t.explicit&&null===t.implicit),t.implicit=e,this||b$c},a.prototype.obj=function(){var e=(this||b$c)._baseState,t=Array.prototype.slice.call(arguments);return e.obj=!0,0!==t.length&&this._useArgs(t),this||b$c},a.prototype.key=function(e){var t=(this||b$c)._baseState;return n(null===t.key),t.key=e,this||b$c},a.prototype.any=function(){return (this||b$c)._baseState.any=!0,this||b$c},a.prototype.choice=function(e){var t=(this||b$c)._baseState;return n(null===t.choice),t.choice=e,this._useArgs(Object.keys(e).map((function(t){return e[t]}))),this||b$c},a.prototype.contains=function(e){var t=(this||b$c)._baseState;return n(null===t.use),t.contains=e,this||b$c},a.prototype._decode=function(e,t){var n=(this||b$c)._baseState;if(null===n.parent)return e.wrapResult(n.children[0]._decode(e,t));var i,o=n.default,s=!0,a=null;if(null!==n.key&&(a=e.enterKey(n.key)),n.optional){var u=null;if(null!==n.explicit?u=n.explicit:null!==n.implicit?u=n.implicit:null!==n.tag&&(u=n.tag),null!==u||n.any){if(s=this._peekTag(e,u,n.any),e.isError(s))return s}else {var c=e.save();try{null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),s=!0;}catch(e){s=!1;}e.restore(c);}}if(n.obj&&s&&(i=e.enterObject()),s){if(null!==n.explicit){var f=this._decodeTag(e,n.explicit);if(e.isError(f))return f;e=f;}var l=e.offset;if(null===n.use&&null===n.choice){if(n.any)c=e.save();var h=this._decodeTag(e,null!==n.implicit?n.implicit:n.tag,n.any);if(e.isError(h))return h;n.any?o=e.raw(c):e=h;}if(t&&t.track&&null!==n.tag&&t.track(e.path(),l,e.length,"tagged"),t&&t.track&&null!==n.tag&&t.track(e.path(),e.offset,e.length,"content"),o=n.any?o:null===n.choice?this._decodeGeneric(n.tag,e,t):this._decodeChoice(e,t),e.isError(o))return o;if(n.any||null!==n.choice||null===n.children||n.children.forEach((function(r){r._decode(e,t);})),n.contains&&("octstr"===n.tag||"bitstr"===n.tag)){var p=new r(o);o=this._getUse(n.contains,e._reporterState.obj)._decode(p,t);}}return n.obj&&s&&(o=e.leaveObject(i)),null===n.key||null===o&&!0!==s?null!==a&&e.exitKey(a):e.leaveKey(a,n.key,o),o},a.prototype._decodeGeneric=function(e,t,r){var n=(this||b$c)._baseState;return "seq"===e||"set"===e?null:"seqof"===e||"setof"===e?this._decodeList(t,e,n.args[0],r):/str$/.test(e)?this._decodeStr(t,e,r):"objid"===e&&n.args?this._decodeObjid(t,n.args[0],n.args[1],r):"objid"===e?this._decodeObjid(t,null,null,r):"gentime"===e||"utctime"===e?this._decodeTime(t,e,r):"null_"===e?this._decodeNull(t,r):"bool"===e?this._decodeBool(t,r):"objDesc"===e?this._decodeStr(t,e,r):"int"===e||"enum"===e?this._decodeInt(t,n.args&&n.args[0],r):null!==n.use?this._getUse(n.use,t._reporterState.obj)._decode(t,r):t.error("unknown tag: "+e)},a.prototype._getUse=function(e,t){var r=(this||b$c)._baseState;return r.useDecoder=this._use(e,t),n(null===r.useDecoder._baseState.parent),r.useDecoder=r.useDecoder._baseState.children[0],r.implicit!==r.useDecoder._baseState.implicit&&(r.useDecoder=r.useDecoder.clone(),r.useDecoder._baseState.implicit=r.implicit),r.useDecoder},a.prototype._decodeChoice=function(e,t){var r=(this||b$c)._baseState,n=null,i=!1;return Object.keys(r.choice).some((function(o){var s=e.save(),a=r.choice[o];try{var u=a._decode(e,t);if(e.isError(u))return !1;n={type:o,value:u},i=!0;}catch(t){return e.restore(s),!1}return !0}),this||b$c),i?n:e.error("Choice not matched")},a.prototype._createEncoderBuffer=function(e){return new t(e,(this||b$c).reporter)},a.prototype._encode=function(e,t,r){var n=(this||b$c)._baseState;if(null===n.default||n.default!==e){var i=this._encodeValue(e,t,r);if(void 0!==i&&!this._skipDefault(i,t,r))return i}},a.prototype._encodeValue=function(t,r,n){var i=(this||b$c)._baseState;if(null===i.parent)return i.children[0]._encode(t,r||new e);var o=null;if((this||b$c).reporter=r,i.optional&&void 0===t){if(null===i.default)return;t=i.default;}var s=null,a=!1;if(i.any)o=this._createEncoderBuffer(t);else if(i.choice)o=this._encodeChoice(t,r);else if(i.contains)s=this._getUse(i.contains,n)._encode(t,r),a=!0;else if(i.children)s=i.children.map((function(e){if("null_"===e._baseState.tag)return e._encode(null,r,t);if(null===e._baseState.key)return r.error("Child should have a key");var n=r.enterKey(e._baseState.key);if("object"!=typeof t)return r.error("Child expected, but input is not object");var i=e._encode(t[e._baseState.key],r,t);return r.leaveKey(n),i}),this||b$c).filter((function(e){return e})),s=this._createEncoderBuffer(s);else if("seqof"===i.tag||"setof"===i.tag){if(!i.args||1!==i.args.length)return r.error("Too many args for : "+i.tag);if(!Array.isArray(t))return r.error("seqof/setof, but data is not Array");var u=this.clone();u._baseState.implicit=null,s=this._createEncoderBuffer(t.map((function(e){var n=(this||b$c)._baseState;return this._getUse(n.args[0],t)._encode(e,r)}),u));}else null!==i.use?o=this._getUse(i.use,n)._encode(t,r):(s=this._encodePrimitive(i.tag,t),a=!0);if(!i.any&&null===i.choice){var c=null!==i.implicit?i.implicit:i.tag,f=null===i.implicit?"universal":"context";null===c?null===i.use&&r.error("Tag could be omitted only for .use()"):null===i.use&&(o=this._encodeComposite(c,a,f,s));}return null!==i.explicit&&(o=this._encodeComposite(i.explicit,!1,"context",o)),o},a.prototype._encodeChoice=function(e,t){var r=(this||b$c)._baseState,i=r.choice[e.type];return i||n(!1,e.type+" not found in "+JSON.stringify(Object.keys(r.choice))),i._encode(e.value,t)},a.prototype._encodePrimitive=function(e,t){var r=(this||b$c)._baseState;if(/str$/.test(e))return this._encodeStr(t,e);if("objid"===e&&r.args)return this._encodeObjid(t,r.reverseArgs[0],r.args[1]);if("objid"===e)return this._encodeObjid(t,null,null);if("gentime"===e||"utctime"===e)return this._encodeTime(t,e);if("null_"===e)return this._encodeNull();if("int"===e||"enum"===e)return this._encodeInt(t,r.args&&r.reverseArgs[0]);if("bool"===e)return this._encodeBool(t);if("objDesc"===e)return this._encodeStr(t,e);throw new Error("Unsupported tag: "+e)},a.prototype._isNumstr=function(e){return /^[0-9 ]*$/.test(e)},a.prototype._isPrintstr=function(e){return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(e)},_$e}(),m$g}var j$6={},w$f=!1;var B$9={},k$c=!1;function T$6(){if(k$c)return B$9;k$c=!0;var e=B$9;return e._reverse=function(e){var t={};return Object.keys(e).forEach((function(r){(0|r)==r&&(r|=0);var n=e[r];t[n]=r;})),t},e.der=function(){if(w$f)return j$6;w$f=!0;var e=T$6();return j$6.tagClass={0:"universal",1:"application",2:"context",3:"private"},j$6.tagClassByName=e._reverse(j$6.tagClass),j$6.tag={0:"end",1:"bool",2:"int",3:"bitstr",4:"octstr",5:"null_",6:"objid",7:"objDesc",8:"external",9:"real",10:"enum",11:"embed",12:"utf8str",13:"relativeOid",16:"seq",17:"set",18:"numstr",19:"printstr",20:"t61str",21:"videostr",22:"ia5str",23:"utctime",24:"gentime",25:"graphstr",26:"iso646str",27:"genstr",28:"unistr",29:"charstr",30:"bmpstr"},j$6.tagByName=e._reverse(j$6.tag),j$6}(),B$9}var D$5={},U$7=!1,N$5="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global;function C$6(){if(U$7)return D$5;U$7=!0;var e=t$2$2,r=Y$3(),n=r.base,i=r.bignum,o=r.constants.der;function s(e){(this||N$5).enc="der",(this||N$5).name=e.name,(this||N$5).entity=e,(this||N$5).tree=new a,(this||N$5).tree._init(e.body);}function a(e){n.Node.call(this||N$5,"der",e);}function u(e,t){var r=e.readUInt8(t);if(e.isError(r))return r;var n=o.tagClass[r>>6],i=0==(32&r);if(31==(31&r)){var s=r;for(r=0;128==(128&s);){if(s=e.readUInt8(t),e.isError(s))return s;r<<=7,r|=127&s;}}else r&=31;return {cls:n,primitive:i,tag:r,tagStr:o.tag[r]}}function c(e,t,r){var n=e.readUInt8(r);if(e.isError(n))return n;if(!t&&128===n)return null;if(0==(128&n))return n;var i=127&n;if(i>4)return e.error("length octect is too long");n=0;for(var o=0;o=31)return n.error("Multi-octet tag encoding unsupported");t||(i|=32);return i|=s.tagClassByName[r||"universal"]<<6}(e,t,n,(this||R$4).reporter);if(i.length<128)return (o=new r(2))[0]=a,o[1]=i.length,this._createEncoderBuffer([o,i]);for(var u=1,c=i.length;c>=256;c>>=8)u++;(o=new r(2+u))[0]=a,o[1]=128|u;c=1+u;for(var f=i.length;f>0;c--,f>>=8)o[c]=255&f;return this._createEncoderBuffer([o,i])},u.prototype._encodeStr=function(e,t){if("bitstr"===t)return this._createEncoderBuffer([0|e.unused,e.data]);if("bmpstr"===t){for(var n=new r(2*e.length),i=0;i=40)return (this||R$4).reporter.error("Second objid identifier OOB");e.splice(0,2,40*e[0]+e[1]);}var o=0;for(i=0;i=128;s>>=7)o++;}var a=new r(o),u=a.length-1;for(i=e.length-1;i>=0;i--){s=e[i];for(a[u--]=127&s;(s>>=7)>0;)a[u--]=128|127&s;}return this._createEncoderBuffer(a)},u.prototype._encodeTime=function(e,t){var r,n=new Date(e);return "gentime"===t?r=[c(n.getFullYear()),c(n.getUTCMonth()+1),c(n.getUTCDate()),c(n.getUTCHours()),c(n.getUTCMinutes()),c(n.getUTCSeconds()),"Z"].join(""):"utctime"===t?r=[c(n.getFullYear()%100),c(n.getUTCMonth()+1),c(n.getUTCDate()),c(n.getUTCHours()),c(n.getUTCMinutes()),c(n.getUTCSeconds()),"Z"].join(""):(this||R$4).reporter.error("Encoding "+t+" time is not supported yet"),this._encodeStr(r,"octstr")},u.prototype._encodeNull=function(){return this._createEncoderBuffer("")},u.prototype._encodeInt=function(e,t){if("string"==typeof e){if(!t)return (this||R$4).reporter.error("String int or enum given, but no values map");if(!t.hasOwnProperty(e))return (this||R$4).reporter.error("Values map doesn't contain: "+JSON.stringify(e));e=t[e];}if("number"!=typeof e&&!r.isBuffer(e)){var n=e.toArray();!e.sign&&128&n[0]&&n.unshift(0),e=new r(n);}if(r.isBuffer(e)){var i=e.length;0===e.length&&i++;var o=new r(i);return e.copy(o),0===e.length&&(o[0]=0),this._createEncoderBuffer(o)}if(e<128)return this._createEncoderBuffer(e);if(e<256)return this._createEncoderBuffer([0,e]);i=1;for(var s=e;s>=256;s>>=8)i++;for(s=(o=new Array(i)).length-1;s>=0;s--)o[s]=255&e,e>>=8;return 128&o[0]&&o.unshift(0),this._createEncoderBuffer(new r(o))},u.prototype._encodeBool=function(e){return this._createEncoderBuffer(e?255:0)},u.prototype._use=function(e,t){return "function"==typeof e&&(e=e(t)),e._getEncoder("der").tree},u.prototype._skipDefault=function(e,t,r){var n,i=(this||R$4)._baseState;if(null===i.default)return !1;var o=e.join();if(void 0===i.defaultBuffer&&(i.defaultBuffer=this._encodeValue(i.default,t,r).join()),o.length!==i.defaultBuffer.length)return !1;for(n=0;n0&&r.ishrn(n),r}function _$f(e,t,r){var n,a;do{for(n=new f$q(0);8*n.length=t)throw new Error("invalid sig")}var K$7=function(e,t,r,n,a){var o=T$7(r);if("ec"===o.type){if("ecdsa"!==n&&"ecdsa/rsa"!==n)throw new Error("wrong public key type");return function(e,t,r){var n=P$7[r.data.algorithm.curve.join(".")];if(!n)throw new Error("unknown curve "+r.data.algorithm.curve.join("."));var a=new j$8(n),o=r.data.subjectPrivateKey.data;return a.verify(t,e,o)}(e,t,o)}if("dsa"===o.type){if("dsa"!==n)throw new Error("wrong public key type");return function(e,t,r){var n=r.data.p,a=r.data.q,o=r.data.g,i=r.data.pub_key,s=T$7.signature.decode(e,"der"),h=s.s,u=s.r;A$a(h,a),A$a(u,a);var p=R$5.mont(n),d=h.invm(a);return 0===o.toRed(p).redPow(new R$5(t).mul(d).mod(a)).fromRed().mul(i.toRed(p).redPow(u.mul(d).mod(a)).fromRed()).mod(n).mod(a).cmp(u)}(e,t,o)}if("rsa"!==n&&"ecdsa/rsa"!==n)throw new Error("wrong public key type");t=L$6.concat([a,t]);for(var i=o.modulus.byteLength(),s=[1],h=0;t.length+s.length+2e-i-2)throw new Error("message too long");var l=B$b.alloc(e-t-i-2),f=e-a-1,u=g$g(a),c=v$j(B$b.concat([o,l,B$b.alloc(1,1),n],f),w$h(u,f)),p=v$j(u,w$h(c,a));return new y$k(B$b.concat([B$b.alloc(1),p,c],e))}(a,n);else if(1===t)o=function(r,n,e){var t,o=n.length,a=r.modulus.byteLength();if(o>a-11)throw new Error("message too long");t=e?B$b.alloc(a-o-3,255):function(r){var n,e=B$b.allocUnsafe(r),t=0,o=g$g(2*r),a=0;for(;t=0)throw new Error("data too long for modulus")}return e?b$g(o,a):E$c(o,a)},L$7=v$h,k$f=u$n,D$7=c$m,U$9=n$c,R$6=l$d,S$c=h$4,j$9=h$j,A$b=u$q.Buffer;var I$a=function(r,n,e){var t;t=r.padding?r.padding:e?1:4;var o,a=L$7(r),i=a.modulus.byteLength();if(n.length>i||new U$9(n).cmp(a.modulus)>=0)throw new Error("decryption error");o=e?j$9(new U$9(n),a):R$6(n,a);var l=A$b.alloc(i-o.length);if(o=A$b.concat([l,o],i),4===t)return function(r,n){var e=r.modulus.byteLength(),t=S$c("sha1").update(A$b.alloc(0)).digest(),o=t.length;if(0!==n[0])throw new Error("decryption error");var a=n.slice(1,o+1),i=n.slice(o+1),l=D$7(a,k$f(i,o)),f=D$7(i,k$f(l,e-o-1));if(function(r,n){r=A$b.from(r),n=A$b.from(n);var e=0,t=r.length;r.length!==n.length&&(e++,t=Math.min(r.length,n.length));var o=-1;for(;++o=n.length){a++;break}var i=n.slice(2,o-1);("0002"!==t.toString("hex")&&!e||"0001"!==t.toString("hex")&&e)&&a++;i.length<8&&a++;if(a)throw new Error("decryption error");return n.slice(o)}(0,o,e);if(3===t)return o;throw new Error("unknown padding")},M$9={};M$9.publicEncrypt=x$9,M$9.privateDecrypt=I$a,M$9.privateEncrypt=function(r,n){return M$9.publicEncrypt(r,n,!0)},M$9.publicDecrypt=function(r,n){return M$9.privateDecrypt(r,n,!0)};var o$r="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof self?self:global,t$b={},f$t=T$9;function i$d(){throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11")}var u$o=u$q,a$o=a,s$o=u$o.Buffer,l$p=u$o.kMaxLength,m$l=o$r.crypto||o$r.msCrypto,p$q=Math.pow(2,32)-1;function y$l(r,e){if("number"!=typeof r||r!=r)throw new TypeError("offset must be a number");if(r>p$q||r<0)throw new TypeError("offset must be a uint32");if(r>l$p||r>e)throw new RangeError("offset out of range")}function b$h(r,e,n){if("number"!=typeof r||r!=r)throw new TypeError("size must be a number");if(r>p$q||r<0)throw new TypeError("size must be a uint32");if(r+e>n||r>l$p)throw new RangeError("buffer too small")}function w$i(r,e,n,o){if(f$t.browser){var t=r.buffer,i=new Uint8Array(t,e,n);return m$l.getRandomValues(i),o?(f$t.nextTick((function(){o(null,r);})),void 0):r}return o?(a$o(n,(function(n,t){if(n)return o(n);t.copy(r,e),o(null,r);})),void 0):(a$o(n).copy(r,e),r)}m$l&&m$l.getRandomValues||!f$t.browser?(t$b.randomFill=function(r,e,n,t){if(!(s$o.isBuffer(r)||r instanceof o$r.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');if("function"==typeof e)t=e,e=0,n=r.length;else if("function"==typeof n)t=n,n=r.length-e;else if("function"!=typeof t)throw new TypeError('"cb" argument must be a function');return y$l(e,r.length),b$h(n,e,r.length),w$i(r,e,n,t)},t$b.randomFillSync=function(r,e,n){void 0===e&&(e=0);if(!(s$o.isBuffer(r)||r instanceof o$r.Uint8Array))throw new TypeError('"buf" argument must be a Buffer or Uint8Array');y$l(e,r.length),void 0===n&&(n=r.length-e);return b$h(n,e,r.length),w$i(r,e,n)}):(t$b.randomFill=i$d,t$b.randomFillSync=i$d);var l$q={};l$q.randomBytes=l$q.rng=l$q.pseudoRandomBytes=l$q.prng=a,l$q.createHash=l$q.Hash=h$4,l$q.createHmac=l$q.Hmac=w$3;var D$8=s$4,s$p=Object.keys(D$8),_$g=["sha1","sha224","sha256","sha384","sha512","md5","rmd160"].concat(s$p);l$q.getHashes=function(){return _$g};var h$k=M$1;l$q.pbkdf2=h$k.pbkdf2,l$q.pbkdf2Sync=h$k.pbkdf2Sync;var y$m=p$d;l$q.Cipher=y$m.Cipher,l$q.createCipher=y$m.createCipher,l$q.Cipheriv=y$m.Cipheriv,l$q.createCipheriv=y$m.createCipheriv,l$q.Decipher=y$m.Decipher,l$q.createDecipher=y$m.createDecipher,l$q.Decipheriv=y$m.Decipheriv,l$q.createDecipheriv=y$m.createDecipheriv,l$q.getCiphers=y$m.getCiphers,l$q.listCiphers=y$m.listCiphers;var E$d=O$3;l$q.DiffieHellmanGroup=E$d.DiffieHellmanGroup,l$q.createDiffieHellmanGroup=E$d.createDiffieHellmanGroup,l$q.getDiffieHellman=E$d.getDiffieHellman,l$q.createDiffieHellman=E$d.createDiffieHellman,l$q.DiffieHellman=E$d.DiffieHellman;var S$d=z$8;l$q.createSign=S$d.createSign,l$q.Sign=S$d.Sign,l$q.createVerify=S$d.createVerify,l$q.Verify=S$d.Verify,l$q.createECDH=f$r;var C$8=M$9;l$q.publicEncrypt=C$8.publicEncrypt,l$q.privateEncrypt=C$8.privateEncrypt,l$q.publicDecrypt=C$8.publicDecrypt,l$q.privateDecrypt=C$8.privateDecrypt;var N$6=t$b;l$q.randomFill=N$6.randomFill,l$q.randomFillSync=N$6.randomFillSync,l$q.createCredentials=function(){throw new Error(["sorry, createCredentials is not implemented yet","we accept pull requests","https://github.com/crypto-browserify/crypto-browserify"].join("\n"))},l$q.constants={DH_CHECK_P_NOT_SAFE_PRIME:2,DH_CHECK_P_NOT_PRIME:1,DH_UNABLE_TO_CHECK_GENERATOR:4,DH_NOT_SUITABLE_GENERATOR:8,NPN_ENABLED:1,ALPN_ENABLED:1,RSA_PKCS1_PADDING:1,RSA_SSLV23_PADDING:2,RSA_NO_PADDING:3,RSA_PKCS1_OAEP_PADDING:4,RSA_X931_PADDING:5,RSA_PKCS1_PSS_PADDING:6,POINT_CONVERSION_COMPRESSED:2,POINT_CONVERSION_UNCOMPRESSED:4,POINT_CONVERSION_HYBRID:6}; +crypto.Cipher; +crypto.Cipheriv; +crypto.Decipher; +crypto.Decipheriv; +crypto.DiffieHellman; +crypto.DiffieHellmanGroup; +crypto.Hash; +crypto.Hmac; +crypto.Sign; +crypto.Verify; +crypto.constants; +crypto.createCipher; +crypto.createCipheriv; +crypto.createCredentials; +crypto.createDecipher; +crypto.createDecipheriv; +crypto.createDiffieHellman; +crypto.createDiffieHellmanGroup; +crypto.createECDH; +crypto.createHash; +crypto.createHmac; +crypto.createSign; +crypto.createVerify; +crypto.getCiphers; +crypto.getDiffieHellman; +crypto.getHashes; +crypto.listCiphers; +crypto.pbkdf2; +crypto.pbkdf2Sync; +crypto.privateDecrypt; +crypto.privateEncrypt; +crypto.prng; +crypto.pseudoRandomBytes; +crypto.publicDecrypt; +crypto.publicEncrypt; +crypto.randomBytes; +crypto.randomFill; +crypto.randomFillSync; +crypto.rng; -var exports$10$1 = {}, - _dewExec$10$1 = false; +var exports$12$2 = {}, + _dewExec$11$2 = false; -var _global$a$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$a$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$10$1() { - if (_dewExec$10$1) return exports$10$1; - _dewExec$10$1 = true; +function dew$11$2() { + if (_dewExec$11$2) return exports$12$2; + _dewExec$11$2 = true; var r; - exports$10$1 = function rand(len) { + exports$12$2 = function rand(len) { if (!r) r = new Rand(null); return r.generate(len); }; function Rand(rand) { - (this || _global$a$1).rand = rand; + (this || _global$a$2).rand = rand; } - exports$10$1.Rand = Rand; + exports$12$2.Rand = Rand; Rand.prototype.generate = function generate(len) { return this._rand(len); @@ -26294,10 +60821,10 @@ function dew$10$1() { Rand.prototype._rand = function _rand(n) { - if ((this || _global$a$1).rand.getBytes) return (this || _global$a$1).rand.getBytes(n); + if ((this || _global$a$2).rand.getBytes) return (this || _global$a$2).rand.getBytes(n); var res = new Uint8Array(n); - for (var i = 0; i < res.length; i++) res[i] = (this || _global$a$1).rand.getByte(); + for (var i = 0; i < res.length; i++) res[i] = (this || _global$a$2).rand.getByte(); return res; }; @@ -26327,36 +60854,36 @@ function dew$10$1() { } else { // Node.js or Web worker with no crypto support try { - var crypto = l$q; - if (typeof crypto.randomBytes !== "function") throw new Error("Not supported"); + var crypto$1 = crypto; + if (typeof crypto$1.randomBytes !== "function") throw new Error("Not supported"); Rand.prototype._rand = function _rand(n) { - return crypto.randomBytes(n); + return crypto$1.randomBytes(n); }; } catch (e) {} } - return exports$10$1; + return exports$12$2; } -var exports$$$1 = {}, - _dewExec$$$1 = false; +var exports$11$2 = {}, + _dewExec$10$2 = false; -var _global$9$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$9$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$$$1() { - if (_dewExec$$$1) return exports$$$1; - _dewExec$$$1 = true; +function dew$10$2() { + if (_dewExec$10$2) return exports$11$2; + _dewExec$10$2 = true; - var bn = dew$11$1(); + var bn = dew$1W(); - var brorand = dew$10$1(); + var brorand = dew$11$2(); function MillerRabin(rand) { - (this || _global$9$1).rand = rand || new brorand.Rand(); + (this || _global$9$2).rand = rand || new brorand.Rand(); } - exports$$$1 = MillerRabin; + exports$11$2 = MillerRabin; MillerRabin.create = function create(rand) { return new MillerRabin(rand); @@ -26367,7 +60894,7 @@ function dew$$$1() { var min_bytes = Math.ceil(len / 8); // Generage random bytes until a number less than n is found. // This ensures that 0..n-1 have an equal probability of being selected. - do var a = new bn((this || _global$9$1).rand.generate(min_bytes)); while (a.cmp(n) >= 0); + do var a = new bn((this || _global$9$2).rand.generate(min_bytes)); while (a.cmp(n) >= 0); return a; }; @@ -26447,26 +60974,26 @@ function dew$$$1() { return false; }; - return exports$$$1; + return exports$11$2; } -var exports$_$1 = {}, - _dewExec$_$1 = false; -function dew$_$1() { - if (_dewExec$_$1) return exports$_$1; - _dewExec$_$1 = true; +var exports$10$2 = {}, + _dewExec$$$2 = false; +function dew$$$2() { + if (_dewExec$$$2) return exports$10$2; + _dewExec$$$2 = true; - var randomBytes = dew$1S(); + var randomBytes = dew$2O(); - exports$_$1 = findPrime; + exports$10$2 = findPrime; findPrime.simpleSieve = simpleSieve; findPrime.fermatTest = fermatTest; - var BN = dew$12(); + var BN = dew$1X(); var TWENTYFOUR = new BN(24); - var MillerRabin = dew$$$1(); + var MillerRabin = dew$10$2(); var millerRabin = new MillerRabin(); var ONE = new BN(1); @@ -26566,10 +61093,10 @@ function dew$_$1() { } } - return exports$_$1; + return exports$10$2; } -var _primes$1 = { +var _primes$2 = { "modp1": { "gen": "02", "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff" @@ -26604,19 +61131,19 @@ var _primes$1 = { } }; -var exports$Z$1 = {}, - _dewExec$Z$1 = false; +var exports$$$2 = {}, + _dewExec$_$2 = false; -var _global$8$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$8$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$Z$1() { - if (_dewExec$Z$1) return exports$Z$1; - _dewExec$Z$1 = true; - var Buffer = e$1$1$1.Buffer; +function dew$_$2() { + if (_dewExec$_$2) return exports$$$2; + _dewExec$_$2 = true; + var Buffer = buffer.Buffer; - var BN = dew$12(); + var BN = dew$1X(); - var MillerRabin = dew$$$1(); + var MillerRabin = dew$10$2(); var millerRabin = new MillerRabin(); var TWENTYFOUR = new BN(24); @@ -26625,11 +61152,11 @@ function dew$Z$1() { var THREE = new BN(3); var SEVEN = new BN(7); - var primes = dew$_$1(); + var primes = dew$$$2(); - var randomBytes = dew$1S(); + var randomBytes = dew$2O(); - exports$Z$1 = DH; + exports$$$2 = DH; function setPublicKey(pub, enc) { enc = enc || "utf8"; @@ -26638,8 +61165,8 @@ function dew$Z$1() { pub = new Buffer(pub, enc); } - (this || _global$8$1)._pub = new BN(pub); - return this || _global$8$1; + (this || _global$8$2)._pub = new BN(pub); + return this || _global$8$2; } function setPrivateKey(priv, enc) { @@ -26649,8 +61176,8 @@ function dew$Z$1() { priv = new Buffer(priv, enc); } - (this || _global$8$1)._priv = new BN(priv); - return this || _global$8$1; + (this || _global$8$2)._priv = new BN(priv); + return this || _global$8$2; } var primeCache = {}; @@ -26719,45 +61246,45 @@ function dew$Z$1() { function DH(prime, generator, malleable) { this.setGenerator(generator); - (this || _global$8$1).__prime = new BN(prime); - (this || _global$8$1)._prime = BN.mont((this || _global$8$1).__prime); - (this || _global$8$1)._primeLen = prime.length; - (this || _global$8$1)._pub = undefined; - (this || _global$8$1)._priv = undefined; - (this || _global$8$1)._primeCode = undefined; + (this || _global$8$2).__prime = new BN(prime); + (this || _global$8$2)._prime = BN.mont((this || _global$8$2).__prime); + (this || _global$8$2)._primeLen = prime.length; + (this || _global$8$2)._pub = undefined; + (this || _global$8$2)._priv = undefined; + (this || _global$8$2)._primeCode = undefined; if (malleable) { - (this || _global$8$1).setPublicKey = setPublicKey; - (this || _global$8$1).setPrivateKey = setPrivateKey; + (this || _global$8$2).setPublicKey = setPublicKey; + (this || _global$8$2).setPrivateKey = setPrivateKey; } else { - (this || _global$8$1)._primeCode = 8; + (this || _global$8$2)._primeCode = 8; } } Object.defineProperty(DH.prototype, "verifyError", { enumerable: true, get: function () { - if (typeof (this || _global$8$1)._primeCode !== "number") { - (this || _global$8$1)._primeCode = checkPrime((this || _global$8$1).__prime, (this || _global$8$1).__gen); + if (typeof (this || _global$8$2)._primeCode !== "number") { + (this || _global$8$2)._primeCode = checkPrime((this || _global$8$2).__prime, (this || _global$8$2).__gen); } - return (this || _global$8$1)._primeCode; + return (this || _global$8$2)._primeCode; } }); DH.prototype.generateKeys = function () { - if (!(this || _global$8$1)._priv) { - (this || _global$8$1)._priv = new BN(randomBytes((this || _global$8$1)._primeLen)); + if (!(this || _global$8$2)._priv) { + (this || _global$8$2)._priv = new BN(randomBytes((this || _global$8$2)._primeLen)); } - (this || _global$8$1)._pub = (this || _global$8$1)._gen.toRed((this || _global$8$1)._prime).redPow((this || _global$8$1)._priv).fromRed(); + (this || _global$8$2)._pub = (this || _global$8$2)._gen.toRed((this || _global$8$2)._prime).redPow((this || _global$8$2)._priv).fromRed(); return this.getPublicKey(); }; DH.prototype.computeSecret = function (other) { other = new BN(other); - other = other.toRed((this || _global$8$1)._prime); - var secret = other.redPow((this || _global$8$1)._priv).fromRed(); + other = other.toRed((this || _global$8$2)._prime); + var secret = other.redPow((this || _global$8$2)._priv).fromRed(); var out = new Buffer(secret.toArray()); var prime = this.getPrime(); @@ -26771,19 +61298,19 @@ function dew$Z$1() { }; DH.prototype.getPublicKey = function getPublicKey(enc) { - return formatReturnValue((this || _global$8$1)._pub, enc); + return formatReturnValue((this || _global$8$2)._pub, enc); }; DH.prototype.getPrivateKey = function getPrivateKey(enc) { - return formatReturnValue((this || _global$8$1)._priv, enc); + return formatReturnValue((this || _global$8$2)._priv, enc); }; DH.prototype.getPrime = function (enc) { - return formatReturnValue((this || _global$8$1).__prime, enc); + return formatReturnValue((this || _global$8$2).__prime, enc); }; DH.prototype.getGenerator = function (enc) { - return formatReturnValue((this || _global$8$1)._gen, enc); + return formatReturnValue((this || _global$8$2)._gen, enc); }; DH.prototype.setGenerator = function (gen, enc) { @@ -26793,9 +61320,9 @@ function dew$Z$1() { gen = new Buffer(gen, enc); } - (this || _global$8$1).__gen = gen; - (this || _global$8$1)._gen = new BN(gen); - return this || _global$8$1; + (this || _global$8$2).__gen = gen; + (this || _global$8$2)._gen = new BN(gen); + return this || _global$8$2; }; function formatReturnValue(bn, enc) { @@ -26808,21 +61335,21 @@ function dew$Z$1() { } } - return exports$Z$1; + return exports$$$2; } -var exports$Y$1 = {}, - _dewExec$Y$1 = false; -function dew$Y$1() { - if (_dewExec$Y$1) return exports$Y$1; - _dewExec$Y$1 = true; - var Buffer = e$1$1$1.Buffer; +var exports$_$2 = {}, + _dewExec$Z$2 = false; +function dew$Z$2() { + if (_dewExec$Z$2) return exports$_$2; + _dewExec$Z$2 = true; + var Buffer = buffer.Buffer; - var generatePrime = dew$_$1(); + var generatePrime = dew$$$2(); - var primes = _primes$1; + var primes = _primes$2; - var DH = dew$Z$1(); + var DH = dew$_$2(); function getDiffieHellman(mod) { var prime = new Buffer(primes[mod].prime, "hex"); @@ -26860,22 +61387,103 @@ function dew$Y$1() { return new DH(prime, generator, true); } - exports$Y$1.DiffieHellmanGroup = exports$Y$1.createDiffieHellmanGroup = exports$Y$1.getDiffieHellman = getDiffieHellman; - exports$Y$1.createDiffieHellman = exports$Y$1.DiffieHellman = createDiffieHellman; - return exports$Y$1; + exports$_$2.DiffieHellmanGroup = exports$_$2.createDiffieHellmanGroup = exports$_$2.getDiffieHellman = getDiffieHellman; + exports$_$2.createDiffieHellman = exports$_$2.DiffieHellman = createDiffieHellman; + return exports$_$2; } -var exports$X$1 = {}, - _dewExec$X$1 = false; -var module$4$1 = { - exports: exports$X$1 +var exports$Z$2 = {}, + _dewExec$Y$2 = false; +function dew$Y$2() { + if (_dewExec$Y$2) return exports$Z$2; + _dewExec$Y$2 = true; + + /*! safe-buffer. MIT License. Feross Aboukhadijeh */ + + /* eslint-disable node/no-deprecated-api */ + var buffer$1 = buffer; + var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers + + function copyProps(src, dst) { + for (var key in src) { + dst[key] = src[key]; + } + } + + if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + exports$Z$2 = buffer$1; + } else { + // Copy properties from require('buffer') + copyProps(buffer$1, exports$Z$2); + exports$Z$2.Buffer = SafeBuffer; + } + + function SafeBuffer(arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length); + } + + SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer + + copyProps(Buffer, SafeBuffer); + + SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === "number") { + throw new TypeError("Argument must not be a number"); + } + + return Buffer(arg, encodingOrOffset, length); + }; + + SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + var buf = Buffer(size); + + if (fill !== undefined) { + if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } + } else { + buf.fill(0); + } + + return buf; + }; + + SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return Buffer(size); + }; + + SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + + return buffer$1.SlowBuffer(size); + }; + + return exports$Z$2; +} + +var exports$Y$2 = {}, + _dewExec$X$2 = false; +var module$4$2 = { + exports: exports$Y$2 }; -var _global$7$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$7$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$X$1() { - if (_dewExec$X$1) return module$4$1.exports; - _dewExec$X$1 = true; +function dew$X$2() { + if (_dewExec$X$2) return module$4$2.exports; + _dewExec$X$2 = true; (function (module, exports) { @@ -26901,11 +61509,11 @@ function dew$X$1() { return number; } - (this || _global$7$1).negative = 0; - (this || _global$7$1).words = null; - (this || _global$7$1).length = 0; // Reduction context + (this || _global$7$2).negative = 0; + (this || _global$7$2).words = null; + (this || _global$7$2).length = 0; // Reduction context - (this || _global$7$1).red = null; + (this || _global$7$2).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -26931,7 +61539,7 @@ function dew$X$1() { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = e$1$1$1.Buffer; + Buffer = buffer.Buffer; } } catch (e) {} @@ -26972,7 +61580,7 @@ function dew$X$1() { if (number[0] === "-") { start++; - (this || _global$7$1).negative = 1; + (this || _global$7$2).negative = 1; } if (start < number.length) { @@ -26990,21 +61598,21 @@ function dew$X$1() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$7$1).negative = 1; + (this || _global$7$2).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$7$1).words = [number & 67108863]; - (this || _global$7$1).length = 1; + (this || _global$7$2).words = [number & 67108863]; + (this || _global$7$2).length = 1; } else if (number < 4503599627370496) { - (this || _global$7$1).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$7$1).length = 2; + (this || _global$7$2).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$7$2).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$7$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$7$1).length = 3; + (this || _global$7$2).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$7$2).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -27017,16 +61625,16 @@ function dew$X$1() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$7$1).words = [0]; - (this || _global$7$1).length = 1; - return this || _global$7$1; + (this || _global$7$2).words = [0]; + (this || _global$7$2).length = 1; + return this || _global$7$2; } - (this || _global$7$1).length = Math.ceil(number.length / 3); - (this || _global$7$1).words = new Array((this || _global$7$1).length); + (this || _global$7$2).length = Math.ceil(number.length / 3); + (this || _global$7$2).words = new Array((this || _global$7$2).length); - for (var i = 0; i < (this || _global$7$1).length; i++) { - (this || _global$7$1).words[i] = 0; + for (var i = 0; i < (this || _global$7$2).length; i++) { + (this || _global$7$2).words[i] = 0; } var j, w; @@ -27035,8 +61643,8 @@ function dew$X$1() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$7$1).words[j] |= w << off & 67108863; - (this || _global$7$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$7$2).words[j] |= w << off & 67108863; + (this || _global$7$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -27047,8 +61655,8 @@ function dew$X$1() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$7$1).words[j] |= w << off & 67108863; - (this || _global$7$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$7$2).words[j] |= w << off & 67108863; + (this || _global$7$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -27087,11 +61695,11 @@ function dew$X$1() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$7$1).length = Math.ceil((number.length - start) / 6); - (this || _global$7$1).words = new Array((this || _global$7$1).length); + (this || _global$7$2).length = Math.ceil((number.length - start) / 6); + (this || _global$7$2).words = new Array((this || _global$7$2).length); - for (var i = 0; i < (this || _global$7$1).length; i++) { - (this || _global$7$1).words[i] = 0; + for (var i = 0; i < (this || _global$7$2).length; i++) { + (this || _global$7$2).words[i] = 0; } // 24-bits chunks @@ -27102,12 +61710,12 @@ function dew$X$1() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$7$1).words[j] |= w & 67108863; + (this || _global$7$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$7$1).words[j] |= w >>> 26; + (this || _global$7$2).words[j] |= w >>> 26; } else { off += 8; } @@ -27117,12 +61725,12 @@ function dew$X$1() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$7$1).words[j] |= w & 67108863; + (this || _global$7$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$7$1).words[j] |= w >>> 26; + (this || _global$7$2).words[j] |= w >>> 26; } else { off += 8; } @@ -27158,8 +61766,8 @@ function dew$X$1() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$7$1).words = [0]; - (this || _global$7$1).length = 1; // Find length of limb in base + (this || _global$7$2).words = [0]; + (this || _global$7$2).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -27176,8 +61784,8 @@ function dew$X$1() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$7$1).words[0] + word < 67108864) { - (this || _global$7$1).words[0] += word; + if ((this || _global$7$2).words[0] + word < 67108864) { + (this || _global$7$2).words[0] += word; } else { this._iaddn(word); } @@ -27193,8 +61801,8 @@ function dew$X$1() { this.imuln(pow); - if ((this || _global$7$1).words[0] + word < 67108864) { - (this || _global$7$1).words[0] += word; + if ((this || _global$7$2).words[0] + word < 67108864) { + (this || _global$7$2).words[0] += word; } else { this._iaddn(word); } @@ -27204,15 +61812,15 @@ function dew$X$1() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$7$1).length); + dest.words = new Array((this || _global$7$2).length); - for (var i = 0; i < (this || _global$7$1).length; i++) { - dest.words[i] = (this || _global$7$1).words[i]; + for (var i = 0; i < (this || _global$7$2).length; i++) { + dest.words[i] = (this || _global$7$2).words[i]; } - dest.length = (this || _global$7$1).length; - dest.negative = (this || _global$7$1).negative; - dest.red = (this || _global$7$1).red; + dest.length = (this || _global$7$2).length; + dest.negative = (this || _global$7$2).negative; + dest.red = (this || _global$7$2).red; }; function move(dest, src) { @@ -27223,7 +61831,7 @@ function dew$X$1() { } BN.prototype._move = function _move(dest) { - move(dest, this || _global$7$1); + move(dest, this || _global$7$2); }; BN.prototype.clone = function clone() { @@ -27233,17 +61841,17 @@ function dew$X$1() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$7$1).length < size) { - (this || _global$7$1).words[(this || _global$7$1).length++] = 0; + while ((this || _global$7$2).length < size) { + (this || _global$7$2).words[(this || _global$7$2).length++] = 0; } - return this || _global$7$1; + return this || _global$7$2; }; // Remove leading `0` from `this` BN.prototype._strip = function strip() { - while ((this || _global$7$1).length > 1 && (this || _global$7$1).words[(this || _global$7$1).length - 1] === 0) { - (this || _global$7$1).length--; + while ((this || _global$7$2).length > 1 && (this || _global$7$2).words[(this || _global$7$2).length - 1] === 0) { + (this || _global$7$2).length--; } return this._normSign(); @@ -27251,11 +61859,11 @@ function dew$X$1() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$7$1).length === 1 && (this || _global$7$1).words[0] === 0) { - (this || _global$7$1).negative = 0; + if ((this || _global$7$2).length === 1 && (this || _global$7$2).words[0] === 0) { + (this || _global$7$2).negative = 0; } - return this || _global$7$1; + return this || _global$7$2; }; // Check Symbol.for because not everywhere where Symbol defined // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility @@ -27271,7 +61879,7 @@ function dew$X$1() { } function inspect() { - return ((this || _global$7$1).red ? ""; + return ((this || _global$7$2).red ? ""; } /* var zeros = []; @@ -27315,12 +61923,12 @@ function dew$X$1() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$7$1).length; i++) { - var w = (this || _global$7$1).words[i]; + for (var i = 0; i < (this || _global$7$2).length; i++) { + var w = (this || _global$7$2).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$7$1).length - 1) { + if (carry !== 0 || i !== (this || _global$7$2).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -27342,7 +61950,7 @@ function dew$X$1() { out = "0" + out; } - if ((this || _global$7$1).negative !== 0) { + if ((this || _global$7$2).negative !== 0) { out = "-" + out; } @@ -27377,7 +61985,7 @@ function dew$X$1() { out = "0" + out; } - if ((this || _global$7$1).negative !== 0) { + if ((this || _global$7$2).negative !== 0) { out = "-" + out; } @@ -27388,18 +61996,18 @@ function dew$X$1() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$7$1).words[0]; + var ret = (this || _global$7$2).words[0]; - if ((this || _global$7$1).length === 2) { - ret += (this || _global$7$1).words[1] * 67108864; - } else if ((this || _global$7$1).length === 3 && (this || _global$7$1).words[2] === 1) { + if ((this || _global$7$2).length === 2) { + ret += (this || _global$7$2).words[1] * 67108864; + } else if ((this || _global$7$2).length === 3 && (this || _global$7$2).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$7$1).words[1] * 67108864; - } else if ((this || _global$7$1).length > 2) { + ret += 4503599627370496 + (this || _global$7$2).words[1] * 67108864; + } else if ((this || _global$7$2).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$7$1).negative !== 0 ? -ret : ret; + return (this || _global$7$2).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -27441,8 +62049,8 @@ function dew$X$1() { var position = 0; var carry = 0; - for (var i = 0, shift = 0; i < (this || _global$7$1).length; i++) { - var word = (this || _global$7$1).words[i] << shift | carry; + for (var i = 0, shift = 0; i < (this || _global$7$2).length; i++) { + var word = (this || _global$7$2).words[i] << shift | carry; res[position++] = word & 255; if (position < res.length) { @@ -27479,8 +62087,8 @@ function dew$X$1() { var position = res.length - 1; var carry = 0; - for (var i = 0, shift = 0; i < (this || _global$7$1).length; i++) { - var word = (this || _global$7$1).words[i] << shift | carry; + for (var i = 0, shift = 0; i < (this || _global$7$2).length; i++) { + var word = (this || _global$7$2).words[i] << shift | carry; res[position--] = word & 255; if (position >= 0) { @@ -27581,11 +62189,11 @@ function dew$X$1() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$7$1).words[(this || _global$7$1).length - 1]; + var w = (this || _global$7$2).words[(this || _global$7$2).length - 1]; var hi = this._countBits(w); - return ((this || _global$7$1).length - 1) * 26 + hi; + return ((this || _global$7$2).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -27605,8 +62213,8 @@ function dew$X$1() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$7$1).length; i++) { - var b = this._zeroBits((this || _global$7$1).words[i]); + for (var i = 0; i < (this || _global$7$2).length; i++) { + var b = this._zeroBits((this || _global$7$2).words[i]); r += b; if (b !== 26) break; @@ -27620,7 +62228,7 @@ function dew$X$1() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$7$1).negative !== 0) { + if ((this || _global$7$2).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -27636,7 +62244,7 @@ function dew$X$1() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$7$1).negative !== 0; + return (this || _global$7$2).negative !== 0; }; // Return negative clone of `this` @@ -27646,39 +62254,39 @@ function dew$X$1() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$7$1).negative ^= 1; + (this || _global$7$2).negative ^= 1; } - return this || _global$7$1; + return this || _global$7$2; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$7$1).length < num.length) { - (this || _global$7$1).words[(this || _global$7$1).length++] = 0; + while ((this || _global$7$2).length < num.length) { + (this || _global$7$2).words[(this || _global$7$2).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$7$1).words[i] = (this || _global$7$1).words[i] | num.words[i]; + (this || _global$7$2).words[i] = (this || _global$7$2).words[i] | num.words[i]; } return this._strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$7$1).negative | num.negative) === 0); + assert(((this || _global$7$2).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$7$1).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$7$2); }; BN.prototype.uor = function uor(num) { - if ((this || _global$7$1).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$7$2); }; // And `num` with `this` in-place @@ -27686,34 +62294,34 @@ function dew$X$1() { // b = min-length(num, this) var b; - if ((this || _global$7$1).length > num.length) { + if ((this || _global$7$2).length > num.length) { b = num; } else { - b = this || _global$7$1; + b = this || _global$7$2; } for (var i = 0; i < b.length; i++) { - (this || _global$7$1).words[i] = (this || _global$7$1).words[i] & num.words[i]; + (this || _global$7$2).words[i] = (this || _global$7$2).words[i] & num.words[i]; } - (this || _global$7$1).length = b.length; + (this || _global$7$2).length = b.length; return this._strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$7$1).negative | num.negative) === 0); + assert(((this || _global$7$2).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$7$1).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$7$2); }; BN.prototype.uand = function uand(num) { - if ((this || _global$7$1).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$7$2); }; // Xor `num` with `this` in-place @@ -27722,42 +62330,42 @@ function dew$X$1() { var a; var b; - if ((this || _global$7$1).length > num.length) { - a = this || _global$7$1; + if ((this || _global$7$2).length > num.length) { + a = this || _global$7$2; b = num; } else { a = num; - b = this || _global$7$1; + b = this || _global$7$2; } for (var i = 0; i < b.length; i++) { - (this || _global$7$1).words[i] = a.words[i] ^ b.words[i]; + (this || _global$7$2).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$7$1) !== a) { + if ((this || _global$7$2) !== a) { for (; i < a.length; i++) { - (this || _global$7$1).words[i] = a.words[i]; + (this || _global$7$2).words[i] = a.words[i]; } } - (this || _global$7$1).length = a.length; + (this || _global$7$2).length = a.length; return this._strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$7$1).negative | num.negative) === 0); + assert(((this || _global$7$2).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$7$1).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$7$2); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$7$1).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$7$2); }; // Not ``this`` with ``width`` bitwidth @@ -27774,12 +62382,12 @@ function dew$X$1() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$7$1).words[i] = ~(this || _global$7$1).words[i] & 67108863; + (this || _global$7$2).words[i] = ~(this || _global$7$2).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$7$1).words[i] = ~(this || _global$7$1).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$7$2).words[i] = ~(this || _global$7$2).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -27799,9 +62407,9 @@ function dew$X$1() { this._expand(off + 1); if (val) { - (this || _global$7$1).words[off] = (this || _global$7$1).words[off] | 1 << wbit; + (this || _global$7$2).words[off] = (this || _global$7$2).words[off] | 1 << wbit; } else { - (this || _global$7$1).words[off] = (this || _global$7$1).words[off] & ~(1 << wbit); + (this || _global$7$2).words[off] = (this || _global$7$2).words[off] & ~(1 << wbit); } return this._strip(); @@ -27811,12 +62419,12 @@ function dew$X$1() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$7$1).negative !== 0 && num.negative === 0) { - (this || _global$7$1).negative = 0; + if ((this || _global$7$2).negative !== 0 && num.negative === 0) { + (this || _global$7$2).negative = 0; r = this.isub(num); - (this || _global$7$1).negative ^= 1; + (this || _global$7$2).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$7$1).negative === 0 && num.negative !== 0) { + } else if ((this || _global$7$2).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -27826,60 +62434,60 @@ function dew$X$1() { var a, b; - if ((this || _global$7$1).length > num.length) { - a = this || _global$7$1; + if ((this || _global$7$2).length > num.length) { + a = this || _global$7$2; b = num; } else { a = num; - b = this || _global$7$1; + b = this || _global$7$2; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$7$1).words[i] = r & 67108863; + (this || _global$7$2).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$7$1).words[i] = r & 67108863; + (this || _global$7$2).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$7$1).length = a.length; + (this || _global$7$2).length = a.length; if (carry !== 0) { - (this || _global$7$1).words[(this || _global$7$1).length] = carry; - (this || _global$7$1).length++; // Copy the rest of the words - } else if (a !== (this || _global$7$1)) { + (this || _global$7$2).words[(this || _global$7$2).length] = carry; + (this || _global$7$2).length++; // Copy the rest of the words + } else if (a !== (this || _global$7$2)) { for (; i < a.length; i++) { - (this || _global$7$1).words[i] = a.words[i]; + (this || _global$7$2).words[i] = a.words[i]; } } - return this || _global$7$1; + return this || _global$7$2; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$7$1).negative === 0) { + if (num.negative !== 0 && (this || _global$7$2).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$7$1).negative !== 0) { - (this || _global$7$1).negative = 0; - res = num.sub(this || _global$7$1); - (this || _global$7$1).negative = 1; + } else if (num.negative === 0 && (this || _global$7$2).negative !== 0) { + (this || _global$7$2).negative = 0; + res = num.sub(this || _global$7$2); + (this || _global$7$2).negative = 1; return res; } - if ((this || _global$7$1).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$7$1); + if ((this || _global$7$2).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$7$2); }; // Subtract `num` from `this` in-place @@ -27890,10 +62498,10 @@ function dew$X$1() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$7$1).negative !== 0) { - (this || _global$7$1).negative = 0; + } else if ((this || _global$7$2).negative !== 0) { + (this || _global$7$2).negative = 0; this.iadd(num); - (this || _global$7$1).negative = 1; + (this || _global$7$2).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -27901,21 +62509,21 @@ function dew$X$1() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$7$1).negative = 0; - (this || _global$7$1).length = 1; - (this || _global$7$1).words[0] = 0; - return this || _global$7$1; + (this || _global$7$2).negative = 0; + (this || _global$7$2).length = 1; + (this || _global$7$2).words[0] = 0; + return this || _global$7$2; } // a > b var a, b; if (cmp > 0) { - a = this || _global$7$1; + a = this || _global$7$2; b = num; } else { a = num; - b = this || _global$7$1; + b = this || _global$7$2; } var carry = 0; @@ -27923,26 +62531,26 @@ function dew$X$1() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$7$1).words[i] = r & 67108863; + (this || _global$7$2).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$7$1).words[i] = r & 67108863; + (this || _global$7$2).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$7$1)) { + if (carry === 0 && i < a.length && a !== (this || _global$7$2)) { for (; i < a.length; i++) { - (this || _global$7$1).words[i] = a.words[i]; + (this || _global$7$2).words[i] = a.words[i]; } } - (this || _global$7$1).length = Math.max((this || _global$7$1).length, i); + (this || _global$7$2).length = Math.max((this || _global$7$2).length, i); - if (a !== (this || _global$7$1)) { - (this || _global$7$1).negative = 1; + if (a !== (this || _global$7$2)) { + (this || _global$7$2).negative = 1; } return this._strip(); @@ -28647,16 +63255,16 @@ function dew$X$1() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$7$1).length + num.length; + var len = (this || _global$7$2).length + num.length; - if ((this || _global$7$1).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$7$1, num, out); + if ((this || _global$7$2).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$7$2, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$7$1, num, out); + res = smallMulTo(this || _global$7$2, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$7$1, num, out); + res = bigMulTo(this || _global$7$2, num, out); } else { - res = jumboMulTo(this || _global$7$1, num, out); + res = jumboMulTo(this || _global$7$2, num, out); } return res; @@ -28665,20 +63273,20 @@ function dew$X$1() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$7$1).length + num.length); + out.words = new Array((this || _global$7$2).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$7$1).length + num.length); - return jumboMulTo(this || _global$7$1, num, out); + out.words = new Array((this || _global$7$2).length + num.length); + return jumboMulTo(this || _global$7$2, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$7$1); + return this.clone().mulTo(num, this || _global$7$2); }; BN.prototype.imuln = function imuln(num) { @@ -28689,22 +63297,22 @@ function dew$X$1() { var carry = 0; - for (var i = 0; i < (this || _global$7$1).length; i++) { - var w = ((this || _global$7$1).words[i] | 0) * num; + for (var i = 0; i < (this || _global$7$2).length; i++) { + var w = ((this || _global$7$2).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$7$1).words[i] = lo & 67108863; + (this || _global$7$2).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$7$1).words[i] = carry; - (this || _global$7$1).length++; + (this || _global$7$2).words[i] = carry; + (this || _global$7$2).length++; } - return isNegNum ? this.ineg() : this || _global$7$1; + return isNegNum ? this.ineg() : this || _global$7$2; }; BN.prototype.muln = function muln(num) { @@ -28713,7 +63321,7 @@ function dew$X$1() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$7$1); + return this.mul(this || _global$7$2); }; // `this` * `this` in-place @@ -28726,7 +63334,7 @@ function dew$X$1() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$7$1; + var res = this || _global$7$2; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -28753,29 +63361,29 @@ function dew$X$1() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$7$1).length; i++) { - var newCarry = (this || _global$7$1).words[i] & carryMask; - var c = ((this || _global$7$1).words[i] | 0) - newCarry << r; - (this || _global$7$1).words[i] = c | carry; + for (i = 0; i < (this || _global$7$2).length; i++) { + var newCarry = (this || _global$7$2).words[i] & carryMask; + var c = ((this || _global$7$2).words[i] | 0) - newCarry << r; + (this || _global$7$2).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$7$1).words[i] = carry; - (this || _global$7$1).length++; + (this || _global$7$2).words[i] = carry; + (this || _global$7$2).length++; } } if (s !== 0) { - for (i = (this || _global$7$1).length - 1; i >= 0; i--) { - (this || _global$7$1).words[i + s] = (this || _global$7$1).words[i]; + for (i = (this || _global$7$2).length - 1; i >= 0; i--) { + (this || _global$7$2).words[i + s] = (this || _global$7$2).words[i]; } for (i = 0; i < s; i++) { - (this || _global$7$1).words[i] = 0; + (this || _global$7$2).words[i] = 0; } - (this || _global$7$1).length += s; + (this || _global$7$2).length += s; } return this._strip(); @@ -28783,7 +63391,7 @@ function dew$X$1() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$7$1).negative === 0); + assert((this || _global$7$2).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -28801,7 +63409,7 @@ function dew$X$1() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$7$1).length); + var s = Math.min((bits - r) / 26, (this || _global$7$2).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -28809,28 +63417,28 @@ function dew$X$1() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$7$1).words[i]; + maskedWords.words[i] = (this || _global$7$2).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$7$1).length > s) { - (this || _global$7$1).length -= s; + if (s === 0) ; else if ((this || _global$7$2).length > s) { + (this || _global$7$2).length -= s; - for (i = 0; i < (this || _global$7$1).length; i++) { - (this || _global$7$1).words[i] = (this || _global$7$1).words[i + s]; + for (i = 0; i < (this || _global$7$2).length; i++) { + (this || _global$7$2).words[i] = (this || _global$7$2).words[i + s]; } } else { - (this || _global$7$1).words[0] = 0; - (this || _global$7$1).length = 1; + (this || _global$7$2).words[0] = 0; + (this || _global$7$2).length = 1; } var carry = 0; - for (i = (this || _global$7$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$7$1).words[i] | 0; - (this || _global$7$1).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$7$2).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$7$2).words[i] | 0; + (this || _global$7$2).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -28839,9 +63447,9 @@ function dew$X$1() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$7$1).length === 0) { - (this || _global$7$1).words[0] = 0; - (this || _global$7$1).length = 1; + if ((this || _global$7$2).length === 0) { + (this || _global$7$2).words[0] = 0; + (this || _global$7$2).length = 1; } return this._strip(); @@ -28849,7 +63457,7 @@ function dew$X$1() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$7$1).negative === 0); + assert((this || _global$7$2).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -28878,9 +63486,9 @@ function dew$X$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$7$1).length <= s) return false; // Check bit and return + if ((this || _global$7$2).length <= s) return false; // Check bit and return - var w = (this || _global$7$1).words[s]; + var w = (this || _global$7$2).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -28889,21 +63497,21 @@ function dew$X$1() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$7$1).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$7$2).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$7$1).length <= s) { - return this || _global$7$1; + if ((this || _global$7$2).length <= s) { + return this || _global$7$2; } if (r !== 0) { s++; } - (this || _global$7$1).length = Math.min(s, (this || _global$7$1).length); + (this || _global$7$2).length = Math.min(s, (this || _global$7$2).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$7$1).words[(this || _global$7$1).length - 1] &= mask; + (this || _global$7$2).words[(this || _global$7$2).length - 1] &= mask; } return this._strip(); @@ -28920,17 +63528,17 @@ function dew$X$1() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$7$1).negative !== 0) { - if ((this || _global$7$1).length === 1 && ((this || _global$7$1).words[0] | 0) <= num) { - (this || _global$7$1).words[0] = num - ((this || _global$7$1).words[0] | 0); - (this || _global$7$1).negative = 0; - return this || _global$7$1; + if ((this || _global$7$2).negative !== 0) { + if ((this || _global$7$2).length === 1 && ((this || _global$7$2).words[0] | 0) <= num) { + (this || _global$7$2).words[0] = num - ((this || _global$7$2).words[0] | 0); + (this || _global$7$2).negative = 0; + return this || _global$7$2; } - (this || _global$7$1).negative = 0; + (this || _global$7$2).negative = 0; this.isubn(num); - (this || _global$7$1).negative = 1; - return this || _global$7$1; + (this || _global$7$2).negative = 1; + return this || _global$7$2; } // Add without checks @@ -28938,20 +63546,20 @@ function dew$X$1() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$7$1).words[0] += num; // Carry + (this || _global$7$2).words[0] += num; // Carry - for (var i = 0; i < (this || _global$7$1).length && (this || _global$7$1).words[i] >= 67108864; i++) { - (this || _global$7$1).words[i] -= 67108864; + for (var i = 0; i < (this || _global$7$2).length && (this || _global$7$2).words[i] >= 67108864; i++) { + (this || _global$7$2).words[i] -= 67108864; - if (i === (this || _global$7$1).length - 1) { - (this || _global$7$1).words[i + 1] = 1; + if (i === (this || _global$7$2).length - 1) { + (this || _global$7$2).words[i + 1] = 1; } else { - (this || _global$7$1).words[i + 1]++; + (this || _global$7$2).words[i + 1]++; } } - (this || _global$7$1).length = Math.max((this || _global$7$1).length, i + 1); - return this || _global$7$1; + (this || _global$7$2).length = Math.max((this || _global$7$2).length, i + 1); + return this || _global$7$2; }; // Subtract plain number `num` from `this` @@ -28960,23 +63568,23 @@ function dew$X$1() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$7$1).negative !== 0) { - (this || _global$7$1).negative = 0; + if ((this || _global$7$2).negative !== 0) { + (this || _global$7$2).negative = 0; this.iaddn(num); - (this || _global$7$1).negative = 1; - return this || _global$7$1; + (this || _global$7$2).negative = 1; + return this || _global$7$2; } - (this || _global$7$1).words[0] -= num; + (this || _global$7$2).words[0] -= num; - if ((this || _global$7$1).length === 1 && (this || _global$7$1).words[0] < 0) { - (this || _global$7$1).words[0] = -(this || _global$7$1).words[0]; - (this || _global$7$1).negative = 1; + if ((this || _global$7$2).length === 1 && (this || _global$7$2).words[0] < 0) { + (this || _global$7$2).words[0] = -(this || _global$7$2).words[0]; + (this || _global$7$2).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$7$1).length && (this || _global$7$1).words[i] < 0; i++) { - (this || _global$7$1).words[i] += 67108864; - (this || _global$7$1).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$7$2).length && (this || _global$7$2).words[i] < 0; i++) { + (this || _global$7$2).words[i] += 67108864; + (this || _global$7$2).words[i + 1] -= 1; } } @@ -28992,8 +63600,8 @@ function dew$X$1() { }; BN.prototype.iabs = function iabs() { - (this || _global$7$1).negative = 0; - return this || _global$7$1; + (this || _global$7$2).negative = 0; + return this || _global$7$2; }; BN.prototype.abs = function abs() { @@ -29010,17 +63618,17 @@ function dew$X$1() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$7$1).words[i + shift] | 0) + carry; + w = ((this || _global$7$2).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$7$1).words[i + shift] = w & 67108863; + (this || _global$7$2).words[i + shift] = w & 67108863; } - for (; i < (this || _global$7$1).length - shift; i++) { - w = ((this || _global$7$1).words[i + shift] | 0) + carry; + for (; i < (this || _global$7$2).length - shift; i++) { + w = ((this || _global$7$2).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$7$1).words[i + shift] = w & 67108863; + (this || _global$7$2).words[i + shift] = w & 67108863; } if (carry === 0) return this._strip(); // Subtraction overflow @@ -29028,18 +63636,18 @@ function dew$X$1() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$7$1).length; i++) { - w = -((this || _global$7$1).words[i] | 0) + carry; + for (i = 0; i < (this || _global$7$2).length; i++) { + w = -((this || _global$7$2).words[i] | 0) + carry; carry = w >> 26; - (this || _global$7$1).words[i] = w & 67108863; + (this || _global$7$2).words[i] = w & 67108863; } - (this || _global$7$1).negative = 1; + (this || _global$7$2).negative = 1; return this._strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$7$1).length - num.length; + var shift = (this || _global$7$2).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -29136,7 +63744,7 @@ function dew$X$1() { var div, mod, res; - if ((this || _global$7$1).negative !== 0 && num.negative === 0) { + if ((this || _global$7$2).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -29157,7 +63765,7 @@ function dew$X$1() { }; } - if ((this || _global$7$1).negative === 0 && num.negative !== 0) { + if ((this || _global$7$2).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -29170,7 +63778,7 @@ function dew$X$1() { }; } - if (((this || _global$7$1).negative & num.negative) !== 0) { + if (((this || _global$7$2).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -29189,10 +63797,10 @@ function dew$X$1() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$7$1).length || this.cmp(num) < 0) { + if (num.length > (this || _global$7$2).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$7$1 + mod: this || _global$7$2 }; } // Very short reduction @@ -29257,8 +63865,8 @@ function dew$X$1() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$7$1).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$7$1).words[i] | 0)) % num; + for (var i = (this || _global$7$2).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$7$2).words[i] | 0)) % num; } return isNegNum ? -acc : acc; @@ -29276,15 +63884,15 @@ function dew$X$1() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$7$1).length - 1; i >= 0; i--) { - var w = ((this || _global$7$1).words[i] | 0) + carry * 67108864; - (this || _global$7$1).words[i] = w / num | 0; + for (var i = (this || _global$7$2).length - 1; i >= 0; i--) { + var w = ((this || _global$7$2).words[i] | 0) + carry * 67108864; + (this || _global$7$2).words[i] = w / num | 0; carry = w % num; } this._strip(); - return isNegNum ? this.ineg() : this || _global$7$1; + return isNegNum ? this.ineg() : this || _global$7$2; }; BN.prototype.divn = function divn(num) { @@ -29294,7 +63902,7 @@ function dew$X$1() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$7$1; + var x = this || _global$7$2; var y = p.clone(); if (x.negative !== 0) { @@ -29377,7 +63985,7 @@ function dew$X$1() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$7$1; + var a = this || _global$7$2; var b = p.clone(); if (a.negative !== 0) { @@ -29488,16 +64096,16 @@ function dew$X$1() { }; BN.prototype.isEven = function isEven() { - return ((this || _global$7$1).words[0] & 1) === 0; + return ((this || _global$7$2).words[0] & 1) === 0; }; BN.prototype.isOdd = function isOdd() { - return ((this || _global$7$1).words[0] & 1) === 1; + return ((this || _global$7$2).words[0] & 1) === 1; }; // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$7$1).words[0] & num; + return (this || _global$7$2).words[0] & num; }; // Increment at the bit position in-line @@ -29507,46 +64115,46 @@ function dew$X$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$7$1).length <= s) { + if ((this || _global$7$2).length <= s) { this._expand(s + 1); - (this || _global$7$1).words[s] |= q; - return this || _global$7$1; + (this || _global$7$2).words[s] |= q; + return this || _global$7$2; } // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$7$1).length; i++) { - var w = (this || _global$7$1).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$7$2).length; i++) { + var w = (this || _global$7$2).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$7$1).words[i] = w; + (this || _global$7$2).words[i] = w; } if (carry !== 0) { - (this || _global$7$1).words[i] = carry; - (this || _global$7$1).length++; + (this || _global$7$2).words[i] = carry; + (this || _global$7$2).length++; } - return this || _global$7$1; + return this || _global$7$2; }; BN.prototype.isZero = function isZero() { - return (this || _global$7$1).length === 1 && (this || _global$7$1).words[0] === 0; + return (this || _global$7$2).length === 1 && (this || _global$7$2).words[0] === 0; }; BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$7$1).negative !== 0 && !negative) return -1; - if ((this || _global$7$1).negative === 0 && negative) return 1; + if ((this || _global$7$2).negative !== 0 && !negative) return -1; + if ((this || _global$7$2).negative === 0 && negative) return 1; this._strip(); var res; - if ((this || _global$7$1).length > 1) { + if ((this || _global$7$2).length > 1) { res = 1; } else { if (negative) { @@ -29554,11 +64162,11 @@ function dew$X$1() { } assert(num <= 67108863, "Number is too big"); - var w = (this || _global$7$1).words[0] | 0; + var w = (this || _global$7$2).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$7$1).negative !== 0) return -res | 0; + if ((this || _global$7$2).negative !== 0) return -res | 0; return res; }; // Compare two numbers and return: // 1 - if `this` > `num` @@ -29567,22 +64175,22 @@ function dew$X$1() { BN.prototype.cmp = function cmp(num) { - if ((this || _global$7$1).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$7$1).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$7$2).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$7$2).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$7$1).negative !== 0) return -res | 0; + if ((this || _global$7$2).negative !== 0) return -res | 0; return res; }; // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$7$1).length > num.length) return 1; - if ((this || _global$7$1).length < num.length) return -1; + if ((this || _global$7$2).length > num.length) return 1; + if ((this || _global$7$2).length < num.length) return -1; var res = 0; - for (var i = (this || _global$7$1).length - 1; i >= 0; i--) { - var a = (this || _global$7$1).words[i] | 0; + for (var i = (this || _global$7$2).length - 1; i >= 0; i--) { + var a = (this || _global$7$2).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; @@ -29647,115 +64255,115 @@ function dew$X$1() { }; BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$7$1).red, "Already a number in reduction context"); - assert((this || _global$7$1).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$7$1)._forceRed(ctx); + assert(!(this || _global$7$2).red, "Already a number in reduction context"); + assert((this || _global$7$2).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$7$2)._forceRed(ctx); }; BN.prototype.fromRed = function fromRed() { - assert((this || _global$7$1).red, "fromRed works only with numbers in reduction context"); - return (this || _global$7$1).red.convertFrom(this || _global$7$1); + assert((this || _global$7$2).red, "fromRed works only with numbers in reduction context"); + return (this || _global$7$2).red.convertFrom(this || _global$7$2); }; BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$7$1).red = ctx; - return this || _global$7$1; + (this || _global$7$2).red = ctx; + return this || _global$7$2; }; BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$7$1).red, "Already a number in reduction context"); + assert(!(this || _global$7$2).red, "Already a number in reduction context"); return this._forceRed(ctx); }; BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$7$1).red, "redAdd works only with red numbers"); - return (this || _global$7$1).red.add(this || _global$7$1, num); + assert((this || _global$7$2).red, "redAdd works only with red numbers"); + return (this || _global$7$2).red.add(this || _global$7$2, num); }; BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$7$1).red, "redIAdd works only with red numbers"); - return (this || _global$7$1).red.iadd(this || _global$7$1, num); + assert((this || _global$7$2).red, "redIAdd works only with red numbers"); + return (this || _global$7$2).red.iadd(this || _global$7$2, num); }; BN.prototype.redSub = function redSub(num) { - assert((this || _global$7$1).red, "redSub works only with red numbers"); - return (this || _global$7$1).red.sub(this || _global$7$1, num); + assert((this || _global$7$2).red, "redSub works only with red numbers"); + return (this || _global$7$2).red.sub(this || _global$7$2, num); }; BN.prototype.redISub = function redISub(num) { - assert((this || _global$7$1).red, "redISub works only with red numbers"); - return (this || _global$7$1).red.isub(this || _global$7$1, num); + assert((this || _global$7$2).red, "redISub works only with red numbers"); + return (this || _global$7$2).red.isub(this || _global$7$2, num); }; BN.prototype.redShl = function redShl(num) { - assert((this || _global$7$1).red, "redShl works only with red numbers"); - return (this || _global$7$1).red.shl(this || _global$7$1, num); + assert((this || _global$7$2).red, "redShl works only with red numbers"); + return (this || _global$7$2).red.shl(this || _global$7$2, num); }; BN.prototype.redMul = function redMul(num) { - assert((this || _global$7$1).red, "redMul works only with red numbers"); + assert((this || _global$7$2).red, "redMul works only with red numbers"); - (this || _global$7$1).red._verify2(this || _global$7$1, num); + (this || _global$7$2).red._verify2(this || _global$7$2, num); - return (this || _global$7$1).red.mul(this || _global$7$1, num); + return (this || _global$7$2).red.mul(this || _global$7$2, num); }; BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$7$1).red, "redMul works only with red numbers"); + assert((this || _global$7$2).red, "redMul works only with red numbers"); - (this || _global$7$1).red._verify2(this || _global$7$1, num); + (this || _global$7$2).red._verify2(this || _global$7$2, num); - return (this || _global$7$1).red.imul(this || _global$7$1, num); + return (this || _global$7$2).red.imul(this || _global$7$2, num); }; BN.prototype.redSqr = function redSqr() { - assert((this || _global$7$1).red, "redSqr works only with red numbers"); + assert((this || _global$7$2).red, "redSqr works only with red numbers"); - (this || _global$7$1).red._verify1(this || _global$7$1); + (this || _global$7$2).red._verify1(this || _global$7$2); - return (this || _global$7$1).red.sqr(this || _global$7$1); + return (this || _global$7$2).red.sqr(this || _global$7$2); }; BN.prototype.redISqr = function redISqr() { - assert((this || _global$7$1).red, "redISqr works only with red numbers"); + assert((this || _global$7$2).red, "redISqr works only with red numbers"); - (this || _global$7$1).red._verify1(this || _global$7$1); + (this || _global$7$2).red._verify1(this || _global$7$2); - return (this || _global$7$1).red.isqr(this || _global$7$1); + return (this || _global$7$2).red.isqr(this || _global$7$2); }; // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$7$1).red, "redSqrt works only with red numbers"); + assert((this || _global$7$2).red, "redSqrt works only with red numbers"); - (this || _global$7$1).red._verify1(this || _global$7$1); + (this || _global$7$2).red._verify1(this || _global$7$2); - return (this || _global$7$1).red.sqrt(this || _global$7$1); + return (this || _global$7$2).red.sqrt(this || _global$7$2); }; BN.prototype.redInvm = function redInvm() { - assert((this || _global$7$1).red, "redInvm works only with red numbers"); + assert((this || _global$7$2).red, "redInvm works only with red numbers"); - (this || _global$7$1).red._verify1(this || _global$7$1); + (this || _global$7$2).red._verify1(this || _global$7$2); - return (this || _global$7$1).red.invm(this || _global$7$1); + return (this || _global$7$2).red.invm(this || _global$7$2); }; // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$7$1).red, "redNeg works only with red numbers"); + assert((this || _global$7$2).red, "redNeg works only with red numbers"); - (this || _global$7$1).red._verify1(this || _global$7$1); + (this || _global$7$2).red._verify1(this || _global$7$2); - return (this || _global$7$1).red.neg(this || _global$7$1); + return (this || _global$7$2).red.neg(this || _global$7$2); }; BN.prototype.redPow = function redPow(num) { - assert((this || _global$7$1).red && !num.red, "redPow(normalNum)"); + assert((this || _global$7$2).red && !num.red, "redPow(normalNum)"); - (this || _global$7$1).red._verify1(this || _global$7$1); + (this || _global$7$2).red._verify1(this || _global$7$2); - return (this || _global$7$1).red.pow(this || _global$7$1, num); + return (this || _global$7$2).red.pow(this || _global$7$2, num); }; // Prime numbers with efficient reduction @@ -29768,16 +64376,16 @@ function dew$X$1() { function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$7$1).name = name; - (this || _global$7$1).p = new BN(p, 16); - (this || _global$7$1).n = (this || _global$7$1).p.bitLength(); - (this || _global$7$1).k = new BN(1).iushln((this || _global$7$1).n).isub((this || _global$7$1).p); - (this || _global$7$1).tmp = this._tmp(); + (this || _global$7$2).name = name; + (this || _global$7$2).p = new BN(p, 16); + (this || _global$7$2).n = (this || _global$7$2).p.bitLength(); + (this || _global$7$2).k = new BN(1).iushln((this || _global$7$2).n).isub((this || _global$7$2).p); + (this || _global$7$2).tmp = this._tmp(); } MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$7$1).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$7$2).n / 13)); return tmp; }; @@ -29788,19 +64396,19 @@ function dew$X$1() { var rlen; do { - this.split(r, (this || _global$7$1).tmp); + this.split(r, (this || _global$7$2).tmp); r = this.imulK(r); - r = r.iadd((this || _global$7$1).tmp); + r = r.iadd((this || _global$7$2).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$7$1).n); + } while (rlen > (this || _global$7$2).n); - var cmp = rlen < (this || _global$7$1).n ? -1 : r.ucmp((this || _global$7$1).p); + var cmp = rlen < (this || _global$7$2).n ? -1 : r.ucmp((this || _global$7$2).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$7$1).p); + r.isub((this || _global$7$2).p); } else { if (r.strip !== undefined) { // r is a BN v4 instance @@ -29815,15 +64423,15 @@ function dew$X$1() { }; MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$7$1).n, 0, out); + input.iushrn((this || _global$7$2).n, 0, out); }; MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$7$1).k); + return num.imul((this || _global$7$2).k); }; function K256() { - MPrime.call(this || _global$7$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$7$2, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } inherits(K256, MPrime); @@ -29893,20 +64501,20 @@ function dew$X$1() { }; function P224() { - MPrime.call(this || _global$7$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$7$2, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } inherits(P224, MPrime); function P192() { - MPrime.call(this || _global$7$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$7$2, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } inherits(P192, MPrime); function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$7$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$7$2, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } inherits(P25519, MPrime); @@ -29959,12 +64567,12 @@ function dew$X$1() { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$7$1).m = prime.p; - (this || _global$7$1).prime = prime; + (this || _global$7$2).m = prime.p; + (this || _global$7$2).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$7$1).m = m; - (this || _global$7$1).prime = null; + (this || _global$7$2).m = m; + (this || _global$7$2).prime = null; } } @@ -29979,8 +64587,8 @@ function dew$X$1() { }; Red.prototype.imod = function imod(a) { - if ((this || _global$7$1).prime) return (this || _global$7$1).prime.ireduce(a)._forceRed(this || _global$7$1); - move(a, a.umod((this || _global$7$1).m)._forceRed(this || _global$7$1)); + if ((this || _global$7$2).prime) return (this || _global$7$2).prime.ireduce(a)._forceRed(this || _global$7$2); + move(a, a.umod((this || _global$7$2).m)._forceRed(this || _global$7$2)); return a; }; @@ -29989,7 +64597,7 @@ function dew$X$1() { return a.clone(); } - return (this || _global$7$1).m.sub(a)._forceRed(this || _global$7$1); + return (this || _global$7$2).m.sub(a)._forceRed(this || _global$7$2); }; Red.prototype.add = function add(a, b) { @@ -29997,11 +64605,11 @@ function dew$X$1() { var res = a.add(b); - if (res.cmp((this || _global$7$1).m) >= 0) { - res.isub((this || _global$7$1).m); + if (res.cmp((this || _global$7$2).m) >= 0) { + res.isub((this || _global$7$2).m); } - return res._forceRed(this || _global$7$1); + return res._forceRed(this || _global$7$2); }; Red.prototype.iadd = function iadd(a, b) { @@ -30009,8 +64617,8 @@ function dew$X$1() { var res = a.iadd(b); - if (res.cmp((this || _global$7$1).m) >= 0) { - res.isub((this || _global$7$1).m); + if (res.cmp((this || _global$7$2).m) >= 0) { + res.isub((this || _global$7$2).m); } return res; @@ -30022,10 +64630,10 @@ function dew$X$1() { var res = a.sub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$7$1).m); + res.iadd((this || _global$7$2).m); } - return res._forceRed(this || _global$7$1); + return res._forceRed(this || _global$7$2); }; Red.prototype.isub = function isub(a, b) { @@ -30034,7 +64642,7 @@ function dew$X$1() { var res = a.isub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$7$1).m); + res.iadd((this || _global$7$2).m); } return res; @@ -30069,12 +64677,12 @@ function dew$X$1() { Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$7$1).m.andln(3); + var mod3 = (this || _global$7$2).m.andln(3); assert(mod3 % 2 === 1); // Fast case if (mod3 === 3) { - var pow = (this || _global$7$1).m.add(new BN(1)).iushrn(2); + var pow = (this || _global$7$2).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); } // Tonelli-Shanks algorithm (Totally unoptimized and slow) @@ -30082,7 +64690,7 @@ function dew$X$1() { // Find Q and S, that Q * 2 ^ S = (P - 1) - var q = (this || _global$7$1).m.subn(1); + var q = (this || _global$7$2).m.subn(1); var s = 0; @@ -30092,15 +64700,15 @@ function dew$X$1() { } assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$7$1); + var one = new BN(1).toRed(this || _global$7$2); var nOne = one.redNeg(); // Find quadratic non-residue // NOTE: Max is such because of generalized Riemann hypothesis. - var lpow = (this || _global$7$1).m.subn(1).iushrn(1); + var lpow = (this || _global$7$2).m.subn(1).iushrn(1); - var z = (this || _global$7$1).m.bitLength(); + var z = (this || _global$7$2).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$7$1); + z = new BN(2 * z * z).toRed(this || _global$7$2); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); @@ -30130,7 +64738,7 @@ function dew$X$1() { }; Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$7$1).m); + var inv = a._invmp((this || _global$7$2).m); if (inv.negative !== 0) { inv.negative = 0; @@ -30141,11 +64749,11 @@ function dew$X$1() { }; Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$7$1); + if (num.isZero()) return new BN(1).toRed(this || _global$7$2); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$7$1); + wnd[0] = new BN(1).toRed(this || _global$7$2); wnd[1] = a; for (var i = 2; i < wnd.length; i++) { @@ -30192,7 +64800,7 @@ function dew$X$1() { }; Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$7$1).m); + var r = num.umod((this || _global$7$2).m); return r === num ? r.clone() : r; }; @@ -30210,29 +64818,29 @@ function dew$X$1() { }; function Mont(m) { - Red.call(this || _global$7$1, m); - (this || _global$7$1).shift = (this || _global$7$1).m.bitLength(); + Red.call(this || _global$7$2, m); + (this || _global$7$2).shift = (this || _global$7$2).m.bitLength(); - if ((this || _global$7$1).shift % 26 !== 0) { - (this || _global$7$1).shift += 26 - (this || _global$7$1).shift % 26; + if ((this || _global$7$2).shift % 26 !== 0) { + (this || _global$7$2).shift += 26 - (this || _global$7$2).shift % 26; } - (this || _global$7$1).r = new BN(1).iushln((this || _global$7$1).shift); - (this || _global$7$1).r2 = this.imod((this || _global$7$1).r.sqr()); - (this || _global$7$1).rinv = (this || _global$7$1).r._invmp((this || _global$7$1).m); - (this || _global$7$1).minv = (this || _global$7$1).rinv.mul((this || _global$7$1).r).isubn(1).div((this || _global$7$1).m); - (this || _global$7$1).minv = (this || _global$7$1).minv.umod((this || _global$7$1).r); - (this || _global$7$1).minv = (this || _global$7$1).r.sub((this || _global$7$1).minv); + (this || _global$7$2).r = new BN(1).iushln((this || _global$7$2).shift); + (this || _global$7$2).r2 = this.imod((this || _global$7$2).r.sqr()); + (this || _global$7$2).rinv = (this || _global$7$2).r._invmp((this || _global$7$2).m); + (this || _global$7$2).minv = (this || _global$7$2).rinv.mul((this || _global$7$2).r).isubn(1).div((this || _global$7$2).m); + (this || _global$7$2).minv = (this || _global$7$2).minv.umod((this || _global$7$2).r); + (this || _global$7$2).minv = (this || _global$7$2).r.sub((this || _global$7$2).minv); } inherits(Mont, Red); Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$7$1).shift)); + return this.imod(num.ushln((this || _global$7$2).shift)); }; Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$7$1).rinv)); + var r = this.imod(num.mul((this || _global$7$2).rinv)); r.red = null; return r; }; @@ -30245,55 +64853,55 @@ function dew$X$1() { } var t = a.imul(b); - var c = t.maskn((this || _global$7$1).shift).mul((this || _global$7$1).minv).imaskn((this || _global$7$1).shift).mul((this || _global$7$1).m); - var u = t.isub(c).iushrn((this || _global$7$1).shift); + var c = t.maskn((this || _global$7$2).shift).mul((this || _global$7$2).minv).imaskn((this || _global$7$2).shift).mul((this || _global$7$2).m); + var u = t.isub(c).iushrn((this || _global$7$2).shift); var res = u; - if (u.cmp((this || _global$7$1).m) >= 0) { - res = u.isub((this || _global$7$1).m); + if (u.cmp((this || _global$7$2).m) >= 0) { + res = u.isub((this || _global$7$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$7$1).m); + res = u.iadd((this || _global$7$2).m); } - return res._forceRed(this || _global$7$1); + return res._forceRed(this || _global$7$2); }; Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$7$1); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$7$2); var t = a.mul(b); - var c = t.maskn((this || _global$7$1).shift).mul((this || _global$7$1).minv).imaskn((this || _global$7$1).shift).mul((this || _global$7$1).m); - var u = t.isub(c).iushrn((this || _global$7$1).shift); + var c = t.maskn((this || _global$7$2).shift).mul((this || _global$7$2).minv).imaskn((this || _global$7$2).shift).mul((this || _global$7$2).m); + var u = t.isub(c).iushrn((this || _global$7$2).shift); var res = u; - if (u.cmp((this || _global$7$1).m) >= 0) { - res = u.isub((this || _global$7$1).m); + if (u.cmp((this || _global$7$2).m) >= 0) { + res = u.isub((this || _global$7$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$7$1).m); + res = u.iadd((this || _global$7$2).m); } - return res._forceRed(this || _global$7$1); + return res._forceRed(this || _global$7$2); }; Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$7$1).m).mul((this || _global$7$1).r2)); - return res._forceRed(this || _global$7$1); + var res = this.imod(a._invmp((this || _global$7$2).m).mul((this || _global$7$2).r2)); + return res._forceRed(this || _global$7$2); }; - })(module$4$1, exports$X$1); + })(module$4$2, exports$Y$2); - return module$4$1.exports; + return module$4$2.exports; } -var exports$W$1 = {}, - _dewExec$W$1 = false; -function dew$W$1() { - if (_dewExec$W$1) return exports$W$1; - _dewExec$W$1 = true; - var Buffer = e$1$1$1.Buffer; +var exports$X$2 = {}, + _dewExec$W$2 = false; +function dew$W$2() { + if (_dewExec$W$2) return exports$X$2; + _dewExec$W$2 = true; + var Buffer = buffer.Buffer; - var BN = dew$X$1(); + var BN = dew$X$2(); - var randomBytes = dew$1S(); + var randomBytes = dew$2O(); function blind(priv) { var r = getr(priv); @@ -30331,57 +64939,41 @@ function dew$W$1() { } crt.getr = getr; - exports$W$1 = crt; - return exports$W$1; + exports$X$2 = crt; + return exports$X$2; } -var _package$1 = { - "_args": [ - [ - "elliptic@6.5.4", - "C:\\Users\\guybe\\Projects\\rollup-plugin-jspm" - ] +var _package$2 = { + "name": "elliptic", + "version": "6.5.4", + "description": "EC cryptography", + "main": "lib/elliptic.js", + "files": [ + "lib" ], - "_from": "elliptic@6.5.4", - "_id": "elliptic@6.5.4", - "_inBundle": false, - "_integrity": "sha512-iLhC6ULemrljPZb+QutR5TQGB+pdW6KGD5RSegS+8sorOZT+rdQFbsQFJgvN3eRqNALqJer4oQ16YvJHlU8hzQ==", - "_location": "/@jspm/core/elliptic", - "_phantomChildren": {}, - "_requested": { - "type": "version", - "registry": true, - "raw": "elliptic@6.5.4", - "name": "elliptic", - "escapedName": "elliptic", - "rawSpec": "6.5.4", - "saveSpec": null, - "fetchSpec": "6.5.4" + "scripts": { + "lint": "eslint lib test", + "lint:fix": "npm run lint -- --fix", + "unit": "istanbul test _mocha --reporter=spec test/index.js", + "test": "npm run lint && npm run unit", + "version": "grunt dist && git add dist/" }, - "_requiredBy": [ - "/@jspm/core/browserify-sign", - "/@jspm/core/create-ecdh" - ], - "_resolved": "https://registry.npmjs.org/elliptic/-/elliptic-6.5.4.tgz", - "_spec": "6.5.4", - "_where": "C:\\Users\\guybe\\Projects\\rollup-plugin-jspm", - "author": { - "name": "Fedor Indutny", - "email": "fedor@indutny.com" + "repository": { + "type": "git", + "url": "git@github.com:indutny/elliptic" }, + "keywords": [ + "EC", + "Elliptic", + "curve", + "Cryptography" + ], + "author": "Fedor Indutny ", + "license": "MIT", "bugs": { "url": "https://github.com/indutny/elliptic/issues" }, - "dependencies": { - "bn.js": "^4.11.9", - "brorand": "^1.1.0", - "hash.js": "^1.0.0", - "hmac-drbg": "^1.0.1", - "inherits": "^2.0.4", - "minimalistic-assert": "^1.0.1", - "minimalistic-crypto-utils": "^1.0.1" - }, - "description": "EC cryptography", + "homepage": "https://github.com/indutny/elliptic", "devDependencies": { "brfs": "^2.0.2", "coveralls": "^3.1.0", @@ -30397,44 +64989,28 @@ var _package$1 = { "istanbul": "^0.4.5", "mocha": "^8.0.1" }, - "files": [ - "lib" - ], - "homepage": "https://github.com/indutny/elliptic", - "keywords": [ - "EC", - "Elliptic", - "curve", - "Cryptography" - ], - "license": "MIT", - "main": "lib/elliptic.js", - "name": "elliptic", - "repository": { - "type": "git", - "url": "git+ssh://git@github.com/indutny/elliptic.git" - }, - "scripts": { - "lint": "eslint lib test", - "lint:fix": "npm run lint -- --fix", - "test": "npm run lint && npm run unit", - "unit": "istanbul test _mocha --reporter=spec test/index.js", - "version": "grunt dist && git add dist/" - }, - "version": "6.5.4" + "dependencies": { + "bn.js": "^4.11.9", + "brorand": "^1.1.0", + "hash.js": "^1.0.0", + "hmac-drbg": "^1.0.1", + "inherits": "^2.0.4", + "minimalistic-assert": "^1.0.1", + "minimalistic-crypto-utils": "^1.0.1" + } }; -var exports$V$1 = {}, - _dewExec$V$1 = false; -var module$3$1 = { - exports: exports$V$1 +var exports$W$2 = {}, + _dewExec$V$2 = false; +var module$3$2 = { + exports: exports$W$2 }; -var _global$6$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$6$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$V$1() { - if (_dewExec$V$1) return module$3$1.exports; - _dewExec$V$1 = true; +function dew$V$2() { + if (_dewExec$V$2) return module$3$2.exports; + _dewExec$V$2 = true; (function (module, exports) { @@ -30460,11 +65036,11 @@ function dew$V$1() { return number; } - (this || _global$6$1).negative = 0; - (this || _global$6$1).words = null; - (this || _global$6$1).length = 0; // Reduction context + (this || _global$6$2).negative = 0; + (this || _global$6$2).words = null; + (this || _global$6$2).length = 0; // Reduction context - (this || _global$6$1).red = null; + (this || _global$6$2).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -30490,7 +65066,7 @@ function dew$V$1() { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = e$1$1$1.Buffer; + Buffer = buffer.Buffer; } } catch (e) {} @@ -30531,7 +65107,7 @@ function dew$V$1() { if (number[0] === "-") { start++; - (this || _global$6$1).negative = 1; + (this || _global$6$2).negative = 1; } if (start < number.length) { @@ -30549,21 +65125,21 @@ function dew$V$1() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$6$1).negative = 1; + (this || _global$6$2).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$6$1).words = [number & 67108863]; - (this || _global$6$1).length = 1; + (this || _global$6$2).words = [number & 67108863]; + (this || _global$6$2).length = 1; } else if (number < 4503599627370496) { - (this || _global$6$1).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$6$1).length = 2; + (this || _global$6$2).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$6$2).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$6$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$6$1).length = 3; + (this || _global$6$2).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$6$2).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -30576,16 +65152,16 @@ function dew$V$1() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$6$1).words = [0]; - (this || _global$6$1).length = 1; - return this || _global$6$1; + (this || _global$6$2).words = [0]; + (this || _global$6$2).length = 1; + return this || _global$6$2; } - (this || _global$6$1).length = Math.ceil(number.length / 3); - (this || _global$6$1).words = new Array((this || _global$6$1).length); + (this || _global$6$2).length = Math.ceil(number.length / 3); + (this || _global$6$2).words = new Array((this || _global$6$2).length); - for (var i = 0; i < (this || _global$6$1).length; i++) { - (this || _global$6$1).words[i] = 0; + for (var i = 0; i < (this || _global$6$2).length; i++) { + (this || _global$6$2).words[i] = 0; } var j, w; @@ -30594,8 +65170,8 @@ function dew$V$1() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$6$1).words[j] |= w << off & 67108863; - (this || _global$6$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$6$2).words[j] |= w << off & 67108863; + (this || _global$6$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -30606,8 +65182,8 @@ function dew$V$1() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$6$1).words[j] |= w << off & 67108863; - (this || _global$6$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$6$2).words[j] |= w << off & 67108863; + (this || _global$6$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -30644,11 +65220,11 @@ function dew$V$1() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$6$1).length = Math.ceil((number.length - start) / 6); - (this || _global$6$1).words = new Array((this || _global$6$1).length); + (this || _global$6$2).length = Math.ceil((number.length - start) / 6); + (this || _global$6$2).words = new Array((this || _global$6$2).length); - for (var i = 0; i < (this || _global$6$1).length; i++) { - (this || _global$6$1).words[i] = 0; + for (var i = 0; i < (this || _global$6$2).length; i++) { + (this || _global$6$2).words[i] = 0; } // 24-bits chunks @@ -30659,12 +65235,12 @@ function dew$V$1() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$6$1).words[j] |= w & 67108863; + (this || _global$6$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$6$1).words[j] |= w >>> 26; + (this || _global$6$2).words[j] |= w >>> 26; } else { off += 8; } @@ -30674,12 +65250,12 @@ function dew$V$1() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$6$1).words[j] |= w & 67108863; + (this || _global$6$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$6$1).words[j] |= w >>> 26; + (this || _global$6$2).words[j] |= w >>> 26; } else { off += 8; } @@ -30711,8 +65287,8 @@ function dew$V$1() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$6$1).words = [0]; - (this || _global$6$1).length = 1; // Find length of limb in base + (this || _global$6$2).words = [0]; + (this || _global$6$2).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -30729,8 +65305,8 @@ function dew$V$1() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$6$1).words[0] + word < 67108864) { - (this || _global$6$1).words[0] += word; + if ((this || _global$6$2).words[0] + word < 67108864) { + (this || _global$6$2).words[0] += word; } else { this._iaddn(word); } @@ -30746,8 +65322,8 @@ function dew$V$1() { this.imuln(pow); - if ((this || _global$6$1).words[0] + word < 67108864) { - (this || _global$6$1).words[0] += word; + if ((this || _global$6$2).words[0] + word < 67108864) { + (this || _global$6$2).words[0] += word; } else { this._iaddn(word); } @@ -30757,15 +65333,15 @@ function dew$V$1() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$6$1).length); + dest.words = new Array((this || _global$6$2).length); - for (var i = 0; i < (this || _global$6$1).length; i++) { - dest.words[i] = (this || _global$6$1).words[i]; + for (var i = 0; i < (this || _global$6$2).length; i++) { + dest.words[i] = (this || _global$6$2).words[i]; } - dest.length = (this || _global$6$1).length; - dest.negative = (this || _global$6$1).negative; - dest.red = (this || _global$6$1).red; + dest.length = (this || _global$6$2).length; + dest.negative = (this || _global$6$2).negative; + dest.red = (this || _global$6$2).red; }; BN.prototype.clone = function clone() { @@ -30775,17 +65351,17 @@ function dew$V$1() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$6$1).length < size) { - (this || _global$6$1).words[(this || _global$6$1).length++] = 0; + while ((this || _global$6$2).length < size) { + (this || _global$6$2).words[(this || _global$6$2).length++] = 0; } - return this || _global$6$1; + return this || _global$6$2; }; // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$6$1).length > 1 && (this || _global$6$1).words[(this || _global$6$1).length - 1] === 0) { - (this || _global$6$1).length--; + while ((this || _global$6$2).length > 1 && (this || _global$6$2).words[(this || _global$6$2).length - 1] === 0) { + (this || _global$6$2).length--; } return this._normSign(); @@ -30793,15 +65369,15 @@ function dew$V$1() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$6$1).length === 1 && (this || _global$6$1).words[0] === 0) { - (this || _global$6$1).negative = 0; + if ((this || _global$6$2).length === 1 && (this || _global$6$2).words[0] === 0) { + (this || _global$6$2).negative = 0; } - return this || _global$6$1; + return this || _global$6$2; }; BN.prototype.inspect = function inspect() { - return ((this || _global$6$1).red ? ""; + return ((this || _global$6$2).red ? ""; }; /* var zeros = []; @@ -30845,12 +65421,12 @@ function dew$V$1() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$6$1).length; i++) { - var w = (this || _global$6$1).words[i]; + for (var i = 0; i < (this || _global$6$2).length; i++) { + var w = (this || _global$6$2).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$6$1).length - 1) { + if (carry !== 0 || i !== (this || _global$6$2).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -30872,7 +65448,7 @@ function dew$V$1() { out = "0" + out; } - if ((this || _global$6$1).negative !== 0) { + if ((this || _global$6$2).negative !== 0) { out = "-" + out; } @@ -30907,7 +65483,7 @@ function dew$V$1() { out = "0" + out; } - if ((this || _global$6$1).negative !== 0) { + if ((this || _global$6$2).negative !== 0) { out = "-" + out; } @@ -30918,18 +65494,18 @@ function dew$V$1() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$6$1).words[0]; + var ret = (this || _global$6$2).words[0]; - if ((this || _global$6$1).length === 2) { - ret += (this || _global$6$1).words[1] * 67108864; - } else if ((this || _global$6$1).length === 3 && (this || _global$6$1).words[2] === 1) { + if ((this || _global$6$2).length === 2) { + ret += (this || _global$6$2).words[1] * 67108864; + } else if ((this || _global$6$2).length === 3 && (this || _global$6$2).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$6$1).words[1] * 67108864; - } else if ((this || _global$6$1).length > 2) { + ret += 4503599627370496 + (this || _global$6$2).words[1] * 67108864; + } else if ((this || _global$6$2).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$6$1).negative !== 0 ? -ret : ret; + return (this || _global$6$2).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -31050,11 +65626,11 @@ function dew$V$1() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$6$1).words[(this || _global$6$1).length - 1]; + var w = (this || _global$6$2).words[(this || _global$6$2).length - 1]; var hi = this._countBits(w); - return ((this || _global$6$1).length - 1) * 26 + hi; + return ((this || _global$6$2).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -31074,8 +65650,8 @@ function dew$V$1() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$6$1).length; i++) { - var b = this._zeroBits((this || _global$6$1).words[i]); + for (var i = 0; i < (this || _global$6$2).length; i++) { + var b = this._zeroBits((this || _global$6$2).words[i]); r += b; if (b !== 26) break; @@ -31089,7 +65665,7 @@ function dew$V$1() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$6$1).negative !== 0) { + if ((this || _global$6$2).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -31105,7 +65681,7 @@ function dew$V$1() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$6$1).negative !== 0; + return (this || _global$6$2).negative !== 0; }; // Return negative clone of `this` @@ -31115,39 +65691,39 @@ function dew$V$1() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$6$1).negative ^= 1; + (this || _global$6$2).negative ^= 1; } - return this || _global$6$1; + return this || _global$6$2; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$6$1).length < num.length) { - (this || _global$6$1).words[(this || _global$6$1).length++] = 0; + while ((this || _global$6$2).length < num.length) { + (this || _global$6$2).words[(this || _global$6$2).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$6$1).words[i] = (this || _global$6$1).words[i] | num.words[i]; + (this || _global$6$2).words[i] = (this || _global$6$2).words[i] | num.words[i]; } return this.strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$6$1).negative | num.negative) === 0); + assert(((this || _global$6$2).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$6$1).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$6$2); }; BN.prototype.uor = function uor(num) { - if ((this || _global$6$1).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$6$2); }; // And `num` with `this` in-place @@ -31155,34 +65731,34 @@ function dew$V$1() { // b = min-length(num, this) var b; - if ((this || _global$6$1).length > num.length) { + if ((this || _global$6$2).length > num.length) { b = num; } else { - b = this || _global$6$1; + b = this || _global$6$2; } for (var i = 0; i < b.length; i++) { - (this || _global$6$1).words[i] = (this || _global$6$1).words[i] & num.words[i]; + (this || _global$6$2).words[i] = (this || _global$6$2).words[i] & num.words[i]; } - (this || _global$6$1).length = b.length; + (this || _global$6$2).length = b.length; return this.strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$6$1).negative | num.negative) === 0); + assert(((this || _global$6$2).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$6$1).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$6$2); }; BN.prototype.uand = function uand(num) { - if ((this || _global$6$1).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$6$2); }; // Xor `num` with `this` in-place @@ -31191,42 +65767,42 @@ function dew$V$1() { var a; var b; - if ((this || _global$6$1).length > num.length) { - a = this || _global$6$1; + if ((this || _global$6$2).length > num.length) { + a = this || _global$6$2; b = num; } else { a = num; - b = this || _global$6$1; + b = this || _global$6$2; } for (var i = 0; i < b.length; i++) { - (this || _global$6$1).words[i] = a.words[i] ^ b.words[i]; + (this || _global$6$2).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$6$1) !== a) { + if ((this || _global$6$2) !== a) { for (; i < a.length; i++) { - (this || _global$6$1).words[i] = a.words[i]; + (this || _global$6$2).words[i] = a.words[i]; } } - (this || _global$6$1).length = a.length; + (this || _global$6$2).length = a.length; return this.strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$6$1).negative | num.negative) === 0); + assert(((this || _global$6$2).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$6$1).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$6$2); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$6$1).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$6$2); }; // Not ``this`` with ``width`` bitwidth @@ -31243,12 +65819,12 @@ function dew$V$1() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$6$1).words[i] = ~(this || _global$6$1).words[i] & 67108863; + (this || _global$6$2).words[i] = ~(this || _global$6$2).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$6$1).words[i] = ~(this || _global$6$1).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$6$2).words[i] = ~(this || _global$6$2).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -31268,9 +65844,9 @@ function dew$V$1() { this._expand(off + 1); if (val) { - (this || _global$6$1).words[off] = (this || _global$6$1).words[off] | 1 << wbit; + (this || _global$6$2).words[off] = (this || _global$6$2).words[off] | 1 << wbit; } else { - (this || _global$6$1).words[off] = (this || _global$6$1).words[off] & ~(1 << wbit); + (this || _global$6$2).words[off] = (this || _global$6$2).words[off] & ~(1 << wbit); } return this.strip(); @@ -31280,12 +65856,12 @@ function dew$V$1() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$6$1).negative !== 0 && num.negative === 0) { - (this || _global$6$1).negative = 0; + if ((this || _global$6$2).negative !== 0 && num.negative === 0) { + (this || _global$6$2).negative = 0; r = this.isub(num); - (this || _global$6$1).negative ^= 1; + (this || _global$6$2).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$6$1).negative === 0 && num.negative !== 0) { + } else if ((this || _global$6$2).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -31295,60 +65871,60 @@ function dew$V$1() { var a, b; - if ((this || _global$6$1).length > num.length) { - a = this || _global$6$1; + if ((this || _global$6$2).length > num.length) { + a = this || _global$6$2; b = num; } else { a = num; - b = this || _global$6$1; + b = this || _global$6$2; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$6$1).words[i] = r & 67108863; + (this || _global$6$2).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$6$1).words[i] = r & 67108863; + (this || _global$6$2).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$6$1).length = a.length; + (this || _global$6$2).length = a.length; if (carry !== 0) { - (this || _global$6$1).words[(this || _global$6$1).length] = carry; - (this || _global$6$1).length++; // Copy the rest of the words - } else if (a !== (this || _global$6$1)) { + (this || _global$6$2).words[(this || _global$6$2).length] = carry; + (this || _global$6$2).length++; // Copy the rest of the words + } else if (a !== (this || _global$6$2)) { for (; i < a.length; i++) { - (this || _global$6$1).words[i] = a.words[i]; + (this || _global$6$2).words[i] = a.words[i]; } } - return this || _global$6$1; + return this || _global$6$2; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$6$1).negative === 0) { + if (num.negative !== 0 && (this || _global$6$2).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$6$1).negative !== 0) { - (this || _global$6$1).negative = 0; - res = num.sub(this || _global$6$1); - (this || _global$6$1).negative = 1; + } else if (num.negative === 0 && (this || _global$6$2).negative !== 0) { + (this || _global$6$2).negative = 0; + res = num.sub(this || _global$6$2); + (this || _global$6$2).negative = 1; return res; } - if ((this || _global$6$1).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$6$1); + if ((this || _global$6$2).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$6$2); }; // Subtract `num` from `this` in-place @@ -31359,10 +65935,10 @@ function dew$V$1() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$6$1).negative !== 0) { - (this || _global$6$1).negative = 0; + } else if ((this || _global$6$2).negative !== 0) { + (this || _global$6$2).negative = 0; this.iadd(num); - (this || _global$6$1).negative = 1; + (this || _global$6$2).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -31370,21 +65946,21 @@ function dew$V$1() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$6$1).negative = 0; - (this || _global$6$1).length = 1; - (this || _global$6$1).words[0] = 0; - return this || _global$6$1; + (this || _global$6$2).negative = 0; + (this || _global$6$2).length = 1; + (this || _global$6$2).words[0] = 0; + return this || _global$6$2; } // a > b var a, b; if (cmp > 0) { - a = this || _global$6$1; + a = this || _global$6$2; b = num; } else { a = num; - b = this || _global$6$1; + b = this || _global$6$2; } var carry = 0; @@ -31392,26 +65968,26 @@ function dew$V$1() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$6$1).words[i] = r & 67108863; + (this || _global$6$2).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$6$1).words[i] = r & 67108863; + (this || _global$6$2).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$6$1)) { + if (carry === 0 && i < a.length && a !== (this || _global$6$2)) { for (; i < a.length; i++) { - (this || _global$6$1).words[i] = a.words[i]; + (this || _global$6$2).words[i] = a.words[i]; } } - (this || _global$6$1).length = Math.max((this || _global$6$1).length, i); + (this || _global$6$2).length = Math.max((this || _global$6$2).length, i); - if (a !== (this || _global$6$1)) { - (this || _global$6$1).negative = 1; + if (a !== (this || _global$6$2)) { + (this || _global$6$2).negative = 1; } return this.strip(); @@ -32114,16 +66690,16 @@ function dew$V$1() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$6$1).length + num.length; + var len = (this || _global$6$2).length + num.length; - if ((this || _global$6$1).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$6$1, num, out); + if ((this || _global$6$2).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$6$2, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$6$1, num, out); + res = smallMulTo(this || _global$6$2, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$6$1, num, out); + res = bigMulTo(this || _global$6$2, num, out); } else { - res = jumboMulTo(this || _global$6$1, num, out); + res = jumboMulTo(this || _global$6$2, num, out); } return res; @@ -32132,8 +66708,8 @@ function dew$V$1() { function FFTM(x, y) { - (this || _global$6$1).x = x; - (this || _global$6$1).y = y; + (this || _global$6$2).x = x; + (this || _global$6$2).y = y; } FFTM.prototype.makeRBT = function makeRBT(N) { @@ -32314,20 +66890,20 @@ function dew$V$1() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$6$1).length + num.length); + out.words = new Array((this || _global$6$2).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$6$1).length + num.length); - return jumboMulTo(this || _global$6$1, num, out); + out.words = new Array((this || _global$6$2).length + num.length); + return jumboMulTo(this || _global$6$2, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$6$1); + return this.clone().mulTo(num, this || _global$6$2); }; BN.prototype.imuln = function imuln(num) { @@ -32336,22 +66912,22 @@ function dew$V$1() { var carry = 0; - for (var i = 0; i < (this || _global$6$1).length; i++) { - var w = ((this || _global$6$1).words[i] | 0) * num; + for (var i = 0; i < (this || _global$6$2).length; i++) { + var w = ((this || _global$6$2).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$6$1).words[i] = lo & 67108863; + (this || _global$6$2).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$6$1).words[i] = carry; - (this || _global$6$1).length++; + (this || _global$6$2).words[i] = carry; + (this || _global$6$2).length++; } - return this || _global$6$1; + return this || _global$6$2; }; BN.prototype.muln = function muln(num) { @@ -32360,7 +66936,7 @@ function dew$V$1() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$6$1); + return this.mul(this || _global$6$2); }; // `this` * `this` in-place @@ -32373,7 +66949,7 @@ function dew$V$1() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$6$1; + var res = this || _global$6$2; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -32400,29 +66976,29 @@ function dew$V$1() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$6$1).length; i++) { - var newCarry = (this || _global$6$1).words[i] & carryMask; - var c = ((this || _global$6$1).words[i] | 0) - newCarry << r; - (this || _global$6$1).words[i] = c | carry; + for (i = 0; i < (this || _global$6$2).length; i++) { + var newCarry = (this || _global$6$2).words[i] & carryMask; + var c = ((this || _global$6$2).words[i] | 0) - newCarry << r; + (this || _global$6$2).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$6$1).words[i] = carry; - (this || _global$6$1).length++; + (this || _global$6$2).words[i] = carry; + (this || _global$6$2).length++; } } if (s !== 0) { - for (i = (this || _global$6$1).length - 1; i >= 0; i--) { - (this || _global$6$1).words[i + s] = (this || _global$6$1).words[i]; + for (i = (this || _global$6$2).length - 1; i >= 0; i--) { + (this || _global$6$2).words[i + s] = (this || _global$6$2).words[i]; } for (i = 0; i < s; i++) { - (this || _global$6$1).words[i] = 0; + (this || _global$6$2).words[i] = 0; } - (this || _global$6$1).length += s; + (this || _global$6$2).length += s; } return this.strip(); @@ -32430,7 +67006,7 @@ function dew$V$1() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$6$1).negative === 0); + assert((this || _global$6$2).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -32448,7 +67024,7 @@ function dew$V$1() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$6$1).length); + var s = Math.min((bits - r) / 26, (this || _global$6$2).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -32456,28 +67032,28 @@ function dew$V$1() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$6$1).words[i]; + maskedWords.words[i] = (this || _global$6$2).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$6$1).length > s) { - (this || _global$6$1).length -= s; + if (s === 0) ; else if ((this || _global$6$2).length > s) { + (this || _global$6$2).length -= s; - for (i = 0; i < (this || _global$6$1).length; i++) { - (this || _global$6$1).words[i] = (this || _global$6$1).words[i + s]; + for (i = 0; i < (this || _global$6$2).length; i++) { + (this || _global$6$2).words[i] = (this || _global$6$2).words[i + s]; } } else { - (this || _global$6$1).words[0] = 0; - (this || _global$6$1).length = 1; + (this || _global$6$2).words[0] = 0; + (this || _global$6$2).length = 1; } var carry = 0; - for (i = (this || _global$6$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$6$1).words[i] | 0; - (this || _global$6$1).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$6$2).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$6$2).words[i] | 0; + (this || _global$6$2).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -32486,9 +67062,9 @@ function dew$V$1() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$6$1).length === 0) { - (this || _global$6$1).words[0] = 0; - (this || _global$6$1).length = 1; + if ((this || _global$6$2).length === 0) { + (this || _global$6$2).words[0] = 0; + (this || _global$6$2).length = 1; } return this.strip(); @@ -32496,7 +67072,7 @@ function dew$V$1() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$6$1).negative === 0); + assert((this || _global$6$2).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -32525,9 +67101,9 @@ function dew$V$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$6$1).length <= s) return false; // Check bit and return + if ((this || _global$6$2).length <= s) return false; // Check bit and return - var w = (this || _global$6$1).words[s]; + var w = (this || _global$6$2).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -32536,21 +67112,21 @@ function dew$V$1() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$6$1).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$6$2).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$6$1).length <= s) { - return this || _global$6$1; + if ((this || _global$6$2).length <= s) { + return this || _global$6$2; } if (r !== 0) { s++; } - (this || _global$6$1).length = Math.min(s, (this || _global$6$1).length); + (this || _global$6$2).length = Math.min(s, (this || _global$6$2).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$6$1).words[(this || _global$6$1).length - 1] &= mask; + (this || _global$6$2).words[(this || _global$6$2).length - 1] &= mask; } return this.strip(); @@ -32567,17 +67143,17 @@ function dew$V$1() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$6$1).negative !== 0) { - if ((this || _global$6$1).length === 1 && ((this || _global$6$1).words[0] | 0) < num) { - (this || _global$6$1).words[0] = num - ((this || _global$6$1).words[0] | 0); - (this || _global$6$1).negative = 0; - return this || _global$6$1; + if ((this || _global$6$2).negative !== 0) { + if ((this || _global$6$2).length === 1 && ((this || _global$6$2).words[0] | 0) < num) { + (this || _global$6$2).words[0] = num - ((this || _global$6$2).words[0] | 0); + (this || _global$6$2).negative = 0; + return this || _global$6$2; } - (this || _global$6$1).negative = 0; + (this || _global$6$2).negative = 0; this.isubn(num); - (this || _global$6$1).negative = 1; - return this || _global$6$1; + (this || _global$6$2).negative = 1; + return this || _global$6$2; } // Add without checks @@ -32585,20 +67161,20 @@ function dew$V$1() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$6$1).words[0] += num; // Carry + (this || _global$6$2).words[0] += num; // Carry - for (var i = 0; i < (this || _global$6$1).length && (this || _global$6$1).words[i] >= 67108864; i++) { - (this || _global$6$1).words[i] -= 67108864; + for (var i = 0; i < (this || _global$6$2).length && (this || _global$6$2).words[i] >= 67108864; i++) { + (this || _global$6$2).words[i] -= 67108864; - if (i === (this || _global$6$1).length - 1) { - (this || _global$6$1).words[i + 1] = 1; + if (i === (this || _global$6$2).length - 1) { + (this || _global$6$2).words[i + 1] = 1; } else { - (this || _global$6$1).words[i + 1]++; + (this || _global$6$2).words[i + 1]++; } } - (this || _global$6$1).length = Math.max((this || _global$6$1).length, i + 1); - return this || _global$6$1; + (this || _global$6$2).length = Math.max((this || _global$6$2).length, i + 1); + return this || _global$6$2; }; // Subtract plain number `num` from `this` @@ -32607,23 +67183,23 @@ function dew$V$1() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$6$1).negative !== 0) { - (this || _global$6$1).negative = 0; + if ((this || _global$6$2).negative !== 0) { + (this || _global$6$2).negative = 0; this.iaddn(num); - (this || _global$6$1).negative = 1; - return this || _global$6$1; + (this || _global$6$2).negative = 1; + return this || _global$6$2; } - (this || _global$6$1).words[0] -= num; + (this || _global$6$2).words[0] -= num; - if ((this || _global$6$1).length === 1 && (this || _global$6$1).words[0] < 0) { - (this || _global$6$1).words[0] = -(this || _global$6$1).words[0]; - (this || _global$6$1).negative = 1; + if ((this || _global$6$2).length === 1 && (this || _global$6$2).words[0] < 0) { + (this || _global$6$2).words[0] = -(this || _global$6$2).words[0]; + (this || _global$6$2).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$6$1).length && (this || _global$6$1).words[i] < 0; i++) { - (this || _global$6$1).words[i] += 67108864; - (this || _global$6$1).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$6$2).length && (this || _global$6$2).words[i] < 0; i++) { + (this || _global$6$2).words[i] += 67108864; + (this || _global$6$2).words[i + 1] -= 1; } } @@ -32639,8 +67215,8 @@ function dew$V$1() { }; BN.prototype.iabs = function iabs() { - (this || _global$6$1).negative = 0; - return this || _global$6$1; + (this || _global$6$2).negative = 0; + return this || _global$6$2; }; BN.prototype.abs = function abs() { @@ -32657,17 +67233,17 @@ function dew$V$1() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$6$1).words[i + shift] | 0) + carry; + w = ((this || _global$6$2).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$6$1).words[i + shift] = w & 67108863; + (this || _global$6$2).words[i + shift] = w & 67108863; } - for (; i < (this || _global$6$1).length - shift; i++) { - w = ((this || _global$6$1).words[i + shift] | 0) + carry; + for (; i < (this || _global$6$2).length - shift; i++) { + w = ((this || _global$6$2).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$6$1).words[i + shift] = w & 67108863; + (this || _global$6$2).words[i + shift] = w & 67108863; } if (carry === 0) return this.strip(); // Subtraction overflow @@ -32675,18 +67251,18 @@ function dew$V$1() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$6$1).length; i++) { - w = -((this || _global$6$1).words[i] | 0) + carry; + for (i = 0; i < (this || _global$6$2).length; i++) { + w = -((this || _global$6$2).words[i] | 0) + carry; carry = w >> 26; - (this || _global$6$1).words[i] = w & 67108863; + (this || _global$6$2).words[i] = w & 67108863; } - (this || _global$6$1).negative = 1; + (this || _global$6$2).negative = 1; return this.strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$6$1).length - num.length; + var shift = (this || _global$6$2).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -32782,7 +67358,7 @@ function dew$V$1() { var div, mod, res; - if ((this || _global$6$1).negative !== 0 && num.negative === 0) { + if ((this || _global$6$2).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -32803,7 +67379,7 @@ function dew$V$1() { }; } - if ((this || _global$6$1).negative === 0 && num.negative !== 0) { + if ((this || _global$6$2).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -32816,7 +67392,7 @@ function dew$V$1() { }; } - if (((this || _global$6$1).negative & num.negative) !== 0) { + if (((this || _global$6$2).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -32835,10 +67411,10 @@ function dew$V$1() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$6$1).length || this.cmp(num) < 0) { + if (num.length > (this || _global$6$2).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$6$1 + mod: this || _global$6$2 }; } // Very short reduction @@ -32901,8 +67477,8 @@ function dew$V$1() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$6$1).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$6$1).words[i] | 0)) % num; + for (var i = (this || _global$6$2).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$6$2).words[i] | 0)) % num; } return acc; @@ -32913,9 +67489,9 @@ function dew$V$1() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$6$1).length - 1; i >= 0; i--) { - var w = ((this || _global$6$1).words[i] | 0) + carry * 67108864; - (this || _global$6$1).words[i] = w / num | 0; + for (var i = (this || _global$6$2).length - 1; i >= 0; i--) { + var w = ((this || _global$6$2).words[i] | 0) + carry * 67108864; + (this || _global$6$2).words[i] = w / num | 0; carry = w % num; } @@ -32929,7 +67505,7 @@ function dew$V$1() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$6$1; + var x = this || _global$6$2; var y = p.clone(); if (x.negative !== 0) { @@ -33012,7 +67588,7 @@ function dew$V$1() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$6$1; + var a = this || _global$6$2; var b = p.clone(); if (a.negative !== 0) { @@ -33123,16 +67699,16 @@ function dew$V$1() { }; BN.prototype.isEven = function isEven() { - return ((this || _global$6$1).words[0] & 1) === 0; + return ((this || _global$6$2).words[0] & 1) === 0; }; BN.prototype.isOdd = function isOdd() { - return ((this || _global$6$1).words[0] & 1) === 1; + return ((this || _global$6$2).words[0] & 1) === 1; }; // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$6$1).words[0] & num; + return (this || _global$6$2).words[0] & num; }; // Increment at the bit position in-line @@ -33142,44 +67718,44 @@ function dew$V$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$6$1).length <= s) { + if ((this || _global$6$2).length <= s) { this._expand(s + 1); - (this || _global$6$1).words[s] |= q; - return this || _global$6$1; + (this || _global$6$2).words[s] |= q; + return this || _global$6$2; } // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$6$1).length; i++) { - var w = (this || _global$6$1).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$6$2).length; i++) { + var w = (this || _global$6$2).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$6$1).words[i] = w; + (this || _global$6$2).words[i] = w; } if (carry !== 0) { - (this || _global$6$1).words[i] = carry; - (this || _global$6$1).length++; + (this || _global$6$2).words[i] = carry; + (this || _global$6$2).length++; } - return this || _global$6$1; + return this || _global$6$2; }; BN.prototype.isZero = function isZero() { - return (this || _global$6$1).length === 1 && (this || _global$6$1).words[0] === 0; + return (this || _global$6$2).length === 1 && (this || _global$6$2).words[0] === 0; }; BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$6$1).negative !== 0 && !negative) return -1; - if ((this || _global$6$1).negative === 0 && negative) return 1; + if ((this || _global$6$2).negative !== 0 && !negative) return -1; + if ((this || _global$6$2).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$6$1).length > 1) { + if ((this || _global$6$2).length > 1) { res = 1; } else { if (negative) { @@ -33187,11 +67763,11 @@ function dew$V$1() { } assert(num <= 67108863, "Number is too big"); - var w = (this || _global$6$1).words[0] | 0; + var w = (this || _global$6$2).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$6$1).negative !== 0) return -res | 0; + if ((this || _global$6$2).negative !== 0) return -res | 0; return res; }; // Compare two numbers and return: // 1 - if `this` > `num` @@ -33200,22 +67776,22 @@ function dew$V$1() { BN.prototype.cmp = function cmp(num) { - if ((this || _global$6$1).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$6$1).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$6$2).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$6$2).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$6$1).negative !== 0) return -res | 0; + if ((this || _global$6$2).negative !== 0) return -res | 0; return res; }; // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$6$1).length > num.length) return 1; - if ((this || _global$6$1).length < num.length) return -1; + if ((this || _global$6$2).length > num.length) return 1; + if ((this || _global$6$2).length < num.length) return -1; var res = 0; - for (var i = (this || _global$6$1).length - 1; i >= 0; i--) { - var a = (this || _global$6$1).words[i] | 0; + for (var i = (this || _global$6$2).length - 1; i >= 0; i--) { + var a = (this || _global$6$2).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; @@ -33280,115 +67856,115 @@ function dew$V$1() { }; BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$6$1).red, "Already a number in reduction context"); - assert((this || _global$6$1).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$6$1)._forceRed(ctx); + assert(!(this || _global$6$2).red, "Already a number in reduction context"); + assert((this || _global$6$2).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$6$2)._forceRed(ctx); }; BN.prototype.fromRed = function fromRed() { - assert((this || _global$6$1).red, "fromRed works only with numbers in reduction context"); - return (this || _global$6$1).red.convertFrom(this || _global$6$1); + assert((this || _global$6$2).red, "fromRed works only with numbers in reduction context"); + return (this || _global$6$2).red.convertFrom(this || _global$6$2); }; BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$6$1).red = ctx; - return this || _global$6$1; + (this || _global$6$2).red = ctx; + return this || _global$6$2; }; BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$6$1).red, "Already a number in reduction context"); + assert(!(this || _global$6$2).red, "Already a number in reduction context"); return this._forceRed(ctx); }; BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$6$1).red, "redAdd works only with red numbers"); - return (this || _global$6$1).red.add(this || _global$6$1, num); + assert((this || _global$6$2).red, "redAdd works only with red numbers"); + return (this || _global$6$2).red.add(this || _global$6$2, num); }; BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$6$1).red, "redIAdd works only with red numbers"); - return (this || _global$6$1).red.iadd(this || _global$6$1, num); + assert((this || _global$6$2).red, "redIAdd works only with red numbers"); + return (this || _global$6$2).red.iadd(this || _global$6$2, num); }; BN.prototype.redSub = function redSub(num) { - assert((this || _global$6$1).red, "redSub works only with red numbers"); - return (this || _global$6$1).red.sub(this || _global$6$1, num); + assert((this || _global$6$2).red, "redSub works only with red numbers"); + return (this || _global$6$2).red.sub(this || _global$6$2, num); }; BN.prototype.redISub = function redISub(num) { - assert((this || _global$6$1).red, "redISub works only with red numbers"); - return (this || _global$6$1).red.isub(this || _global$6$1, num); + assert((this || _global$6$2).red, "redISub works only with red numbers"); + return (this || _global$6$2).red.isub(this || _global$6$2, num); }; BN.prototype.redShl = function redShl(num) { - assert((this || _global$6$1).red, "redShl works only with red numbers"); - return (this || _global$6$1).red.shl(this || _global$6$1, num); + assert((this || _global$6$2).red, "redShl works only with red numbers"); + return (this || _global$6$2).red.shl(this || _global$6$2, num); }; BN.prototype.redMul = function redMul(num) { - assert((this || _global$6$1).red, "redMul works only with red numbers"); + assert((this || _global$6$2).red, "redMul works only with red numbers"); - (this || _global$6$1).red._verify2(this || _global$6$1, num); + (this || _global$6$2).red._verify2(this || _global$6$2, num); - return (this || _global$6$1).red.mul(this || _global$6$1, num); + return (this || _global$6$2).red.mul(this || _global$6$2, num); }; BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$6$1).red, "redMul works only with red numbers"); + assert((this || _global$6$2).red, "redMul works only with red numbers"); - (this || _global$6$1).red._verify2(this || _global$6$1, num); + (this || _global$6$2).red._verify2(this || _global$6$2, num); - return (this || _global$6$1).red.imul(this || _global$6$1, num); + return (this || _global$6$2).red.imul(this || _global$6$2, num); }; BN.prototype.redSqr = function redSqr() { - assert((this || _global$6$1).red, "redSqr works only with red numbers"); + assert((this || _global$6$2).red, "redSqr works only with red numbers"); - (this || _global$6$1).red._verify1(this || _global$6$1); + (this || _global$6$2).red._verify1(this || _global$6$2); - return (this || _global$6$1).red.sqr(this || _global$6$1); + return (this || _global$6$2).red.sqr(this || _global$6$2); }; BN.prototype.redISqr = function redISqr() { - assert((this || _global$6$1).red, "redISqr works only with red numbers"); + assert((this || _global$6$2).red, "redISqr works only with red numbers"); - (this || _global$6$1).red._verify1(this || _global$6$1); + (this || _global$6$2).red._verify1(this || _global$6$2); - return (this || _global$6$1).red.isqr(this || _global$6$1); + return (this || _global$6$2).red.isqr(this || _global$6$2); }; // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$6$1).red, "redSqrt works only with red numbers"); + assert((this || _global$6$2).red, "redSqrt works only with red numbers"); - (this || _global$6$1).red._verify1(this || _global$6$1); + (this || _global$6$2).red._verify1(this || _global$6$2); - return (this || _global$6$1).red.sqrt(this || _global$6$1); + return (this || _global$6$2).red.sqrt(this || _global$6$2); }; BN.prototype.redInvm = function redInvm() { - assert((this || _global$6$1).red, "redInvm works only with red numbers"); + assert((this || _global$6$2).red, "redInvm works only with red numbers"); - (this || _global$6$1).red._verify1(this || _global$6$1); + (this || _global$6$2).red._verify1(this || _global$6$2); - return (this || _global$6$1).red.invm(this || _global$6$1); + return (this || _global$6$2).red.invm(this || _global$6$2); }; // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$6$1).red, "redNeg works only with red numbers"); + assert((this || _global$6$2).red, "redNeg works only with red numbers"); - (this || _global$6$1).red._verify1(this || _global$6$1); + (this || _global$6$2).red._verify1(this || _global$6$2); - return (this || _global$6$1).red.neg(this || _global$6$1); + return (this || _global$6$2).red.neg(this || _global$6$2); }; BN.prototype.redPow = function redPow(num) { - assert((this || _global$6$1).red && !num.red, "redPow(normalNum)"); + assert((this || _global$6$2).red && !num.red, "redPow(normalNum)"); - (this || _global$6$1).red._verify1(this || _global$6$1); + (this || _global$6$2).red._verify1(this || _global$6$2); - return (this || _global$6$1).red.pow(this || _global$6$1, num); + return (this || _global$6$2).red.pow(this || _global$6$2, num); }; // Prime numbers with efficient reduction @@ -33401,16 +67977,16 @@ function dew$V$1() { function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$6$1).name = name; - (this || _global$6$1).p = new BN(p, 16); - (this || _global$6$1).n = (this || _global$6$1).p.bitLength(); - (this || _global$6$1).k = new BN(1).iushln((this || _global$6$1).n).isub((this || _global$6$1).p); - (this || _global$6$1).tmp = this._tmp(); + (this || _global$6$2).name = name; + (this || _global$6$2).p = new BN(p, 16); + (this || _global$6$2).n = (this || _global$6$2).p.bitLength(); + (this || _global$6$2).k = new BN(1).iushln((this || _global$6$2).n).isub((this || _global$6$2).p); + (this || _global$6$2).tmp = this._tmp(); } MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$6$1).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$6$2).n / 13)); return tmp; }; @@ -33421,19 +67997,19 @@ function dew$V$1() { var rlen; do { - this.split(r, (this || _global$6$1).tmp); + this.split(r, (this || _global$6$2).tmp); r = this.imulK(r); - r = r.iadd((this || _global$6$1).tmp); + r = r.iadd((this || _global$6$2).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$6$1).n); + } while (rlen > (this || _global$6$2).n); - var cmp = rlen < (this || _global$6$1).n ? -1 : r.ucmp((this || _global$6$1).p); + var cmp = rlen < (this || _global$6$2).n ? -1 : r.ucmp((this || _global$6$2).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$6$1).p); + r.isub((this || _global$6$2).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -33448,15 +68024,15 @@ function dew$V$1() { }; MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$6$1).n, 0, out); + input.iushrn((this || _global$6$2).n, 0, out); }; MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$6$1).k); + return num.imul((this || _global$6$2).k); }; function K256() { - MPrime.call(this || _global$6$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$6$2, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } inherits(K256, MPrime); @@ -33526,20 +68102,20 @@ function dew$V$1() { }; function P224() { - MPrime.call(this || _global$6$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$6$2, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } inherits(P224, MPrime); function P192() { - MPrime.call(this || _global$6$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$6$2, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } inherits(P192, MPrime); function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$6$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$6$2, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } inherits(P25519, MPrime); @@ -33592,12 +68168,12 @@ function dew$V$1() { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$6$1).m = prime.p; - (this || _global$6$1).prime = prime; + (this || _global$6$2).m = prime.p; + (this || _global$6$2).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$6$1).m = m; - (this || _global$6$1).prime = null; + (this || _global$6$2).m = m; + (this || _global$6$2).prime = null; } } @@ -33612,8 +68188,8 @@ function dew$V$1() { }; Red.prototype.imod = function imod(a) { - if ((this || _global$6$1).prime) return (this || _global$6$1).prime.ireduce(a)._forceRed(this || _global$6$1); - return a.umod((this || _global$6$1).m)._forceRed(this || _global$6$1); + if ((this || _global$6$2).prime) return (this || _global$6$2).prime.ireduce(a)._forceRed(this || _global$6$2); + return a.umod((this || _global$6$2).m)._forceRed(this || _global$6$2); }; Red.prototype.neg = function neg(a) { @@ -33621,7 +68197,7 @@ function dew$V$1() { return a.clone(); } - return (this || _global$6$1).m.sub(a)._forceRed(this || _global$6$1); + return (this || _global$6$2).m.sub(a)._forceRed(this || _global$6$2); }; Red.prototype.add = function add(a, b) { @@ -33629,11 +68205,11 @@ function dew$V$1() { var res = a.add(b); - if (res.cmp((this || _global$6$1).m) >= 0) { - res.isub((this || _global$6$1).m); + if (res.cmp((this || _global$6$2).m) >= 0) { + res.isub((this || _global$6$2).m); } - return res._forceRed(this || _global$6$1); + return res._forceRed(this || _global$6$2); }; Red.prototype.iadd = function iadd(a, b) { @@ -33641,8 +68217,8 @@ function dew$V$1() { var res = a.iadd(b); - if (res.cmp((this || _global$6$1).m) >= 0) { - res.isub((this || _global$6$1).m); + if (res.cmp((this || _global$6$2).m) >= 0) { + res.isub((this || _global$6$2).m); } return res; @@ -33654,10 +68230,10 @@ function dew$V$1() { var res = a.sub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$6$1).m); + res.iadd((this || _global$6$2).m); } - return res._forceRed(this || _global$6$1); + return res._forceRed(this || _global$6$2); }; Red.prototype.isub = function isub(a, b) { @@ -33666,7 +68242,7 @@ function dew$V$1() { var res = a.isub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$6$1).m); + res.iadd((this || _global$6$2).m); } return res; @@ -33701,12 +68277,12 @@ function dew$V$1() { Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$6$1).m.andln(3); + var mod3 = (this || _global$6$2).m.andln(3); assert(mod3 % 2 === 1); // Fast case if (mod3 === 3) { - var pow = (this || _global$6$1).m.add(new BN(1)).iushrn(2); + var pow = (this || _global$6$2).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); } // Tonelli-Shanks algorithm (Totally unoptimized and slow) @@ -33714,7 +68290,7 @@ function dew$V$1() { // Find Q and S, that Q * 2 ^ S = (P - 1) - var q = (this || _global$6$1).m.subn(1); + var q = (this || _global$6$2).m.subn(1); var s = 0; @@ -33724,15 +68300,15 @@ function dew$V$1() { } assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$6$1); + var one = new BN(1).toRed(this || _global$6$2); var nOne = one.redNeg(); // Find quadratic non-residue // NOTE: Max is such because of generalized Riemann hypothesis. - var lpow = (this || _global$6$1).m.subn(1).iushrn(1); + var lpow = (this || _global$6$2).m.subn(1).iushrn(1); - var z = (this || _global$6$1).m.bitLength(); + var z = (this || _global$6$2).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$6$1); + z = new BN(2 * z * z).toRed(this || _global$6$2); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); @@ -33762,7 +68338,7 @@ function dew$V$1() { }; Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$6$1).m); + var inv = a._invmp((this || _global$6$2).m); if (inv.negative !== 0) { inv.negative = 0; @@ -33773,11 +68349,11 @@ function dew$V$1() { }; Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$6$1); + if (num.isZero()) return new BN(1).toRed(this || _global$6$2); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$6$1); + wnd[0] = new BN(1).toRed(this || _global$6$2); wnd[1] = a; for (var i = 2; i < wnd.length; i++) { @@ -33824,7 +68400,7 @@ function dew$V$1() { }; Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$6$1).m); + var r = num.umod((this || _global$6$2).m); return r === num ? r.clone() : r; }; @@ -33842,29 +68418,29 @@ function dew$V$1() { }; function Mont(m) { - Red.call(this || _global$6$1, m); - (this || _global$6$1).shift = (this || _global$6$1).m.bitLength(); + Red.call(this || _global$6$2, m); + (this || _global$6$2).shift = (this || _global$6$2).m.bitLength(); - if ((this || _global$6$1).shift % 26 !== 0) { - (this || _global$6$1).shift += 26 - (this || _global$6$1).shift % 26; + if ((this || _global$6$2).shift % 26 !== 0) { + (this || _global$6$2).shift += 26 - (this || _global$6$2).shift % 26; } - (this || _global$6$1).r = new BN(1).iushln((this || _global$6$1).shift); - (this || _global$6$1).r2 = this.imod((this || _global$6$1).r.sqr()); - (this || _global$6$1).rinv = (this || _global$6$1).r._invmp((this || _global$6$1).m); - (this || _global$6$1).minv = (this || _global$6$1).rinv.mul((this || _global$6$1).r).isubn(1).div((this || _global$6$1).m); - (this || _global$6$1).minv = (this || _global$6$1).minv.umod((this || _global$6$1).r); - (this || _global$6$1).minv = (this || _global$6$1).r.sub((this || _global$6$1).minv); + (this || _global$6$2).r = new BN(1).iushln((this || _global$6$2).shift); + (this || _global$6$2).r2 = this.imod((this || _global$6$2).r.sqr()); + (this || _global$6$2).rinv = (this || _global$6$2).r._invmp((this || _global$6$2).m); + (this || _global$6$2).minv = (this || _global$6$2).rinv.mul((this || _global$6$2).r).isubn(1).div((this || _global$6$2).m); + (this || _global$6$2).minv = (this || _global$6$2).minv.umod((this || _global$6$2).r); + (this || _global$6$2).minv = (this || _global$6$2).r.sub((this || _global$6$2).minv); } inherits(Mont, Red); Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$6$1).shift)); + return this.imod(num.ushln((this || _global$6$2).shift)); }; Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$6$1).rinv)); + var r = this.imod(num.mul((this || _global$6$2).rinv)); r.red = null; return r; }; @@ -33877,51 +68453,51 @@ function dew$V$1() { } var t = a.imul(b); - var c = t.maskn((this || _global$6$1).shift).mul((this || _global$6$1).minv).imaskn((this || _global$6$1).shift).mul((this || _global$6$1).m); - var u = t.isub(c).iushrn((this || _global$6$1).shift); + var c = t.maskn((this || _global$6$2).shift).mul((this || _global$6$2).minv).imaskn((this || _global$6$2).shift).mul((this || _global$6$2).m); + var u = t.isub(c).iushrn((this || _global$6$2).shift); var res = u; - if (u.cmp((this || _global$6$1).m) >= 0) { - res = u.isub((this || _global$6$1).m); + if (u.cmp((this || _global$6$2).m) >= 0) { + res = u.isub((this || _global$6$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$6$1).m); + res = u.iadd((this || _global$6$2).m); } - return res._forceRed(this || _global$6$1); + return res._forceRed(this || _global$6$2); }; Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$6$1); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$6$2); var t = a.mul(b); - var c = t.maskn((this || _global$6$1).shift).mul((this || _global$6$1).minv).imaskn((this || _global$6$1).shift).mul((this || _global$6$1).m); - var u = t.isub(c).iushrn((this || _global$6$1).shift); + var c = t.maskn((this || _global$6$2).shift).mul((this || _global$6$2).minv).imaskn((this || _global$6$2).shift).mul((this || _global$6$2).m); + var u = t.isub(c).iushrn((this || _global$6$2).shift); var res = u; - if (u.cmp((this || _global$6$1).m) >= 0) { - res = u.isub((this || _global$6$1).m); + if (u.cmp((this || _global$6$2).m) >= 0) { + res = u.isub((this || _global$6$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$6$1).m); + res = u.iadd((this || _global$6$2).m); } - return res._forceRed(this || _global$6$1); + return res._forceRed(this || _global$6$2); }; Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$6$1).m).mul((this || _global$6$1).r2)); - return res._forceRed(this || _global$6$1); + var res = this.imod(a._invmp((this || _global$6$2).m).mul((this || _global$6$2).r2)); + return res._forceRed(this || _global$6$2); }; - })(module$3$1, exports$V$1); + })(module$3$2, exports$W$2); - return module$3$1.exports; + return module$3$2.exports; } -var exports$U$1 = {}, - _dewExec$U$1 = false; -function dew$U$1() { - if (_dewExec$U$1) return exports$U$1; - _dewExec$U$1 = true; - var utils = exports$U$1; +var exports$V$2 = {}, + _dewExec$U$2 = false; +function dew$U$2() { + if (_dewExec$U$2) return exports$V$2; + _dewExec$U$2 = true; + var utils = exports$V$2; function toArray(msg, enc) { if (Array.isArray(msg)) return msg.slice(); @@ -33973,21 +68549,21 @@ function dew$U$1() { if (enc === "hex") return toHex(arr);else return arr; }; - return exports$U$1; + return exports$V$2; } -var exports$T$1 = {}, - _dewExec$T$1 = false; -function dew$T$1() { - if (_dewExec$T$1) return exports$T$1; - _dewExec$T$1 = true; - var utils = exports$T$1; +var exports$U$2 = {}, + _dewExec$T$2 = false; +function dew$T$2() { + if (_dewExec$T$2) return exports$U$2; + _dewExec$T$2 = true; + var utils = exports$U$2; - var BN = dew$V$1(); + var BN = dew$V$2(); - var minAssert = dew$1t(); + var minAssert = dew$2m(); - var minUtils = dew$U$1(); + var minUtils = dew$U$2(); utils.assert = minAssert; utils.toArray = minUtils.toArray; @@ -34088,18 +68664,18 @@ function dew$T$1() { } utils.intFromLE = intFromLE; - return exports$T$1; + return exports$U$2; } -var exports$S$1 = {}, - _dewExec$S$1 = false; -function dew$S$1() { - if (_dewExec$S$1) return exports$S$1; - _dewExec$S$1 = true; +var exports$T$2 = {}, + _dewExec$S$2 = false; +function dew$S$2() { + if (_dewExec$S$2) return exports$T$2; + _dewExec$S$2 = true; - var BN = dew$V$1(); + var BN = dew$V$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); var getNAF = utils.getNAF; var getJSF = utils.getJSF; @@ -34134,7 +68710,7 @@ function dew$S$1() { } } - exports$S$1 = BaseCurve; + exports$T$2 = BaseCurve; BaseCurve.prototype.point = function point() { throw new Error("Not implemented"); @@ -34446,22 +69022,22 @@ function dew$S$1() { return r; }; - return exports$S$1; + return exports$T$2; } -var exports$R$1 = {}, - _dewExec$R$1 = false; -function dew$R$1() { - if (_dewExec$R$1) return exports$R$1; - _dewExec$R$1 = true; +var exports$S$2 = {}, + _dewExec$R$2 = false; +function dew$R$2() { + if (_dewExec$R$2) return exports$S$2; + _dewExec$R$2 = true; - var utils = dew$T$1(); + var utils = dew$T$2(); - var BN = dew$V$1(); + var BN = dew$V$2(); - var inherits = dew$f$2(); + var inherits = dew$f$4(); - var Base = dew$S$1(); + var Base = dew$S$2(); var assert = utils.assert; @@ -34479,7 +69055,7 @@ function dew$R$1() { } inherits(ShortCurve, Base); - exports$R$1 = ShortCurve; + exports$S$2 = ShortCurve; ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) { // No efficient endomorphism @@ -35289,22 +69865,22 @@ function dew$R$1() { return this.z.cmpn(0) === 0; }; - return exports$R$1; + return exports$S$2; } -var exports$Q$1 = {}, - _dewExec$Q$1 = false; -function dew$Q$1() { - if (_dewExec$Q$1) return exports$Q$1; - _dewExec$Q$1 = true; +var exports$R$2 = {}, + _dewExec$Q$2 = false; +function dew$Q$2() { + if (_dewExec$Q$2) return exports$R$2; + _dewExec$Q$2 = true; - var BN = dew$V$1(); + var BN = dew$V$2(); - var inherits = dew$f$2(); + var inherits = dew$f$4(); - var Base = dew$S$1(); + var Base = dew$S$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); function MontCurve(conf) { Base.call(this, "mont", conf); @@ -35316,7 +69892,7 @@ function dew$Q$1() { } inherits(MontCurve, Base); - exports$Q$1 = MontCurve; + exports$R$2 = MontCurve; MontCurve.prototype.validate = function validate(point) { var x = point.normalize().x; @@ -35472,22 +70048,22 @@ function dew$Q$1() { return this.x.fromRed(); }; - return exports$Q$1; + return exports$R$2; } -var exports$P$1 = {}, - _dewExec$P$1 = false; -function dew$P$1() { - if (_dewExec$P$1) return exports$P$1; - _dewExec$P$1 = true; +var exports$Q$2 = {}, + _dewExec$P$2 = false; +function dew$P$2() { + if (_dewExec$P$2) return exports$Q$2; + _dewExec$P$2 = true; - var utils = dew$T$1(); + var utils = dew$T$2(); - var BN = dew$V$1(); + var BN = dew$V$2(); - var inherits = dew$f$2(); + var inherits = dew$f$4(); - var Base = dew$S$1(); + var Base = dew$S$2(); var assert = utils.assert; @@ -35508,7 +70084,7 @@ function dew$P$1() { } inherits(EdwardsCurve, Base); - exports$P$1 = EdwardsCurve; + exports$Q$2 = EdwardsCurve; EdwardsCurve.prototype._mulA = function _mulA(num) { if (this.mOneA) return num.redNeg();else return this.a.redMul(num); @@ -35855,33 +70431,33 @@ function dew$P$1() { Point.prototype.toP = Point.prototype.normalize; Point.prototype.mixedAdd = Point.prototype.add; - return exports$P$1; + return exports$Q$2; } -var exports$O$1 = {}, - _dewExec$O$1 = false; -function dew$O$1() { - if (_dewExec$O$1) return exports$O$1; - _dewExec$O$1 = true; - var curve = exports$O$1; - curve.base = dew$S$1(); - curve.short = dew$R$1(); - curve.mont = dew$Q$1(); - curve.edwards = dew$P$1(); - return exports$O$1; +var exports$P$2 = {}, + _dewExec$O$2 = false; +function dew$O$2() { + if (_dewExec$O$2) return exports$P$2; + _dewExec$O$2 = true; + var curve = exports$P$2; + curve.base = dew$S$2(); + curve.short = dew$R$2(); + curve.mont = dew$Q$2(); + curve.edwards = dew$P$2(); + return exports$P$2; } -var exports$N$1 = {}, - _dewExec$N$1 = false; -function dew$N$1() { - if (_dewExec$N$1) return exports$N$1; - _dewExec$N$1 = true; +var exports$O$2 = {}, + _dewExec$N$2 = false; +function dew$N$2() { + if (_dewExec$N$2) return exports$O$2; + _dewExec$N$2 = true; - var assert = dew$1t(); + var assert = dew$2m(); - var inherits = dew$f$2(); + var inherits = dew$f$4(); - exports$N$1.inherits = inherits; + exports$O$2.inherits = inherits; function isSurrogatePair(msg, i) { if ((msg.charCodeAt(i) & 64512) !== 55296) { @@ -35941,7 +70517,7 @@ function dew$N$1() { return res; } - exports$N$1.toArray = toArray; + exports$O$2.toArray = toArray; function toHex(msg) { var res = ""; @@ -35951,14 +70527,14 @@ function dew$N$1() { return res; } - exports$N$1.toHex = toHex; + exports$O$2.toHex = toHex; function htonl(w) { var res = w >>> 24 | w >>> 8 & 65280 | w << 8 & 16711680 | (w & 255) << 24; return res >>> 0; } - exports$N$1.htonl = htonl; + exports$O$2.htonl = htonl; function toHex32(msg, endian) { var res = ""; @@ -35972,19 +70548,19 @@ function dew$N$1() { return res; } - exports$N$1.toHex32 = toHex32; + exports$O$2.toHex32 = toHex32; function zero2(word) { if (word.length === 1) return "0" + word;else return word; } - exports$N$1.zero2 = zero2; + exports$O$2.zero2 = zero2; function zero8(word) { if (word.length === 7) return "0" + word;else if (word.length === 6) return "00" + word;else if (word.length === 5) return "000" + word;else if (word.length === 4) return "0000" + word;else if (word.length === 3) return "00000" + word;else if (word.length === 2) return "000000" + word;else if (word.length === 1) return "0000000" + word;else return word; } - exports$N$1.zero8 = zero8; + exports$O$2.zero8 = zero8; function join32(msg, start, end, endian) { var len = end - start; @@ -36000,7 +70576,7 @@ function dew$N$1() { return res; } - exports$N$1.join32 = join32; + exports$O$2.join32 = join32; function split32(msg, endian) { var res = new Array(msg.length * 4); @@ -36024,43 +70600,43 @@ function dew$N$1() { return res; } - exports$N$1.split32 = split32; + exports$O$2.split32 = split32; function rotr32(w, b) { return w >>> b | w << 32 - b; } - exports$N$1.rotr32 = rotr32; + exports$O$2.rotr32 = rotr32; function rotl32(w, b) { return w << b | w >>> 32 - b; } - exports$N$1.rotl32 = rotl32; + exports$O$2.rotl32 = rotl32; function sum32(a, b) { return a + b >>> 0; } - exports$N$1.sum32 = sum32; + exports$O$2.sum32 = sum32; function sum32_3(a, b, c) { return a + b + c >>> 0; } - exports$N$1.sum32_3 = sum32_3; + exports$O$2.sum32_3 = sum32_3; function sum32_4(a, b, c, d) { return a + b + c + d >>> 0; } - exports$N$1.sum32_4 = sum32_4; + exports$O$2.sum32_4 = sum32_4; function sum32_5(a, b, c, d, e) { return a + b + c + d + e >>> 0; } - exports$N$1.sum32_5 = sum32_5; + exports$O$2.sum32_5 = sum32_5; function sum64(buf, pos, ah, al) { var bh = buf[pos]; @@ -36071,7 +70647,7 @@ function dew$N$1() { buf[pos + 1] = lo; } - exports$N$1.sum64 = sum64; + exports$O$2.sum64 = sum64; function sum64_hi(ah, al, bh, bl) { var lo = al + bl >>> 0; @@ -36079,14 +70655,14 @@ function dew$N$1() { return hi >>> 0; } - exports$N$1.sum64_hi = sum64_hi; + exports$O$2.sum64_hi = sum64_hi; function sum64_lo(ah, al, bh, bl) { var lo = al + bl; return lo >>> 0; } - exports$N$1.sum64_lo = sum64_lo; + exports$O$2.sum64_lo = sum64_lo; function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { var carry = 0; @@ -36101,14 +70677,14 @@ function dew$N$1() { return hi >>> 0; } - exports$N$1.sum64_4_hi = sum64_4_hi; + exports$O$2.sum64_4_hi = sum64_4_hi; function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { var lo = al + bl + cl + dl; return lo >>> 0; } - exports$N$1.sum64_4_lo = sum64_4_lo; + exports$O$2.sum64_4_lo = sum64_4_lo; function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { var carry = 0; @@ -36125,53 +70701,53 @@ function dew$N$1() { return hi >>> 0; } - exports$N$1.sum64_5_hi = sum64_5_hi; + exports$O$2.sum64_5_hi = sum64_5_hi; function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { var lo = al + bl + cl + dl + el; return lo >>> 0; } - exports$N$1.sum64_5_lo = sum64_5_lo; + exports$O$2.sum64_5_lo = sum64_5_lo; function rotr64_hi(ah, al, num) { var r = al << 32 - num | ah >>> num; return r >>> 0; } - exports$N$1.rotr64_hi = rotr64_hi; + exports$O$2.rotr64_hi = rotr64_hi; function rotr64_lo(ah, al, num) { var r = ah << 32 - num | al >>> num; return r >>> 0; } - exports$N$1.rotr64_lo = rotr64_lo; + exports$O$2.rotr64_lo = rotr64_lo; function shr64_hi(ah, al, num) { return ah >>> num; } - exports$N$1.shr64_hi = shr64_hi; + exports$O$2.shr64_hi = shr64_hi; function shr64_lo(ah, al, num) { var r = ah << 32 - num | al >>> num; return r >>> 0; } - exports$N$1.shr64_lo = shr64_lo; - return exports$N$1; + exports$O$2.shr64_lo = shr64_lo; + return exports$O$2; } -var exports$M$1 = {}, - _dewExec$M$1 = false; -function dew$M$1() { - if (_dewExec$M$1) return exports$M$1; - _dewExec$M$1 = true; +var exports$N$2 = {}, + _dewExec$M$2 = false; +function dew$M$2() { + if (_dewExec$M$2) return exports$N$2; + _dewExec$M$2 = true; - var utils = dew$N$1(); + var utils = dew$N$2(); - var assert = dew$1t(); + var assert = dew$2m(); function BlockHash() { this.pending = null; @@ -36185,7 +70761,7 @@ function dew$M$1() { this._delta32 = this.blockSize / 32; } - exports$M$1.BlockHash = BlockHash; + exports$N$2.BlockHash = BlockHash; BlockHash.prototype.update = function update(msg, enc) { // Convert message to array, pad it, and join into 32bit blocks @@ -36252,26 +70828,26 @@ function dew$M$1() { return res; }; - return exports$M$1; + return exports$N$2; } -var exports$L$1 = {}, - _dewExec$L$1 = false; -function dew$L$1() { - if (_dewExec$L$1) return exports$L$1; - _dewExec$L$1 = true; - return exports$L$1; +var exports$M$2 = {}, + _dewExec$L$2 = false; +function dew$L$2() { + if (_dewExec$L$2) return exports$M$2; + _dewExec$L$2 = true; + return exports$M$2; } -var exports$K$1 = {}, - _dewExec$K$1 = false; -function dew$K$1() { - if (_dewExec$K$1) return exports$K$1; - _dewExec$K$1 = true; +var exports$L$2 = {}, + _dewExec$K$2 = false; +function dew$K$2() { + if (_dewExec$K$2) return exports$L$2; + _dewExec$K$2 = true; - var utils = dew$N$1(); + var utils = dew$N$2(); - var common = dew$M$1(); + var common = dew$M$2(); var rotl32 = utils.rotl32; var sum32 = utils.sum32; @@ -36287,7 +70863,7 @@ function dew$K$1() { } utils.inherits(RIPEMD160, BlockHash); - exports$K$1.ripemd160 = RIPEMD160; + exports$L$2.ripemd160 = RIPEMD160; RIPEMD160.blockSize = 512; RIPEMD160.outSize = 160; RIPEMD160.hmacStrength = 192; @@ -36348,18 +70924,18 @@ function dew$K$1() { var rh = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; var s = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]; var sh = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; - return exports$K$1; + return exports$L$2; } -var exports$J$1 = {}, - _dewExec$J$1 = false; -function dew$J$1() { - if (_dewExec$J$1) return exports$J$1; - _dewExec$J$1 = true; +var exports$K$2 = {}, + _dewExec$J$2 = false; +function dew$J$2() { + if (_dewExec$J$2) return exports$K$2; + _dewExec$J$2 = true; - var utils = dew$N$1(); + var utils = dew$N$2(); - var assert = dew$1t(); + var assert = dew$2m(); function Hmac(hash, key, enc) { if (!(this instanceof Hmac)) return new Hmac(hash, key, enc); @@ -36372,7 +70948,7 @@ function dew$J$1() { this._init(utils.toArray(key, enc)); } - exports$J$1 = Hmac; + exports$K$2 = Hmac; Hmac.prototype._init = function init(key) { // Shorten key, if needed @@ -36400,20 +70976,20 @@ function dew$J$1() { return this.outer.digest(enc); }; - return exports$J$1; + return exports$K$2; } -var exports$I$1 = {}, - _dewExec$I$1 = false; -function dew$I$1() { - if (_dewExec$I$1) return exports$I$1; - _dewExec$I$1 = true; - var hash = exports$I$1; - hash.utils = dew$N$1(); - hash.common = dew$M$1(); - hash.sha = dew$L$1(); - hash.ripemd = dew$K$1(); - hash.hmac = dew$J$1(); // Proxy hash functions to the main object +var exports$J$2 = {}, + _dewExec$I$2 = false; +function dew$I$2() { + if (_dewExec$I$2) return exports$J$2; + _dewExec$I$2 = true; + var hash = exports$J$2; + hash.utils = dew$N$2(); + hash.common = dew$M$2(); + hash.sha = dew$L$2(); + hash.ripemd = dew$K$2(); + hash.hmac = dew$J$2(); // Proxy hash functions to the main object hash.sha1 = hash.sha.sha1; hash.sha256 = hash.sha.sha256; @@ -36421,15 +70997,15 @@ function dew$I$1() { hash.sha384 = hash.sha.sha384; hash.sha512 = hash.sha.sha512; hash.ripemd160 = hash.ripemd.ripemd160; - return exports$I$1; + return exports$J$2; } -var exports$H$1 = {}, - _dewExec$H$1 = false; -function dew$H$1() { - if (_dewExec$H$1) return exports$H$1; - _dewExec$H$1 = true; - exports$H$1 = { +var exports$I$2 = {}, + _dewExec$H$2 = false; +function dew$H$2() { + if (_dewExec$H$2) return exports$I$2; + _dewExec$H$2 = true; + exports$I$2 = { doubles: { step: 4, points: [["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a", "f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"], ["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508", "11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"], ["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739", "d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"], ["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640", "4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"], ["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c", "4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"], ["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda", "96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"], ["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa", "5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"], ["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0", "cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"], ["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d", "9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"], ["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d", "e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"], ["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1", "9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"], ["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0", "5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"], ["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047", "10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"], ["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862", "283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"], ["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7", "7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"], ["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd", "56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"], ["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83", "7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"], ["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a", "53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"], ["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8", "bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"], ["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d", "4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"], ["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725", "7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"], ["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754", "4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"], ["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c", "17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"], ["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6", "6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"], ["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39", "c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"], ["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891", "893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"], ["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b", "febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"], ["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03", "2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"], ["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d", "eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"], ["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070", "7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"], ["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4", "e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"], ["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da", "662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"], ["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11", "1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"], ["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e", "efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"], ["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41", "2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"], ["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef", "67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"], ["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8", "db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"], ["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d", "648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"], ["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96", "35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"], ["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd", "ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"], ["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5", "9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"], ["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266", "40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"], ["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71", "34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"], ["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac", "c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"], ["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751", "1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"], ["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e", "493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"], ["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241", "c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"], ["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3", "be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"], ["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f", "4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"], ["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19", "aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"], ["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be", "b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"], ["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9", "6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"], ["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2", "8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"], ["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13", "7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"], ["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c", "ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"], ["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba", "2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"], ["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151", "e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"], ["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073", "d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"], ["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458", "38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"], ["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b", "69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"], ["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366", "d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"], ["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa", "40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"], ["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0", "620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"], ["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787", "7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"], ["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e", "ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]] @@ -36439,21 +71015,21 @@ function dew$H$1() { points: [["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9", "388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"], ["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4", "d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"], ["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc", "6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"], ["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe", "cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"], ["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb", "d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"], ["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8", "ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"], ["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e", "581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"], ["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34", "4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"], ["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c", "85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"], ["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5", "321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"], ["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f", "2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"], ["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714", "73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"], ["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729", "a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"], ["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db", "2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"], ["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4", "e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"], ["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5", "b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"], ["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479", "2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"], ["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d", "80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"], ["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f", "1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"], ["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb", "d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"], ["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9", "eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"], ["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963", "758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"], ["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74", "958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"], ["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530", "e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"], ["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b", "5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"], ["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247", "cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"], ["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1", "cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"], ["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120", "4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"], ["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435", "91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"], ["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18", "673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"], ["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8", "59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"], ["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb", "3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"], ["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f", "55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"], ["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143", "efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"], ["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba", "e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"], ["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45", "f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"], ["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a", "744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"], ["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e", "c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"], ["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8", "e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"], ["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c", "30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"], ["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519", "e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"], ["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab", "100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"], ["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca", "ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"], ["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf", "8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"], ["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610", "68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"], ["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4", "f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"], ["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c", "d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"], ["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940", "edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"], ["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980", "a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"], ["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3", "66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"], ["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf", "9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"], ["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63", "4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"], ["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448", "fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"], ["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf", "5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"], ["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5", "8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"], ["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6", "8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"], ["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5", "5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"], ["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99", "f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"], ["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51", "f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"], ["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5", "42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"], ["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5", "204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"], ["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997", "4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"], ["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881", "73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"], ["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5", "39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"], ["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66", "d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"], ["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726", "ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"], ["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede", "6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"], ["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94", "60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"], ["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31", "3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"], ["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51", "b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"], ["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252", "ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"], ["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5", "cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"], ["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b", "6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"], ["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4", "322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"], ["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f", "6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"], ["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889", "2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"], ["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246", "b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"], ["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984", "998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"], ["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a", "b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"], ["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030", "bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"], ["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197", "6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"], ["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593", "c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"], ["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef", "21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"], ["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38", "60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"], ["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a", "49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"], ["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111", "5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"], ["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502", "7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"], ["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea", "be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"], ["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26", "8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"], ["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986", "39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"], ["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e", "62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"], ["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4", "25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"], ["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda", "ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"], ["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859", "cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"], ["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f", "f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"], ["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c", "6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"], ["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942", "fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"], ["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a", "1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"], ["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80", "5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"], ["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d", "438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"], ["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1", "cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"], ["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63", "c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"], ["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352", "6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"], ["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193", "ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"], ["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00", "9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"], ["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58", "ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"], ["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7", "d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"], ["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8", "c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"], ["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e", "67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"], ["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d", "cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"], ["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b", "299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"], ["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f", "f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"], ["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6", "462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"], ["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297", "62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"], ["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a", "7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"], ["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c", "ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"], ["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52", "4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"], ["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb", "bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"], ["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065", "bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"], ["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917", "603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"], ["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9", "cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"], ["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3", "553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"], ["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57", "712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"], ["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66", "ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"], ["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8", "9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"], ["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721", "9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"], ["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180", "4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]] } }; - return exports$H$1; + return exports$I$2; } -var exports$G$1 = {}, - _dewExec$G$1 = false; -function dew$G$1() { - if (_dewExec$G$1) return exports$G$1; - _dewExec$G$1 = true; - var curves = exports$G$1; +var exports$H$2 = {}, + _dewExec$G$2 = false; +function dew$G$2() { + if (_dewExec$G$2) return exports$H$2; + _dewExec$G$2 = true; + var curves = exports$H$2; - var hash = dew$I$1(); + var hash = dew$I$2(); - var curve = dew$O$1(); + var curve = dew$O$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); var assert = utils.assert; @@ -36567,7 +71143,7 @@ function dew$G$1() { var pre; try { - pre = dew$H$1(); + pre = dew$H$2(); } catch (e) { pre = undefined; } @@ -36594,20 +71170,20 @@ function dew$G$1() { gRed: false, g: ["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", pre] }); - return exports$G$1; + return exports$H$2; } -var exports$F$1 = {}, - _dewExec$F$1 = false; -function dew$F$1() { - if (_dewExec$F$1) return exports$F$1; - _dewExec$F$1 = true; +var exports$G$2 = {}, + _dewExec$F$2 = false; +function dew$F$2() { + if (_dewExec$F$2) return exports$G$2; + _dewExec$F$2 = true; - var hash = dew$I$1(); + var hash = dew$I$2(); - var utils = dew$U$1(); + var utils = dew$U$2(); - var assert = dew$1t(); + var assert = dew$2m(); function HmacDRBG(options) { if (!(this instanceof HmacDRBG)) return new HmacDRBG(options); @@ -36627,7 +71203,7 @@ function dew$F$1() { this._init(entropy, nonce, pers); } - exports$F$1 = HmacDRBG; + exports$G$2 = HmacDRBG; HmacDRBG.prototype._init = function init(entropy, nonce, pers) { var seed = entropy.concat(nonce).concat(pers); @@ -36708,18 +71284,18 @@ function dew$F$1() { return utils.encode(res, enc); }; - return exports$F$1; + return exports$G$2; } -var exports$E$1 = {}, - _dewExec$E$1 = false; -function dew$E$1() { - if (_dewExec$E$1) return exports$E$1; - _dewExec$E$1 = true; +var exports$F$2 = {}, + _dewExec$E$2 = false; +function dew$E$2() { + if (_dewExec$E$2) return exports$F$2; + _dewExec$E$2 = true; - var BN = dew$V$1(); + var BN = dew$V$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); var assert = utils.assert; @@ -36732,7 +71308,7 @@ function dew$E$1() { if (options.pub) this._importPublic(options.pub, options.pubEnc); } - exports$E$1 = KeyPair; + exports$F$2 = KeyPair; KeyPair.fromPublic = function fromPublic(ec, pub, enc) { if (pub instanceof KeyPair) return pub; @@ -36833,18 +71409,18 @@ function dew$E$1() { return ""; }; - return exports$E$1; + return exports$F$2; } -var exports$D$1 = {}, - _dewExec$D$1 = false; -function dew$D$1() { - if (_dewExec$D$1) return exports$D$1; - _dewExec$D$1 = true; +var exports$E$2 = {}, + _dewExec$D$2 = false; +function dew$D$2() { + if (_dewExec$D$2) return exports$E$2; + _dewExec$D$2 = true; - var BN = dew$V$1(); + var BN = dew$V$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); var assert = utils.assert; @@ -36857,7 +71433,7 @@ function dew$D$1() { if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam; } - exports$D$1 = Signature; + exports$E$2 = Signature; function Position() { this.place = 0; @@ -37021,30 +71597,30 @@ function dew$D$1() { return utils.encode(res, enc); }; - return exports$D$1; + return exports$E$2; } -var exports$C$1 = {}, - _dewExec$C$1 = false; -function dew$C$1() { - if (_dewExec$C$1) return exports$C$1; - _dewExec$C$1 = true; +var exports$D$2 = {}, + _dewExec$C$2 = false; +function dew$C$2() { + if (_dewExec$C$2) return exports$D$2; + _dewExec$C$2 = true; - var BN = dew$V$1(); + var BN = dew$V$2(); - var HmacDRBG = dew$F$1(); + var HmacDRBG = dew$F$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); - var curves = dew$G$1(); + var curves = dew$G$2(); - var rand = dew$10$1(); + var rand = dew$11$2(); var assert = utils.assert; - var KeyPair = dew$E$1(); + var KeyPair = dew$E$2(); - var Signature = dew$D$1(); + var Signature = dew$D$2(); function EC(options) { if (!(this instanceof EC)) return new EC(options); // Shortcut `elliptic.ec(curve-name)` @@ -37069,7 +71645,7 @@ function dew$C$1() { this.hash = options.hash || options.curve.hash; } - exports$C$1 = EC; + exports$D$2 = EC; EC.prototype.keyPair = function keyPair(options) { return new KeyPair(this, options); @@ -37234,16 +71810,16 @@ function dew$C$1() { throw new Error("Unable to find valid recovery factor"); }; - return exports$C$1; + return exports$D$2; } -var exports$B$1 = {}, - _dewExec$B$1 = false; -function dew$B$1() { - if (_dewExec$B$1) return exports$B$1; - _dewExec$B$1 = true; +var exports$C$2 = {}, + _dewExec$B$2 = false; +function dew$B$2() { + if (_dewExec$B$2) return exports$C$2; + _dewExec$B$2 = true; - var utils = dew$T$1(); + var utils = dew$T$2(); var assert = utils.assert; var parseBytes = utils.parseBytes; @@ -37327,19 +71903,19 @@ function dew$B$1() { return utils.encode(this.pubBytes(), enc); }; - exports$B$1 = KeyPair; - return exports$B$1; + exports$C$2 = KeyPair; + return exports$C$2; } -var exports$A$1 = {}, - _dewExec$A$1 = false; -function dew$A$1() { - if (_dewExec$A$1) return exports$A$1; - _dewExec$A$1 = true; +var exports$B$2 = {}, + _dewExec$A$2 = false; +function dew$A$2() { + if (_dewExec$A$2) return exports$B$2; + _dewExec$A$2 = true; - var BN = dew$V$1(); + var BN = dew$V$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); var assert = utils.assert; var cachedProperty = utils.cachedProperty; @@ -37392,28 +71968,28 @@ function dew$A$1() { return utils.encode(this.toBytes(), "hex").toUpperCase(); }; - exports$A$1 = Signature; - return exports$A$1; + exports$B$2 = Signature; + return exports$B$2; } -var exports$z$1 = {}, - _dewExec$z$1 = false; -function dew$z$1() { - if (_dewExec$z$1) return exports$z$1; - _dewExec$z$1 = true; +var exports$A$2 = {}, + _dewExec$z$2 = false; +function dew$z$2() { + if (_dewExec$z$2) return exports$A$2; + _dewExec$z$2 = true; - var hash = dew$I$1(); + var hash = dew$I$2(); - var curves = dew$G$1(); + var curves = dew$G$2(); - var utils = dew$T$1(); + var utils = dew$T$2(); var assert = utils.assert; var parseBytes = utils.parseBytes; - var KeyPair = dew$B$1(); + var KeyPair = dew$B$2(); - var Signature = dew$A$1(); + var Signature = dew$A$2(); function EDDSA(curve) { assert(curve === "ed25519", "only tested with ed25519 so far"); @@ -37427,7 +72003,7 @@ function dew$z$1() { this.hash = hash.sha512; } - exports$z$1 = EDDSA; + exports$A$2 = EDDSA; /** * @param {Array|String} message - message bytes * @param {Array|String|KeyPair} secret - secret bytes or a keypair @@ -37523,37 +72099,37 @@ function dew$z$1() { return val instanceof this.pointClass; }; - return exports$z$1; + return exports$A$2; } -var exports$y$1 = {}, - _dewExec$y$1 = false; -function dew$y$1() { - if (_dewExec$y$1) return exports$y$1; - _dewExec$y$1 = true; - var elliptic = exports$y$1; - elliptic.version = _package$1.version; - elliptic.utils = dew$T$1(); - elliptic.rand = dew$10$1(); - elliptic.curve = dew$O$1(); - elliptic.curves = dew$G$1(); // Protocols - - elliptic.ec = dew$C$1(); - elliptic.eddsa = dew$z$1(); - return exports$y$1; +var exports$z$2 = {}, + _dewExec$y$2 = false; +function dew$y$2() { + if (_dewExec$y$2) return exports$z$2; + _dewExec$y$2 = true; + var elliptic = exports$z$2; + elliptic.version = _package$2.version; + elliptic.utils = dew$T$2(); + elliptic.rand = dew$11$2(); + elliptic.curve = dew$O$2(); + elliptic.curves = dew$G$2(); // Protocols + + elliptic.ec = dew$C$2(); + elliptic.eddsa = dew$z$2(); + return exports$z$2; } -var exports$x$1 = {}, - _dewExec$x$1 = false; -var module$2$1 = { - exports: exports$x$1 +var exports$y$2 = {}, + _dewExec$x$2 = false; +var module$2$2 = { + exports: exports$y$2 }; -var _global$5$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$5$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$x$1() { - if (_dewExec$x$1) return module$2$1.exports; - _dewExec$x$1 = true; +function dew$x$2() { + if (_dewExec$x$2) return module$2$2.exports; + _dewExec$x$2 = true; (function (module, exports) { @@ -37579,11 +72155,11 @@ function dew$x$1() { return number; } - (this || _global$5$1).negative = 0; - (this || _global$5$1).words = null; - (this || _global$5$1).length = 0; // Reduction context + (this || _global$5$2).negative = 0; + (this || _global$5$2).words = null; + (this || _global$5$2).length = 0; // Reduction context - (this || _global$5$1).red = null; + (this || _global$5$2).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -37609,7 +72185,7 @@ function dew$x$1() { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = e$1$1$1.Buffer; + Buffer = buffer.Buffer; } } catch (e) {} @@ -37650,7 +72226,7 @@ function dew$x$1() { if (number[0] === "-") { start++; - (this || _global$5$1).negative = 1; + (this || _global$5$2).negative = 1; } if (start < number.length) { @@ -37668,21 +72244,21 @@ function dew$x$1() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$5$1).negative = 1; + (this || _global$5$2).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$5$1).words = [number & 67108863]; - (this || _global$5$1).length = 1; + (this || _global$5$2).words = [number & 67108863]; + (this || _global$5$2).length = 1; } else if (number < 4503599627370496) { - (this || _global$5$1).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$5$1).length = 2; + (this || _global$5$2).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$5$2).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$5$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$5$1).length = 3; + (this || _global$5$2).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$5$2).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -37695,16 +72271,16 @@ function dew$x$1() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$5$1).words = [0]; - (this || _global$5$1).length = 1; - return this || _global$5$1; + (this || _global$5$2).words = [0]; + (this || _global$5$2).length = 1; + return this || _global$5$2; } - (this || _global$5$1).length = Math.ceil(number.length / 3); - (this || _global$5$1).words = new Array((this || _global$5$1).length); + (this || _global$5$2).length = Math.ceil(number.length / 3); + (this || _global$5$2).words = new Array((this || _global$5$2).length); - for (var i = 0; i < (this || _global$5$1).length; i++) { - (this || _global$5$1).words[i] = 0; + for (var i = 0; i < (this || _global$5$2).length; i++) { + (this || _global$5$2).words[i] = 0; } var j, w; @@ -37713,8 +72289,8 @@ function dew$x$1() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$5$1).words[j] |= w << off & 67108863; - (this || _global$5$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$5$2).words[j] |= w << off & 67108863; + (this || _global$5$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -37725,8 +72301,8 @@ function dew$x$1() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$5$1).words[j] |= w << off & 67108863; - (this || _global$5$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$5$2).words[j] |= w << off & 67108863; + (this || _global$5$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -37763,11 +72339,11 @@ function dew$x$1() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$5$1).length = Math.ceil((number.length - start) / 6); - (this || _global$5$1).words = new Array((this || _global$5$1).length); + (this || _global$5$2).length = Math.ceil((number.length - start) / 6); + (this || _global$5$2).words = new Array((this || _global$5$2).length); - for (var i = 0; i < (this || _global$5$1).length; i++) { - (this || _global$5$1).words[i] = 0; + for (var i = 0; i < (this || _global$5$2).length; i++) { + (this || _global$5$2).words[i] = 0; } // 24-bits chunks @@ -37778,12 +72354,12 @@ function dew$x$1() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$5$1).words[j] |= w & 67108863; + (this || _global$5$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$5$1).words[j] |= w >>> 26; + (this || _global$5$2).words[j] |= w >>> 26; } else { off += 8; } @@ -37793,12 +72369,12 @@ function dew$x$1() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$5$1).words[j] |= w & 67108863; + (this || _global$5$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$5$1).words[j] |= w >>> 26; + (this || _global$5$2).words[j] |= w >>> 26; } else { off += 8; } @@ -37830,8 +72406,8 @@ function dew$x$1() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$5$1).words = [0]; - (this || _global$5$1).length = 1; // Find length of limb in base + (this || _global$5$2).words = [0]; + (this || _global$5$2).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -37848,8 +72424,8 @@ function dew$x$1() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$5$1).words[0] + word < 67108864) { - (this || _global$5$1).words[0] += word; + if ((this || _global$5$2).words[0] + word < 67108864) { + (this || _global$5$2).words[0] += word; } else { this._iaddn(word); } @@ -37865,8 +72441,8 @@ function dew$x$1() { this.imuln(pow); - if ((this || _global$5$1).words[0] + word < 67108864) { - (this || _global$5$1).words[0] += word; + if ((this || _global$5$2).words[0] + word < 67108864) { + (this || _global$5$2).words[0] += word; } else { this._iaddn(word); } @@ -37876,15 +72452,15 @@ function dew$x$1() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$5$1).length); + dest.words = new Array((this || _global$5$2).length); - for (var i = 0; i < (this || _global$5$1).length; i++) { - dest.words[i] = (this || _global$5$1).words[i]; + for (var i = 0; i < (this || _global$5$2).length; i++) { + dest.words[i] = (this || _global$5$2).words[i]; } - dest.length = (this || _global$5$1).length; - dest.negative = (this || _global$5$1).negative; - dest.red = (this || _global$5$1).red; + dest.length = (this || _global$5$2).length; + dest.negative = (this || _global$5$2).negative; + dest.red = (this || _global$5$2).red; }; BN.prototype.clone = function clone() { @@ -37894,17 +72470,17 @@ function dew$x$1() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$5$1).length < size) { - (this || _global$5$1).words[(this || _global$5$1).length++] = 0; + while ((this || _global$5$2).length < size) { + (this || _global$5$2).words[(this || _global$5$2).length++] = 0; } - return this || _global$5$1; + return this || _global$5$2; }; // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$5$1).length > 1 && (this || _global$5$1).words[(this || _global$5$1).length - 1] === 0) { - (this || _global$5$1).length--; + while ((this || _global$5$2).length > 1 && (this || _global$5$2).words[(this || _global$5$2).length - 1] === 0) { + (this || _global$5$2).length--; } return this._normSign(); @@ -37912,15 +72488,15 @@ function dew$x$1() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$5$1).length === 1 && (this || _global$5$1).words[0] === 0) { - (this || _global$5$1).negative = 0; + if ((this || _global$5$2).length === 1 && (this || _global$5$2).words[0] === 0) { + (this || _global$5$2).negative = 0; } - return this || _global$5$1; + return this || _global$5$2; }; BN.prototype.inspect = function inspect() { - return ((this || _global$5$1).red ? ""; + return ((this || _global$5$2).red ? ""; }; /* var zeros = []; @@ -37964,12 +72540,12 @@ function dew$x$1() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$5$1).length; i++) { - var w = (this || _global$5$1).words[i]; + for (var i = 0; i < (this || _global$5$2).length; i++) { + var w = (this || _global$5$2).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$5$1).length - 1) { + if (carry !== 0 || i !== (this || _global$5$2).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -37991,7 +72567,7 @@ function dew$x$1() { out = "0" + out; } - if ((this || _global$5$1).negative !== 0) { + if ((this || _global$5$2).negative !== 0) { out = "-" + out; } @@ -38026,7 +72602,7 @@ function dew$x$1() { out = "0" + out; } - if ((this || _global$5$1).negative !== 0) { + if ((this || _global$5$2).negative !== 0) { out = "-" + out; } @@ -38037,18 +72613,18 @@ function dew$x$1() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$5$1).words[0]; + var ret = (this || _global$5$2).words[0]; - if ((this || _global$5$1).length === 2) { - ret += (this || _global$5$1).words[1] * 67108864; - } else if ((this || _global$5$1).length === 3 && (this || _global$5$1).words[2] === 1) { + if ((this || _global$5$2).length === 2) { + ret += (this || _global$5$2).words[1] * 67108864; + } else if ((this || _global$5$2).length === 3 && (this || _global$5$2).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$5$1).words[1] * 67108864; - } else if ((this || _global$5$1).length > 2) { + ret += 4503599627370496 + (this || _global$5$2).words[1] * 67108864; + } else if ((this || _global$5$2).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$5$1).negative !== 0 ? -ret : ret; + return (this || _global$5$2).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -38169,11 +72745,11 @@ function dew$x$1() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$5$1).words[(this || _global$5$1).length - 1]; + var w = (this || _global$5$2).words[(this || _global$5$2).length - 1]; var hi = this._countBits(w); - return ((this || _global$5$1).length - 1) * 26 + hi; + return ((this || _global$5$2).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -38193,8 +72769,8 @@ function dew$x$1() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$5$1).length; i++) { - var b = this._zeroBits((this || _global$5$1).words[i]); + for (var i = 0; i < (this || _global$5$2).length; i++) { + var b = this._zeroBits((this || _global$5$2).words[i]); r += b; if (b !== 26) break; @@ -38208,7 +72784,7 @@ function dew$x$1() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$5$1).negative !== 0) { + if ((this || _global$5$2).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -38224,7 +72800,7 @@ function dew$x$1() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$5$1).negative !== 0; + return (this || _global$5$2).negative !== 0; }; // Return negative clone of `this` @@ -38234,39 +72810,39 @@ function dew$x$1() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$5$1).negative ^= 1; + (this || _global$5$2).negative ^= 1; } - return this || _global$5$1; + return this || _global$5$2; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$5$1).length < num.length) { - (this || _global$5$1).words[(this || _global$5$1).length++] = 0; + while ((this || _global$5$2).length < num.length) { + (this || _global$5$2).words[(this || _global$5$2).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$5$1).words[i] = (this || _global$5$1).words[i] | num.words[i]; + (this || _global$5$2).words[i] = (this || _global$5$2).words[i] | num.words[i]; } return this.strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$5$1).negative | num.negative) === 0); + assert(((this || _global$5$2).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$5$1).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$5$2); }; BN.prototype.uor = function uor(num) { - if ((this || _global$5$1).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$5$2); }; // And `num` with `this` in-place @@ -38274,34 +72850,34 @@ function dew$x$1() { // b = min-length(num, this) var b; - if ((this || _global$5$1).length > num.length) { + if ((this || _global$5$2).length > num.length) { b = num; } else { - b = this || _global$5$1; + b = this || _global$5$2; } for (var i = 0; i < b.length; i++) { - (this || _global$5$1).words[i] = (this || _global$5$1).words[i] & num.words[i]; + (this || _global$5$2).words[i] = (this || _global$5$2).words[i] & num.words[i]; } - (this || _global$5$1).length = b.length; + (this || _global$5$2).length = b.length; return this.strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$5$1).negative | num.negative) === 0); + assert(((this || _global$5$2).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$5$1).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$5$2); }; BN.prototype.uand = function uand(num) { - if ((this || _global$5$1).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$5$2); }; // Xor `num` with `this` in-place @@ -38310,42 +72886,42 @@ function dew$x$1() { var a; var b; - if ((this || _global$5$1).length > num.length) { - a = this || _global$5$1; + if ((this || _global$5$2).length > num.length) { + a = this || _global$5$2; b = num; } else { a = num; - b = this || _global$5$1; + b = this || _global$5$2; } for (var i = 0; i < b.length; i++) { - (this || _global$5$1).words[i] = a.words[i] ^ b.words[i]; + (this || _global$5$2).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$5$1) !== a) { + if ((this || _global$5$2) !== a) { for (; i < a.length; i++) { - (this || _global$5$1).words[i] = a.words[i]; + (this || _global$5$2).words[i] = a.words[i]; } } - (this || _global$5$1).length = a.length; + (this || _global$5$2).length = a.length; return this.strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$5$1).negative | num.negative) === 0); + assert(((this || _global$5$2).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$5$1).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$5$2); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$5$1).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$5$2); }; // Not ``this`` with ``width`` bitwidth @@ -38362,12 +72938,12 @@ function dew$x$1() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$5$1).words[i] = ~(this || _global$5$1).words[i] & 67108863; + (this || _global$5$2).words[i] = ~(this || _global$5$2).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$5$1).words[i] = ~(this || _global$5$1).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$5$2).words[i] = ~(this || _global$5$2).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -38387,9 +72963,9 @@ function dew$x$1() { this._expand(off + 1); if (val) { - (this || _global$5$1).words[off] = (this || _global$5$1).words[off] | 1 << wbit; + (this || _global$5$2).words[off] = (this || _global$5$2).words[off] | 1 << wbit; } else { - (this || _global$5$1).words[off] = (this || _global$5$1).words[off] & ~(1 << wbit); + (this || _global$5$2).words[off] = (this || _global$5$2).words[off] & ~(1 << wbit); } return this.strip(); @@ -38399,12 +72975,12 @@ function dew$x$1() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$5$1).negative !== 0 && num.negative === 0) { - (this || _global$5$1).negative = 0; + if ((this || _global$5$2).negative !== 0 && num.negative === 0) { + (this || _global$5$2).negative = 0; r = this.isub(num); - (this || _global$5$1).negative ^= 1; + (this || _global$5$2).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$5$1).negative === 0 && num.negative !== 0) { + } else if ((this || _global$5$2).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -38414,60 +72990,60 @@ function dew$x$1() { var a, b; - if ((this || _global$5$1).length > num.length) { - a = this || _global$5$1; + if ((this || _global$5$2).length > num.length) { + a = this || _global$5$2; b = num; } else { a = num; - b = this || _global$5$1; + b = this || _global$5$2; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$5$1).words[i] = r & 67108863; + (this || _global$5$2).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$5$1).words[i] = r & 67108863; + (this || _global$5$2).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$5$1).length = a.length; + (this || _global$5$2).length = a.length; if (carry !== 0) { - (this || _global$5$1).words[(this || _global$5$1).length] = carry; - (this || _global$5$1).length++; // Copy the rest of the words - } else if (a !== (this || _global$5$1)) { + (this || _global$5$2).words[(this || _global$5$2).length] = carry; + (this || _global$5$2).length++; // Copy the rest of the words + } else if (a !== (this || _global$5$2)) { for (; i < a.length; i++) { - (this || _global$5$1).words[i] = a.words[i]; + (this || _global$5$2).words[i] = a.words[i]; } } - return this || _global$5$1; + return this || _global$5$2; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$5$1).negative === 0) { + if (num.negative !== 0 && (this || _global$5$2).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$5$1).negative !== 0) { - (this || _global$5$1).negative = 0; - res = num.sub(this || _global$5$1); - (this || _global$5$1).negative = 1; + } else if (num.negative === 0 && (this || _global$5$2).negative !== 0) { + (this || _global$5$2).negative = 0; + res = num.sub(this || _global$5$2); + (this || _global$5$2).negative = 1; return res; } - if ((this || _global$5$1).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$5$1); + if ((this || _global$5$2).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$5$2); }; // Subtract `num` from `this` in-place @@ -38478,10 +73054,10 @@ function dew$x$1() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$5$1).negative !== 0) { - (this || _global$5$1).negative = 0; + } else if ((this || _global$5$2).negative !== 0) { + (this || _global$5$2).negative = 0; this.iadd(num); - (this || _global$5$1).negative = 1; + (this || _global$5$2).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -38489,21 +73065,21 @@ function dew$x$1() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$5$1).negative = 0; - (this || _global$5$1).length = 1; - (this || _global$5$1).words[0] = 0; - return this || _global$5$1; + (this || _global$5$2).negative = 0; + (this || _global$5$2).length = 1; + (this || _global$5$2).words[0] = 0; + return this || _global$5$2; } // a > b var a, b; if (cmp > 0) { - a = this || _global$5$1; + a = this || _global$5$2; b = num; } else { a = num; - b = this || _global$5$1; + b = this || _global$5$2; } var carry = 0; @@ -38511,26 +73087,26 @@ function dew$x$1() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$5$1).words[i] = r & 67108863; + (this || _global$5$2).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$5$1).words[i] = r & 67108863; + (this || _global$5$2).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$5$1)) { + if (carry === 0 && i < a.length && a !== (this || _global$5$2)) { for (; i < a.length; i++) { - (this || _global$5$1).words[i] = a.words[i]; + (this || _global$5$2).words[i] = a.words[i]; } } - (this || _global$5$1).length = Math.max((this || _global$5$1).length, i); + (this || _global$5$2).length = Math.max((this || _global$5$2).length, i); - if (a !== (this || _global$5$1)) { - (this || _global$5$1).negative = 1; + if (a !== (this || _global$5$2)) { + (this || _global$5$2).negative = 1; } return this.strip(); @@ -39233,16 +73809,16 @@ function dew$x$1() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$5$1).length + num.length; + var len = (this || _global$5$2).length + num.length; - if ((this || _global$5$1).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$5$1, num, out); + if ((this || _global$5$2).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$5$2, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$5$1, num, out); + res = smallMulTo(this || _global$5$2, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$5$1, num, out); + res = bigMulTo(this || _global$5$2, num, out); } else { - res = jumboMulTo(this || _global$5$1, num, out); + res = jumboMulTo(this || _global$5$2, num, out); } return res; @@ -39251,8 +73827,8 @@ function dew$x$1() { function FFTM(x, y) { - (this || _global$5$1).x = x; - (this || _global$5$1).y = y; + (this || _global$5$2).x = x; + (this || _global$5$2).y = y; } FFTM.prototype.makeRBT = function makeRBT(N) { @@ -39433,20 +74009,20 @@ function dew$x$1() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$5$1).length + num.length); + out.words = new Array((this || _global$5$2).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$5$1).length + num.length); - return jumboMulTo(this || _global$5$1, num, out); + out.words = new Array((this || _global$5$2).length + num.length); + return jumboMulTo(this || _global$5$2, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$5$1); + return this.clone().mulTo(num, this || _global$5$2); }; BN.prototype.imuln = function imuln(num) { @@ -39455,22 +74031,22 @@ function dew$x$1() { var carry = 0; - for (var i = 0; i < (this || _global$5$1).length; i++) { - var w = ((this || _global$5$1).words[i] | 0) * num; + for (var i = 0; i < (this || _global$5$2).length; i++) { + var w = ((this || _global$5$2).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$5$1).words[i] = lo & 67108863; + (this || _global$5$2).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$5$1).words[i] = carry; - (this || _global$5$1).length++; + (this || _global$5$2).words[i] = carry; + (this || _global$5$2).length++; } - return this || _global$5$1; + return this || _global$5$2; }; BN.prototype.muln = function muln(num) { @@ -39479,7 +74055,7 @@ function dew$x$1() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$5$1); + return this.mul(this || _global$5$2); }; // `this` * `this` in-place @@ -39492,7 +74068,7 @@ function dew$x$1() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$5$1; + var res = this || _global$5$2; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -39519,29 +74095,29 @@ function dew$x$1() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$5$1).length; i++) { - var newCarry = (this || _global$5$1).words[i] & carryMask; - var c = ((this || _global$5$1).words[i] | 0) - newCarry << r; - (this || _global$5$1).words[i] = c | carry; + for (i = 0; i < (this || _global$5$2).length; i++) { + var newCarry = (this || _global$5$2).words[i] & carryMask; + var c = ((this || _global$5$2).words[i] | 0) - newCarry << r; + (this || _global$5$2).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$5$1).words[i] = carry; - (this || _global$5$1).length++; + (this || _global$5$2).words[i] = carry; + (this || _global$5$2).length++; } } if (s !== 0) { - for (i = (this || _global$5$1).length - 1; i >= 0; i--) { - (this || _global$5$1).words[i + s] = (this || _global$5$1).words[i]; + for (i = (this || _global$5$2).length - 1; i >= 0; i--) { + (this || _global$5$2).words[i + s] = (this || _global$5$2).words[i]; } for (i = 0; i < s; i++) { - (this || _global$5$1).words[i] = 0; + (this || _global$5$2).words[i] = 0; } - (this || _global$5$1).length += s; + (this || _global$5$2).length += s; } return this.strip(); @@ -39549,7 +74125,7 @@ function dew$x$1() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$5$1).negative === 0); + assert((this || _global$5$2).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -39567,7 +74143,7 @@ function dew$x$1() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$5$1).length); + var s = Math.min((bits - r) / 26, (this || _global$5$2).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -39575,28 +74151,28 @@ function dew$x$1() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$5$1).words[i]; + maskedWords.words[i] = (this || _global$5$2).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$5$1).length > s) { - (this || _global$5$1).length -= s; + if (s === 0) ; else if ((this || _global$5$2).length > s) { + (this || _global$5$2).length -= s; - for (i = 0; i < (this || _global$5$1).length; i++) { - (this || _global$5$1).words[i] = (this || _global$5$1).words[i + s]; + for (i = 0; i < (this || _global$5$2).length; i++) { + (this || _global$5$2).words[i] = (this || _global$5$2).words[i + s]; } } else { - (this || _global$5$1).words[0] = 0; - (this || _global$5$1).length = 1; + (this || _global$5$2).words[0] = 0; + (this || _global$5$2).length = 1; } var carry = 0; - for (i = (this || _global$5$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$5$1).words[i] | 0; - (this || _global$5$1).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$5$2).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$5$2).words[i] | 0; + (this || _global$5$2).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -39605,9 +74181,9 @@ function dew$x$1() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$5$1).length === 0) { - (this || _global$5$1).words[0] = 0; - (this || _global$5$1).length = 1; + if ((this || _global$5$2).length === 0) { + (this || _global$5$2).words[0] = 0; + (this || _global$5$2).length = 1; } return this.strip(); @@ -39615,7 +74191,7 @@ function dew$x$1() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$5$1).negative === 0); + assert((this || _global$5$2).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -39644,9 +74220,9 @@ function dew$x$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$5$1).length <= s) return false; // Check bit and return + if ((this || _global$5$2).length <= s) return false; // Check bit and return - var w = (this || _global$5$1).words[s]; + var w = (this || _global$5$2).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -39655,21 +74231,21 @@ function dew$x$1() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$5$1).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$5$2).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$5$1).length <= s) { - return this || _global$5$1; + if ((this || _global$5$2).length <= s) { + return this || _global$5$2; } if (r !== 0) { s++; } - (this || _global$5$1).length = Math.min(s, (this || _global$5$1).length); + (this || _global$5$2).length = Math.min(s, (this || _global$5$2).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$5$1).words[(this || _global$5$1).length - 1] &= mask; + (this || _global$5$2).words[(this || _global$5$2).length - 1] &= mask; } return this.strip(); @@ -39686,17 +74262,17 @@ function dew$x$1() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$5$1).negative !== 0) { - if ((this || _global$5$1).length === 1 && ((this || _global$5$1).words[0] | 0) < num) { - (this || _global$5$1).words[0] = num - ((this || _global$5$1).words[0] | 0); - (this || _global$5$1).negative = 0; - return this || _global$5$1; + if ((this || _global$5$2).negative !== 0) { + if ((this || _global$5$2).length === 1 && ((this || _global$5$2).words[0] | 0) < num) { + (this || _global$5$2).words[0] = num - ((this || _global$5$2).words[0] | 0); + (this || _global$5$2).negative = 0; + return this || _global$5$2; } - (this || _global$5$1).negative = 0; + (this || _global$5$2).negative = 0; this.isubn(num); - (this || _global$5$1).negative = 1; - return this || _global$5$1; + (this || _global$5$2).negative = 1; + return this || _global$5$2; } // Add without checks @@ -39704,20 +74280,20 @@ function dew$x$1() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$5$1).words[0] += num; // Carry + (this || _global$5$2).words[0] += num; // Carry - for (var i = 0; i < (this || _global$5$1).length && (this || _global$5$1).words[i] >= 67108864; i++) { - (this || _global$5$1).words[i] -= 67108864; + for (var i = 0; i < (this || _global$5$2).length && (this || _global$5$2).words[i] >= 67108864; i++) { + (this || _global$5$2).words[i] -= 67108864; - if (i === (this || _global$5$1).length - 1) { - (this || _global$5$1).words[i + 1] = 1; + if (i === (this || _global$5$2).length - 1) { + (this || _global$5$2).words[i + 1] = 1; } else { - (this || _global$5$1).words[i + 1]++; + (this || _global$5$2).words[i + 1]++; } } - (this || _global$5$1).length = Math.max((this || _global$5$1).length, i + 1); - return this || _global$5$1; + (this || _global$5$2).length = Math.max((this || _global$5$2).length, i + 1); + return this || _global$5$2; }; // Subtract plain number `num` from `this` @@ -39726,23 +74302,23 @@ function dew$x$1() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$5$1).negative !== 0) { - (this || _global$5$1).negative = 0; + if ((this || _global$5$2).negative !== 0) { + (this || _global$5$2).negative = 0; this.iaddn(num); - (this || _global$5$1).negative = 1; - return this || _global$5$1; + (this || _global$5$2).negative = 1; + return this || _global$5$2; } - (this || _global$5$1).words[0] -= num; + (this || _global$5$2).words[0] -= num; - if ((this || _global$5$1).length === 1 && (this || _global$5$1).words[0] < 0) { - (this || _global$5$1).words[0] = -(this || _global$5$1).words[0]; - (this || _global$5$1).negative = 1; + if ((this || _global$5$2).length === 1 && (this || _global$5$2).words[0] < 0) { + (this || _global$5$2).words[0] = -(this || _global$5$2).words[0]; + (this || _global$5$2).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$5$1).length && (this || _global$5$1).words[i] < 0; i++) { - (this || _global$5$1).words[i] += 67108864; - (this || _global$5$1).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$5$2).length && (this || _global$5$2).words[i] < 0; i++) { + (this || _global$5$2).words[i] += 67108864; + (this || _global$5$2).words[i + 1] -= 1; } } @@ -39758,8 +74334,8 @@ function dew$x$1() { }; BN.prototype.iabs = function iabs() { - (this || _global$5$1).negative = 0; - return this || _global$5$1; + (this || _global$5$2).negative = 0; + return this || _global$5$2; }; BN.prototype.abs = function abs() { @@ -39776,17 +74352,17 @@ function dew$x$1() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$5$1).words[i + shift] | 0) + carry; + w = ((this || _global$5$2).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$5$1).words[i + shift] = w & 67108863; + (this || _global$5$2).words[i + shift] = w & 67108863; } - for (; i < (this || _global$5$1).length - shift; i++) { - w = ((this || _global$5$1).words[i + shift] | 0) + carry; + for (; i < (this || _global$5$2).length - shift; i++) { + w = ((this || _global$5$2).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$5$1).words[i + shift] = w & 67108863; + (this || _global$5$2).words[i + shift] = w & 67108863; } if (carry === 0) return this.strip(); // Subtraction overflow @@ -39794,18 +74370,18 @@ function dew$x$1() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$5$1).length; i++) { - w = -((this || _global$5$1).words[i] | 0) + carry; + for (i = 0; i < (this || _global$5$2).length; i++) { + w = -((this || _global$5$2).words[i] | 0) + carry; carry = w >> 26; - (this || _global$5$1).words[i] = w & 67108863; + (this || _global$5$2).words[i] = w & 67108863; } - (this || _global$5$1).negative = 1; + (this || _global$5$2).negative = 1; return this.strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$5$1).length - num.length; + var shift = (this || _global$5$2).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -39901,7 +74477,7 @@ function dew$x$1() { var div, mod, res; - if ((this || _global$5$1).negative !== 0 && num.negative === 0) { + if ((this || _global$5$2).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -39922,7 +74498,7 @@ function dew$x$1() { }; } - if ((this || _global$5$1).negative === 0 && num.negative !== 0) { + if ((this || _global$5$2).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -39935,7 +74511,7 @@ function dew$x$1() { }; } - if (((this || _global$5$1).negative & num.negative) !== 0) { + if (((this || _global$5$2).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -39954,10 +74530,10 @@ function dew$x$1() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$5$1).length || this.cmp(num) < 0) { + if (num.length > (this || _global$5$2).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$5$1 + mod: this || _global$5$2 }; } // Very short reduction @@ -40020,8 +74596,8 @@ function dew$x$1() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$5$1).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$5$1).words[i] | 0)) % num; + for (var i = (this || _global$5$2).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$5$2).words[i] | 0)) % num; } return acc; @@ -40032,9 +74608,9 @@ function dew$x$1() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$5$1).length - 1; i >= 0; i--) { - var w = ((this || _global$5$1).words[i] | 0) + carry * 67108864; - (this || _global$5$1).words[i] = w / num | 0; + for (var i = (this || _global$5$2).length - 1; i >= 0; i--) { + var w = ((this || _global$5$2).words[i] | 0) + carry * 67108864; + (this || _global$5$2).words[i] = w / num | 0; carry = w % num; } @@ -40048,7 +74624,7 @@ function dew$x$1() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$5$1; + var x = this || _global$5$2; var y = p.clone(); if (x.negative !== 0) { @@ -40131,7 +74707,7 @@ function dew$x$1() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$5$1; + var a = this || _global$5$2; var b = p.clone(); if (a.negative !== 0) { @@ -40242,16 +74818,16 @@ function dew$x$1() { }; BN.prototype.isEven = function isEven() { - return ((this || _global$5$1).words[0] & 1) === 0; + return ((this || _global$5$2).words[0] & 1) === 0; }; BN.prototype.isOdd = function isOdd() { - return ((this || _global$5$1).words[0] & 1) === 1; + return ((this || _global$5$2).words[0] & 1) === 1; }; // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$5$1).words[0] & num; + return (this || _global$5$2).words[0] & num; }; // Increment at the bit position in-line @@ -40261,44 +74837,44 @@ function dew$x$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$5$1).length <= s) { + if ((this || _global$5$2).length <= s) { this._expand(s + 1); - (this || _global$5$1).words[s] |= q; - return this || _global$5$1; + (this || _global$5$2).words[s] |= q; + return this || _global$5$2; } // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$5$1).length; i++) { - var w = (this || _global$5$1).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$5$2).length; i++) { + var w = (this || _global$5$2).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$5$1).words[i] = w; + (this || _global$5$2).words[i] = w; } if (carry !== 0) { - (this || _global$5$1).words[i] = carry; - (this || _global$5$1).length++; + (this || _global$5$2).words[i] = carry; + (this || _global$5$2).length++; } - return this || _global$5$1; + return this || _global$5$2; }; BN.prototype.isZero = function isZero() { - return (this || _global$5$1).length === 1 && (this || _global$5$1).words[0] === 0; + return (this || _global$5$2).length === 1 && (this || _global$5$2).words[0] === 0; }; BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$5$1).negative !== 0 && !negative) return -1; - if ((this || _global$5$1).negative === 0 && negative) return 1; + if ((this || _global$5$2).negative !== 0 && !negative) return -1; + if ((this || _global$5$2).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$5$1).length > 1) { + if ((this || _global$5$2).length > 1) { res = 1; } else { if (negative) { @@ -40306,11 +74882,11 @@ function dew$x$1() { } assert(num <= 67108863, "Number is too big"); - var w = (this || _global$5$1).words[0] | 0; + var w = (this || _global$5$2).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$5$1).negative !== 0) return -res | 0; + if ((this || _global$5$2).negative !== 0) return -res | 0; return res; }; // Compare two numbers and return: // 1 - if `this` > `num` @@ -40319,22 +74895,22 @@ function dew$x$1() { BN.prototype.cmp = function cmp(num) { - if ((this || _global$5$1).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$5$1).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$5$2).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$5$2).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$5$1).negative !== 0) return -res | 0; + if ((this || _global$5$2).negative !== 0) return -res | 0; return res; }; // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$5$1).length > num.length) return 1; - if ((this || _global$5$1).length < num.length) return -1; + if ((this || _global$5$2).length > num.length) return 1; + if ((this || _global$5$2).length < num.length) return -1; var res = 0; - for (var i = (this || _global$5$1).length - 1; i >= 0; i--) { - var a = (this || _global$5$1).words[i] | 0; + for (var i = (this || _global$5$2).length - 1; i >= 0; i--) { + var a = (this || _global$5$2).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; @@ -40399,115 +74975,115 @@ function dew$x$1() { }; BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$5$1).red, "Already a number in reduction context"); - assert((this || _global$5$1).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$5$1)._forceRed(ctx); + assert(!(this || _global$5$2).red, "Already a number in reduction context"); + assert((this || _global$5$2).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$5$2)._forceRed(ctx); }; BN.prototype.fromRed = function fromRed() { - assert((this || _global$5$1).red, "fromRed works only with numbers in reduction context"); - return (this || _global$5$1).red.convertFrom(this || _global$5$1); + assert((this || _global$5$2).red, "fromRed works only with numbers in reduction context"); + return (this || _global$5$2).red.convertFrom(this || _global$5$2); }; BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$5$1).red = ctx; - return this || _global$5$1; + (this || _global$5$2).red = ctx; + return this || _global$5$2; }; BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$5$1).red, "Already a number in reduction context"); + assert(!(this || _global$5$2).red, "Already a number in reduction context"); return this._forceRed(ctx); }; BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$5$1).red, "redAdd works only with red numbers"); - return (this || _global$5$1).red.add(this || _global$5$1, num); + assert((this || _global$5$2).red, "redAdd works only with red numbers"); + return (this || _global$5$2).red.add(this || _global$5$2, num); }; BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$5$1).red, "redIAdd works only with red numbers"); - return (this || _global$5$1).red.iadd(this || _global$5$1, num); + assert((this || _global$5$2).red, "redIAdd works only with red numbers"); + return (this || _global$5$2).red.iadd(this || _global$5$2, num); }; BN.prototype.redSub = function redSub(num) { - assert((this || _global$5$1).red, "redSub works only with red numbers"); - return (this || _global$5$1).red.sub(this || _global$5$1, num); + assert((this || _global$5$2).red, "redSub works only with red numbers"); + return (this || _global$5$2).red.sub(this || _global$5$2, num); }; BN.prototype.redISub = function redISub(num) { - assert((this || _global$5$1).red, "redISub works only with red numbers"); - return (this || _global$5$1).red.isub(this || _global$5$1, num); + assert((this || _global$5$2).red, "redISub works only with red numbers"); + return (this || _global$5$2).red.isub(this || _global$5$2, num); }; BN.prototype.redShl = function redShl(num) { - assert((this || _global$5$1).red, "redShl works only with red numbers"); - return (this || _global$5$1).red.shl(this || _global$5$1, num); + assert((this || _global$5$2).red, "redShl works only with red numbers"); + return (this || _global$5$2).red.shl(this || _global$5$2, num); }; BN.prototype.redMul = function redMul(num) { - assert((this || _global$5$1).red, "redMul works only with red numbers"); + assert((this || _global$5$2).red, "redMul works only with red numbers"); - (this || _global$5$1).red._verify2(this || _global$5$1, num); + (this || _global$5$2).red._verify2(this || _global$5$2, num); - return (this || _global$5$1).red.mul(this || _global$5$1, num); + return (this || _global$5$2).red.mul(this || _global$5$2, num); }; BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$5$1).red, "redMul works only with red numbers"); + assert((this || _global$5$2).red, "redMul works only with red numbers"); - (this || _global$5$1).red._verify2(this || _global$5$1, num); + (this || _global$5$2).red._verify2(this || _global$5$2, num); - return (this || _global$5$1).red.imul(this || _global$5$1, num); + return (this || _global$5$2).red.imul(this || _global$5$2, num); }; BN.prototype.redSqr = function redSqr() { - assert((this || _global$5$1).red, "redSqr works only with red numbers"); + assert((this || _global$5$2).red, "redSqr works only with red numbers"); - (this || _global$5$1).red._verify1(this || _global$5$1); + (this || _global$5$2).red._verify1(this || _global$5$2); - return (this || _global$5$1).red.sqr(this || _global$5$1); + return (this || _global$5$2).red.sqr(this || _global$5$2); }; BN.prototype.redISqr = function redISqr() { - assert((this || _global$5$1).red, "redISqr works only with red numbers"); + assert((this || _global$5$2).red, "redISqr works only with red numbers"); - (this || _global$5$1).red._verify1(this || _global$5$1); + (this || _global$5$2).red._verify1(this || _global$5$2); - return (this || _global$5$1).red.isqr(this || _global$5$1); + return (this || _global$5$2).red.isqr(this || _global$5$2); }; // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$5$1).red, "redSqrt works only with red numbers"); + assert((this || _global$5$2).red, "redSqrt works only with red numbers"); - (this || _global$5$1).red._verify1(this || _global$5$1); + (this || _global$5$2).red._verify1(this || _global$5$2); - return (this || _global$5$1).red.sqrt(this || _global$5$1); + return (this || _global$5$2).red.sqrt(this || _global$5$2); }; BN.prototype.redInvm = function redInvm() { - assert((this || _global$5$1).red, "redInvm works only with red numbers"); + assert((this || _global$5$2).red, "redInvm works only with red numbers"); - (this || _global$5$1).red._verify1(this || _global$5$1); + (this || _global$5$2).red._verify1(this || _global$5$2); - return (this || _global$5$1).red.invm(this || _global$5$1); + return (this || _global$5$2).red.invm(this || _global$5$2); }; // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$5$1).red, "redNeg works only with red numbers"); + assert((this || _global$5$2).red, "redNeg works only with red numbers"); - (this || _global$5$1).red._verify1(this || _global$5$1); + (this || _global$5$2).red._verify1(this || _global$5$2); - return (this || _global$5$1).red.neg(this || _global$5$1); + return (this || _global$5$2).red.neg(this || _global$5$2); }; BN.prototype.redPow = function redPow(num) { - assert((this || _global$5$1).red && !num.red, "redPow(normalNum)"); + assert((this || _global$5$2).red && !num.red, "redPow(normalNum)"); - (this || _global$5$1).red._verify1(this || _global$5$1); + (this || _global$5$2).red._verify1(this || _global$5$2); - return (this || _global$5$1).red.pow(this || _global$5$1, num); + return (this || _global$5$2).red.pow(this || _global$5$2, num); }; // Prime numbers with efficient reduction @@ -40520,16 +75096,16 @@ function dew$x$1() { function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$5$1).name = name; - (this || _global$5$1).p = new BN(p, 16); - (this || _global$5$1).n = (this || _global$5$1).p.bitLength(); - (this || _global$5$1).k = new BN(1).iushln((this || _global$5$1).n).isub((this || _global$5$1).p); - (this || _global$5$1).tmp = this._tmp(); + (this || _global$5$2).name = name; + (this || _global$5$2).p = new BN(p, 16); + (this || _global$5$2).n = (this || _global$5$2).p.bitLength(); + (this || _global$5$2).k = new BN(1).iushln((this || _global$5$2).n).isub((this || _global$5$2).p); + (this || _global$5$2).tmp = this._tmp(); } MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$5$1).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$5$2).n / 13)); return tmp; }; @@ -40540,19 +75116,19 @@ function dew$x$1() { var rlen; do { - this.split(r, (this || _global$5$1).tmp); + this.split(r, (this || _global$5$2).tmp); r = this.imulK(r); - r = r.iadd((this || _global$5$1).tmp); + r = r.iadd((this || _global$5$2).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$5$1).n); + } while (rlen > (this || _global$5$2).n); - var cmp = rlen < (this || _global$5$1).n ? -1 : r.ucmp((this || _global$5$1).p); + var cmp = rlen < (this || _global$5$2).n ? -1 : r.ucmp((this || _global$5$2).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$5$1).p); + r.isub((this || _global$5$2).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -40567,15 +75143,15 @@ function dew$x$1() { }; MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$5$1).n, 0, out); + input.iushrn((this || _global$5$2).n, 0, out); }; MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$5$1).k); + return num.imul((this || _global$5$2).k); }; function K256() { - MPrime.call(this || _global$5$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$5$2, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } inherits(K256, MPrime); @@ -40645,20 +75221,20 @@ function dew$x$1() { }; function P224() { - MPrime.call(this || _global$5$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$5$2, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } inherits(P224, MPrime); function P192() { - MPrime.call(this || _global$5$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$5$2, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } inherits(P192, MPrime); function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$5$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$5$2, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } inherits(P25519, MPrime); @@ -40711,12 +75287,12 @@ function dew$x$1() { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$5$1).m = prime.p; - (this || _global$5$1).prime = prime; + (this || _global$5$2).m = prime.p; + (this || _global$5$2).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$5$1).m = m; - (this || _global$5$1).prime = null; + (this || _global$5$2).m = m; + (this || _global$5$2).prime = null; } } @@ -40731,8 +75307,8 @@ function dew$x$1() { }; Red.prototype.imod = function imod(a) { - if ((this || _global$5$1).prime) return (this || _global$5$1).prime.ireduce(a)._forceRed(this || _global$5$1); - return a.umod((this || _global$5$1).m)._forceRed(this || _global$5$1); + if ((this || _global$5$2).prime) return (this || _global$5$2).prime.ireduce(a)._forceRed(this || _global$5$2); + return a.umod((this || _global$5$2).m)._forceRed(this || _global$5$2); }; Red.prototype.neg = function neg(a) { @@ -40740,7 +75316,7 @@ function dew$x$1() { return a.clone(); } - return (this || _global$5$1).m.sub(a)._forceRed(this || _global$5$1); + return (this || _global$5$2).m.sub(a)._forceRed(this || _global$5$2); }; Red.prototype.add = function add(a, b) { @@ -40748,11 +75324,11 @@ function dew$x$1() { var res = a.add(b); - if (res.cmp((this || _global$5$1).m) >= 0) { - res.isub((this || _global$5$1).m); + if (res.cmp((this || _global$5$2).m) >= 0) { + res.isub((this || _global$5$2).m); } - return res._forceRed(this || _global$5$1); + return res._forceRed(this || _global$5$2); }; Red.prototype.iadd = function iadd(a, b) { @@ -40760,8 +75336,8 @@ function dew$x$1() { var res = a.iadd(b); - if (res.cmp((this || _global$5$1).m) >= 0) { - res.isub((this || _global$5$1).m); + if (res.cmp((this || _global$5$2).m) >= 0) { + res.isub((this || _global$5$2).m); } return res; @@ -40773,10 +75349,10 @@ function dew$x$1() { var res = a.sub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$5$1).m); + res.iadd((this || _global$5$2).m); } - return res._forceRed(this || _global$5$1); + return res._forceRed(this || _global$5$2); }; Red.prototype.isub = function isub(a, b) { @@ -40785,7 +75361,7 @@ function dew$x$1() { var res = a.isub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$5$1).m); + res.iadd((this || _global$5$2).m); } return res; @@ -40820,12 +75396,12 @@ function dew$x$1() { Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$5$1).m.andln(3); + var mod3 = (this || _global$5$2).m.andln(3); assert(mod3 % 2 === 1); // Fast case if (mod3 === 3) { - var pow = (this || _global$5$1).m.add(new BN(1)).iushrn(2); + var pow = (this || _global$5$2).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); } // Tonelli-Shanks algorithm (Totally unoptimized and slow) @@ -40833,7 +75409,7 @@ function dew$x$1() { // Find Q and S, that Q * 2 ^ S = (P - 1) - var q = (this || _global$5$1).m.subn(1); + var q = (this || _global$5$2).m.subn(1); var s = 0; @@ -40843,15 +75419,15 @@ function dew$x$1() { } assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$5$1); + var one = new BN(1).toRed(this || _global$5$2); var nOne = one.redNeg(); // Find quadratic non-residue // NOTE: Max is such because of generalized Riemann hypothesis. - var lpow = (this || _global$5$1).m.subn(1).iushrn(1); + var lpow = (this || _global$5$2).m.subn(1).iushrn(1); - var z = (this || _global$5$1).m.bitLength(); + var z = (this || _global$5$2).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$5$1); + z = new BN(2 * z * z).toRed(this || _global$5$2); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); @@ -40881,7 +75457,7 @@ function dew$x$1() { }; Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$5$1).m); + var inv = a._invmp((this || _global$5$2).m); if (inv.negative !== 0) { inv.negative = 0; @@ -40892,11 +75468,11 @@ function dew$x$1() { }; Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$5$1); + if (num.isZero()) return new BN(1).toRed(this || _global$5$2); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$5$1); + wnd[0] = new BN(1).toRed(this || _global$5$2); wnd[1] = a; for (var i = 2; i < wnd.length; i++) { @@ -40943,7 +75519,7 @@ function dew$x$1() { }; Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$5$1).m); + var r = num.umod((this || _global$5$2).m); return r === num ? r.clone() : r; }; @@ -40961,29 +75537,29 @@ function dew$x$1() { }; function Mont(m) { - Red.call(this || _global$5$1, m); - (this || _global$5$1).shift = (this || _global$5$1).m.bitLength(); + Red.call(this || _global$5$2, m); + (this || _global$5$2).shift = (this || _global$5$2).m.bitLength(); - if ((this || _global$5$1).shift % 26 !== 0) { - (this || _global$5$1).shift += 26 - (this || _global$5$1).shift % 26; + if ((this || _global$5$2).shift % 26 !== 0) { + (this || _global$5$2).shift += 26 - (this || _global$5$2).shift % 26; } - (this || _global$5$1).r = new BN(1).iushln((this || _global$5$1).shift); - (this || _global$5$1).r2 = this.imod((this || _global$5$1).r.sqr()); - (this || _global$5$1).rinv = (this || _global$5$1).r._invmp((this || _global$5$1).m); - (this || _global$5$1).minv = (this || _global$5$1).rinv.mul((this || _global$5$1).r).isubn(1).div((this || _global$5$1).m); - (this || _global$5$1).minv = (this || _global$5$1).minv.umod((this || _global$5$1).r); - (this || _global$5$1).minv = (this || _global$5$1).r.sub((this || _global$5$1).minv); + (this || _global$5$2).r = new BN(1).iushln((this || _global$5$2).shift); + (this || _global$5$2).r2 = this.imod((this || _global$5$2).r.sqr()); + (this || _global$5$2).rinv = (this || _global$5$2).r._invmp((this || _global$5$2).m); + (this || _global$5$2).minv = (this || _global$5$2).rinv.mul((this || _global$5$2).r).isubn(1).div((this || _global$5$2).m); + (this || _global$5$2).minv = (this || _global$5$2).minv.umod((this || _global$5$2).r); + (this || _global$5$2).minv = (this || _global$5$2).r.sub((this || _global$5$2).minv); } inherits(Mont, Red); Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$5$1).shift)); + return this.imod(num.ushln((this || _global$5$2).shift)); }; Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$5$1).rinv)); + var r = this.imod(num.mul((this || _global$5$2).rinv)); r.red = null; return r; }; @@ -40996,60 +75572,60 @@ function dew$x$1() { } var t = a.imul(b); - var c = t.maskn((this || _global$5$1).shift).mul((this || _global$5$1).minv).imaskn((this || _global$5$1).shift).mul((this || _global$5$1).m); - var u = t.isub(c).iushrn((this || _global$5$1).shift); + var c = t.maskn((this || _global$5$2).shift).mul((this || _global$5$2).minv).imaskn((this || _global$5$2).shift).mul((this || _global$5$2).m); + var u = t.isub(c).iushrn((this || _global$5$2).shift); var res = u; - if (u.cmp((this || _global$5$1).m) >= 0) { - res = u.isub((this || _global$5$1).m); + if (u.cmp((this || _global$5$2).m) >= 0) { + res = u.isub((this || _global$5$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$5$1).m); + res = u.iadd((this || _global$5$2).m); } - return res._forceRed(this || _global$5$1); + return res._forceRed(this || _global$5$2); }; Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$5$1); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$5$2); var t = a.mul(b); - var c = t.maskn((this || _global$5$1).shift).mul((this || _global$5$1).minv).imaskn((this || _global$5$1).shift).mul((this || _global$5$1).m); - var u = t.isub(c).iushrn((this || _global$5$1).shift); + var c = t.maskn((this || _global$5$2).shift).mul((this || _global$5$2).minv).imaskn((this || _global$5$2).shift).mul((this || _global$5$2).m); + var u = t.isub(c).iushrn((this || _global$5$2).shift); var res = u; - if (u.cmp((this || _global$5$1).m) >= 0) { - res = u.isub((this || _global$5$1).m); + if (u.cmp((this || _global$5$2).m) >= 0) { + res = u.isub((this || _global$5$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$5$1).m); + res = u.iadd((this || _global$5$2).m); } - return res._forceRed(this || _global$5$1); + return res._forceRed(this || _global$5$2); }; Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$5$1).m).mul((this || _global$5$1).r2)); - return res._forceRed(this || _global$5$1); + var res = this.imod(a._invmp((this || _global$5$2).m).mul((this || _global$5$2).r2)); + return res._forceRed(this || _global$5$2); }; - })(module$2$1, exports$x$1); + })(module$2$2, exports$y$2); - return module$2$1.exports; + return module$2$2.exports; } -var exports$w$1 = {}, - _dewExec$w$1 = false; -function dew$w$1() { - if (_dewExec$w$1) return exports$w$1; - _dewExec$w$1 = true; - var process = T$9; - var buffer = e$1$1$1; - var Buffer = buffer.Buffer; +var exports$x$2 = {}, + _dewExec$w$2 = false; +function dew$w$2() { + if (_dewExec$w$2) return exports$x$2; + _dewExec$w$2 = true; + var process$1$1 = process$1; + var buffer$1 = buffer; + var Buffer = buffer$1.Buffer; var safer = {}; var key; - for (key in buffer) { - if (!buffer.hasOwnProperty(key)) continue; + for (key in buffer$1) { + if (!buffer$1.hasOwnProperty(key)) continue; if (key === "SlowBuffer" || key === "Buffer") continue; - safer[key] = buffer[key]; + safer[key] = buffer$1[key]; } var Safer = safer.Buffer = {}; @@ -41102,7 +75678,7 @@ function dew$w$1() { if (!safer.kStringMaxLength) { try { - safer.kStringMaxLength = process.binding("buffer").kStringMaxLength; + safer.kStringMaxLength = process$1$1.binding("buffer").kStringMaxLength; } catch (e) {// we can't determine kStringMaxLength in environments where process.binding // is unsupported, so let's not set it } @@ -41118,17 +75694,17 @@ function dew$w$1() { } } - exports$w$1 = safer; - return exports$w$1; + exports$x$2 = safer; + return exports$x$2; } -var exports$v$1 = {}, - _dewExec$v$1 = false; -function dew$v$1() { - if (_dewExec$v$1) return exports$v$1; - _dewExec$v$1 = true; +var exports$w$2 = {}, + _dewExec$v$2 = false; +function dew$v$2() { + if (_dewExec$v$2) return exports$w$2; + _dewExec$v$2 = true; - const inherits = dew$f$2(); + const inherits = dew$f$4(); function Reporter(options) { this._reporterState = { @@ -41139,7 +75715,7 @@ function dew$v$1() { }; } - exports$v$1.Reporter = Reporter; + exports$w$2.Reporter = Reporter; Reporter.prototype.isError = function isError(obj) { return obj instanceof ReporterError; @@ -41242,20 +75818,20 @@ function dew$v$1() { return this; }; - return exports$v$1; + return exports$w$2; } -var exports$u$1 = {}, - _dewExec$u$1 = false; -function dew$u$1() { - if (_dewExec$u$1) return exports$u$1; - _dewExec$u$1 = true; +var exports$v$2 = {}, + _dewExec$u$2 = false; +function dew$u$2() { + if (_dewExec$u$2) return exports$v$2; + _dewExec$u$2 = true; - const inherits = dew$f$2(); + const inherits = dew$f$4(); - const Reporter = dew$v$1().Reporter; + const Reporter = dew$v$2().Reporter; - const Buffer = dew$w$1().Buffer; + const Buffer = dew$w$2().Buffer; function DecoderBuffer(base, options) { Reporter.call(this, options); @@ -41271,7 +75847,7 @@ function dew$u$1() { } inherits(DecoderBuffer, Reporter); - exports$u$1.DecoderBuffer = DecoderBuffer; + exports$v$2.DecoderBuffer = DecoderBuffer; DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) { if (data instanceof DecoderBuffer) { @@ -41346,7 +75922,7 @@ function dew$u$1() { } } - exports$u$1.EncoderBuffer = EncoderBuffer; + exports$v$2.EncoderBuffer = EncoderBuffer; EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) { if (data instanceof EncoderBuffer) { @@ -41376,22 +75952,22 @@ function dew$u$1() { return out; }; - return exports$u$1; + return exports$v$2; } -var exports$t$1 = {}, - _dewExec$t$1 = false; -function dew$t$1() { - if (_dewExec$t$1) return exports$t$1; - _dewExec$t$1 = true; +var exports$u$2 = {}, + _dewExec$t$2 = false; +function dew$t$2() { + if (_dewExec$t$2) return exports$u$2; + _dewExec$t$2 = true; - const Reporter = dew$v$1().Reporter; + const Reporter = dew$v$2().Reporter; - const EncoderBuffer = dew$u$1().EncoderBuffer; + const EncoderBuffer = dew$u$2().EncoderBuffer; - const DecoderBuffer = dew$u$1().DecoderBuffer; + const DecoderBuffer = dew$u$2().DecoderBuffer; - const assert = dew$1t(); // Supported tags + const assert = dew$2m(); // Supported tags const tags = ["seq", "seqof", "set", "setof", "objid", "bool", "gentime", "utctime", "null_", "enum", "int", "objDesc", "bitstr", "bmpstr", "charstr", "genstr", "graphstr", "ia5str", "iso646str", "numstr", "octstr", "printstr", "t61str", "unistr", "utf8str", "videostr"]; // Public methods list @@ -41430,7 +76006,7 @@ function dew$t$1() { } } - exports$t$1 = Node; + exports$u$2 = Node; const stateProps = ["enc", "parent", "children", "tag", "args", "reverseArgs", "choice", "optional", "any", "obj", "use", "alteredUse", "key", "default", "explicit", "implicit", "contains"]; Node.prototype.clone = function clone() { @@ -41866,14 +76442,14 @@ function dew$t$1() { return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str); }; - return exports$t$1; + return exports$u$2; } -var exports$s$1 = {}, - _dewExec$s$1 = false; -function dew$s$1() { - if (_dewExec$s$1) return exports$s$1; - _dewExec$s$1 = true; +var exports$t$2 = {}, + _dewExec$s$2 = false; +function dew$s$2() { + if (_dewExec$s$2) return exports$t$2; + _dewExec$s$2 = true; // Helper function reverse(map) { @@ -41887,14 +76463,14 @@ function dew$s$1() { return res; } - exports$s$1.tagClass = { + exports$t$2.tagClass = { 0: "universal", 1: "application", 2: "context", 3: "private" }; - exports$s$1.tagClassByName = reverse(exports$s$1.tagClass); - exports$s$1.tag = { + exports$t$2.tagClassByName = reverse(exports$t$2.tagClass); + exports$t$2.tag = { 0: "end", 1: "bool", 2: "int", @@ -41925,24 +76501,24 @@ function dew$s$1() { 29: "charstr", 30: "bmpstr" }; - exports$s$1.tagByName = reverse(exports$s$1.tag); - return exports$s$1; + exports$t$2.tagByName = reverse(exports$t$2.tag); + return exports$t$2; } -var exports$r$1 = {}, - _dewExec$r$1 = false; -function dew$r$1() { - if (_dewExec$r$1) return exports$r$1; - _dewExec$r$1 = true; +var exports$s$2 = {}, + _dewExec$r$2 = false; +function dew$r$2() { + if (_dewExec$r$2) return exports$s$2; + _dewExec$r$2 = true; - const inherits = dew$f$2(); + const inherits = dew$f$4(); - const Buffer = dew$w$1().Buffer; + const Buffer = dew$w$2().Buffer; - const Node = dew$t$1(); // Import DER constants + const Node = dew$t$2(); // Import DER constants - const der = dew$s$1(); + const der = dew$s$2(); function DEREncoder(entity) { this.enc = "der"; @@ -41954,7 +76530,7 @@ function dew$r$1() { this.tree._init(entity.body); } - exports$r$1 = DEREncoder; + exports$s$2 = DEREncoder; DEREncoder.prototype.encode = function encode(data, reporter) { return this.tree._encode(data, reporter).join(); @@ -42175,18 +76751,18 @@ function dew$r$1() { return res; } - return exports$r$1; + return exports$s$2; } -var exports$q$1 = {}, - _dewExec$q$1 = false; -function dew$q$1() { - if (_dewExec$q$1) return exports$q$1; - _dewExec$q$1 = true; +var exports$r$2 = {}, + _dewExec$q$2 = false; +function dew$q$2() { + if (_dewExec$q$2) return exports$r$2; + _dewExec$q$2 = true; - const inherits = dew$f$2(); + const inherits = dew$f$4(); - const DEREncoder = dew$r$1(); + const DEREncoder = dew$r$2(); function PEMEncoder(entity) { DEREncoder.call(this, entity); @@ -42194,7 +76770,7 @@ function dew$q$1() { } inherits(PEMEncoder, DEREncoder); - exports$q$1 = PEMEncoder; + exports$r$2 = PEMEncoder; PEMEncoder.prototype.encode = function encode(data, options) { const buf = DEREncoder.prototype.encode.call(this, data); @@ -42207,36 +76783,36 @@ function dew$q$1() { return out.join("\n"); }; - return exports$q$1; + return exports$r$2; } -var exports$p$1 = {}, - _dewExec$p$1 = false; -function dew$p$1() { - if (_dewExec$p$1) return exports$p$1; - _dewExec$p$1 = true; - const encoders = exports$p$1; - encoders.der = dew$r$1(); - encoders.pem = dew$q$1(); - return exports$p$1; +var exports$q$2 = {}, + _dewExec$p$2 = false; +function dew$p$2() { + if (_dewExec$p$2) return exports$q$2; + _dewExec$p$2 = true; + const encoders = exports$q$2; + encoders.der = dew$r$2(); + encoders.pem = dew$q$2(); + return exports$q$2; } -var exports$o$1 = {}, - _dewExec$o$1 = false; -function dew$o$1() { - if (_dewExec$o$1) return exports$o$1; - _dewExec$o$1 = true; +var exports$p$2 = {}, + _dewExec$o$2 = false; +function dew$o$2() { + if (_dewExec$o$2) return exports$p$2; + _dewExec$o$2 = true; - const inherits = dew$f$2(); + const inherits = dew$f$4(); - const bignum = dew$x$1(); + const bignum = dew$x$2(); - const DecoderBuffer = dew$u$1().DecoderBuffer; + const DecoderBuffer = dew$u$2().DecoderBuffer; - const Node = dew$t$1(); // Import DER constants + const Node = dew$t$2(); // Import DER constants - const der = dew$s$1(); + const der = dew$s$2(); function DERDecoder(entity) { this.enc = "der"; @@ -42248,7 +76824,7 @@ function dew$o$1() { this.tree._init(entity.body); } - exports$o$1 = DERDecoder; + exports$p$2 = DERDecoder; DERDecoder.prototype.decode = function decode(data, options) { if (!DecoderBuffer.isDecoderBuffer(data)) { @@ -42511,20 +77087,20 @@ function dew$o$1() { return len; } - return exports$o$1; + return exports$p$2; } -var exports$n$1 = {}, - _dewExec$n$1 = false; -function dew$n$1() { - if (_dewExec$n$1) return exports$n$1; - _dewExec$n$1 = true; +var exports$o$2 = {}, + _dewExec$n$2 = false; +function dew$n$2() { + if (_dewExec$n$2) return exports$o$2; + _dewExec$n$2 = true; - const inherits = dew$f$2(); + const inherits = dew$f$4(); - const Buffer = dew$w$1().Buffer; + const Buffer = dew$w$2().Buffer; - const DERDecoder = dew$o$1(); + const DERDecoder = dew$o$2(); function PEMDecoder(entity) { DERDecoder.call(this, entity); @@ -42532,7 +77108,7 @@ function dew$n$1() { } inherits(PEMDecoder, DERDecoder); - exports$n$1 = PEMDecoder; + exports$o$2 = PEMDecoder; PEMDecoder.prototype.decode = function decode(data, options) { const lines = data.toString().split(/[\r\n]+/g); @@ -42564,33 +77140,33 @@ function dew$n$1() { return DERDecoder.prototype.decode.call(this, input, options); }; - return exports$n$1; + return exports$o$2; } -var exports$m$1 = {}, - _dewExec$m$1 = false; -function dew$m$1() { - if (_dewExec$m$1) return exports$m$1; - _dewExec$m$1 = true; - const decoders = exports$m$1; - decoders.der = dew$o$1(); - decoders.pem = dew$n$1(); - return exports$m$1; +var exports$n$2 = {}, + _dewExec$m$2 = false; +function dew$m$2() { + if (_dewExec$m$2) return exports$n$2; + _dewExec$m$2 = true; + const decoders = exports$n$2; + decoders.der = dew$o$2(); + decoders.pem = dew$n$2(); + return exports$n$2; } -var exports$l$1 = {}, - _dewExec$l$1 = false; -function dew$l$1() { - if (_dewExec$l$1) return exports$l$1; - _dewExec$l$1 = true; +var exports$m$2 = {}, + _dewExec$l$2 = false; +function dew$l$2() { + if (_dewExec$l$2) return exports$m$2; + _dewExec$l$2 = true; - const encoders = dew$p$1(); + const encoders = dew$p$2(); - const decoders = dew$m$1(); + const decoders = dew$m$2(); - const inherits = dew$f$2(); + const inherits = dew$f$4(); - const api = exports$l$1; + const api = exports$m$2; api.define = function define(name, body) { return new Entity(name, body); @@ -42643,28 +77219,28 @@ function dew$l$1() { return this._getEncoder(enc).encode(data, reporter); }; - return exports$l$1; + return exports$m$2; } -var exports$k$1 = {}, - _dewExec$k$1 = false; -function dew$k$1() { - if (_dewExec$k$1) return exports$k$1; - _dewExec$k$1 = true; - const base = exports$k$1; - base.Reporter = dew$v$1().Reporter; - base.DecoderBuffer = dew$u$1().DecoderBuffer; - base.EncoderBuffer = dew$u$1().EncoderBuffer; - base.Node = dew$t$1(); - return exports$k$1; +var exports$l$2 = {}, + _dewExec$k$2 = false; +function dew$k$2() { + if (_dewExec$k$2) return exports$l$2; + _dewExec$k$2 = true; + const base = exports$l$2; + base.Reporter = dew$v$2().Reporter; + base.DecoderBuffer = dew$u$2().DecoderBuffer; + base.EncoderBuffer = dew$u$2().EncoderBuffer; + base.Node = dew$t$2(); + return exports$l$2; } -var exports$j$1 = {}, - _dewExec$j$1 = false; -function dew$j$1() { - if (_dewExec$j$1) return exports$j$1; - _dewExec$j$1 = true; - const constants = exports$j$1; // Helper +var exports$k$2 = {}, + _dewExec$j$2 = false; +function dew$j$2() { + if (_dewExec$j$2) return exports$k$2; + _dewExec$j$2 = true; + const constants = exports$k$2; // Helper constants._reverse = function reverse(map) { const res = {}; @@ -42677,32 +77253,32 @@ function dew$j$1() { return res; }; - constants.der = dew$s$1(); - return exports$j$1; + constants.der = dew$s$2(); + return exports$k$2; } -var exports$i$1 = {}, - _dewExec$i$1 = false; -function dew$i$1() { - if (_dewExec$i$1) return exports$i$1; - _dewExec$i$1 = true; - const asn1 = exports$i$1; - asn1.bignum = dew$x$1(); - asn1.define = dew$l$1().define; - asn1.base = dew$k$1(); - asn1.constants = dew$j$1(); - asn1.decoders = dew$m$1(); - asn1.encoders = dew$p$1(); - return exports$i$1; +var exports$j$2 = {}, + _dewExec$i$2 = false; +function dew$i$2() { + if (_dewExec$i$2) return exports$j$2; + _dewExec$i$2 = true; + const asn1 = exports$j$2; + asn1.bignum = dew$x$2(); + asn1.define = dew$l$2().define; + asn1.base = dew$k$2(); + asn1.constants = dew$j$2(); + asn1.decoders = dew$m$2(); + asn1.encoders = dew$p$2(); + return exports$j$2; } -var exports$h$1 = {}, - _dewExec$h$1 = false; -function dew$h$1() { - if (_dewExec$h$1) return exports$h$1; - _dewExec$h$1 = true; +var exports$i$2 = {}, + _dewExec$h$2 = false; +function dew$h$2() { + if (_dewExec$h$2) return exports$i$2; + _dewExec$h$2 = true; - var asn = dew$i$1(); + var asn = dew$i$2(); var Time = asn.define("Time", function () { this.choice({ @@ -42742,65 +77318,65 @@ function dew$h$1() { var X509Certificate = asn.define("X509Certificate", function () { this.seq().obj(this.key("tbsCertificate").use(TBSCertificate), this.key("signatureAlgorithm").use(AlgorithmIdentifier), this.key("signatureValue").bitstr()); }); - exports$h$1 = X509Certificate; - return exports$h$1; + exports$i$2 = X509Certificate; + return exports$i$2; } -var exports$g$1 = {}, - _dewExec$g$1 = false; -function dew$g$1() { - if (_dewExec$g$1) return exports$g$1; - _dewExec$g$1 = true; +var exports$h$2 = {}, + _dewExec$g$2 = false; +function dew$g$2() { + if (_dewExec$g$2) return exports$h$2; + _dewExec$g$2 = true; - var asn1 = dew$i$1(); + var asn1 = dew$i$2(); - exports$g$1.certificate = dew$h$1(); + exports$h$2.certificate = dew$h$2(); var RSAPrivateKey = asn1.define("RSAPrivateKey", function () { this.seq().obj(this.key("version").int(), this.key("modulus").int(), this.key("publicExponent").int(), this.key("privateExponent").int(), this.key("prime1").int(), this.key("prime2").int(), this.key("exponent1").int(), this.key("exponent2").int(), this.key("coefficient").int()); }); - exports$g$1.RSAPrivateKey = RSAPrivateKey; + exports$h$2.RSAPrivateKey = RSAPrivateKey; var RSAPublicKey = asn1.define("RSAPublicKey", function () { this.seq().obj(this.key("modulus").int(), this.key("publicExponent").int()); }); - exports$g$1.RSAPublicKey = RSAPublicKey; + exports$h$2.RSAPublicKey = RSAPublicKey; var PublicKey = asn1.define("SubjectPublicKeyInfo", function () { this.seq().obj(this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPublicKey").bitstr()); }); - exports$g$1.PublicKey = PublicKey; + exports$h$2.PublicKey = PublicKey; var AlgorithmIdentifier = asn1.define("AlgorithmIdentifier", function () { this.seq().obj(this.key("algorithm").objid(), this.key("none").null_().optional(), this.key("curve").objid().optional(), this.key("params").seq().obj(this.key("p").int(), this.key("q").int(), this.key("g").int()).optional()); }); var PrivateKeyInfo = asn1.define("PrivateKeyInfo", function () { this.seq().obj(this.key("version").int(), this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPrivateKey").octstr()); }); - exports$g$1.PrivateKey = PrivateKeyInfo; + exports$h$2.PrivateKey = PrivateKeyInfo; var EncryptedPrivateKeyInfo = asn1.define("EncryptedPrivateKeyInfo", function () { this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(), this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(), this.key("kdeparams").seq().obj(this.key("salt").octstr(), this.key("iters").int())), this.key("cipher").seq().obj(this.key("algo").objid(), this.key("iv").octstr()))), this.key("subjectPrivateKey").octstr()); }); - exports$g$1.EncryptedPrivateKey = EncryptedPrivateKeyInfo; + exports$h$2.EncryptedPrivateKey = EncryptedPrivateKeyInfo; var DSAPrivateKey = asn1.define("DSAPrivateKey", function () { this.seq().obj(this.key("version").int(), this.key("p").int(), this.key("q").int(), this.key("g").int(), this.key("pub_key").int(), this.key("priv_key").int()); }); - exports$g$1.DSAPrivateKey = DSAPrivateKey; - exports$g$1.DSAparam = asn1.define("DSAparam", function () { + exports$h$2.DSAPrivateKey = DSAPrivateKey; + exports$h$2.DSAparam = asn1.define("DSAparam", function () { this.int(); }); var ECPrivateKey = asn1.define("ECPrivateKey", function () { this.seq().obj(this.key("version").int(), this.key("privateKey").octstr(), this.key("parameters").optional().explicit(0).use(ECParameters), this.key("publicKey").optional().explicit(1).bitstr()); }); - exports$g$1.ECPrivateKey = ECPrivateKey; + exports$h$2.ECPrivateKey = ECPrivateKey; var ECParameters = asn1.define("ECParameters", function () { this.choice({ namedCurve: this.objid() }); }); - exports$g$1.signature = asn1.define("signature", function () { + exports$h$2.signature = asn1.define("signature", function () { this.seq().obj(this.key("r").int(), this.key("s").int()); }); - return exports$g$1; + return exports$h$2; } -var _aesid$1 = {"2.16.840.1.101.3.4.1.1": "aes-128-ecb", +var _aesid$2 = {"2.16.840.1.101.3.4.1.1": "aes-128-ecb", "2.16.840.1.101.3.4.1.2": "aes-128-cbc", "2.16.840.1.101.3.4.1.3": "aes-128-ofb", "2.16.840.1.101.3.4.1.4": "aes-128-cfb", @@ -42814,23 +77390,23 @@ var _aesid$1 = {"2.16.840.1.101.3.4.1.1": "aes-128-ecb", "2.16.840.1.101.3.4.1.44": "aes-256-cfb" }; -var exports$f$1 = {}, - _dewExec$f$1 = false; -function dew$f$1() { - if (_dewExec$f$1) return exports$f$1; - _dewExec$f$1 = true; +var exports$g$2 = {}, + _dewExec$f$3 = false; +function dew$f$3() { + if (_dewExec$f$3) return exports$g$2; + _dewExec$f$3 = true; // adapted from https://github.com/apatil/pemstrip var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m; var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m; var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m; - var evp = dew$18(); + var evp = dew$21(); - var ciphers = dew$15(); + var ciphers = dew$1_(); - var Buffer = dew$1T().Buffer; + var Buffer = dew$2P().Buffer; - exports$f$1 = function (okey, password) { + exports$g$2 = function (okey, password) { var key = okey.toString(); var match = key.match(findProc); var decrypted; @@ -42857,28 +77433,28 @@ function dew$f$1() { }; }; - return exports$f$1; + return exports$g$2; } -var exports$e$1 = {}, - _dewExec$e$1 = false; -function dew$e$1() { - if (_dewExec$e$1) return exports$e$1; - _dewExec$e$1 = true; +var exports$f$3 = {}, + _dewExec$e$3 = false; +function dew$e$3() { + if (_dewExec$e$3) return exports$f$3; + _dewExec$e$3 = true; - var asn1 = dew$g$1(); + var asn1 = dew$g$2(); - var aesid = _aesid$1; + var aesid = _aesid$2; - var fixProc = dew$f$1(); + var fixProc = dew$f$3(); - var ciphers = dew$15(); + var ciphers = dew$1_(); - var compat = dew$1v(); + var compat = dew$2o(); - var Buffer = dew$1T().Buffer; + var Buffer = dew$2P().Buffer; - exports$e$1 = parseKeys; + exports$f$3 = parseKeys; function parseKeys(buffer) { var password; @@ -43006,10 +77582,10 @@ function dew$e$1() { return Buffer.concat(out); } - return exports$e$1; + return exports$f$3; } -var _curves$1 = { +var _curves$2 = { "1.3.132.0.10": "secp256k1", "1.3.132.0.33": "p224", "1.2.840.10045.3.1.1": "p192", @@ -43018,26 +77594,26 @@ var _curves$1 = { "1.3.132.0.35": "p521" }; -var exports$d$1 = {}, - _dewExec$d$1 = false; -function dew$d$1() { - if (_dewExec$d$1) return exports$d$1; - _dewExec$d$1 = true; +var exports$e$3 = {}, + _dewExec$d$3 = false; +function dew$d$3() { + if (_dewExec$d$3) return exports$e$3; + _dewExec$d$3 = true; // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js - var Buffer = dew$1T().Buffer; + var Buffer = dew$Y$2().Buffer; - var createHmac = dew$1C(); + var createHmac = dew$2v(); - var crt = dew$W$1(); + var crt = dew$W$2(); - var EC = dew$y$1().ec; + var EC = dew$y$2().ec; - var BN = dew$X$1(); + var BN = dew$X$2(); - var parseKeys = dew$e$1(); + var parseKeys = dew$e$3(); - var curves = _curves$1; + var curves = _curves$2; function sign(hash, key, hashType, signType, tag) { var priv = parseKeys(key); @@ -43181,28 +77757,28 @@ function dew$d$1() { return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q); } - exports$d$1 = sign; - exports$d$1.getKey = getKey; - exports$d$1.makeKey = makeKey; - return exports$d$1; + exports$e$3 = sign; + exports$e$3.getKey = getKey; + exports$e$3.makeKey = makeKey; + return exports$e$3; } -var exports$c$1 = {}, - _dewExec$c$1 = false; -function dew$c$1() { - if (_dewExec$c$1) return exports$c$1; - _dewExec$c$1 = true; +var exports$d$3 = {}, + _dewExec$c$3 = false; +function dew$c$3() { + if (_dewExec$c$3) return exports$d$3; + _dewExec$c$3 = true; // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js - var Buffer = dew$1T().Buffer; + var Buffer = dew$Y$2().Buffer; - var BN = dew$X$1(); + var BN = dew$X$2(); - var EC = dew$y$1().ec; + var EC = dew$y$2().ec; - var parseKeys = dew$e$1(); + var parseKeys = dew$e$3(); - var curves = _curves$1; + var curves = _curves$2; function verify(sig, hash, key, signType, tag) { var pub = parseKeys(key); @@ -43279,51 +77855,51 @@ function dew$c$1() { if (b.cmp(q) >= q) throw new Error("invalid sig"); } - exports$c$1 = verify; - return exports$c$1; + exports$d$3 = verify; + return exports$d$3; } -var exports$b$1 = {}, - _dewExec$b$1 = false; +var exports$c$3 = {}, + _dewExec$b$3 = false; -var _global$4$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$4$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$b$1() { - if (_dewExec$b$1) return exports$b$1; - _dewExec$b$1 = true; +function dew$b$3() { + if (_dewExec$b$3) return exports$c$3; + _dewExec$b$3 = true; - var Buffer = dew$1T().Buffer; + var Buffer = dew$Y$2().Buffer; - var createHash = dew$1F(); + var createHash = dew$2y(); - var stream = dew$1V(); + var stream = dew$3K(); - var inherits = dew$f$2(); + var inherits = dew$f$4(); - var sign = dew$d$1(); + var sign = dew$d$3(); - var verify = dew$c$1(); + var verify = dew$c$3(); - var algorithms = _algorithms; + var algorithms = _algorithms$1; Object.keys(algorithms).forEach(function (key) { algorithms[key].id = Buffer.from(algorithms[key].id, "hex"); algorithms[key.toLowerCase()] = algorithms[key]; }); function Sign(algorithm) { - stream.Writable.call(this || _global$4$1); + stream.Writable.call(this || _global$4$2); var data = algorithms[algorithm]; if (!data) throw new Error("Unknown message digest"); - (this || _global$4$1)._hashType = data.hash; - (this || _global$4$1)._hash = createHash(data.hash); - (this || _global$4$1)._tag = data.id; - (this || _global$4$1)._signType = data.sign; + (this || _global$4$2)._hashType = data.hash; + (this || _global$4$2)._hash = createHash(data.hash); + (this || _global$4$2)._tag = data.id; + (this || _global$4$2)._signType = data.sign; } inherits(Sign, stream.Writable); Sign.prototype._write = function _write(data, _, done) { - (this || _global$4$1)._hash.update(data); + (this || _global$4$2)._hash.update(data); done(); }; @@ -43331,33 +77907,33 @@ function dew$b$1() { Sign.prototype.update = function update(data, enc) { if (typeof data === "string") data = Buffer.from(data, enc); - (this || _global$4$1)._hash.update(data); + (this || _global$4$2)._hash.update(data); - return this || _global$4$1; + return this || _global$4$2; }; Sign.prototype.sign = function signMethod(key, enc) { this.end(); - var hash = (this || _global$4$1)._hash.digest(); + var hash = (this || _global$4$2)._hash.digest(); - var sig = sign(hash, key, (this || _global$4$1)._hashType, (this || _global$4$1)._signType, (this || _global$4$1)._tag); + var sig = sign(hash, key, (this || _global$4$2)._hashType, (this || _global$4$2)._signType, (this || _global$4$2)._tag); return enc ? sig.toString(enc) : sig; }; function Verify(algorithm) { - stream.Writable.call(this || _global$4$1); + stream.Writable.call(this || _global$4$2); var data = algorithms[algorithm]; if (!data) throw new Error("Unknown message digest"); - (this || _global$4$1)._hash = createHash(data.hash); - (this || _global$4$1)._tag = data.id; - (this || _global$4$1)._signType = data.sign; + (this || _global$4$2)._hash = createHash(data.hash); + (this || _global$4$2)._tag = data.id; + (this || _global$4$2)._signType = data.sign; } inherits(Verify, stream.Writable); Verify.prototype._write = function _write(data, _, done) { - (this || _global$4$1)._hash.update(data); + (this || _global$4$2)._hash.update(data); done(); }; @@ -43365,18 +77941,18 @@ function dew$b$1() { Verify.prototype.update = function update(data, enc) { if (typeof data === "string") data = Buffer.from(data, enc); - (this || _global$4$1)._hash.update(data); + (this || _global$4$2)._hash.update(data); - return this || _global$4$1; + return this || _global$4$2; }; Verify.prototype.verify = function verifyMethod(key, sig, enc) { if (typeof sig === "string") sig = Buffer.from(sig, enc); this.end(); - var hash = (this || _global$4$1)._hash.digest(); + var hash = (this || _global$4$2)._hash.digest(); - return verify(sig, hash, key, (this || _global$4$1)._signType, (this || _global$4$1)._tag); + return verify(sig, hash, key, (this || _global$4$2)._signType, (this || _global$4$2)._tag); }; function createSign(algorithm) { @@ -43387,26 +77963,26 @@ function dew$b$1() { return new Verify(algorithm); } - exports$b$1 = { + exports$c$3 = { Sign: createSign, Verify: createVerify, createSign: createSign, createVerify: createVerify }; - return exports$b$1; + return exports$c$3; } -var exports$a$1 = {}, - _dewExec$a$1 = false; -var module$1$1 = { - exports: exports$a$1 +var exports$b$3 = {}, + _dewExec$a$3 = false; +var module$1$2 = { + exports: exports$b$3 }; -var _global$3$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$3$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$a$1() { - if (_dewExec$a$1) return module$1$1.exports; - _dewExec$a$1 = true; +function dew$a$3() { + if (_dewExec$a$3) return module$1$2.exports; + _dewExec$a$3 = true; (function (module, exports) { @@ -43432,11 +78008,11 @@ function dew$a$1() { return number; } - (this || _global$3$1).negative = 0; - (this || _global$3$1).words = null; - (this || _global$3$1).length = 0; // Reduction context + (this || _global$3$2).negative = 0; + (this || _global$3$2).words = null; + (this || _global$3$2).length = 0; // Reduction context - (this || _global$3$1).red = null; + (this || _global$3$2).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -43462,7 +78038,7 @@ function dew$a$1() { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = e$1$1$1.Buffer; + Buffer = buffer.Buffer; } } catch (e) {} @@ -43503,7 +78079,7 @@ function dew$a$1() { if (number[0] === "-") { start++; - (this || _global$3$1).negative = 1; + (this || _global$3$2).negative = 1; } if (start < number.length) { @@ -43521,21 +78097,21 @@ function dew$a$1() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$3$1).negative = 1; + (this || _global$3$2).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$3$1).words = [number & 67108863]; - (this || _global$3$1).length = 1; + (this || _global$3$2).words = [number & 67108863]; + (this || _global$3$2).length = 1; } else if (number < 4503599627370496) { - (this || _global$3$1).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$3$1).length = 2; + (this || _global$3$2).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$3$2).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$3$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$3$1).length = 3; + (this || _global$3$2).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$3$2).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -43548,16 +78124,16 @@ function dew$a$1() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$3$1).words = [0]; - (this || _global$3$1).length = 1; - return this || _global$3$1; + (this || _global$3$2).words = [0]; + (this || _global$3$2).length = 1; + return this || _global$3$2; } - (this || _global$3$1).length = Math.ceil(number.length / 3); - (this || _global$3$1).words = new Array((this || _global$3$1).length); + (this || _global$3$2).length = Math.ceil(number.length / 3); + (this || _global$3$2).words = new Array((this || _global$3$2).length); - for (var i = 0; i < (this || _global$3$1).length; i++) { - (this || _global$3$1).words[i] = 0; + for (var i = 0; i < (this || _global$3$2).length; i++) { + (this || _global$3$2).words[i] = 0; } var j, w; @@ -43566,8 +78142,8 @@ function dew$a$1() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$3$1).words[j] |= w << off & 67108863; - (this || _global$3$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$3$2).words[j] |= w << off & 67108863; + (this || _global$3$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -43578,8 +78154,8 @@ function dew$a$1() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$3$1).words[j] |= w << off & 67108863; - (this || _global$3$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$3$2).words[j] |= w << off & 67108863; + (this || _global$3$2).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -43616,11 +78192,11 @@ function dew$a$1() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$3$1).length = Math.ceil((number.length - start) / 6); - (this || _global$3$1).words = new Array((this || _global$3$1).length); + (this || _global$3$2).length = Math.ceil((number.length - start) / 6); + (this || _global$3$2).words = new Array((this || _global$3$2).length); - for (var i = 0; i < (this || _global$3$1).length; i++) { - (this || _global$3$1).words[i] = 0; + for (var i = 0; i < (this || _global$3$2).length; i++) { + (this || _global$3$2).words[i] = 0; } // 24-bits chunks @@ -43631,12 +78207,12 @@ function dew$a$1() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$3$1).words[j] |= w & 67108863; + (this || _global$3$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$3$1).words[j] |= w >>> 26; + (this || _global$3$2).words[j] |= w >>> 26; } else { off += 8; } @@ -43646,12 +78222,12 @@ function dew$a$1() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$3$1).words[j] |= w & 67108863; + (this || _global$3$2).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$3$1).words[j] |= w >>> 26; + (this || _global$3$2).words[j] |= w >>> 26; } else { off += 8; } @@ -43683,8 +78259,8 @@ function dew$a$1() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$3$1).words = [0]; - (this || _global$3$1).length = 1; // Find length of limb in base + (this || _global$3$2).words = [0]; + (this || _global$3$2).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -43701,8 +78277,8 @@ function dew$a$1() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$3$1).words[0] + word < 67108864) { - (this || _global$3$1).words[0] += word; + if ((this || _global$3$2).words[0] + word < 67108864) { + (this || _global$3$2).words[0] += word; } else { this._iaddn(word); } @@ -43718,8 +78294,8 @@ function dew$a$1() { this.imuln(pow); - if ((this || _global$3$1).words[0] + word < 67108864) { - (this || _global$3$1).words[0] += word; + if ((this || _global$3$2).words[0] + word < 67108864) { + (this || _global$3$2).words[0] += word; } else { this._iaddn(word); } @@ -43729,15 +78305,15 @@ function dew$a$1() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$3$1).length); + dest.words = new Array((this || _global$3$2).length); - for (var i = 0; i < (this || _global$3$1).length; i++) { - dest.words[i] = (this || _global$3$1).words[i]; + for (var i = 0; i < (this || _global$3$2).length; i++) { + dest.words[i] = (this || _global$3$2).words[i]; } - dest.length = (this || _global$3$1).length; - dest.negative = (this || _global$3$1).negative; - dest.red = (this || _global$3$1).red; + dest.length = (this || _global$3$2).length; + dest.negative = (this || _global$3$2).negative; + dest.red = (this || _global$3$2).red; }; BN.prototype.clone = function clone() { @@ -43747,17 +78323,17 @@ function dew$a$1() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$3$1).length < size) { - (this || _global$3$1).words[(this || _global$3$1).length++] = 0; + while ((this || _global$3$2).length < size) { + (this || _global$3$2).words[(this || _global$3$2).length++] = 0; } - return this || _global$3$1; + return this || _global$3$2; }; // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$3$1).length > 1 && (this || _global$3$1).words[(this || _global$3$1).length - 1] === 0) { - (this || _global$3$1).length--; + while ((this || _global$3$2).length > 1 && (this || _global$3$2).words[(this || _global$3$2).length - 1] === 0) { + (this || _global$3$2).length--; } return this._normSign(); @@ -43765,15 +78341,15 @@ function dew$a$1() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$3$1).length === 1 && (this || _global$3$1).words[0] === 0) { - (this || _global$3$1).negative = 0; + if ((this || _global$3$2).length === 1 && (this || _global$3$2).words[0] === 0) { + (this || _global$3$2).negative = 0; } - return this || _global$3$1; + return this || _global$3$2; }; BN.prototype.inspect = function inspect() { - return ((this || _global$3$1).red ? ""; + return ((this || _global$3$2).red ? ""; }; /* var zeros = []; @@ -43817,12 +78393,12 @@ function dew$a$1() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$3$1).length; i++) { - var w = (this || _global$3$1).words[i]; + for (var i = 0; i < (this || _global$3$2).length; i++) { + var w = (this || _global$3$2).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$3$1).length - 1) { + if (carry !== 0 || i !== (this || _global$3$2).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -43844,7 +78420,7 @@ function dew$a$1() { out = "0" + out; } - if ((this || _global$3$1).negative !== 0) { + if ((this || _global$3$2).negative !== 0) { out = "-" + out; } @@ -43879,7 +78455,7 @@ function dew$a$1() { out = "0" + out; } - if ((this || _global$3$1).negative !== 0) { + if ((this || _global$3$2).negative !== 0) { out = "-" + out; } @@ -43890,18 +78466,18 @@ function dew$a$1() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$3$1).words[0]; + var ret = (this || _global$3$2).words[0]; - if ((this || _global$3$1).length === 2) { - ret += (this || _global$3$1).words[1] * 67108864; - } else if ((this || _global$3$1).length === 3 && (this || _global$3$1).words[2] === 1) { + if ((this || _global$3$2).length === 2) { + ret += (this || _global$3$2).words[1] * 67108864; + } else if ((this || _global$3$2).length === 3 && (this || _global$3$2).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$3$1).words[1] * 67108864; - } else if ((this || _global$3$1).length > 2) { + ret += 4503599627370496 + (this || _global$3$2).words[1] * 67108864; + } else if ((this || _global$3$2).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$3$1).negative !== 0 ? -ret : ret; + return (this || _global$3$2).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -44022,11 +78598,11 @@ function dew$a$1() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$3$1).words[(this || _global$3$1).length - 1]; + var w = (this || _global$3$2).words[(this || _global$3$2).length - 1]; var hi = this._countBits(w); - return ((this || _global$3$1).length - 1) * 26 + hi; + return ((this || _global$3$2).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -44046,8 +78622,8 @@ function dew$a$1() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$3$1).length; i++) { - var b = this._zeroBits((this || _global$3$1).words[i]); + for (var i = 0; i < (this || _global$3$2).length; i++) { + var b = this._zeroBits((this || _global$3$2).words[i]); r += b; if (b !== 26) break; @@ -44061,7 +78637,7 @@ function dew$a$1() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$3$1).negative !== 0) { + if ((this || _global$3$2).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -44077,7 +78653,7 @@ function dew$a$1() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$3$1).negative !== 0; + return (this || _global$3$2).negative !== 0; }; // Return negative clone of `this` @@ -44087,39 +78663,39 @@ function dew$a$1() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$3$1).negative ^= 1; + (this || _global$3$2).negative ^= 1; } - return this || _global$3$1; + return this || _global$3$2; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$3$1).length < num.length) { - (this || _global$3$1).words[(this || _global$3$1).length++] = 0; + while ((this || _global$3$2).length < num.length) { + (this || _global$3$2).words[(this || _global$3$2).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$3$1).words[i] = (this || _global$3$1).words[i] | num.words[i]; + (this || _global$3$2).words[i] = (this || _global$3$2).words[i] | num.words[i]; } return this.strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$3$1).negative | num.negative) === 0); + assert(((this || _global$3$2).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$3$1).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$3$2); }; BN.prototype.uor = function uor(num) { - if ((this || _global$3$1).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$3$2); }; // And `num` with `this` in-place @@ -44127,34 +78703,34 @@ function dew$a$1() { // b = min-length(num, this) var b; - if ((this || _global$3$1).length > num.length) { + if ((this || _global$3$2).length > num.length) { b = num; } else { - b = this || _global$3$1; + b = this || _global$3$2; } for (var i = 0; i < b.length; i++) { - (this || _global$3$1).words[i] = (this || _global$3$1).words[i] & num.words[i]; + (this || _global$3$2).words[i] = (this || _global$3$2).words[i] & num.words[i]; } - (this || _global$3$1).length = b.length; + (this || _global$3$2).length = b.length; return this.strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$3$1).negative | num.negative) === 0); + assert(((this || _global$3$2).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$3$1).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$3$2); }; BN.prototype.uand = function uand(num) { - if ((this || _global$3$1).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$3$2); }; // Xor `num` with `this` in-place @@ -44163,42 +78739,42 @@ function dew$a$1() { var a; var b; - if ((this || _global$3$1).length > num.length) { - a = this || _global$3$1; + if ((this || _global$3$2).length > num.length) { + a = this || _global$3$2; b = num; } else { a = num; - b = this || _global$3$1; + b = this || _global$3$2; } for (var i = 0; i < b.length; i++) { - (this || _global$3$1).words[i] = a.words[i] ^ b.words[i]; + (this || _global$3$2).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$3$1) !== a) { + if ((this || _global$3$2) !== a) { for (; i < a.length; i++) { - (this || _global$3$1).words[i] = a.words[i]; + (this || _global$3$2).words[i] = a.words[i]; } } - (this || _global$3$1).length = a.length; + (this || _global$3$2).length = a.length; return this.strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$3$1).negative | num.negative) === 0); + assert(((this || _global$3$2).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$3$1).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$3$2); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$3$1).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$3$2); }; // Not ``this`` with ``width`` bitwidth @@ -44215,12 +78791,12 @@ function dew$a$1() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$3$1).words[i] = ~(this || _global$3$1).words[i] & 67108863; + (this || _global$3$2).words[i] = ~(this || _global$3$2).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$3$1).words[i] = ~(this || _global$3$1).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$3$2).words[i] = ~(this || _global$3$2).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -44240,9 +78816,9 @@ function dew$a$1() { this._expand(off + 1); if (val) { - (this || _global$3$1).words[off] = (this || _global$3$1).words[off] | 1 << wbit; + (this || _global$3$2).words[off] = (this || _global$3$2).words[off] | 1 << wbit; } else { - (this || _global$3$1).words[off] = (this || _global$3$1).words[off] & ~(1 << wbit); + (this || _global$3$2).words[off] = (this || _global$3$2).words[off] & ~(1 << wbit); } return this.strip(); @@ -44252,12 +78828,12 @@ function dew$a$1() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$3$1).negative !== 0 && num.negative === 0) { - (this || _global$3$1).negative = 0; + if ((this || _global$3$2).negative !== 0 && num.negative === 0) { + (this || _global$3$2).negative = 0; r = this.isub(num); - (this || _global$3$1).negative ^= 1; + (this || _global$3$2).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$3$1).negative === 0 && num.negative !== 0) { + } else if ((this || _global$3$2).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -44267,60 +78843,60 @@ function dew$a$1() { var a, b; - if ((this || _global$3$1).length > num.length) { - a = this || _global$3$1; + if ((this || _global$3$2).length > num.length) { + a = this || _global$3$2; b = num; } else { a = num; - b = this || _global$3$1; + b = this || _global$3$2; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$3$1).words[i] = r & 67108863; + (this || _global$3$2).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$3$1).words[i] = r & 67108863; + (this || _global$3$2).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$3$1).length = a.length; + (this || _global$3$2).length = a.length; if (carry !== 0) { - (this || _global$3$1).words[(this || _global$3$1).length] = carry; - (this || _global$3$1).length++; // Copy the rest of the words - } else if (a !== (this || _global$3$1)) { + (this || _global$3$2).words[(this || _global$3$2).length] = carry; + (this || _global$3$2).length++; // Copy the rest of the words + } else if (a !== (this || _global$3$2)) { for (; i < a.length; i++) { - (this || _global$3$1).words[i] = a.words[i]; + (this || _global$3$2).words[i] = a.words[i]; } } - return this || _global$3$1; + return this || _global$3$2; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$3$1).negative === 0) { + if (num.negative !== 0 && (this || _global$3$2).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$3$1).negative !== 0) { - (this || _global$3$1).negative = 0; - res = num.sub(this || _global$3$1); - (this || _global$3$1).negative = 1; + } else if (num.negative === 0 && (this || _global$3$2).negative !== 0) { + (this || _global$3$2).negative = 0; + res = num.sub(this || _global$3$2); + (this || _global$3$2).negative = 1; return res; } - if ((this || _global$3$1).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$3$1); + if ((this || _global$3$2).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$3$2); }; // Subtract `num` from `this` in-place @@ -44331,10 +78907,10 @@ function dew$a$1() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$3$1).negative !== 0) { - (this || _global$3$1).negative = 0; + } else if ((this || _global$3$2).negative !== 0) { + (this || _global$3$2).negative = 0; this.iadd(num); - (this || _global$3$1).negative = 1; + (this || _global$3$2).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -44342,21 +78918,21 @@ function dew$a$1() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$3$1).negative = 0; - (this || _global$3$1).length = 1; - (this || _global$3$1).words[0] = 0; - return this || _global$3$1; + (this || _global$3$2).negative = 0; + (this || _global$3$2).length = 1; + (this || _global$3$2).words[0] = 0; + return this || _global$3$2; } // a > b var a, b; if (cmp > 0) { - a = this || _global$3$1; + a = this || _global$3$2; b = num; } else { a = num; - b = this || _global$3$1; + b = this || _global$3$2; } var carry = 0; @@ -44364,26 +78940,26 @@ function dew$a$1() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$3$1).words[i] = r & 67108863; + (this || _global$3$2).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$3$1).words[i] = r & 67108863; + (this || _global$3$2).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$3$1)) { + if (carry === 0 && i < a.length && a !== (this || _global$3$2)) { for (; i < a.length; i++) { - (this || _global$3$1).words[i] = a.words[i]; + (this || _global$3$2).words[i] = a.words[i]; } } - (this || _global$3$1).length = Math.max((this || _global$3$1).length, i); + (this || _global$3$2).length = Math.max((this || _global$3$2).length, i); - if (a !== (this || _global$3$1)) { - (this || _global$3$1).negative = 1; + if (a !== (this || _global$3$2)) { + (this || _global$3$2).negative = 1; } return this.strip(); @@ -45086,16 +79662,16 @@ function dew$a$1() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$3$1).length + num.length; + var len = (this || _global$3$2).length + num.length; - if ((this || _global$3$1).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$3$1, num, out); + if ((this || _global$3$2).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$3$2, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$3$1, num, out); + res = smallMulTo(this || _global$3$2, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$3$1, num, out); + res = bigMulTo(this || _global$3$2, num, out); } else { - res = jumboMulTo(this || _global$3$1, num, out); + res = jumboMulTo(this || _global$3$2, num, out); } return res; @@ -45104,8 +79680,8 @@ function dew$a$1() { function FFTM(x, y) { - (this || _global$3$1).x = x; - (this || _global$3$1).y = y; + (this || _global$3$2).x = x; + (this || _global$3$2).y = y; } FFTM.prototype.makeRBT = function makeRBT(N) { @@ -45286,20 +79862,20 @@ function dew$a$1() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$3$1).length + num.length); + out.words = new Array((this || _global$3$2).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$3$1).length + num.length); - return jumboMulTo(this || _global$3$1, num, out); + out.words = new Array((this || _global$3$2).length + num.length); + return jumboMulTo(this || _global$3$2, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$3$1); + return this.clone().mulTo(num, this || _global$3$2); }; BN.prototype.imuln = function imuln(num) { @@ -45308,22 +79884,22 @@ function dew$a$1() { var carry = 0; - for (var i = 0; i < (this || _global$3$1).length; i++) { - var w = ((this || _global$3$1).words[i] | 0) * num; + for (var i = 0; i < (this || _global$3$2).length; i++) { + var w = ((this || _global$3$2).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$3$1).words[i] = lo & 67108863; + (this || _global$3$2).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$3$1).words[i] = carry; - (this || _global$3$1).length++; + (this || _global$3$2).words[i] = carry; + (this || _global$3$2).length++; } - return this || _global$3$1; + return this || _global$3$2; }; BN.prototype.muln = function muln(num) { @@ -45332,7 +79908,7 @@ function dew$a$1() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$3$1); + return this.mul(this || _global$3$2); }; // `this` * `this` in-place @@ -45345,7 +79921,7 @@ function dew$a$1() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$3$1; + var res = this || _global$3$2; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -45372,29 +79948,29 @@ function dew$a$1() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$3$1).length; i++) { - var newCarry = (this || _global$3$1).words[i] & carryMask; - var c = ((this || _global$3$1).words[i] | 0) - newCarry << r; - (this || _global$3$1).words[i] = c | carry; + for (i = 0; i < (this || _global$3$2).length; i++) { + var newCarry = (this || _global$3$2).words[i] & carryMask; + var c = ((this || _global$3$2).words[i] | 0) - newCarry << r; + (this || _global$3$2).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$3$1).words[i] = carry; - (this || _global$3$1).length++; + (this || _global$3$2).words[i] = carry; + (this || _global$3$2).length++; } } if (s !== 0) { - for (i = (this || _global$3$1).length - 1; i >= 0; i--) { - (this || _global$3$1).words[i + s] = (this || _global$3$1).words[i]; + for (i = (this || _global$3$2).length - 1; i >= 0; i--) { + (this || _global$3$2).words[i + s] = (this || _global$3$2).words[i]; } for (i = 0; i < s; i++) { - (this || _global$3$1).words[i] = 0; + (this || _global$3$2).words[i] = 0; } - (this || _global$3$1).length += s; + (this || _global$3$2).length += s; } return this.strip(); @@ -45402,7 +79978,7 @@ function dew$a$1() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$3$1).negative === 0); + assert((this || _global$3$2).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -45420,7 +79996,7 @@ function dew$a$1() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$3$1).length); + var s = Math.min((bits - r) / 26, (this || _global$3$2).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -45428,28 +80004,28 @@ function dew$a$1() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$3$1).words[i]; + maskedWords.words[i] = (this || _global$3$2).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$3$1).length > s) { - (this || _global$3$1).length -= s; + if (s === 0) ; else if ((this || _global$3$2).length > s) { + (this || _global$3$2).length -= s; - for (i = 0; i < (this || _global$3$1).length; i++) { - (this || _global$3$1).words[i] = (this || _global$3$1).words[i + s]; + for (i = 0; i < (this || _global$3$2).length; i++) { + (this || _global$3$2).words[i] = (this || _global$3$2).words[i + s]; } } else { - (this || _global$3$1).words[0] = 0; - (this || _global$3$1).length = 1; + (this || _global$3$2).words[0] = 0; + (this || _global$3$2).length = 1; } var carry = 0; - for (i = (this || _global$3$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$3$1).words[i] | 0; - (this || _global$3$1).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$3$2).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$3$2).words[i] | 0; + (this || _global$3$2).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -45458,9 +80034,9 @@ function dew$a$1() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$3$1).length === 0) { - (this || _global$3$1).words[0] = 0; - (this || _global$3$1).length = 1; + if ((this || _global$3$2).length === 0) { + (this || _global$3$2).words[0] = 0; + (this || _global$3$2).length = 1; } return this.strip(); @@ -45468,7 +80044,7 @@ function dew$a$1() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$3$1).negative === 0); + assert((this || _global$3$2).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -45497,9 +80073,9 @@ function dew$a$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$3$1).length <= s) return false; // Check bit and return + if ((this || _global$3$2).length <= s) return false; // Check bit and return - var w = (this || _global$3$1).words[s]; + var w = (this || _global$3$2).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -45508,21 +80084,21 @@ function dew$a$1() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$3$1).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$3$2).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$3$1).length <= s) { - return this || _global$3$1; + if ((this || _global$3$2).length <= s) { + return this || _global$3$2; } if (r !== 0) { s++; } - (this || _global$3$1).length = Math.min(s, (this || _global$3$1).length); + (this || _global$3$2).length = Math.min(s, (this || _global$3$2).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$3$1).words[(this || _global$3$1).length - 1] &= mask; + (this || _global$3$2).words[(this || _global$3$2).length - 1] &= mask; } return this.strip(); @@ -45539,17 +80115,17 @@ function dew$a$1() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$3$1).negative !== 0) { - if ((this || _global$3$1).length === 1 && ((this || _global$3$1).words[0] | 0) < num) { - (this || _global$3$1).words[0] = num - ((this || _global$3$1).words[0] | 0); - (this || _global$3$1).negative = 0; - return this || _global$3$1; + if ((this || _global$3$2).negative !== 0) { + if ((this || _global$3$2).length === 1 && ((this || _global$3$2).words[0] | 0) < num) { + (this || _global$3$2).words[0] = num - ((this || _global$3$2).words[0] | 0); + (this || _global$3$2).negative = 0; + return this || _global$3$2; } - (this || _global$3$1).negative = 0; + (this || _global$3$2).negative = 0; this.isubn(num); - (this || _global$3$1).negative = 1; - return this || _global$3$1; + (this || _global$3$2).negative = 1; + return this || _global$3$2; } // Add without checks @@ -45557,20 +80133,20 @@ function dew$a$1() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$3$1).words[0] += num; // Carry + (this || _global$3$2).words[0] += num; // Carry - for (var i = 0; i < (this || _global$3$1).length && (this || _global$3$1).words[i] >= 67108864; i++) { - (this || _global$3$1).words[i] -= 67108864; + for (var i = 0; i < (this || _global$3$2).length && (this || _global$3$2).words[i] >= 67108864; i++) { + (this || _global$3$2).words[i] -= 67108864; - if (i === (this || _global$3$1).length - 1) { - (this || _global$3$1).words[i + 1] = 1; + if (i === (this || _global$3$2).length - 1) { + (this || _global$3$2).words[i + 1] = 1; } else { - (this || _global$3$1).words[i + 1]++; + (this || _global$3$2).words[i + 1]++; } } - (this || _global$3$1).length = Math.max((this || _global$3$1).length, i + 1); - return this || _global$3$1; + (this || _global$3$2).length = Math.max((this || _global$3$2).length, i + 1); + return this || _global$3$2; }; // Subtract plain number `num` from `this` @@ -45579,23 +80155,23 @@ function dew$a$1() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$3$1).negative !== 0) { - (this || _global$3$1).negative = 0; + if ((this || _global$3$2).negative !== 0) { + (this || _global$3$2).negative = 0; this.iaddn(num); - (this || _global$3$1).negative = 1; - return this || _global$3$1; + (this || _global$3$2).negative = 1; + return this || _global$3$2; } - (this || _global$3$1).words[0] -= num; + (this || _global$3$2).words[0] -= num; - if ((this || _global$3$1).length === 1 && (this || _global$3$1).words[0] < 0) { - (this || _global$3$1).words[0] = -(this || _global$3$1).words[0]; - (this || _global$3$1).negative = 1; + if ((this || _global$3$2).length === 1 && (this || _global$3$2).words[0] < 0) { + (this || _global$3$2).words[0] = -(this || _global$3$2).words[0]; + (this || _global$3$2).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$3$1).length && (this || _global$3$1).words[i] < 0; i++) { - (this || _global$3$1).words[i] += 67108864; - (this || _global$3$1).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$3$2).length && (this || _global$3$2).words[i] < 0; i++) { + (this || _global$3$2).words[i] += 67108864; + (this || _global$3$2).words[i + 1] -= 1; } } @@ -45611,8 +80187,8 @@ function dew$a$1() { }; BN.prototype.iabs = function iabs() { - (this || _global$3$1).negative = 0; - return this || _global$3$1; + (this || _global$3$2).negative = 0; + return this || _global$3$2; }; BN.prototype.abs = function abs() { @@ -45629,17 +80205,17 @@ function dew$a$1() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$3$1).words[i + shift] | 0) + carry; + w = ((this || _global$3$2).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$3$1).words[i + shift] = w & 67108863; + (this || _global$3$2).words[i + shift] = w & 67108863; } - for (; i < (this || _global$3$1).length - shift; i++) { - w = ((this || _global$3$1).words[i + shift] | 0) + carry; + for (; i < (this || _global$3$2).length - shift; i++) { + w = ((this || _global$3$2).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$3$1).words[i + shift] = w & 67108863; + (this || _global$3$2).words[i + shift] = w & 67108863; } if (carry === 0) return this.strip(); // Subtraction overflow @@ -45647,18 +80223,18 @@ function dew$a$1() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$3$1).length; i++) { - w = -((this || _global$3$1).words[i] | 0) + carry; + for (i = 0; i < (this || _global$3$2).length; i++) { + w = -((this || _global$3$2).words[i] | 0) + carry; carry = w >> 26; - (this || _global$3$1).words[i] = w & 67108863; + (this || _global$3$2).words[i] = w & 67108863; } - (this || _global$3$1).negative = 1; + (this || _global$3$2).negative = 1; return this.strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$3$1).length - num.length; + var shift = (this || _global$3$2).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -45754,7 +80330,7 @@ function dew$a$1() { var div, mod, res; - if ((this || _global$3$1).negative !== 0 && num.negative === 0) { + if ((this || _global$3$2).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -45775,7 +80351,7 @@ function dew$a$1() { }; } - if ((this || _global$3$1).negative === 0 && num.negative !== 0) { + if ((this || _global$3$2).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -45788,7 +80364,7 @@ function dew$a$1() { }; } - if (((this || _global$3$1).negative & num.negative) !== 0) { + if (((this || _global$3$2).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -45807,10 +80383,10 @@ function dew$a$1() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$3$1).length || this.cmp(num) < 0) { + if (num.length > (this || _global$3$2).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$3$1 + mod: this || _global$3$2 }; } // Very short reduction @@ -45873,8 +80449,8 @@ function dew$a$1() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$3$1).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$3$1).words[i] | 0)) % num; + for (var i = (this || _global$3$2).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$3$2).words[i] | 0)) % num; } return acc; @@ -45885,9 +80461,9 @@ function dew$a$1() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$3$1).length - 1; i >= 0; i--) { - var w = ((this || _global$3$1).words[i] | 0) + carry * 67108864; - (this || _global$3$1).words[i] = w / num | 0; + for (var i = (this || _global$3$2).length - 1; i >= 0; i--) { + var w = ((this || _global$3$2).words[i] | 0) + carry * 67108864; + (this || _global$3$2).words[i] = w / num | 0; carry = w % num; } @@ -45901,7 +80477,7 @@ function dew$a$1() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$3$1; + var x = this || _global$3$2; var y = p.clone(); if (x.negative !== 0) { @@ -45984,7 +80560,7 @@ function dew$a$1() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$3$1; + var a = this || _global$3$2; var b = p.clone(); if (a.negative !== 0) { @@ -46095,16 +80671,16 @@ function dew$a$1() { }; BN.prototype.isEven = function isEven() { - return ((this || _global$3$1).words[0] & 1) === 0; + return ((this || _global$3$2).words[0] & 1) === 0; }; BN.prototype.isOdd = function isOdd() { - return ((this || _global$3$1).words[0] & 1) === 1; + return ((this || _global$3$2).words[0] & 1) === 1; }; // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$3$1).words[0] & num; + return (this || _global$3$2).words[0] & num; }; // Increment at the bit position in-line @@ -46114,44 +80690,44 @@ function dew$a$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$3$1).length <= s) { + if ((this || _global$3$2).length <= s) { this._expand(s + 1); - (this || _global$3$1).words[s] |= q; - return this || _global$3$1; + (this || _global$3$2).words[s] |= q; + return this || _global$3$2; } // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$3$1).length; i++) { - var w = (this || _global$3$1).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$3$2).length; i++) { + var w = (this || _global$3$2).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$3$1).words[i] = w; + (this || _global$3$2).words[i] = w; } if (carry !== 0) { - (this || _global$3$1).words[i] = carry; - (this || _global$3$1).length++; + (this || _global$3$2).words[i] = carry; + (this || _global$3$2).length++; } - return this || _global$3$1; + return this || _global$3$2; }; BN.prototype.isZero = function isZero() { - return (this || _global$3$1).length === 1 && (this || _global$3$1).words[0] === 0; + return (this || _global$3$2).length === 1 && (this || _global$3$2).words[0] === 0; }; BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$3$1).negative !== 0 && !negative) return -1; - if ((this || _global$3$1).negative === 0 && negative) return 1; + if ((this || _global$3$2).negative !== 0 && !negative) return -1; + if ((this || _global$3$2).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$3$1).length > 1) { + if ((this || _global$3$2).length > 1) { res = 1; } else { if (negative) { @@ -46159,11 +80735,11 @@ function dew$a$1() { } assert(num <= 67108863, "Number is too big"); - var w = (this || _global$3$1).words[0] | 0; + var w = (this || _global$3$2).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$3$1).negative !== 0) return -res | 0; + if ((this || _global$3$2).negative !== 0) return -res | 0; return res; }; // Compare two numbers and return: // 1 - if `this` > `num` @@ -46172,22 +80748,22 @@ function dew$a$1() { BN.prototype.cmp = function cmp(num) { - if ((this || _global$3$1).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$3$1).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$3$2).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$3$2).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$3$1).negative !== 0) return -res | 0; + if ((this || _global$3$2).negative !== 0) return -res | 0; return res; }; // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$3$1).length > num.length) return 1; - if ((this || _global$3$1).length < num.length) return -1; + if ((this || _global$3$2).length > num.length) return 1; + if ((this || _global$3$2).length < num.length) return -1; var res = 0; - for (var i = (this || _global$3$1).length - 1; i >= 0; i--) { - var a = (this || _global$3$1).words[i] | 0; + for (var i = (this || _global$3$2).length - 1; i >= 0; i--) { + var a = (this || _global$3$2).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; @@ -46252,115 +80828,115 @@ function dew$a$1() { }; BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$3$1).red, "Already a number in reduction context"); - assert((this || _global$3$1).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$3$1)._forceRed(ctx); + assert(!(this || _global$3$2).red, "Already a number in reduction context"); + assert((this || _global$3$2).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$3$2)._forceRed(ctx); }; BN.prototype.fromRed = function fromRed() { - assert((this || _global$3$1).red, "fromRed works only with numbers in reduction context"); - return (this || _global$3$1).red.convertFrom(this || _global$3$1); + assert((this || _global$3$2).red, "fromRed works only with numbers in reduction context"); + return (this || _global$3$2).red.convertFrom(this || _global$3$2); }; BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$3$1).red = ctx; - return this || _global$3$1; + (this || _global$3$2).red = ctx; + return this || _global$3$2; }; BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$3$1).red, "Already a number in reduction context"); + assert(!(this || _global$3$2).red, "Already a number in reduction context"); return this._forceRed(ctx); }; BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$3$1).red, "redAdd works only with red numbers"); - return (this || _global$3$1).red.add(this || _global$3$1, num); + assert((this || _global$3$2).red, "redAdd works only with red numbers"); + return (this || _global$3$2).red.add(this || _global$3$2, num); }; BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$3$1).red, "redIAdd works only with red numbers"); - return (this || _global$3$1).red.iadd(this || _global$3$1, num); + assert((this || _global$3$2).red, "redIAdd works only with red numbers"); + return (this || _global$3$2).red.iadd(this || _global$3$2, num); }; BN.prototype.redSub = function redSub(num) { - assert((this || _global$3$1).red, "redSub works only with red numbers"); - return (this || _global$3$1).red.sub(this || _global$3$1, num); + assert((this || _global$3$2).red, "redSub works only with red numbers"); + return (this || _global$3$2).red.sub(this || _global$3$2, num); }; BN.prototype.redISub = function redISub(num) { - assert((this || _global$3$1).red, "redISub works only with red numbers"); - return (this || _global$3$1).red.isub(this || _global$3$1, num); + assert((this || _global$3$2).red, "redISub works only with red numbers"); + return (this || _global$3$2).red.isub(this || _global$3$2, num); }; BN.prototype.redShl = function redShl(num) { - assert((this || _global$3$1).red, "redShl works only with red numbers"); - return (this || _global$3$1).red.shl(this || _global$3$1, num); + assert((this || _global$3$2).red, "redShl works only with red numbers"); + return (this || _global$3$2).red.shl(this || _global$3$2, num); }; BN.prototype.redMul = function redMul(num) { - assert((this || _global$3$1).red, "redMul works only with red numbers"); + assert((this || _global$3$2).red, "redMul works only with red numbers"); - (this || _global$3$1).red._verify2(this || _global$3$1, num); + (this || _global$3$2).red._verify2(this || _global$3$2, num); - return (this || _global$3$1).red.mul(this || _global$3$1, num); + return (this || _global$3$2).red.mul(this || _global$3$2, num); }; BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$3$1).red, "redMul works only with red numbers"); + assert((this || _global$3$2).red, "redMul works only with red numbers"); - (this || _global$3$1).red._verify2(this || _global$3$1, num); + (this || _global$3$2).red._verify2(this || _global$3$2, num); - return (this || _global$3$1).red.imul(this || _global$3$1, num); + return (this || _global$3$2).red.imul(this || _global$3$2, num); }; BN.prototype.redSqr = function redSqr() { - assert((this || _global$3$1).red, "redSqr works only with red numbers"); + assert((this || _global$3$2).red, "redSqr works only with red numbers"); - (this || _global$3$1).red._verify1(this || _global$3$1); + (this || _global$3$2).red._verify1(this || _global$3$2); - return (this || _global$3$1).red.sqr(this || _global$3$1); + return (this || _global$3$2).red.sqr(this || _global$3$2); }; BN.prototype.redISqr = function redISqr() { - assert((this || _global$3$1).red, "redISqr works only with red numbers"); + assert((this || _global$3$2).red, "redISqr works only with red numbers"); - (this || _global$3$1).red._verify1(this || _global$3$1); + (this || _global$3$2).red._verify1(this || _global$3$2); - return (this || _global$3$1).red.isqr(this || _global$3$1); + return (this || _global$3$2).red.isqr(this || _global$3$2); }; // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$3$1).red, "redSqrt works only with red numbers"); + assert((this || _global$3$2).red, "redSqrt works only with red numbers"); - (this || _global$3$1).red._verify1(this || _global$3$1); + (this || _global$3$2).red._verify1(this || _global$3$2); - return (this || _global$3$1).red.sqrt(this || _global$3$1); + return (this || _global$3$2).red.sqrt(this || _global$3$2); }; BN.prototype.redInvm = function redInvm() { - assert((this || _global$3$1).red, "redInvm works only with red numbers"); + assert((this || _global$3$2).red, "redInvm works only with red numbers"); - (this || _global$3$1).red._verify1(this || _global$3$1); + (this || _global$3$2).red._verify1(this || _global$3$2); - return (this || _global$3$1).red.invm(this || _global$3$1); + return (this || _global$3$2).red.invm(this || _global$3$2); }; // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$3$1).red, "redNeg works only with red numbers"); + assert((this || _global$3$2).red, "redNeg works only with red numbers"); - (this || _global$3$1).red._verify1(this || _global$3$1); + (this || _global$3$2).red._verify1(this || _global$3$2); - return (this || _global$3$1).red.neg(this || _global$3$1); + return (this || _global$3$2).red.neg(this || _global$3$2); }; BN.prototype.redPow = function redPow(num) { - assert((this || _global$3$1).red && !num.red, "redPow(normalNum)"); + assert((this || _global$3$2).red && !num.red, "redPow(normalNum)"); - (this || _global$3$1).red._verify1(this || _global$3$1); + (this || _global$3$2).red._verify1(this || _global$3$2); - return (this || _global$3$1).red.pow(this || _global$3$1, num); + return (this || _global$3$2).red.pow(this || _global$3$2, num); }; // Prime numbers with efficient reduction @@ -46373,16 +80949,16 @@ function dew$a$1() { function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$3$1).name = name; - (this || _global$3$1).p = new BN(p, 16); - (this || _global$3$1).n = (this || _global$3$1).p.bitLength(); - (this || _global$3$1).k = new BN(1).iushln((this || _global$3$1).n).isub((this || _global$3$1).p); - (this || _global$3$1).tmp = this._tmp(); + (this || _global$3$2).name = name; + (this || _global$3$2).p = new BN(p, 16); + (this || _global$3$2).n = (this || _global$3$2).p.bitLength(); + (this || _global$3$2).k = new BN(1).iushln((this || _global$3$2).n).isub((this || _global$3$2).p); + (this || _global$3$2).tmp = this._tmp(); } MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$3$1).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$3$2).n / 13)); return tmp; }; @@ -46393,19 +80969,19 @@ function dew$a$1() { var rlen; do { - this.split(r, (this || _global$3$1).tmp); + this.split(r, (this || _global$3$2).tmp); r = this.imulK(r); - r = r.iadd((this || _global$3$1).tmp); + r = r.iadd((this || _global$3$2).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$3$1).n); + } while (rlen > (this || _global$3$2).n); - var cmp = rlen < (this || _global$3$1).n ? -1 : r.ucmp((this || _global$3$1).p); + var cmp = rlen < (this || _global$3$2).n ? -1 : r.ucmp((this || _global$3$2).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$3$1).p); + r.isub((this || _global$3$2).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -46420,15 +80996,15 @@ function dew$a$1() { }; MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$3$1).n, 0, out); + input.iushrn((this || _global$3$2).n, 0, out); }; MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$3$1).k); + return num.imul((this || _global$3$2).k); }; function K256() { - MPrime.call(this || _global$3$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$3$2, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } inherits(K256, MPrime); @@ -46498,20 +81074,20 @@ function dew$a$1() { }; function P224() { - MPrime.call(this || _global$3$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$3$2, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } inherits(P224, MPrime); function P192() { - MPrime.call(this || _global$3$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$3$2, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } inherits(P192, MPrime); function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$3$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$3$2, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } inherits(P25519, MPrime); @@ -46564,12 +81140,12 @@ function dew$a$1() { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$3$1).m = prime.p; - (this || _global$3$1).prime = prime; + (this || _global$3$2).m = prime.p; + (this || _global$3$2).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$3$1).m = m; - (this || _global$3$1).prime = null; + (this || _global$3$2).m = m; + (this || _global$3$2).prime = null; } } @@ -46584,8 +81160,8 @@ function dew$a$1() { }; Red.prototype.imod = function imod(a) { - if ((this || _global$3$1).prime) return (this || _global$3$1).prime.ireduce(a)._forceRed(this || _global$3$1); - return a.umod((this || _global$3$1).m)._forceRed(this || _global$3$1); + if ((this || _global$3$2).prime) return (this || _global$3$2).prime.ireduce(a)._forceRed(this || _global$3$2); + return a.umod((this || _global$3$2).m)._forceRed(this || _global$3$2); }; Red.prototype.neg = function neg(a) { @@ -46593,7 +81169,7 @@ function dew$a$1() { return a.clone(); } - return (this || _global$3$1).m.sub(a)._forceRed(this || _global$3$1); + return (this || _global$3$2).m.sub(a)._forceRed(this || _global$3$2); }; Red.prototype.add = function add(a, b) { @@ -46601,11 +81177,11 @@ function dew$a$1() { var res = a.add(b); - if (res.cmp((this || _global$3$1).m) >= 0) { - res.isub((this || _global$3$1).m); + if (res.cmp((this || _global$3$2).m) >= 0) { + res.isub((this || _global$3$2).m); } - return res._forceRed(this || _global$3$1); + return res._forceRed(this || _global$3$2); }; Red.prototype.iadd = function iadd(a, b) { @@ -46613,8 +81189,8 @@ function dew$a$1() { var res = a.iadd(b); - if (res.cmp((this || _global$3$1).m) >= 0) { - res.isub((this || _global$3$1).m); + if (res.cmp((this || _global$3$2).m) >= 0) { + res.isub((this || _global$3$2).m); } return res; @@ -46626,10 +81202,10 @@ function dew$a$1() { var res = a.sub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$3$1).m); + res.iadd((this || _global$3$2).m); } - return res._forceRed(this || _global$3$1); + return res._forceRed(this || _global$3$2); }; Red.prototype.isub = function isub(a, b) { @@ -46638,7 +81214,7 @@ function dew$a$1() { var res = a.isub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$3$1).m); + res.iadd((this || _global$3$2).m); } return res; @@ -46673,12 +81249,12 @@ function dew$a$1() { Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$3$1).m.andln(3); + var mod3 = (this || _global$3$2).m.andln(3); assert(mod3 % 2 === 1); // Fast case if (mod3 === 3) { - var pow = (this || _global$3$1).m.add(new BN(1)).iushrn(2); + var pow = (this || _global$3$2).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); } // Tonelli-Shanks algorithm (Totally unoptimized and slow) @@ -46686,7 +81262,7 @@ function dew$a$1() { // Find Q and S, that Q * 2 ^ S = (P - 1) - var q = (this || _global$3$1).m.subn(1); + var q = (this || _global$3$2).m.subn(1); var s = 0; @@ -46696,15 +81272,15 @@ function dew$a$1() { } assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$3$1); + var one = new BN(1).toRed(this || _global$3$2); var nOne = one.redNeg(); // Find quadratic non-residue // NOTE: Max is such because of generalized Riemann hypothesis. - var lpow = (this || _global$3$1).m.subn(1).iushrn(1); + var lpow = (this || _global$3$2).m.subn(1).iushrn(1); - var z = (this || _global$3$1).m.bitLength(); + var z = (this || _global$3$2).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$3$1); + z = new BN(2 * z * z).toRed(this || _global$3$2); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); @@ -46734,7 +81310,7 @@ function dew$a$1() { }; Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$3$1).m); + var inv = a._invmp((this || _global$3$2).m); if (inv.negative !== 0) { inv.negative = 0; @@ -46745,11 +81321,11 @@ function dew$a$1() { }; Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$3$1); + if (num.isZero()) return new BN(1).toRed(this || _global$3$2); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$3$1); + wnd[0] = new BN(1).toRed(this || _global$3$2); wnd[1] = a; for (var i = 2; i < wnd.length; i++) { @@ -46796,7 +81372,7 @@ function dew$a$1() { }; Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$3$1).m); + var r = num.umod((this || _global$3$2).m); return r === num ? r.clone() : r; }; @@ -46814,29 +81390,29 @@ function dew$a$1() { }; function Mont(m) { - Red.call(this || _global$3$1, m); - (this || _global$3$1).shift = (this || _global$3$1).m.bitLength(); + Red.call(this || _global$3$2, m); + (this || _global$3$2).shift = (this || _global$3$2).m.bitLength(); - if ((this || _global$3$1).shift % 26 !== 0) { - (this || _global$3$1).shift += 26 - (this || _global$3$1).shift % 26; + if ((this || _global$3$2).shift % 26 !== 0) { + (this || _global$3$2).shift += 26 - (this || _global$3$2).shift % 26; } - (this || _global$3$1).r = new BN(1).iushln((this || _global$3$1).shift); - (this || _global$3$1).r2 = this.imod((this || _global$3$1).r.sqr()); - (this || _global$3$1).rinv = (this || _global$3$1).r._invmp((this || _global$3$1).m); - (this || _global$3$1).minv = (this || _global$3$1).rinv.mul((this || _global$3$1).r).isubn(1).div((this || _global$3$1).m); - (this || _global$3$1).minv = (this || _global$3$1).minv.umod((this || _global$3$1).r); - (this || _global$3$1).minv = (this || _global$3$1).r.sub((this || _global$3$1).minv); + (this || _global$3$2).r = new BN(1).iushln((this || _global$3$2).shift); + (this || _global$3$2).r2 = this.imod((this || _global$3$2).r.sqr()); + (this || _global$3$2).rinv = (this || _global$3$2).r._invmp((this || _global$3$2).m); + (this || _global$3$2).minv = (this || _global$3$2).rinv.mul((this || _global$3$2).r).isubn(1).div((this || _global$3$2).m); + (this || _global$3$2).minv = (this || _global$3$2).minv.umod((this || _global$3$2).r); + (this || _global$3$2).minv = (this || _global$3$2).r.sub((this || _global$3$2).minv); } inherits(Mont, Red); Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$3$1).shift)); + return this.imod(num.ushln((this || _global$3$2).shift)); }; Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$3$1).rinv)); + var r = this.imod(num.mul((this || _global$3$2).rinv)); r.red = null; return r; }; @@ -46849,60 +81425,60 @@ function dew$a$1() { } var t = a.imul(b); - var c = t.maskn((this || _global$3$1).shift).mul((this || _global$3$1).minv).imaskn((this || _global$3$1).shift).mul((this || _global$3$1).m); - var u = t.isub(c).iushrn((this || _global$3$1).shift); + var c = t.maskn((this || _global$3$2).shift).mul((this || _global$3$2).minv).imaskn((this || _global$3$2).shift).mul((this || _global$3$2).m); + var u = t.isub(c).iushrn((this || _global$3$2).shift); var res = u; - if (u.cmp((this || _global$3$1).m) >= 0) { - res = u.isub((this || _global$3$1).m); + if (u.cmp((this || _global$3$2).m) >= 0) { + res = u.isub((this || _global$3$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$3$1).m); + res = u.iadd((this || _global$3$2).m); } - return res._forceRed(this || _global$3$1); + return res._forceRed(this || _global$3$2); }; Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$3$1); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$3$2); var t = a.mul(b); - var c = t.maskn((this || _global$3$1).shift).mul((this || _global$3$1).minv).imaskn((this || _global$3$1).shift).mul((this || _global$3$1).m); - var u = t.isub(c).iushrn((this || _global$3$1).shift); + var c = t.maskn((this || _global$3$2).shift).mul((this || _global$3$2).minv).imaskn((this || _global$3$2).shift).mul((this || _global$3$2).m); + var u = t.isub(c).iushrn((this || _global$3$2).shift); var res = u; - if (u.cmp((this || _global$3$1).m) >= 0) { - res = u.isub((this || _global$3$1).m); + if (u.cmp((this || _global$3$2).m) >= 0) { + res = u.isub((this || _global$3$2).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$3$1).m); + res = u.iadd((this || _global$3$2).m); } - return res._forceRed(this || _global$3$1); + return res._forceRed(this || _global$3$2); }; Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$3$1).m).mul((this || _global$3$1).r2)); - return res._forceRed(this || _global$3$1); + var res = this.imod(a._invmp((this || _global$3$2).m).mul((this || _global$3$2).r2)); + return res._forceRed(this || _global$3$2); }; - })(module$1$1, exports$a$1); + })(module$1$2, exports$b$3); - return module$1$1.exports; + return module$1$2.exports; } -var exports$9$1 = {}, - _dewExec$9$1 = false; +var exports$a$3 = {}, + _dewExec$9$3 = false; -var _global$2$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$2$3 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$9$1() { - if (_dewExec$9$1) return exports$9$1; - _dewExec$9$1 = true; - var Buffer = e$1$1$1.Buffer; +function dew$9$3() { + if (_dewExec$9$3) return exports$a$3; + _dewExec$9$3 = true; + var Buffer = buffer.Buffer; - var elliptic = dew$y$1(); + var elliptic = dew$y$2(); - var BN = dew$a$1(); + var BN = dew$a$3(); - exports$9$1 = function createECDH(curve) { + exports$a$3 = function createECDH(curve) { return new ECDH(curve); }; @@ -46943,21 +81519,21 @@ function dew$9$1() { aliases.p521 = aliases.secp521r1; function ECDH(curve) { - (this || _global$2$1).curveType = aliases[curve]; + (this || _global$2$3).curveType = aliases[curve]; - if (!(this || _global$2$1).curveType) { - (this || _global$2$1).curveType = { + if (!(this || _global$2$3).curveType) { + (this || _global$2$3).curveType = { name: curve }; } - (this || _global$2$1).curve = new elliptic.ec((this || _global$2$1).curveType.name); // eslint-disable-line new-cap + (this || _global$2$3).curve = new elliptic.ec((this || _global$2$3).curveType.name); // eslint-disable-line new-cap - (this || _global$2$1).keys = void 0; + (this || _global$2$3).keys = void 0; } ECDH.prototype.generateKeys = function (enc, format) { - (this || _global$2$1).keys = (this || _global$2$1).curve.genKeyPair(); + (this || _global$2$3).keys = (this || _global$2$3).curve.genKeyPair(); return this.getPublicKey(enc, format); }; @@ -46968,14 +81544,14 @@ function dew$9$1() { other = new Buffer(other, inenc); } - var otherPub = (this || _global$2$1).curve.keyFromPublic(other).getPublic(); + var otherPub = (this || _global$2$3).curve.keyFromPublic(other).getPublic(); - var out = otherPub.mul((this || _global$2$1).keys.getPrivate()).getX(); - return formatReturnValue(out, enc, (this || _global$2$1).curveType.byteLength); + var out = otherPub.mul((this || _global$2$3).keys.getPrivate()).getX(); + return formatReturnValue(out, enc, (this || _global$2$3).curveType.byteLength); }; ECDH.prototype.getPublicKey = function (enc, format) { - var key = (this || _global$2$1).keys.getPublic(format === "compressed", true); + var key = (this || _global$2$3).keys.getPublic(format === "compressed", true); if (format === "hybrid") { if (key[key.length - 1] % 2) { @@ -46989,7 +81565,7 @@ function dew$9$1() { }; ECDH.prototype.getPrivateKey = function (enc) { - return formatReturnValue((this || _global$2$1).keys.getPrivate(), enc); + return formatReturnValue((this || _global$2$3).keys.getPrivate(), enc); }; ECDH.prototype.setPublicKey = function (pub, enc) { @@ -46999,9 +81575,9 @@ function dew$9$1() { pub = new Buffer(pub, enc); } - (this || _global$2$1).keys._importPublic(pub); + (this || _global$2$3).keys._importPublic(pub); - return this || _global$2$1; + return this || _global$2$3; }; ECDH.prototype.setPrivateKey = function (priv, enc) { @@ -47014,11 +81590,11 @@ function dew$9$1() { var _priv = new BN(priv); _priv = _priv.toString(16); - (this || _global$2$1).keys = (this || _global$2$1).curve.genKeyPair(); + (this || _global$2$3).keys = (this || _global$2$3).curve.genKeyPair(); - (this || _global$2$1).keys._importPrivate(_priv); + (this || _global$2$3).keys._importPrivate(_priv); - return this || _global$2$1; + return this || _global$2$3; }; function formatReturnValue(bn, enc, len) { @@ -47041,20 +81617,20 @@ function dew$9$1() { } } - return exports$9$1; + return exports$a$3; } -var exports$8$1 = {}, - _dewExec$8$1 = false; -function dew$8$1() { - if (_dewExec$8$1) return exports$8$1; - _dewExec$8$1 = true; +var exports$9$3 = {}, + _dewExec$8$3 = false; +function dew$8$3() { + if (_dewExec$8$3) return exports$9$3; + _dewExec$8$3 = true; - var createHash = dew$1F(); + var createHash = dew$2y(); - var Buffer = dew$1T().Buffer; + var Buffer = dew$2P().Buffer; - exports$8$1 = function (seed, len) { + exports$9$3 = function (seed, len) { var t = Buffer.alloc(0); var i = 0; var c; @@ -47073,16 +81649,16 @@ function dew$8$1() { return out; } - return exports$8$1; + return exports$9$3; } -var exports$7$1 = {}, - _dewExec$7$1 = false; -function dew$7$1() { - if (_dewExec$7$1) return exports$7$1; - _dewExec$7$1 = true; +var exports$8$3 = {}, + _dewExec$7$3 = false; +function dew$7$3() { + if (_dewExec$7$3) return exports$8$3; + _dewExec$7$3 = true; - exports$7$1 = function xor(a, b) { + exports$8$3 = function xor(a, b) { var len = a.length; var i = -1; @@ -47093,20 +81669,20 @@ function dew$7$1() { return a; }; - return exports$7$1; + return exports$8$3; } -var exports$6$1 = {}, - _dewExec$6$1 = false; -var module$8 = { - exports: exports$6$1 +var exports$7$3 = {}, + _dewExec$6$3 = false; +var module$c = { + exports: exports$7$3 }; -var _global$1$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$1$3 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; -function dew$6$1() { - if (_dewExec$6$1) return module$8.exports; - _dewExec$6$1 = true; +function dew$6$3() { + if (_dewExec$6$3) return module$c.exports; + _dewExec$6$3 = true; (function (module, exports) { @@ -47132,11 +81708,11 @@ function dew$6$1() { return number; } - (this || _global$1$1).negative = 0; - (this || _global$1$1).words = null; - (this || _global$1$1).length = 0; // Reduction context + (this || _global$1$3).negative = 0; + (this || _global$1$3).words = null; + (this || _global$1$3).length = 0; // Reduction context - (this || _global$1$1).red = null; + (this || _global$1$3).red = null; if (number !== null) { if (base === "le" || base === "be") { @@ -47162,7 +81738,7 @@ function dew$6$1() { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = e$1$1$1.Buffer; + Buffer = buffer.Buffer; } } catch (e) {} @@ -47203,7 +81779,7 @@ function dew$6$1() { if (number[0] === "-") { start++; - (this || _global$1$1).negative = 1; + (this || _global$1$3).negative = 1; } if (start < number.length) { @@ -47221,21 +81797,21 @@ function dew$6$1() { BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$1$1).negative = 1; + (this || _global$1$3).negative = 1; number = -number; } if (number < 67108864) { - (this || _global$1$1).words = [number & 67108863]; - (this || _global$1$1).length = 1; + (this || _global$1$3).words = [number & 67108863]; + (this || _global$1$3).length = 1; } else if (number < 4503599627370496) { - (this || _global$1$1).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$1$1).length = 2; + (this || _global$1$3).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$1$3).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$1$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$1$1).length = 3; + (this || _global$1$3).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$1$3).length = 3; } if (endian !== "le") return; // Reverse the bytes @@ -47248,16 +81824,16 @@ function dew$6$1() { assert(typeof number.length === "number"); if (number.length <= 0) { - (this || _global$1$1).words = [0]; - (this || _global$1$1).length = 1; - return this || _global$1$1; + (this || _global$1$3).words = [0]; + (this || _global$1$3).length = 1; + return this || _global$1$3; } - (this || _global$1$1).length = Math.ceil(number.length / 3); - (this || _global$1$1).words = new Array((this || _global$1$1).length); + (this || _global$1$3).length = Math.ceil(number.length / 3); + (this || _global$1$3).words = new Array((this || _global$1$3).length); - for (var i = 0; i < (this || _global$1$1).length; i++) { - (this || _global$1$1).words[i] = 0; + for (var i = 0; i < (this || _global$1$3).length; i++) { + (this || _global$1$3).words[i] = 0; } var j, w; @@ -47266,8 +81842,8 @@ function dew$6$1() { if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$1$1).words[j] |= w << off & 67108863; - (this || _global$1$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$1$3).words[j] |= w << off & 67108863; + (this || _global$1$3).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -47278,8 +81854,8 @@ function dew$6$1() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$1$1).words[j] |= w << off & 67108863; - (this || _global$1$1).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$1$3).words[j] |= w << off & 67108863; + (this || _global$1$3).words[j + 1] = w >>> 26 - off & 67108863; off += 24; if (off >= 26) { @@ -47316,11 +81892,11 @@ function dew$6$1() { BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$1$1).length = Math.ceil((number.length - start) / 6); - (this || _global$1$1).words = new Array((this || _global$1$1).length); + (this || _global$1$3).length = Math.ceil((number.length - start) / 6); + (this || _global$1$3).words = new Array((this || _global$1$3).length); - for (var i = 0; i < (this || _global$1$1).length; i++) { - (this || _global$1$1).words[i] = 0; + for (var i = 0; i < (this || _global$1$3).length; i++) { + (this || _global$1$3).words[i] = 0; } // 24-bits chunks @@ -47331,12 +81907,12 @@ function dew$6$1() { if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$1$1).words[j] |= w & 67108863; + (this || _global$1$3).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$1$1).words[j] |= w >>> 26; + (this || _global$1$3).words[j] |= w >>> 26; } else { off += 8; } @@ -47346,12 +81922,12 @@ function dew$6$1() { for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$1$1).words[j] |= w & 67108863; + (this || _global$1$3).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$1$1).words[j] |= w >>> 26; + (this || _global$1$3).words[j] |= w >>> 26; } else { off += 8; } @@ -47383,8 +81959,8 @@ function dew$6$1() { BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$1$1).words = [0]; - (this || _global$1$1).length = 1; // Find length of limb in base + (this || _global$1$3).words = [0]; + (this || _global$1$3).length = 1; // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; @@ -47401,8 +81977,8 @@ function dew$6$1() { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$1$1).words[0] + word < 67108864) { - (this || _global$1$1).words[0] += word; + if ((this || _global$1$3).words[0] + word < 67108864) { + (this || _global$1$3).words[0] += word; } else { this._iaddn(word); } @@ -47418,8 +81994,8 @@ function dew$6$1() { this.imuln(pow); - if ((this || _global$1$1).words[0] + word < 67108864) { - (this || _global$1$1).words[0] += word; + if ((this || _global$1$3).words[0] + word < 67108864) { + (this || _global$1$3).words[0] += word; } else { this._iaddn(word); } @@ -47429,15 +82005,15 @@ function dew$6$1() { }; BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$1$1).length); + dest.words = new Array((this || _global$1$3).length); - for (var i = 0; i < (this || _global$1$1).length; i++) { - dest.words[i] = (this || _global$1$1).words[i]; + for (var i = 0; i < (this || _global$1$3).length; i++) { + dest.words[i] = (this || _global$1$3).words[i]; } - dest.length = (this || _global$1$1).length; - dest.negative = (this || _global$1$1).negative; - dest.red = (this || _global$1$1).red; + dest.length = (this || _global$1$3).length; + dest.negative = (this || _global$1$3).negative; + dest.red = (this || _global$1$3).red; }; BN.prototype.clone = function clone() { @@ -47447,17 +82023,17 @@ function dew$6$1() { }; BN.prototype._expand = function _expand(size) { - while ((this || _global$1$1).length < size) { - (this || _global$1$1).words[(this || _global$1$1).length++] = 0; + while ((this || _global$1$3).length < size) { + (this || _global$1$3).words[(this || _global$1$3).length++] = 0; } - return this || _global$1$1; + return this || _global$1$3; }; // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$1$1).length > 1 && (this || _global$1$1).words[(this || _global$1$1).length - 1] === 0) { - (this || _global$1$1).length--; + while ((this || _global$1$3).length > 1 && (this || _global$1$3).words[(this || _global$1$3).length - 1] === 0) { + (this || _global$1$3).length--; } return this._normSign(); @@ -47465,15 +82041,15 @@ function dew$6$1() { BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$1$1).length === 1 && (this || _global$1$1).words[0] === 0) { - (this || _global$1$1).negative = 0; + if ((this || _global$1$3).length === 1 && (this || _global$1$3).words[0] === 0) { + (this || _global$1$3).negative = 0; } - return this || _global$1$1; + return this || _global$1$3; }; BN.prototype.inspect = function inspect() { - return ((this || _global$1$1).red ? ""; + return ((this || _global$1$3).red ? ""; }; /* var zeros = []; @@ -47517,12 +82093,12 @@ function dew$6$1() { var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$1$1).length; i++) { - var w = (this || _global$1$1).words[i]; + for (var i = 0; i < (this || _global$1$3).length; i++) { + var w = (this || _global$1$3).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$1$1).length - 1) { + if (carry !== 0 || i !== (this || _global$1$3).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; @@ -47544,7 +82120,7 @@ function dew$6$1() { out = "0" + out; } - if ((this || _global$1$1).negative !== 0) { + if ((this || _global$1$3).negative !== 0) { out = "-" + out; } @@ -47579,7 +82155,7 @@ function dew$6$1() { out = "0" + out; } - if ((this || _global$1$1).negative !== 0) { + if ((this || _global$1$3).negative !== 0) { out = "-" + out; } @@ -47590,18 +82166,18 @@ function dew$6$1() { }; BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$1$1).words[0]; + var ret = (this || _global$1$3).words[0]; - if ((this || _global$1$1).length === 2) { - ret += (this || _global$1$1).words[1] * 67108864; - } else if ((this || _global$1$1).length === 3 && (this || _global$1$1).words[2] === 1) { + if ((this || _global$1$3).length === 2) { + ret += (this || _global$1$3).words[1] * 67108864; + } else if ((this || _global$1$3).length === 3 && (this || _global$1$3).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$1$1).words[1] * 67108864; - } else if ((this || _global$1$1).length > 2) { + ret += 4503599627370496 + (this || _global$1$3).words[1] * 67108864; + } else if ((this || _global$1$3).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$1$1).negative !== 0 ? -ret : ret; + return (this || _global$1$3).negative !== 0 ? -ret : ret; }; BN.prototype.toJSON = function toJSON() { @@ -47722,11 +82298,11 @@ function dew$6$1() { BN.prototype.bitLength = function bitLength() { - var w = (this || _global$1$1).words[(this || _global$1$1).length - 1]; + var w = (this || _global$1$3).words[(this || _global$1$3).length - 1]; var hi = this._countBits(w); - return ((this || _global$1$1).length - 1) * 26 + hi; + return ((this || _global$1$3).length - 1) * 26 + hi; }; function toBitArray(num) { @@ -47746,8 +82322,8 @@ function dew$6$1() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$1$1).length; i++) { - var b = this._zeroBits((this || _global$1$1).words[i]); + for (var i = 0; i < (this || _global$1$3).length; i++) { + var b = this._zeroBits((this || _global$1$3).words[i]); r += b; if (b !== 26) break; @@ -47761,7 +82337,7 @@ function dew$6$1() { }; BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$1$1).negative !== 0) { + if ((this || _global$1$3).negative !== 0) { return this.abs().inotn(width).iaddn(1); } @@ -47777,7 +82353,7 @@ function dew$6$1() { }; BN.prototype.isNeg = function isNeg() { - return (this || _global$1$1).negative !== 0; + return (this || _global$1$3).negative !== 0; }; // Return negative clone of `this` @@ -47787,39 +82363,39 @@ function dew$6$1() { BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$1$1).negative ^= 1; + (this || _global$1$3).negative ^= 1; } - return this || _global$1$1; + return this || _global$1$3; }; // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$1$1).length < num.length) { - (this || _global$1$1).words[(this || _global$1$1).length++] = 0; + while ((this || _global$1$3).length < num.length) { + (this || _global$1$3).words[(this || _global$1$3).length++] = 0; } for (var i = 0; i < num.length; i++) { - (this || _global$1$1).words[i] = (this || _global$1$1).words[i] | num.words[i]; + (this || _global$1$3).words[i] = (this || _global$1$3).words[i] | num.words[i]; } return this.strip(); }; BN.prototype.ior = function ior(num) { - assert(((this || _global$1$1).negative | num.negative) === 0); + assert(((this || _global$1$3).negative | num.negative) === 0); return this.iuor(num); }; // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$1$1).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$1$3); }; BN.prototype.uor = function uor(num) { - if ((this || _global$1$1).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$1$3); }; // And `num` with `this` in-place @@ -47827,34 +82403,34 @@ function dew$6$1() { // b = min-length(num, this) var b; - if ((this || _global$1$1).length > num.length) { + if ((this || _global$1$3).length > num.length) { b = num; } else { - b = this || _global$1$1; + b = this || _global$1$3; } for (var i = 0; i < b.length; i++) { - (this || _global$1$1).words[i] = (this || _global$1$1).words[i] & num.words[i]; + (this || _global$1$3).words[i] = (this || _global$1$3).words[i] & num.words[i]; } - (this || _global$1$1).length = b.length; + (this || _global$1$3).length = b.length; return this.strip(); }; BN.prototype.iand = function iand(num) { - assert(((this || _global$1$1).negative | num.negative) === 0); + assert(((this || _global$1$3).negative | num.negative) === 0); return this.iuand(num); }; // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$1$1).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$1$3); }; BN.prototype.uand = function uand(num) { - if ((this || _global$1$1).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$1$3); }; // Xor `num` with `this` in-place @@ -47863,42 +82439,42 @@ function dew$6$1() { var a; var b; - if ((this || _global$1$1).length > num.length) { - a = this || _global$1$1; + if ((this || _global$1$3).length > num.length) { + a = this || _global$1$3; b = num; } else { a = num; - b = this || _global$1$1; + b = this || _global$1$3; } for (var i = 0; i < b.length; i++) { - (this || _global$1$1).words[i] = a.words[i] ^ b.words[i]; + (this || _global$1$3).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$1$1) !== a) { + if ((this || _global$1$3) !== a) { for (; i < a.length; i++) { - (this || _global$1$1).words[i] = a.words[i]; + (this || _global$1$3).words[i] = a.words[i]; } } - (this || _global$1$1).length = a.length; + (this || _global$1$3).length = a.length; return this.strip(); }; BN.prototype.ixor = function ixor(num) { - assert(((this || _global$1$1).negative | num.negative) === 0); + assert(((this || _global$1$3).negative | num.negative) === 0); return this.iuxor(num); }; // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$1$1).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$1$3); }; BN.prototype.uxor = function uxor(num) { - if ((this || _global$1$1).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$1$3); }; // Not ``this`` with ``width`` bitwidth @@ -47915,12 +82491,12 @@ function dew$6$1() { for (var i = 0; i < bytesNeeded; i++) { - (this || _global$1$1).words[i] = ~(this || _global$1$1).words[i] & 67108863; + (this || _global$1$3).words[i] = ~(this || _global$1$3).words[i] & 67108863; } // Handle the residue if (bitsLeft > 0) { - (this || _global$1$1).words[i] = ~(this || _global$1$1).words[i] & 67108863 >> 26 - bitsLeft; + (this || _global$1$3).words[i] = ~(this || _global$1$3).words[i] & 67108863 >> 26 - bitsLeft; } // And remove leading zeroes @@ -47940,9 +82516,9 @@ function dew$6$1() { this._expand(off + 1); if (val) { - (this || _global$1$1).words[off] = (this || _global$1$1).words[off] | 1 << wbit; + (this || _global$1$3).words[off] = (this || _global$1$3).words[off] | 1 << wbit; } else { - (this || _global$1$1).words[off] = (this || _global$1$1).words[off] & ~(1 << wbit); + (this || _global$1$3).words[off] = (this || _global$1$3).words[off] & ~(1 << wbit); } return this.strip(); @@ -47952,12 +82528,12 @@ function dew$6$1() { BN.prototype.iadd = function iadd(num) { var r; // negative + positive - if ((this || _global$1$1).negative !== 0 && num.negative === 0) { - (this || _global$1$1).negative = 0; + if ((this || _global$1$3).negative !== 0 && num.negative === 0) { + (this || _global$1$3).negative = 0; r = this.isub(num); - (this || _global$1$1).negative ^= 1; + (this || _global$1$3).negative ^= 1; return this._normSign(); // positive + negative - } else if ((this || _global$1$1).negative === 0 && num.negative !== 0) { + } else if ((this || _global$1$3).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; @@ -47967,60 +82543,60 @@ function dew$6$1() { var a, b; - if ((this || _global$1$1).length > num.length) { - a = this || _global$1$1; + if ((this || _global$1$3).length > num.length) { + a = this || _global$1$3; b = num; } else { a = num; - b = this || _global$1$1; + b = this || _global$1$3; } var carry = 0; for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$1$1).words[i] = r & 67108863; + (this || _global$1$3).words[i] = r & 67108863; carry = r >>> 26; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$1$1).words[i] = r & 67108863; + (this || _global$1$3).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$1$1).length = a.length; + (this || _global$1$3).length = a.length; if (carry !== 0) { - (this || _global$1$1).words[(this || _global$1$1).length] = carry; - (this || _global$1$1).length++; // Copy the rest of the words - } else if (a !== (this || _global$1$1)) { + (this || _global$1$3).words[(this || _global$1$3).length] = carry; + (this || _global$1$3).length++; // Copy the rest of the words + } else if (a !== (this || _global$1$3)) { for (; i < a.length; i++) { - (this || _global$1$1).words[i] = a.words[i]; + (this || _global$1$3).words[i] = a.words[i]; } } - return this || _global$1$1; + return this || _global$1$3; }; // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$1$1).negative === 0) { + if (num.negative !== 0 && (this || _global$1$3).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$1$1).negative !== 0) { - (this || _global$1$1).negative = 0; - res = num.sub(this || _global$1$1); - (this || _global$1$1).negative = 1; + } else if (num.negative === 0 && (this || _global$1$3).negative !== 0) { + (this || _global$1$3).negative = 0; + res = num.sub(this || _global$1$3); + (this || _global$1$3).negative = 1; return res; } - if ((this || _global$1$1).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$1$1); + if ((this || _global$1$3).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$1$3); }; // Subtract `num` from `this` in-place @@ -48031,10 +82607,10 @@ function dew$6$1() { var r = this.iadd(num); num.negative = 1; return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$1$1).negative !== 0) { - (this || _global$1$1).negative = 0; + } else if ((this || _global$1$3).negative !== 0) { + (this || _global$1$3).negative = 0; this.iadd(num); - (this || _global$1$1).negative = 1; + (this || _global$1$3).negative = 1; return this._normSign(); } // At this point both numbers are positive @@ -48042,21 +82618,21 @@ function dew$6$1() { var cmp = this.cmp(num); // Optimization - zeroify if (cmp === 0) { - (this || _global$1$1).negative = 0; - (this || _global$1$1).length = 1; - (this || _global$1$1).words[0] = 0; - return this || _global$1$1; + (this || _global$1$3).negative = 0; + (this || _global$1$3).length = 1; + (this || _global$1$3).words[0] = 0; + return this || _global$1$3; } // a > b var a, b; if (cmp > 0) { - a = this || _global$1$1; + a = this || _global$1$3; b = num; } else { a = num; - b = this || _global$1$1; + b = this || _global$1$3; } var carry = 0; @@ -48064,26 +82640,26 @@ function dew$6$1() { for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$1$1).words[i] = r & 67108863; + (this || _global$1$3).words[i] = r & 67108863; } for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$1$1).words[i] = r & 67108863; + (this || _global$1$3).words[i] = r & 67108863; } // Copy rest of the words - if (carry === 0 && i < a.length && a !== (this || _global$1$1)) { + if (carry === 0 && i < a.length && a !== (this || _global$1$3)) { for (; i < a.length; i++) { - (this || _global$1$1).words[i] = a.words[i]; + (this || _global$1$3).words[i] = a.words[i]; } } - (this || _global$1$1).length = Math.max((this || _global$1$1).length, i); + (this || _global$1$3).length = Math.max((this || _global$1$3).length, i); - if (a !== (this || _global$1$1)) { - (this || _global$1$1).negative = 1; + if (a !== (this || _global$1$3)) { + (this || _global$1$3).negative = 1; } return this.strip(); @@ -48786,16 +83362,16 @@ function dew$6$1() { BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$1$1).length + num.length; + var len = (this || _global$1$3).length + num.length; - if ((this || _global$1$1).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$1$1, num, out); + if ((this || _global$1$3).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$1$3, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$1$1, num, out); + res = smallMulTo(this || _global$1$3, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$1$1, num, out); + res = bigMulTo(this || _global$1$3, num, out); } else { - res = jumboMulTo(this || _global$1$1, num, out); + res = jumboMulTo(this || _global$1$3, num, out); } return res; @@ -48804,8 +83380,8 @@ function dew$6$1() { function FFTM(x, y) { - (this || _global$1$1).x = x; - (this || _global$1$1).y = y; + (this || _global$1$3).x = x; + (this || _global$1$3).y = y; } FFTM.prototype.makeRBT = function makeRBT(N) { @@ -48986,20 +83562,20 @@ function dew$6$1() { BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$1$1).length + num.length); + out.words = new Array((this || _global$1$3).length + num.length); return this.mulTo(num, out); }; // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$1$1).length + num.length); - return jumboMulTo(this || _global$1$1, num, out); + out.words = new Array((this || _global$1$3).length + num.length); + return jumboMulTo(this || _global$1$3, num, out); }; // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$1$1); + return this.clone().mulTo(num, this || _global$1$3); }; BN.prototype.imuln = function imuln(num) { @@ -49008,22 +83584,22 @@ function dew$6$1() { var carry = 0; - for (var i = 0; i < (this || _global$1$1).length; i++) { - var w = ((this || _global$1$1).words[i] | 0) * num; + for (var i = 0; i < (this || _global$1$3).length; i++) { + var w = ((this || _global$1$3).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$1$1).words[i] = lo & 67108863; + (this || _global$1$3).words[i] = lo & 67108863; } if (carry !== 0) { - (this || _global$1$1).words[i] = carry; - (this || _global$1$1).length++; + (this || _global$1$3).words[i] = carry; + (this || _global$1$3).length++; } - return this || _global$1$1; + return this || _global$1$3; }; BN.prototype.muln = function muln(num) { @@ -49032,7 +83608,7 @@ function dew$6$1() { BN.prototype.sqr = function sqr() { - return this.mul(this || _global$1$1); + return this.mul(this || _global$1$3); }; // `this` * `this` in-place @@ -49045,7 +83621,7 @@ function dew$6$1() { var w = toBitArray(num); if (w.length === 0) return new BN(1); // Skip leading zeroes - var res = this || _global$1$1; + var res = this || _global$1$3; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; @@ -49072,29 +83648,29 @@ function dew$6$1() { if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$1$1).length; i++) { - var newCarry = (this || _global$1$1).words[i] & carryMask; - var c = ((this || _global$1$1).words[i] | 0) - newCarry << r; - (this || _global$1$1).words[i] = c | carry; + for (i = 0; i < (this || _global$1$3).length; i++) { + var newCarry = (this || _global$1$3).words[i] & carryMask; + var c = ((this || _global$1$3).words[i] | 0) - newCarry << r; + (this || _global$1$3).words[i] = c | carry; carry = newCarry >>> 26 - r; } if (carry) { - (this || _global$1$1).words[i] = carry; - (this || _global$1$1).length++; + (this || _global$1$3).words[i] = carry; + (this || _global$1$3).length++; } } if (s !== 0) { - for (i = (this || _global$1$1).length - 1; i >= 0; i--) { - (this || _global$1$1).words[i + s] = (this || _global$1$1).words[i]; + for (i = (this || _global$1$3).length - 1; i >= 0; i--) { + (this || _global$1$3).words[i + s] = (this || _global$1$3).words[i]; } for (i = 0; i < s; i++) { - (this || _global$1$1).words[i] = 0; + (this || _global$1$3).words[i] = 0; } - (this || _global$1$1).length += s; + (this || _global$1$3).length += s; } return this.strip(); @@ -49102,7 +83678,7 @@ function dew$6$1() { BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$1$1).negative === 0); + assert((this || _global$1$3).negative === 0); return this.iushln(bits); }; // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes @@ -49120,7 +83696,7 @@ function dew$6$1() { } var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$1$1).length); + var s = Math.min((bits - r) / 26, (this || _global$1$3).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; @@ -49128,28 +83704,28 @@ function dew$6$1() { if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$1$1).words[i]; + maskedWords.words[i] = (this || _global$1$3).words[i]; } maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$1$1).length > s) { - (this || _global$1$1).length -= s; + if (s === 0) ; else if ((this || _global$1$3).length > s) { + (this || _global$1$3).length -= s; - for (i = 0; i < (this || _global$1$1).length; i++) { - (this || _global$1$1).words[i] = (this || _global$1$1).words[i + s]; + for (i = 0; i < (this || _global$1$3).length; i++) { + (this || _global$1$3).words[i] = (this || _global$1$3).words[i + s]; } } else { - (this || _global$1$1).words[0] = 0; - (this || _global$1$1).length = 1; + (this || _global$1$3).words[0] = 0; + (this || _global$1$3).length = 1; } var carry = 0; - for (i = (this || _global$1$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$1$1).words[i] | 0; - (this || _global$1$1).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$1$3).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$1$3).words[i] | 0; + (this || _global$1$3).words[i] = carry << 26 - r | word >>> r; carry = word & mask; } // Push carried bits as a mask @@ -49158,9 +83734,9 @@ function dew$6$1() { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$1$1).length === 0) { - (this || _global$1$1).words[0] = 0; - (this || _global$1$1).length = 1; + if ((this || _global$1$3).length === 0) { + (this || _global$1$3).words[0] = 0; + (this || _global$1$3).length = 1; } return this.strip(); @@ -49168,7 +83744,7 @@ function dew$6$1() { BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$1$1).negative === 0); + assert((this || _global$1$3).negative === 0); return this.iushrn(bits, hint, extended); }; // Shift-left @@ -49197,9 +83773,9 @@ function dew$6$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$1$1).length <= s) return false; // Check bit and return + if ((this || _global$1$3).length <= s) return false; // Check bit and return - var w = (this || _global$1$1).words[s]; + var w = (this || _global$1$3).words[s]; return !!(w & q); }; // Return only lowers bits of number (in-place) @@ -49208,21 +83784,21 @@ function dew$6$1() { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$1$1).negative === 0, "imaskn works only with positive numbers"); + assert((this || _global$1$3).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$1$1).length <= s) { - return this || _global$1$1; + if ((this || _global$1$3).length <= s) { + return this || _global$1$3; } if (r !== 0) { s++; } - (this || _global$1$1).length = Math.min(s, (this || _global$1$1).length); + (this || _global$1$3).length = Math.min(s, (this || _global$1$3).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$1$1).words[(this || _global$1$1).length - 1] &= mask; + (this || _global$1$3).words[(this || _global$1$3).length - 1] &= mask; } return this.strip(); @@ -49239,17 +83815,17 @@ function dew$6$1() { assert(num < 67108864); if (num < 0) return this.isubn(-num); // Possible sign change - if ((this || _global$1$1).negative !== 0) { - if ((this || _global$1$1).length === 1 && ((this || _global$1$1).words[0] | 0) < num) { - (this || _global$1$1).words[0] = num - ((this || _global$1$1).words[0] | 0); - (this || _global$1$1).negative = 0; - return this || _global$1$1; + if ((this || _global$1$3).negative !== 0) { + if ((this || _global$1$3).length === 1 && ((this || _global$1$3).words[0] | 0) < num) { + (this || _global$1$3).words[0] = num - ((this || _global$1$3).words[0] | 0); + (this || _global$1$3).negative = 0; + return this || _global$1$3; } - (this || _global$1$1).negative = 0; + (this || _global$1$3).negative = 0; this.isubn(num); - (this || _global$1$1).negative = 1; - return this || _global$1$1; + (this || _global$1$3).negative = 1; + return this || _global$1$3; } // Add without checks @@ -49257,20 +83833,20 @@ function dew$6$1() { }; BN.prototype._iaddn = function _iaddn(num) { - (this || _global$1$1).words[0] += num; // Carry + (this || _global$1$3).words[0] += num; // Carry - for (var i = 0; i < (this || _global$1$1).length && (this || _global$1$1).words[i] >= 67108864; i++) { - (this || _global$1$1).words[i] -= 67108864; + for (var i = 0; i < (this || _global$1$3).length && (this || _global$1$3).words[i] >= 67108864; i++) { + (this || _global$1$3).words[i] -= 67108864; - if (i === (this || _global$1$1).length - 1) { - (this || _global$1$1).words[i + 1] = 1; + if (i === (this || _global$1$3).length - 1) { + (this || _global$1$3).words[i + 1] = 1; } else { - (this || _global$1$1).words[i + 1]++; + (this || _global$1$3).words[i + 1]++; } } - (this || _global$1$1).length = Math.max((this || _global$1$1).length, i + 1); - return this || _global$1$1; + (this || _global$1$3).length = Math.max((this || _global$1$3).length, i + 1); + return this || _global$1$3; }; // Subtract plain number `num` from `this` @@ -49279,23 +83855,23 @@ function dew$6$1() { assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$1$1).negative !== 0) { - (this || _global$1$1).negative = 0; + if ((this || _global$1$3).negative !== 0) { + (this || _global$1$3).negative = 0; this.iaddn(num); - (this || _global$1$1).negative = 1; - return this || _global$1$1; + (this || _global$1$3).negative = 1; + return this || _global$1$3; } - (this || _global$1$1).words[0] -= num; + (this || _global$1$3).words[0] -= num; - if ((this || _global$1$1).length === 1 && (this || _global$1$1).words[0] < 0) { - (this || _global$1$1).words[0] = -(this || _global$1$1).words[0]; - (this || _global$1$1).negative = 1; + if ((this || _global$1$3).length === 1 && (this || _global$1$3).words[0] < 0) { + (this || _global$1$3).words[0] = -(this || _global$1$3).words[0]; + (this || _global$1$3).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$1$1).length && (this || _global$1$1).words[i] < 0; i++) { - (this || _global$1$1).words[i] += 67108864; - (this || _global$1$1).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$1$3).length && (this || _global$1$3).words[i] < 0; i++) { + (this || _global$1$3).words[i] += 67108864; + (this || _global$1$3).words[i + 1] -= 1; } } @@ -49311,8 +83887,8 @@ function dew$6$1() { }; BN.prototype.iabs = function iabs() { - (this || _global$1$1).negative = 0; - return this || _global$1$1; + (this || _global$1$3).negative = 0; + return this || _global$1$3; }; BN.prototype.abs = function abs() { @@ -49329,17 +83905,17 @@ function dew$6$1() { var carry = 0; for (i = 0; i < num.length; i++) { - w = ((this || _global$1$1).words[i + shift] | 0) + carry; + w = ((this || _global$1$3).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$1$1).words[i + shift] = w & 67108863; + (this || _global$1$3).words[i + shift] = w & 67108863; } - for (; i < (this || _global$1$1).length - shift; i++) { - w = ((this || _global$1$1).words[i + shift] | 0) + carry; + for (; i < (this || _global$1$3).length - shift; i++) { + w = ((this || _global$1$3).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$1$1).words[i + shift] = w & 67108863; + (this || _global$1$3).words[i + shift] = w & 67108863; } if (carry === 0) return this.strip(); // Subtraction overflow @@ -49347,18 +83923,18 @@ function dew$6$1() { assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$1$1).length; i++) { - w = -((this || _global$1$1).words[i] | 0) + carry; + for (i = 0; i < (this || _global$1$3).length; i++) { + w = -((this || _global$1$3).words[i] | 0) + carry; carry = w >> 26; - (this || _global$1$1).words[i] = w & 67108863; + (this || _global$1$3).words[i] = w & 67108863; } - (this || _global$1$1).negative = 1; + (this || _global$1$3).negative = 1; return this.strip(); }; BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$1$1).length - num.length; + var shift = (this || _global$1$3).length - num.length; var a = this.clone(); var b = num; // Normalize @@ -49454,7 +84030,7 @@ function dew$6$1() { var div, mod, res; - if ((this || _global$1$1).negative !== 0 && num.negative === 0) { + if ((this || _global$1$3).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); if (mode !== "mod") { @@ -49475,7 +84051,7 @@ function dew$6$1() { }; } - if ((this || _global$1$1).negative === 0 && num.negative !== 0) { + if ((this || _global$1$3).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); if (mode !== "mod") { @@ -49488,7 +84064,7 @@ function dew$6$1() { }; } - if (((this || _global$1$1).negative & num.negative) !== 0) { + if (((this || _global$1$3).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); if (mode !== "div") { @@ -49507,10 +84083,10 @@ function dew$6$1() { // Strip both numbers to approximate shift value - if (num.length > (this || _global$1$1).length || this.cmp(num) < 0) { + if (num.length > (this || _global$1$3).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$1$1 + mod: this || _global$1$3 }; } // Very short reduction @@ -49573,8 +84149,8 @@ function dew$6$1() { var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$1$1).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$1$1).words[i] | 0)) % num; + for (var i = (this || _global$1$3).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$1$3).words[i] | 0)) % num; } return acc; @@ -49585,9 +84161,9 @@ function dew$6$1() { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$1$1).length - 1; i >= 0; i--) { - var w = ((this || _global$1$1).words[i] | 0) + carry * 67108864; - (this || _global$1$1).words[i] = w / num | 0; + for (var i = (this || _global$1$3).length - 1; i >= 0; i--) { + var w = ((this || _global$1$3).words[i] | 0) + carry * 67108864; + (this || _global$1$3).words[i] = w / num | 0; carry = w % num; } @@ -49601,7 +84177,7 @@ function dew$6$1() { BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$1$1; + var x = this || _global$1$3; var y = p.clone(); if (x.negative !== 0) { @@ -49684,7 +84260,7 @@ function dew$6$1() { BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$1$1; + var a = this || _global$1$3; var b = p.clone(); if (a.negative !== 0) { @@ -49795,16 +84371,16 @@ function dew$6$1() { }; BN.prototype.isEven = function isEven() { - return ((this || _global$1$1).words[0] & 1) === 0; + return ((this || _global$1$3).words[0] & 1) === 0; }; BN.prototype.isOdd = function isOdd() { - return ((this || _global$1$1).words[0] & 1) === 1; + return ((this || _global$1$3).words[0] & 1) === 1; }; // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$1$1).words[0] & num; + return (this || _global$1$3).words[0] & num; }; // Increment at the bit position in-line @@ -49814,44 +84390,44 @@ function dew$6$1() { var s = (bit - r) / 26; var q = 1 << r; // Fast case: bit is much higher than all existing words - if ((this || _global$1$1).length <= s) { + if ((this || _global$1$3).length <= s) { this._expand(s + 1); - (this || _global$1$1).words[s] |= q; - return this || _global$1$1; + (this || _global$1$3).words[s] |= q; + return this || _global$1$3; } // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$1$1).length; i++) { - var w = (this || _global$1$1).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$1$3).length; i++) { + var w = (this || _global$1$3).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$1$1).words[i] = w; + (this || _global$1$3).words[i] = w; } if (carry !== 0) { - (this || _global$1$1).words[i] = carry; - (this || _global$1$1).length++; + (this || _global$1$3).words[i] = carry; + (this || _global$1$3).length++; } - return this || _global$1$1; + return this || _global$1$3; }; BN.prototype.isZero = function isZero() { - return (this || _global$1$1).length === 1 && (this || _global$1$1).words[0] === 0; + return (this || _global$1$3).length === 1 && (this || _global$1$3).words[0] === 0; }; BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$1$1).negative !== 0 && !negative) return -1; - if ((this || _global$1$1).negative === 0 && negative) return 1; + if ((this || _global$1$3).negative !== 0 && !negative) return -1; + if ((this || _global$1$3).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$1$1).length > 1) { + if ((this || _global$1$3).length > 1) { res = 1; } else { if (negative) { @@ -49859,11 +84435,11 @@ function dew$6$1() { } assert(num <= 67108863, "Number is too big"); - var w = (this || _global$1$1).words[0] | 0; + var w = (this || _global$1$3).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$1$1).negative !== 0) return -res | 0; + if ((this || _global$1$3).negative !== 0) return -res | 0; return res; }; // Compare two numbers and return: // 1 - if `this` > `num` @@ -49872,22 +84448,22 @@ function dew$6$1() { BN.prototype.cmp = function cmp(num) { - if ((this || _global$1$1).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$1$1).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$1$3).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$1$3).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$1$1).negative !== 0) return -res | 0; + if ((this || _global$1$3).negative !== 0) return -res | 0; return res; }; // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$1$1).length > num.length) return 1; - if ((this || _global$1$1).length < num.length) return -1; + if ((this || _global$1$3).length > num.length) return 1; + if ((this || _global$1$3).length < num.length) return -1; var res = 0; - for (var i = (this || _global$1$1).length - 1; i >= 0; i--) { - var a = (this || _global$1$1).words[i] | 0; + for (var i = (this || _global$1$3).length - 1; i >= 0; i--) { + var a = (this || _global$1$3).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; @@ -49952,115 +84528,115 @@ function dew$6$1() { }; BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$1$1).red, "Already a number in reduction context"); - assert((this || _global$1$1).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$1$1)._forceRed(ctx); + assert(!(this || _global$1$3).red, "Already a number in reduction context"); + assert((this || _global$1$3).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$1$3)._forceRed(ctx); }; BN.prototype.fromRed = function fromRed() { - assert((this || _global$1$1).red, "fromRed works only with numbers in reduction context"); - return (this || _global$1$1).red.convertFrom(this || _global$1$1); + assert((this || _global$1$3).red, "fromRed works only with numbers in reduction context"); + return (this || _global$1$3).red.convertFrom(this || _global$1$3); }; BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$1$1).red = ctx; - return this || _global$1$1; + (this || _global$1$3).red = ctx; + return this || _global$1$3; }; BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$1$1).red, "Already a number in reduction context"); + assert(!(this || _global$1$3).red, "Already a number in reduction context"); return this._forceRed(ctx); }; BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$1$1).red, "redAdd works only with red numbers"); - return (this || _global$1$1).red.add(this || _global$1$1, num); + assert((this || _global$1$3).red, "redAdd works only with red numbers"); + return (this || _global$1$3).red.add(this || _global$1$3, num); }; BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$1$1).red, "redIAdd works only with red numbers"); - return (this || _global$1$1).red.iadd(this || _global$1$1, num); + assert((this || _global$1$3).red, "redIAdd works only with red numbers"); + return (this || _global$1$3).red.iadd(this || _global$1$3, num); }; BN.prototype.redSub = function redSub(num) { - assert((this || _global$1$1).red, "redSub works only with red numbers"); - return (this || _global$1$1).red.sub(this || _global$1$1, num); + assert((this || _global$1$3).red, "redSub works only with red numbers"); + return (this || _global$1$3).red.sub(this || _global$1$3, num); }; BN.prototype.redISub = function redISub(num) { - assert((this || _global$1$1).red, "redISub works only with red numbers"); - return (this || _global$1$1).red.isub(this || _global$1$1, num); + assert((this || _global$1$3).red, "redISub works only with red numbers"); + return (this || _global$1$3).red.isub(this || _global$1$3, num); }; BN.prototype.redShl = function redShl(num) { - assert((this || _global$1$1).red, "redShl works only with red numbers"); - return (this || _global$1$1).red.shl(this || _global$1$1, num); + assert((this || _global$1$3).red, "redShl works only with red numbers"); + return (this || _global$1$3).red.shl(this || _global$1$3, num); }; BN.prototype.redMul = function redMul(num) { - assert((this || _global$1$1).red, "redMul works only with red numbers"); + assert((this || _global$1$3).red, "redMul works only with red numbers"); - (this || _global$1$1).red._verify2(this || _global$1$1, num); + (this || _global$1$3).red._verify2(this || _global$1$3, num); - return (this || _global$1$1).red.mul(this || _global$1$1, num); + return (this || _global$1$3).red.mul(this || _global$1$3, num); }; BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$1$1).red, "redMul works only with red numbers"); + assert((this || _global$1$3).red, "redMul works only with red numbers"); - (this || _global$1$1).red._verify2(this || _global$1$1, num); + (this || _global$1$3).red._verify2(this || _global$1$3, num); - return (this || _global$1$1).red.imul(this || _global$1$1, num); + return (this || _global$1$3).red.imul(this || _global$1$3, num); }; BN.prototype.redSqr = function redSqr() { - assert((this || _global$1$1).red, "redSqr works only with red numbers"); + assert((this || _global$1$3).red, "redSqr works only with red numbers"); - (this || _global$1$1).red._verify1(this || _global$1$1); + (this || _global$1$3).red._verify1(this || _global$1$3); - return (this || _global$1$1).red.sqr(this || _global$1$1); + return (this || _global$1$3).red.sqr(this || _global$1$3); }; BN.prototype.redISqr = function redISqr() { - assert((this || _global$1$1).red, "redISqr works only with red numbers"); + assert((this || _global$1$3).red, "redISqr works only with red numbers"); - (this || _global$1$1).red._verify1(this || _global$1$1); + (this || _global$1$3).red._verify1(this || _global$1$3); - return (this || _global$1$1).red.isqr(this || _global$1$1); + return (this || _global$1$3).red.isqr(this || _global$1$3); }; // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$1$1).red, "redSqrt works only with red numbers"); + assert((this || _global$1$3).red, "redSqrt works only with red numbers"); - (this || _global$1$1).red._verify1(this || _global$1$1); + (this || _global$1$3).red._verify1(this || _global$1$3); - return (this || _global$1$1).red.sqrt(this || _global$1$1); + return (this || _global$1$3).red.sqrt(this || _global$1$3); }; BN.prototype.redInvm = function redInvm() { - assert((this || _global$1$1).red, "redInvm works only with red numbers"); + assert((this || _global$1$3).red, "redInvm works only with red numbers"); - (this || _global$1$1).red._verify1(this || _global$1$1); + (this || _global$1$3).red._verify1(this || _global$1$3); - return (this || _global$1$1).red.invm(this || _global$1$1); + return (this || _global$1$3).red.invm(this || _global$1$3); }; // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$1$1).red, "redNeg works only with red numbers"); + assert((this || _global$1$3).red, "redNeg works only with red numbers"); - (this || _global$1$1).red._verify1(this || _global$1$1); + (this || _global$1$3).red._verify1(this || _global$1$3); - return (this || _global$1$1).red.neg(this || _global$1$1); + return (this || _global$1$3).red.neg(this || _global$1$3); }; BN.prototype.redPow = function redPow(num) { - assert((this || _global$1$1).red && !num.red, "redPow(normalNum)"); + assert((this || _global$1$3).red && !num.red, "redPow(normalNum)"); - (this || _global$1$1).red._verify1(this || _global$1$1); + (this || _global$1$3).red._verify1(this || _global$1$3); - return (this || _global$1$1).red.pow(this || _global$1$1, num); + return (this || _global$1$3).red.pow(this || _global$1$3, num); }; // Prime numbers with efficient reduction @@ -50073,16 +84649,16 @@ function dew$6$1() { function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$1$1).name = name; - (this || _global$1$1).p = new BN(p, 16); - (this || _global$1$1).n = (this || _global$1$1).p.bitLength(); - (this || _global$1$1).k = new BN(1).iushln((this || _global$1$1).n).isub((this || _global$1$1).p); - (this || _global$1$1).tmp = this._tmp(); + (this || _global$1$3).name = name; + (this || _global$1$3).p = new BN(p, 16); + (this || _global$1$3).n = (this || _global$1$3).p.bitLength(); + (this || _global$1$3).k = new BN(1).iushln((this || _global$1$3).n).isub((this || _global$1$3).p); + (this || _global$1$3).tmp = this._tmp(); } MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$1$1).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$1$3).n / 13)); return tmp; }; @@ -50093,19 +84669,19 @@ function dew$6$1() { var rlen; do { - this.split(r, (this || _global$1$1).tmp); + this.split(r, (this || _global$1$3).tmp); r = this.imulK(r); - r = r.iadd((this || _global$1$1).tmp); + r = r.iadd((this || _global$1$3).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$1$1).n); + } while (rlen > (this || _global$1$3).n); - var cmp = rlen < (this || _global$1$1).n ? -1 : r.ucmp((this || _global$1$1).p); + var cmp = rlen < (this || _global$1$3).n ? -1 : r.ucmp((this || _global$1$3).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$1$1).p); + r.isub((this || _global$1$3).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -50120,15 +84696,15 @@ function dew$6$1() { }; MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$1$1).n, 0, out); + input.iushrn((this || _global$1$3).n, 0, out); }; MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$1$1).k); + return num.imul((this || _global$1$3).k); }; function K256() { - MPrime.call(this || _global$1$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$1$3, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } inherits(K256, MPrime); @@ -50198,20 +84774,20 @@ function dew$6$1() { }; function P224() { - MPrime.call(this || _global$1$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$1$3, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } inherits(P224, MPrime); function P192() { - MPrime.call(this || _global$1$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$1$3, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } inherits(P192, MPrime); function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$1$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$1$3, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } inherits(P25519, MPrime); @@ -50264,12 +84840,12 @@ function dew$6$1() { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$1$1).m = prime.p; - (this || _global$1$1).prime = prime; + (this || _global$1$3).m = prime.p; + (this || _global$1$3).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$1$1).m = m; - (this || _global$1$1).prime = null; + (this || _global$1$3).m = m; + (this || _global$1$3).prime = null; } } @@ -50284,8 +84860,8 @@ function dew$6$1() { }; Red.prototype.imod = function imod(a) { - if ((this || _global$1$1).prime) return (this || _global$1$1).prime.ireduce(a)._forceRed(this || _global$1$1); - return a.umod((this || _global$1$1).m)._forceRed(this || _global$1$1); + if ((this || _global$1$3).prime) return (this || _global$1$3).prime.ireduce(a)._forceRed(this || _global$1$3); + return a.umod((this || _global$1$3).m)._forceRed(this || _global$1$3); }; Red.prototype.neg = function neg(a) { @@ -50293,7 +84869,7 @@ function dew$6$1() { return a.clone(); } - return (this || _global$1$1).m.sub(a)._forceRed(this || _global$1$1); + return (this || _global$1$3).m.sub(a)._forceRed(this || _global$1$3); }; Red.prototype.add = function add(a, b) { @@ -50301,11 +84877,11 @@ function dew$6$1() { var res = a.add(b); - if (res.cmp((this || _global$1$1).m) >= 0) { - res.isub((this || _global$1$1).m); + if (res.cmp((this || _global$1$3).m) >= 0) { + res.isub((this || _global$1$3).m); } - return res._forceRed(this || _global$1$1); + return res._forceRed(this || _global$1$3); }; Red.prototype.iadd = function iadd(a, b) { @@ -50313,8 +84889,8 @@ function dew$6$1() { var res = a.iadd(b); - if (res.cmp((this || _global$1$1).m) >= 0) { - res.isub((this || _global$1$1).m); + if (res.cmp((this || _global$1$3).m) >= 0) { + res.isub((this || _global$1$3).m); } return res; @@ -50326,10 +84902,10 @@ function dew$6$1() { var res = a.sub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$1$1).m); + res.iadd((this || _global$1$3).m); } - return res._forceRed(this || _global$1$1); + return res._forceRed(this || _global$1$3); }; Red.prototype.isub = function isub(a, b) { @@ -50338,7 +84914,7 @@ function dew$6$1() { var res = a.isub(b); if (res.cmpn(0) < 0) { - res.iadd((this || _global$1$1).m); + res.iadd((this || _global$1$3).m); } return res; @@ -50373,12 +84949,12 @@ function dew$6$1() { Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$1$1).m.andln(3); + var mod3 = (this || _global$1$3).m.andln(3); assert(mod3 % 2 === 1); // Fast case if (mod3 === 3) { - var pow = (this || _global$1$1).m.add(new BN(1)).iushrn(2); + var pow = (this || _global$1$3).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); } // Tonelli-Shanks algorithm (Totally unoptimized and slow) @@ -50386,7 +84962,7 @@ function dew$6$1() { // Find Q and S, that Q * 2 ^ S = (P - 1) - var q = (this || _global$1$1).m.subn(1); + var q = (this || _global$1$3).m.subn(1); var s = 0; @@ -50396,15 +84972,15 @@ function dew$6$1() { } assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$1$1); + var one = new BN(1).toRed(this || _global$1$3); var nOne = one.redNeg(); // Find quadratic non-residue // NOTE: Max is such because of generalized Riemann hypothesis. - var lpow = (this || _global$1$1).m.subn(1).iushrn(1); + var lpow = (this || _global$1$3).m.subn(1).iushrn(1); - var z = (this || _global$1$1).m.bitLength(); + var z = (this || _global$1$3).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$1$1); + z = new BN(2 * z * z).toRed(this || _global$1$3); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); @@ -50433,1593 +85009,3568 @@ function dew$6$1() { return r; }; - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$1$1).m); + Red.prototype.invm = function invm(a) { + var inv = a._invmp((this || _global$1$3).m); + + if (inv.negative !== 0) { + inv.negative = 0; + return this.imod(inv).redNeg(); + } else { + return this.imod(inv); + } + }; + + Red.prototype.pow = function pow(a, num) { + if (num.isZero()) return new BN(1).toRed(this || _global$1$3); + if (num.cmpn(1) === 0) return a.clone(); + var windowSize = 4; + var wnd = new Array(1 << windowSize); + wnd[0] = new BN(1).toRed(this || _global$1$3); + wnd[1] = a; + + for (var i = 2; i < wnd.length; i++) { + wnd[i] = this.mul(wnd[i - 1], a); + } + + var res = wnd[0]; + var current = 0; + var currentLen = 0; + var start = num.bitLength() % 26; + + if (start === 0) { + start = 26; + } + + for (i = num.length - 1; i >= 0; i--) { + var word = num.words[i]; + + for (var j = start - 1; j >= 0; j--) { + var bit = word >> j & 1; + + if (res !== wnd[0]) { + res = this.sqr(res); + } + + if (bit === 0 && current === 0) { + currentLen = 0; + continue; + } + + current <<= 1; + current |= bit; + currentLen++; + if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; + res = this.mul(res, wnd[current]); + currentLen = 0; + current = 0; + } + + start = 26; + } + + return res; + }; + + Red.prototype.convertTo = function convertTo(num) { + var r = num.umod((this || _global$1$3).m); + return r === num ? r.clone() : r; + }; + + Red.prototype.convertFrom = function convertFrom(num) { + var res = num.clone(); + res.red = null; + return res; + }; // + // Montgomery method engine + // + + + BN.mont = function mont(num) { + return new Mont(num); + }; + + function Mont(m) { + Red.call(this || _global$1$3, m); + (this || _global$1$3).shift = (this || _global$1$3).m.bitLength(); + + if ((this || _global$1$3).shift % 26 !== 0) { + (this || _global$1$3).shift += 26 - (this || _global$1$3).shift % 26; + } + + (this || _global$1$3).r = new BN(1).iushln((this || _global$1$3).shift); + (this || _global$1$3).r2 = this.imod((this || _global$1$3).r.sqr()); + (this || _global$1$3).rinv = (this || _global$1$3).r._invmp((this || _global$1$3).m); + (this || _global$1$3).minv = (this || _global$1$3).rinv.mul((this || _global$1$3).r).isubn(1).div((this || _global$1$3).m); + (this || _global$1$3).minv = (this || _global$1$3).minv.umod((this || _global$1$3).r); + (this || _global$1$3).minv = (this || _global$1$3).r.sub((this || _global$1$3).minv); + } + + inherits(Mont, Red); + + Mont.prototype.convertTo = function convertTo(num) { + return this.imod(num.ushln((this || _global$1$3).shift)); + }; + + Mont.prototype.convertFrom = function convertFrom(num) { + var r = this.imod(num.mul((this || _global$1$3).rinv)); + r.red = null; + return r; + }; + + Mont.prototype.imul = function imul(a, b) { + if (a.isZero() || b.isZero()) { + a.words[0] = 0; + a.length = 1; + return a; + } + + var t = a.imul(b); + var c = t.maskn((this || _global$1$3).shift).mul((this || _global$1$3).minv).imaskn((this || _global$1$3).shift).mul((this || _global$1$3).m); + var u = t.isub(c).iushrn((this || _global$1$3).shift); + var res = u; + + if (u.cmp((this || _global$1$3).m) >= 0) { + res = u.isub((this || _global$1$3).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$1$3).m); + } + + return res._forceRed(this || _global$1$3); + }; + + Mont.prototype.mul = function mul(a, b) { + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$1$3); + var t = a.mul(b); + var c = t.maskn((this || _global$1$3).shift).mul((this || _global$1$3).minv).imaskn((this || _global$1$3).shift).mul((this || _global$1$3).m); + var u = t.isub(c).iushrn((this || _global$1$3).shift); + var res = u; + + if (u.cmp((this || _global$1$3).m) >= 0) { + res = u.isub((this || _global$1$3).m); + } else if (u.cmpn(0) < 0) { + res = u.iadd((this || _global$1$3).m); + } + + return res._forceRed(this || _global$1$3); + }; + + Mont.prototype.invm = function invm(a) { + // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R + var res = this.imod(a._invmp((this || _global$1$3).m).mul((this || _global$1$3).r2)); + return res._forceRed(this || _global$1$3); + }; + })(module$c, exports$7$3); + + return module$c.exports; +} + +var exports$6$3 = {}, + _dewExec$5$3 = false; +function dew$5$3() { + if (_dewExec$5$3) return exports$6$3; + _dewExec$5$3 = true; + + var BN = dew$6$3(); + + var Buffer = dew$2P().Buffer; + + function withPublic(paddedMsg, key) { + return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray()); + } + + exports$6$3 = withPublic; + return exports$6$3; +} + +var exports$5$3 = {}, + _dewExec$4$3 = false; +function dew$4$3() { + if (_dewExec$4$3) return exports$5$3; + _dewExec$4$3 = true; + + var parseKeys = dew$e$3(); + + var randomBytes = dew$2O(); + + var createHash = dew$2y(); + + var mgf = dew$8$3(); + + var xor = dew$7$3(); + + var BN = dew$6$3(); + + var withPublic = dew$5$3(); + + var crt = dew$W$2(); + + var Buffer = dew$2P().Buffer; + + exports$5$3 = function publicEncrypt(publicKey, msg, reverse) { + var padding; + + if (publicKey.padding) { + padding = publicKey.padding; + } else if (reverse) { + padding = 1; + } else { + padding = 4; + } + + var key = parseKeys(publicKey); + var paddedMsg; + + if (padding === 4) { + paddedMsg = oaep(key, msg); + } else if (padding === 1) { + paddedMsg = pkcs1(key, msg, reverse); + } else if (padding === 3) { + paddedMsg = new BN(msg); + + if (paddedMsg.cmp(key.modulus) >= 0) { + throw new Error("data too long for modulus"); + } + } else { + throw new Error("unknown padding"); + } + + if (reverse) { + return crt(paddedMsg, key); + } else { + return withPublic(paddedMsg, key); + } + }; + + function oaep(key, msg) { + var k = key.modulus.byteLength(); + var mLen = msg.length; + var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); + var hLen = iHash.length; + var hLen2 = 2 * hLen; + + if (mLen > k - hLen2 - 2) { + throw new Error("message too long"); + } + + var ps = Buffer.alloc(k - mLen - hLen2 - 2); + var dblen = k - hLen - 1; + var seed = randomBytes(hLen); + var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen)); + var maskedSeed = xor(seed, mgf(maskedDb, hLen)); + return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k)); + } + + function pkcs1(key, msg, reverse) { + var mLen = msg.length; + var k = key.modulus.byteLength(); + + if (mLen > k - 11) { + throw new Error("message too long"); + } + + var ps; + + if (reverse) { + ps = Buffer.alloc(k - mLen - 3, 255); + } else { + ps = nonZero(k - mLen - 3); + } + + return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k)); + } + + function nonZero(len) { + var out = Buffer.allocUnsafe(len); + var i = 0; + var cache = randomBytes(len * 2); + var cur = 0; + var num; + + while (i < len) { + if (cur === cache.length) { + cache = randomBytes(len * 2); + cur = 0; + } + + num = cache[cur++]; + + if (num) { + out[i++] = num; + } + } + + return out; + } + + return exports$5$3; +} + +var exports$4$3 = {}, + _dewExec$3$3 = false; +function dew$3$3() { + if (_dewExec$3$3) return exports$4$3; + _dewExec$3$3 = true; + + var parseKeys = dew$e$3(); + + var mgf = dew$8$3(); + + var xor = dew$7$3(); + + var BN = dew$6$3(); + + var crt = dew$W$2(); + + var createHash = dew$2y(); + + var withPublic = dew$5$3(); + + var Buffer = dew$2P().Buffer; + + exports$4$3 = function privateDecrypt(privateKey, enc, reverse) { + var padding; + + if (privateKey.padding) { + padding = privateKey.padding; + } else if (reverse) { + padding = 1; + } else { + padding = 4; + } + + var key = parseKeys(privateKey); + var k = key.modulus.byteLength(); + + if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) { + throw new Error("decryption error"); + } + + var msg; + + if (reverse) { + msg = withPublic(new BN(enc), key); + } else { + msg = crt(enc, key); + } + + var zBuffer = Buffer.alloc(k - msg.length); + msg = Buffer.concat([zBuffer, msg], k); + + if (padding === 4) { + return oaep(key, msg); + } else if (padding === 1) { + return pkcs1(key, msg, reverse); + } else if (padding === 3) { + return msg; + } else { + throw new Error("unknown padding"); + } + }; + + function oaep(key, msg) { + var k = key.modulus.byteLength(); + var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); + var hLen = iHash.length; + + if (msg[0] !== 0) { + throw new Error("decryption error"); + } + + var maskedSeed = msg.slice(1, hLen + 1); + var maskedDb = msg.slice(hLen + 1); + var seed = xor(maskedSeed, mgf(maskedDb, hLen)); + var db = xor(maskedDb, mgf(seed, k - hLen - 1)); + + if (compare(iHash, db.slice(0, hLen))) { + throw new Error("decryption error"); + } + + var i = hLen; + + while (db[i] === 0) { + i++; + } + + if (db[i++] !== 1) { + throw new Error("decryption error"); + } + + return db.slice(i); + } + + function pkcs1(key, msg, reverse) { + var p1 = msg.slice(0, 2); + var i = 2; + var status = 0; + + while (msg[i++] !== 0) { + if (i >= msg.length) { + status++; + break; + } + } + + var ps = msg.slice(2, i - 1); + + if (p1.toString("hex") !== "0002" && !reverse || p1.toString("hex") !== "0001" && reverse) { + status++; + } + + if (ps.length < 8) { + status++; + } + + if (status) { + throw new Error("decryption error"); + } + + return msg.slice(i); + } + + function compare(a, b) { + a = Buffer.from(a); + b = Buffer.from(b); + var dif = 0; + var len = a.length; - if (inv.negative !== 0) { - inv.negative = 0; - return this.imod(inv).redNeg(); - } else { - return this.imod(inv); - } - }; + if (a.length !== b.length) { + dif++; + len = Math.min(a.length, b.length); + } - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$1$1); - if (num.cmpn(1) === 0) return a.clone(); - var windowSize = 4; - var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$1$1); - wnd[1] = a; + var i = -1; - for (var i = 2; i < wnd.length; i++) { - wnd[i] = this.mul(wnd[i - 1], a); - } + while (++i < len) { + dif += a[i] ^ b[i]; + } - var res = wnd[0]; - var current = 0; - var currentLen = 0; - var start = num.bitLength() % 26; + return dif; + } - if (start === 0) { - start = 26; - } + return exports$4$3; +} - for (i = num.length - 1; i >= 0; i--) { - var word = num.words[i]; +var exports$3$3 = {}, + _dewExec$2$3 = false; +function dew$2$3() { + if (_dewExec$2$3) return exports$3$3; + _dewExec$2$3 = true; + exports$3$3.publicEncrypt = dew$4$3(); + exports$3$3.privateDecrypt = dew$3$3(); - for (var j = start - 1; j >= 0; j--) { - var bit = word >> j & 1; + exports$3$3.privateEncrypt = function privateEncrypt(key, buf) { + return exports$3$3.publicEncrypt(key, buf, true); + }; - if (res !== wnd[0]) { - res = this.sqr(res); - } + exports$3$3.publicDecrypt = function publicDecrypt(key, buf) { + return exports$3$3.privateDecrypt(key, buf, true); + }; - if (bit === 0 && current === 0) { - currentLen = 0; - continue; - } + return exports$3$3; +} - current <<= 1; - current |= bit; - currentLen++; - if (currentLen !== windowSize && (i !== 0 || j !== 0)) continue; - res = this.mul(res, wnd[current]); - currentLen = 0; - current = 0; - } +var exports$2$3 = {}, + _dewExec$1$3 = false; - start = 26; - } +var _global$V = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - return res; - }; +function dew$1$3() { + if (_dewExec$1$3) return exports$2$3; + _dewExec$1$3 = true; + var process$1$1 = process$1; - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$1$1).m); - return r === num ? r.clone() : r; - }; + function oldBrowser() { + throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11"); + } - Red.prototype.convertFrom = function convertFrom(num) { - var res = num.clone(); - res.red = null; - return res; - }; // - // Montgomery method engine - // + var safeBuffer = dew$2P(); + var randombytes = dew$2O(); - BN.mont = function mont(num) { - return new Mont(num); - }; + var Buffer = safeBuffer.Buffer; + var kBufferMaxLength = safeBuffer.kMaxLength; + var crypto = _global$V.crypto || _global$V.msCrypto; + var kMaxUint32 = Math.pow(2, 32) - 1; - function Mont(m) { - Red.call(this || _global$1$1, m); - (this || _global$1$1).shift = (this || _global$1$1).m.bitLength(); + function assertOffset(offset, length) { + if (typeof offset !== "number" || offset !== offset) { + // eslint-disable-line no-self-compare + throw new TypeError("offset must be a number"); + } - if ((this || _global$1$1).shift % 26 !== 0) { - (this || _global$1$1).shift += 26 - (this || _global$1$1).shift % 26; - } + if (offset > kMaxUint32 || offset < 0) { + throw new TypeError("offset must be a uint32"); + } - (this || _global$1$1).r = new BN(1).iushln((this || _global$1$1).shift); - (this || _global$1$1).r2 = this.imod((this || _global$1$1).r.sqr()); - (this || _global$1$1).rinv = (this || _global$1$1).r._invmp((this || _global$1$1).m); - (this || _global$1$1).minv = (this || _global$1$1).rinv.mul((this || _global$1$1).r).isubn(1).div((this || _global$1$1).m); - (this || _global$1$1).minv = (this || _global$1$1).minv.umod((this || _global$1$1).r); - (this || _global$1$1).minv = (this || _global$1$1).r.sub((this || _global$1$1).minv); + if (offset > kBufferMaxLength || offset > length) { + throw new RangeError("offset out of range"); } + } - inherits(Mont, Red); + function assertSize(size, offset, length) { + if (typeof size !== "number" || size !== size) { + // eslint-disable-line no-self-compare + throw new TypeError("size must be a number"); + } - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$1$1).shift)); - }; + if (size > kMaxUint32 || size < 0) { + throw new TypeError("size must be a uint32"); + } - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$1$1).rinv)); - r.red = null; - return r; - }; + if (size + offset > length || size > kBufferMaxLength) { + throw new RangeError("buffer too small"); + } + } - Mont.prototype.imul = function imul(a, b) { - if (a.isZero() || b.isZero()) { - a.words[0] = 0; - a.length = 1; - return a; - } + if (crypto && crypto.getRandomValues || !process$1$1.browser) { + exports$2$3.randomFill = randomFill; + exports$2$3.randomFillSync = randomFillSync; + } else { + exports$2$3.randomFill = oldBrowser; + exports$2$3.randomFillSync = oldBrowser; + } - var t = a.imul(b); - var c = t.maskn((this || _global$1$1).shift).mul((this || _global$1$1).minv).imaskn((this || _global$1$1).shift).mul((this || _global$1$1).m); - var u = t.isub(c).iushrn((this || _global$1$1).shift); - var res = u; + function randomFill(buf, offset, size, cb) { + if (!Buffer.isBuffer(buf) && !(buf instanceof _global$V.Uint8Array)) { + throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); + } - if (u.cmp((this || _global$1$1).m) >= 0) { - res = u.isub((this || _global$1$1).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$1$1).m); - } + if (typeof offset === "function") { + cb = offset; + offset = 0; + size = buf.length; + } else if (typeof size === "function") { + cb = size; + size = buf.length - offset; + } else if (typeof cb !== "function") { + throw new TypeError("\"cb\" argument must be a function"); + } - return res._forceRed(this || _global$1$1); - }; + assertOffset(offset, buf.length); + assertSize(size, offset, buf.length); + return actualFill(buf, offset, size, cb); + } - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$1$1); - var t = a.mul(b); - var c = t.maskn((this || _global$1$1).shift).mul((this || _global$1$1).minv).imaskn((this || _global$1$1).shift).mul((this || _global$1$1).m); - var u = t.isub(c).iushrn((this || _global$1$1).shift); - var res = u; + function actualFill(buf, offset, size, cb) { + if (process$1$1.browser) { + var ourBuf = buf.buffer; + var uint = new Uint8Array(ourBuf, offset, size); + crypto.getRandomValues(uint); - if (u.cmp((this || _global$1$1).m) >= 0) { - res = u.isub((this || _global$1$1).m); - } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$1$1).m); + if (cb) { + process$1$1.nextTick(function () { + cb(null, buf); + }); + return; } - return res._forceRed(this || _global$1$1); - }; + return buf; + } - Mont.prototype.invm = function invm(a) { - // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$1$1).m).mul((this || _global$1$1).r2)); - return res._forceRed(this || _global$1$1); - }; - })(module$8, exports$6$1); + if (cb) { + randombytes(size, function (err, bytes) { + if (err) { + return cb(err); + } - return module$8.exports; -} + bytes.copy(buf, offset); + cb(null, buf); + }); + return; + } -var exports$5$1 = {}, - _dewExec$5$1 = false; -function dew$5$1() { - if (_dewExec$5$1) return exports$5$1; - _dewExec$5$1 = true; + var bytes = randombytes(size); + bytes.copy(buf, offset); + return buf; + } - var BN = dew$6$1(); + function randomFillSync(buf, offset, size) { + if (typeof offset === "undefined") { + offset = 0; + } - var Buffer = dew$1T().Buffer; + if (!Buffer.isBuffer(buf) && !(buf instanceof _global$V.Uint8Array)) { + throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); + } - function withPublic(paddedMsg, key) { - return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray()); + assertOffset(offset, buf.length); + if (size === undefined) size = buf.length - offset; + assertSize(size, offset, buf.length); + return actualFill(buf, offset, size); } - exports$5$1 = withPublic; - return exports$5$1; + return exports$2$3; } -var exports$4$1 = {}, - _dewExec$4$1 = false; -function dew$4$1() { - if (_dewExec$4$1) return exports$4$1; - _dewExec$4$1 = true; +var exports$1$3 = {}, + _dewExec$2Q = false; +function dew$2Q() { + if (_dewExec$2Q) return exports$1$3; + _dewExec$2Q = true; + exports$1$3.randomBytes = exports$1$3.rng = exports$1$3.pseudoRandomBytes = exports$1$3.prng = dew$2O(); + exports$1$3.createHash = exports$1$3.Hash = dew$2y(); + exports$1$3.createHmac = exports$1$3.Hmac = dew$2v(); - var parseKeys = dew$e$1(); + var algos = dew$2u(); - var randomBytes = dew$1S(); + var algoKeys = Object.keys(algos); + var hashes = ["sha1", "sha224", "sha256", "sha384", "sha512", "md5", "rmd160"].concat(algoKeys); - var createHash = dew$1F(); + exports$1$3.getHashes = function () { + return hashes; + }; - var mgf = dew$8$1(); + var p = dew$2o(); - var xor = dew$7$1(); + exports$1$3.pbkdf2 = p.pbkdf2; + exports$1$3.pbkdf2Sync = p.pbkdf2Sync; - var BN = dew$6$1(); + var aes = dew$1Y(); - var withPublic = dew$5$1(); + exports$1$3.Cipher = aes.Cipher; + exports$1$3.createCipher = aes.createCipher; + exports$1$3.Cipheriv = aes.Cipheriv; + exports$1$3.createCipheriv = aes.createCipheriv; + exports$1$3.Decipher = aes.Decipher; + exports$1$3.createDecipher = aes.createDecipher; + exports$1$3.Decipheriv = aes.Decipheriv; + exports$1$3.createDecipheriv = aes.createDecipheriv; + exports$1$3.getCiphers = aes.getCiphers; + exports$1$3.listCiphers = aes.listCiphers; + + var dh = dew$Z$2(); + + exports$1$3.DiffieHellmanGroup = dh.DiffieHellmanGroup; + exports$1$3.createDiffieHellmanGroup = dh.createDiffieHellmanGroup; + exports$1$3.getDiffieHellman = dh.getDiffieHellman; + exports$1$3.createDiffieHellman = dh.createDiffieHellman; + exports$1$3.DiffieHellman = dh.DiffieHellman; + + var sign = dew$b$3(); + + exports$1$3.createSign = sign.createSign; + exports$1$3.Sign = sign.Sign; + exports$1$3.createVerify = sign.createVerify; + exports$1$3.Verify = sign.Verify; + exports$1$3.createECDH = dew$9$3(); + + var publicEncrypt = dew$2$3(); + + exports$1$3.publicEncrypt = publicEncrypt.publicEncrypt; + exports$1$3.privateEncrypt = publicEncrypt.privateEncrypt; + exports$1$3.publicDecrypt = publicEncrypt.publicDecrypt; + exports$1$3.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api. + // ;[ + // 'createCredentials' + // ].forEach(function (name) { + // exports[name] = function () { + // throw new Error([ + // 'sorry, ' + name + ' is not implemented yet', + // 'we accept pull requests', + // 'https://github.com/crypto-browserify/crypto-browserify' + // ].join('\n')) + // } + // }) - var crt = dew$W$1(); + var rf = dew$1$3(); - var Buffer = dew$1T().Buffer; + exports$1$3.randomFill = rf.randomFill; + exports$1$3.randomFillSync = rf.randomFillSync; - exports$4$1 = function publicEncrypt(publicKey, msg, reverse) { - var padding; + exports$1$3.createCredentials = function () { + throw new Error(["sorry, createCredentials is not implemented yet", "we accept pull requests", "https://github.com/crypto-browserify/crypto-browserify"].join("\n")); + }; - if (publicKey.padding) { - padding = publicKey.padding; - } else if (reverse) { - padding = 1; - } else { - padding = 4; + exports$1$3.constants = { + "DH_CHECK_P_NOT_SAFE_PRIME": 2, + "DH_CHECK_P_NOT_PRIME": 1, + "DH_UNABLE_TO_CHECK_GENERATOR": 4, + "DH_NOT_SUITABLE_GENERATOR": 8, + "NPN_ENABLED": 1, + "ALPN_ENABLED": 1, + "RSA_PKCS1_PADDING": 1, + "RSA_SSLV23_PADDING": 2, + "RSA_NO_PADDING": 3, + "RSA_PKCS1_OAEP_PADDING": 4, + "RSA_X931_PADDING": 5, + "RSA_PKCS1_PSS_PADDING": 6, + "POINT_CONVERSION_COMPRESSED": 2, + "POINT_CONVERSION_UNCOMPRESSED": 4, + "POINT_CONVERSION_HYBRID": 6 + }; + return exports$1$3; +} + +const exports$2R = dew$2Q(); +exports$2R['randomBytes']; exports$2R['rng']; exports$2R['pseudoRandomBytes']; exports$2R['prng']; exports$2R['createHash']; exports$2R['Hash']; exports$2R['createHmac']; exports$2R['Hmac']; exports$2R['getHashes']; exports$2R['pbkdf2']; exports$2R['pbkdf2Sync']; exports$2R['Cipher']; exports$2R['createCipher']; exports$2R['Cipheriv']; exports$2R['createCipheriv']; exports$2R['Decipher']; exports$2R['createDecipher']; exports$2R['Decipheriv']; exports$2R['createDecipheriv']; exports$2R['getCiphers']; exports$2R['listCiphers']; exports$2R['DiffieHellmanGroup']; exports$2R['createDiffieHellmanGroup']; exports$2R['getDiffieHellman']; exports$2R['createDiffieHellman']; exports$2R['DiffieHellman']; exports$2R['createSign']; exports$2R['Sign']; exports$2R['createVerify']; exports$2R['Verify']; exports$2R['createECDH']; exports$2R['publicEncrypt']; exports$2R['privateEncrypt']; exports$2R['publicDecrypt']; exports$2R['privateDecrypt']; exports$2R['randomFill']; exports$2R['randomFillSync']; exports$2R['createCredentials']; exports$2R['constants']; + +exports$2R.webcrypto = globalThis.crypto; +exports$2R.Cipher; +exports$2R.Cipheriv; +exports$2R.Decipher; +exports$2R.Decipheriv; +exports$2R.DiffieHellman; +exports$2R.DiffieHellmanGroup; +exports$2R.Hash; +exports$2R.Hmac; +exports$2R.Sign; +exports$2R.Verify; +exports$2R.constants; +exports$2R.createCipher; +exports$2R.createCipheriv; +exports$2R.createCredentials; +exports$2R.createDecipher; +exports$2R.createDecipheriv; +exports$2R.createDiffieHellman; +exports$2R.createDiffieHellmanGroup; +exports$2R.createECDH; +exports$2R.createHash; +exports$2R.createHmac; +exports$2R.createSign; +exports$2R.createVerify; +exports$2R.getCiphers; +exports$2R.getDiffieHellman; +exports$2R.getHashes; +exports$2R.listCiphers; +exports$2R.pbkdf2; +exports$2R.pbkdf2Sync; +exports$2R.privateDecrypt; +exports$2R.privateEncrypt; +exports$2R.prng; +exports$2R.pseudoRandomBytes; +exports$2R.publicDecrypt; +exports$2R.publicEncrypt; +exports$2R.randomBytes; +exports$2R.randomFill; +exports$2R.randomFillSync; +exports$2R.rng; +exports$2R.webcrypto; + +var exports$1j = {}, + _dewExec$1i = false; +var _global$j = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$1i() { + if (_dewExec$1i) return exports$1j; + _dewExec$1i = true; + var r; + exports$1j = function rand(len) { + if (!r) r = new Rand(null); + return r.generate(len); + }; + function Rand(rand) { + (this || _global$j).rand = rand; + } + exports$1j.Rand = Rand; + Rand.prototype.generate = function generate(len) { + return this._rand(len); + }; + + // Emulate crypto API using randy + Rand.prototype._rand = function _rand(n) { + if ((this || _global$j).rand.getBytes) return (this || _global$j).rand.getBytes(n); + var res = new Uint8Array(n); + for (var i = 0; i < res.length; i++) res[i] = (this || _global$j).rand.getByte(); + return res; + }; + if (typeof self === "object") { + if (self.crypto && self.crypto.getRandomValues) { + // Modern browsers + Rand.prototype._rand = function _rand(n) { + var arr = new Uint8Array(n); + self.crypto.getRandomValues(arr); + return arr; + }; + } else if (self.msCrypto && self.msCrypto.getRandomValues) { + // IE + Rand.prototype._rand = function _rand(n) { + var arr = new Uint8Array(n); + self.msCrypto.getRandomValues(arr); + return arr; + }; + + // Safari's WebWorkers do not have `crypto` + } else if (typeof window === "object") { + // Old junk + Rand.prototype._rand = function () { + throw new Error("Not implemented yet"); + }; } + } else { + // Node.js or Web worker with no crypto support + try { + var crypto = exports$2R; + if (typeof crypto.randomBytes !== "function") throw new Error("Not supported"); + Rand.prototype._rand = function _rand(n) { + return crypto.randomBytes(n); + }; + } catch (e) {} + } + return exports$1j; +} - var key = parseKeys(publicKey); - var paddedMsg; +var exports$1i = {}, + _dewExec$1h = false; +var _global$i = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$1h() { + if (_dewExec$1h) return exports$1i; + _dewExec$1h = true; + var bn = dew$2R(); + var brorand = dew$1i(); + function MillerRabin(rand) { + (this || _global$i).rand = rand || new brorand.Rand(); + } + exports$1i = MillerRabin; + MillerRabin.create = function create(rand) { + return new MillerRabin(rand); + }; + MillerRabin.prototype._randbelow = function _randbelow(n) { + var len = n.bitLength(); + var min_bytes = Math.ceil(len / 8); - if (padding === 4) { - paddedMsg = oaep(key, msg); - } else if (padding === 1) { - paddedMsg = pkcs1(key, msg, reverse); - } else if (padding === 3) { - paddedMsg = new BN(msg); + // Generage random bytes until a number less than n is found. + // This ensures that 0..n-1 have an equal probability of being selected. + do var a = new bn((this || _global$i).rand.generate(min_bytes)); while (a.cmp(n) >= 0); + return a; + }; + MillerRabin.prototype._randrange = function _randrange(start, stop) { + // Generate a random number greater than or equal to start and less than stop. + var size = stop.sub(start); + return start.add(this._randbelow(size)); + }; + MillerRabin.prototype.test = function test(n, k, cb) { + var len = n.bitLength(); + var red = bn.mont(n); + var rone = new bn(1).toRed(red); + if (!k) k = Math.max(1, len / 48 | 0); - if (paddedMsg.cmp(key.modulus) >= 0) { - throw new Error("data too long for modulus"); + // Find d and s, (n - 1) = (2 ^ s) * d; + var n1 = n.subn(1); + for (var s = 0; !n1.testn(s); s++) {} + var d = n.shrn(s); + var rn1 = n1.toRed(red); + var prime = true; + for (; k > 0; k--) { + var a = this._randrange(new bn(2), n1); + if (cb) cb(a); + var x = a.toRed(red).redPow(d); + if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue; + for (var i = 1; i < s; i++) { + x = x.redSqr(); + if (x.cmp(rone) === 0) return false; + if (x.cmp(rn1) === 0) break; } - } else { - throw new Error("unknown padding"); + if (i === s) return false; } + return prime; + }; + MillerRabin.prototype.getDivisor = function getDivisor(n, k) { + var len = n.bitLength(); + var red = bn.mont(n); + var rone = new bn(1).toRed(red); + if (!k) k = Math.max(1, len / 48 | 0); - if (reverse) { - return crt(paddedMsg, key); - } else { - return withPublic(paddedMsg, key); + // Find d and s, (n - 1) = (2 ^ s) * d; + var n1 = n.subn(1); + for (var s = 0; !n1.testn(s); s++) {} + var d = n.shrn(s); + var rn1 = n1.toRed(red); + for (; k > 0; k--) { + var a = this._randrange(new bn(2), n1); + var g = n.gcd(a); + if (g.cmpn(1) !== 0) return g; + var x = a.toRed(red).redPow(d); + if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue; + for (var i = 1; i < s; i++) { + x = x.redSqr(); + if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n); + if (x.cmp(rn1) === 0) break; + } + if (i === s) { + x = x.redSqr(); + return x.fromRed().subn(1).gcd(n); + } } + return false; }; + return exports$1i; +} - function oaep(key, msg) { - var k = key.modulus.byteLength(); - var mLen = msg.length; - var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); - var hLen = iHash.length; - var hLen2 = 2 * hLen; - - if (mLen > k - hLen2 - 2) { - throw new Error("message too long"); +var exports$1h = {}, + _dewExec$1g = false; +function dew$1g() { + if (_dewExec$1g) return exports$1h; + _dewExec$1g = true; + var randomBytes = dew$3G(); + exports$1h = findPrime; + findPrime.simpleSieve = simpleSieve; + findPrime.fermatTest = fermatTest; + var BN = dew$2S(); + var TWENTYFOUR = new BN(24); + var MillerRabin = dew$1h(); + var millerRabin = new MillerRabin(); + var ONE = new BN(1); + var TWO = new BN(2); + var FIVE = new BN(5); + new BN(16); + new BN(8); + var TEN = new BN(10); + var THREE = new BN(3); + new BN(7); + var ELEVEN = new BN(11); + var FOUR = new BN(4); + new BN(12); + var primes = null; + function _getPrimes() { + if (primes !== null) return primes; + var limit = 1048576; + var res = []; + res[0] = 2; + for (var i = 1, k = 3; k < limit; k += 2) { + var sqrt = Math.ceil(Math.sqrt(k)); + for (var j = 0; j < i && res[j] <= sqrt; j++) if (k % res[j] === 0) break; + if (i !== j && res[j] <= sqrt) continue; + res[i++] = k; + } + primes = res; + return res; + } + function simpleSieve(p) { + var primes = _getPrimes(); + for (var i = 0; i < primes.length; i++) if (p.modn(primes[i]) === 0) { + if (p.cmpn(primes[i]) === 0) { + return true; + } else { + return false; + } + } + return true; + } + function fermatTest(p) { + var red = BN.mont(p); + return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0; + } + function findPrime(bits, gen) { + if (bits < 16) { + // this is what openssl does + if (gen === 2 || gen === 5) { + return new BN([140, 123]); + } else { + return new BN([140, 39]); + } + } + gen = new BN(gen); + var num, n2; + while (true) { + num = new BN(randomBytes(Math.ceil(bits / 8))); + while (num.bitLength() > bits) { + num.ishrn(1); + } + if (num.isEven()) { + num.iadd(ONE); + } + if (!num.testn(1)) { + num.iadd(TWO); + } + if (!gen.cmp(TWO)) { + while (num.mod(TWENTYFOUR).cmp(ELEVEN)) { + num.iadd(FOUR); + } + } else if (!gen.cmp(FIVE)) { + while (num.mod(TEN).cmp(THREE)) { + num.iadd(FOUR); + } + } + n2 = num.shrn(1); + if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) { + return num; + } } - - var ps = Buffer.alloc(k - mLen - hLen2 - 2); - var dblen = k - hLen - 1; - var seed = randomBytes(hLen); - var maskedDb = xor(Buffer.concat([iHash, ps, Buffer.alloc(1, 1), msg], dblen), mgf(seed, dblen)); - var maskedSeed = xor(seed, mgf(maskedDb, hLen)); - return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k)); } + return exports$1h; +} - function pkcs1(key, msg, reverse) { - var mLen = msg.length; - var k = key.modulus.byteLength(); - - if (mLen > k - 11) { - throw new Error("message too long"); +var _primes = { + "modp1": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff" + }, + "modp2": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff" + }, + "modp5": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff" + }, + "modp14": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff" + }, + "modp15": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff" + }, + "modp16": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff" + }, + "modp17": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff" + }, + "modp18": { + "gen": "02", + "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff" } +}; - var ps; - - if (reverse) { - ps = Buffer.alloc(k - mLen - 3, 255); - } else { - ps = nonZero(k - mLen - 3); +var exports$1g = {}, + _dewExec$1f = false; +var _global$h = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$1f() { + if (_dewExec$1f) return exports$1g; + _dewExec$1f = true; + var Buffer = dew$3J().Buffer; + var BN = dew$2S(); + var MillerRabin = dew$1h(); + var millerRabin = new MillerRabin(); + var TWENTYFOUR = new BN(24); + var ELEVEN = new BN(11); + var TEN = new BN(10); + var THREE = new BN(3); + var SEVEN = new BN(7); + var primes = dew$1g(); + var randomBytes = dew$3G(); + exports$1g = DH; + function setPublicKey(pub, enc) { + enc = enc || "utf8"; + if (!Buffer.isBuffer(pub)) { + pub = new Buffer(pub, enc); } - - return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k)); + (this || _global$h)._pub = new BN(pub); + return this || _global$h; } - - function nonZero(len) { - var out = Buffer.allocUnsafe(len); - var i = 0; - var cache = randomBytes(len * 2); - var cur = 0; - var num; - - while (i < len) { - if (cur === cache.length) { - cache = randomBytes(len * 2); - cur = 0; - } - - num = cache[cur++]; - - if (num) { - out[i++] = num; + function setPrivateKey(priv, enc) { + enc = enc || "utf8"; + if (!Buffer.isBuffer(priv)) { + priv = new Buffer(priv, enc); + } + (this || _global$h)._priv = new BN(priv); + return this || _global$h; + } + var primeCache = {}; + function checkPrime(prime, generator) { + var gen = generator.toString("hex"); + var hex = [gen, prime.toString(16)].join("_"); + if (hex in primeCache) { + return primeCache[hex]; + } + var error = 0; + if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) { + //not a prime so +1 + error += 1; + if (gen === "02" || gen === "05") { + // we'd be able to check the generator + // it would fail so +8 + error += 8; + } else { + //we wouldn't be able to test the generator + // so +4 + error += 4; } + primeCache[hex] = error; + return error; } - - return out; + if (!millerRabin.test(prime.shrn(1))) { + //not a safe prime + error += 2; + } + var rem; + switch (gen) { + case "02": + if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) { + // unsuidable generator + error += 8; + } + break; + case "05": + rem = prime.mod(TEN); + if (rem.cmp(THREE) && rem.cmp(SEVEN)) { + // prime mod 10 needs to equal 3 or 7 + error += 8; + } + break; + default: + error += 4; + } + primeCache[hex] = error; + return error; } - - return exports$4$1; -} - -var exports$3$1 = {}, - _dewExec$3$1 = false; -function dew$3$1() { - if (_dewExec$3$1) return exports$3$1; - _dewExec$3$1 = true; - - var parseKeys = dew$e$1(); - - var mgf = dew$8$1(); - - var xor = dew$7$1(); - - var BN = dew$6$1(); - - var crt = dew$W$1(); - - var createHash = dew$1F(); - - var withPublic = dew$5$1(); - - var Buffer = dew$1T().Buffer; - - exports$3$1 = function privateDecrypt(privateKey, enc, reverse) { - var padding; - - if (privateKey.padding) { - padding = privateKey.padding; - } else if (reverse) { - padding = 1; + function DH(prime, generator, malleable) { + this.setGenerator(generator); + (this || _global$h).__prime = new BN(prime); + (this || _global$h)._prime = BN.mont((this || _global$h).__prime); + (this || _global$h)._primeLen = prime.length; + (this || _global$h)._pub = undefined; + (this || _global$h)._priv = undefined; + (this || _global$h)._primeCode = undefined; + if (malleable) { + (this || _global$h).setPublicKey = setPublicKey; + (this || _global$h).setPrivateKey = setPrivateKey; } else { - padding = 4; + (this || _global$h)._primeCode = 8; } - - var key = parseKeys(privateKey); - var k = key.modulus.byteLength(); - - if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) { - throw new Error("decryption error"); + } + Object.defineProperty(DH.prototype, "verifyError", { + enumerable: true, + get: function () { + if (typeof (this || _global$h)._primeCode !== "number") { + (this || _global$h)._primeCode = checkPrime((this || _global$h).__prime, (this || _global$h).__gen); + } + return (this || _global$h)._primeCode; } - - var msg; - - if (reverse) { - msg = withPublic(new BN(enc), key); - } else { - msg = crt(enc, key); + }); + DH.prototype.generateKeys = function () { + if (!(this || _global$h)._priv) { + (this || _global$h)._priv = new BN(randomBytes((this || _global$h)._primeLen)); } - - var zBuffer = Buffer.alloc(k - msg.length); - msg = Buffer.concat([zBuffer, msg], k); - - if (padding === 4) { - return oaep(key, msg); - } else if (padding === 1) { - return pkcs1(key, msg, reverse); - } else if (padding === 3) { - return msg; - } else { - throw new Error("unknown padding"); + (this || _global$h)._pub = (this || _global$h)._gen.toRed((this || _global$h)._prime).redPow((this || _global$h)._priv).fromRed(); + return this.getPublicKey(); + }; + DH.prototype.computeSecret = function (other) { + other = new BN(other); + other = other.toRed((this || _global$h)._prime); + var secret = other.redPow((this || _global$h)._priv).fromRed(); + var out = new Buffer(secret.toArray()); + var prime = this.getPrime(); + if (out.length < prime.length) { + var front = new Buffer(prime.length - out.length); + front.fill(0); + out = Buffer.concat([front, out]); } + return out; }; - - function oaep(key, msg) { - var k = key.modulus.byteLength(); - var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); - var hLen = iHash.length; - - if (msg[0] !== 0) { - throw new Error("decryption error"); + DH.prototype.getPublicKey = function getPublicKey(enc) { + return formatReturnValue((this || _global$h)._pub, enc); + }; + DH.prototype.getPrivateKey = function getPrivateKey(enc) { + return formatReturnValue((this || _global$h)._priv, enc); + }; + DH.prototype.getPrime = function (enc) { + return formatReturnValue((this || _global$h).__prime, enc); + }; + DH.prototype.getGenerator = function (enc) { + return formatReturnValue((this || _global$h)._gen, enc); + }; + DH.prototype.setGenerator = function (gen, enc) { + enc = enc || "utf8"; + if (!Buffer.isBuffer(gen)) { + gen = new Buffer(gen, enc); } - - var maskedSeed = msg.slice(1, hLen + 1); - var maskedDb = msg.slice(hLen + 1); - var seed = xor(maskedSeed, mgf(maskedDb, hLen)); - var db = xor(maskedDb, mgf(seed, k - hLen - 1)); - - if (compare(iHash, db.slice(0, hLen))) { - throw new Error("decryption error"); + (this || _global$h).__gen = gen; + (this || _global$h)._gen = new BN(gen); + return this || _global$h; + }; + function formatReturnValue(bn, enc) { + var buf = new Buffer(bn.toArray()); + if (!enc) { + return buf; + } else { + return buf.toString(enc); } + } + return exports$1g; +} - var i = hLen; - - while (db[i] === 0) { - i++; +var exports$1f = {}, + _dewExec$1e = false; +function dew$1e() { + if (_dewExec$1e) return exports$1f; + _dewExec$1e = true; + var Buffer = dew$3J().Buffer; + var generatePrime = dew$1g(); + var primes = _primes; + var DH = dew$1f(); + function getDiffieHellman(mod) { + var prime = new Buffer(primes[mod].prime, "hex"); + var gen = new Buffer(primes[mod].gen, "hex"); + return new DH(prime, gen); + } + var ENCODINGS = { + "binary": true, + "hex": true, + "base64": true + }; + function createDiffieHellman(prime, enc, generator, genc) { + if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) { + return createDiffieHellman(prime, "binary", enc, generator); } - - if (db[i++] !== 1) { - throw new Error("decryption error"); + enc = enc || "binary"; + genc = genc || "binary"; + generator = generator || new Buffer([2]); + if (!Buffer.isBuffer(generator)) { + generator = new Buffer(generator, genc); } - - return db.slice(i); - } - - function pkcs1(key, msg, reverse) { - var p1 = msg.slice(0, 2); - var i = 2; - var status = 0; - - while (msg[i++] !== 0) { - if (i >= msg.length) { - status++; - break; - } + if (typeof prime === "number") { + return new DH(generatePrime(prime, generator), generator, true); } - - var ps = msg.slice(2, i - 1); - - if (p1.toString("hex") !== "0002" && !reverse || p1.toString("hex") !== "0001" && reverse) { - status++; + if (!Buffer.isBuffer(prime)) { + prime = new Buffer(prime, enc); } + return new DH(prime, generator, true); + } + exports$1f.DiffieHellmanGroup = exports$1f.createDiffieHellmanGroup = exports$1f.getDiffieHellman = getDiffieHellman; + exports$1f.createDiffieHellman = exports$1f.DiffieHellman = createDiffieHellman; + return exports$1f; +} - if (ps.length < 8) { - status++; +var exports$1e = {}, + _dewExec$1d = false; +function dew$1d() { + if (_dewExec$1d) return exports$1e; + _dewExec$1d = true; + var process$1 = process; + if (typeof process$1 === "undefined" || !process$1.version || process$1.version.indexOf("v0.") === 0 || process$1.version.indexOf("v1.") === 0 && process$1.version.indexOf("v1.8.") !== 0) { + exports$1e = { + nextTick: nextTick + }; + } else { + exports$1e = process$1; + } + function nextTick(fn, arg1, arg2, arg3) { + if (typeof fn !== "function") { + throw new TypeError("\"callback\" argument must be a function"); } - - if (status) { - throw new Error("decryption error"); + var len = arguments.length; + var args, i; + switch (len) { + case 0: + case 1: + return process$1.nextTick(fn); + case 2: + return process$1.nextTick(function afterTickOne() { + fn.call(null, arg1); + }); + case 3: + return process$1.nextTick(function afterTickTwo() { + fn.call(null, arg1, arg2); + }); + case 4: + return process$1.nextTick(function afterTickThree() { + fn.call(null, arg1, arg2, arg3); + }); + default: + args = new Array(len - 1); + i = 0; + while (i < args.length) { + args[i++] = arguments[i]; + } + return process$1.nextTick(function afterTick() { + fn.apply(null, args); + }); } - - return msg.slice(i); } + return exports$1e; +} - function compare(a, b) { - a = Buffer.from(a); - b = Buffer.from(b); - var dif = 0; - var len = a.length; +var exports$1d = {}, + _dewExec$1c = false; +function dew$1c() { + if (_dewExec$1c) return exports$1d; + _dewExec$1c = true; + var toString = {}.toString; + exports$1d = Array.isArray || function (arr) { + return toString.call(arr) == "[object Array]"; + }; + return exports$1d; +} - if (a.length !== b.length) { - dif++; - len = Math.min(a.length, b.length); - } +var exports$1c = {}, + _dewExec$1b = false; +function dew$1b() { + if (_dewExec$1b) return exports$1c; + _dewExec$1b = true; + exports$1c = y$o.EventEmitter; + return exports$1c; +} - var i = -1; +var exports$1b = {}, + _dewExec$1a = false; +function dew$1a() { + if (_dewExec$1a) return exports$1b; + _dewExec$1a = true; + /* eslint-disable node/no-deprecated-api */ + var buffer = dew$3J(); + var Buffer = buffer.Buffer; - while (++i < len) { - dif += a[i] ^ b[i]; + // alternative to using Object.keys for old browsers + function copyProps(src, dst) { + for (var key in src) { + dst[key] = src[key]; } - - return dif; + } + if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { + exports$1b = buffer; + } else { + // Copy properties from require('buffer') + copyProps(buffer, exports$1b); + exports$1b.Buffer = SafeBuffer; + } + function SafeBuffer(arg, encodingOrOffset, length) { + return Buffer(arg, encodingOrOffset, length); } - return exports$3$1; -} - -var exports$2$1 = {}, - _dewExec$2$1 = false; -function dew$2$1() { - if (_dewExec$2$1) return exports$2$1; - _dewExec$2$1 = true; - exports$2$1.publicEncrypt = dew$4$1(); - exports$2$1.privateDecrypt = dew$3$1(); - - exports$2$1.privateEncrypt = function privateEncrypt(key, buf) { - return exports$2$1.publicEncrypt(key, buf, true); + // Copy static methods from Buffer + copyProps(Buffer, SafeBuffer); + SafeBuffer.from = function (arg, encodingOrOffset, length) { + if (typeof arg === "number") { + throw new TypeError("Argument must not be a number"); + } + return Buffer(arg, encodingOrOffset, length); }; - - exports$2$1.publicDecrypt = function publicDecrypt(key, buf) { - return exports$2$1.privateDecrypt(key, buf, true); + SafeBuffer.alloc = function (size, fill, encoding) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + var buf = Buffer(size); + if (fill !== undefined) { + if (typeof encoding === "string") { + buf.fill(fill, encoding); + } else { + buf.fill(fill); + } + } else { + buf.fill(0); + } + return buf; }; - - return exports$2$1; + SafeBuffer.allocUnsafe = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + return Buffer(size); + }; + SafeBuffer.allocUnsafeSlow = function (size) { + if (typeof size !== "number") { + throw new TypeError("Argument must be a number"); + } + return buffer.SlowBuffer(size); + }; + return exports$1b; } -var exports$1$1 = {}, - _dewExec$1$1 = false; +var exports$1a = {}, + _dewExec$19 = false; +function dew$19() { + if (_dewExec$19) return exports$1a; + _dewExec$19 = true; + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. -var _global$x = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + // NOTE: These type checking functions intentionally don't use `instanceof` + // because it is fragile and can be easily faked with `Object.create()`. -function dew$1$1() { - if (_dewExec$1$1) return exports$1$1; - _dewExec$1$1 = true; - var process = T$9; + function isArray(arg) { + if (Array.isArray) { + return Array.isArray(arg); + } + return objectToString(arg) === "[object Array]"; + } + exports$1a.isArray = isArray; + function isBoolean(arg) { + return typeof arg === "boolean"; + } + exports$1a.isBoolean = isBoolean; + function isNull(arg) { + return arg === null; + } + exports$1a.isNull = isNull; + function isNullOrUndefined(arg) { + return arg == null; + } + exports$1a.isNullOrUndefined = isNullOrUndefined; + function isNumber(arg) { + return typeof arg === "number"; + } + exports$1a.isNumber = isNumber; + function isString(arg) { + return typeof arg === "string"; + } + exports$1a.isString = isString; + function isSymbol(arg) { + return typeof arg === "symbol"; + } + exports$1a.isSymbol = isSymbol; + function isUndefined(arg) { + return arg === void 0; + } + exports$1a.isUndefined = isUndefined; + function isRegExp(re) { + return objectToString(re) === "[object RegExp]"; + } + exports$1a.isRegExp = isRegExp; + function isObject(arg) { + return typeof arg === "object" && arg !== null; + } + exports$1a.isObject = isObject; + function isDate(d) { + return objectToString(d) === "[object Date]"; + } + exports$1a.isDate = isDate; + function isError(e) { + return objectToString(e) === "[object Error]" || e instanceof Error; + } + exports$1a.isError = isError; + function isFunction(arg) { + return typeof arg === "function"; + } + exports$1a.isFunction = isFunction; + function isPrimitive(arg) { + return arg === null || typeof arg === "boolean" || typeof arg === "number" || typeof arg === "string" || typeof arg === "symbol" || + // ES6 symbol + typeof arg === "undefined"; + } + exports$1a.isPrimitive = isPrimitive; + exports$1a.isBuffer = dew$3J().Buffer.isBuffer; + function objectToString(o) { + return Object.prototype.toString.call(o); + } + return exports$1a; +} - function oldBrowser() { - throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11"); +var exports$19 = {}, + _dewExec$18 = false; +function dew$18() { + if (_dewExec$18) return exports$19; + _dewExec$18 = true; + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + var Buffer = dew$1a().Buffer; + var util = X$5; + function copyBuffer(src, target, offset) { + src.copy(target, offset); + } + exports$19 = function () { + function BufferList() { + _classCallCheck(this, BufferList); + this.head = null; + this.tail = null; + this.length = 0; + } + BufferList.prototype.push = function push(v) { + var entry = { + data: v, + next: null + }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + }; + BufferList.prototype.unshift = function unshift(v) { + var entry = { + data: v, + next: this.head + }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + }; + BufferList.prototype.shift = function shift() { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + }; + BufferList.prototype.clear = function clear() { + this.head = this.tail = null; + this.length = 0; + }; + BufferList.prototype.join = function join(s) { + if (this.length === 0) return ""; + var p = this.head; + var ret = "" + p.data; + while (p = p.next) { + ret += s + p.data; + } + return ret; + }; + BufferList.prototype.concat = function concat(n) { + if (this.length === 0) return Buffer.alloc(0); + var ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + copyBuffer(p.data, ret, i); + i += p.data.length; + p = p.next; + } + return ret; + }; + return BufferList; + }(); + if (util && util.inspect && util.inspect.custom) { + exports$19.prototype[util.inspect.custom] = function () { + var obj = util.inspect({ + length: this.length + }); + return this.constructor.name + " " + obj; + }; } + return exports$19; +} - var safeBuffer = dew$1T(); - - var randombytes = dew$1S(); +var exports$18 = {}, + _dewExec$17 = false; +function dew$17() { + if (_dewExec$17) return exports$18; + _dewExec$17 = true; + /**/ - var Buffer = safeBuffer.Buffer; - var kBufferMaxLength = safeBuffer.kMaxLength; - var crypto = _global$x.crypto || _global$x.msCrypto; - var kMaxUint32 = Math.pow(2, 32) - 1; + var pna = dew$1d(); + /**/ - function assertOffset(offset, length) { - if (typeof offset !== "number" || offset !== offset) { - // eslint-disable-line no-self-compare - throw new TypeError("offset must be a number"); + // undocumented cb() API, needed for core, not for public API + function destroy(err, cb) { + var _this = this; + var readableDestroyed = this._readableState && this._readableState.destroyed; + var writableDestroyed = this._writableState && this._writableState.destroyed; + if (readableDestroyed || writableDestroyed) { + if (cb) { + cb(err); + } else if (err) { + if (!this._writableState) { + pna.nextTick(emitErrorNT, this, err); + } else if (!this._writableState.errorEmitted) { + this._writableState.errorEmitted = true; + pna.nextTick(emitErrorNT, this, err); + } + } + return this; } - if (offset > kMaxUint32 || offset < 0) { - throw new TypeError("offset must be a uint32"); - } + // we set destroyed to true before firing error callbacks in order + // to make it re-entrance safe in case destroy() is called within callbacks - if (offset > kBufferMaxLength || offset > length) { - throw new RangeError("offset out of range"); + if (this._readableState) { + this._readableState.destroyed = true; } - } - function assertSize(size, offset, length) { - if (typeof size !== "number" || size !== size) { - // eslint-disable-line no-self-compare - throw new TypeError("size must be a number"); + // if this is a duplex stream mark the writable part as destroyed as well + if (this._writableState) { + this._writableState.destroyed = true; } - - if (size > kMaxUint32 || size < 0) { - throw new TypeError("size must be a uint32"); + this._destroy(err || null, function (err) { + if (!cb && err) { + if (!_this._writableState) { + pna.nextTick(emitErrorNT, _this, err); + } else if (!_this._writableState.errorEmitted) { + _this._writableState.errorEmitted = true; + pna.nextTick(emitErrorNT, _this, err); + } + } else if (cb) { + cb(err); + } + }); + return this; + } + function undestroy() { + if (this._readableState) { + this._readableState.destroyed = false; + this._readableState.reading = false; + this._readableState.ended = false; + this._readableState.endEmitted = false; } - - if (size + offset > length || size > kBufferMaxLength) { - throw new RangeError("buffer too small"); + if (this._writableState) { + this._writableState.destroyed = false; + this._writableState.ended = false; + this._writableState.ending = false; + this._writableState.finalCalled = false; + this._writableState.prefinished = false; + this._writableState.finished = false; + this._writableState.errorEmitted = false; } } - - if (crypto && crypto.getRandomValues || !process.browser) { - exports$1$1.randomFill = randomFill; - exports$1$1.randomFillSync = randomFillSync; - } else { - exports$1$1.randomFill = oldBrowser; - exports$1$1.randomFillSync = oldBrowser; + function emitErrorNT(self, err) { + self.emit("error", err); } + exports$18 = { + destroy: destroy, + undestroy: undestroy + }; + return exports$18; +} - function randomFill(buf, offset, size, cb) { - if (!Buffer.isBuffer(buf) && !(buf instanceof _global$x.Uint8Array)) { - throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); - } +var exports$17 = {}, + _dewExec$16 = false; +var _global$g = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$16() { + if (_dewExec$16) return exports$17; + _dewExec$16 = true; + var process$1 = process; + /**/ - if (typeof offset === "function") { - cb = offset; - offset = 0; - size = buf.length; - } else if (typeof size === "function") { - cb = size; - size = buf.length - offset; - } else if (typeof cb !== "function") { - throw new TypeError("\"cb\" argument must be a function"); - } + var pna = dew$1d(); + /**/ - assertOffset(offset, buf.length); - assertSize(size, offset, buf.length); - return actualFill(buf, offset, size, cb); - } + exports$17 = Writable; - function actualFill(buf, offset, size, cb) { - if (process.browser) { - var ourBuf = buf.buffer; - var uint = new Uint8Array(ourBuf, offset, size); - crypto.getRandomValues(uint); + // It seems a linked list but it is not + // there will be only 2 of these for each stream + function CorkedRequest(state) { + var _this = this; + this.next = null; + this.entry = null; + this.finish = function () { + onCorkedFinish(_this, state); + }; + } + /* */ - if (cb) { - process.nextTick(function () { - cb(null, buf); - }); - return; - } + /**/ + var asyncWrite = !process$1.browser && ["v0.10", "v0.9."].indexOf(process$1.version.slice(0, 5)) > -1 ? process$1.nextTick : pna.nextTick; + /**/ - return buf; - } + /**/ + var Duplex; + /**/ - if (cb) { - randombytes(size, function (err, bytes) { - if (err) { - return cb(err); - } + Writable.WritableState = WritableState; - bytes.copy(buf, offset); - cb(null, buf); - }); - return; - } + /**/ + var util = Object.create(dew$19()); + util.inherits = dew$3I(); + /**/ - var bytes = randombytes(size); - bytes.copy(buf, offset); - return buf; - } + /**/ + var internalUtil = { + deprecate: dew$3L() + }; + /**/ - function randomFillSync(buf, offset, size) { - if (typeof offset === "undefined") { - offset = 0; - } + /**/ + var Stream = dew$1b(); + /**/ - if (!Buffer.isBuffer(buf) && !(buf instanceof _global$x.Uint8Array)) { - throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); - } + /**/ - assertOffset(offset, buf.length); - if (size === undefined) size = buf.length - offset; - assertSize(size, offset, buf.length); - return actualFill(buf, offset, size); + var Buffer = dew$1a().Buffer; + var OurUint8Array = (typeof _global$g !== "undefined" ? _global$g : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function () {}; + function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); + } + function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; } - return exports$1$1; -} + /**/ -var exports$1V = {}, - _dewExec$1U = false; -function dew$1U() { - if (_dewExec$1U) return exports$1V; - _dewExec$1U = true; - exports$1V.randomBytes = exports$1V.rng = exports$1V.pseudoRandomBytes = exports$1V.prng = dew$1S(); - exports$1V.createHash = exports$1V.Hash = dew$1F(); - exports$1V.createHmac = exports$1V.Hmac = dew$1C(); + var destroyImpl = dew$17(); + util.inherits(Writable, Stream); + function nop() {} + function WritableState(options, stream) { + Duplex = Duplex || dew$15(); + options = options || {}; - var algos = dew$1B(); + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream. + // These options can be provided separately as readableXXX and writableXXX. + var isDuplex = stream instanceof Duplex; - var algoKeys = Object.keys(algos); - var hashes = ["sha1", "sha224", "sha256", "sha384", "sha512", "md5", "rmd160"].concat(algoKeys); + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; - exports$1V.getHashes = function () { - return hashes; - }; + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + var hwm = options.highWaterMark; + var writableHwm = options.writableHighWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (writableHwm || writableHwm === 0)) this.highWaterMark = writableHwm;else this.highWaterMark = defaultHwm; + + // cast to ints. + this.highWaterMark = Math.floor(this.highWaterMark); + + // if _final has been called + this.finalCalled = false; + + // drain event flag. + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; - var p = dew$1v(); + // has it been destroyed + this.destroyed = false; - exports$1V.pbkdf2 = p.pbkdf2; - exports$1V.pbkdf2Sync = p.pbkdf2Sync; + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; - var aes = dew$13(); + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || "utf8"; - exports$1V.Cipher = aes.Cipher; - exports$1V.createCipher = aes.createCipher; - exports$1V.Cipheriv = aes.Cipheriv; - exports$1V.createCipheriv = aes.createCipheriv; - exports$1V.Decipher = aes.Decipher; - exports$1V.createDecipher = aes.createDecipher; - exports$1V.Decipheriv = aes.Decipheriv; - exports$1V.createDecipheriv = aes.createDecipheriv; - exports$1V.getCiphers = aes.getCiphers; - exports$1V.listCiphers = aes.listCiphers; + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; - var dh = dew$Y$1(); + // a flag to see when we're in the middle of a write. + this.writing = false; - exports$1V.DiffieHellmanGroup = dh.DiffieHellmanGroup; - exports$1V.createDiffieHellmanGroup = dh.createDiffieHellmanGroup; - exports$1V.getDiffieHellman = dh.getDiffieHellman; - exports$1V.createDiffieHellman = dh.createDiffieHellman; - exports$1V.DiffieHellman = dh.DiffieHellman; + // when true all writes will be buffered until .uncork() call + this.corked = 0; - var sign = dew$b$1(); + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; - exports$1V.createSign = sign.createSign; - exports$1V.Sign = sign.Sign; - exports$1V.createVerify = sign.createVerify; - exports$1V.Verify = sign.Verify; - exports$1V.createECDH = dew$9$1(); + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; - var publicEncrypt = dew$2$1(); + // the callback that's passed to _write(chunk,cb) + this.onwrite = function (er) { + onwrite(stream, er); + }; - exports$1V.publicEncrypt = publicEncrypt.publicEncrypt; - exports$1V.privateEncrypt = publicEncrypt.privateEncrypt; - exports$1V.publicDecrypt = publicEncrypt.publicDecrypt; - exports$1V.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api. - // ;[ - // 'createCredentials' - // ].forEach(function (name) { - // exports[name] = function () { - // throw new Error([ - // 'sorry, ' + name + ' is not implemented yet', - // 'we accept pull requests', - // 'https://github.com/crypto-browserify/crypto-browserify' - // ].join('\n')) - // } - // }) + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; - var rf = dew$1$1(); + // the amount that is being written when _write is called. + this.writelen = 0; + this.bufferedRequest = null; + this.lastBufferedRequest = null; - exports$1V.randomFill = rf.randomFill; - exports$1V.randomFillSync = rf.randomFillSync; + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; - exports$1V.createCredentials = function () { - throw new Error(["sorry, createCredentials is not implemented yet", "we accept pull requests", "https://github.com/crypto-browserify/crypto-browserify"].join("\n")); - }; + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; - exports$1V.constants = { - "DH_CHECK_P_NOT_SAFE_PRIME": 2, - "DH_CHECK_P_NOT_PRIME": 1, - "DH_UNABLE_TO_CHECK_GENERATOR": 4, - "DH_NOT_SUITABLE_GENERATOR": 8, - "NPN_ENABLED": 1, - "ALPN_ENABLED": 1, - "RSA_PKCS1_PADDING": 1, - "RSA_SSLV23_PADDING": 2, - "RSA_NO_PADDING": 3, - "RSA_PKCS1_OAEP_PADDING": 4, - "RSA_X931_PADDING": 5, - "RSA_PKCS1_PSS_PADDING": 6, - "POINT_CONVERSION_COMPRESSED": 2, - "POINT_CONVERSION_UNCOMPRESSED": 4, - "POINT_CONVERSION_HYBRID": 6 + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; + + // count buffered requests + this.bufferedRequestCount = 0; + + // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two + this.corkedRequestsFree = new CorkedRequest(this); + } + WritableState.prototype.getBuffer = function getBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; }; - return exports$1V; -} + (function () { + try { + Object.defineProperty(WritableState.prototype, "buffer", { + get: internalUtil.deprecate(function () { + return this.getBuffer(); + }, "_writableState.buffer is deprecated. Use _writableState.getBuffer " + "instead.", "DEP0003") + }); + } catch (_) {} + })(); -var crypto = dew$1U(); + // Test _writableState for inheritance to account for Duplex streams, + // whose prototype chain only points to Readable. + var realHasInstance; + if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") { + realHasInstance = Function.prototype[Symbol.hasInstance]; + Object.defineProperty(Writable, Symbol.hasInstance, { + value: function (object) { + if (realHasInstance.call(this, object)) return true; + if (this !== Writable) return false; + return object && object._writableState instanceof WritableState; + } + }); + } else { + realHasInstance = function (object) { + return object instanceof this; + }; + } + function Writable(options) { + Duplex = Duplex || dew$15(); -crypto.Cipher; -crypto.Cipheriv; -crypto.Decipher; -crypto.Decipheriv; -crypto.DiffieHellman; -crypto.DiffieHellmanGroup; -crypto.Hash; -crypto.Hmac; -crypto.Sign; -crypto.Verify; -crypto.constants; -crypto.createCipher; -crypto.createCipheriv; -crypto.createCredentials; -crypto.createDecipher; -crypto.createDecipheriv; -crypto.createDiffieHellman; -crypto.createDiffieHellmanGroup; -crypto.createECDH; -crypto.createHash; -crypto.createHmac; -crypto.createSign; -crypto.createVerify; -crypto.getCiphers; -crypto.getDiffieHellman; -crypto.getHashes; -crypto.listCiphers; -crypto.pbkdf2; -crypto.pbkdf2Sync; -crypto.privateDecrypt; -crypto.privateEncrypt; -crypto.prng; -crypto.pseudoRandomBytes; -crypto.publicDecrypt; -crypto.publicEncrypt; -crypto.randomBytes; -crypto.randomFill; -crypto.randomFillSync; -crypto.rng; + // Writable ctor is applied to Duplexes, too. + // `realHasInstance` is necessary because using plain `instanceof` + // would return false, as no `_writableState` property is attached. -var exports$12 = {}, - _dewExec$11 = false; + // Trying to use the custom `instanceof` for Writable here will also break the + // Node.js LazyTransform implementation, which has a non-trivial getter for + // `_writableState` that would lead to infinite recursion. + if (!realHasInstance.call(Writable, this) && !(this instanceof Duplex)) { + return new Writable(options); + } + this._writableState = new WritableState(options, this); -var _global$a = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + // legacy. + this.writable = true; + if (options) { + if (typeof options.write === "function") this._write = options.write; + if (typeof options.writev === "function") this._writev = options.writev; + if (typeof options.destroy === "function") this._destroy = options.destroy; + if (typeof options.final === "function") this._final = options.final; + } + Stream.call(this); + } -function dew$11() { - if (_dewExec$11) return exports$12; - _dewExec$11 = true; - var r; + // Otherwise people can pipe Writable streams, which is just wrong. + Writable.prototype.pipe = function () { + this.emit("error", new Error("Cannot pipe, not readable")); + }; + function writeAfterEnd(stream, cb) { + var er = new Error("write after end"); + // TODO: defer error events consistently everywhere, not just the cb + stream.emit("error", er); + pna.nextTick(cb, er); + } - exports$12 = function rand(len) { - if (!r) r = new Rand(null); - return r.generate(len); + // Checks that a user-supplied chunk is valid, especially for the particular + // mode the stream is in. Currently this means that `null` is never accepted + // and undefined/non-string values are only allowed in object mode. + function validChunk(stream, state, chunk, cb) { + var valid = true; + var er = false; + if (chunk === null) { + er = new TypeError("May not write null values to stream"); + } else if (typeof chunk !== "string" && chunk !== undefined && !state.objectMode) { + er = new TypeError("Invalid non-string/buffer chunk"); + } + if (er) { + stream.emit("error", er); + pna.nextTick(cb, er); + valid = false; + } + return valid; + } + Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + var isBuf = !state.objectMode && _isUint8Array(chunk); + if (isBuf && !Buffer.isBuffer(chunk)) { + chunk = _uint8ArrayToBuffer(chunk); + } + if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + if (isBuf) encoding = "buffer";else if (!encoding) encoding = state.defaultEncoding; + if (typeof cb !== "function") cb = nop; + if (state.ended) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); + } + return ret; + }; + Writable.prototype.cork = function () { + var state = this._writableState; + state.corked++; }; + Writable.prototype.uncork = function () { + var state = this._writableState; + if (state.corked) { + state.corked--; + if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } + }; + Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === "string") encoding = encoding.toLowerCase(); + if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1)) throw new TypeError("Unknown encoding: " + encoding); + this._writableState.defaultEncoding = encoding; + return this; + }; + function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") { + chunk = Buffer.from(chunk, encoding); + } + return chunk; + } + Object.defineProperty(Writable.prototype, "writableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function () { + return this._writableState.highWaterMark; + } + }); - function Rand(rand) { - (this || _global$a).rand = rand; + // if we're already writing something, then just put this + // in the queue, and wait our turn. Otherwise, call _write + // If we return false, then we need a drain event, so set that flag. + function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { + if (!isBuf) { + var newChunk = decodeChunk(state, chunk, encoding); + if (chunk !== newChunk) { + isBuf = true; + encoding = "buffer"; + chunk = newChunk; + } + } + var len = state.objectMode ? 1 : chunk.length; + state.length += len; + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = { + chunk: chunk, + encoding: encoding, + isBuf: isBuf, + callback: cb, + next: null + }; + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + return ret; + } + function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } + function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) { + // defer the callback if we are being called synchronously + // to avoid piling up things on the stack + pna.nextTick(cb, er); + // this can emit finish, and it will always happen + // after error + pna.nextTick(finishMaybe, stream, state); + stream._writableState.errorEmitted = true; + stream.emit("error", er); + } else { + // the caller expect this to happen before if + // it is async + cb(er); + stream._writableState.errorEmitted = true; + stream.emit("error", er); + // this can emit finish, but finish must + // always follow error + finishMaybe(stream, state); + } + } + function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; + } + function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + onwriteStateUpdate(state); + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state); + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); + } + if (sync) { + /**/ + asyncWrite(afterWrite, stream, state, finished, cb); + /**/ + } else { + afterWrite(stream, state, finished, cb); + } + } + } + function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); } - exports$12.Rand = Rand; - - Rand.prototype.generate = function generate(len) { - return this._rand(len); - }; // Emulate crypto API using randy - - - Rand.prototype._rand = function _rand(n) { - if ((this || _global$a).rand.getBytes) return (this || _global$a).rand.getBytes(n); - var res = new Uint8Array(n); + // Must force callback to be called on nextTick, so that we don't + // emit 'drain' before the write() consumer gets the 'false' return + // value, and has a chance to attach a 'drain' listener. + function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit("drain"); + } + } - for (var i = 0; i < res.length; i++) res[i] = (this || _global$a).rand.getByte(); + // if there's something in the buffer waiting, then process it + function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + var count = 0; + var allBuffers = true; + while (entry) { + buffer[count] = entry; + if (!entry.isBuf) allBuffers = false; + entry = entry.next; + count += 1; + } + buffer.allBuffers = allBuffers; + doWrite(stream, state, true, state.length, buffer, "", holder.finish); - return res; + // doWrite is almost always async, defer these to save a bit of time + // as the hot path ends with doWrite + state.pendingcb++; + state.lastBufferedRequest = null; + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); + } + state.bufferedRequestCount = 0; + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + state.bufferedRequestCount--; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } + } + if (entry === null) state.lastBufferedRequest = null; + } + state.bufferedRequest = entry; + state.bufferProcessing = false; + } + Writable.prototype._write = function (chunk, encoding, cb) { + cb(new Error("_write() is not implemented")); }; + Writable.prototype._writev = null; + Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; + if (typeof chunk === "function") { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); - if (typeof self === "object") { - if (self.crypto && self.crypto.getRandomValues) { - // Modern browsers - Rand.prototype._rand = function _rand(n) { - var arr = new Uint8Array(n); - self.crypto.getRandomValues(arr); - return arr; - }; - } else if (self.msCrypto && self.msCrypto.getRandomValues) { - // IE - Rand.prototype._rand = function _rand(n) { - var arr = new Uint8Array(n); - self.msCrypto.getRandomValues(arr); - return arr; - }; // Safari's WebWorkers do not have `crypto` - - } else if (typeof window === "object") { - // Old junk - Rand.prototype._rand = function () { - throw new Error("Not implemented yet"); - }; + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); } - } else { - // Node.js or Web worker with no crypto support - try { - var crypto$1 = crypto; - if (typeof crypto$1.randomBytes !== "function") throw new Error("Not supported"); - Rand.prototype._rand = function _rand(n) { - return crypto$1.randomBytes(n); - }; - } catch (e) {} + // ignore unnecessary end() calls. + if (!state.ending) endWritable(this, state, cb); + }; + function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; } - - return exports$12; -} - -var exports$11 = {}, - _dewExec$10 = false; - -var _global$9 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$10() { - if (_dewExec$10) return exports$11; - _dewExec$10 = true; - - var bn = dew$1W(); - - var brorand = dew$11(); - - function MillerRabin(rand) { - (this || _global$9).rand = rand || new brorand.Rand(); + function callFinal(stream, state) { + stream._final(function (err) { + state.pendingcb--; + if (err) { + stream.emit("error", err); + } + state.prefinished = true; + stream.emit("prefinish"); + finishMaybe(stream, state); + }); + } + function prefinish(stream, state) { + if (!state.prefinished && !state.finalCalled) { + if (typeof stream._final === "function") { + state.pendingcb++; + state.finalCalled = true; + pna.nextTick(callFinal, stream, state); + } else { + state.prefinished = true; + stream.emit("prefinish"); + } + } + } + function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + prefinish(stream, state); + if (state.pendingcb === 0) { + state.finished = true; + stream.emit("finish"); + } + } + return need; + } + function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) pna.nextTick(cb);else stream.once("finish", cb); + } + state.ended = true; + stream.writable = false; } + function onCorkedFinish(corkReq, state, err) { + var entry = corkReq.entry; + corkReq.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } - exports$11 = MillerRabin; + // reuse the free corkReq. + state.corkedRequestsFree.next = corkReq; + } + Object.defineProperty(Writable.prototype, "destroyed", { + get: function () { + if (this._writableState === undefined) { + return false; + } + return this._writableState.destroyed; + }, + set: function (value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._writableState) { + return; + } - MillerRabin.create = function create(rand) { - return new MillerRabin(rand); + // backward compatibility, the user is explicitly + // managing destroyed + this._writableState.destroyed = value; + } + }); + Writable.prototype.destroy = destroyImpl.destroy; + Writable.prototype._undestroy = destroyImpl.undestroy; + Writable.prototype._destroy = function (err, cb) { + this.end(); + cb(err); }; + return exports$17; +} - MillerRabin.prototype._randbelow = function _randbelow(n) { - var len = n.bitLength(); - var min_bytes = Math.ceil(len / 8); // Generage random bytes until a number less than n is found. - // This ensures that 0..n-1 have an equal probability of being selected. - - do var a = new bn((this || _global$9).rand.generate(min_bytes)); while (a.cmp(n) >= 0); +var exports$16 = {}, + _dewExec$15 = false; +function dew$15() { + if (_dewExec$15) return exports$16; + _dewExec$15 = true; + /**/ - return a; - }; + var pna = dew$1d(); + /**/ - MillerRabin.prototype._randrange = function _randrange(start, stop) { - // Generate a random number greater than or equal to start and less than stop. - var size = stop.sub(start); - return start.add(this._randbelow(size)); + /**/ + var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) { + keys.push(key); + } + return keys; }; + /**/ - MillerRabin.prototype.test = function test(n, k, cb) { - var len = n.bitLength(); - var red = bn.mont(n); - var rone = new bn(1).toRed(red); - if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d; - - var n1 = n.subn(1); - - for (var s = 0; !n1.testn(s); s++) {} + exports$16 = Duplex; - var d = n.shrn(s); - var rn1 = n1.toRed(red); - var prime = true; + /**/ + var util = Object.create(dew$19()); + util.inherits = dew$3I(); + /**/ - for (; k > 0; k--) { - var a = this._randrange(new bn(2), n1); + var Readable = dew$14(); + var Writable = dew$16(); + util.inherits(Duplex, Readable); + { + // avoid scope creep, the keys array can then be collected + var keys = objectKeys(Writable.prototype); + for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + } + } + function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + Readable.call(this, options); + Writable.call(this, options); + if (options && options.readable === false) this.readable = false; + if (options && options.writable === false) this.writable = false; + this.allowHalfOpen = true; + if (options && options.allowHalfOpen === false) this.allowHalfOpen = false; + this.once("end", onend); + } + Object.defineProperty(Duplex.prototype, "writableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function () { + return this._writableState.highWaterMark; + } + }); - if (cb) cb(a); - var x = a.toRed(red).redPow(d); - if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue; + // the no-half-open enforcer + function onend() { + // if we allow half-open state, or if the writable side ended, + // then we're ok. + if (this.allowHalfOpen || this._writableState.ended) return; - for (var i = 1; i < s; i++) { - x = x.redSqr(); - if (x.cmp(rone) === 0) return false; - if (x.cmp(rn1) === 0) break; + // no more data can be written. + // But allow more writes to happen in this tick. + pna.nextTick(onEndNT, this); + } + function onEndNT(self) { + self.end(); + } + Object.defineProperty(Duplex.prototype, "destroyed", { + get: function () { + if (this._readableState === undefined || this._writableState === undefined) { + return false; + } + return this._readableState.destroyed && this._writableState.destroyed; + }, + set: function (value) { + // we ignore the value if the stream + // has not been initialized yet + if (this._readableState === undefined || this._writableState === undefined) { + return; } - if (i === s) return false; + // backward compatibility, the user is explicitly + // managing destroyed + this._readableState.destroyed = value; + this._writableState.destroyed = value; } - - return prime; + }); + Duplex.prototype._destroy = function (err, cb) { + this.push(null); + this.end(); + pna.nextTick(cb, err); }; + return exports$16; +} - MillerRabin.prototype.getDivisor = function getDivisor(n, k) { - var len = n.bitLength(); - var red = bn.mont(n); - var rone = new bn(1).toRed(red); - if (!k) k = Math.max(1, len / 48 | 0); // Find d and s, (n - 1) = (2 ^ s) * d; - - var n1 = n.subn(1); - - for (var s = 0; !n1.testn(s); s++) {} +var exports$15 = {}, + _dewExec$14 = false; +var _global$f = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$14() { + if (_dewExec$14) return exports$15; + _dewExec$14 = true; + var process$1 = process; + /**/ - var d = n.shrn(s); - var rn1 = n1.toRed(red); + var pna = dew$1d(); + /**/ - for (; k > 0; k--) { - var a = this._randrange(new bn(2), n1); + exports$15 = Readable; - var g = n.gcd(a); - if (g.cmpn(1) !== 0) return g; - var x = a.toRed(red).redPow(d); - if (x.cmp(rone) === 0 || x.cmp(rn1) === 0) continue; + /**/ + var isArray = dew$1c(); + /**/ - for (var i = 1; i < s; i++) { - x = x.redSqr(); - if (x.cmp(rone) === 0) return x.fromRed().subn(1).gcd(n); - if (x.cmp(rn1) === 0) break; - } + /**/ + var Duplex; + /**/ - if (i === s) { - x = x.redSqr(); - return x.fromRed().subn(1).gcd(n); - } - } + Readable.ReadableState = ReadableState; - return false; + /**/ + y$o.EventEmitter; + var EElistenerCount = function (emitter, type) { + return emitter.listeners(type).length; }; + /**/ - return exports$11; -} - -var exports$10 = {}, - _dewExec$$ = false; -function dew$$() { - if (_dewExec$$) return exports$10; - _dewExec$$ = true; - - var randomBytes = dew$2O(); - - exports$10 = findPrime; - findPrime.simpleSieve = simpleSieve; - findPrime.fermatTest = fermatTest; + /**/ + var Stream = dew$1b(); + /**/ - var BN = dew$1X(); + /**/ - var TWENTYFOUR = new BN(24); + var Buffer = dew$1a().Buffer; + var OurUint8Array = (typeof _global$f !== "undefined" ? _global$f : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function () {}; + function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); + } + function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + } - var MillerRabin = dew$10(); + /**/ - var millerRabin = new MillerRabin(); - var ONE = new BN(1); - var TWO = new BN(2); - var FIVE = new BN(5); - new BN(16); - new BN(8); - var TEN = new BN(10); - var THREE = new BN(3); - new BN(7); - var ELEVEN = new BN(11); - var FOUR = new BN(4); - new BN(12); - var primes = null; + /**/ + var util = Object.create(dew$19()); + util.inherits = dew$3I(); + /**/ - function _getPrimes() { - if (primes !== null) return primes; - var limit = 1048576; - var res = []; - res[0] = 2; + /**/ + var debugUtil = X$5; + var debug = void 0; + if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog("stream"); + } else { + debug = function () {}; + } + /**/ - for (var i = 1, k = 3; k < limit; k += 2) { - var sqrt = Math.ceil(Math.sqrt(k)); + var BufferList = dew$18(); + var destroyImpl = dew$17(); + var StringDecoder; + util.inherits(Readable, Stream); + var kProxyEvents = ["error", "close", "destroy", "pause", "resume"]; + function prependListener(emitter, event, fn) { + // Sadly this is not cacheable as some libraries bundle their own + // event emitter implementation with them. + if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn); - for (var j = 0; j < i && res[j] <= sqrt; j++) if (k % res[j] === 0) break; + // This is a hack to make sure that our error handler is attached before any + // userland ones. NEVER DO THIS. This is here only because this code needs + // to continue to work with older versions of Node.js that do not include + // the prependListener() method. The goal is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; + } + function ReadableState(options, stream) { + Duplex = Duplex || dew$15(); + options = options || {}; - if (i !== j && res[j] <= sqrt) continue; - res[i++] = k; - } + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream. + // These options can be provided separately as readableXXX and writableXXX. + var isDuplex = stream instanceof Duplex; - primes = res; - return res; - } + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; - function simpleSieve(p) { - var primes = _getPrimes(); + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + var hwm = options.highWaterMark; + var readableHwm = options.readableHighWaterMark; + var defaultHwm = this.objectMode ? 16 : 16 * 1024; + if (hwm || hwm === 0) this.highWaterMark = hwm;else if (isDuplex && (readableHwm || readableHwm === 0)) this.highWaterMark = readableHwm;else this.highWaterMark = defaultHwm; - for (var i = 0; i < primes.length; i++) if (p.modn(primes[i]) === 0) { - if (p.cmpn(primes[i]) === 0) { - return true; - } else { - return false; - } - } + // cast to ints. + this.highWaterMark = Math.floor(this.highWaterMark); - return true; - } + // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift() + this.buffer = new BufferList(); + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; - function fermatTest(p) { - var red = BN.mont(p); - return TWO.toRed(red).redPow(p.subn(1)).fromRed().cmpn(1) === 0; - } + // a flag to be able to tell if the event 'readable'/'data' is emitted + // immediately, or on a later tick. We set this to true at first, because + // any actions that shouldn't happen until "later" should generally also + // not happen before the first read call. + this.sync = true; - function findPrime(bits, gen) { - if (bits < 16) { - // this is what openssl does - if (gen === 2 || gen === 5) { - return new BN([140, 123]); - } else { - return new BN([140, 39]); - } - } + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + this.resumeScheduled = false; - gen = new BN(gen); - var num, n2; + // has it been destroyed + this.destroyed = false; - while (true) { - num = new BN(randomBytes(Math.ceil(bits / 8))); + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || "utf8"; - while (num.bitLength() > bits) { - num.ishrn(1); - } + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; - if (num.isEven()) { - num.iadd(ONE); - } + // if true, a maybeReadMore has been scheduled + this.readingMore = false; + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) StringDecoder = exports$3J.StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } + } + function Readable(options) { + Duplex = Duplex || dew$15(); + if (!(this instanceof Readable)) return new Readable(options); + this._readableState = new ReadableState(options, this); - if (!num.testn(1)) { - num.iadd(TWO); + // legacy + this.readable = true; + if (options) { + if (typeof options.read === "function") this._read = options.read; + if (typeof options.destroy === "function") this._destroy = options.destroy; + } + Stream.call(this); + } + Object.defineProperty(Readable.prototype, "destroyed", { + get: function () { + if (this._readableState === undefined) { + return false; + } + return this._readableState.destroyed; + }, + set: function (value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._readableState) { + return; } - if (!gen.cmp(TWO)) { - while (num.mod(TWENTYFOUR).cmp(ELEVEN)) { - num.iadd(FOUR); - } - } else if (!gen.cmp(FIVE)) { - while (num.mod(TEN).cmp(THREE)) { - num.iadd(FOUR); + // backward compatibility, the user is explicitly + // managing destroyed + this._readableState.destroyed = value; + } + }); + Readable.prototype.destroy = destroyImpl.destroy; + Readable.prototype._undestroy = destroyImpl.undestroy; + Readable.prototype._destroy = function (err, cb) { + this.push(null); + cb(err); + }; + + // Manually shove something into the read() buffer. + // This returns true if the highWaterMark has not been hit yet, + // similar to how Writable.write() returns true if you should + // write() some more. + Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; + var skipChunkCheck; + if (!state.objectMode) { + if (typeof chunk === "string") { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = Buffer.from(chunk, encoding); + encoding = ""; } + skipChunkCheck = true; } + } else { + skipChunkCheck = true; + } + return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); + }; - n2 = num.shrn(1); - - if (simpleSieve(n2) && simpleSieve(num) && fermatTest(n2) && fermatTest(num) && millerRabin.test(n2) && millerRabin.test(num)) { - return num; + // Unshift should *always* be something directly out of read() + Readable.prototype.unshift = function (chunk) { + return readableAddChunk(this, chunk, null, true, false); + }; + function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { + var state = stream._readableState; + if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else { + var er; + if (!skipChunkCheck) er = chunkInvalid(state, chunk); + if (er) { + stream.emit("error", er); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { + chunk = _uint8ArrayToBuffer(chunk); + } + if (addToFront) { + if (state.endEmitted) stream.emit("error", new Error("stream.unshift() after end event"));else addChunk(stream, state, chunk, true); + } else if (state.ended) { + stream.emit("error", new Error("stream.push() after EOF")); + } else { + state.reading = false; + if (state.decoder && !encoding) { + chunk = state.decoder.write(chunk); + if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); + } else { + addChunk(stream, state, chunk, false); + } + } + } else if (!addToFront) { + state.reading = false; } } + return needMoreData(state); } - - return exports$10; -} - -var _primes = { - "modp1": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a63a3620ffffffffffffffff" - }, - "modp2": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece65381ffffffffffffffff" - }, - "modp5": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca237327ffffffffffffffff" - }, - "modp14": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aacaa68ffffffffffffffff" - }, - "modp15": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a93ad2caffffffffffffffff" - }, - "modp16": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c934063199ffffffffffffffff" - }, - "modp17": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dcc4024ffffffffffffffff" - }, - "modp18": { - "gen": "02", - "prime": "ffffffffffffffffc90fdaa22168c234c4c6628b80dc1cd129024e088a67cc74020bbea63b139b22514a08798e3404ddef9519b3cd3a431b302b0a6df25f14374fe1356d6d51c245e485b576625e7ec6f44c42e9a637ed6b0bff5cb6f406b7edee386bfb5a899fa5ae9f24117c4b1fe649286651ece45b3dc2007cb8a163bf0598da48361c55d39a69163fa8fd24cf5f83655d23dca3ad961c62f356208552bb9ed529077096966d670c354e4abc9804f1746c08ca18217c32905e462e36ce3be39e772c180e86039b2783a2ec07a28fb5c55df06f4c52c9de2bcbf6955817183995497cea956ae515d2261898fa051015728e5a8aaac42dad33170d04507a33a85521abdf1cba64ecfb850458dbef0a8aea71575d060c7db3970f85a6e1e4c7abf5ae8cdb0933d71e8c94e04a25619dcee3d2261ad2ee6bf12ffa06d98a0864d87602733ec86a64521f2b18177b200cbbe117577a615d6c770988c0bad946e208e24fa074e5ab3143db5bfce0fd108e4b82d120a92108011a723c12a787e6d788719a10bdba5b2699c327186af4e23c1a946834b6150bda2583e9ca2ad44ce8dbbbc2db04de8ef92e8efc141fbecaa6287c59474e6bc05d99b2964fa090c3a2233ba186515be7ed1f612970cee2d7afb81bdd762170481cd0069127d5b05aa993b4ea988d8fddc186ffb7dc90a6c08f4df435c93402849236c3fab4d27c7026c1d4dcb2602646dec9751e763dba37bdf8ff9406ad9e530ee5db382f413001aeb06a53ed9027d831179727b0865a8918da3edbebcf9b14ed44ce6cbaced4bb1bdb7f1447e6cc254b332051512bd7af426fb8f401378cd2bf5983ca01c64b92ecf032ea15d1721d03f482d7ce6e74fef6d55e702f46980c82b5a84031900b1c9e59e7c97fbec7e8f323a97a7e36cc88be0f1d45b7ff585ac54bd407b22b4154aacc8f6d7ebf48e1d814cc5ed20f8037e0a79715eef29be32806a1d58bb7c5da76f550aa3d8a1fbff0eb19ccb1a313d55cda56c9ec2ef29632387fe8d76e3c0468043e8f663f4860ee12bf2d5b0b7474d6e694f91e6dbe115974a3926f12fee5e438777cb6a932df8cd8bec4d073b931ba3bc832b68d9dd300741fa7bf8afc47ed2576f6936ba424663aab639c5ae4f5683423b4742bf1c978238f16cbe39d652de3fdb8befc848ad922222e04a4037c0713eb57a81a23f0c73473fc646cea306b4bcbc8862f8385ddfa9d4b7fa2c087e879683303ed5bdd3a062b3cf5b3a278a66d2a13f83f44f82ddf310ee074ab6a364597e899a0255dc164f31cc50846851df9ab48195ded7ea1b1d510bd7ee74d73faf36bc31ecfa268359046f4eb879f924009438b481c6cd7889a002ed5ee382bc9190da6fc026e479558e4475677e9aa9e3050e2765694dfc81f56e880b96e7160c980dd98edd3dfffffffffffffffff" + function addChunk(stream, state, chunk, addToFront) { + if (state.flowing && state.length === 0 && !state.sync) { + stream.emit("data", chunk); + stream.read(0); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + if (state.needReadable) emitReadable(stream); } -}; - -var exports$$ = {}, - _dewExec$_ = false; + maybeReadMore(stream, state); + } + function chunkInvalid(state, chunk) { + var er; + if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== undefined && !state.objectMode) { + er = new TypeError("Invalid non-string/buffer chunk"); + } + return er; + } -var _global$8 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + // if it's past the high water mark, we can push in some more. + // Also, if we have no data yet, we can stand some + // more bytes. This is to work around cases where hwm=0, + // such as the repl. Also, if the push() triggered a + // readable event, and the user called read(largeNumber) such that + // needReadable was set, then we ought to push more, so that another + // 'readable' event will be triggered. + function needMoreData(state) { + return !state.ended && (state.needReadable || state.length < state.highWaterMark || state.length === 0); + } + Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; + }; -function dew$_() { - if (_dewExec$_) return exports$$; - _dewExec$_ = true; - var Buffer = buffer.Buffer; + // backwards compatibility. + Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = exports$3J.StringDecoder; + this._readableState.decoder = new StringDecoder(enc); + this._readableState.encoding = enc; + return this; + }; - var BN = dew$1X(); + // Don't raise the hwm > 8MB + var MAX_HWM = 8388608; + function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + n = MAX_HWM; + } else { + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; + } - var MillerRabin = dew$10(); + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function howMuchToRead(n, state) { + if (n <= 0 || state.length === 0 && state.ended) return 0; + if (state.objectMode) return 1; + if (n !== n) { + // Only flow one buffer at a time + if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; + } + // If we're asking for more than the current hwm, then raise the hwm. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + if (n <= state.length) return n; + // Don't have enough + if (!state.ended) { + state.needReadable = true; + return 0; + } + return state.length; + } - var millerRabin = new MillerRabin(); - var TWENTYFOUR = new BN(24); - var ELEVEN = new BN(11); - var TEN = new BN(10); - var THREE = new BN(3); - var SEVEN = new BN(7); + // you can override either this method, or the async _read(n) below. + Readable.prototype.read = function (n) { + debug("read", n); + n = parseInt(n, 10); + var state = this._readableState; + var nOrig = n; + if (n !== 0) state.emittedReadable = false; - var primes = dew$$(); + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && (state.length >= state.highWaterMark || state.ended)) { + debug("read: emitReadable", state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; + } + n = howMuchToRead(n, state); - var randomBytes = dew$2O(); + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; + } - exports$$ = DH; + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. - function setPublicKey(pub, enc) { - enc = enc || "utf8"; + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug("need readable", doRead); - if (!Buffer.isBuffer(pub)) { - pub = new Buffer(pub, enc); + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug("length less than watermark", doRead); } - (this || _global$8)._pub = new BN(pub); - return this || _global$8; - } - - function setPrivateKey(priv, enc) { - enc = enc || "utf8"; + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug("reading or ended", doRead); + } else if (doRead) { + debug("do read"); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (!state.reading) n = howMuchToRead(nOrig, state); + } + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; + if (ret === null) { + state.needReadable = true; + n = 0; + } else { + state.length -= n; + } + if (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!state.ended) state.needReadable = true; - if (!Buffer.isBuffer(priv)) { - priv = new Buffer(priv, enc); + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended) endReadable(this); + } + if (ret !== null) this.emit("data", ret); + return ret; + }; + function onEofChunk(stream, state) { + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } } + state.ended = true; - (this || _global$8)._priv = new BN(priv); - return this || _global$8; + // emit 'readable' now to make sure it gets picked up. + emitReadable(stream); } - var primeCache = {}; - - function checkPrime(prime, generator) { - var gen = generator.toString("hex"); - var hex = [gen, prime.toString(16)].join("_"); - - if (hex in primeCache) { - return primeCache[hex]; + // Don't emit readable right away in sync mode, because this can trigger + // another read() call => stack overflow. This way, it might trigger + // a nextTick recursion warning, but that's not so bad. + function emitReadable(stream) { + var state = stream._readableState; + state.needReadable = false; + if (!state.emittedReadable) { + debug("emitReadable", state.flowing); + state.emittedReadable = true; + if (state.sync) pna.nextTick(emitReadable_, stream);else emitReadable_(stream); } + } + function emitReadable_(stream) { + debug("emit readable"); + stream.emit("readable"); + flow(stream); + } - var error = 0; - - if (prime.isEven() || !primes.simpleSieve || !primes.fermatTest(prime) || !millerRabin.test(prime)) { - //not a prime so +1 - error += 1; + // at this point, the user has presumably seen the 'readable' event, + // and called read() to consume some data. that may have triggered + // in turn another _read(n) call, in which case reading = true if + // it's in progress. + // However, if we're not ended, or reading, and the length < hwm, + // then go ahead and try to read some more preemptively. + function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + pna.nextTick(maybeReadMore_, stream, state); + } + } + function maybeReadMore_(stream, state) { + var len = state.length; + while (!state.reading && !state.flowing && !state.ended && state.length < state.highWaterMark) { + debug("maybeReadMore read 0"); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break;else len = state.length; + } + state.readingMore = false; + } - if (gen === "02" || gen === "05") { - // we'd be able to check the generator - // it would fail so +8 - error += 8; - } else { - //we wouldn't be able to test the generator - // so +4 - error += 4; + // abstract method. to be overridden in specific implementation classes. + // call cb(er, data) where data is <= n in length. + // for virtual (non-string, non-buffer) streams, "length" is somewhat + // arbitrary, and perhaps not very meaningful. + Readable.prototype._read = function (n) { + this.emit("error", new Error("_read() is not implemented")); + }; + Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts); + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process$1.stdout && dest !== process$1.stderr; + var endFn = doEnd ? onend : unpipe; + if (state.endEmitted) pna.nextTick(endFn);else src.once("end", endFn); + dest.on("unpipe", onunpipe); + function onunpipe(readable, unpipeInfo) { + debug("onunpipe"); + if (readable === src) { + if (unpipeInfo && unpipeInfo.hasUnpiped === false) { + unpipeInfo.hasUnpiped = true; + cleanup(); + } } - - primeCache[hex] = error; - return error; } - - if (!millerRabin.test(prime.shrn(1))) { - //not a safe prime - error += 2; + function onend() { + debug("onend"); + dest.end(); } - var rem; + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on("drain", ondrain); + var cleanedUp = false; + function cleanup() { + debug("cleanup"); + // cleanup event handlers once the pipe is broken + dest.removeListener("close", onclose); + dest.removeListener("finish", onfinish); + dest.removeListener("drain", ondrain); + dest.removeListener("error", onerror); + dest.removeListener("unpipe", onunpipe); + src.removeListener("end", onend); + src.removeListener("end", unpipe); + src.removeListener("data", ondata); + cleanedUp = true; - switch (gen) { - case "02": - if (prime.mod(TWENTYFOUR).cmp(ELEVEN)) { - // unsuidable generator - error += 8; + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + + // If the user pushes more data while we're writing to dest then we'll end up + // in ondata again. However, we only want to increase awaitDrain once because + // dest will only emit one 'drain' event for the multiple writes. + // => Introduce a guard on increasing awaitDrain. + var increasedAwaitDrain = false; + src.on("data", ondata); + function ondata(chunk) { + debug("ondata"); + increasedAwaitDrain = false; + var ret = dest.write(chunk); + if (false === ret && !increasedAwaitDrain) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { + debug("false write response, pause", state.awaitDrain); + state.awaitDrain++; + increasedAwaitDrain = true; } + src.pause(); + } + } - break; + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug("onerror", er); + unpipe(); + dest.removeListener("error", onerror); + if (EElistenerCount(dest, "error") === 0) dest.emit("error", er); + } - case "05": - rem = prime.mod(TEN); + // Make sure our error handler is attached before userland ones. + prependListener(dest, "error", onerror); - if (rem.cmp(THREE) && rem.cmp(SEVEN)) { - // prime mod 10 needs to equal 3 or 7 - error += 8; - } + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener("finish", onfinish); + unpipe(); + } + dest.once("close", onclose); + function onfinish() { + debug("onfinish"); + dest.removeListener("close", onclose); + unpipe(); + } + dest.once("finish", onfinish); + function unpipe() { + debug("unpipe"); + src.unpipe(dest); + } - break; + // tell the dest that it's being piped to + dest.emit("pipe", src); - default: - error += 4; + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug("pipe resume"); + src.resume(); } - - primeCache[hex] = error; - return error; + return dest; + }; + function pipeOnDrain(src) { + return function () { + var state = src._readableState; + debug("pipeOnDrain", state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, "data")) { + state.flowing = true; + flow(src); + } + }; } + Readable.prototype.unpipe = function (dest) { + var state = this._readableState; + var unpipeInfo = { + hasUnpiped: false + }; - function DH(prime, generator, malleable) { - this.setGenerator(generator); - (this || _global$8).__prime = new BN(prime); - (this || _global$8)._prime = BN.mont((this || _global$8).__prime); - (this || _global$8)._primeLen = prime.length; - (this || _global$8)._pub = undefined; - (this || _global$8)._priv = undefined; - (this || _global$8)._primeCode = undefined; + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) return this; - if (malleable) { - (this || _global$8).setPublicKey = setPublicKey; - (this || _global$8).setPrivateKey = setPrivateKey; - } else { - (this || _global$8)._primeCode = 8; + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; + if (!dest) dest = state.pipes; + + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit("unpipe", this, unpipeInfo); + return this; } - } - Object.defineProperty(DH.prototype, "verifyError", { - enumerable: true, - get: function () { - if (typeof (this || _global$8)._primeCode !== "number") { - (this || _global$8)._primeCode = checkPrime((this || _global$8).__prime, (this || _global$8).__gen); + // slow case. multiple pipe destinations. + + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + for (var i = 0; i < len; i++) { + dests[i].emit("unpipe", this, { + hasUnpiped: false + }); } - - return (this || _global$8)._primeCode; - } - }); - - DH.prototype.generateKeys = function () { - if (!(this || _global$8)._priv) { - (this || _global$8)._priv = new BN(randomBytes((this || _global$8)._primeLen)); + return this; } - (this || _global$8)._pub = (this || _global$8)._gen.toRed((this || _global$8)._prime).redPow((this || _global$8)._priv).fromRed(); - return this.getPublicKey(); + // try to find the right one. + var index = indexOf(state.pipes, dest); + if (index === -1) return this; + state.pipes.splice(index, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; + dest.emit("unpipe", this, unpipeInfo); + return this; }; - DH.prototype.computeSecret = function (other) { - other = new BN(other); - other = other.toRed((this || _global$8)._prime); - var secret = other.redPow((this || _global$8)._priv).fromRed(); - var out = new Buffer(secret.toArray()); - var prime = this.getPrime(); - - if (out.length < prime.length) { - var front = new Buffer(prime.length - out.length); - front.fill(0); - out = Buffer.concat([front, out]); + // set up data events if they are asked for + // Ensure readable listeners eventually get something + Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + if (ev === "data") { + // Start flowing on next tick if stream isn't explicitly paused + if (this._readableState.flowing !== false) this.resume(); + } else if (ev === "readable") { + var state = this._readableState; + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; + state.emittedReadable = false; + if (!state.reading) { + pna.nextTick(nReadingNextTick, this); + } else if (state.length) { + emitReadable(this); + } + } } - - return out; + return res; }; + Readable.prototype.addListener = Readable.prototype.on; + function nReadingNextTick(self) { + debug("readable nexttick read 0"); + self.read(0); + } - DH.prototype.getPublicKey = function getPublicKey(enc) { - return formatReturnValue((this || _global$8)._pub, enc); + // pause() and resume() are remnants of the legacy readable stream API + // If the user uses them, then switch into old mode. + Readable.prototype.resume = function () { + var state = this._readableState; + if (!state.flowing) { + debug("resume"); + state.flowing = true; + resume(this, state); + } + return this; }; - - DH.prototype.getPrivateKey = function getPrivateKey(enc) { - return formatReturnValue((this || _global$8)._priv, enc); + function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + pna.nextTick(resume_, stream, state); + } + } + function resume_(stream, state) { + if (!state.reading) { + debug("resume read 0"); + stream.read(0); + } + state.resumeScheduled = false; + state.awaitDrain = 0; + stream.emit("resume"); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); + } + Readable.prototype.pause = function () { + debug("call pause flowing=%j", this._readableState.flowing); + if (false !== this._readableState.flowing) { + debug("pause"); + this._readableState.flowing = false; + this.emit("pause"); + } + return this; }; + function flow(stream) { + var state = stream._readableState; + debug("flow", state.flowing); + while (state.flowing && stream.read() !== null) {} + } - DH.prototype.getPrime = function (enc) { - return formatReturnValue((this || _global$8).__prime, enc); - }; + // wrap an old-style stream as the async data source. + // This is *not* part of the readable stream interface. + // It is an ugly unfortunate mess of history. + Readable.prototype.wrap = function (stream) { + var _this = this; + var state = this._readableState; + var paused = false; + stream.on("end", function () { + debug("wrapped end"); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) _this.push(chunk); + } + _this.push(null); + }); + stream.on("data", function (chunk) { + debug("wrapped data"); + if (state.decoder) chunk = state.decoder.write(chunk); - DH.prototype.getGenerator = function (enc) { - return formatReturnValue((this || _global$8)._gen, enc); - }; + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + var ret = _this.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); - DH.prototype.setGenerator = function (gen, enc) { - enc = enc || "utf8"; + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === "function") { + this[i] = function (method) { + return function () { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } - if (!Buffer.isBuffer(gen)) { - gen = new Buffer(gen, enc); + // proxy certain important events. + for (var n = 0; n < kProxyEvents.length; n++) { + stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n])); } - (this || _global$8).__gen = gen; - (this || _global$8)._gen = new BN(gen); - return this || _global$8; + // when we try to consume some more bytes, simply unpause the + // underlying stream. + this._read = function (n) { + debug("wrapped _read", n); + if (paused) { + paused = false; + stream.resume(); + } + }; + return this; }; + Object.defineProperty(Readable.prototype, "readableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function () { + return this._readableState.highWaterMark; + } + }); - function formatReturnValue(bn, enc) { - var buf = new Buffer(bn.toArray()); + // exposed for testing purposes only. + Readable._fromList = fromList; - if (!enc) { - return buf; + // Pluck off n bytes from an array of buffers. + // Length is the combined lengths of all the buffers in the list. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function fromList(n, state) { + // nothing buffered + if (state.length === 0) return null; + var ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // read it all, truncate the list + if (state.decoder) ret = state.buffer.join("");else if (state.buffer.length === 1) ret = state.buffer.head.data;else ret = state.buffer.concat(state.length); + state.buffer.clear(); } else { - return buf.toString(enc); + // read part of list + ret = fromListPartial(n, state.buffer, state.decoder); } + return ret; } - return exports$$; -} - -var exports$_ = {}, - _dewExec$Z = false; -function dew$Z() { - if (_dewExec$Z) return exports$_; - _dewExec$Z = true; - var Buffer = buffer.Buffer; - - var generatePrime = dew$$(); - - var primes = _primes; - - var DH = dew$_(); - - function getDiffieHellman(mod) { - var prime = new Buffer(primes[mod].prime, "hex"); - var gen = new Buffer(primes[mod].gen, "hex"); - return new DH(prime, gen); + // Extracts only enough buffered data to satisfy the amount requested. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function fromListPartial(n, list, hasStrings) { + var ret; + if (n < list.head.data.length) { + // slice is the same for buffers and strings + ret = list.head.data.slice(0, n); + list.head.data = list.head.data.slice(n); + } else if (n === list.head.data.length) { + // first chunk is a perfect match + ret = list.shift(); + } else { + // result spans more than one buffer + ret = hasStrings ? copyFromBufferString(n, list) : copyFromBuffer(n, list); + } + return ret; } - var ENCODINGS = { - "binary": true, - "hex": true, - "base64": true - }; - - function createDiffieHellman(prime, enc, generator, genc) { - if (Buffer.isBuffer(enc) || ENCODINGS[enc] === undefined) { - return createDiffieHellman(prime, "binary", enc, generator); + // Copies a specified amount of characters from the list of buffered data + // chunks. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function copyFromBufferString(n, list) { + var p = list.head; + var c = 1; + var ret = p.data; + n -= ret.length; + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) list.head = p.next;else list.head = list.tail = null; + } else { + list.head = p; + p.data = str.slice(nb); + } + break; + } + ++c; } + list.length -= c; + return ret; + } - enc = enc || "binary"; - genc = genc || "binary"; - generator = generator || new Buffer([2]); - - if (!Buffer.isBuffer(generator)) { - generator = new Buffer(generator, genc); + // Copies a specified amount of bytes from the list of buffered data chunks. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function copyFromBuffer(n, list) { + var ret = Buffer.allocUnsafe(n); + var p = list.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) list.head = p.next;else list.head = list.tail = null; + } else { + list.head = p; + p.data = buf.slice(nb); + } + break; + } + ++c; } + list.length -= c; + return ret; + } + function endReadable(stream) { + var state = stream._readableState; - if (typeof prime === "number") { - return new DH(generatePrime(prime, generator), generator, true); + // If we get here before consuming all the bytes, then that is a + // bug in node. Should never happen. + if (state.length > 0) throw new Error("\"endReadable()\" called on non-empty stream"); + if (!state.endEmitted) { + state.ended = true; + pna.nextTick(endReadableNT, state, stream); } - - if (!Buffer.isBuffer(prime)) { - prime = new Buffer(prime, enc); + } + function endReadableNT(state, stream) { + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit("end"); } - - return new DH(prime, generator, true); } - - exports$_.DiffieHellmanGroup = exports$_.createDiffieHellmanGroup = exports$_.getDiffieHellman = getDiffieHellman; - exports$_.createDiffieHellman = exports$_.DiffieHellman = createDiffieHellman; - return exports$_; + function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; + } + return exports$15; } -var exports$Z = {}, - _dewExec$Y = false; -function dew$Y() { - if (_dewExec$Y) return exports$Z; - _dewExec$Y = true; - - /*! safe-buffer. MIT License. Feross Aboukhadijeh */ +var exports$14 = {}, + _dewExec$13 = false; +function dew$13() { + if (_dewExec$13) return exports$14; + _dewExec$13 = true; + exports$14 = Transform; + var Duplex = dew$15(); - /* eslint-disable node/no-deprecated-api */ - var buffer$1 = buffer; - var Buffer = buffer$1.Buffer; // alternative to using Object.keys for old browsers + /**/ + var util = Object.create(dew$19()); + util.inherits = dew$3I(); + /**/ - function copyProps(src, dst) { - for (var key in src) { - dst[key] = src[key]; + util.inherits(Transform, Duplex); + function afterTransform(er, data) { + var ts = this._transformState; + ts.transforming = false; + var cb = ts.writecb; + if (!cb) { + return this.emit("error", new Error("write callback called multiple times")); + } + ts.writechunk = null; + ts.writecb = null; + if (data != null) + // single equals check for both `null` and `undefined` + this.push(data); + cb(er); + var rs = this._readableState; + rs.reading = false; + if (rs.needReadable || rs.length < rs.highWaterMark) { + this._read(rs.highWaterMark); } } + function Transform(options) { + if (!(this instanceof Transform)) return new Transform(options); + Duplex.call(this, options); + this._transformState = { + afterTransform: afterTransform.bind(this), + needTransform: false, + transforming: false, + writecb: null, + writechunk: null, + writeencoding: null + }; - if (Buffer.from && Buffer.alloc && Buffer.allocUnsafe && Buffer.allocUnsafeSlow) { - exports$Z = buffer$1; - } else { - // Copy properties from require('buffer') - copyProps(buffer$1, exports$Z); - exports$Z.Buffer = SafeBuffer; - } - - function SafeBuffer(arg, encodingOrOffset, length) { - return Buffer(arg, encodingOrOffset, length); - } - - SafeBuffer.prototype = Object.create(Buffer.prototype); // Copy static methods from Buffer - - copyProps(Buffer, SafeBuffer); + // start out asking for a readable event once data is transformed. + this._readableState.needReadable = true; - SafeBuffer.from = function (arg, encodingOrOffset, length) { - if (typeof arg === "number") { - throw new TypeError("Argument must not be a number"); + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + if (options) { + if (typeof options.transform === "function") this._transform = options.transform; + if (typeof options.flush === "function") this._flush = options.flush; } - return Buffer(arg, encodingOrOffset, length); + // When the writable side finishes, then flush out anything remaining. + this.on("prefinish", prefinish); + } + function prefinish() { + var _this = this; + if (typeof this._flush === "function") { + this._flush(function (er, data) { + done(_this, er, data); + }); + } else { + done(this, null, null); + } + } + Transform.prototype.push = function (chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); }; - SafeBuffer.alloc = function (size, fill, encoding) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); + // This is the part where you do stuff! + // override this function in implementation classes. + // 'chunk' is an input chunk. + // + // Call `push(newChunk)` to pass along transformed output + // to the readable side. You may call 'push' zero or more times. + // + // Call `cb(err)` when you are done with this chunk. If you pass + // an error, then that'll put the hurt on the whole operation. If you + // never call cb(), then you'll never get another chunk. + Transform.prototype._transform = function (chunk, encoding, cb) { + throw new Error("_transform() is not implemented"); + }; + Transform.prototype._write = function (chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); } + }; - var buf = Buffer(size); - - if (fill !== undefined) { - if (typeof encoding === "string") { - buf.fill(fill, encoding); - } else { - buf.fill(fill); - } + // Doesn't matter what the args are here. + // _transform does all the work. + // That we got here means that the readable side wants more data. + Transform.prototype._read = function (n) { + var ts = this._transformState; + if (ts.writechunk !== null && ts.writecb && !ts.transforming) { + ts.transforming = true; + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); } else { - buf.fill(0); + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; } - - return buf; }; + Transform.prototype._destroy = function (err, cb) { + var _this2 = this; + Duplex.prototype._destroy.call(this, err, function (err2) { + cb(err2); + _this2.emit("close"); + }); + }; + function done(stream, er, data) { + if (er) return stream.emit("error", er); + if (data != null) + // single equals check for both `null` and `undefined` + stream.push(data); - SafeBuffer.allocUnsafe = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + if (stream._writableState.length) throw new Error("Calling transform done when ws.length != 0"); + if (stream._transformState.transforming) throw new Error("Calling transform done when still transforming"); + return stream.push(null); + } + return exports$14; +} - return Buffer(size); - }; +var exports$13 = {}, + _dewExec$12 = false; +function dew$12() { + if (_dewExec$12) return exports$13; + _dewExec$12 = true; + exports$13 = PassThrough; + var Transform = dew$13(); - SafeBuffer.allocUnsafeSlow = function (size) { - if (typeof size !== "number") { - throw new TypeError("Argument must be a number"); - } + /**/ + var util = Object.create(dew$19()); + util.inherits = dew$3I(); + /**/ - return buffer$1.SlowBuffer(size); + util.inherits(PassThrough, Transform); + function PassThrough(options) { + if (!(this instanceof PassThrough)) return new PassThrough(options); + Transform.call(this, options); + } + PassThrough.prototype._transform = function (chunk, encoding, cb) { + cb(null, chunk); }; + return exports$13; +} - return exports$Z; +var exports$12 = {}, + _dewExec$11 = false; +function dew$11() { + if (_dewExec$11) return exports$12; + _dewExec$11 = true; + exports$12 = exports$12 = dew$14(); + exports$12.Stream = exports$12; + exports$12.Readable = exports$12; + exports$12.Writable = dew$16(); + exports$12.Duplex = dew$15(); + exports$12.Transform = dew$13(); + exports$12.PassThrough = dew$12(); + return exports$12; } -var exports$Y = {}, - _dewExec$X = false; +var exports$11 = {}, + _dewExec$10 = false; var module$4 = { - exports: exports$Y + exports: exports$11 }; - -var _global$7 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$X() { - if (_dewExec$X) return module$4.exports; - _dewExec$X = true; - +var _global$e = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$10() { + if (_dewExec$10) return module$4.exports; + _dewExec$10 = true; (function (module, exports) { + // Utils function assert(val, msg) { if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. - + } + // Could use `inherits` module, but don't want to move from single file + // architecture yet. function inherits(ctor, superCtor) { ctor.super_ = superCtor; - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; - } // BN + } + // BN function BN(number, base, endian) { if (BN.isBN(number)) { return number; } + (this || _global$e).negative = 0; + (this || _global$e).words = null; + (this || _global$e).length = 0; - (this || _global$7).negative = 0; - (this || _global$7).words = null; - (this || _global$7).length = 0; // Reduction context - - (this || _global$7).red = null; - + // Reduction context + (this || _global$e).red = null; if (number !== null) { if (base === "le" || base === "be") { endian = base; base = 10; } - this._init(number || 0, base || 10, endian || "be"); } } - if (typeof module === "object") { module.exports = BN; } else { exports.BN = BN; } - BN.BN = BN; BN.wordSize = 26; var Buffer; - try { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = buffer.Buffer; + Buffer = dew$3J().Buffer; } } catch (e) {} - BN.isBN = function isBN(num) { if (num instanceof BN) { return true; } - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); }; - BN.max = function max(left, right) { if (left.cmp(right) > 0) return left; return right; }; - BN.min = function min(left, right) { if (left.cmp(right) < 0) return left; return right; }; - BN.prototype._init = function init(number, base, endian) { if (typeof number === "number") { return this._initNumber(number, base, endian); } - if (typeof number === "object") { return this._initArray(number, base, endian); } - if (base === "hex") { base = 16; } - assert(base === (base | 0) && base >= 2 && base <= 36); number = number.toString().replace(/\s+/g, ""); var start = 0; - if (number[0] === "-") { start++; - (this || _global$7).negative = 1; + (this || _global$e).negative = 1; } - if (start < number.length) { if (base === 16) { this._parseHex(number, start, endian); } else { this._parseBase(number, base, start); - if (endian === "le") { this._initArray(this.toArray(), base, endian); } } } }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$7).negative = 1; + (this || _global$e).negative = 1; number = -number; } - if (number < 67108864) { - (this || _global$7).words = [number & 67108863]; - (this || _global$7).length = 1; + (this || _global$e).words = [number & 67108863]; + (this || _global$e).length = 1; } else if (number < 4503599627370496) { - (this || _global$7).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$7).length = 2; + (this || _global$e).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$e).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - - (this || _global$7).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$7).length = 3; + (this || _global$e).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$e).length = 3; } + if (endian !== "le") return; - if (endian !== "le") return; // Reverse the bytes - + // Reverse the bytes this._initArray(this.toArray(), base, endian); }; - BN.prototype._initArray = function _initArray(number, base, endian) { // Perhaps a Uint8Array assert(typeof number.length === "number"); - if (number.length <= 0) { - (this || _global$7).words = [0]; - (this || _global$7).length = 1; - return this || _global$7; + (this || _global$e).words = [0]; + (this || _global$e).length = 1; + return this || _global$e; } - - (this || _global$7).length = Math.ceil(number.length / 3); - (this || _global$7).words = new Array((this || _global$7).length); - - for (var i = 0; i < (this || _global$7).length; i++) { - (this || _global$7).words[i] = 0; + (this || _global$e).length = Math.ceil(number.length / 3); + (this || _global$e).words = new Array((this || _global$e).length); + for (var i = 0; i < (this || _global$e).length; i++) { + (this || _global$e).words[i] = 0; } - var j, w; var off = 0; - if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$7).words[j] |= w << off & 67108863; - (this || _global$7).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$e).words[j] |= w << off & 67108863; + (this || _global$e).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; @@ -52028,219 +88579,190 @@ function dew$X() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$7).words[j] |= w << off & 67108863; - (this || _global$7).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$e).words[j] |= w << off & 67108863; + (this || _global$e).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; } } } - return this._strip(); }; - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // '0' - '9' - + var c = string.charCodeAt(index); + // '0' - '9' if (c >= 48 && c <= 57) { - return c - 48; // 'A' - 'F' + return c - 48; + // 'A' - 'F' } else if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' + return c - 55; + // 'a' - 'f' } else if (c >= 97 && c <= 102) { return c - 87; } else { assert(false, "Invalid character in " + string); } } - function parseHexByte(string, lowerBound, index) { var r = parseHex4Bits(string, index); - if (index - 1 >= lowerBound) { r |= parseHex4Bits(string, index - 1) << 4; } - return r; } - BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$7).length = Math.ceil((number.length - start) / 6); - (this || _global$7).words = new Array((this || _global$7).length); - - for (var i = 0; i < (this || _global$7).length; i++) { - (this || _global$7).words[i] = 0; - } // 24-bits chunks - + (this || _global$e).length = Math.ceil((number.length - start) / 6); + (this || _global$e).words = new Array((this || _global$e).length); + for (var i = 0; i < (this || _global$e).length; i++) { + (this || _global$e).words[i] = 0; + } + // 24-bits chunks var off = 0; var j = 0; var w; - if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$7).words[j] |= w & 67108863; - + (this || _global$e).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$7).words[j] |= w >>> 26; + (this || _global$e).words[j] |= w >>> 26; } else { off += 8; } } } else { var parseLength = number.length - start; - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$7).words[j] |= w & 67108863; - + (this || _global$e).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$7).words[j] |= w >>> 26; + (this || _global$e).words[j] |= w >>> 26; } else { off += 8; } } } - this._strip(); }; - function parseBase(str, start, end, mul) { var r = 0; var b = 0; var len = Math.min(str.length, end); - for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + r *= mul; + // 'a' if (c >= 49) { - b = c - 49 + 10; // 'A' + b = c - 49 + 10; + + // 'A' } else if (c >= 17) { - b = c - 17 + 10; // '0' - '9' + b = c - 17 + 10; + + // '0' - '9' } else { b = c; } - assert(c >= 0 && b < mul, "Invalid character"); r += b; } - return r; } - BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$7).words = [0]; - (this || _global$7).length = 1; // Find length of limb in base + (this || _global$e).words = [0]; + (this || _global$e).length = 1; + // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; } - limbLen--; limbPow = limbPow / base | 0; var total = number.length - start; var mod = total % limbLen; var end = Math.min(total, total - mod) + start; var word = 0; - for (var i = start; i < end; i += limbLen) { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - - if ((this || _global$7).words[0] + word < 67108864) { - (this || _global$7).words[0] += word; + if ((this || _global$e).words[0] + word < 67108864) { + (this || _global$e).words[0] += word; } else { this._iaddn(word); } } - if (mod !== 0) { var pow = 1; word = parseBase(number, i, number.length, base); - for (i = 0; i < mod; i++) { pow *= base; } - this.imuln(pow); - - if ((this || _global$7).words[0] + word < 67108864) { - (this || _global$7).words[0] += word; + if ((this || _global$e).words[0] + word < 67108864) { + (this || _global$e).words[0] += word; } else { this._iaddn(word); } } - this._strip(); }; - BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$7).length); - - for (var i = 0; i < (this || _global$7).length; i++) { - dest.words[i] = (this || _global$7).words[i]; + dest.words = new Array((this || _global$e).length); + for (var i = 0; i < (this || _global$e).length; i++) { + dest.words[i] = (this || _global$e).words[i]; } - - dest.length = (this || _global$7).length; - dest.negative = (this || _global$7).negative; - dest.red = (this || _global$7).red; + dest.length = (this || _global$e).length; + dest.negative = (this || _global$e).negative; + dest.red = (this || _global$e).red; }; - function move(dest, src) { dest.words = src.words; dest.length = src.length; dest.negative = src.negative; dest.red = src.red; } - BN.prototype._move = function _move(dest) { - move(dest, this || _global$7); + move(dest, this || _global$e); }; - BN.prototype.clone = function clone() { var r = new BN(null); this.copy(r); return r; }; - BN.prototype._expand = function _expand(size) { - while ((this || _global$7).length < size) { - (this || _global$7).words[(this || _global$7).length++] = 0; + while ((this || _global$e).length < size) { + (this || _global$e).words[(this || _global$e).length++] = 0; } + return this || _global$e; + }; - return this || _global$7; - }; // Remove leading `0` from `this` - - + // Remove leading `0` from `this` BN.prototype._strip = function strip() { - while ((this || _global$7).length > 1 && (this || _global$7).words[(this || _global$7).length - 1] === 0) { - (this || _global$7).length--; + while ((this || _global$e).length > 1 && (this || _global$e).words[(this || _global$e).length - 1] === 0) { + (this || _global$e).length--; } - return this._normSign(); }; - BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$7).length === 1 && (this || _global$7).words[0] === 0) { - (this || _global$7).negative = 0; + if ((this || _global$e).length === 1 && (this || _global$e).words[0] === 0) { + (this || _global$e).negative = 0; } + return this || _global$e; + }; - return this || _global$7; - }; // Check Symbol.for because not everywhere where Symbol defined + // Check Symbol.for because not everywhere where Symbol defined // See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol#Browser_compatibility - - if (typeof Symbol !== "undefined" && typeof Symbol.for === "function") { try { BN.prototype[Symbol.for("nodejs.util.inspect.custom")] = inspect; @@ -52250,10 +88772,10 @@ function dew$X() { } else { BN.prototype.inspect = inspect; } - function inspect() { - return ((this || _global$7).red ? ""; + return ((this || _global$e).red ? ""; } + /* var zeros = []; var groupSizes = []; @@ -52281,133 +88803,104 @@ function dew$X() { } */ - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - BN.prototype.toString = function toString(base, padding) { base = base || 10; padding = padding | 0 || 1; var out; - if (base === 16 || base === "hex") { out = ""; var off = 0; var carry = 0; - - for (var i = 0; i < (this || _global$7).length; i++) { - var w = (this || _global$7).words[i]; + for (var i = 0; i < (this || _global$e).length; i++) { + var w = (this || _global$e).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - - if (carry !== 0 || i !== (this || _global$7).length - 1) { - out = zeros[6 - word.length] + word + out; - } else { - out = word + out; - } - off += 2; - if (off >= 26) { off -= 26; i--; } + if (carry !== 0 || i !== (this || _global$e).length - 1) { + out = zeros[6 - word.length] + word + out; + } else { + out = word + out; + } } - if (carry !== 0) { out = carry.toString(16) + out; } - while (out.length % padding !== 0) { out = "0" + out; } - - if ((this || _global$7).negative !== 0) { + if ((this || _global$e).negative !== 0) { out = "-" + out; } - return out; } - if (base === (base | 0) && base >= 2 && base <= 36) { // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); var groupBase = groupBases[base]; out = ""; var c = this.clone(); c.negative = 0; - while (!c.isZero()) { var r = c.modrn(groupBase).toString(base); c = c.idivn(groupBase); - if (!c.isZero()) { out = zeros[groupSize - r.length] + r + out; } else { out = r + out; } } - if (this.isZero()) { out = "0" + out; } - while (out.length % padding !== 0) { out = "0" + out; } - - if ((this || _global$7).negative !== 0) { + if ((this || _global$e).negative !== 0) { out = "-" + out; } - return out; } - assert(false, "Base should be between 2 and 36"); }; - BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$7).words[0]; - - if ((this || _global$7).length === 2) { - ret += (this || _global$7).words[1] * 67108864; - } else if ((this || _global$7).length === 3 && (this || _global$7).words[2] === 1) { + var ret = (this || _global$e).words[0]; + if ((this || _global$e).length === 2) { + ret += (this || _global$e).words[1] * 67108864; + } else if ((this || _global$e).length === 3 && (this || _global$e).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$7).words[1] * 67108864; - } else if ((this || _global$7).length > 2) { + ret += 4503599627370496 + (this || _global$e).words[1] * 67108864; + } else if ((this || _global$e).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - - return (this || _global$7).negative !== 0 ? -ret : ret; + return (this || _global$e).negative !== 0 ? -ret : ret; }; - BN.prototype.toJSON = function toJSON() { return this.toString(16, 2); }; - if (Buffer) { BN.prototype.toBuffer = function toBuffer(endian, length) { return this.toArrayLike(Buffer, endian, length); }; } - BN.prototype.toArray = function toArray(endian, length) { return this.toArrayLike(Array, endian, length); }; - var allocate = function allocate(ArrayType, size) { if (ArrayType.allocUnsafe) { return ArrayType.allocUnsafe(size); } - return new ArrayType(size); }; - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { this._strip(); - var byteLength = this.byteLength(); var reqLength = length || Math.max(1, byteLength); assert(byteLength <= reqLength, "byte array longer than desired length"); @@ -52417,28 +88910,22 @@ function dew$X() { this["_toArrayLike" + postfix](res, byteLength); return res; }; - BN.prototype._toArrayLikeLE = function _toArrayLikeLE(res, byteLength) { var position = 0; var carry = 0; - - for (var i = 0, shift = 0; i < (this || _global$7).length; i++) { - var word = (this || _global$7).words[i] << shift | carry; + for (var i = 0, shift = 0; i < (this || _global$e).length; i++) { + var word = (this || _global$e).words[i] << shift | carry; res[position++] = word & 255; - if (position < res.length) { res[position++] = word >> 8 & 255; } - if (position < res.length) { res[position++] = word >> 16 & 255; } - if (shift === 6) { if (position < res.length) { res[position++] = word >> 24 & 255; } - carry = 0; shift = 0; } else { @@ -52446,37 +88933,29 @@ function dew$X() { shift += 2; } } - if (position < res.length) { res[position++] = carry; - while (position < res.length) { res[position++] = 0; } } }; - BN.prototype._toArrayLikeBE = function _toArrayLikeBE(res, byteLength) { var position = res.length - 1; var carry = 0; - - for (var i = 0, shift = 0; i < (this || _global$7).length; i++) { - var word = (this || _global$7).words[i] << shift | carry; + for (var i = 0, shift = 0; i < (this || _global$e).length; i++) { + var word = (this || _global$e).words[i] << shift | carry; res[position--] = word & 255; - if (position >= 0) { res[position--] = word >> 8 & 255; } - if (position >= 0) { res[position--] = word >> 16 & 255; } - if (shift === 6) { if (position >= 0) { res[position--] = word >> 24 & 255; } - carry = 0; shift = 0; } else { @@ -52484,16 +88963,13 @@ function dew$X() { shift += 2; } } - if (position >= 0) { res[position--] = carry; - while (position >= 0) { res[position--] = 0; } } }; - if (Math.clz32) { BN.prototype._countBits = function _countBits(w) { return 32 - Math.clz32(w); @@ -52502,458 +88978,400 @@ function dew$X() { BN.prototype._countBits = function _countBits(w) { var t = w; var r = 0; - if (t >= 4096) { r += 13; t >>>= 13; } - if (t >= 64) { r += 7; t >>>= 7; } - if (t >= 8) { r += 4; t >>>= 4; } - if (t >= 2) { r += 2; t >>>= 2; } - return r + t; }; } - BN.prototype._zeroBits = function _zeroBits(w) { // Short-cut if (w === 0) return 26; var t = w; var r = 0; - if ((t & 8191) === 0) { r += 13; t >>>= 13; } - if ((t & 127) === 0) { r += 7; t >>>= 7; } - if ((t & 15) === 0) { r += 4; t >>>= 4; } - if ((t & 3) === 0) { r += 2; t >>>= 2; } - if ((t & 1) === 0) { r++; } - return r; - }; // Return number of used bits in a BN - + }; + // Return number of used bits in a BN BN.prototype.bitLength = function bitLength() { - var w = (this || _global$7).words[(this || _global$7).length - 1]; - + var w = (this || _global$e).words[(this || _global$e).length - 1]; var hi = this._countBits(w); - - return ((this || _global$7).length - 1) * 26 + hi; + return ((this || _global$e).length - 1) * 26 + hi; }; - function toBitArray(num) { var w = new Array(num.bitLength()); - for (var bit = 0; bit < w.length; bit++) { var off = bit / 26 | 0; var wbit = bit % 26; w[bit] = num.words[off] >>> wbit & 1; } - return w; - } // Number of trailing zero bits - + } + // Number of trailing zero bits BN.prototype.zeroBits = function zeroBits() { if (this.isZero()) return 0; var r = 0; - - for (var i = 0; i < (this || _global$7).length; i++) { - var b = this._zeroBits((this || _global$7).words[i]); - + for (var i = 0; i < (this || _global$e).length; i++) { + var b = this._zeroBits((this || _global$e).words[i]); r += b; if (b !== 26) break; } - return r; }; - BN.prototype.byteLength = function byteLength() { return Math.ceil(this.bitLength() / 8); }; - BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$7).negative !== 0) { + if ((this || _global$e).negative !== 0) { return this.abs().inotn(width).iaddn(1); } - return this.clone(); }; - BN.prototype.fromTwos = function fromTwos(width) { if (this.testn(width - 1)) { return this.notn(width).iaddn(1).ineg(); } - return this.clone(); }; - BN.prototype.isNeg = function isNeg() { - return (this || _global$7).negative !== 0; - }; // Return negative clone of `this` - + return (this || _global$e).negative !== 0; + }; + // Return negative clone of `this` BN.prototype.neg = function neg() { return this.clone().ineg(); }; - BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$7).negative ^= 1; + (this || _global$e).negative ^= 1; } + return this || _global$e; + }; - return this || _global$7; - }; // Or `num` with `this` in-place - - + // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$7).length < num.length) { - (this || _global$7).words[(this || _global$7).length++] = 0; + while ((this || _global$e).length < num.length) { + (this || _global$e).words[(this || _global$e).length++] = 0; } - for (var i = 0; i < num.length; i++) { - (this || _global$7).words[i] = (this || _global$7).words[i] | num.words[i]; + (this || _global$e).words[i] = (this || _global$e).words[i] | num.words[i]; } - return this._strip(); }; - BN.prototype.ior = function ior(num) { - assert(((this || _global$7).negative | num.negative) === 0); + assert(((this || _global$e).negative | num.negative) === 0); return this.iuor(num); - }; // Or `num` with `this` - + }; + // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$7).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$7); + if ((this || _global$e).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$e); }; - BN.prototype.uor = function uor(num) { - if ((this || _global$7).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$7); - }; // And `num` with `this` in-place - + if ((this || _global$e).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$e); + }; + // And `num` with `this` in-place BN.prototype.iuand = function iuand(num) { // b = min-length(num, this) var b; - - if ((this || _global$7).length > num.length) { + if ((this || _global$e).length > num.length) { b = num; } else { - b = this || _global$7; + b = this || _global$e; } - for (var i = 0; i < b.length; i++) { - (this || _global$7).words[i] = (this || _global$7).words[i] & num.words[i]; + (this || _global$e).words[i] = (this || _global$e).words[i] & num.words[i]; } - - (this || _global$7).length = b.length; + (this || _global$e).length = b.length; return this._strip(); }; - BN.prototype.iand = function iand(num) { - assert(((this || _global$7).negative | num.negative) === 0); + assert(((this || _global$e).negative | num.negative) === 0); return this.iuand(num); - }; // And `num` with `this` - + }; + // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$7).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$7); + if ((this || _global$e).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$e); }; - BN.prototype.uand = function uand(num) { - if ((this || _global$7).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$7); - }; // Xor `num` with `this` in-place - + if ((this || _global$e).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$e); + }; + // Xor `num` with `this` in-place BN.prototype.iuxor = function iuxor(num) { // a.length > b.length var a; var b; - - if ((this || _global$7).length > num.length) { - a = this || _global$7; + if ((this || _global$e).length > num.length) { + a = this || _global$e; b = num; } else { a = num; - b = this || _global$7; + b = this || _global$e; } - for (var i = 0; i < b.length; i++) { - (this || _global$7).words[i] = a.words[i] ^ b.words[i]; + (this || _global$e).words[i] = a.words[i] ^ b.words[i]; } - - if ((this || _global$7) !== a) { + if ((this || _global$e) !== a) { for (; i < a.length; i++) { - (this || _global$7).words[i] = a.words[i]; + (this || _global$e).words[i] = a.words[i]; } } - - (this || _global$7).length = a.length; + (this || _global$e).length = a.length; return this._strip(); }; - BN.prototype.ixor = function ixor(num) { - assert(((this || _global$7).negative | num.negative) === 0); + assert(((this || _global$e).negative | num.negative) === 0); return this.iuxor(num); - }; // Xor `num` with `this` - + }; + // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$7).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$7); + if ((this || _global$e).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$e); }; - BN.prototype.uxor = function uxor(num) { - if ((this || _global$7).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$7); - }; // Not ``this`` with ``width`` bitwidth - + if ((this || _global$e).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$e); + }; + // Not ``this`` with ``width`` bitwidth BN.prototype.inotn = function inotn(width) { assert(typeof width === "number" && width >= 0); var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + var bitsLeft = width % 26; + // Extend the buffer with leading zeroes this._expand(bytesNeeded); - if (bitsLeft > 0) { bytesNeeded--; - } // Handle complete words - + } + // Handle complete words for (var i = 0; i < bytesNeeded; i++) { - (this || _global$7).words[i] = ~(this || _global$7).words[i] & 67108863; - } // Handle the residue - + (this || _global$e).words[i] = ~(this || _global$e).words[i] & 67108863; + } + // Handle the residue if (bitsLeft > 0) { - (this || _global$7).words[i] = ~(this || _global$7).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes - + (this || _global$e).words[i] = ~(this || _global$e).words[i] & 67108863 >> 26 - bitsLeft; + } + // And remove leading zeroes return this._strip(); }; - BN.prototype.notn = function notn(width) { return this.clone().inotn(width); - }; // Set `bit` of `this` - + }; + // Set `bit` of `this` BN.prototype.setn = function setn(bit, val) { assert(typeof bit === "number" && bit >= 0); var off = bit / 26 | 0; var wbit = bit % 26; - this._expand(off + 1); - if (val) { - (this || _global$7).words[off] = (this || _global$7).words[off] | 1 << wbit; + (this || _global$e).words[off] = (this || _global$e).words[off] | 1 << wbit; } else { - (this || _global$7).words[off] = (this || _global$7).words[off] & ~(1 << wbit); + (this || _global$e).words[off] = (this || _global$e).words[off] & ~(1 << wbit); } - return this._strip(); - }; // Add `num` to `this` in-place - + }; + // Add `num` to `this` in-place BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + var r; - if ((this || _global$7).negative !== 0 && num.negative === 0) { - (this || _global$7).negative = 0; + // negative + positive + if ((this || _global$e).negative !== 0 && num.negative === 0) { + (this || _global$e).negative = 0; r = this.isub(num); - (this || _global$7).negative ^= 1; - return this._normSign(); // positive + negative - } else if ((this || _global$7).negative === 0 && num.negative !== 0) { + (this || _global$e).negative ^= 1; + return this._normSign(); + + // positive + negative + } else if ((this || _global$e).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; return r._normSign(); - } // a.length > b.length - + } + // a.length > b.length var a, b; - - if ((this || _global$7).length > num.length) { - a = this || _global$7; + if ((this || _global$e).length > num.length) { + a = this || _global$e; b = num; } else { a = num; - b = this || _global$7; + b = this || _global$e; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$7).words[i] = r & 67108863; + (this || _global$e).words[i] = r & 67108863; carry = r >>> 26; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$7).words[i] = r & 67108863; + (this || _global$e).words[i] = r & 67108863; carry = r >>> 26; } - - (this || _global$7).length = a.length; - + (this || _global$e).length = a.length; if (carry !== 0) { - (this || _global$7).words[(this || _global$7).length] = carry; - (this || _global$7).length++; // Copy the rest of the words - } else if (a !== (this || _global$7)) { + (this || _global$e).words[(this || _global$e).length] = carry; + (this || _global$e).length++; + // Copy the rest of the words + } else if (a !== (this || _global$e)) { for (; i < a.length; i++) { - (this || _global$7).words[i] = a.words[i]; + (this || _global$e).words[i] = a.words[i]; } } + return this || _global$e; + }; - return this || _global$7; - }; // Add `num` to `this` - - + // Add `num` to `this` BN.prototype.add = function add(num) { var res; - - if (num.negative !== 0 && (this || _global$7).negative === 0) { + if (num.negative !== 0 && (this || _global$e).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$7).negative !== 0) { - (this || _global$7).negative = 0; - res = num.sub(this || _global$7); - (this || _global$7).negative = 1; + } else if (num.negative === 0 && (this || _global$e).negative !== 0) { + (this || _global$e).negative = 0; + res = num.sub(this || _global$e); + (this || _global$e).negative = 1; return res; } + if ((this || _global$e).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$e); + }; - if ((this || _global$7).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$7); - }; // Subtract `num` from `this` in-place - - + // Subtract `num` from `this` in-place BN.prototype.isub = function isub(num) { // this - (-num) = this + num if (num.negative !== 0) { num.negative = 0; var r = this.iadd(num); num.negative = 1; - return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$7).negative !== 0) { - (this || _global$7).negative = 0; + return r._normSign(); + + // -this - num = -(this + num) + } else if ((this || _global$e).negative !== 0) { + (this || _global$e).negative = 0; this.iadd(num); - (this || _global$7).negative = 1; + (this || _global$e).negative = 1; return this._normSign(); - } // At this point both numbers are positive - + } - var cmp = this.cmp(num); // Optimization - zeroify + // At this point both numbers are positive + var cmp = this.cmp(num); + // Optimization - zeroify if (cmp === 0) { - (this || _global$7).negative = 0; - (this || _global$7).length = 1; - (this || _global$7).words[0] = 0; - return this || _global$7; - } // a > b - + (this || _global$e).negative = 0; + (this || _global$e).length = 1; + (this || _global$e).words[0] = 0; + return this || _global$e; + } + // a > b var a, b; - if (cmp > 0) { - a = this || _global$7; + a = this || _global$e; b = num; } else { a = num; - b = this || _global$7; + b = this || _global$e; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$7).words[i] = r & 67108863; + (this || _global$e).words[i] = r & 67108863; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$7).words[i] = r & 67108863; - } // Copy rest of the words - + (this || _global$e).words[i] = r & 67108863; + } - if (carry === 0 && i < a.length && a !== (this || _global$7)) { + // Copy rest of the words + if (carry === 0 && i < a.length && a !== (this || _global$e)) { for (; i < a.length; i++) { - (this || _global$7).words[i] = a.words[i]; + (this || _global$e).words[i] = a.words[i]; } } - - (this || _global$7).length = Math.max((this || _global$7).length, i); - - if (a !== (this || _global$7)) { - (this || _global$7).negative = 1; + (this || _global$e).length = Math.max((this || _global$e).length, i); + if (a !== (this || _global$e)) { + (this || _global$e).negative = 1; } - return this._strip(); - }; // Subtract `num` from `this` - + }; + // Subtract `num` from `this` BN.prototype.sub = function sub(num) { return this.clone().isub(num); }; - function smallMulTo(self, num, out) { out.negative = num.negative ^ self.negative; var len = self.length + num.length | 0; out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + len = len - 1 | 0; + // Peel one iteration (compiler can't do it, because of code complexity) var a = self.words[0] | 0; var b = num.words[0] | 0; var r = a * b; var lo = r & 67108863; var carry = r / 67108864 | 0; out.words[0] = lo; - for (var k = 1; k < len; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff var ncarry = carry >>> 26; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j | 0; a = self.words[i] | 0; @@ -52962,23 +89380,20 @@ function dew$X() { ncarry += r / 67108864 | 0; rword = r & 67108863; } - out.words[k] = rword | 0; carry = ncarry | 0; } - if (carry !== 0) { out.words[k] = carry | 0; } else { out.length--; } - return out._strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need + } + + // TODO(indutny): it may be reasonable to omit it for users who don't need // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit // multiplication (like elliptic secp256k1). - - var comb10MulTo = function comb10MulTo(self, num, out) { var a = self.words; var b = num.words; @@ -53050,7 +89465,6 @@ function dew$X() { out.negative = self.negative ^ num.negative; out.length = 19; /* k = 0 */ - lo = Math.imul(al0, bl0); mid = Math.imul(al0, bh0); mid = mid + Math.imul(ah0, bl0) | 0; @@ -53059,7 +89473,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; w0 &= 67108863; /* k = 1 */ - lo = Math.imul(al1, bl0); mid = Math.imul(al1, bh0); mid = mid + Math.imul(ah1, bl0) | 0; @@ -53072,7 +89485,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; w1 &= 67108863; /* k = 2 */ - lo = Math.imul(al2, bl0); mid = Math.imul(al2, bh0); mid = mid + Math.imul(ah2, bl0) | 0; @@ -53089,7 +89501,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; w2 &= 67108863; /* k = 3 */ - lo = Math.imul(al3, bl0); mid = Math.imul(al3, bh0); mid = mid + Math.imul(ah3, bl0) | 0; @@ -53110,7 +89521,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; w3 &= 67108863; /* k = 4 */ - lo = Math.imul(al4, bl0); mid = Math.imul(al4, bh0); mid = mid + Math.imul(ah4, bl0) | 0; @@ -53135,7 +89545,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; w4 &= 67108863; /* k = 5 */ - lo = Math.imul(al5, bl0); mid = Math.imul(al5, bh0); mid = mid + Math.imul(ah5, bl0) | 0; @@ -53164,7 +89573,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; w5 &= 67108863; /* k = 6 */ - lo = Math.imul(al6, bl0); mid = Math.imul(al6, bh0); mid = mid + Math.imul(ah6, bl0) | 0; @@ -53197,7 +89605,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; w6 &= 67108863; /* k = 7 */ - lo = Math.imul(al7, bl0); mid = Math.imul(al7, bh0); mid = mid + Math.imul(ah7, bl0) | 0; @@ -53234,7 +89641,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; w7 &= 67108863; /* k = 8 */ - lo = Math.imul(al8, bl0); mid = Math.imul(al8, bh0); mid = mid + Math.imul(ah8, bl0) | 0; @@ -53275,7 +89681,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; w8 &= 67108863; /* k = 9 */ - lo = Math.imul(al9, bl0); mid = Math.imul(al9, bh0); mid = mid + Math.imul(ah9, bl0) | 0; @@ -53320,7 +89725,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; w9 &= 67108863; /* k = 10 */ - lo = Math.imul(al9, bl1); mid = Math.imul(al9, bh1); mid = mid + Math.imul(ah9, bl1) | 0; @@ -53361,7 +89765,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; w10 &= 67108863; /* k = 11 */ - lo = Math.imul(al9, bl2); mid = Math.imul(al9, bh2); mid = mid + Math.imul(ah9, bl2) | 0; @@ -53398,7 +89801,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; w11 &= 67108863; /* k = 12 */ - lo = Math.imul(al9, bl3); mid = Math.imul(al9, bh3); mid = mid + Math.imul(ah9, bl3) | 0; @@ -53431,7 +89833,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; w12 &= 67108863; /* k = 13 */ - lo = Math.imul(al9, bl4); mid = Math.imul(al9, bh4); mid = mid + Math.imul(ah9, bl4) | 0; @@ -53460,7 +89861,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; w13 &= 67108863; /* k = 14 */ - lo = Math.imul(al9, bl5); mid = Math.imul(al9, bh5); mid = mid + Math.imul(ah9, bl5) | 0; @@ -53485,7 +89885,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; w14 &= 67108863; /* k = 15 */ - lo = Math.imul(al9, bl6); mid = Math.imul(al9, bh6); mid = mid + Math.imul(ah9, bl6) | 0; @@ -53506,7 +89905,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; w15 &= 67108863; /* k = 16 */ - lo = Math.imul(al9, bl7); mid = Math.imul(al9, bh7); mid = mid + Math.imul(ah9, bl7) | 0; @@ -53523,7 +89921,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; w16 &= 67108863; /* k = 17 */ - lo = Math.imul(al9, bl8); mid = Math.imul(al9, bh8); mid = mid + Math.imul(ah9, bl8) | 0; @@ -53536,7 +89933,6 @@ function dew$X() { c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; w17 &= 67108863; /* k = 18 */ - lo = Math.imul(al9, bl9); mid = Math.imul(al9, bh9); mid = mid + Math.imul(ah9, bl9) | 0; @@ -53563,26 +89959,22 @@ function dew$X() { o[16] = w16; o[17] = w17; o[18] = w18; - if (c !== 0) { o[19] = c; out.length++; } - return out; - }; // Polyfill comb - + }; + // Polyfill comb if (!Math.imul) { comb10MulTo = smallMulTo; } - function bigMulTo(self, num, out) { out.negative = num.negative ^ self.negative; out.length = self.length + num.length; var carry = 0; var hncarry = 0; - for (var k = 0; k < out.length - 1; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff @@ -53590,7 +89982,6 @@ function dew$X() { hncarry = 0; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j; var a = self.words[i] | 0; @@ -53604,580 +89995,499 @@ function dew$X() { hncarry += ncarry >>> 26; ncarry &= 67108863; } - out.words[k] = rword; carry = ncarry; ncarry = hncarry; } - if (carry !== 0) { out.words[k] = carry; } else { out.length--; } - return out._strip(); } - function jumboMulTo(self, num, out) { // Temporary disable, see https://github.com/indutny/bn.js/issues/211 // var fftm = new FFTM(); // return fftm.mulp(self, num, out); return bigMulTo(self, num, out); } - BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$7).length + num.length; - - if ((this || _global$7).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$7, num, out); + var len = (this || _global$e).length + num.length; + if ((this || _global$e).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$e, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$7, num, out); + res = smallMulTo(this || _global$e, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$7, num, out); + res = bigMulTo(this || _global$e, num, out); } else { - res = jumboMulTo(this || _global$7, num, out); + res = jumboMulTo(this || _global$e, num, out); } - return res; - }; // Cooley-Tukey algorithm for FFT - + }; + // Multiply `this` by `num` BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$7).length + num.length); + out.words = new Array((this || _global$e).length + num.length); return this.mulTo(num, out); - }; // Multiply employing FFT - + }; + // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$7).length + num.length); - return jumboMulTo(this || _global$7, num, out); - }; // In-place Multiplication - + out.words = new Array((this || _global$e).length + num.length); + return jumboMulTo(this || _global$e, num, out); + }; + // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$7); + return this.clone().mulTo(num, this || _global$e); }; - BN.prototype.imuln = function imuln(num) { var isNegNum = num < 0; if (isNegNum) num = -num; assert(typeof num === "number"); - assert(num < 67108864); // Carry + assert(num < 67108864); + // Carry var carry = 0; - - for (var i = 0; i < (this || _global$7).length; i++) { - var w = ((this || _global$7).words[i] | 0) * num; + for (var i = 0; i < (this || _global$e).length; i++) { + var w = ((this || _global$e).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$7).words[i] = lo & 67108863; + (this || _global$e).words[i] = lo & 67108863; } - if (carry !== 0) { - (this || _global$7).words[i] = carry; - (this || _global$7).length++; + (this || _global$e).words[i] = carry; + (this || _global$e).length++; } - - return isNegNum ? this.ineg() : this || _global$7; + return isNegNum ? this.ineg() : this || _global$e; }; - BN.prototype.muln = function muln(num) { return this.clone().imuln(num); - }; // `this` * `this` - + }; + // `this` * `this` BN.prototype.sqr = function sqr() { - return this.mul(this || _global$7); - }; // `this` * `this` in-place - + return this.mul(this || _global$e); + }; + // `this` * `this` in-place BN.prototype.isqr = function isqr() { return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) - + }; + // Math.pow(`this`, `num`) BN.prototype.pow = function pow(num) { var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes - - var res = this || _global$7; + if (w.length === 0) return new BN(1); + // Skip leading zeroes + var res = this || _global$e; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; } - if (++i < w.length) { for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { if (w[i] === 0) continue; res = res.mul(q); } } - return res; - }; // Shift-left in-place - + }; + // Shift-left in-place BN.prototype.iushln = function iushln(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; var carryMask = 67108863 >>> 26 - r << 26 - r; var i; - if (r !== 0) { var carry = 0; - - for (i = 0; i < (this || _global$7).length; i++) { - var newCarry = (this || _global$7).words[i] & carryMask; - var c = ((this || _global$7).words[i] | 0) - newCarry << r; - (this || _global$7).words[i] = c | carry; + for (i = 0; i < (this || _global$e).length; i++) { + var newCarry = (this || _global$e).words[i] & carryMask; + var c = ((this || _global$e).words[i] | 0) - newCarry << r; + (this || _global$e).words[i] = c | carry; carry = newCarry >>> 26 - r; } - if (carry) { - (this || _global$7).words[i] = carry; - (this || _global$7).length++; + (this || _global$e).words[i] = carry; + (this || _global$e).length++; } } - if (s !== 0) { - for (i = (this || _global$7).length - 1; i >= 0; i--) { - (this || _global$7).words[i + s] = (this || _global$7).words[i]; + for (i = (this || _global$e).length - 1; i >= 0; i--) { + (this || _global$e).words[i + s] = (this || _global$e).words[i]; } - for (i = 0; i < s; i++) { - (this || _global$7).words[i] = 0; + (this || _global$e).words[i] = 0; } - - (this || _global$7).length += s; + (this || _global$e).length += s; } - return this._strip(); }; - BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$7).negative === 0); + assert((this || _global$e).negative === 0); return this.iushln(bits); - }; // Shift-right in-place + }; + + // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes // NOTE: if `extended` is present - it will be filled with destroyed bits - - BN.prototype.iushrn = function iushrn(bits, hint, extended) { assert(typeof bits === "number" && bits >= 0); var h; - if (hint) { h = (hint - hint % 26) / 26; } else { h = 0; } - var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$7).length); + var s = Math.min((bits - r) / 26, (this || _global$e).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; - h = Math.max(0, h); // Extended mode, copy masked part + h = Math.max(0, h); + // Extended mode, copy masked part if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$7).words[i]; + maskedWords.words[i] = (this || _global$e).words[i]; } - maskedWords.length = s; } - - if (s === 0) ; else if ((this || _global$7).length > s) { - (this || _global$7).length -= s; - - for (i = 0; i < (this || _global$7).length; i++) { - (this || _global$7).words[i] = (this || _global$7).words[i + s]; + if (s === 0) ; else if ((this || _global$e).length > s) { + (this || _global$e).length -= s; + for (i = 0; i < (this || _global$e).length; i++) { + (this || _global$e).words[i] = (this || _global$e).words[i + s]; } } else { - (this || _global$7).words[0] = 0; - (this || _global$7).length = 1; + (this || _global$e).words[0] = 0; + (this || _global$e).length = 1; } - var carry = 0; - - for (i = (this || _global$7).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$7).words[i] | 0; - (this || _global$7).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$e).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$e).words[i] | 0; + (this || _global$e).words[i] = carry << 26 - r | word >>> r; carry = word & mask; - } // Push carried bits as a mask - + } + // Push carried bits as a mask if (maskedWords && carry !== 0) { maskedWords.words[maskedWords.length++] = carry; } - - if ((this || _global$7).length === 0) { - (this || _global$7).words[0] = 0; - (this || _global$7).length = 1; + if ((this || _global$e).length === 0) { + (this || _global$e).words[0] = 0; + (this || _global$e).length = 1; } - return this._strip(); }; - BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$7).negative === 0); + assert((this || _global$e).negative === 0); return this.iushrn(bits, hint, extended); - }; // Shift-left - + }; + // Shift-left BN.prototype.shln = function shln(bits) { return this.clone().ishln(bits); }; - BN.prototype.ushln = function ushln(bits) { return this.clone().iushln(bits); - }; // Shift-right - + }; + // Shift-right BN.prototype.shrn = function shrn(bits) { return this.clone().ishrn(bits); }; - BN.prototype.ushrn = function ushrn(bits) { return this.clone().iushrn(bits); - }; // Test if n bit is set - + }; + // Test if n bit is set BN.prototype.testn = function testn(bit) { assert(typeof bit === "number" && bit >= 0); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$7).length <= s) return false; // Check bit and return + // Fast case: bit is much higher than all existing words + if ((this || _global$e).length <= s) return false; - var w = (this || _global$7).words[s]; + // Check bit and return + var w = (this || _global$e).words[s]; return !!(w & q); - }; // Return only lowers bits of number (in-place) - + }; + // Return only lowers bits of number (in-place) BN.prototype.imaskn = function imaskn(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$7).negative === 0, "imaskn works only with positive numbers"); - - if ((this || _global$7).length <= s) { - return this || _global$7; + assert((this || _global$e).negative === 0, "imaskn works only with positive numbers"); + if ((this || _global$e).length <= s) { + return this || _global$e; } - if (r !== 0) { s++; } - - (this || _global$7).length = Math.min(s, (this || _global$7).length); - + (this || _global$e).length = Math.min(s, (this || _global$e).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$7).words[(this || _global$7).length - 1] &= mask; + (this || _global$e).words[(this || _global$e).length - 1] &= mask; } - return this._strip(); - }; // Return only lowers bits of number - + }; + // Return only lowers bits of number BN.prototype.maskn = function maskn(bits) { return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` - + }; + // Add plain number `num` to `this` BN.prototype.iaddn = function iaddn(num) { assert(typeof num === "number"); assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + if (num < 0) return this.isubn(-num); - if ((this || _global$7).negative !== 0) { - if ((this || _global$7).length === 1 && ((this || _global$7).words[0] | 0) <= num) { - (this || _global$7).words[0] = num - ((this || _global$7).words[0] | 0); - (this || _global$7).negative = 0; - return this || _global$7; + // Possible sign change + if ((this || _global$e).negative !== 0) { + if ((this || _global$e).length === 1 && ((this || _global$e).words[0] | 0) <= num) { + (this || _global$e).words[0] = num - ((this || _global$e).words[0] | 0); + (this || _global$e).negative = 0; + return this || _global$e; } - - (this || _global$7).negative = 0; + (this || _global$e).negative = 0; this.isubn(num); - (this || _global$7).negative = 1; - return this || _global$7; - } // Add without checks - + (this || _global$e).negative = 1; + return this || _global$e; + } + // Add without checks return this._iaddn(num); }; - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$7).words[0] += num; // Carry - - for (var i = 0; i < (this || _global$7).length && (this || _global$7).words[i] >= 67108864; i++) { - (this || _global$7).words[i] -= 67108864; + (this || _global$e).words[0] += num; - if (i === (this || _global$7).length - 1) { - (this || _global$7).words[i + 1] = 1; + // Carry + for (var i = 0; i < (this || _global$e).length && (this || _global$e).words[i] >= 67108864; i++) { + (this || _global$e).words[i] -= 67108864; + if (i === (this || _global$e).length - 1) { + (this || _global$e).words[i + 1] = 1; } else { - (this || _global$7).words[i + 1]++; + (this || _global$e).words[i + 1]++; } } + (this || _global$e).length = Math.max((this || _global$e).length, i + 1); + return this || _global$e; + }; - (this || _global$7).length = Math.max((this || _global$7).length, i + 1); - return this || _global$7; - }; // Subtract plain number `num` from `this` - - + // Subtract plain number `num` from `this` BN.prototype.isubn = function isubn(num) { assert(typeof num === "number"); assert(num < 67108864); if (num < 0) return this.iaddn(-num); - - if ((this || _global$7).negative !== 0) { - (this || _global$7).negative = 0; + if ((this || _global$e).negative !== 0) { + (this || _global$e).negative = 0; this.iaddn(num); - (this || _global$7).negative = 1; - return this || _global$7; + (this || _global$e).negative = 1; + return this || _global$e; } - - (this || _global$7).words[0] -= num; - - if ((this || _global$7).length === 1 && (this || _global$7).words[0] < 0) { - (this || _global$7).words[0] = -(this || _global$7).words[0]; - (this || _global$7).negative = 1; + (this || _global$e).words[0] -= num; + if ((this || _global$e).length === 1 && (this || _global$e).words[0] < 0) { + (this || _global$e).words[0] = -(this || _global$e).words[0]; + (this || _global$e).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$7).length && (this || _global$7).words[i] < 0; i++) { - (this || _global$7).words[i] += 67108864; - (this || _global$7).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$e).length && (this || _global$e).words[i] < 0; i++) { + (this || _global$e).words[i] += 67108864; + (this || _global$e).words[i + 1] -= 1; } } - return this._strip(); }; - BN.prototype.addn = function addn(num) { return this.clone().iaddn(num); }; - BN.prototype.subn = function subn(num) { return this.clone().isubn(num); }; - BN.prototype.iabs = function iabs() { - (this || _global$7).negative = 0; - return this || _global$7; + (this || _global$e).negative = 0; + return this || _global$e; }; - BN.prototype.abs = function abs() { return this.clone().iabs(); }; - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { var len = num.length + shift; var i; - this._expand(len); - var w; var carry = 0; - for (i = 0; i < num.length; i++) { - w = ((this || _global$7).words[i + shift] | 0) + carry; + w = ((this || _global$e).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$7).words[i + shift] = w & 67108863; + (this || _global$e).words[i + shift] = w & 67108863; } - - for (; i < (this || _global$7).length - shift; i++) { - w = ((this || _global$7).words[i + shift] | 0) + carry; + for (; i < (this || _global$e).length - shift; i++) { + w = ((this || _global$e).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$7).words[i + shift] = w & 67108863; + (this || _global$e).words[i + shift] = w & 67108863; } + if (carry === 0) return this._strip(); - if (carry === 0) return this._strip(); // Subtraction overflow - + // Subtraction overflow assert(carry === -1); carry = 0; - - for (i = 0; i < (this || _global$7).length; i++) { - w = -((this || _global$7).words[i] | 0) + carry; + for (i = 0; i < (this || _global$e).length; i++) { + w = -((this || _global$e).words[i] | 0) + carry; carry = w >> 26; - (this || _global$7).words[i] = w & 67108863; + (this || _global$e).words[i] = w & 67108863; } - - (this || _global$7).negative = 1; + (this || _global$e).negative = 1; return this._strip(); }; - BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$7).length - num.length; + var shift = (this || _global$e).length - num.length; var a = this.clone(); - var b = num; // Normalize + var b = num; + // Normalize var bhi = b.words[b.length - 1] | 0; - var bhiBits = this._countBits(bhi); - shift = 26 - bhiBits; - if (shift !== 0) { b = b.ushln(shift); a.iushln(shift); bhi = b.words[b.length - 1] | 0; - } // Initialize quotient - + } + // Initialize quotient var m = a.length - b.length; var q; - if (mode !== "mod") { q = new BN(null); q.length = m + 1; q.words = new Array(q.length); - for (var i = 0; i < q.length; i++) { q.words[i] = 0; } } - var diff = a.clone()._ishlnsubmul(b, 1, m); - if (diff.negative === 0) { a = diff; - if (q) { q.words[m] = 1; } } - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) qj = Math.min(qj / bhi | 0, 67108863); - a._ishlnsubmul(b, qj, j); - while (a.negative !== 0) { qj--; a.negative = 0; - a._ishlnsubmul(b, 1, j); - if (!a.isZero()) { a.negative ^= 1; } } - if (q) { q.words[j] = qj; } } - if (q) { q._strip(); } + a._strip(); - a._strip(); // Denormalize - - + // Denormalize if (mode !== "div" && shift !== 0) { a.iushrn(shift); } - return { div: q || null, mod: a }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, // to `div` to request div only, or be absent to // request both div & mod // 2) `positive` is true if unsigned mod is requested - - BN.prototype.divmod = function divmod(num, mode, positive) { assert(!num.isZero()); - if (this.isZero()) { return { div: new BN(0), mod: new BN(0) }; } - var div, mod, res; - - if ((this || _global$7).negative !== 0 && num.negative === 0) { + if ((this || _global$e).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); - if (mode !== "mod") { div = res.div.neg(); } - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.iadd(num); } } - return { div: div, mod: mod }; } - - if ((this || _global$7).negative === 0 && num.negative !== 0) { + if ((this || _global$e).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); - if (mode !== "mod") { div = res.div.neg(); } - return { div: div, mod: res.mod }; } - - if (((this || _global$7).negative & num.negative) !== 0) { + if (((this || _global$e).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.isub(num); } } - return { div: res.div, mod: mod }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + } + // Both numbers are positive at this point - if (num.length > (this || _global$7).length || this.cmp(num) < 0) { + // Strip both numbers to approximate shift value + if (num.length > (this || _global$e).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$7 + mod: this || _global$e }; - } // Very short reduction - + } + // Very short reduction if (num.length === 1) { if (mode === "div") { return { @@ -54185,155 +90495,135 @@ function dew$X() { mod: null }; } - if (mode === "mod") { return { div: null, mod: new BN(this.modrn(num.words[0])) }; } - return { div: this.divn(num.words[0]), mod: new BN(this.modrn(num.words[0])) }; } - return this._wordDiv(num, mode); - }; // Find `this` / `num` - + }; + // Find `this` / `num` BN.prototype.div = function div(num) { return this.divmod(num, "div", false).div; - }; // Find `this` % `num` - + }; + // Find `this` % `num` BN.prototype.mod = function mod(num) { return this.divmod(num, "mod", false).mod; }; - BN.prototype.umod = function umod(num) { return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) - + }; + // Find Round(`this` / `num`) BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + var dm = this.divmod(num); + // Fast case - exact division if (dm.mod.isZero()) return dm.div; var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; var half = num.ushrn(1); var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + var cmp = mod.cmp(half); - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + // Round up return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); }; - BN.prototype.modrn = function modrn(num) { var isNegNum = num < 0; if (isNegNum) num = -num; assert(num <= 67108863); var p = (1 << 26) % num; var acc = 0; - - for (var i = (this || _global$7).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$7).words[i] | 0)) % num; + for (var i = (this || _global$e).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$e).words[i] | 0)) % num; } - return isNegNum ? -acc : acc; - }; // WARNING: DEPRECATED - + }; + // WARNING: DEPRECATED BN.prototype.modn = function modn(num) { return this.modrn(num); - }; // In-place division by number - + }; + // In-place division by number BN.prototype.idivn = function idivn(num) { var isNegNum = num < 0; if (isNegNum) num = -num; assert(num <= 67108863); var carry = 0; - - for (var i = (this || _global$7).length - 1; i >= 0; i--) { - var w = ((this || _global$7).words[i] | 0) + carry * 67108864; - (this || _global$7).words[i] = w / num | 0; + for (var i = (this || _global$e).length - 1; i >= 0; i--) { + var w = ((this || _global$e).words[i] | 0) + carry * 67108864; + (this || _global$e).words[i] = w / num | 0; carry = w % num; } - this._strip(); - - return isNegNum ? this.ineg() : this || _global$7; + return isNegNum ? this.ineg() : this || _global$e; }; - BN.prototype.divn = function divn(num) { return this.clone().idivn(num); }; - BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$7; + var x = this || _global$e; var y = p.clone(); - if (x.negative !== 0) { x = x.umod(p); } else { x = x.clone(); - } // A * x + B * y = x - + } + // A * x + B * y = x var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + var B = new BN(0); + // C * x + D * y = y var C = new BN(0); var D = new BN(1); var g = 0; - while (x.isEven() && y.isEven()) { x.iushrn(1); y.iushrn(1); ++g; } - var yp = y.clone(); var xp = x.clone(); - while (!x.isZero()) { for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { x.iushrn(i); - while (i-- > 0) { if (A.isOdd() || B.isOdd()) { A.iadd(yp); B.isub(xp); } - A.iushrn(1); B.iushrn(1); } } - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { y.iushrn(j); - while (j-- > 0) { if (C.isOdd() || D.isOdd()) { C.iadd(yp); D.isub(xp); } - C.iushrn(1); D.iushrn(1); } } - if (x.cmp(y) >= 0) { x.isub(y); A.isub(C); @@ -54344,62 +90634,50 @@ function dew$X() { D.isub(B); } } - return { a: C, b: D, gcd: y.iushln(g) }; - }; // This is reduced incarnation of the binary EEA + }; + + // This is reduced incarnation of the binary EEA // above, designated to invert members of the // _prime_ fields F(p) at a maximal speed - - BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$7; + var a = this || _global$e; var b = p.clone(); - if (a.negative !== 0) { a = a.umod(p); } else { a = a.clone(); } - var x1 = new BN(1); var x2 = new BN(0); var delta = b.clone(); - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { a.iushrn(i); - while (i-- > 0) { if (x1.isOdd()) { x1.iadd(delta); } - x1.iushrn(1); } } - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { b.iushrn(j); - while (j-- > 0) { if (x2.isOdd()) { x2.iadd(delta); } - x2.iushrn(1); } } - if (a.cmp(b) >= 0) { a.isub(b); x1.isub(x2); @@ -54408,46 +90686,38 @@ function dew$X() { x2.isub(x1); } } - var res; - if (a.cmpn(1) === 0) { res = x1; } else { res = x2; } - if (res.cmpn(0) < 0) { res.iadd(p); } - return res; }; - BN.prototype.gcd = function gcd(num) { if (this.isZero()) return num.abs(); if (num.isZero()) return this.abs(); var a = this.clone(); var b = num.clone(); a.negative = 0; - b.negative = 0; // Remove common factor of two + b.negative = 0; + // Remove common factor of two for (var shift = 0; a.isEven() && b.isEven(); shift++) { a.iushrn(1); b.iushrn(1); } - do { while (a.isEven()) { a.iushrn(1); } - while (b.isEven()) { b.iushrn(1); } - var r = a.cmp(b); - if (r < 0) { // Swap `a` and `b` to make `a` always bigger than `b` var t = a; @@ -54456,332 +90726,269 @@ function dew$X() { } else if (r === 0 || b.cmpn(1) === 0) { break; } - a.isub(b); } while (true); - return b.iushln(shift); - }; // Invert number in the field F(num) - + }; + // Invert number in the field F(num) BN.prototype.invm = function invm(num) { return this.egcd(num).a.umod(num); }; - BN.prototype.isEven = function isEven() { - return ((this || _global$7).words[0] & 1) === 0; + return ((this || _global$e).words[0] & 1) === 0; }; - BN.prototype.isOdd = function isOdd() { - return ((this || _global$7).words[0] & 1) === 1; - }; // And first word and num - + return ((this || _global$e).words[0] & 1) === 1; + }; + // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$7).words[0] & num; - }; // Increment at the bit position in-line - + return (this || _global$e).words[0] & num; + }; + // Increment at the bit position in-line BN.prototype.bincn = function bincn(bit) { assert(typeof bit === "number"); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$7).length <= s) { + // Fast case: bit is much higher than all existing words + if ((this || _global$e).length <= s) { this._expand(s + 1); + (this || _global$e).words[s] |= q; + return this || _global$e; + } - (this || _global$7).words[s] |= q; - return this || _global$7; - } // Add bit and propagate, if needed - - + // Add bit and propagate, if needed var carry = q; - - for (var i = s; carry !== 0 && i < (this || _global$7).length; i++) { - var w = (this || _global$7).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$e).length; i++) { + var w = (this || _global$e).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$7).words[i] = w; + (this || _global$e).words[i] = w; } - if (carry !== 0) { - (this || _global$7).words[i] = carry; - (this || _global$7).length++; + (this || _global$e).words[i] = carry; + (this || _global$e).length++; } - - return this || _global$7; + return this || _global$e; }; - BN.prototype.isZero = function isZero() { - return (this || _global$7).length === 1 && (this || _global$7).words[0] === 0; + return (this || _global$e).length === 1 && (this || _global$e).words[0] === 0; }; - BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$7).negative !== 0 && !negative) return -1; - if ((this || _global$7).negative === 0 && negative) return 1; - + if ((this || _global$e).negative !== 0 && !negative) return -1; + if ((this || _global$e).negative === 0 && negative) return 1; this._strip(); - var res; - - if ((this || _global$7).length > 1) { + if ((this || _global$e).length > 1) { res = 1; } else { if (negative) { num = -num; } - assert(num <= 67108863, "Number is too big"); - var w = (this || _global$7).words[0] | 0; + var w = (this || _global$e).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - - if ((this || _global$7).negative !== 0) return -res | 0; + if ((this || _global$e).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: + }; + + // Compare two numbers and return: // 1 - if `this` > `num` // 0 - if `this` == `num` // -1 - if `this` < `num` - - BN.prototype.cmp = function cmp(num) { - if ((this || _global$7).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$7).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$e).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$e).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$7).negative !== 0) return -res | 0; + if ((this || _global$e).negative !== 0) return -res | 0; return res; - }; // Unsigned comparison - + }; + // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$7).length > num.length) return 1; - if ((this || _global$7).length < num.length) return -1; + if ((this || _global$e).length > num.length) return 1; + if ((this || _global$e).length < num.length) return -1; var res = 0; - - for (var i = (this || _global$7).length - 1; i >= 0; i--) { - var a = (this || _global$7).words[i] | 0; + for (var i = (this || _global$e).length - 1; i >= 0; i--) { + var a = (this || _global$e).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; - if (a < b) { res = -1; } else if (a > b) { res = 1; } - break; } - return res; }; - BN.prototype.gtn = function gtn(num) { return this.cmpn(num) === 1; }; - BN.prototype.gt = function gt(num) { return this.cmp(num) === 1; }; - BN.prototype.gten = function gten(num) { return this.cmpn(num) >= 0; }; - BN.prototype.gte = function gte(num) { return this.cmp(num) >= 0; }; - BN.prototype.ltn = function ltn(num) { return this.cmpn(num) === -1; }; - BN.prototype.lt = function lt(num) { return this.cmp(num) === -1; }; - BN.prototype.lten = function lten(num) { return this.cmpn(num) <= 0; }; - BN.prototype.lte = function lte(num) { return this.cmp(num) <= 0; }; - BN.prototype.eqn = function eqn(num) { return this.cmpn(num) === 0; }; - BN.prototype.eq = function eq(num) { return this.cmp(num) === 0; - }; // + }; + + // // A reduce context, could be using montgomery or something better, depending // on the `m` itself. // - - BN.red = function red(num) { return new Red(num); }; - BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$7).red, "Already a number in reduction context"); - assert((this || _global$7).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$7)._forceRed(ctx); + assert(!(this || _global$e).red, "Already a number in reduction context"); + assert((this || _global$e).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$e)._forceRed(ctx); }; - BN.prototype.fromRed = function fromRed() { - assert((this || _global$7).red, "fromRed works only with numbers in reduction context"); - return (this || _global$7).red.convertFrom(this || _global$7); + assert((this || _global$e).red, "fromRed works only with numbers in reduction context"); + return (this || _global$e).red.convertFrom(this || _global$e); }; - BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$7).red = ctx; - return this || _global$7; + (this || _global$e).red = ctx; + return this || _global$e; }; - BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$7).red, "Already a number in reduction context"); + assert(!(this || _global$e).red, "Already a number in reduction context"); return this._forceRed(ctx); }; - BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$7).red, "redAdd works only with red numbers"); - return (this || _global$7).red.add(this || _global$7, num); + assert((this || _global$e).red, "redAdd works only with red numbers"); + return (this || _global$e).red.add(this || _global$e, num); }; - BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$7).red, "redIAdd works only with red numbers"); - return (this || _global$7).red.iadd(this || _global$7, num); + assert((this || _global$e).red, "redIAdd works only with red numbers"); + return (this || _global$e).red.iadd(this || _global$e, num); }; - BN.prototype.redSub = function redSub(num) { - assert((this || _global$7).red, "redSub works only with red numbers"); - return (this || _global$7).red.sub(this || _global$7, num); + assert((this || _global$e).red, "redSub works only with red numbers"); + return (this || _global$e).red.sub(this || _global$e, num); }; - BN.prototype.redISub = function redISub(num) { - assert((this || _global$7).red, "redISub works only with red numbers"); - return (this || _global$7).red.isub(this || _global$7, num); + assert((this || _global$e).red, "redISub works only with red numbers"); + return (this || _global$e).red.isub(this || _global$e, num); }; - BN.prototype.redShl = function redShl(num) { - assert((this || _global$7).red, "redShl works only with red numbers"); - return (this || _global$7).red.shl(this || _global$7, num); + assert((this || _global$e).red, "redShl works only with red numbers"); + return (this || _global$e).red.shl(this || _global$e, num); }; - BN.prototype.redMul = function redMul(num) { - assert((this || _global$7).red, "redMul works only with red numbers"); - - (this || _global$7).red._verify2(this || _global$7, num); - - return (this || _global$7).red.mul(this || _global$7, num); + assert((this || _global$e).red, "redMul works only with red numbers"); + (this || _global$e).red._verify2(this || _global$e, num); + return (this || _global$e).red.mul(this || _global$e, num); }; - BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$7).red, "redMul works only with red numbers"); - - (this || _global$7).red._verify2(this || _global$7, num); - - return (this || _global$7).red.imul(this || _global$7, num); + assert((this || _global$e).red, "redMul works only with red numbers"); + (this || _global$e).red._verify2(this || _global$e, num); + return (this || _global$e).red.imul(this || _global$e, num); }; - BN.prototype.redSqr = function redSqr() { - assert((this || _global$7).red, "redSqr works only with red numbers"); - - (this || _global$7).red._verify1(this || _global$7); - - return (this || _global$7).red.sqr(this || _global$7); + assert((this || _global$e).red, "redSqr works only with red numbers"); + (this || _global$e).red._verify1(this || _global$e); + return (this || _global$e).red.sqr(this || _global$e); }; - BN.prototype.redISqr = function redISqr() { - assert((this || _global$7).red, "redISqr works only with red numbers"); - - (this || _global$7).red._verify1(this || _global$7); - - return (this || _global$7).red.isqr(this || _global$7); - }; // Square root over p - + assert((this || _global$e).red, "redISqr works only with red numbers"); + (this || _global$e).red._verify1(this || _global$e); + return (this || _global$e).red.isqr(this || _global$e); + }; + // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$7).red, "redSqrt works only with red numbers"); - - (this || _global$7).red._verify1(this || _global$7); - - return (this || _global$7).red.sqrt(this || _global$7); + assert((this || _global$e).red, "redSqrt works only with red numbers"); + (this || _global$e).red._verify1(this || _global$e); + return (this || _global$e).red.sqrt(this || _global$e); }; - BN.prototype.redInvm = function redInvm() { - assert((this || _global$7).red, "redInvm works only with red numbers"); - - (this || _global$7).red._verify1(this || _global$7); - - return (this || _global$7).red.invm(this || _global$7); - }; // Return negative clone of `this` % `red modulo` - + assert((this || _global$e).red, "redInvm works only with red numbers"); + (this || _global$e).red._verify1(this || _global$e); + return (this || _global$e).red.invm(this || _global$e); + }; + // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$7).red, "redNeg works only with red numbers"); - - (this || _global$7).red._verify1(this || _global$7); - - return (this || _global$7).red.neg(this || _global$7); + assert((this || _global$e).red, "redNeg works only with red numbers"); + (this || _global$e).red._verify1(this || _global$e); + return (this || _global$e).red.neg(this || _global$e); }; - BN.prototype.redPow = function redPow(num) { - assert((this || _global$7).red && !num.red, "redPow(normalNum)"); - - (this || _global$7).red._verify1(this || _global$7); - - return (this || _global$7).red.pow(this || _global$7, num); - }; // Prime numbers with efficient reduction - + assert((this || _global$e).red && !num.red, "redPow(normalNum)"); + (this || _global$e).red._verify1(this || _global$e); + return (this || _global$e).red.pow(this || _global$e, num); + }; + // Prime numbers with efficient reduction var primes = { k256: null, p224: null, p192: null, p25519: null - }; // Pseudo-Mersenne prime + }; + // Pseudo-Mersenne prime function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$7).name = name; - (this || _global$7).p = new BN(p, 16); - (this || _global$7).n = (this || _global$7).p.bitLength(); - (this || _global$7).k = new BN(1).iushln((this || _global$7).n).isub((this || _global$7).p); - (this || _global$7).tmp = this._tmp(); + (this || _global$e).name = name; + (this || _global$e).p = new BN(p, 16); + (this || _global$e).n = (this || _global$e).p.bitLength(); + (this || _global$e).k = new BN(1).iushln((this || _global$e).n).isub((this || _global$e).p); + (this || _global$e).tmp = this._tmp(); } - MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$7).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$e).n / 13)); return tmp; }; - MPrime.prototype.ireduce = function ireduce(num) { // Assumes that `num` is less than `P^2` // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) var r = num; var rlen; - do { - this.split(r, (this || _global$7).tmp); + this.split(r, (this || _global$e).tmp); r = this.imulK(r); - r = r.iadd((this || _global$7).tmp); + r = r.iadd((this || _global$e).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$7).n); - - var cmp = rlen < (this || _global$7).n ? -1 : r.ucmp((this || _global$7).p); - + } while (rlen > (this || _global$e).n); + var cmp = rlen < (this || _global$e).n ? -1 : r.ucmp((this || _global$e).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$7).p); + r.isub((this || _global$e).p); } else { if (r.strip !== undefined) { // r is a BN v4 instance @@ -54791,111 +90998,88 @@ function dew$X() { r._strip(); } } - return r; }; - MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$7).n, 0, out); + input.iushrn((this || _global$e).n, 0, out); }; - MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$7).k); + return num.imul((this || _global$e).k); }; - function K256() { - MPrime.call(this || _global$7, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$e, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - inherits(K256, MPrime); - K256.prototype.split = function split(input, output) { // 256 = 9 * 26 + 22 var mask = 4194303; var outLen = Math.min(input.length, 9); - for (var i = 0; i < outLen; i++) { output.words[i] = input.words[i]; } - output.length = outLen; - if (input.length <= 9) { input.words[0] = 0; input.length = 1; return; - } // Shift by 9 limbs - + } + // Shift by 9 limbs var prev = input.words[9]; output.words[output.length++] = prev & mask; - for (i = 10; i < input.length; i++) { var next = input.words[i] | 0; input.words[i - 10] = (next & mask) << 4 | prev >>> 22; prev = next; } - prev >>>= 22; input.words[i - 10] = prev; - if (prev === 0 && input.length > 10) { input.length -= 10; } else { input.length -= 9; } }; - K256.prototype.imulK = function imulK(num) { // K = 0x1000003d1 = [ 0x40, 0x3d1 ] num.words[num.length] = 0; num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + num.length += 2; + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 var lo = 0; - for (var i = 0; i < num.length; i++) { var w = num.words[i] | 0; lo += w * 977; num.words[i] = lo & 67108863; lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction - + } + // Fast length reduction if (num.words[num.length - 1] === 0) { num.length--; - if (num.words[num.length - 1] === 0) { num.length--; } } - return num; }; - function P224() { - MPrime.call(this || _global$7, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$e, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } - inherits(P224, MPrime); - function P192() { - MPrime.call(this || _global$7, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$e, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } - inherits(P192, MPrime); - function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$7, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$e, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } - inherits(P25519, MPrime); - P25519.prototype.imulK = function imulK(num) { // K = 0x13 var carry = 0; - for (var i = 0; i < num.length; i++) { var hi = (num.words[i] | 0) * 19 + carry; var lo = hi & 67108863; @@ -54903,20 +91087,17 @@ function dew$X() { num.words[i] = lo; carry = hi; } - if (carry !== 0) { num.words[num.length++] = carry; } - return num; - }; // Exported mostly for testing purposes, use plain name instead - + }; + // Exported mostly for testing purposes, use plain name instead BN._prime = function prime(name) { // Cached version of prime if (primes[name]) return primes[name]; var prime; - if (name === "k256") { prime = new K256(); } else if (name === "p224") { @@ -54928,177 +91109,134 @@ function dew$X() { } else { throw new Error("Unknown prime " + name); } - primes[name] = prime; return prime; - }; // + }; + + // // Base reduction engine // - - function Red(m) { if (typeof m === "string") { var prime = BN._prime(m); - - (this || _global$7).m = prime.p; - (this || _global$7).prime = prime; + (this || _global$e).m = prime.p; + (this || _global$e).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$7).m = m; - (this || _global$7).prime = null; + (this || _global$e).m = m; + (this || _global$e).prime = null; } } - Red.prototype._verify1 = function _verify1(a) { assert(a.negative === 0, "red works only with positives"); assert(a.red, "red works only with red numbers"); }; - Red.prototype._verify2 = function _verify2(a, b) { assert((a.negative | b.negative) === 0, "red works only with positives"); assert(a.red && a.red === b.red, "red works only with red numbers"); }; - Red.prototype.imod = function imod(a) { - if ((this || _global$7).prime) return (this || _global$7).prime.ireduce(a)._forceRed(this || _global$7); - move(a, a.umod((this || _global$7).m)._forceRed(this || _global$7)); + if ((this || _global$e).prime) return (this || _global$e).prime.ireduce(a)._forceRed(this || _global$e); + move(a, a.umod((this || _global$e).m)._forceRed(this || _global$e)); return a; }; - Red.prototype.neg = function neg(a) { if (a.isZero()) { return a.clone(); } - - return (this || _global$7).m.sub(a)._forceRed(this || _global$7); + return (this || _global$e).m.sub(a)._forceRed(this || _global$e); }; - Red.prototype.add = function add(a, b) { this._verify2(a, b); - var res = a.add(b); - - if (res.cmp((this || _global$7).m) >= 0) { - res.isub((this || _global$7).m); + if (res.cmp((this || _global$e).m) >= 0) { + res.isub((this || _global$e).m); } - - return res._forceRed(this || _global$7); + return res._forceRed(this || _global$e); }; - Red.prototype.iadd = function iadd(a, b) { this._verify2(a, b); - var res = a.iadd(b); - - if (res.cmp((this || _global$7).m) >= 0) { - res.isub((this || _global$7).m); + if (res.cmp((this || _global$e).m) >= 0) { + res.isub((this || _global$e).m); } - return res; }; - Red.prototype.sub = function sub(a, b) { this._verify2(a, b); - var res = a.sub(b); - if (res.cmpn(0) < 0) { - res.iadd((this || _global$7).m); + res.iadd((this || _global$e).m); } - - return res._forceRed(this || _global$7); + return res._forceRed(this || _global$e); }; - Red.prototype.isub = function isub(a, b) { this._verify2(a, b); - var res = a.isub(b); - if (res.cmpn(0) < 0) { - res.iadd((this || _global$7).m); + res.iadd((this || _global$e).m); } - return res; }; - Red.prototype.shl = function shl(a, num) { this._verify1(a); - return this.imod(a.ushln(num)); }; - Red.prototype.imul = function imul(a, b) { this._verify2(a, b); - return this.imod(a.imul(b)); }; - Red.prototype.mul = function mul(a, b) { this._verify2(a, b); - return this.imod(a.mul(b)); }; - Red.prototype.isqr = function isqr(a) { return this.imul(a, a.clone()); }; - Red.prototype.sqr = function sqr(a) { return this.mul(a, a); }; - Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); + var mod3 = (this || _global$e).m.andln(3); + assert(mod3 % 2 === 1); - var mod3 = (this || _global$7).m.andln(3); - - assert(mod3 % 2 === 1); // Fast case - + // Fast case if (mod3 === 3) { - var pow = (this || _global$7).m.add(new BN(1)).iushrn(2); - + var pow = (this || _global$e).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) // // Find Q and S, that Q * 2 ^ S = (P - 1) - - - var q = (this || _global$7).m.subn(1); - + var q = (this || _global$e).m.subn(1); var s = 0; - while (!q.isZero() && q.andln(1) === 0) { s++; q.iushrn(1); } - assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$7); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. - - var lpow = (this || _global$7).m.subn(1).iushrn(1); - - var z = (this || _global$7).m.bitLength(); - - z = new BN(2 * z * z).toRed(this || _global$7); + var one = new BN(1).toRed(this || _global$e); + var nOne = one.redNeg(); + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + var lpow = (this || _global$e).m.subn(1).iushrn(1); + var z = (this || _global$e).m.bitLength(); + z = new BN(2 * z * z).toRed(this || _global$e); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); } - var c = this.pow(z, q); var r = this.pow(a, q.addn(1).iushrn(1)); var t = this.pow(a, q); var m = s; - while (t.cmp(one) !== 0) { var tmp = t; - for (var i = 0; tmp.cmp(one) !== 0; i++) { tmp = tmp.redSqr(); } - assert(i < m); var b = this.pow(c, new BN(1).iushln(m - i - 1)); r = r.redMul(b); @@ -55106,13 +91244,10 @@ function dew$X() { t = t.redMul(c); m = i; } - return r; }; - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$7).m); - + var inv = a._invmp((this || _global$e).m); if (inv.negative !== 0) { inv.negative = 0; return this.imod(inv).redNeg(); @@ -55120,43 +91255,34 @@ function dew$X() { return this.imod(inv); } }; - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$7); + if (num.isZero()) return new BN(1).toRed(this || _global$e); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$7); + wnd[0] = new BN(1).toRed(this || _global$e); wnd[1] = a; - for (var i = 2; i < wnd.length; i++) { wnd[i] = this.mul(wnd[i - 1], a); } - var res = wnd[0]; var current = 0; var currentLen = 0; var start = num.bitLength() % 26; - if (start === 0) { start = 26; } - for (i = num.length - 1; i >= 0; i--) { var word = num.words[i]; - for (var j = start - 1; j >= 0; j--) { var bit = word >> j & 1; - if (res !== wnd[0]) { res = this.sqr(res); } - if (bit === 0 && current === 0) { currentLen = 0; continue; } - current <<= 1; current |= bit; currentLen++; @@ -55165,137 +91291,112 @@ function dew$X() { currentLen = 0; current = 0; } - start = 26; } - return res; }; - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$7).m); + var r = num.umod((this || _global$e).m); return r === num ? r.clone() : r; }; - Red.prototype.convertFrom = function convertFrom(num) { var res = num.clone(); res.red = null; return res; - }; // + }; + + // // Montgomery method engine // - BN.mont = function mont(num) { return new Mont(num); }; - function Mont(m) { - Red.call(this || _global$7, m); - (this || _global$7).shift = (this || _global$7).m.bitLength(); - - if ((this || _global$7).shift % 26 !== 0) { - (this || _global$7).shift += 26 - (this || _global$7).shift % 26; - } - - (this || _global$7).r = new BN(1).iushln((this || _global$7).shift); - (this || _global$7).r2 = this.imod((this || _global$7).r.sqr()); - (this || _global$7).rinv = (this || _global$7).r._invmp((this || _global$7).m); - (this || _global$7).minv = (this || _global$7).rinv.mul((this || _global$7).r).isubn(1).div((this || _global$7).m); - (this || _global$7).minv = (this || _global$7).minv.umod((this || _global$7).r); - (this || _global$7).minv = (this || _global$7).r.sub((this || _global$7).minv); + Red.call(this || _global$e, m); + (this || _global$e).shift = (this || _global$e).m.bitLength(); + if ((this || _global$e).shift % 26 !== 0) { + (this || _global$e).shift += 26 - (this || _global$e).shift % 26; + } + (this || _global$e).r = new BN(1).iushln((this || _global$e).shift); + (this || _global$e).r2 = this.imod((this || _global$e).r.sqr()); + (this || _global$e).rinv = (this || _global$e).r._invmp((this || _global$e).m); + (this || _global$e).minv = (this || _global$e).rinv.mul((this || _global$e).r).isubn(1).div((this || _global$e).m); + (this || _global$e).minv = (this || _global$e).minv.umod((this || _global$e).r); + (this || _global$e).minv = (this || _global$e).r.sub((this || _global$e).minv); } - inherits(Mont, Red); - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$7).shift)); + return this.imod(num.ushln((this || _global$e).shift)); }; - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$7).rinv)); + var r = this.imod(num.mul((this || _global$e).rinv)); r.red = null; return r; }; - Mont.prototype.imul = function imul(a, b) { if (a.isZero() || b.isZero()) { a.words[0] = 0; a.length = 1; return a; } - var t = a.imul(b); - var c = t.maskn((this || _global$7).shift).mul((this || _global$7).minv).imaskn((this || _global$7).shift).mul((this || _global$7).m); - var u = t.isub(c).iushrn((this || _global$7).shift); + var c = t.maskn((this || _global$e).shift).mul((this || _global$e).minv).imaskn((this || _global$e).shift).mul((this || _global$e).m); + var u = t.isub(c).iushrn((this || _global$e).shift); var res = u; - - if (u.cmp((this || _global$7).m) >= 0) { - res = u.isub((this || _global$7).m); + if (u.cmp((this || _global$e).m) >= 0) { + res = u.isub((this || _global$e).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$7).m); + res = u.iadd((this || _global$e).m); } - - return res._forceRed(this || _global$7); + return res._forceRed(this || _global$e); }; - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$7); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$e); var t = a.mul(b); - var c = t.maskn((this || _global$7).shift).mul((this || _global$7).minv).imaskn((this || _global$7).shift).mul((this || _global$7).m); - var u = t.isub(c).iushrn((this || _global$7).shift); + var c = t.maskn((this || _global$e).shift).mul((this || _global$e).minv).imaskn((this || _global$e).shift).mul((this || _global$e).m); + var u = t.isub(c).iushrn((this || _global$e).shift); var res = u; - - if (u.cmp((this || _global$7).m) >= 0) { - res = u.isub((this || _global$7).m); + if (u.cmp((this || _global$e).m) >= 0) { + res = u.isub((this || _global$e).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$7).m); + res = u.iadd((this || _global$e).m); } - - return res._forceRed(this || _global$7); + return res._forceRed(this || _global$e); }; - Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$7).m).mul((this || _global$7).r2)); - return res._forceRed(this || _global$7); + var res = this.imod(a._invmp((this || _global$e).m).mul((this || _global$e).r2)); + return res._forceRed(this || _global$e); }; - })(module$4, exports$Y); - + })(module$4, exports$11); return module$4.exports; } -var exports$X = {}, - _dewExec$W = false; -function dew$W() { - if (_dewExec$W) return exports$X; - _dewExec$W = true; - var Buffer = buffer.Buffer; - - var BN = dew$X(); - - var randomBytes = dew$2O(); - - function blind(priv) { - var r = getr(priv); - var blinder = r.toRed(BN.mont(priv.modulus)).redPow(new BN(priv.publicExponent)).fromRed(); - return { - blinder: blinder, - unblinder: r.invm(priv.modulus) - }; - } - +var exports$10 = {}, + _dewExec$$ = false; +function dew$$() { + if (_dewExec$$) return exports$10; + _dewExec$$ = true; + var BN = dew$10(); + var randomBytes = dew$3G(); + var Buffer = dew$3H().Buffer; function getr(priv) { var len = priv.modulus.byteLength(); var r; - do { r = new BN(randomBytes(len)); } while (r.cmp(priv.modulus) >= 0 || !r.umod(priv.prime1) || !r.umod(priv.prime2)); - return r; } - + function blind(priv) { + var r = getr(priv); + var blinder = r.toRed(BN.mont(priv.modulus)).redPow(new BN(priv.publicExponent)).fromRed(); + return { + blinder: blinder, + unblinder: r.invm(priv.modulus) + }; + } function crt(msg, priv) { var blinds = blind(priv); var len = priv.modulus.byteLength(); @@ -55310,15 +91411,14 @@ function dew$W() { var h = m1.isub(m2).imul(qinv).umod(p).imul(q); return m2.iadd(h).imul(blinds.unblinder).umod(priv.modulus).toArrayLike(Buffer, "be", len); } - crt.getr = getr; - exports$X = crt; - return exports$X; + exports$10 = crt; + return exports$10; } var _package = { "name": "elliptic", - "version": "6.5.4", + "version": "6.5.7", "description": "EC cryptography", "main": "lib/elliptic.js", "files": [ @@ -55373,180 +91473,151 @@ var _package = { } }; -var exports$W = {}, - _dewExec$V = false; +var exports$$ = {}, + _dewExec$_ = false; var module$3 = { - exports: exports$W + exports: exports$$ }; - -var _global$6 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - -function dew$V() { - if (_dewExec$V) return module$3.exports; - _dewExec$V = true; - +var _global$d = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$_() { + if (_dewExec$_) return module$3.exports; + _dewExec$_ = true; (function (module, exports) { + // Utils function assert(val, msg) { if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. - + } + // Could use `inherits` module, but don't want to move from single file + // architecture yet. function inherits(ctor, superCtor) { ctor.super_ = superCtor; - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; - } // BN + } + // BN function BN(number, base, endian) { if (BN.isBN(number)) { return number; } + (this || _global$d).negative = 0; + (this || _global$d).words = null; + (this || _global$d).length = 0; - (this || _global$6).negative = 0; - (this || _global$6).words = null; - (this || _global$6).length = 0; // Reduction context - - (this || _global$6).red = null; - + // Reduction context + (this || _global$d).red = null; if (number !== null) { if (base === "le" || base === "be") { endian = base; base = 10; } - this._init(number || 0, base || 10, endian || "be"); } } - if (typeof module === "object") { module.exports = BN; } else { exports.BN = BN; } - BN.BN = BN; BN.wordSize = 26; var Buffer; - try { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = buffer.Buffer; + Buffer = dew$3J().Buffer; } } catch (e) {} - BN.isBN = function isBN(num) { if (num instanceof BN) { return true; } - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); }; - BN.max = function max(left, right) { if (left.cmp(right) > 0) return left; return right; }; - BN.min = function min(left, right) { if (left.cmp(right) < 0) return left; return right; }; - BN.prototype._init = function init(number, base, endian) { if (typeof number === "number") { return this._initNumber(number, base, endian); } - if (typeof number === "object") { return this._initArray(number, base, endian); } - if (base === "hex") { base = 16; } - assert(base === (base | 0) && base >= 2 && base <= 36); number = number.toString().replace(/\s+/g, ""); var start = 0; - if (number[0] === "-") { start++; - (this || _global$6).negative = 1; + (this || _global$d).negative = 1; } - if (start < number.length) { if (base === 16) { this._parseHex(number, start, endian); } else { this._parseBase(number, base, start); - if (endian === "le") { this._initArray(this.toArray(), base, endian); } } } }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$6).negative = 1; + (this || _global$d).negative = 1; number = -number; } - if (number < 67108864) { - (this || _global$6).words = [number & 67108863]; - (this || _global$6).length = 1; + (this || _global$d).words = [number & 67108863]; + (this || _global$d).length = 1; } else if (number < 4503599627370496) { - (this || _global$6).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$6).length = 2; + (this || _global$d).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$d).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - - (this || _global$6).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$6).length = 3; + (this || _global$d).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$d).length = 3; } + if (endian !== "le") return; - if (endian !== "le") return; // Reverse the bytes - + // Reverse the bytes this._initArray(this.toArray(), base, endian); }; - BN.prototype._initArray = function _initArray(number, base, endian) { // Perhaps a Uint8Array assert(typeof number.length === "number"); - if (number.length <= 0) { - (this || _global$6).words = [0]; - (this || _global$6).length = 1; - return this || _global$6; + (this || _global$d).words = [0]; + (this || _global$d).length = 1; + return this || _global$d; } - - (this || _global$6).length = Math.ceil(number.length / 3); - (this || _global$6).words = new Array((this || _global$6).length); - - for (var i = 0; i < (this || _global$6).length; i++) { - (this || _global$6).words[i] = 0; + (this || _global$d).length = Math.ceil(number.length / 3); + (this || _global$d).words = new Array((this || _global$d).length); + for (var i = 0; i < (this || _global$d).length; i++) { + (this || _global$d).words[i] = 0; } - var j, w; var off = 0; - if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$6).words[j] |= w << off & 67108863; - (this || _global$6).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$d).words[j] |= w << off & 67108863; + (this || _global$d).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; @@ -55555,203 +91626,177 @@ function dew$V() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$6).words[j] |= w << off & 67108863; - (this || _global$6).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$d).words[j] |= w << off & 67108863; + (this || _global$d).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; } } } - return this.strip(); }; - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // 'A' - 'F' - + var c = string.charCodeAt(index); + // 'A' - 'F' if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' + return c - 55; + // 'a' - 'f' } else if (c >= 97 && c <= 102) { - return c - 87; // '0' - '9' + return c - 87; + // '0' - '9' } else { return c - 48 & 15; } } - function parseHexByte(string, lowerBound, index) { var r = parseHex4Bits(string, index); - if (index - 1 >= lowerBound) { r |= parseHex4Bits(string, index - 1) << 4; } - return r; } - BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$6).length = Math.ceil((number.length - start) / 6); - (this || _global$6).words = new Array((this || _global$6).length); - - for (var i = 0; i < (this || _global$6).length; i++) { - (this || _global$6).words[i] = 0; - } // 24-bits chunks - + (this || _global$d).length = Math.ceil((number.length - start) / 6); + (this || _global$d).words = new Array((this || _global$d).length); + for (var i = 0; i < (this || _global$d).length; i++) { + (this || _global$d).words[i] = 0; + } + // 24-bits chunks var off = 0; var j = 0; var w; - if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$6).words[j] |= w & 67108863; - + (this || _global$d).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$6).words[j] |= w >>> 26; + (this || _global$d).words[j] |= w >>> 26; } else { off += 8; } } } else { var parseLength = number.length - start; - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$6).words[j] |= w & 67108863; - + (this || _global$d).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$6).words[j] |= w >>> 26; + (this || _global$d).words[j] |= w >>> 26; } else { off += 8; } } } - this.strip(); }; - function parseBase(str, start, end, mul) { var r = 0; var len = Math.min(str.length, end); - for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + r *= mul; + // 'a' if (c >= 49) { - r += c - 49 + 10; // 'A' + r += c - 49 + 10; + + // 'A' } else if (c >= 17) { - r += c - 17 + 10; // '0' - '9' + r += c - 17 + 10; + + // '0' - '9' } else { r += c; } } - return r; } - BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$6).words = [0]; - (this || _global$6).length = 1; // Find length of limb in base + (this || _global$d).words = [0]; + (this || _global$d).length = 1; + // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; } - limbLen--; limbPow = limbPow / base | 0; var total = number.length - start; var mod = total % limbLen; var end = Math.min(total, total - mod) + start; var word = 0; - for (var i = start; i < end; i += limbLen) { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - - if ((this || _global$6).words[0] + word < 67108864) { - (this || _global$6).words[0] += word; + if ((this || _global$d).words[0] + word < 67108864) { + (this || _global$d).words[0] += word; } else { this._iaddn(word); } } - if (mod !== 0) { var pow = 1; word = parseBase(number, i, number.length, base); - for (i = 0; i < mod; i++) { pow *= base; } - this.imuln(pow); - - if ((this || _global$6).words[0] + word < 67108864) { - (this || _global$6).words[0] += word; + if ((this || _global$d).words[0] + word < 67108864) { + (this || _global$d).words[0] += word; } else { this._iaddn(word); } } - this.strip(); }; - BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$6).length); - - for (var i = 0; i < (this || _global$6).length; i++) { - dest.words[i] = (this || _global$6).words[i]; + dest.words = new Array((this || _global$d).length); + for (var i = 0; i < (this || _global$d).length; i++) { + dest.words[i] = (this || _global$d).words[i]; } - - dest.length = (this || _global$6).length; - dest.negative = (this || _global$6).negative; - dest.red = (this || _global$6).red; + dest.length = (this || _global$d).length; + dest.negative = (this || _global$d).negative; + dest.red = (this || _global$d).red; }; - BN.prototype.clone = function clone() { var r = new BN(null); this.copy(r); return r; }; - BN.prototype._expand = function _expand(size) { - while ((this || _global$6).length < size) { - (this || _global$6).words[(this || _global$6).length++] = 0; + while ((this || _global$d).length < size) { + (this || _global$d).words[(this || _global$d).length++] = 0; } + return this || _global$d; + }; - return this || _global$6; - }; // Remove leading `0` from `this` - - + // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$6).length > 1 && (this || _global$6).words[(this || _global$6).length - 1] === 0) { - (this || _global$6).length--; + while ((this || _global$d).length > 1 && (this || _global$d).words[(this || _global$d).length - 1] === 0) { + (this || _global$d).length--; } - return this._normSign(); }; - BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$6).length === 1 && (this || _global$6).words[0] === 0) { - (this || _global$6).negative = 0; + if ((this || _global$d).length === 1 && (this || _global$d).words[0] === 0) { + (this || _global$d).negative = 0; } - - return this || _global$6; + return this || _global$d; }; - BN.prototype.inspect = function inspect() { - return ((this || _global$6).red ? ""; + return ((this || _global$d).red ? ""; }; + /* var zeros = []; var groupSizes = []; @@ -55779,121 +91824,95 @@ function dew$V() { } */ - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - BN.prototype.toString = function toString(base, padding) { base = base || 10; padding = padding | 0 || 1; var out; - if (base === 16 || base === "hex") { out = ""; var off = 0; var carry = 0; - - for (var i = 0; i < (this || _global$6).length; i++) { - var w = (this || _global$6).words[i]; + for (var i = 0; i < (this || _global$d).length; i++) { + var w = (this || _global$d).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - - if (carry !== 0 || i !== (this || _global$6).length - 1) { + if (carry !== 0 || i !== (this || _global$d).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; } - off += 2; - if (off >= 26) { off -= 26; i--; } } - if (carry !== 0) { out = carry.toString(16) + out; } - while (out.length % padding !== 0) { out = "0" + out; } - - if ((this || _global$6).negative !== 0) { + if ((this || _global$d).negative !== 0) { out = "-" + out; } - return out; } - if (base === (base | 0) && base >= 2 && base <= 36) { // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); var groupBase = groupBases[base]; out = ""; var c = this.clone(); c.negative = 0; - while (!c.isZero()) { var r = c.modn(groupBase).toString(base); c = c.idivn(groupBase); - if (!c.isZero()) { out = zeros[groupSize - r.length] + r + out; } else { out = r + out; } } - if (this.isZero()) { out = "0" + out; } - while (out.length % padding !== 0) { out = "0" + out; } - - if ((this || _global$6).negative !== 0) { + if ((this || _global$d).negative !== 0) { out = "-" + out; } - return out; } - assert(false, "Base should be between 2 and 36"); }; - BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$6).words[0]; - - if ((this || _global$6).length === 2) { - ret += (this || _global$6).words[1] * 67108864; - } else if ((this || _global$6).length === 3 && (this || _global$6).words[2] === 1) { + var ret = (this || _global$d).words[0]; + if ((this || _global$d).length === 2) { + ret += (this || _global$d).words[1] * 67108864; + } else if ((this || _global$d).length === 3 && (this || _global$d).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$6).words[1] * 67108864; - } else if ((this || _global$6).length > 2) { + ret += 4503599627370496 + (this || _global$d).words[1] * 67108864; + } else if ((this || _global$d).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - - return (this || _global$6).negative !== 0 ? -ret : ret; + return (this || _global$d).negative !== 0 ? -ret : ret; }; - BN.prototype.toJSON = function toJSON() { return this.toString(16); }; - BN.prototype.toBuffer = function toBuffer(endian, length) { assert(typeof Buffer !== "undefined"); return this.toArrayLike(Buffer, endian, length); }; - BN.prototype.toArray = function toArray(endian, length) { return this.toArrayLike(Array, endian, length); }; - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { var byteLength = this.byteLength(); var reqLength = length || Math.max(1, byteLength); @@ -55904,13 +91923,11 @@ function dew$V() { var res = new ArrayType(reqLength); var b, i; var q = this.clone(); - if (!littleEndian) { // Assume big-endian for (i = 0; i < reqLength - byteLength; i++) { res[i] = 0; } - for (i = 0; !q.isZero(); i++) { b = q.andln(255); q.iushrn(8); @@ -55922,15 +91939,12 @@ function dew$V() { q.iushrn(8); res[i] = b; } - for (; i < reqLength; i++) { res[i] = 0; } } - return res; }; - if (Math.clz32) { BN.prototype._countBits = function _countBits(w) { return 32 - Math.clz32(w); @@ -55939,458 +91953,400 @@ function dew$V() { BN.prototype._countBits = function _countBits(w) { var t = w; var r = 0; - if (t >= 4096) { r += 13; t >>>= 13; } - if (t >= 64) { r += 7; t >>>= 7; } - if (t >= 8) { r += 4; t >>>= 4; } - if (t >= 2) { r += 2; t >>>= 2; } - return r + t; }; } - BN.prototype._zeroBits = function _zeroBits(w) { // Short-cut if (w === 0) return 26; var t = w; var r = 0; - if ((t & 8191) === 0) { r += 13; t >>>= 13; } - if ((t & 127) === 0) { r += 7; t >>>= 7; } - if ((t & 15) === 0) { r += 4; t >>>= 4; } - if ((t & 3) === 0) { r += 2; t >>>= 2; } - if ((t & 1) === 0) { r++; } - return r; - }; // Return number of used bits in a BN - + }; + // Return number of used bits in a BN BN.prototype.bitLength = function bitLength() { - var w = (this || _global$6).words[(this || _global$6).length - 1]; - + var w = (this || _global$d).words[(this || _global$d).length - 1]; var hi = this._countBits(w); - - return ((this || _global$6).length - 1) * 26 + hi; + return ((this || _global$d).length - 1) * 26 + hi; }; - function toBitArray(num) { var w = new Array(num.bitLength()); - for (var bit = 0; bit < w.length; bit++) { var off = bit / 26 | 0; var wbit = bit % 26; w[bit] = (num.words[off] & 1 << wbit) >>> wbit; } - return w; - } // Number of trailing zero bits - + } + // Number of trailing zero bits BN.prototype.zeroBits = function zeroBits() { if (this.isZero()) return 0; var r = 0; - - for (var i = 0; i < (this || _global$6).length; i++) { - var b = this._zeroBits((this || _global$6).words[i]); - + for (var i = 0; i < (this || _global$d).length; i++) { + var b = this._zeroBits((this || _global$d).words[i]); r += b; if (b !== 26) break; } - return r; }; - BN.prototype.byteLength = function byteLength() { return Math.ceil(this.bitLength() / 8); }; - BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$6).negative !== 0) { + if ((this || _global$d).negative !== 0) { return this.abs().inotn(width).iaddn(1); } - return this.clone(); }; - BN.prototype.fromTwos = function fromTwos(width) { if (this.testn(width - 1)) { return this.notn(width).iaddn(1).ineg(); } - return this.clone(); }; - BN.prototype.isNeg = function isNeg() { - return (this || _global$6).negative !== 0; - }; // Return negative clone of `this` - + return (this || _global$d).negative !== 0; + }; + // Return negative clone of `this` BN.prototype.neg = function neg() { return this.clone().ineg(); }; - BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$6).negative ^= 1; + (this || _global$d).negative ^= 1; } + return this || _global$d; + }; - return this || _global$6; - }; // Or `num` with `this` in-place - - + // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$6).length < num.length) { - (this || _global$6).words[(this || _global$6).length++] = 0; + while ((this || _global$d).length < num.length) { + (this || _global$d).words[(this || _global$d).length++] = 0; } - for (var i = 0; i < num.length; i++) { - (this || _global$6).words[i] = (this || _global$6).words[i] | num.words[i]; + (this || _global$d).words[i] = (this || _global$d).words[i] | num.words[i]; } - return this.strip(); }; - BN.prototype.ior = function ior(num) { - assert(((this || _global$6).negative | num.negative) === 0); + assert(((this || _global$d).negative | num.negative) === 0); return this.iuor(num); - }; // Or `num` with `this` - + }; + // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$6).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$6); + if ((this || _global$d).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$d); }; - BN.prototype.uor = function uor(num) { - if ((this || _global$6).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$6); - }; // And `num` with `this` in-place - + if ((this || _global$d).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$d); + }; + // And `num` with `this` in-place BN.prototype.iuand = function iuand(num) { // b = min-length(num, this) var b; - - if ((this || _global$6).length > num.length) { + if ((this || _global$d).length > num.length) { b = num; } else { - b = this || _global$6; + b = this || _global$d; } - for (var i = 0; i < b.length; i++) { - (this || _global$6).words[i] = (this || _global$6).words[i] & num.words[i]; + (this || _global$d).words[i] = (this || _global$d).words[i] & num.words[i]; } - - (this || _global$6).length = b.length; + (this || _global$d).length = b.length; return this.strip(); }; - BN.prototype.iand = function iand(num) { - assert(((this || _global$6).negative | num.negative) === 0); + assert(((this || _global$d).negative | num.negative) === 0); return this.iuand(num); - }; // And `num` with `this` - + }; + // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$6).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$6); + if ((this || _global$d).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$d); }; - BN.prototype.uand = function uand(num) { - if ((this || _global$6).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$6); - }; // Xor `num` with `this` in-place - + if ((this || _global$d).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$d); + }; + // Xor `num` with `this` in-place BN.prototype.iuxor = function iuxor(num) { // a.length > b.length var a; var b; - - if ((this || _global$6).length > num.length) { - a = this || _global$6; + if ((this || _global$d).length > num.length) { + a = this || _global$d; b = num; } else { a = num; - b = this || _global$6; + b = this || _global$d; } - for (var i = 0; i < b.length; i++) { - (this || _global$6).words[i] = a.words[i] ^ b.words[i]; + (this || _global$d).words[i] = a.words[i] ^ b.words[i]; } - - if ((this || _global$6) !== a) { + if ((this || _global$d) !== a) { for (; i < a.length; i++) { - (this || _global$6).words[i] = a.words[i]; + (this || _global$d).words[i] = a.words[i]; } } - - (this || _global$6).length = a.length; + (this || _global$d).length = a.length; return this.strip(); }; - BN.prototype.ixor = function ixor(num) { - assert(((this || _global$6).negative | num.negative) === 0); + assert(((this || _global$d).negative | num.negative) === 0); return this.iuxor(num); - }; // Xor `num` with `this` - + }; + // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$6).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$6); + if ((this || _global$d).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$d); }; - BN.prototype.uxor = function uxor(num) { - if ((this || _global$6).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$6); - }; // Not ``this`` with ``width`` bitwidth - + if ((this || _global$d).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$d); + }; + // Not ``this`` with ``width`` bitwidth BN.prototype.inotn = function inotn(width) { assert(typeof width === "number" && width >= 0); var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + var bitsLeft = width % 26; + // Extend the buffer with leading zeroes this._expand(bytesNeeded); - if (bitsLeft > 0) { bytesNeeded--; - } // Handle complete words - + } + // Handle complete words for (var i = 0; i < bytesNeeded; i++) { - (this || _global$6).words[i] = ~(this || _global$6).words[i] & 67108863; - } // Handle the residue - + (this || _global$d).words[i] = ~(this || _global$d).words[i] & 67108863; + } + // Handle the residue if (bitsLeft > 0) { - (this || _global$6).words[i] = ~(this || _global$6).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes - + (this || _global$d).words[i] = ~(this || _global$d).words[i] & 67108863 >> 26 - bitsLeft; + } + // And remove leading zeroes return this.strip(); }; - BN.prototype.notn = function notn(width) { return this.clone().inotn(width); - }; // Set `bit` of `this` - + }; + // Set `bit` of `this` BN.prototype.setn = function setn(bit, val) { assert(typeof bit === "number" && bit >= 0); var off = bit / 26 | 0; var wbit = bit % 26; - this._expand(off + 1); - if (val) { - (this || _global$6).words[off] = (this || _global$6).words[off] | 1 << wbit; + (this || _global$d).words[off] = (this || _global$d).words[off] | 1 << wbit; } else { - (this || _global$6).words[off] = (this || _global$6).words[off] & ~(1 << wbit); + (this || _global$d).words[off] = (this || _global$d).words[off] & ~(1 << wbit); } - return this.strip(); - }; // Add `num` to `this` in-place - + }; + // Add `num` to `this` in-place BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + var r; - if ((this || _global$6).negative !== 0 && num.negative === 0) { - (this || _global$6).negative = 0; + // negative + positive + if ((this || _global$d).negative !== 0 && num.negative === 0) { + (this || _global$d).negative = 0; r = this.isub(num); - (this || _global$6).negative ^= 1; - return this._normSign(); // positive + negative - } else if ((this || _global$6).negative === 0 && num.negative !== 0) { + (this || _global$d).negative ^= 1; + return this._normSign(); + + // positive + negative + } else if ((this || _global$d).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; return r._normSign(); - } // a.length > b.length - + } + // a.length > b.length var a, b; - - if ((this || _global$6).length > num.length) { - a = this || _global$6; + if ((this || _global$d).length > num.length) { + a = this || _global$d; b = num; } else { a = num; - b = this || _global$6; + b = this || _global$d; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$6).words[i] = r & 67108863; + (this || _global$d).words[i] = r & 67108863; carry = r >>> 26; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$6).words[i] = r & 67108863; + (this || _global$d).words[i] = r & 67108863; carry = r >>> 26; } - - (this || _global$6).length = a.length; - + (this || _global$d).length = a.length; if (carry !== 0) { - (this || _global$6).words[(this || _global$6).length] = carry; - (this || _global$6).length++; // Copy the rest of the words - } else if (a !== (this || _global$6)) { + (this || _global$d).words[(this || _global$d).length] = carry; + (this || _global$d).length++; + // Copy the rest of the words + } else if (a !== (this || _global$d)) { for (; i < a.length; i++) { - (this || _global$6).words[i] = a.words[i]; + (this || _global$d).words[i] = a.words[i]; } } + return this || _global$d; + }; - return this || _global$6; - }; // Add `num` to `this` - - + // Add `num` to `this` BN.prototype.add = function add(num) { var res; - - if (num.negative !== 0 && (this || _global$6).negative === 0) { + if (num.negative !== 0 && (this || _global$d).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$6).negative !== 0) { - (this || _global$6).negative = 0; - res = num.sub(this || _global$6); - (this || _global$6).negative = 1; + } else if (num.negative === 0 && (this || _global$d).negative !== 0) { + (this || _global$d).negative = 0; + res = num.sub(this || _global$d); + (this || _global$d).negative = 1; return res; } + if ((this || _global$d).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$d); + }; - if ((this || _global$6).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$6); - }; // Subtract `num` from `this` in-place - - + // Subtract `num` from `this` in-place BN.prototype.isub = function isub(num) { // this - (-num) = this + num if (num.negative !== 0) { num.negative = 0; var r = this.iadd(num); num.negative = 1; - return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$6).negative !== 0) { - (this || _global$6).negative = 0; + return r._normSign(); + + // -this - num = -(this + num) + } else if ((this || _global$d).negative !== 0) { + (this || _global$d).negative = 0; this.iadd(num); - (this || _global$6).negative = 1; + (this || _global$d).negative = 1; return this._normSign(); - } // At this point both numbers are positive + } + // At this point both numbers are positive + var cmp = this.cmp(num); - var cmp = this.cmp(num); // Optimization - zeroify - + // Optimization - zeroify if (cmp === 0) { - (this || _global$6).negative = 0; - (this || _global$6).length = 1; - (this || _global$6).words[0] = 0; - return this || _global$6; - } // a > b - + (this || _global$d).negative = 0; + (this || _global$d).length = 1; + (this || _global$d).words[0] = 0; + return this || _global$d; + } + // a > b var a, b; - if (cmp > 0) { - a = this || _global$6; + a = this || _global$d; b = num; } else { a = num; - b = this || _global$6; + b = this || _global$d; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$6).words[i] = r & 67108863; + (this || _global$d).words[i] = r & 67108863; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$6).words[i] = r & 67108863; - } // Copy rest of the words - + (this || _global$d).words[i] = r & 67108863; + } - if (carry === 0 && i < a.length && a !== (this || _global$6)) { + // Copy rest of the words + if (carry === 0 && i < a.length && a !== (this || _global$d)) { for (; i < a.length; i++) { - (this || _global$6).words[i] = a.words[i]; + (this || _global$d).words[i] = a.words[i]; } } - - (this || _global$6).length = Math.max((this || _global$6).length, i); - - if (a !== (this || _global$6)) { - (this || _global$6).negative = 1; + (this || _global$d).length = Math.max((this || _global$d).length, i); + if (a !== (this || _global$d)) { + (this || _global$d).negative = 1; } - return this.strip(); - }; // Subtract `num` from `this` - + }; + // Subtract `num` from `this` BN.prototype.sub = function sub(num) { return this.clone().isub(num); }; - function smallMulTo(self, num, out) { out.negative = num.negative ^ self.negative; var len = self.length + num.length | 0; out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + len = len - 1 | 0; + // Peel one iteration (compiler can't do it, because of code complexity) var a = self.words[0] | 0; var b = num.words[0] | 0; var r = a * b; var lo = r & 67108863; var carry = r / 67108864 | 0; out.words[0] = lo; - for (var k = 1; k < len; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff var ncarry = carry >>> 26; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j | 0; a = self.words[i] | 0; @@ -56399,23 +92355,20 @@ function dew$V() { ncarry += r / 67108864 | 0; rword = r & 67108863; } - out.words[k] = rword | 0; carry = ncarry | 0; } - if (carry !== 0) { out.words[k] = carry | 0; } else { out.length--; } - return out.strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need + } + + // TODO(indutny): it may be reasonable to omit it for users who don't need // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit // multiplication (like elliptic secp256k1). - - var comb10MulTo = function comb10MulTo(self, num, out) { var a = self.words; var b = num.words; @@ -56487,7 +92440,6 @@ function dew$V() { out.negative = self.negative ^ num.negative; out.length = 19; /* k = 0 */ - lo = Math.imul(al0, bl0); mid = Math.imul(al0, bh0); mid = mid + Math.imul(ah0, bl0) | 0; @@ -56496,7 +92448,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; w0 &= 67108863; /* k = 1 */ - lo = Math.imul(al1, bl0); mid = Math.imul(al1, bh0); mid = mid + Math.imul(ah1, bl0) | 0; @@ -56509,7 +92460,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; w1 &= 67108863; /* k = 2 */ - lo = Math.imul(al2, bl0); mid = Math.imul(al2, bh0); mid = mid + Math.imul(ah2, bl0) | 0; @@ -56526,7 +92476,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; w2 &= 67108863; /* k = 3 */ - lo = Math.imul(al3, bl0); mid = Math.imul(al3, bh0); mid = mid + Math.imul(ah3, bl0) | 0; @@ -56547,7 +92496,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; w3 &= 67108863; /* k = 4 */ - lo = Math.imul(al4, bl0); mid = Math.imul(al4, bh0); mid = mid + Math.imul(ah4, bl0) | 0; @@ -56572,7 +92520,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; w4 &= 67108863; /* k = 5 */ - lo = Math.imul(al5, bl0); mid = Math.imul(al5, bh0); mid = mid + Math.imul(ah5, bl0) | 0; @@ -56601,7 +92548,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; w5 &= 67108863; /* k = 6 */ - lo = Math.imul(al6, bl0); mid = Math.imul(al6, bh0); mid = mid + Math.imul(ah6, bl0) | 0; @@ -56634,7 +92580,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; w6 &= 67108863; /* k = 7 */ - lo = Math.imul(al7, bl0); mid = Math.imul(al7, bh0); mid = mid + Math.imul(ah7, bl0) | 0; @@ -56671,7 +92616,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; w7 &= 67108863; /* k = 8 */ - lo = Math.imul(al8, bl0); mid = Math.imul(al8, bh0); mid = mid + Math.imul(ah8, bl0) | 0; @@ -56712,7 +92656,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; w8 &= 67108863; /* k = 9 */ - lo = Math.imul(al9, bl0); mid = Math.imul(al9, bh0); mid = mid + Math.imul(ah9, bl0) | 0; @@ -56757,7 +92700,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; w9 &= 67108863; /* k = 10 */ - lo = Math.imul(al9, bl1); mid = Math.imul(al9, bh1); mid = mid + Math.imul(ah9, bl1) | 0; @@ -56798,7 +92740,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; w10 &= 67108863; /* k = 11 */ - lo = Math.imul(al9, bl2); mid = Math.imul(al9, bh2); mid = mid + Math.imul(ah9, bl2) | 0; @@ -56835,7 +92776,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; w11 &= 67108863; /* k = 12 */ - lo = Math.imul(al9, bl3); mid = Math.imul(al9, bh3); mid = mid + Math.imul(ah9, bl3) | 0; @@ -56868,7 +92808,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; w12 &= 67108863; /* k = 13 */ - lo = Math.imul(al9, bl4); mid = Math.imul(al9, bh4); mid = mid + Math.imul(ah9, bl4) | 0; @@ -56897,7 +92836,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; w13 &= 67108863; /* k = 14 */ - lo = Math.imul(al9, bl5); mid = Math.imul(al9, bh5); mid = mid + Math.imul(ah9, bl5) | 0; @@ -56922,7 +92860,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; w14 &= 67108863; /* k = 15 */ - lo = Math.imul(al9, bl6); mid = Math.imul(al9, bh6); mid = mid + Math.imul(ah9, bl6) | 0; @@ -56943,7 +92880,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; w15 &= 67108863; /* k = 16 */ - lo = Math.imul(al9, bl7); mid = Math.imul(al9, bh7); mid = mid + Math.imul(ah9, bl7) | 0; @@ -56960,7 +92896,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; w16 &= 67108863; /* k = 17 */ - lo = Math.imul(al9, bl8); mid = Math.imul(al9, bh8); mid = mid + Math.imul(ah9, bl8) | 0; @@ -56973,7 +92908,6 @@ function dew$V() { c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; w17 &= 67108863; /* k = 18 */ - lo = Math.imul(al9, bl9); mid = Math.imul(al9, bh9); mid = mid + Math.imul(ah9, bl9) | 0; @@ -57000,26 +92934,22 @@ function dew$V() { o[16] = w16; o[17] = w17; o[18] = w18; - if (c !== 0) { o[19] = c; out.length++; } - return out; - }; // Polyfill comb - + }; + // Polyfill comb if (!Math.imul) { comb10MulTo = smallMulTo; } - function bigMulTo(self, num, out) { out.negative = num.negative ^ self.negative; out.length = self.length + num.length; var carry = 0; var hncarry = 0; - for (var k = 0; k < out.length - 1; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff @@ -57027,7 +92957,6 @@ function dew$V() { hncarry = 0; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j; var a = self.words[i] | 0; @@ -57041,95 +92970,80 @@ function dew$V() { hncarry += ncarry >>> 26; ncarry &= 67108863; } - out.words[k] = rword; carry = ncarry; ncarry = hncarry; } - if (carry !== 0) { out.words[k] = carry; } else { out.length--; } - return out.strip(); } - function jumboMulTo(self, num, out) { var fftm = new FFTM(); return fftm.mulp(self, num, out); } - BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$6).length + num.length; - - if ((this || _global$6).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$6, num, out); + var len = (this || _global$d).length + num.length; + if ((this || _global$d).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$d, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$6, num, out); + res = smallMulTo(this || _global$d, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$6, num, out); + res = bigMulTo(this || _global$d, num, out); } else { - res = jumboMulTo(this || _global$6, num, out); + res = jumboMulTo(this || _global$d, num, out); } - return res; - }; // Cooley-Tukey algorithm for FFT - // slightly revisited to rely on looping instead of recursion + }; + // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion function FFTM(x, y) { - (this || _global$6).x = x; - (this || _global$6).y = y; + (this || _global$d).x = x; + (this || _global$d).y = y; } - FFTM.prototype.makeRBT = function makeRBT(N) { var t = new Array(N); var l = BN.prototype._countBits(N) - 1; - for (var i = 0; i < N; i++) { t[i] = this.revBin(i, l, N); } - return t; - }; // Returns binary-reversed representation of `x` - + }; + // Returns binary-reversed representation of `x` FFTM.prototype.revBin = function revBin(x, l, N) { if (x === 0 || x === N - 1) return x; var rb = 0; - for (var i = 0; i < l; i++) { rb |= (x & 1) << l - i - 1; x >>= 1; } - return rb; - }; // Performs "tweedling" phase, therefore 'emulating' - // behaviour of the recursive algorithm - + }; + // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { for (var i = 0; i < N; i++) { rtws[i] = rws[rbt[i]]; itws[i] = iws[rbt[i]]; } }; - FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { this.permute(rbt, rws, iws, rtws, itws, N); - for (var s = 1; s < N; s <<= 1) { var l = s << 1; var rtwdf = Math.cos(2 * Math.PI / l); var itwdf = Math.sin(2 * Math.PI / l); - for (var p = 0; p < N; p += l) { var rtwdf_ = rtwdf; var itwdf_ = itwdf; - for (var j = 0; j < s; j++) { var re = rtws[p + j]; var ie = itws[p + j]; @@ -57142,8 +93056,8 @@ function dew$V() { itws[p + j] = ie + io; rtws[p + j + s] = re - ro; itws[p + j + s] = ie - io; - /* jshint maxdepth : false */ + /* jshint maxdepth : false */ if (j !== l) { rx = rtwdf * rtwdf_ - itwdf * itwdf_; itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; @@ -57153,22 +93067,17 @@ function dew$V() { } } }; - FFTM.prototype.guessLen13b = function guessLen13b(n, m) { var N = Math.max(m, n) | 1; var odd = N & 1; var i = 0; - for (N = N / 2 | 0; N; N = N >>> 1) { i++; } - return 1 << i + 1 + odd; }; - FFTM.prototype.conjugate = function conjugate(rws, iws, N) { if (N <= 1) return; - for (var i = 0; i < N / 2; i++) { var t = rws[i]; rws[i] = rws[N - i - 1]; @@ -57178,60 +93087,47 @@ function dew$V() { iws[N - i - 1] = -t; } }; - FFTM.prototype.normalize13b = function normalize13b(ws, N) { var carry = 0; - for (var i = 0; i < N / 2; i++) { var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; ws[i] = w & 67108863; - if (w < 67108864) { carry = 0; } else { carry = w / 67108864 | 0; } } - return ws; }; - FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { var carry = 0; - for (var i = 0; i < len; i++) { carry = carry + (ws[i] | 0); rws[2 * i] = carry & 8191; carry = carry >>> 13; rws[2 * i + 1] = carry & 8191; carry = carry >>> 13; - } // Pad with zeroes - + } + // Pad with zeroes for (i = 2 * len; i < N; ++i) { rws[i] = 0; } - assert(carry === 0); assert((carry & ~8191) === 0); }; - FFTM.prototype.stub = function stub(N) { var ph = new Array(N); - for (var i = 0; i < N; i++) { ph[i] = 0; } - return ph; }; - FFTM.prototype.mulp = function mulp(x, y, out) { var N = 2 * this.guessLen13b(x.length, y.length); var rbt = this.makeRBT(N); - var _ = this.stub(N); - var rws = new Array(N); var rwst = new Array(N); var iwst = new Array(N); @@ -57244,13 +93140,11 @@ function dew$V() { this.convert13b(y.words, y.length, nrws, N); this.transform(rws, _, rwst, iwst, N, rbt); this.transform(nrws, _, nrwst, niwst, N, rbt); - for (var i = 0; i < N; i++) { var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; rwst[i] = rx; } - this.conjugate(rwst, iwst, N); this.transform(rwst, iwst, rmws, _, N, rbt); this.conjugate(rmws, _, N); @@ -57258,540 +93152,467 @@ function dew$V() { out.negative = x.negative ^ y.negative; out.length = x.length + y.length; return out.strip(); - }; // Multiply `this` by `num` - + }; + // Multiply `this` by `num` BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$6).length + num.length); + out.words = new Array((this || _global$d).length + num.length); return this.mulTo(num, out); - }; // Multiply employing FFT - + }; + // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$6).length + num.length); - return jumboMulTo(this || _global$6, num, out); - }; // In-place Multiplication - + out.words = new Array((this || _global$d).length + num.length); + return jumboMulTo(this || _global$d, num, out); + }; + // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$6); + return this.clone().mulTo(num, this || _global$d); }; - BN.prototype.imuln = function imuln(num) { assert(typeof num === "number"); - assert(num < 67108864); // Carry + assert(num < 67108864); + // Carry var carry = 0; - - for (var i = 0; i < (this || _global$6).length; i++) { - var w = ((this || _global$6).words[i] | 0) * num; + for (var i = 0; i < (this || _global$d).length; i++) { + var w = ((this || _global$d).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$6).words[i] = lo & 67108863; + (this || _global$d).words[i] = lo & 67108863; } - if (carry !== 0) { - (this || _global$6).words[i] = carry; - (this || _global$6).length++; + (this || _global$d).words[i] = carry; + (this || _global$d).length++; } - - return this || _global$6; + return this || _global$d; }; - BN.prototype.muln = function muln(num) { return this.clone().imuln(num); - }; // `this` * `this` - + }; + // `this` * `this` BN.prototype.sqr = function sqr() { - return this.mul(this || _global$6); - }; // `this` * `this` in-place - + return this.mul(this || _global$d); + }; + // `this` * `this` in-place BN.prototype.isqr = function isqr() { return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) - + }; + // Math.pow(`this`, `num`) BN.prototype.pow = function pow(num) { var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes - - var res = this || _global$6; + if (w.length === 0) return new BN(1); + // Skip leading zeroes + var res = this || _global$d; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; } - if (++i < w.length) { for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { if (w[i] === 0) continue; res = res.mul(q); } } - return res; - }; // Shift-left in-place - + }; + // Shift-left in-place BN.prototype.iushln = function iushln(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; var carryMask = 67108863 >>> 26 - r << 26 - r; var i; - if (r !== 0) { var carry = 0; - - for (i = 0; i < (this || _global$6).length; i++) { - var newCarry = (this || _global$6).words[i] & carryMask; - var c = ((this || _global$6).words[i] | 0) - newCarry << r; - (this || _global$6).words[i] = c | carry; + for (i = 0; i < (this || _global$d).length; i++) { + var newCarry = (this || _global$d).words[i] & carryMask; + var c = ((this || _global$d).words[i] | 0) - newCarry << r; + (this || _global$d).words[i] = c | carry; carry = newCarry >>> 26 - r; } - if (carry) { - (this || _global$6).words[i] = carry; - (this || _global$6).length++; + (this || _global$d).words[i] = carry; + (this || _global$d).length++; } } - if (s !== 0) { - for (i = (this || _global$6).length - 1; i >= 0; i--) { - (this || _global$6).words[i + s] = (this || _global$6).words[i]; + for (i = (this || _global$d).length - 1; i >= 0; i--) { + (this || _global$d).words[i + s] = (this || _global$d).words[i]; } - for (i = 0; i < s; i++) { - (this || _global$6).words[i] = 0; + (this || _global$d).words[i] = 0; } - - (this || _global$6).length += s; + (this || _global$d).length += s; } - return this.strip(); }; - BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$6).negative === 0); + assert((this || _global$d).negative === 0); return this.iushln(bits); - }; // Shift-right in-place + }; + + // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes // NOTE: if `extended` is present - it will be filled with destroyed bits - - BN.prototype.iushrn = function iushrn(bits, hint, extended) { assert(typeof bits === "number" && bits >= 0); var h; - if (hint) { h = (hint - hint % 26) / 26; } else { h = 0; } - var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$6).length); + var s = Math.min((bits - r) / 26, (this || _global$d).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; - h = Math.max(0, h); // Extended mode, copy masked part + h = Math.max(0, h); + // Extended mode, copy masked part if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$6).words[i]; + maskedWords.words[i] = (this || _global$d).words[i]; } - maskedWords.length = s; } - - if (s === 0) ; else if ((this || _global$6).length > s) { - (this || _global$6).length -= s; - - for (i = 0; i < (this || _global$6).length; i++) { - (this || _global$6).words[i] = (this || _global$6).words[i + s]; + if (s === 0) ; else if ((this || _global$d).length > s) { + (this || _global$d).length -= s; + for (i = 0; i < (this || _global$d).length; i++) { + (this || _global$d).words[i] = (this || _global$d).words[i + s]; } } else { - (this || _global$6).words[0] = 0; - (this || _global$6).length = 1; + (this || _global$d).words[0] = 0; + (this || _global$d).length = 1; } - var carry = 0; - - for (i = (this || _global$6).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$6).words[i] | 0; - (this || _global$6).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$d).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$d).words[i] | 0; + (this || _global$d).words[i] = carry << 26 - r | word >>> r; carry = word & mask; - } // Push carried bits as a mask - + } + // Push carried bits as a mask if (maskedWords && carry !== 0) { maskedWords.words[maskedWords.length++] = carry; } - - if ((this || _global$6).length === 0) { - (this || _global$6).words[0] = 0; - (this || _global$6).length = 1; + if ((this || _global$d).length === 0) { + (this || _global$d).words[0] = 0; + (this || _global$d).length = 1; } - return this.strip(); }; - BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$6).negative === 0); + assert((this || _global$d).negative === 0); return this.iushrn(bits, hint, extended); - }; // Shift-left - + }; + // Shift-left BN.prototype.shln = function shln(bits) { return this.clone().ishln(bits); }; - BN.prototype.ushln = function ushln(bits) { return this.clone().iushln(bits); - }; // Shift-right - + }; + // Shift-right BN.prototype.shrn = function shrn(bits) { return this.clone().ishrn(bits); }; - BN.prototype.ushrn = function ushrn(bits) { return this.clone().iushrn(bits); - }; // Test if n bit is set - + }; + // Test if n bit is set BN.prototype.testn = function testn(bit) { assert(typeof bit === "number" && bit >= 0); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$6).length <= s) return false; // Check bit and return + // Fast case: bit is much higher than all existing words + if ((this || _global$d).length <= s) return false; - var w = (this || _global$6).words[s]; + // Check bit and return + var w = (this || _global$d).words[s]; return !!(w & q); - }; // Return only lowers bits of number (in-place) - + }; + // Return only lowers bits of number (in-place) BN.prototype.imaskn = function imaskn(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$6).negative === 0, "imaskn works only with positive numbers"); - - if ((this || _global$6).length <= s) { - return this || _global$6; + assert((this || _global$d).negative === 0, "imaskn works only with positive numbers"); + if ((this || _global$d).length <= s) { + return this || _global$d; } - if (r !== 0) { s++; } - - (this || _global$6).length = Math.min(s, (this || _global$6).length); - + (this || _global$d).length = Math.min(s, (this || _global$d).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$6).words[(this || _global$6).length - 1] &= mask; + (this || _global$d).words[(this || _global$d).length - 1] &= mask; } - return this.strip(); - }; // Return only lowers bits of number - + }; + // Return only lowers bits of number BN.prototype.maskn = function maskn(bits) { return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` - + }; + // Add plain number `num` to `this` BN.prototype.iaddn = function iaddn(num) { assert(typeof num === "number"); assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + if (num < 0) return this.isubn(-num); - if ((this || _global$6).negative !== 0) { - if ((this || _global$6).length === 1 && ((this || _global$6).words[0] | 0) < num) { - (this || _global$6).words[0] = num - ((this || _global$6).words[0] | 0); - (this || _global$6).negative = 0; - return this || _global$6; + // Possible sign change + if ((this || _global$d).negative !== 0) { + if ((this || _global$d).length === 1 && ((this || _global$d).words[0] | 0) < num) { + (this || _global$d).words[0] = num - ((this || _global$d).words[0] | 0); + (this || _global$d).negative = 0; + return this || _global$d; } - - (this || _global$6).negative = 0; + (this || _global$d).negative = 0; this.isubn(num); - (this || _global$6).negative = 1; - return this || _global$6; - } // Add without checks - + (this || _global$d).negative = 1; + return this || _global$d; + } + // Add without checks return this._iaddn(num); }; - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$6).words[0] += num; // Carry - - for (var i = 0; i < (this || _global$6).length && (this || _global$6).words[i] >= 67108864; i++) { - (this || _global$6).words[i] -= 67108864; + (this || _global$d).words[0] += num; - if (i === (this || _global$6).length - 1) { - (this || _global$6).words[i + 1] = 1; + // Carry + for (var i = 0; i < (this || _global$d).length && (this || _global$d).words[i] >= 67108864; i++) { + (this || _global$d).words[i] -= 67108864; + if (i === (this || _global$d).length - 1) { + (this || _global$d).words[i + 1] = 1; } else { - (this || _global$6).words[i + 1]++; + (this || _global$d).words[i + 1]++; } } + (this || _global$d).length = Math.max((this || _global$d).length, i + 1); + return this || _global$d; + }; - (this || _global$6).length = Math.max((this || _global$6).length, i + 1); - return this || _global$6; - }; // Subtract plain number `num` from `this` - - + // Subtract plain number `num` from `this` BN.prototype.isubn = function isubn(num) { assert(typeof num === "number"); assert(num < 67108864); if (num < 0) return this.iaddn(-num); - - if ((this || _global$6).negative !== 0) { - (this || _global$6).negative = 0; + if ((this || _global$d).negative !== 0) { + (this || _global$d).negative = 0; this.iaddn(num); - (this || _global$6).negative = 1; - return this || _global$6; + (this || _global$d).negative = 1; + return this || _global$d; } - - (this || _global$6).words[0] -= num; - - if ((this || _global$6).length === 1 && (this || _global$6).words[0] < 0) { - (this || _global$6).words[0] = -(this || _global$6).words[0]; - (this || _global$6).negative = 1; + (this || _global$d).words[0] -= num; + if ((this || _global$d).length === 1 && (this || _global$d).words[0] < 0) { + (this || _global$d).words[0] = -(this || _global$d).words[0]; + (this || _global$d).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$6).length && (this || _global$6).words[i] < 0; i++) { - (this || _global$6).words[i] += 67108864; - (this || _global$6).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$d).length && (this || _global$d).words[i] < 0; i++) { + (this || _global$d).words[i] += 67108864; + (this || _global$d).words[i + 1] -= 1; } } - return this.strip(); }; - BN.prototype.addn = function addn(num) { return this.clone().iaddn(num); }; - BN.prototype.subn = function subn(num) { return this.clone().isubn(num); }; - BN.prototype.iabs = function iabs() { - (this || _global$6).negative = 0; - return this || _global$6; + (this || _global$d).negative = 0; + return this || _global$d; }; - BN.prototype.abs = function abs() { return this.clone().iabs(); }; - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { var len = num.length + shift; var i; - this._expand(len); - var w; var carry = 0; - for (i = 0; i < num.length; i++) { - w = ((this || _global$6).words[i + shift] | 0) + carry; + w = ((this || _global$d).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$6).words[i + shift] = w & 67108863; + (this || _global$d).words[i + shift] = w & 67108863; } - - for (; i < (this || _global$6).length - shift; i++) { - w = ((this || _global$6).words[i + shift] | 0) + carry; + for (; i < (this || _global$d).length - shift; i++) { + w = ((this || _global$d).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$6).words[i + shift] = w & 67108863; + (this || _global$d).words[i + shift] = w & 67108863; } + if (carry === 0) return this.strip(); - if (carry === 0) return this.strip(); // Subtraction overflow - + // Subtraction overflow assert(carry === -1); carry = 0; - - for (i = 0; i < (this || _global$6).length; i++) { - w = -((this || _global$6).words[i] | 0) + carry; + for (i = 0; i < (this || _global$d).length; i++) { + w = -((this || _global$d).words[i] | 0) + carry; carry = w >> 26; - (this || _global$6).words[i] = w & 67108863; + (this || _global$d).words[i] = w & 67108863; } - - (this || _global$6).negative = 1; + (this || _global$d).negative = 1; return this.strip(); }; - BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$6).length - num.length; + var shift = (this || _global$d).length - num.length; var a = this.clone(); - var b = num; // Normalize + var b = num; + // Normalize var bhi = b.words[b.length - 1] | 0; - var bhiBits = this._countBits(bhi); - shift = 26 - bhiBits; - if (shift !== 0) { b = b.ushln(shift); a.iushln(shift); bhi = b.words[b.length - 1] | 0; - } // Initialize quotient - + } + // Initialize quotient var m = a.length - b.length; var q; - if (mode !== "mod") { q = new BN(null); q.length = m + 1; q.words = new Array(q.length); - for (var i = 0; i < q.length; i++) { q.words[i] = 0; } } - var diff = a.clone()._ishlnsubmul(b, 1, m); - if (diff.negative === 0) { a = diff; - if (q) { q.words[m] = 1; } } - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) qj = Math.min(qj / bhi | 0, 67108863); - a._ishlnsubmul(b, qj, j); - while (a.negative !== 0) { qj--; a.negative = 0; - a._ishlnsubmul(b, 1, j); - if (!a.isZero()) { a.negative ^= 1; } } - if (q) { q.words[j] = qj; } } - if (q) { q.strip(); } + a.strip(); - a.strip(); // Denormalize - + // Denormalize if (mode !== "div" && shift !== 0) { a.iushrn(shift); } - return { div: q || null, mod: a }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, // to `div` to request div only, or be absent to // request both div & mod // 2) `positive` is true if unsigned mod is requested - - BN.prototype.divmod = function divmod(num, mode, positive) { assert(!num.isZero()); - if (this.isZero()) { return { div: new BN(0), mod: new BN(0) }; } - var div, mod, res; - - if ((this || _global$6).negative !== 0 && num.negative === 0) { + if ((this || _global$d).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); - if (mode !== "mod") { div = res.div.neg(); } - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.iadd(num); } } - return { div: div, mod: mod }; } - - if ((this || _global$6).negative === 0 && num.negative !== 0) { + if ((this || _global$d).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); - if (mode !== "mod") { div = res.div.neg(); } - return { div: div, mod: res.mod }; } - - if (((this || _global$6).negative & num.negative) !== 0) { + if (((this || _global$d).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.isub(num); } } - return { div: res.div, mod: mod }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + } + // Both numbers are positive at this point - if (num.length > (this || _global$6).length || this.cmp(num) < 0) { + // Strip both numbers to approximate shift value + if (num.length > (this || _global$d).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$6 + mod: this || _global$d }; - } // Very short reduction - + } + // Very short reduction if (num.length === 1) { if (mode === "div") { return { @@ -57799,144 +93620,125 @@ function dew$V() { mod: null }; } - if (mode === "mod") { return { div: null, mod: new BN(this.modn(num.words[0])) }; } - return { div: this.divn(num.words[0]), mod: new BN(this.modn(num.words[0])) }; } - return this._wordDiv(num, mode); - }; // Find `this` / `num` - + }; + // Find `this` / `num` BN.prototype.div = function div(num) { return this.divmod(num, "div", false).div; - }; // Find `this` % `num` - + }; + // Find `this` % `num` BN.prototype.mod = function mod(num) { return this.divmod(num, "mod", false).mod; }; - BN.prototype.umod = function umod(num) { return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) - + }; + // Find Round(`this` / `num`) BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + var dm = this.divmod(num); + // Fast case - exact division if (dm.mod.isZero()) return dm.div; var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; var half = num.ushrn(1); var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + var cmp = mod.cmp(half); - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + // Round up return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); }; - BN.prototype.modn = function modn(num) { assert(num <= 67108863); var p = (1 << 26) % num; var acc = 0; - - for (var i = (this || _global$6).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$6).words[i] | 0)) % num; + for (var i = (this || _global$d).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$d).words[i] | 0)) % num; } - return acc; - }; // In-place division by number - + }; + // In-place division by number BN.prototype.idivn = function idivn(num) { assert(num <= 67108863); var carry = 0; - - for (var i = (this || _global$6).length - 1; i >= 0; i--) { - var w = ((this || _global$6).words[i] | 0) + carry * 67108864; - (this || _global$6).words[i] = w / num | 0; + for (var i = (this || _global$d).length - 1; i >= 0; i--) { + var w = ((this || _global$d).words[i] | 0) + carry * 67108864; + (this || _global$d).words[i] = w / num | 0; carry = w % num; } - return this.strip(); }; - BN.prototype.divn = function divn(num) { return this.clone().idivn(num); }; - BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$6; + var x = this || _global$d; var y = p.clone(); - if (x.negative !== 0) { x = x.umod(p); } else { x = x.clone(); - } // A * x + B * y = x - + } + // A * x + B * y = x var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + var B = new BN(0); + // C * x + D * y = y var C = new BN(0); var D = new BN(1); var g = 0; - while (x.isEven() && y.isEven()) { x.iushrn(1); y.iushrn(1); ++g; } - var yp = y.clone(); var xp = x.clone(); - while (!x.isZero()) { for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { x.iushrn(i); - while (i-- > 0) { if (A.isOdd() || B.isOdd()) { A.iadd(yp); B.isub(xp); } - A.iushrn(1); B.iushrn(1); } } - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { y.iushrn(j); - while (j-- > 0) { if (C.isOdd() || D.isOdd()) { C.iadd(yp); D.isub(xp); } - C.iushrn(1); D.iushrn(1); } } - if (x.cmp(y) >= 0) { x.isub(y); A.isub(C); @@ -57947,62 +93749,50 @@ function dew$V() { D.isub(B); } } - return { a: C, b: D, gcd: y.iushln(g) }; - }; // This is reduced incarnation of the binary EEA + }; + + // This is reduced incarnation of the binary EEA // above, designated to invert members of the // _prime_ fields F(p) at a maximal speed - - BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$6; + var a = this || _global$d; var b = p.clone(); - if (a.negative !== 0) { a = a.umod(p); } else { a = a.clone(); } - var x1 = new BN(1); var x2 = new BN(0); var delta = b.clone(); - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { a.iushrn(i); - while (i-- > 0) { if (x1.isOdd()) { x1.iadd(delta); } - x1.iushrn(1); } } - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { b.iushrn(j); - while (j-- > 0) { if (x2.isOdd()) { x2.iadd(delta); } - x2.iushrn(1); } } - if (a.cmp(b) >= 0) { a.isub(b); x1.isub(x2); @@ -58011,46 +93801,38 @@ function dew$V() { x2.isub(x1); } } - var res; - if (a.cmpn(1) === 0) { res = x1; } else { res = x2; } - if (res.cmpn(0) < 0) { res.iadd(p); } - return res; }; - BN.prototype.gcd = function gcd(num) { if (this.isZero()) return num.abs(); if (num.isZero()) return this.abs(); var a = this.clone(); var b = num.clone(); a.negative = 0; - b.negative = 0; // Remove common factor of two + b.negative = 0; + // Remove common factor of two for (var shift = 0; a.isEven() && b.isEven(); shift++) { a.iushrn(1); b.iushrn(1); } - do { while (a.isEven()) { a.iushrn(1); } - while (b.isEven()) { b.iushrn(1); } - var r = a.cmp(b); - if (r < 0) { // Swap `a` and `b` to make `a` always bigger than `b` var t = a; @@ -58059,330 +93841,269 @@ function dew$V() { } else if (r === 0 || b.cmpn(1) === 0) { break; } - a.isub(b); } while (true); - return b.iushln(shift); - }; // Invert number in the field F(num) - + }; + // Invert number in the field F(num) BN.prototype.invm = function invm(num) { return this.egcd(num).a.umod(num); }; - BN.prototype.isEven = function isEven() { - return ((this || _global$6).words[0] & 1) === 0; + return ((this || _global$d).words[0] & 1) === 0; }; - BN.prototype.isOdd = function isOdd() { - return ((this || _global$6).words[0] & 1) === 1; - }; // And first word and num - + return ((this || _global$d).words[0] & 1) === 1; + }; + // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$6).words[0] & num; - }; // Increment at the bit position in-line - + return (this || _global$d).words[0] & num; + }; + // Increment at the bit position in-line BN.prototype.bincn = function bincn(bit) { assert(typeof bit === "number"); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$6).length <= s) { + // Fast case: bit is much higher than all existing words + if ((this || _global$d).length <= s) { this._expand(s + 1); + (this || _global$d).words[s] |= q; + return this || _global$d; + } - (this || _global$6).words[s] |= q; - return this || _global$6; - } // Add bit and propagate, if needed - - + // Add bit and propagate, if needed var carry = q; - - for (var i = s; carry !== 0 && i < (this || _global$6).length; i++) { - var w = (this || _global$6).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$d).length; i++) { + var w = (this || _global$d).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$6).words[i] = w; + (this || _global$d).words[i] = w; } - if (carry !== 0) { - (this || _global$6).words[i] = carry; - (this || _global$6).length++; + (this || _global$d).words[i] = carry; + (this || _global$d).length++; } - - return this || _global$6; + return this || _global$d; }; - BN.prototype.isZero = function isZero() { - return (this || _global$6).length === 1 && (this || _global$6).words[0] === 0; + return (this || _global$d).length === 1 && (this || _global$d).words[0] === 0; }; - BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$6).negative !== 0 && !negative) return -1; - if ((this || _global$6).negative === 0 && negative) return 1; + if ((this || _global$d).negative !== 0 && !negative) return -1; + if ((this || _global$d).negative === 0 && negative) return 1; this.strip(); var res; - - if ((this || _global$6).length > 1) { + if ((this || _global$d).length > 1) { res = 1; } else { if (negative) { num = -num; } - assert(num <= 67108863, "Number is too big"); - var w = (this || _global$6).words[0] | 0; + var w = (this || _global$d).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - - if ((this || _global$6).negative !== 0) return -res | 0; + if ((this || _global$d).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: + }; + + // Compare two numbers and return: // 1 - if `this` > `num` // 0 - if `this` == `num` // -1 - if `this` < `num` - - BN.prototype.cmp = function cmp(num) { - if ((this || _global$6).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$6).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$d).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$d).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$6).negative !== 0) return -res | 0; + if ((this || _global$d).negative !== 0) return -res | 0; return res; - }; // Unsigned comparison - + }; + // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$6).length > num.length) return 1; - if ((this || _global$6).length < num.length) return -1; + if ((this || _global$d).length > num.length) return 1; + if ((this || _global$d).length < num.length) return -1; var res = 0; - - for (var i = (this || _global$6).length - 1; i >= 0; i--) { - var a = (this || _global$6).words[i] | 0; + for (var i = (this || _global$d).length - 1; i >= 0; i--) { + var a = (this || _global$d).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; - if (a < b) { res = -1; } else if (a > b) { res = 1; } - break; } - return res; }; - BN.prototype.gtn = function gtn(num) { return this.cmpn(num) === 1; }; - BN.prototype.gt = function gt(num) { return this.cmp(num) === 1; }; - BN.prototype.gten = function gten(num) { return this.cmpn(num) >= 0; }; - BN.prototype.gte = function gte(num) { return this.cmp(num) >= 0; }; - BN.prototype.ltn = function ltn(num) { return this.cmpn(num) === -1; }; - BN.prototype.lt = function lt(num) { return this.cmp(num) === -1; }; - BN.prototype.lten = function lten(num) { return this.cmpn(num) <= 0; }; - BN.prototype.lte = function lte(num) { return this.cmp(num) <= 0; }; - BN.prototype.eqn = function eqn(num) { return this.cmpn(num) === 0; }; - BN.prototype.eq = function eq(num) { return this.cmp(num) === 0; - }; // + }; + + // // A reduce context, could be using montgomery or something better, depending // on the `m` itself. // - - BN.red = function red(num) { return new Red(num); }; - BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$6).red, "Already a number in reduction context"); - assert((this || _global$6).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$6)._forceRed(ctx); + assert(!(this || _global$d).red, "Already a number in reduction context"); + assert((this || _global$d).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$d)._forceRed(ctx); }; - BN.prototype.fromRed = function fromRed() { - assert((this || _global$6).red, "fromRed works only with numbers in reduction context"); - return (this || _global$6).red.convertFrom(this || _global$6); + assert((this || _global$d).red, "fromRed works only with numbers in reduction context"); + return (this || _global$d).red.convertFrom(this || _global$d); }; - BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$6).red = ctx; - return this || _global$6; + (this || _global$d).red = ctx; + return this || _global$d; }; - BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$6).red, "Already a number in reduction context"); + assert(!(this || _global$d).red, "Already a number in reduction context"); return this._forceRed(ctx); }; - BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$6).red, "redAdd works only with red numbers"); - return (this || _global$6).red.add(this || _global$6, num); + assert((this || _global$d).red, "redAdd works only with red numbers"); + return (this || _global$d).red.add(this || _global$d, num); }; - BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$6).red, "redIAdd works only with red numbers"); - return (this || _global$6).red.iadd(this || _global$6, num); + assert((this || _global$d).red, "redIAdd works only with red numbers"); + return (this || _global$d).red.iadd(this || _global$d, num); }; - BN.prototype.redSub = function redSub(num) { - assert((this || _global$6).red, "redSub works only with red numbers"); - return (this || _global$6).red.sub(this || _global$6, num); + assert((this || _global$d).red, "redSub works only with red numbers"); + return (this || _global$d).red.sub(this || _global$d, num); }; - BN.prototype.redISub = function redISub(num) { - assert((this || _global$6).red, "redISub works only with red numbers"); - return (this || _global$6).red.isub(this || _global$6, num); + assert((this || _global$d).red, "redISub works only with red numbers"); + return (this || _global$d).red.isub(this || _global$d, num); }; - BN.prototype.redShl = function redShl(num) { - assert((this || _global$6).red, "redShl works only with red numbers"); - return (this || _global$6).red.shl(this || _global$6, num); + assert((this || _global$d).red, "redShl works only with red numbers"); + return (this || _global$d).red.shl(this || _global$d, num); }; - BN.prototype.redMul = function redMul(num) { - assert((this || _global$6).red, "redMul works only with red numbers"); - - (this || _global$6).red._verify2(this || _global$6, num); - - return (this || _global$6).red.mul(this || _global$6, num); + assert((this || _global$d).red, "redMul works only with red numbers"); + (this || _global$d).red._verify2(this || _global$d, num); + return (this || _global$d).red.mul(this || _global$d, num); }; - BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$6).red, "redMul works only with red numbers"); - - (this || _global$6).red._verify2(this || _global$6, num); - - return (this || _global$6).red.imul(this || _global$6, num); + assert((this || _global$d).red, "redMul works only with red numbers"); + (this || _global$d).red._verify2(this || _global$d, num); + return (this || _global$d).red.imul(this || _global$d, num); }; - BN.prototype.redSqr = function redSqr() { - assert((this || _global$6).red, "redSqr works only with red numbers"); - - (this || _global$6).red._verify1(this || _global$6); - - return (this || _global$6).red.sqr(this || _global$6); + assert((this || _global$d).red, "redSqr works only with red numbers"); + (this || _global$d).red._verify1(this || _global$d); + return (this || _global$d).red.sqr(this || _global$d); }; - BN.prototype.redISqr = function redISqr() { - assert((this || _global$6).red, "redISqr works only with red numbers"); - - (this || _global$6).red._verify1(this || _global$6); - - return (this || _global$6).red.isqr(this || _global$6); - }; // Square root over p - + assert((this || _global$d).red, "redISqr works only with red numbers"); + (this || _global$d).red._verify1(this || _global$d); + return (this || _global$d).red.isqr(this || _global$d); + }; + // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$6).red, "redSqrt works only with red numbers"); - - (this || _global$6).red._verify1(this || _global$6); - - return (this || _global$6).red.sqrt(this || _global$6); + assert((this || _global$d).red, "redSqrt works only with red numbers"); + (this || _global$d).red._verify1(this || _global$d); + return (this || _global$d).red.sqrt(this || _global$d); }; - BN.prototype.redInvm = function redInvm() { - assert((this || _global$6).red, "redInvm works only with red numbers"); - - (this || _global$6).red._verify1(this || _global$6); - - return (this || _global$6).red.invm(this || _global$6); - }; // Return negative clone of `this` % `red modulo` - + assert((this || _global$d).red, "redInvm works only with red numbers"); + (this || _global$d).red._verify1(this || _global$d); + return (this || _global$d).red.invm(this || _global$d); + }; + // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$6).red, "redNeg works only with red numbers"); - - (this || _global$6).red._verify1(this || _global$6); - - return (this || _global$6).red.neg(this || _global$6); + assert((this || _global$d).red, "redNeg works only with red numbers"); + (this || _global$d).red._verify1(this || _global$d); + return (this || _global$d).red.neg(this || _global$d); }; - BN.prototype.redPow = function redPow(num) { - assert((this || _global$6).red && !num.red, "redPow(normalNum)"); - - (this || _global$6).red._verify1(this || _global$6); - - return (this || _global$6).red.pow(this || _global$6, num); - }; // Prime numbers with efficient reduction - + assert((this || _global$d).red && !num.red, "redPow(normalNum)"); + (this || _global$d).red._verify1(this || _global$d); + return (this || _global$d).red.pow(this || _global$d, num); + }; + // Prime numbers with efficient reduction var primes = { k256: null, p224: null, p192: null, p25519: null - }; // Pseudo-Mersenne prime + }; + // Pseudo-Mersenne prime function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$6).name = name; - (this || _global$6).p = new BN(p, 16); - (this || _global$6).n = (this || _global$6).p.bitLength(); - (this || _global$6).k = new BN(1).iushln((this || _global$6).n).isub((this || _global$6).p); - (this || _global$6).tmp = this._tmp(); + (this || _global$d).name = name; + (this || _global$d).p = new BN(p, 16); + (this || _global$d).n = (this || _global$d).p.bitLength(); + (this || _global$d).k = new BN(1).iushln((this || _global$d).n).isub((this || _global$d).p); + (this || _global$d).tmp = this._tmp(); } - MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$6).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$d).n / 13)); return tmp; }; - MPrime.prototype.ireduce = function ireduce(num) { // Assumes that `num` is less than `P^2` // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) var r = num; var rlen; - do { - this.split(r, (this || _global$6).tmp); + this.split(r, (this || _global$d).tmp); r = this.imulK(r); - r = r.iadd((this || _global$6).tmp); + r = r.iadd((this || _global$d).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$6).n); - - var cmp = rlen < (this || _global$6).n ? -1 : r.ucmp((this || _global$6).p); - + } while (rlen > (this || _global$d).n); + var cmp = rlen < (this || _global$d).n ? -1 : r.ucmp((this || _global$d).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$6).p); + r.isub((this || _global$d).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -58392,111 +94113,88 @@ function dew$V() { r._strip(); } } - return r; }; - MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$6).n, 0, out); + input.iushrn((this || _global$d).n, 0, out); }; - MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$6).k); + return num.imul((this || _global$d).k); }; - function K256() { - MPrime.call(this || _global$6, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$d, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - inherits(K256, MPrime); - K256.prototype.split = function split(input, output) { // 256 = 9 * 26 + 22 var mask = 4194303; var outLen = Math.min(input.length, 9); - for (var i = 0; i < outLen; i++) { output.words[i] = input.words[i]; } - output.length = outLen; - if (input.length <= 9) { input.words[0] = 0; input.length = 1; return; - } // Shift by 9 limbs - + } + // Shift by 9 limbs var prev = input.words[9]; output.words[output.length++] = prev & mask; - for (i = 10; i < input.length; i++) { var next = input.words[i] | 0; input.words[i - 10] = (next & mask) << 4 | prev >>> 22; prev = next; } - prev >>>= 22; input.words[i - 10] = prev; - if (prev === 0 && input.length > 10) { input.length -= 10; } else { input.length -= 9; } }; - K256.prototype.imulK = function imulK(num) { // K = 0x1000003d1 = [ 0x40, 0x3d1 ] num.words[num.length] = 0; num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + num.length += 2; + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 var lo = 0; - for (var i = 0; i < num.length; i++) { var w = num.words[i] | 0; lo += w * 977; num.words[i] = lo & 67108863; lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction - + } + // Fast length reduction if (num.words[num.length - 1] === 0) { num.length--; - if (num.words[num.length - 1] === 0) { num.length--; } } - return num; }; - function P224() { - MPrime.call(this || _global$6, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$d, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } - inherits(P224, MPrime); - function P192() { - MPrime.call(this || _global$6, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$d, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } - inherits(P192, MPrime); - function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$6, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$d, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } - inherits(P25519, MPrime); - P25519.prototype.imulK = function imulK(num) { // K = 0x13 var carry = 0; - for (var i = 0; i < num.length; i++) { var hi = (num.words[i] | 0) * 19 + carry; var lo = hi & 67108863; @@ -58504,20 +94202,17 @@ function dew$V() { num.words[i] = lo; carry = hi; } - if (carry !== 0) { num.words[num.length++] = carry; } - return num; - }; // Exported mostly for testing purposes, use plain name instead - + }; + // Exported mostly for testing purposes, use plain name instead BN._prime = function prime(name) { // Cached version of prime if (primes[name]) return primes[name]; var prime; - if (name === "k256") { prime = new K256(); } else if (name === "p224") { @@ -58529,176 +94224,133 @@ function dew$V() { } else { throw new Error("Unknown prime " + name); } - primes[name] = prime; return prime; - }; // + }; + + // // Base reduction engine // - - function Red(m) { if (typeof m === "string") { var prime = BN._prime(m); - - (this || _global$6).m = prime.p; - (this || _global$6).prime = prime; + (this || _global$d).m = prime.p; + (this || _global$d).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$6).m = m; - (this || _global$6).prime = null; + (this || _global$d).m = m; + (this || _global$d).prime = null; } } - Red.prototype._verify1 = function _verify1(a) { assert(a.negative === 0, "red works only with positives"); assert(a.red, "red works only with red numbers"); }; - Red.prototype._verify2 = function _verify2(a, b) { assert((a.negative | b.negative) === 0, "red works only with positives"); assert(a.red && a.red === b.red, "red works only with red numbers"); }; - Red.prototype.imod = function imod(a) { - if ((this || _global$6).prime) return (this || _global$6).prime.ireduce(a)._forceRed(this || _global$6); - return a.umod((this || _global$6).m)._forceRed(this || _global$6); + if ((this || _global$d).prime) return (this || _global$d).prime.ireduce(a)._forceRed(this || _global$d); + return a.umod((this || _global$d).m)._forceRed(this || _global$d); }; - Red.prototype.neg = function neg(a) { if (a.isZero()) { return a.clone(); } - - return (this || _global$6).m.sub(a)._forceRed(this || _global$6); + return (this || _global$d).m.sub(a)._forceRed(this || _global$d); }; - Red.prototype.add = function add(a, b) { this._verify2(a, b); - var res = a.add(b); - - if (res.cmp((this || _global$6).m) >= 0) { - res.isub((this || _global$6).m); + if (res.cmp((this || _global$d).m) >= 0) { + res.isub((this || _global$d).m); } - - return res._forceRed(this || _global$6); + return res._forceRed(this || _global$d); }; - Red.prototype.iadd = function iadd(a, b) { this._verify2(a, b); - var res = a.iadd(b); - - if (res.cmp((this || _global$6).m) >= 0) { - res.isub((this || _global$6).m); + if (res.cmp((this || _global$d).m) >= 0) { + res.isub((this || _global$d).m); } - return res; }; - Red.prototype.sub = function sub(a, b) { this._verify2(a, b); - var res = a.sub(b); - if (res.cmpn(0) < 0) { - res.iadd((this || _global$6).m); + res.iadd((this || _global$d).m); } - - return res._forceRed(this || _global$6); + return res._forceRed(this || _global$d); }; - Red.prototype.isub = function isub(a, b) { this._verify2(a, b); - var res = a.isub(b); - if (res.cmpn(0) < 0) { - res.iadd((this || _global$6).m); + res.iadd((this || _global$d).m); } - return res; }; - Red.prototype.shl = function shl(a, num) { this._verify1(a); - return this.imod(a.ushln(num)); }; - Red.prototype.imul = function imul(a, b) { this._verify2(a, b); - return this.imod(a.imul(b)); }; - Red.prototype.mul = function mul(a, b) { this._verify2(a, b); - return this.imod(a.mul(b)); }; - Red.prototype.isqr = function isqr(a) { return this.imul(a, a.clone()); }; - Red.prototype.sqr = function sqr(a) { return this.mul(a, a); }; - Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); + var mod3 = (this || _global$d).m.andln(3); + assert(mod3 % 2 === 1); - var mod3 = (this || _global$6).m.andln(3); - - assert(mod3 % 2 === 1); // Fast case - + // Fast case if (mod3 === 3) { - var pow = (this || _global$6).m.add(new BN(1)).iushrn(2); - + var pow = (this || _global$d).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) // // Find Q and S, that Q * 2 ^ S = (P - 1) - - - var q = (this || _global$6).m.subn(1); - + var q = (this || _global$d).m.subn(1); var s = 0; - while (!q.isZero() && q.andln(1) === 0) { s++; q.iushrn(1); } - assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$6); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. - - var lpow = (this || _global$6).m.subn(1).iushrn(1); - - var z = (this || _global$6).m.bitLength(); - - z = new BN(2 * z * z).toRed(this || _global$6); + var one = new BN(1).toRed(this || _global$d); + var nOne = one.redNeg(); + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + var lpow = (this || _global$d).m.subn(1).iushrn(1); + var z = (this || _global$d).m.bitLength(); + z = new BN(2 * z * z).toRed(this || _global$d); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); } - var c = this.pow(z, q); var r = this.pow(a, q.addn(1).iushrn(1)); var t = this.pow(a, q); var m = s; - while (t.cmp(one) !== 0) { var tmp = t; - for (var i = 0; tmp.cmp(one) !== 0; i++) { tmp = tmp.redSqr(); } - assert(i < m); var b = this.pow(c, new BN(1).iushln(m - i - 1)); r = r.redMul(b); @@ -58706,13 +94358,10 @@ function dew$V() { t = t.redMul(c); m = i; } - return r; }; - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$6).m); - + var inv = a._invmp((this || _global$d).m); if (inv.negative !== 0) { inv.negative = 0; return this.imod(inv).redNeg(); @@ -58720,43 +94369,34 @@ function dew$V() { return this.imod(inv); } }; - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$6); + if (num.isZero()) return new BN(1).toRed(this || _global$d); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$6); + wnd[0] = new BN(1).toRed(this || _global$d); wnd[1] = a; - for (var i = 2; i < wnd.length; i++) { wnd[i] = this.mul(wnd[i - 1], a); } - var res = wnd[0]; var current = 0; var currentLen = 0; var start = num.bitLength() % 26; - if (start === 0) { start = 26; } - for (i = num.length - 1; i >= 0; i--) { var word = num.words[i]; - for (var j = start - 1; j >= 0; j--) { var bit = word >> j & 1; - if (res !== wnd[0]) { res = this.sqr(res); } - if (bit === 0 && current === 0) { currentLen = 0; continue; } - current <<= 1; current |= bit; currentLen++; @@ -58765,128 +94405,105 @@ function dew$V() { currentLen = 0; current = 0; } - start = 26; } - return res; }; - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$6).m); + var r = num.umod((this || _global$d).m); return r === num ? r.clone() : r; }; - Red.prototype.convertFrom = function convertFrom(num) { var res = num.clone(); res.red = null; return res; - }; // + }; + + // // Montgomery method engine // - BN.mont = function mont(num) { return new Mont(num); }; - function Mont(m) { - Red.call(this || _global$6, m); - (this || _global$6).shift = (this || _global$6).m.bitLength(); - - if ((this || _global$6).shift % 26 !== 0) { - (this || _global$6).shift += 26 - (this || _global$6).shift % 26; + Red.call(this || _global$d, m); + (this || _global$d).shift = (this || _global$d).m.bitLength(); + if ((this || _global$d).shift % 26 !== 0) { + (this || _global$d).shift += 26 - (this || _global$d).shift % 26; } - - (this || _global$6).r = new BN(1).iushln((this || _global$6).shift); - (this || _global$6).r2 = this.imod((this || _global$6).r.sqr()); - (this || _global$6).rinv = (this || _global$6).r._invmp((this || _global$6).m); - (this || _global$6).minv = (this || _global$6).rinv.mul((this || _global$6).r).isubn(1).div((this || _global$6).m); - (this || _global$6).minv = (this || _global$6).minv.umod((this || _global$6).r); - (this || _global$6).minv = (this || _global$6).r.sub((this || _global$6).minv); + (this || _global$d).r = new BN(1).iushln((this || _global$d).shift); + (this || _global$d).r2 = this.imod((this || _global$d).r.sqr()); + (this || _global$d).rinv = (this || _global$d).r._invmp((this || _global$d).m); + (this || _global$d).minv = (this || _global$d).rinv.mul((this || _global$d).r).isubn(1).div((this || _global$d).m); + (this || _global$d).minv = (this || _global$d).minv.umod((this || _global$d).r); + (this || _global$d).minv = (this || _global$d).r.sub((this || _global$d).minv); } - inherits(Mont, Red); - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$6).shift)); + return this.imod(num.ushln((this || _global$d).shift)); }; - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$6).rinv)); + var r = this.imod(num.mul((this || _global$d).rinv)); r.red = null; return r; }; - Mont.prototype.imul = function imul(a, b) { if (a.isZero() || b.isZero()) { a.words[0] = 0; a.length = 1; return a; } - var t = a.imul(b); - var c = t.maskn((this || _global$6).shift).mul((this || _global$6).minv).imaskn((this || _global$6).shift).mul((this || _global$6).m); - var u = t.isub(c).iushrn((this || _global$6).shift); + var c = t.maskn((this || _global$d).shift).mul((this || _global$d).minv).imaskn((this || _global$d).shift).mul((this || _global$d).m); + var u = t.isub(c).iushrn((this || _global$d).shift); var res = u; - - if (u.cmp((this || _global$6).m) >= 0) { - res = u.isub((this || _global$6).m); + if (u.cmp((this || _global$d).m) >= 0) { + res = u.isub((this || _global$d).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$6).m); + res = u.iadd((this || _global$d).m); } - - return res._forceRed(this || _global$6); + return res._forceRed(this || _global$d); }; - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$6); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$d); var t = a.mul(b); - var c = t.maskn((this || _global$6).shift).mul((this || _global$6).minv).imaskn((this || _global$6).shift).mul((this || _global$6).m); - var u = t.isub(c).iushrn((this || _global$6).shift); + var c = t.maskn((this || _global$d).shift).mul((this || _global$d).minv).imaskn((this || _global$d).shift).mul((this || _global$d).m); + var u = t.isub(c).iushrn((this || _global$d).shift); var res = u; - - if (u.cmp((this || _global$6).m) >= 0) { - res = u.isub((this || _global$6).m); + if (u.cmp((this || _global$d).m) >= 0) { + res = u.isub((this || _global$d).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$6).m); + res = u.iadd((this || _global$d).m); } - - return res._forceRed(this || _global$6); + return res._forceRed(this || _global$d); }; - Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$6).m).mul((this || _global$6).r2)); - return res._forceRed(this || _global$6); + var res = this.imod(a._invmp((this || _global$d).m).mul((this || _global$d).r2)); + return res._forceRed(this || _global$d); }; - })(module$3, exports$W); - + })(module$3, exports$$); return module$3.exports; } -var exports$V = {}, - _dewExec$U = false; -function dew$U() { - if (_dewExec$U) return exports$V; - _dewExec$U = true; - var utils = exports$V; - +var exports$_ = {}, + _dewExec$Z = false; +function dew$Z() { + if (_dewExec$Z) return exports$_; + _dewExec$Z = true; + var utils = exports$_; function toArray(msg, enc) { if (Array.isArray(msg)) return msg.slice(); if (!msg) return []; var res = []; - if (typeof msg !== "string") { for (var i = 0; i < msg.length; i++) res[i] = msg[i] | 0; - return res; } - if (enc === "hex") { msg = msg.replace(/[^a-z0-9]+/ig, ""); if (msg.length % 2 !== 0) msg = "0" + msg; - for (var i = 0; i < msg.length; i += 2) res.push(parseInt(msg[i] + msg[i + 1], 16)); } else { for (var i = 0; i < msg.length; i++) { @@ -58896,80 +94513,66 @@ function dew$U() { if (hi) res.push(hi, lo);else res.push(lo); } } - return res; } - utils.toArray = toArray; - function zero2(word) { if (word.length === 1) return "0" + word;else return word; } - utils.zero2 = zero2; - function toHex(msg) { var res = ""; - for (var i = 0; i < msg.length; i++) res += zero2(msg[i].toString(16)); - return res; } - utils.toHex = toHex; - utils.encode = function encode(arr, enc) { if (enc === "hex") return toHex(arr);else return arr; }; - - return exports$V; + return exports$_; } -var exports$U = {}, - _dewExec$T = false; -function dew$T() { - if (_dewExec$T) return exports$U; - _dewExec$T = true; - var utils = exports$U; - - var BN = dew$V(); - - var minAssert = dew$2m(); - - var minUtils = dew$U(); - +var exports$Z = {}, + _dewExec$Y = false; +function dew$Y() { + if (_dewExec$Y) return exports$Z; + _dewExec$Y = true; + var utils = exports$Z; + var BN = dew$_(); + var minAssert = dew$3h(); + var minUtils = dew$Z(); utils.assert = minAssert; utils.toArray = minUtils.toArray; utils.zero2 = minUtils.zero2; utils.toHex = minUtils.toHex; - utils.encode = minUtils.encode; // Represent num in a w-NAF form + utils.encode = minUtils.encode; + // Represent num in a w-NAF form function getNAF(num, w, bits) { var naf = new Array(Math.max(num.bitLength(), bits) + 1); - naf.fill(0); + var i; + for (i = 0; i < naf.length; i += 1) { + naf[i] = 0; + } var ws = 1 << w + 1; var k = num.clone(); - - for (var i = 0; i < naf.length; i++) { + for (i = 0; i < naf.length; i++) { var z; var mod = k.andln(ws - 1); - if (k.isOdd()) { if (mod > (ws >> 1) - 1) z = (ws >> 1) - mod;else z = mod; k.isubn(z); } else { z = 0; } - naf[i] = z; k.iushrn(1); } - return naf; } + utils.getNAF = getNAF; - utils.getNAF = getNAF; // Represent k1, k2 in a Joint Sparse Form - + // Represent k1, k2 in a Joint Sparse Form function getJSF(k1, k2) { var jsf = [[], []]; k1 = k1.clone(); @@ -58977,7 +94580,6 @@ function dew$T() { var d1 = 0; var d2 = 0; var m8; - while (k1.cmpn(-d1) > 0 || k2.cmpn(-d2) > 0) { // First phase var m14 = k1.andln(3) + d1 & 3; @@ -58985,96 +94587,84 @@ function dew$T() { if (m14 === 3) m14 = -1; if (m24 === 3) m24 = -1; var u1; - if ((m14 & 1) === 0) { u1 = 0; } else { m8 = k1.andln(7) + d1 & 7; if ((m8 === 3 || m8 === 5) && m24 === 2) u1 = -m14;else u1 = m14; } - jsf[0].push(u1); var u2; - if ((m24 & 1) === 0) { u2 = 0; } else { m8 = k2.andln(7) + d2 & 7; if ((m8 === 3 || m8 === 5) && m14 === 2) u2 = -m24;else u2 = m24; } + jsf[1].push(u2); - jsf[1].push(u2); // Second phase - + // Second phase if (2 * d1 === u1 + 1) d1 = 1 - d1; if (2 * d2 === u2 + 1) d2 = 1 - d2; k1.iushrn(1); k2.iushrn(1); } - return jsf; } - utils.getJSF = getJSF; - function cachedProperty(obj, name, computer) { var key = "_" + name; - obj.prototype[name] = function cachedProperty() { return this[key] !== undefined ? this[key] : this[key] = computer.call(this); }; } - utils.cachedProperty = cachedProperty; - function parseBytes(bytes) { return typeof bytes === "string" ? utils.toArray(bytes, "hex") : bytes; } - utils.parseBytes = parseBytes; - function intFromLE(bytes) { return new BN(bytes, "hex", "le"); } - utils.intFromLE = intFromLE; - return exports$U; + return exports$Z; } -var exports$T = {}, - _dewExec$S = false; -function dew$S() { - if (_dewExec$S) return exports$T; - _dewExec$S = true; - - var BN = dew$V(); - - var utils = dew$T(); - +var exports$Y = {}, + _dewExec$X = false; +function dew$X() { + if (_dewExec$X) return exports$Y; + _dewExec$X = true; + var BN = dew$_(); + var utils = dew$Y(); var getNAF = utils.getNAF; var getJSF = utils.getJSF; var assert = utils.assert; - function BaseCurve(type, conf) { this.type = type; - this.p = new BN(conf.p, 16); // Use Montgomery, when there is no fast reduction for the prime + this.p = new BN(conf.p, 16); - this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); // Useful for many curves + // Use Montgomery, when there is no fast reduction for the prime + this.red = conf.prime ? BN.red(conf.prime) : BN.mont(this.p); + // Useful for many curves this.zero = new BN(0).toRed(this.red); this.one = new BN(1).toRed(this.red); - this.two = new BN(2).toRed(this.red); // Curve configuration, optional + this.two = new BN(2).toRed(this.red); + // Curve configuration, optional this.n = conf.n && new BN(conf.n, 16); - this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); // Temporary arrays + this.g = conf.g && this.pointFromJSON(conf.g, conf.gRed); + // Temporary arrays this._wnafT1 = new Array(4); this._wnafT2 = new Array(4); this._wnafT3 = new Array(4); this._wnafT4 = new Array(4); - this._bitLength = this.n ? this.n.bitLength() : 0; // Generalized Greg Maxwell's trick + this._bitLength = this.n ? this.n.bitLength() : 0; + // Generalized Greg Maxwell's trick var adjustCount = this.n && this.p.div(this.n); - if (!adjustCount || adjustCount.cmpn(100) > 0) { this.redN = null; } else { @@ -59082,75 +94672,61 @@ function dew$S() { this.redN = this.n.toRed(this.red); } } - - exports$T = BaseCurve; - + exports$Y = BaseCurve; BaseCurve.prototype.point = function point() { throw new Error("Not implemented"); }; - BaseCurve.prototype.validate = function validate() { throw new Error("Not implemented"); }; - BaseCurve.prototype._fixedNafMul = function _fixedNafMul(p, k) { assert(p.precomputed); - var doubles = p._getDoubles(); - var naf = getNAF(k, 1, this._bitLength); var I = (1 << doubles.step + 1) - (doubles.step % 2 === 0 ? 2 : 1); - I /= 3; // Translate into more windowed form + I /= 3; + // Translate into more windowed form var repr = []; var j; var nafW; - for (j = 0; j < naf.length; j += doubles.step) { nafW = 0; - for (var l = j + doubles.step - 1; l >= j; l--) nafW = (nafW << 1) + naf[l]; - repr.push(nafW); } - var a = this.jpoint(null, null, null); var b = this.jpoint(null, null, null); - for (var i = I; i > 0; i--) { for (j = 0; j < repr.length; j++) { nafW = repr[j]; if (nafW === i) b = b.mixedAdd(doubles.points[j]);else if (nafW === -i) b = b.mixedAdd(doubles.points[j].neg()); } - a = a.add(b); } - return a.toP(); }; - BaseCurve.prototype._wnafMul = function _wnafMul(p, k) { - var w = 4; // Precompute window + var w = 4; + // Precompute window var nafPoints = p._getNAFPoints(w); - w = nafPoints.wnd; - var wnd = nafPoints.points; // Get NAF form + var wnd = nafPoints.points; - var naf = getNAF(k, w, this._bitLength); // Add `this`*(N+1) for every w-NAF index + // Get NAF form + var naf = getNAF(k, w, this._bitLength); + // Add `this`*(N+1) for every w-NAF index var acc = this.jpoint(null, null, null); - for (var i = naf.length - 1; i >= 0; i--) { // Count zeroes for (var l = 0; i >= 0 && naf[i] === 0; i--) l++; - if (i >= 0) l++; acc = acc.dblp(l); if (i < 0) break; var z = naf[i]; assert(z !== 0); - if (p.type === "affine") { // J +- P if (z > 0) acc = acc.mixedAdd(wnd[z - 1 >> 1]);else acc = acc.mixedAdd(wnd[-z - 1 >> 1].neg()); @@ -59159,34 +94735,29 @@ function dew$S() { if (z > 0) acc = acc.add(wnd[z - 1 >> 1]);else acc = acc.add(wnd[-z - 1 >> 1].neg()); } } - return p.type === "affine" ? acc.toP() : acc; }; - BaseCurve.prototype._wnafMulAdd = function _wnafMulAdd(defW, points, coeffs, len, jacobianResult) { var wndWidth = this._wnafT1; var wnd = this._wnafT2; - var naf = this._wnafT3; // Fill all arrays + var naf = this._wnafT3; + // Fill all arrays var max = 0; var i; var j; var p; - for (i = 0; i < len; i++) { p = points[i]; - var nafPoints = p._getNAFPoints(defW); - wndWidth[i] = nafPoints.wnd; wnd[i] = nafPoints.points; - } // Comb small window NAFs - + } + // Comb small window NAFs for (i = len - 1; i >= 1; i -= 2) { var a = i - 1; var b = i; - if (wndWidth[a] !== 1 || wndWidth[b] !== 1) { naf[a] = getNAF(coeffs[a], wndWidth[a], this._bitLength); naf[b] = getNAF(coeffs[b], wndWidth[b], this._bitLength); @@ -59194,17 +94765,12 @@ function dew$S() { max = Math.max(naf[b].length, max); continue; } + var comb = [points[a], /* 1 */ + null, /* 3 */ + null, /* 5 */ + points[b] /* 7 */]; - var comb = [points[a], - /* 1 */ - null, - /* 3 */ - null, - /* 5 */ - points[b] - /* 7 */ - ]; // Try to avoid Projective points, if possible - + // Try to avoid Projective points, if possible if (points[a].y.cmp(points[b].y) === 0) { comb[1] = points[a].add(points[b]); comb[2] = points[a].toJ().mixedAdd(points[b].neg()); @@ -59215,31 +94781,19 @@ function dew$S() { comb[1] = points[a].toJ().mixedAdd(points[b]); comb[2] = points[a].toJ().mixedAdd(points[b].neg()); } - - var index = [-3, - /* -1 -1 */ - -1, - /* -1 0 */ - -5, - /* -1 1 */ - -7, - /* 0 -1 */ - 0, - /* 0 0 */ - 7, - /* 0 1 */ - 5, - /* 1 -1 */ - 1, - /* 1 0 */ - 3 - /* 1 1 */ - ]; + var index = [-3, /* -1 -1 */ + -1, /* -1 0 */ + -5, /* -1 1 */ + -7, /* 0 -1 */ + 0, /* 0 0 */ + 7, /* 0 1 */ + 5, /* 1 -1 */ + 1, /* 1 0 */ + 3 /* 1 1 */]; var jsf = getJSF(coeffs[a], coeffs[b]); max = Math.max(jsf[0].length, max); naf[a] = new Array(max); naf[b] = new Array(max); - for (j = 0; j < max; j++) { var ja = jsf[0][j] | 0; var jb = jsf[1][j] | 0; @@ -59248,63 +94802,51 @@ function dew$S() { wnd[a] = comb; } } - var acc = this.jpoint(null, null, null); var tmp = this._wnafT4; - for (i = max; i >= 0; i--) { var k = 0; - while (i >= 0) { var zero = true; - for (j = 0; j < len; j++) { tmp[j] = naf[j][i] | 0; if (tmp[j] !== 0) zero = false; } - if (!zero) break; k++; i--; } - if (i >= 0) k++; acc = acc.dblp(k); if (i < 0) break; - for (j = 0; j < len; j++) { var z = tmp[j]; if (z === 0) continue;else if (z > 0) p = wnd[j][z - 1 >> 1];else if (z < 0) p = wnd[j][-z - 1 >> 1].neg(); if (p.type === "affine") acc = acc.mixedAdd(p);else acc = acc.add(p); } - } // Zeroify references - - + } + // Zeroify references for (i = 0; i < len; i++) wnd[i] = null; - if (jacobianResult) return acc;else return acc.toP(); }; - function BasePoint(curve, type) { this.curve = curve; this.type = type; this.precomputed = null; } - BaseCurve.BasePoint = BasePoint; - - BasePoint.prototype.eq = function eq() { + BasePoint.prototype.eq = function eq(/*other*/ + ) { throw new Error("Not implemented"); }; - BasePoint.prototype.validate = function validate() { return this.curve.validate(this); }; - BaseCurve.prototype.decodePoint = function decodePoint(bytes, enc) { bytes = utils.toArray(bytes, enc); - var len = this.p.byteLength(); // uncompressed, hybrid-odd, hybrid-even + var len = this.p.byteLength(); + // uncompressed, hybrid-odd, hybrid-even if ((bytes[0] === 4 || bytes[0] === 6 || bytes[0] === 7) && bytes.length - 1 === 2 * len) { if (bytes[0] === 6) assert(bytes[bytes.length - 1] % 2 === 0);else if (bytes[0] === 7) assert(bytes[bytes.length - 1] % 2 === 1); var res = this.point(bytes.slice(1, 1 + len), bytes.slice(1 + len, 1 + 2 * len)); @@ -59312,25 +94854,20 @@ function dew$S() { } else if ((bytes[0] === 2 || bytes[0] === 3) && bytes.length - 1 === len) { return this.pointFromX(bytes.slice(1, 1 + len), bytes[0] === 3); } - throw new Error("Unknown point format"); }; - BasePoint.prototype.encodeCompressed = function encodeCompressed(enc) { return this.encode(enc, true); }; - BasePoint.prototype._encode = function _encode(compact) { var len = this.curve.p.byteLength(); var x = this.getX().toArray("be", len); if (compact) return [this.getY().isEven() ? 2 : 3].concat(x); return [4].concat(x, this.getY().toArray("be", len)); }; - BasePoint.prototype.encode = function encode(enc, compact) { return utils.encode(this._encode(compact), enc); }; - BasePoint.prototype.precompute = function precompute(power) { if (this.precomputed) return this; var precomputed = { @@ -59344,126 +94881,102 @@ function dew$S() { this.precomputed = precomputed; return this; }; - BasePoint.prototype._hasDoubles = function _hasDoubles(k) { if (!this.precomputed) return false; var doubles = this.precomputed.doubles; if (!doubles) return false; return doubles.points.length >= Math.ceil((k.bitLength() + 1) / doubles.step); }; - BasePoint.prototype._getDoubles = function _getDoubles(step, power) { if (this.precomputed && this.precomputed.doubles) return this.precomputed.doubles; var doubles = [this]; var acc = this; - for (var i = 0; i < power; i += step) { for (var j = 0; j < step; j++) acc = acc.dbl(); - doubles.push(acc); } - return { step: step, points: doubles }; }; - BasePoint.prototype._getNAFPoints = function _getNAFPoints(wnd) { if (this.precomputed && this.precomputed.naf) return this.precomputed.naf; var res = [this]; var max = (1 << wnd) - 1; var dbl = max === 1 ? null : this.dbl(); - for (var i = 1; i < max; i++) res[i] = res[i - 1].add(dbl); - return { wnd: wnd, points: res }; }; - BasePoint.prototype._getBeta = function _getBeta() { return null; }; - BasePoint.prototype.dblp = function dblp(k) { var r = this; - for (var i = 0; i < k; i++) r = r.dbl(); - return r; }; - - return exports$T; + return exports$Y; } -var exports$S = {}, - _dewExec$R = false; -function dew$R() { - if (_dewExec$R) return exports$S; - _dewExec$R = true; - - var utils = dew$T(); - - var BN = dew$V(); - - var inherits = dew$2R(); - - var Base = dew$S(); - +var exports$X = {}, + _dewExec$W = false; +function dew$W() { + if (_dewExec$W) return exports$X; + _dewExec$W = true; + var utils = dew$Y(); + var BN = dew$_(); + var inherits = dew$3I(); + var Base = dew$X(); var assert = utils.assert; - function ShortCurve(conf) { Base.call(this, "short", conf); this.a = new BN(conf.a, 16).toRed(this.red); this.b = new BN(conf.b, 16).toRed(this.red); this.tinv = this.two.redInvm(); this.zeroA = this.a.fromRed().cmpn(0) === 0; - this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; // If the curve is endomorphic, precalculate beta and lambda + this.threeA = this.a.fromRed().sub(this.p).cmpn(-3) === 0; + // If the curve is endomorphic, precalculate beta and lambda this.endo = this._getEndomorphism(conf); this._endoWnafT1 = new Array(4); this._endoWnafT2 = new Array(4); } - inherits(ShortCurve, Base); - exports$S = ShortCurve; - + exports$X = ShortCurve; ShortCurve.prototype._getEndomorphism = function _getEndomorphism(conf) { // No efficient endomorphism - if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return; // Compute beta and lambda, that lambda * P = (beta * Px; Py) + if (!this.zeroA || !this.g || !this.n || this.p.modn(3) !== 1) return; + // Compute beta and lambda, that lambda * P = (beta * Px; Py) var beta; var lambda; - if (conf.beta) { beta = new BN(conf.beta, 16).toRed(this.red); } else { - var betas = this._getEndoRoots(this.p); // Choose the smallest beta - - + var betas = this._getEndoRoots(this.p); + // Choose the smallest beta beta = betas[0].cmp(betas[1]) < 0 ? betas[0] : betas[1]; beta = beta.toRed(this.red); } - if (conf.lambda) { lambda = new BN(conf.lambda, 16); } else { // Choose the lambda that is matching selected beta var lambdas = this._getEndoRoots(this.n); - if (this.g.mul(lambdas[0]).x.cmp(this.g.x.redMul(beta)) === 0) { lambda = lambdas[0]; } else { lambda = lambdas[1]; assert(this.g.mul(lambda).x.cmp(this.g.x.redMul(beta)) === 0); } - } // Get basis vectors, used for balanced length-two representation - + } + // Get basis vectors, used for balanced length-two representation var basis; - if (conf.basis) { basis = conf.basis.map(function (vec) { return { @@ -59474,14 +94987,12 @@ function dew$R() { } else { basis = this._getEndoBasis(lambda); } - return { beta: beta, lambda: lambda, basis: basis }; }; - ShortCurve.prototype._getEndoRoots = function _getEndoRoots(num) { // Find roots of for x^2 + x + 1 in F // Root = (-1 +- Sqrt(-3)) / 2 @@ -59494,38 +95005,37 @@ function dew$R() { var l2 = ntinv.redSub(s).fromRed(); return [l1, l2]; }; - ShortCurve.prototype._getEndoBasis = function _getEndoBasis(lambda) { // aprxSqrt >= sqrt(this.n) - var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); // 3.74 - // Run EGCD, until r(L + 1) < aprxSqrt + var aprxSqrt = this.n.ushrn(Math.floor(this.n.bitLength() / 2)); + // 3.74 + // Run EGCD, until r(L + 1) < aprxSqrt var u = lambda; var v = this.n.clone(); var x1 = new BN(1); var y1 = new BN(0); var x2 = new BN(0); - var y2 = new BN(1); // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n) + var y2 = new BN(1); + // NOTE: all vectors are roots of: a + b * lambda = 0 (mod n) var a0; - var b0; // First vector - + var b0; + // First vector var a1; - var b1; // Second vector - + var b1; + // Second vector var a2; var b2; var prevR; var i = 0; var r; var x; - while (u.cmpn(0) !== 0) { var q = v.div(u); r = v.sub(q.mul(u)); x = x2.sub(q.mul(x1)); var y = y2.sub(q.mul(y1)); - if (!a1 && r.cmp(aprxSqrt) < 0) { a0 = prevR.neg(); b0 = x1; @@ -59534,7 +95044,6 @@ function dew$R() { } else if (a1 && ++i === 2) { break; } - prevR = r; v = u; u = r; @@ -59543,28 +95052,24 @@ function dew$R() { y2 = y1; y1 = y; } - a2 = r.neg(); b2 = x; var len1 = a1.sqr().add(b1.sqr()); var len2 = a2.sqr().add(b2.sqr()); - if (len2.cmp(len1) >= 0) { a2 = a0; b2 = b0; - } // Normalize signs - + } + // Normalize signs if (a1.negative) { a1 = a1.neg(); b1 = b1.neg(); } - if (a2.negative) { a2 = a2.neg(); b2 = b2.neg(); } - return [{ a: a1, b: b1 @@ -59573,7 +95078,6 @@ function dew$R() { b: b2 }]; }; - ShortCurve.prototype._endoSplit = function _endoSplit(k) { var basis = this.endo.basis; var v1 = basis[0]; @@ -59583,8 +95087,9 @@ function dew$R() { var p1 = c1.mul(v1.a); var p2 = c2.mul(v2.a); var q1 = c1.mul(v1.b); - var q2 = c2.mul(v2.b); // Calculate answer + var q2 = c2.mul(v2.b); + // Calculate answer var k1 = k.sub(p1).sub(p2); var k2 = q1.add(q2).neg(); return { @@ -59592,20 +95097,19 @@ function dew$R() { k2: k2 }; }; - ShortCurve.prototype.pointFromX = function pointFromX(x, odd) { x = new BN(x, 16); if (!x.red) x = x.toRed(this.red); var y2 = x.redSqr().redMul(x).redIAdd(x.redMul(this.a)).redIAdd(this.b); var y = y2.redSqrt(); - if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error("invalid point"); // XXX Is there any way to tell if the number is odd without converting it - // to non-red form? + if (y.redSqr().redSub(y2).cmp(this.zero) !== 0) throw new Error("invalid point"); + // XXX Is there any way to tell if the number is odd without converting it + // to non-red form? var isOdd = y.fromRed().isOdd(); if (odd && !isOdd || !odd && isOdd) y = y.redNeg(); return this.point(x, y); }; - ShortCurve.prototype.validate = function validate(point) { if (point.inf) return true; var x = point.x; @@ -59614,90 +95118,71 @@ function dew$R() { var rhs = x.redSqr().redMul(x).redIAdd(ax).redIAdd(this.b); return y.redSqr().redISub(rhs).cmpn(0) === 0; }; - ShortCurve.prototype._endoWnafMulAdd = function _endoWnafMulAdd(points, coeffs, jacobianResult) { var npoints = this._endoWnafT1; var ncoeffs = this._endoWnafT2; - for (var i = 0; i < points.length; i++) { var split = this._endoSplit(coeffs[i]); - var p = points[i]; - var beta = p._getBeta(); - if (split.k1.negative) { split.k1.ineg(); p = p.neg(true); } - if (split.k2.negative) { split.k2.ineg(); beta = beta.neg(true); } - npoints[i * 2] = p; npoints[i * 2 + 1] = beta; ncoeffs[i * 2] = split.k1; ncoeffs[i * 2 + 1] = split.k2; } + var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); - var res = this._wnafMulAdd(1, npoints, ncoeffs, i * 2, jacobianResult); // Clean-up references to points and coefficients - - + // Clean-up references to points and coefficients for (var j = 0; j < i * 2; j++) { npoints[j] = null; ncoeffs[j] = null; } - return res; }; - function Point(curve, x, y, isRed) { Base.BasePoint.call(this, curve, "affine"); - if (x === null && y === null) { this.x = null; this.y = null; this.inf = true; } else { this.x = new BN(x, 16); - this.y = new BN(y, 16); // Force redgomery representation when loading from JSON - + this.y = new BN(y, 16); + // Force redgomery representation when loading from JSON if (isRed) { this.x.forceRed(this.curve.red); this.y.forceRed(this.curve.red); } - if (!this.x.red) this.x = this.x.toRed(this.curve.red); if (!this.y.red) this.y = this.y.toRed(this.curve.red); this.inf = false; } } - inherits(Point, Base.BasePoint); - ShortCurve.prototype.point = function point(x, y, isRed) { return new Point(this, x, y, isRed); }; - ShortCurve.prototype.pointFromJSON = function pointFromJSON(obj, red) { return Point.fromJSON(this, obj, red); }; - Point.prototype._getBeta = function _getBeta() { if (!this.curve.endo) return; var pre = this.precomputed; if (pre && pre.beta) return pre.beta; var beta = this.curve.point(this.x.redMul(this.curve.endo.beta), this.y); - if (pre) { var curve = this.curve; - var endoMul = function (p) { return curve.point(p.x.redMul(curve.endo.beta), p.y); }; - pre.beta = beta; beta.precomputed = { beta: null, @@ -59711,10 +95196,8 @@ function dew$R() { } }; } - return beta; }; - Point.prototype.toJSON = function toJSON() { if (!this.precomputed) return [this.x, this.y]; return [this.x, this.y, this.precomputed && { @@ -59728,16 +95211,13 @@ function dew$R() { } }]; }; - Point.fromJSON = function fromJSON(curve, obj, red) { if (typeof obj === "string") obj = JSON.parse(obj); var res = curve.point(obj[0], obj[1], red); if (!obj[2]) return res; - function obj2point(obj) { return curve.point(obj[0], obj[1], red); } - var pre = obj[2]; res.precomputed = { beta: null, @@ -59752,26 +95232,27 @@ function dew$R() { }; return res; }; - Point.prototype.inspect = function inspect() { if (this.isInfinity()) return ""; return ""; }; - Point.prototype.isInfinity = function isInfinity() { return this.inf; }; - Point.prototype.add = function add(p) { // O + P = P - if (this.inf) return p; // P + O = P + if (this.inf) return p; - if (p.inf) return this; // P + P = 2P + // P + O = P + if (p.inf) return this; - if (this.eq(p)) return this.dbl(); // P + (-P) = O + // P + P = 2P + if (this.eq(p)) return this.dbl(); - if (this.neg().eq(p)) return this.curve.point(null, null); // P + Q = O + // P + (-P) = O + if (this.neg().eq(p)) return this.curve.point(null, null); + // P + Q = O if (this.x.cmp(p.x) === 0) return this.curve.point(null, null); var c = this.y.redSub(p.y); if (c.cmpn(0) !== 0) c = c.redMul(this.x.redSub(p.x).redInvm()); @@ -59779,10 +95260,10 @@ function dew$R() { var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); return this.curve.point(nx, ny); }; - Point.prototype.dbl = function dbl() { - if (this.inf) return this; // 2P = O + if (this.inf) return this; + // 2P = O var ys1 = this.y.redAdd(this.y); if (ys1.cmpn(0) === 0) return this.curve.point(null, null); var a = this.curve.a; @@ -59793,47 +95274,37 @@ function dew$R() { var ny = c.redMul(this.x.redSub(nx)).redISub(this.y); return this.curve.point(nx, ny); }; - Point.prototype.getX = function getX() { return this.x.fromRed(); }; - Point.prototype.getY = function getY() { return this.y.fromRed(); }; - Point.prototype.mul = function mul(k) { k = new BN(k, 16); if (this.isInfinity()) return this;else if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else if (this.curve.endo) return this.curve._endoWnafMulAdd([this], [k]);else return this.curve._wnafMul(this, k); }; - Point.prototype.mulAdd = function mulAdd(k1, p2, k2) { var points = [this, p2]; var coeffs = [k1, k2]; if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs);else return this.curve._wnafMulAdd(1, points, coeffs, 2); }; - Point.prototype.jmulAdd = function jmulAdd(k1, p2, k2) { var points = [this, p2]; var coeffs = [k1, k2]; if (this.curve.endo) return this.curve._endoWnafMulAdd(points, coeffs, true);else return this.curve._wnafMulAdd(1, points, coeffs, 2, true); }; - Point.prototype.eq = function eq(p) { return this === p || this.inf === p.inf && (this.inf || this.x.cmp(p.x) === 0 && this.y.cmp(p.y) === 0); }; - Point.prototype.neg = function neg(_precompute) { if (this.inf) return this; var res = this.curve.point(this.x, this.y.redNeg()); - if (_precompute && this.precomputed) { var pre = this.precomputed; - var negate = function (p) { return p.neg(); }; - res.precomputed = { naf: pre.naf && { wnd: pre.naf.wnd, @@ -59845,19 +95316,15 @@ function dew$R() { } }; } - return res; }; - Point.prototype.toJ = function toJ() { if (this.inf) return this.curve.jpoint(null, null, null); var res = this.curve.jpoint(this.x, this.y, this.curve.one); return res; }; - function JPoint(curve, x, y, z) { Base.BasePoint.call(this, curve, "jacobian"); - if (x === null && y === null && z === null) { this.x = this.curve.one; this.y = this.curve.one; @@ -59867,19 +95334,15 @@ function dew$R() { this.y = new BN(y, 16); this.z = new BN(z, 16); } - if (!this.x.red) this.x = this.x.toRed(this.curve.red); if (!this.y.red) this.y = this.y.toRed(this.curve.red); if (!this.z.red) this.z = this.z.toRed(this.curve.red); this.zOne = this.z === this.curve.one; } - inherits(JPoint, Base.BasePoint); - ShortCurve.prototype.jpoint = function jpoint(x, y, z) { return new JPoint(this, x, y, z); }; - JPoint.prototype.toP = function toP() { if (this.isInfinity()) return this.curve.point(null, null); var zinv = this.z.redInvm(); @@ -59888,17 +95351,17 @@ function dew$R() { var ay = this.y.redMul(zinv2).redMul(zinv); return this.curve.point(ax, ay); }; - JPoint.prototype.neg = function neg() { return this.curve.jpoint(this.x, this.y.redNeg(), this.z); }; - JPoint.prototype.add = function add(p) { // O + P = P - if (this.isInfinity()) return p; // P + O = P + if (this.isInfinity()) return p; - if (p.isInfinity()) return this; // 12M + 4S + 7A + // P + O = P + if (p.isInfinity()) return this; + // 12M + 4S + 7A var pz2 = p.z.redSqr(); var z2 = this.z.redSqr(); var u1 = this.x.redMul(pz2); @@ -59907,11 +95370,9 @@ function dew$R() { var s2 = p.y.redMul(z2.redMul(this.z)); var h = u1.redSub(u2); var r = s1.redSub(s2); - if (h.cmpn(0) === 0) { if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl(); } - var h2 = h.redSqr(); var h3 = h2.redMul(h); var v = u1.redMul(h2); @@ -59920,13 +95381,14 @@ function dew$R() { var nz = this.z.redMul(p.z).redMul(h); return this.curve.jpoint(nx, ny, nz); }; - JPoint.prototype.mixedAdd = function mixedAdd(p) { // O + P = P - if (this.isInfinity()) return p.toJ(); // P + O = P + if (this.isInfinity()) return p.toJ(); - if (p.isInfinity()) return this; // 8M + 3S + 7A + // P + O = P + if (p.isInfinity()) return this; + // 8M + 3S + 7A var z2 = this.z.redSqr(); var u1 = this.x; var u2 = p.x.redMul(z2); @@ -59934,11 +95396,9 @@ function dew$R() { var s2 = p.y.redMul(z2).redMul(this.z); var h = u1.redSub(u2); var r = s1.redSub(s2); - if (h.cmpn(0) === 0) { if (r.cmpn(0) !== 0) return this.curve.jpoint(null, null, null);else return this.dbl(); } - var h2 = h.redSqr(); var h3 = h2.redMul(h); var v = u1.redMul(h2); @@ -59947,32 +95407,28 @@ function dew$R() { var nz = this.z.redMul(h); return this.curve.jpoint(nx, ny, nz); }; - JPoint.prototype.dblp = function dblp(pow) { if (pow === 0) return this; if (this.isInfinity()) return this; if (!pow) return this.dbl(); var i; - if (this.curve.zeroA || this.curve.threeA) { var r = this; - for (i = 0; i < pow; i++) r = r.dbl(); - return r; - } // 1M + 2S + 1A + N * (4S + 5M + 8A) - // N = 1 => 6M + 6S + 9A - + } + // 1M + 2S + 1A + N * (4S + 5M + 8A) + // N = 1 => 6M + 6S + 9A var a = this.curve.a; var tinv = this.curve.tinv; var jx = this.x; var jy = this.y; var jz = this.z; - var jz4 = jz.redSqr().redSqr(); // Reuse results + var jz4 = jz.redSqr().redSqr(); + // Reuse results var jyd = jy.redAdd(jy); - for (i = 0; i < pow; i++) { var jx2 = jx.redSqr(); var jyd2 = jyd.redSqr(); @@ -59989,144 +95445,146 @@ function dew$R() { jz = nz; jyd = dny; } - return this.curve.jpoint(jx, jyd.redMul(tinv), jz); }; - JPoint.prototype.dbl = function dbl() { if (this.isInfinity()) return this; if (this.curve.zeroA) return this._zeroDbl();else if (this.curve.threeA) return this._threeDbl();else return this._dbl(); }; - JPoint.prototype._zeroDbl = function _zeroDbl() { var nx; var ny; - var nz; // Z = 1 - + var nz; + // Z = 1 if (this.zOne) { // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html // #doubling-mdbl-2007-bl // 1M + 5S + 14A - // XX = X1^2 - var xx = this.x.redSqr(); // YY = Y1^2 - - var yy = this.y.redSqr(); // YYYY = YY^2 - - var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY) + // XX = X1^2 + var xx = this.x.redSqr(); + // YY = Y1^2 + var yy = this.y.redSqr(); + // YYYY = YY^2 + var yyyy = yy.redSqr(); + // S = 2 * ((X1 + YY)^2 - XX - YYYY) var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); - s = s.redIAdd(s); // M = 3 * XX + a; a = 0 - - var m = xx.redAdd(xx).redIAdd(xx); // T = M ^ 2 - 2*S - - var t = m.redSqr().redISub(s).redISub(s); // 8 * YYYY + s = s.redIAdd(s); + // M = 3 * XX + a; a = 0 + var m = xx.redAdd(xx).redIAdd(xx); + // T = M ^ 2 - 2*S + var t = m.redSqr().redISub(s).redISub(s); + // 8 * YYYY var yyyy8 = yyyy.redIAdd(yyyy); yyyy8 = yyyy8.redIAdd(yyyy8); - yyyy8 = yyyy8.redIAdd(yyyy8); // X3 = T - - nx = t; // Y3 = M * (S - T) - 8 * YYYY - - ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2*Y1 + yyyy8 = yyyy8.redIAdd(yyyy8); + // X3 = T + nx = t; + // Y3 = M * (S - T) - 8 * YYYY + ny = m.redMul(s.redISub(t)).redISub(yyyy8); + // Z3 = 2*Y1 nz = this.y.redAdd(this.y); } else { // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html // #doubling-dbl-2009-l // 2M + 5S + 13A - // A = X1^2 - var a = this.x.redSqr(); // B = Y1^2 - - var b = this.y.redSqr(); // C = B^2 - - var c = b.redSqr(); // D = 2 * ((X1 + B)^2 - A - C) + // A = X1^2 + var a = this.x.redSqr(); + // B = Y1^2 + var b = this.y.redSqr(); + // C = B^2 + var c = b.redSqr(); + // D = 2 * ((X1 + B)^2 - A - C) var d = this.x.redAdd(b).redSqr().redISub(a).redISub(c); - d = d.redIAdd(d); // E = 3 * A - - var e = a.redAdd(a).redIAdd(a); // F = E^2 - - var f = e.redSqr(); // 8 * C + d = d.redIAdd(d); + // E = 3 * A + var e = a.redAdd(a).redIAdd(a); + // F = E^2 + var f = e.redSqr(); + // 8 * C var c8 = c.redIAdd(c); c8 = c8.redIAdd(c8); - c8 = c8.redIAdd(c8); // X3 = F - 2 * D - - nx = f.redISub(d).redISub(d); // Y3 = E * (D - X3) - 8 * C - - ny = e.redMul(d.redISub(nx)).redISub(c8); // Z3 = 2 * Y1 * Z1 + c8 = c8.redIAdd(c8); + // X3 = F - 2 * D + nx = f.redISub(d).redISub(d); + // Y3 = E * (D - X3) - 8 * C + ny = e.redMul(d.redISub(nx)).redISub(c8); + // Z3 = 2 * Y1 * Z1 nz = this.y.redMul(this.z); nz = nz.redIAdd(nz); } - return this.curve.jpoint(nx, ny, nz); }; - JPoint.prototype._threeDbl = function _threeDbl() { var nx; var ny; - var nz; // Z = 1 - + var nz; + // Z = 1 if (this.zOne) { // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html // #doubling-mdbl-2007-bl // 1M + 5S + 15A - // XX = X1^2 - var xx = this.x.redSqr(); // YY = Y1^2 - - var yy = this.y.redSqr(); // YYYY = YY^2 - - var yyyy = yy.redSqr(); // S = 2 * ((X1 + YY)^2 - XX - YYYY) + // XX = X1^2 + var xx = this.x.redSqr(); + // YY = Y1^2 + var yy = this.y.redSqr(); + // YYYY = YY^2 + var yyyy = yy.redSqr(); + // S = 2 * ((X1 + YY)^2 - XX - YYYY) var s = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); - s = s.redIAdd(s); // M = 3 * XX + a - - var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); // T = M^2 - 2 * S - - var t = m.redSqr().redISub(s).redISub(s); // X3 = T - - nx = t; // Y3 = M * (S - T) - 8 * YYYY - + s = s.redIAdd(s); + // M = 3 * XX + a + var m = xx.redAdd(xx).redIAdd(xx).redIAdd(this.curve.a); + // T = M^2 - 2 * S + var t = m.redSqr().redISub(s).redISub(s); + // X3 = T + nx = t; + // Y3 = M * (S - T) - 8 * YYYY var yyyy8 = yyyy.redIAdd(yyyy); yyyy8 = yyyy8.redIAdd(yyyy8); yyyy8 = yyyy8.redIAdd(yyyy8); - ny = m.redMul(s.redISub(t)).redISub(yyyy8); // Z3 = 2 * Y1 - + ny = m.redMul(s.redISub(t)).redISub(yyyy8); + // Z3 = 2 * Y1 nz = this.y.redAdd(this.y); } else { // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-3.html#doubling-dbl-2001-b // 3M + 5S - // delta = Z1^2 - var delta = this.z.redSqr(); // gamma = Y1^2 - - var gamma = this.y.redSqr(); // beta = X1 * gamma - - var beta = this.x.redMul(gamma); // alpha = 3 * (X1 - delta) * (X1 + delta) + // delta = Z1^2 + var delta = this.z.redSqr(); + // gamma = Y1^2 + var gamma = this.y.redSqr(); + // beta = X1 * gamma + var beta = this.x.redMul(gamma); + // alpha = 3 * (X1 - delta) * (X1 + delta) var alpha = this.x.redSub(delta).redMul(this.x.redAdd(delta)); - alpha = alpha.redAdd(alpha).redIAdd(alpha); // X3 = alpha^2 - 8 * beta - + alpha = alpha.redAdd(alpha).redIAdd(alpha); + // X3 = alpha^2 - 8 * beta var beta4 = beta.redIAdd(beta); beta4 = beta4.redIAdd(beta4); var beta8 = beta4.redAdd(beta4); - nx = alpha.redSqr().redISub(beta8); // Z3 = (Y1 + Z1)^2 - gamma - delta - - nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2 - + nx = alpha.redSqr().redISub(beta8); + // Z3 = (Y1 + Z1)^2 - gamma - delta + nz = this.y.redAdd(this.z).redSqr().redISub(gamma).redISub(delta); + // Y3 = alpha * (4 * beta - X3) - 8 * gamma^2 var ggamma8 = gamma.redSqr(); ggamma8 = ggamma8.redIAdd(ggamma8); ggamma8 = ggamma8.redIAdd(ggamma8); ggamma8 = ggamma8.redIAdd(ggamma8); ny = alpha.redMul(beta4.redISub(nx)).redISub(ggamma8); } - return this.curve.jpoint(nx, ny, nz); }; - JPoint.prototype._dbl = function _dbl() { - var a = this.curve.a; // 4M + 6S + 10A + var a = this.curve.a; + // 4M + 6S + 10A var jx = this.x; var jy = this.y; var jz = this.z; @@ -60147,79 +95605,78 @@ function dew$R() { var nz = jy.redAdd(jy).redMul(jz); return this.curve.jpoint(nx, ny, nz); }; - JPoint.prototype.trpl = function trpl() { - if (!this.curve.zeroA) return this.dbl().add(this); // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl - // 5M + 10S + ... - // XX = X1^2 - - var xx = this.x.redSqr(); // YY = Y1^2 - - var yy = this.y.redSqr(); // ZZ = Z1^2 - - var zz = this.z.redSqr(); // YYYY = YY^2 - - var yyyy = yy.redSqr(); // M = 3 * XX + a * ZZ2; a = 0 - - var m = xx.redAdd(xx).redIAdd(xx); // MM = M^2 + if (!this.curve.zeroA) return this.dbl().add(this); - var mm = m.redSqr(); // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM + // hyperelliptic.org/EFD/g1p/auto-shortw-jacobian-0.html#tripling-tpl-2007-bl + // 5M + 10S + ... + // XX = X1^2 + var xx = this.x.redSqr(); + // YY = Y1^2 + var yy = this.y.redSqr(); + // ZZ = Z1^2 + var zz = this.z.redSqr(); + // YYYY = YY^2 + var yyyy = yy.redSqr(); + // M = 3 * XX + a * ZZ2; a = 0 + var m = xx.redAdd(xx).redIAdd(xx); + // MM = M^2 + var mm = m.redSqr(); + // E = 6 * ((X1 + YY)^2 - XX - YYYY) - MM var e = this.x.redAdd(yy).redSqr().redISub(xx).redISub(yyyy); e = e.redIAdd(e); e = e.redAdd(e).redIAdd(e); - e = e.redISub(mm); // EE = E^2 - - var ee = e.redSqr(); // T = 16*YYYY - + e = e.redISub(mm); + // EE = E^2 + var ee = e.redSqr(); + // T = 16*YYYY var t = yyyy.redIAdd(yyyy); t = t.redIAdd(t); t = t.redIAdd(t); - t = t.redIAdd(t); // U = (M + E)^2 - MM - EE - T - - var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); // X3 = 4 * (X1 * EE - 4 * YY * U) - + t = t.redIAdd(t); + // U = (M + E)^2 - MM - EE - T + var u = m.redIAdd(e).redSqr().redISub(mm).redISub(ee).redISub(t); + // X3 = 4 * (X1 * EE - 4 * YY * U) var yyu4 = yy.redMul(u); yyu4 = yyu4.redIAdd(yyu4); yyu4 = yyu4.redIAdd(yyu4); var nx = this.x.redMul(ee).redISub(yyu4); nx = nx.redIAdd(nx); - nx = nx.redIAdd(nx); // Y3 = 8 * Y1 * (U * (T - U) - E * EE) - + nx = nx.redIAdd(nx); + // Y3 = 8 * Y1 * (U * (T - U) - E * EE) var ny = this.y.redMul(u.redMul(t.redISub(u)).redISub(e.redMul(ee))); ny = ny.redIAdd(ny); ny = ny.redIAdd(ny); - ny = ny.redIAdd(ny); // Z3 = (Z1 + E)^2 - ZZ - EE - + ny = ny.redIAdd(ny); + // Z3 = (Z1 + E)^2 - ZZ - EE var nz = this.z.redAdd(e).redSqr().redISub(zz).redISub(ee); return this.curve.jpoint(nx, ny, nz); }; - JPoint.prototype.mul = function mul(k, kbase) { k = new BN(k, kbase); return this.curve._wnafMul(this, k); }; - JPoint.prototype.eq = function eq(p) { if (p.type === "affine") return this.eq(p.toJ()); - if (this === p) return true; // x1 * z2^2 == x2 * z1^2 + if (this === p) return true; + // x1 * z2^2 == x2 * z1^2 var z2 = this.z.redSqr(); var pz2 = p.z.redSqr(); - if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false; // y1 * z2^3 == y2 * z1^3 + if (this.x.redMul(pz2).redISub(p.x.redMul(z2)).cmpn(0) !== 0) return false; + // y1 * z2^3 == y2 * z1^3 var z3 = z2.redMul(this.z); var pz3 = pz2.redMul(p.z); return this.y.redMul(pz3).redISub(p.y.redMul(z3)).cmpn(0) === 0; }; - JPoint.prototype.eqXToP = function eqXToP(x) { var zs = this.z.redSqr(); var rx = x.toRed(this.curve.red).redMul(zs); if (this.x.cmp(rx) === 0) return true; var xc = x.clone(); var t = this.curve.redN.redMul(zs); - for (;;) { xc.iadd(this.curve.n); if (xc.cmp(this.curve.p) >= 0) return false; @@ -60227,34 +95684,26 @@ function dew$R() { if (this.x.cmp(rx) === 0) return true; } }; - JPoint.prototype.inspect = function inspect() { if (this.isInfinity()) return ""; return ""; }; - JPoint.prototype.isInfinity = function isInfinity() { // XXX This code assumes that zero is always zero in red return this.z.cmpn(0) === 0; }; - - return exports$S; + return exports$X; } -var exports$R = {}, - _dewExec$Q = false; -function dew$Q() { - if (_dewExec$Q) return exports$R; - _dewExec$Q = true; - - var BN = dew$V(); - - var inherits = dew$2R(); - - var Base = dew$S(); - - var utils = dew$T(); - +var exports$W = {}, + _dewExec$V = false; +function dew$V() { + if (_dewExec$V) return exports$W; + _dewExec$V = true; + var BN = dew$_(); + var inherits = dew$3I(); + var Base = dew$X(); + var utils = dew$Y(); function MontCurve(conf) { Base.call(this, "mont", conf); this.a = new BN(conf.a, 16).toRed(this.red); @@ -60263,10 +95712,8 @@ function dew$Q() { this.two = new BN(2).toRed(this.red); this.a24 = this.i4.redMul(this.a.redAdd(this.two)); } - inherits(MontCurve, Base); - exports$R = MontCurve; - + exports$W = MontCurve; MontCurve.prototype.validate = function validate(point) { var x = point.normalize().x; var x2 = x.redSqr(); @@ -60274,10 +95721,8 @@ function dew$Q() { var y = rhs.redSqrt(); return y.redSqr().cmp(rhs) === 0; }; - function Point(curve, x, z) { Base.BasePoint.call(this, curve, "projective"); - if (x === null && z === null) { this.x = this.curve.one; this.z = this.curve.zero; @@ -60288,158 +95733,132 @@ function dew$Q() { if (!this.z.red) this.z = this.z.toRed(this.curve.red); } } - inherits(Point, Base.BasePoint); - MontCurve.prototype.decodePoint = function decodePoint(bytes, enc) { return this.point(utils.toArray(bytes, enc), 1); }; - MontCurve.prototype.point = function point(x, z) { return new Point(this, x, z); }; - MontCurve.prototype.pointFromJSON = function pointFromJSON(obj) { return Point.fromJSON(this, obj); }; - - Point.prototype.precompute = function precompute() {// No-op + Point.prototype.precompute = function precompute() { + // No-op }; - Point.prototype._encode = function _encode() { return this.getX().toArray("be", this.curve.p.byteLength()); }; - Point.fromJSON = function fromJSON(curve, obj) { return new Point(curve, obj[0], obj[1] || curve.one); }; + Point.prototype.inspect = function inspect() { + if (this.isInfinity()) return ""; + return ""; + }; + Point.prototype.isInfinity = function isInfinity() { + // XXX This code assumes that zero is always zero in red + return this.z.cmpn(0) === 0; + }; + Point.prototype.dbl = function dbl() { + // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3 + // 2M + 2S + 4A - Point.prototype.inspect = function inspect() { - if (this.isInfinity()) return ""; - return ""; - }; - - Point.prototype.isInfinity = function isInfinity() { - // XXX This code assumes that zero is always zero in red - return this.z.cmpn(0) === 0; - }; - - Point.prototype.dbl = function dbl() { - // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#doubling-dbl-1987-m-3 - // 2M + 2S + 4A - // A = X1 + Z1 - var a = this.x.redAdd(this.z); // AA = A^2 - - var aa = a.redSqr(); // B = X1 - Z1 - - var b = this.x.redSub(this.z); // BB = B^2 - - var bb = b.redSqr(); // C = AA - BB - - var c = aa.redSub(bb); // X3 = AA * BB - - var nx = aa.redMul(bb); // Z3 = C * (BB + A24 * C) - + // A = X1 + Z1 + var a = this.x.redAdd(this.z); + // AA = A^2 + var aa = a.redSqr(); + // B = X1 - Z1 + var b = this.x.redSub(this.z); + // BB = B^2 + var bb = b.redSqr(); + // C = AA - BB + var c = aa.redSub(bb); + // X3 = AA * BB + var nx = aa.redMul(bb); + // Z3 = C * (BB + A24 * C) var nz = c.redMul(bb.redAdd(this.curve.a24.redMul(c))); return this.curve.point(nx, nz); }; - Point.prototype.add = function add() { throw new Error("Not supported on Montgomery curve"); }; - Point.prototype.diffAdd = function diffAdd(p, diff) { // http://hyperelliptic.org/EFD/g1p/auto-montgom-xz.html#diffadd-dadd-1987-m-3 // 4M + 2S + 6A - // A = X2 + Z2 - var a = this.x.redAdd(this.z); // B = X2 - Z2 - - var b = this.x.redSub(this.z); // C = X3 + Z3 - - var c = p.x.redAdd(p.z); // D = X3 - Z3 - - var d = p.x.redSub(p.z); // DA = D * A - - var da = d.redMul(a); // CB = C * B - - var cb = c.redMul(b); // X5 = Z1 * (DA + CB)^2 - - var nx = diff.z.redMul(da.redAdd(cb).redSqr()); // Z5 = X1 * (DA - CB)^2 + // A = X2 + Z2 + var a = this.x.redAdd(this.z); + // B = X2 - Z2 + var b = this.x.redSub(this.z); + // C = X3 + Z3 + var c = p.x.redAdd(p.z); + // D = X3 - Z3 + var d = p.x.redSub(p.z); + // DA = D * A + var da = d.redMul(a); + // CB = C * B + var cb = c.redMul(b); + // X5 = Z1 * (DA + CB)^2 + var nx = diff.z.redMul(da.redAdd(cb).redSqr()); + // Z5 = X1 * (DA - CB)^2 var nz = diff.x.redMul(da.redISub(cb).redSqr()); return this.curve.point(nx, nz); }; - Point.prototype.mul = function mul(k) { var t = k.clone(); var a = this; // (N / 2) * Q + Q - var b = this.curve.point(null, null); // (N / 2) * Q - var c = this; // Q for (var bits = []; t.cmpn(0) !== 0; t.iushrn(1)) bits.push(t.andln(1)); - for (var i = bits.length - 1; i >= 0; i--) { if (bits[i] === 0) { // N * Q + Q = ((N / 2) * Q + Q)) + (N / 2) * Q - a = a.diffAdd(b, c); // N * Q = 2 * ((N / 2) * Q + Q)) - + a = a.diffAdd(b, c); + // N * Q = 2 * ((N / 2) * Q + Q)) b = b.dbl(); } else { // N * Q = ((N / 2) * Q + Q) + ((N / 2) * Q) - b = a.diffAdd(b, c); // N * Q + Q = 2 * ((N / 2) * Q + Q) - + b = a.diffAdd(b, c); + // N * Q + Q = 2 * ((N / 2) * Q + Q) a = a.dbl(); } } - return b; }; - Point.prototype.mulAdd = function mulAdd() { throw new Error("Not supported on Montgomery curve"); }; - Point.prototype.jumlAdd = function jumlAdd() { throw new Error("Not supported on Montgomery curve"); }; - Point.prototype.eq = function eq(other) { return this.getX().cmp(other.getX()) === 0; }; - Point.prototype.normalize = function normalize() { this.x = this.x.redMul(this.z.redInvm()); this.z = this.curve.one; return this; }; - Point.prototype.getX = function getX() { // Normalize coordinates this.normalize(); return this.x.fromRed(); }; - - return exports$R; + return exports$W; } -var exports$Q = {}, - _dewExec$P = false; -function dew$P() { - if (_dewExec$P) return exports$Q; - _dewExec$P = true; - - var utils = dew$T(); - - var BN = dew$V(); - - var inherits = dew$2R(); - - var Base = dew$S(); - +var exports$V = {}, + _dewExec$U = false; +function dew$U() { + if (_dewExec$U) return exports$V; + _dewExec$U = true; + var utils = dew$Y(); + var BN = dew$_(); + var inherits = dew$3I(); + var Base = dew$X(); var assert = utils.assert; - function EdwardsCurve(conf) { // NOTE: Important as we are creating point in Base.call() this.twisted = (conf.a | 0) !== 1; @@ -60455,23 +95874,19 @@ function dew$P() { assert(!this.twisted || this.c.fromRed().cmpn(1) === 0); this.oneC = (conf.c | 0) === 1; } - inherits(EdwardsCurve, Base); - exports$Q = EdwardsCurve; - + exports$V = EdwardsCurve; EdwardsCurve.prototype._mulA = function _mulA(num) { if (this.mOneA) return num.redNeg();else return this.a.redMul(num); }; - EdwardsCurve.prototype._mulC = function _mulC(num) { if (this.oneC) return num;else return this.c.redMul(num); - }; // Just for compatibility with Short curve - + }; + // Just for compatibility with Short curve EdwardsCurve.prototype.jpoint = function jpoint(x, y, z, t) { return this.point(x, y, z, t); }; - EdwardsCurve.prototype.pointFromX = function pointFromX(x, odd) { x = new BN(x, 16); if (!x.red) x = x.toRed(this.red); @@ -60485,29 +95900,27 @@ function dew$P() { if (odd && !isOdd || !odd && isOdd) y = y.redNeg(); return this.point(x, y); }; - EdwardsCurve.prototype.pointFromY = function pointFromY(y, odd) { y = new BN(y, 16); - if (!y.red) y = y.toRed(this.red); // x^2 = (y^2 - c^2) / (c^2 d y^2 - a) + if (!y.red) y = y.toRed(this.red); + // x^2 = (y^2 - c^2) / (c^2 d y^2 - a) var y2 = y.redSqr(); var lhs = y2.redSub(this.c2); var rhs = y2.redMul(this.d).redMul(this.c2).redSub(this.a); var x2 = lhs.redMul(rhs.redInvm()); - if (x2.cmp(this.zero) === 0) { if (odd) throw new Error("invalid point");else return this.point(this.zero, y); } - var x = x2.redSqrt(); if (x.redSqr().redSub(x2).cmp(this.zero) !== 0) throw new Error("invalid point"); if (x.fromRed().isOdd() !== odd) x = x.redNeg(); return this.point(x, y); }; - EdwardsCurve.prototype.validate = function validate(point) { - if (point.isInfinity()) return true; // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2) + if (point.isInfinity()) return true; + // Curve: A * X^2 + Y^2 = C^2 * (1 + D * X^2 * Y^2) point.normalize(); var x2 = point.x.redSqr(); var y2 = point.y.redSqr(); @@ -60515,10 +95928,8 @@ function dew$P() { var rhs = this.c2.redMul(this.one.redAdd(this.d.redMul(x2).redMul(y2))); return lhs.cmp(rhs) === 0; }; - function Point(curve, x, y, z, t) { Base.BasePoint.call(this, curve, "projective"); - if (x === null && y === null && z === null) { this.x = this.curve.zero; this.y = this.curve.one; @@ -60534,83 +95945,77 @@ function dew$P() { if (!this.y.red) this.y = this.y.toRed(this.curve.red); if (!this.z.red) this.z = this.z.toRed(this.curve.red); if (this.t && !this.t.red) this.t = this.t.toRed(this.curve.red); - this.zOne = this.z === this.curve.one; // Use extended coordinates + this.zOne = this.z === this.curve.one; + // Use extended coordinates if (this.curve.extended && !this.t) { this.t = this.x.redMul(this.y); if (!this.zOne) this.t = this.t.redMul(this.z.redInvm()); } } } - inherits(Point, Base.BasePoint); - EdwardsCurve.prototype.pointFromJSON = function pointFromJSON(obj) { return Point.fromJSON(this, obj); }; - EdwardsCurve.prototype.point = function point(x, y, z, t) { return new Point(this, x, y, z, t); }; - Point.fromJSON = function fromJSON(curve, obj) { return new Point(curve, obj[0], obj[1], obj[2]); }; - Point.prototype.inspect = function inspect() { if (this.isInfinity()) return ""; return ""; }; - Point.prototype.isInfinity = function isInfinity() { // XXX This code assumes that zero is always zero in red return this.x.cmpn(0) === 0 && (this.y.cmp(this.z) === 0 || this.zOne && this.y.cmp(this.curve.c) === 0); }; - Point.prototype._extDbl = function _extDbl() { // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html // #doubling-dbl-2008-hwcd // 4M + 4S - // A = X1^2 - var a = this.x.redSqr(); // B = Y1^2 - - var b = this.y.redSqr(); // C = 2 * Z1^2 + // A = X1^2 + var a = this.x.redSqr(); + // B = Y1^2 + var b = this.y.redSqr(); + // C = 2 * Z1^2 var c = this.z.redSqr(); - c = c.redIAdd(c); // D = a * A - - var d = this.curve._mulA(a); // E = (X1 + Y1)^2 - A - B - - - var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); // G = D + B - - var g = d.redAdd(b); // F = G - C - - var f = g.redSub(c); // H = D - B - - var h = d.redSub(b); // X3 = E * F - - var nx = e.redMul(f); // Y3 = G * H - - var ny = g.redMul(h); // T3 = E * H - - var nt = e.redMul(h); // Z3 = F * G - + c = c.redIAdd(c); + // D = a * A + var d = this.curve._mulA(a); + // E = (X1 + Y1)^2 - A - B + var e = this.x.redAdd(this.y).redSqr().redISub(a).redISub(b); + // G = D + B + var g = d.redAdd(b); + // F = G - C + var f = g.redSub(c); + // H = D - B + var h = d.redSub(b); + // X3 = E * F + var nx = e.redMul(f); + // Y3 = G * H + var ny = g.redMul(h); + // T3 = E * H + var nt = e.redMul(h); + // Z3 = F * G var nz = f.redMul(g); return this.curve.point(nx, ny, nz, nt); }; - Point.prototype._projDbl = function _projDbl() { // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html // #doubling-dbl-2008-bbjlp // #doubling-dbl-2007-bl // and others // Generally 3M + 4S or 2M + 4S - // B = (X1 + Y1)^2 - var b = this.x.redAdd(this.y).redSqr(); // C = X1^2 - - var c = this.x.redSqr(); // D = Y1^2 + // B = (X1 + Y1)^2 + var b = this.x.redAdd(this.y).redSqr(); + // C = X1^2 + var c = this.x.redSqr(); + // D = Y1^2 var d = this.y.redSqr(); var nx; var ny; @@ -60618,148 +96023,139 @@ function dew$P() { var e; var h; var j; - if (this.curve.twisted) { // E = a * C - e = this.curve._mulA(c); // F = E + D - + e = this.curve._mulA(c); + // F = E + D var f = e.redAdd(d); - if (this.zOne) { // X3 = (B - C - D) * (F - 2) - nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); // Y3 = F * (E - D) - - ny = f.redMul(e.redSub(d)); // Z3 = F^2 - 2 * F - + nx = b.redSub(c).redSub(d).redMul(f.redSub(this.curve.two)); + // Y3 = F * (E - D) + ny = f.redMul(e.redSub(d)); + // Z3 = F^2 - 2 * F nz = f.redSqr().redSub(f).redSub(f); } else { // H = Z1^2 - h = this.z.redSqr(); // J = F - 2 * H - - j = f.redSub(h).redISub(h); // X3 = (B-C-D)*J - - nx = b.redSub(c).redISub(d).redMul(j); // Y3 = F * (E - D) - - ny = f.redMul(e.redSub(d)); // Z3 = F * J - + h = this.z.redSqr(); + // J = F - 2 * H + j = f.redSub(h).redISub(h); + // X3 = (B-C-D)*J + nx = b.redSub(c).redISub(d).redMul(j); + // Y3 = F * (E - D) + ny = f.redMul(e.redSub(d)); + // Z3 = F * J nz = f.redMul(j); } } else { // E = C + D - e = c.redAdd(d); // H = (c * Z1)^2 - - h = this.curve._mulC(this.z).redSqr(); // J = E - 2 * H - - j = e.redSub(h).redSub(h); // X3 = c * (B - E) * J - - nx = this.curve._mulC(b.redISub(e)).redMul(j); // Y3 = c * E * (C - D) - - ny = this.curve._mulC(e).redMul(c.redISub(d)); // Z3 = E * J - + e = c.redAdd(d); + // H = (c * Z1)^2 + h = this.curve._mulC(this.z).redSqr(); + // J = E - 2 * H + j = e.redSub(h).redSub(h); + // X3 = c * (B - E) * J + nx = this.curve._mulC(b.redISub(e)).redMul(j); + // Y3 = c * E * (C - D) + ny = this.curve._mulC(e).redMul(c.redISub(d)); + // Z3 = E * J nz = e.redMul(j); } - return this.curve.point(nx, ny, nz); }; - Point.prototype.dbl = function dbl() { - if (this.isInfinity()) return this; // Double in extended coordinates + if (this.isInfinity()) return this; + // Double in extended coordinates if (this.curve.extended) return this._extDbl();else return this._projDbl(); }; - Point.prototype._extAdd = function _extAdd(p) { // hyperelliptic.org/EFD/g1p/auto-twisted-extended-1.html // #addition-add-2008-hwcd-3 // 8M - // A = (Y1 - X1) * (Y2 - X2) - var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); // B = (Y1 + X1) * (Y2 + X2) - - var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); // C = T1 * k * T2 - - var c = this.t.redMul(this.curve.dd).redMul(p.t); // D = Z1 * 2 * Z2 - - var d = this.z.redMul(p.z.redAdd(p.z)); // E = B - A - - var e = b.redSub(a); // F = D - C - - var f = d.redSub(c); // G = D + C - - var g = d.redAdd(c); // H = B + A - - var h = b.redAdd(a); // X3 = E * F - - var nx = e.redMul(f); // Y3 = G * H - - var ny = g.redMul(h); // T3 = E * H - - var nt = e.redMul(h); // Z3 = F * G + // A = (Y1 - X1) * (Y2 - X2) + var a = this.y.redSub(this.x).redMul(p.y.redSub(p.x)); + // B = (Y1 + X1) * (Y2 + X2) + var b = this.y.redAdd(this.x).redMul(p.y.redAdd(p.x)); + // C = T1 * k * T2 + var c = this.t.redMul(this.curve.dd).redMul(p.t); + // D = Z1 * 2 * Z2 + var d = this.z.redMul(p.z.redAdd(p.z)); + // E = B - A + var e = b.redSub(a); + // F = D - C + var f = d.redSub(c); + // G = D + C + var g = d.redAdd(c); + // H = B + A + var h = b.redAdd(a); + // X3 = E * F + var nx = e.redMul(f); + // Y3 = G * H + var ny = g.redMul(h); + // T3 = E * H + var nt = e.redMul(h); + // Z3 = F * G var nz = f.redMul(g); return this.curve.point(nx, ny, nz, nt); }; - Point.prototype._projAdd = function _projAdd(p) { // hyperelliptic.org/EFD/g1p/auto-twisted-projective.html // #addition-add-2008-bbjlp // #addition-add-2007-bl // 10M + 1S - // A = Z1 * Z2 - var a = this.z.redMul(p.z); // B = A^2 - - var b = a.redSqr(); // C = X1 * X2 - - var c = this.x.redMul(p.x); // D = Y1 * Y2 - - var d = this.y.redMul(p.y); // E = d * C * D - - var e = this.curve.d.redMul(c).redMul(d); // F = B - E - - var f = b.redSub(e); // G = B + E - - var g = b.redAdd(e); // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D) + // A = Z1 * Z2 + var a = this.z.redMul(p.z); + // B = A^2 + var b = a.redSqr(); + // C = X1 * X2 + var c = this.x.redMul(p.x); + // D = Y1 * Y2 + var d = this.y.redMul(p.y); + // E = d * C * D + var e = this.curve.d.redMul(c).redMul(d); + // F = B - E + var f = b.redSub(e); + // G = B + E + var g = b.redAdd(e); + // X3 = A * F * ((X1 + Y1) * (X2 + Y2) - C - D) var tmp = this.x.redAdd(this.y).redMul(p.x.redAdd(p.y)).redISub(c).redISub(d); var nx = a.redMul(f).redMul(tmp); var ny; var nz; - if (this.curve.twisted) { // Y3 = A * G * (D - a * C) - ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); // Z3 = F * G - + ny = a.redMul(g).redMul(d.redSub(this.curve._mulA(c))); + // Z3 = F * G nz = f.redMul(g); } else { // Y3 = A * G * (D - C) - ny = a.redMul(g).redMul(d.redSub(c)); // Z3 = c * F * G - + ny = a.redMul(g).redMul(d.redSub(c)); + // Z3 = c * F * G nz = this.curve._mulC(f).redMul(g); } - return this.curve.point(nx, ny, nz); }; - Point.prototype.add = function add(p) { if (this.isInfinity()) return p; if (p.isInfinity()) return this; if (this.curve.extended) return this._extAdd(p);else return this._projAdd(p); }; - Point.prototype.mul = function mul(k) { if (this._hasDoubles(k)) return this.curve._fixedNafMul(this, k);else return this.curve._wnafMul(this, k); }; - Point.prototype.mulAdd = function mulAdd(k1, p, k2) { return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, false); }; - Point.prototype.jmulAdd = function jmulAdd(k1, p, k2) { return this.curve._wnafMulAdd(1, [this, p], [k1, k2], 2, true); }; - Point.prototype.normalize = function normalize() { - if (this.zOne) return this; // Normalize coordinates + if (this.zOne) return this; + // Normalize coordinates var zi = this.z.redInvm(); this.x = this.x.redMul(zi); this.y = this.y.redMul(zi); @@ -60768,87 +96164,73 @@ function dew$P() { this.zOne = true; return this; }; - Point.prototype.neg = function neg() { return this.curve.point(this.x.redNeg(), this.y, this.z, this.t && this.t.redNeg()); }; - Point.prototype.getX = function getX() { this.normalize(); return this.x.fromRed(); }; - Point.prototype.getY = function getY() { this.normalize(); return this.y.fromRed(); }; - Point.prototype.eq = function eq(other) { return this === other || this.getX().cmp(other.getX()) === 0 && this.getY().cmp(other.getY()) === 0; }; - Point.prototype.eqXToP = function eqXToP(x) { var rx = x.toRed(this.curve.red).redMul(this.z); if (this.x.cmp(rx) === 0) return true; var xc = x.clone(); var t = this.curve.redN.redMul(this.z); - for (;;) { xc.iadd(this.curve.n); if (xc.cmp(this.curve.p) >= 0) return false; rx.redIAdd(t); if (this.x.cmp(rx) === 0) return true; } - }; // Compatibility with BaseCurve - + }; + // Compatibility with BaseCurve Point.prototype.toP = Point.prototype.normalize; Point.prototype.mixedAdd = Point.prototype.add; - return exports$Q; + return exports$V; } -var exports$P = {}, - _dewExec$O = false; -function dew$O() { - if (_dewExec$O) return exports$P; - _dewExec$O = true; - var curve = exports$P; - curve.base = dew$S(); - curve.short = dew$R(); - curve.mont = dew$Q(); - curve.edwards = dew$P(); - return exports$P; +var exports$U = {}, + _dewExec$T = false; +function dew$T() { + if (_dewExec$T) return exports$U; + _dewExec$T = true; + var curve = exports$U; + curve.base = dew$X(); + curve.short = dew$W(); + curve.mont = dew$V(); + curve.edwards = dew$U(); + return exports$U; } -var exports$O = {}, - _dewExec$N = false; -function dew$N() { - if (_dewExec$N) return exports$O; - _dewExec$N = true; - - var assert = dew$2m(); - - var inherits = dew$2R(); - - exports$O.inherits = inherits; - +var exports$T = {}, + _dewExec$S = false; +function dew$S() { + if (_dewExec$S) return exports$T; + _dewExec$S = true; + var assert = dew$3h(); + var inherits = dew$3I(); + exports$T.inherits = inherits; function isSurrogatePair(msg, i) { if ((msg.charCodeAt(i) & 64512) !== 55296) { return false; } - if (i < 0 || i + 1 >= msg.length) { return false; } - return (msg.charCodeAt(i + 1) & 64512) === 56320; } - function toArray(msg, enc) { if (Array.isArray(msg)) return msg.slice(); if (!msg) return []; var res = []; - if (typeof msg === "string") { if (!enc) { // Inspired by stringToUtf8ByteArray() in closure-library by Google @@ -60856,10 +96238,8 @@ function dew$N() { // Apache License 2.0 // https://github.com/google/closure-library/blob/master/LICENSE var p = 0; - for (var i = 0; i < msg.length; i++) { var c = msg.charCodeAt(i); - if (c < 128) { res[p++] = c; } else if (c < 2048) { @@ -60880,83 +96260,59 @@ function dew$N() { } else if (enc === "hex") { msg = msg.replace(/[^a-z0-9]+/ig, ""); if (msg.length % 2 !== 0) msg = "0" + msg; - for (i = 0; i < msg.length; i += 2) res.push(parseInt(msg[i] + msg[i + 1], 16)); } } else { for (i = 0; i < msg.length; i++) res[i] = msg[i] | 0; } - return res; } - - exports$O.toArray = toArray; - + exports$T.toArray = toArray; function toHex(msg) { var res = ""; - for (var i = 0; i < msg.length; i++) res += zero2(msg[i].toString(16)); - return res; } - - exports$O.toHex = toHex; - + exports$T.toHex = toHex; function htonl(w) { var res = w >>> 24 | w >>> 8 & 65280 | w << 8 & 16711680 | (w & 255) << 24; return res >>> 0; } - - exports$O.htonl = htonl; - + exports$T.htonl = htonl; function toHex32(msg, endian) { var res = ""; - for (var i = 0; i < msg.length; i++) { var w = msg[i]; if (endian === "little") w = htonl(w); res += zero8(w.toString(16)); } - return res; } - - exports$O.toHex32 = toHex32; - + exports$T.toHex32 = toHex32; function zero2(word) { if (word.length === 1) return "0" + word;else return word; } - - exports$O.zero2 = zero2; - + exports$T.zero2 = zero2; function zero8(word) { if (word.length === 7) return "0" + word;else if (word.length === 6) return "00" + word;else if (word.length === 5) return "000" + word;else if (word.length === 4) return "0000" + word;else if (word.length === 3) return "00000" + word;else if (word.length === 2) return "000000" + word;else if (word.length === 1) return "0000000" + word;else return word; } - - exports$O.zero8 = zero8; - + exports$T.zero8 = zero8; function join32(msg, start, end, endian) { var len = end - start; assert(len % 4 === 0); var res = new Array(len / 4); - for (var i = 0, k = start; i < res.length; i++, k += 4) { var w; if (endian === "big") w = msg[k] << 24 | msg[k + 1] << 16 | msg[k + 2] << 8 | msg[k + 3];else w = msg[k + 3] << 24 | msg[k + 2] << 16 | msg[k + 1] << 8 | msg[k]; res[i] = w >>> 0; } - return res; } - - exports$O.join32 = join32; - + exports$T.join32 = join32; function split32(msg, endian) { var res = new Array(msg.length * 4); - for (var i = 0, k = 0; i < msg.length; i++, k += 4) { var m = msg[i]; - if (endian === "big") { res[k] = m >>> 24; res[k + 1] = m >>> 16 & 255; @@ -60969,48 +96325,33 @@ function dew$N() { res[k] = m & 255; } } - return res; } - - exports$O.split32 = split32; - + exports$T.split32 = split32; function rotr32(w, b) { return w >>> b | w << 32 - b; } - - exports$O.rotr32 = rotr32; - + exports$T.rotr32 = rotr32; function rotl32(w, b) { return w << b | w >>> 32 - b; } - - exports$O.rotl32 = rotl32; - + exports$T.rotl32 = rotl32; function sum32(a, b) { return a + b >>> 0; } - - exports$O.sum32 = sum32; - + exports$T.sum32 = sum32; function sum32_3(a, b, c) { return a + b + c >>> 0; } - - exports$O.sum32_3 = sum32_3; - + exports$T.sum32_3 = sum32_3; function sum32_4(a, b, c, d) { return a + b + c + d >>> 0; } - - exports$O.sum32_4 = sum32_4; - + exports$T.sum32_4 = sum32_4; function sum32_5(a, b, c, d, e) { return a + b + c + d + e >>> 0; } - - exports$O.sum32_5 = sum32_5; - + exports$T.sum32_5 = sum32_5; function sum64(buf, pos, ah, al) { var bh = buf[pos]; var bl = buf[pos + 1]; @@ -61019,24 +96360,18 @@ function dew$N() { buf[pos] = hi >>> 0; buf[pos + 1] = lo; } - - exports$O.sum64 = sum64; - + exports$T.sum64 = sum64; function sum64_hi(ah, al, bh, bl) { var lo = al + bl >>> 0; var hi = (lo < al ? 1 : 0) + ah + bh; return hi >>> 0; } - - exports$O.sum64_hi = sum64_hi; - + exports$T.sum64_hi = sum64_hi; function sum64_lo(ah, al, bh, bl) { var lo = al + bl; return lo >>> 0; } - - exports$O.sum64_lo = sum64_lo; - + exports$T.sum64_lo = sum64_lo; function sum64_4_hi(ah, al, bh, bl, ch, cl, dh, dl) { var carry = 0; var lo = al; @@ -61049,16 +96384,12 @@ function dew$N() { var hi = ah + bh + ch + dh + carry; return hi >>> 0; } - - exports$O.sum64_4_hi = sum64_4_hi; - + exports$T.sum64_4_hi = sum64_4_hi; function sum64_4_lo(ah, al, bh, bl, ch, cl, dh, dl) { var lo = al + bl + cl + dl; return lo >>> 0; } - - exports$O.sum64_4_lo = sum64_4_lo; - + exports$T.sum64_4_lo = sum64_4_lo; function sum64_5_hi(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { var carry = 0; var lo = al; @@ -61073,55 +96404,41 @@ function dew$N() { var hi = ah + bh + ch + dh + eh + carry; return hi >>> 0; } - - exports$O.sum64_5_hi = sum64_5_hi; - + exports$T.sum64_5_hi = sum64_5_hi; function sum64_5_lo(ah, al, bh, bl, ch, cl, dh, dl, eh, el) { var lo = al + bl + cl + dl + el; return lo >>> 0; } - - exports$O.sum64_5_lo = sum64_5_lo; - + exports$T.sum64_5_lo = sum64_5_lo; function rotr64_hi(ah, al, num) { var r = al << 32 - num | ah >>> num; return r >>> 0; } - - exports$O.rotr64_hi = rotr64_hi; - + exports$T.rotr64_hi = rotr64_hi; function rotr64_lo(ah, al, num) { var r = ah << 32 - num | al >>> num; return r >>> 0; } - - exports$O.rotr64_lo = rotr64_lo; - + exports$T.rotr64_lo = rotr64_lo; function shr64_hi(ah, al, num) { return ah >>> num; } - - exports$O.shr64_hi = shr64_hi; - + exports$T.shr64_hi = shr64_hi; function shr64_lo(ah, al, num) { var r = ah << 32 - num | al >>> num; return r >>> 0; } - - exports$O.shr64_lo = shr64_lo; - return exports$O; + exports$T.shr64_lo = shr64_lo; + return exports$T; } -var exports$N = {}, - _dewExec$M = false; -function dew$M() { - if (_dewExec$M) return exports$N; - _dewExec$M = true; - - var utils = dew$N(); - - var assert = dew$2m(); - +var exports$S = {}, + _dewExec$R = false; +function dew$R() { + if (_dewExec$R) return exports$S; + _dewExec$R = true; + var utils = dew$S(); + var assert = dew$3h(); function BlockHash() { this.pending = null; this.pendingTotal = 0; @@ -61133,50 +96450,43 @@ function dew$M() { this._delta8 = this.blockSize / 8; this._delta32 = this.blockSize / 32; } - - exports$N.BlockHash = BlockHash; - + exports$S.BlockHash = BlockHash; BlockHash.prototype.update = function update(msg, enc) { // Convert message to array, pad it, and join into 32bit blocks msg = utils.toArray(msg, enc); if (!this.pending) this.pending = msg;else this.pending = this.pending.concat(msg); - this.pendingTotal += msg.length; // Enough data, try updating + this.pendingTotal += msg.length; + // Enough data, try updating if (this.pending.length >= this._delta8) { - msg = this.pending; // Process pending data in blocks + msg = this.pending; + // Process pending data in blocks var r = msg.length % this._delta8; this.pending = msg.slice(msg.length - r, msg.length); if (this.pending.length === 0) this.pending = null; msg = utils.join32(msg, 0, msg.length - r, this.endian); - for (var i = 0; i < msg.length; i += this._delta32) this._update(msg, i, i + this._delta32); } - return this; }; - BlockHash.prototype.digest = function digest(enc) { this.update(this._pad()); assert(this.pending === null); return this._digest(enc); }; - BlockHash.prototype._pad = function pad() { var len = this.pendingTotal; var bytes = this._delta8; var k = bytes - (len + this.padLength) % bytes; var res = new Array(k + this.padLength); res[0] = 128; + for (var i = 1; i < k; i++) res[i] = 0; - for (var i = 1; i < k; i++) res[i] = 0; // Append length - - + // Append length len <<= 3; - if (this.endian === "big") { for (var t = 8; t < this.padLength; t++) res[i++] = 0; - res[i++] = 0; res[i++] = 0; res[i++] = 0; @@ -61194,54 +96504,483 @@ function dew$M() { res[i++] = 0; res[i++] = 0; res[i++] = 0; - for (t = 8; t < this.padLength; t++) res[i++] = 0; } - return res; }; + return exports$S; +} + +var exports$R = {}, + _dewExec$Q = false; +function dew$Q() { + if (_dewExec$Q) return exports$R; + _dewExec$Q = true; + var utils = dew$S(); + var rotr32 = utils.rotr32; + function ft_1(s, x, y, z) { + if (s === 0) return ch32(x, y, z); + if (s === 1 || s === 3) return p32(x, y, z); + if (s === 2) return maj32(x, y, z); + } + exports$R.ft_1 = ft_1; + function ch32(x, y, z) { + return x & y ^ ~x & z; + } + exports$R.ch32 = ch32; + function maj32(x, y, z) { + return x & y ^ x & z ^ y & z; + } + exports$R.maj32 = maj32; + function p32(x, y, z) { + return x ^ y ^ z; + } + exports$R.p32 = p32; + function s0_256(x) { + return rotr32(x, 2) ^ rotr32(x, 13) ^ rotr32(x, 22); + } + exports$R.s0_256 = s0_256; + function s1_256(x) { + return rotr32(x, 6) ^ rotr32(x, 11) ^ rotr32(x, 25); + } + exports$R.s1_256 = s1_256; + function g0_256(x) { + return rotr32(x, 7) ^ rotr32(x, 18) ^ x >>> 3; + } + exports$R.g0_256 = g0_256; + function g1_256(x) { + return rotr32(x, 17) ^ rotr32(x, 19) ^ x >>> 10; + } + exports$R.g1_256 = g1_256; + return exports$R; +} + +var exports$Q = {}, + _dewExec$P = false; +function dew$P() { + if (_dewExec$P) return exports$Q; + _dewExec$P = true; + var utils = dew$S(); + var common = dew$R(); + var shaCommon = dew$Q(); + var rotl32 = utils.rotl32; + var sum32 = utils.sum32; + var sum32_5 = utils.sum32_5; + var ft_1 = shaCommon.ft_1; + var BlockHash = common.BlockHash; + var sha1_K = [1518500249, 1859775393, 2400959708, 3395469782]; + function SHA1() { + if (!(this instanceof SHA1)) return new SHA1(); + BlockHash.call(this); + this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]; + this.W = new Array(80); + } + utils.inherits(SHA1, BlockHash); + exports$Q = SHA1; + SHA1.blockSize = 512; + SHA1.outSize = 160; + SHA1.hmacStrength = 80; + SHA1.padLength = 64; + SHA1.prototype._update = function _update(msg, start) { + var W = this.W; + for (var i = 0; i < 16; i++) W[i] = msg[start + i]; + for (; i < W.length; i++) W[i] = rotl32(W[i - 3] ^ W[i - 8] ^ W[i - 14] ^ W[i - 16], 1); + var a = this.h[0]; + var b = this.h[1]; + var c = this.h[2]; + var d = this.h[3]; + var e = this.h[4]; + for (i = 0; i < W.length; i++) { + var s = ~~(i / 20); + var t = sum32_5(rotl32(a, 5), ft_1(s, b, c, d), e, W[i], sha1_K[s]); + e = d; + d = c; + c = rotl32(b, 30); + b = a; + a = t; + } + this.h[0] = sum32(this.h[0], a); + this.h[1] = sum32(this.h[1], b); + this.h[2] = sum32(this.h[2], c); + this.h[3] = sum32(this.h[3], d); + this.h[4] = sum32(this.h[4], e); + }; + SHA1.prototype._digest = function digest(enc) { + if (enc === "hex") return utils.toHex32(this.h, "big");else return utils.split32(this.h, "big"); + }; + return exports$Q; +} + +var exports$P = {}, + _dewExec$O = false; +function dew$O() { + if (_dewExec$O) return exports$P; + _dewExec$O = true; + var utils = dew$S(); + var common = dew$R(); + var shaCommon = dew$Q(); + var assert = dew$3h(); + var sum32 = utils.sum32; + var sum32_4 = utils.sum32_4; + var sum32_5 = utils.sum32_5; + var ch32 = shaCommon.ch32; + var maj32 = shaCommon.maj32; + var s0_256 = shaCommon.s0_256; + var s1_256 = shaCommon.s1_256; + var g0_256 = shaCommon.g0_256; + var g1_256 = shaCommon.g1_256; + var BlockHash = common.BlockHash; + var sha256_K = [1116352408, 1899447441, 3049323471, 3921009573, 961987163, 1508970993, 2453635748, 2870763221, 3624381080, 310598401, 607225278, 1426881987, 1925078388, 2162078206, 2614888103, 3248222580, 3835390401, 4022224774, 264347078, 604807628, 770255983, 1249150122, 1555081692, 1996064986, 2554220882, 2821834349, 2952996808, 3210313671, 3336571891, 3584528711, 113926993, 338241895, 666307205, 773529912, 1294757372, 1396182291, 1695183700, 1986661051, 2177026350, 2456956037, 2730485921, 2820302411, 3259730800, 3345764771, 3516065817, 3600352804, 4094571909, 275423344, 430227734, 506948616, 659060556, 883997877, 958139571, 1322822218, 1537002063, 1747873779, 1955562222, 2024104815, 2227730452, 2361852424, 2428436474, 2756734187, 3204031479, 3329325298]; + function SHA256() { + if (!(this instanceof SHA256)) return new SHA256(); + BlockHash.call(this); + this.h = [1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]; + this.k = sha256_K; + this.W = new Array(64); + } + utils.inherits(SHA256, BlockHash); + exports$P = SHA256; + SHA256.blockSize = 512; + SHA256.outSize = 256; + SHA256.hmacStrength = 192; + SHA256.padLength = 64; + SHA256.prototype._update = function _update(msg, start) { + var W = this.W; + for (var i = 0; i < 16; i++) W[i] = msg[start + i]; + for (; i < W.length; i++) W[i] = sum32_4(g1_256(W[i - 2]), W[i - 7], g0_256(W[i - 15]), W[i - 16]); + var a = this.h[0]; + var b = this.h[1]; + var c = this.h[2]; + var d = this.h[3]; + var e = this.h[4]; + var f = this.h[5]; + var g = this.h[6]; + var h = this.h[7]; + assert(this.k.length === W.length); + for (i = 0; i < W.length; i++) { + var T1 = sum32_5(h, s1_256(e), ch32(e, f, g), this.k[i], W[i]); + var T2 = sum32(s0_256(a), maj32(a, b, c)); + h = g; + g = f; + f = e; + e = sum32(d, T1); + d = c; + c = b; + b = a; + a = sum32(T1, T2); + } + this.h[0] = sum32(this.h[0], a); + this.h[1] = sum32(this.h[1], b); + this.h[2] = sum32(this.h[2], c); + this.h[3] = sum32(this.h[3], d); + this.h[4] = sum32(this.h[4], e); + this.h[5] = sum32(this.h[5], f); + this.h[6] = sum32(this.h[6], g); + this.h[7] = sum32(this.h[7], h); + }; + SHA256.prototype._digest = function digest(enc) { + if (enc === "hex") return utils.toHex32(this.h, "big");else return utils.split32(this.h, "big"); + }; + return exports$P; +} + +var exports$O = {}, + _dewExec$N = false; +function dew$N() { + if (_dewExec$N) return exports$O; + _dewExec$N = true; + var utils = dew$S(); + var SHA256 = dew$O(); + function SHA224() { + if (!(this instanceof SHA224)) return new SHA224(); + SHA256.call(this); + this.h = [3238371032, 914150663, 812702999, 4144912697, 4290775857, 1750603025, 1694076839, 3204075428]; + } + utils.inherits(SHA224, SHA256); + exports$O = SHA224; + SHA224.blockSize = 512; + SHA224.outSize = 224; + SHA224.hmacStrength = 192; + SHA224.padLength = 64; + SHA224.prototype._digest = function digest(enc) { + // Just truncate output + if (enc === "hex") return utils.toHex32(this.h.slice(0, 7), "big");else return utils.split32(this.h.slice(0, 7), "big"); + }; + return exports$O; +} + +var exports$N = {}, + _dewExec$M = false; +function dew$M() { + if (_dewExec$M) return exports$N; + _dewExec$M = true; + var utils = dew$S(); + var common = dew$R(); + var assert = dew$3h(); + var rotr64_hi = utils.rotr64_hi; + var rotr64_lo = utils.rotr64_lo; + var shr64_hi = utils.shr64_hi; + var shr64_lo = utils.shr64_lo; + var sum64 = utils.sum64; + var sum64_hi = utils.sum64_hi; + var sum64_lo = utils.sum64_lo; + var sum64_4_hi = utils.sum64_4_hi; + var sum64_4_lo = utils.sum64_4_lo; + var sum64_5_hi = utils.sum64_5_hi; + var sum64_5_lo = utils.sum64_5_lo; + var BlockHash = common.BlockHash; + var sha512_K = [1116352408, 3609767458, 1899447441, 602891725, 3049323471, 3964484399, 3921009573, 2173295548, 961987163, 4081628472, 1508970993, 3053834265, 2453635748, 2937671579, 2870763221, 3664609560, 3624381080, 2734883394, 310598401, 1164996542, 607225278, 1323610764, 1426881987, 3590304994, 1925078388, 4068182383, 2162078206, 991336113, 2614888103, 633803317, 3248222580, 3479774868, 3835390401, 2666613458, 4022224774, 944711139, 264347078, 2341262773, 604807628, 2007800933, 770255983, 1495990901, 1249150122, 1856431235, 1555081692, 3175218132, 1996064986, 2198950837, 2554220882, 3999719339, 2821834349, 766784016, 2952996808, 2566594879, 3210313671, 3203337956, 3336571891, 1034457026, 3584528711, 2466948901, 113926993, 3758326383, 338241895, 168717936, 666307205, 1188179964, 773529912, 1546045734, 1294757372, 1522805485, 1396182291, 2643833823, 1695183700, 2343527390, 1986661051, 1014477480, 2177026350, 1206759142, 2456956037, 344077627, 2730485921, 1290863460, 2820302411, 3158454273, 3259730800, 3505952657, 3345764771, 106217008, 3516065817, 3606008344, 3600352804, 1432725776, 4094571909, 1467031594, 275423344, 851169720, 430227734, 3100823752, 506948616, 1363258195, 659060556, 3750685593, 883997877, 3785050280, 958139571, 3318307427, 1322822218, 3812723403, 1537002063, 2003034995, 1747873779, 3602036899, 1955562222, 1575990012, 2024104815, 1125592928, 2227730452, 2716904306, 2361852424, 442776044, 2428436474, 593698344, 2756734187, 3733110249, 3204031479, 2999351573, 3329325298, 3815920427, 3391569614, 3928383900, 3515267271, 566280711, 3940187606, 3454069534, 4118630271, 4000239992, 116418474, 1914138554, 174292421, 2731055270, 289380356, 3203993006, 460393269, 320620315, 685471733, 587496836, 852142971, 1086792851, 1017036298, 365543100, 1126000580, 2618297676, 1288033470, 3409855158, 1501505948, 4234509866, 1607167915, 987167468, 1816402316, 1246189591]; + function SHA512() { + if (!(this instanceof SHA512)) return new SHA512(); + BlockHash.call(this); + this.h = [1779033703, 4089235720, 3144134277, 2227873595, 1013904242, 4271175723, 2773480762, 1595750129, 1359893119, 2917565137, 2600822924, 725511199, 528734635, 4215389547, 1541459225, 327033209]; + this.k = sha512_K; + this.W = new Array(160); + } + utils.inherits(SHA512, BlockHash); + exports$N = SHA512; + SHA512.blockSize = 1024; + SHA512.outSize = 512; + SHA512.hmacStrength = 192; + SHA512.padLength = 128; + SHA512.prototype._prepareBlock = function _prepareBlock(msg, start) { + var W = this.W; + + // 32 x 32bit words + for (var i = 0; i < 32; i++) W[i] = msg[start + i]; + for (; i < W.length; i += 2) { + var c0_hi = g1_512_hi(W[i - 4], W[i - 3]); // i - 2 + var c0_lo = g1_512_lo(W[i - 4], W[i - 3]); + var c1_hi = W[i - 14]; // i - 7 + var c1_lo = W[i - 13]; + var c2_hi = g0_512_hi(W[i - 30], W[i - 29]); // i - 15 + var c2_lo = g0_512_lo(W[i - 30], W[i - 29]); + var c3_hi = W[i - 32]; // i - 16 + var c3_lo = W[i - 31]; + W[i] = sum64_4_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo); + W[i + 1] = sum64_4_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo); + } + }; + SHA512.prototype._update = function _update(msg, start) { + this._prepareBlock(msg, start); + var W = this.W; + var ah = this.h[0]; + var al = this.h[1]; + var bh = this.h[2]; + var bl = this.h[3]; + var ch = this.h[4]; + var cl = this.h[5]; + var dh = this.h[6]; + var dl = this.h[7]; + var eh = this.h[8]; + var el = this.h[9]; + var fh = this.h[10]; + var fl = this.h[11]; + var gh = this.h[12]; + var gl = this.h[13]; + var hh = this.h[14]; + var hl = this.h[15]; + assert(this.k.length === W.length); + for (var i = 0; i < W.length; i += 2) { + var c0_hi = hh; + var c0_lo = hl; + var c1_hi = s1_512_hi(eh, el); + var c1_lo = s1_512_lo(eh, el); + var c2_hi = ch64_hi(eh, el, fh, fl, gh); + var c2_lo = ch64_lo(eh, el, fh, fl, gh, gl); + var c3_hi = this.k[i]; + var c3_lo = this.k[i + 1]; + var c4_hi = W[i]; + var c4_lo = W[i + 1]; + var T1_hi = sum64_5_hi(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo); + var T1_lo = sum64_5_lo(c0_hi, c0_lo, c1_hi, c1_lo, c2_hi, c2_lo, c3_hi, c3_lo, c4_hi, c4_lo); + c0_hi = s0_512_hi(ah, al); + c0_lo = s0_512_lo(ah, al); + c1_hi = maj64_hi(ah, al, bh, bl, ch); + c1_lo = maj64_lo(ah, al, bh, bl, ch, cl); + var T2_hi = sum64_hi(c0_hi, c0_lo, c1_hi, c1_lo); + var T2_lo = sum64_lo(c0_hi, c0_lo, c1_hi, c1_lo); + hh = gh; + hl = gl; + gh = fh; + gl = fl; + fh = eh; + fl = el; + eh = sum64_hi(dh, dl, T1_hi, T1_lo); + el = sum64_lo(dl, dl, T1_hi, T1_lo); + dh = ch; + dl = cl; + ch = bh; + cl = bl; + bh = ah; + bl = al; + ah = sum64_hi(T1_hi, T1_lo, T2_hi, T2_lo); + al = sum64_lo(T1_hi, T1_lo, T2_hi, T2_lo); + } + sum64(this.h, 0, ah, al); + sum64(this.h, 2, bh, bl); + sum64(this.h, 4, ch, cl); + sum64(this.h, 6, dh, dl); + sum64(this.h, 8, eh, el); + sum64(this.h, 10, fh, fl); + sum64(this.h, 12, gh, gl); + sum64(this.h, 14, hh, hl); + }; + SHA512.prototype._digest = function digest(enc) { + if (enc === "hex") return utils.toHex32(this.h, "big");else return utils.split32(this.h, "big"); + }; + function ch64_hi(xh, xl, yh, yl, zh) { + var r = xh & yh ^ ~xh & zh; + if (r < 0) r += 4294967296; + return r; + } + function ch64_lo(xh, xl, yh, yl, zh, zl) { + var r = xl & yl ^ ~xl & zl; + if (r < 0) r += 4294967296; + return r; + } + function maj64_hi(xh, xl, yh, yl, zh) { + var r = xh & yh ^ xh & zh ^ yh & zh; + if (r < 0) r += 4294967296; + return r; + } + function maj64_lo(xh, xl, yh, yl, zh, zl) { + var r = xl & yl ^ xl & zl ^ yl & zl; + if (r < 0) r += 4294967296; + return r; + } + function s0_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 28); + var c1_hi = rotr64_hi(xl, xh, 2); // 34 + var c2_hi = rotr64_hi(xl, xh, 7); // 39 + + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) r += 4294967296; + return r; + } + function s0_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 28); + var c1_lo = rotr64_lo(xl, xh, 2); // 34 + var c2_lo = rotr64_lo(xl, xh, 7); // 39 + + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) r += 4294967296; + return r; + } + function s1_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 14); + var c1_hi = rotr64_hi(xh, xl, 18); + var c2_hi = rotr64_hi(xl, xh, 9); // 41 + + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) r += 4294967296; + return r; + } + function s1_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 14); + var c1_lo = rotr64_lo(xh, xl, 18); + var c2_lo = rotr64_lo(xl, xh, 9); // 41 + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) r += 4294967296; + return r; + } + function g0_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 1); + var c1_hi = rotr64_hi(xh, xl, 8); + var c2_hi = shr64_hi(xh, xl, 7); + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) r += 4294967296; + return r; + } + function g0_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 1); + var c1_lo = rotr64_lo(xh, xl, 8); + var c2_lo = shr64_lo(xh, xl, 7); + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) r += 4294967296; + return r; + } + function g1_512_hi(xh, xl) { + var c0_hi = rotr64_hi(xh, xl, 19); + var c1_hi = rotr64_hi(xl, xh, 29); // 61 + var c2_hi = shr64_hi(xh, xl, 6); + var r = c0_hi ^ c1_hi ^ c2_hi; + if (r < 0) r += 4294967296; + return r; + } + function g1_512_lo(xh, xl) { + var c0_lo = rotr64_lo(xh, xl, 19); + var c1_lo = rotr64_lo(xl, xh, 29); // 61 + var c2_lo = shr64_lo(xh, xl, 6); + var r = c0_lo ^ c1_lo ^ c2_lo; + if (r < 0) r += 4294967296; + return r; + } return exports$N; } var exports$M = {}, - _dewExec$L = false; + _dewExec$L = false; function dew$L() { if (_dewExec$L) return exports$M; _dewExec$L = true; + var utils = dew$S(); + var SHA512 = dew$M(); + function SHA384() { + if (!(this instanceof SHA384)) return new SHA384(); + SHA512.call(this); + this.h = [3418070365, 3238371032, 1654270250, 914150663, 2438529370, 812702999, 355462360, 4144912697, 1731405415, 4290775857, 2394180231, 1750603025, 3675008525, 1694076839, 1203062813, 3204075428]; + } + utils.inherits(SHA384, SHA512); + exports$M = SHA384; + SHA384.blockSize = 1024; + SHA384.outSize = 384; + SHA384.hmacStrength = 192; + SHA384.padLength = 128; + SHA384.prototype._digest = function digest(enc) { + if (enc === "hex") return utils.toHex32(this.h.slice(0, 12), "big");else return utils.split32(this.h.slice(0, 12), "big"); + }; return exports$M; } var exports$L = {}, - _dewExec$K = false; + _dewExec$K = false; function dew$K() { if (_dewExec$K) return exports$L; _dewExec$K = true; + exports$L.sha1 = dew$P(); + exports$L.sha224 = dew$N(); + exports$L.sha256 = dew$O(); + exports$L.sha384 = dew$L(); + exports$L.sha512 = dew$M(); + return exports$L; +} - var utils = dew$N(); - - var common = dew$M(); - +var exports$K = {}, + _dewExec$J = false; +function dew$J() { + if (_dewExec$J) return exports$K; + _dewExec$J = true; + var utils = dew$S(); + var common = dew$R(); var rotl32 = utils.rotl32; var sum32 = utils.sum32; var sum32_3 = utils.sum32_3; var sum32_4 = utils.sum32_4; var BlockHash = common.BlockHash; - function RIPEMD160() { if (!(this instanceof RIPEMD160)) return new RIPEMD160(); BlockHash.call(this); this.h = [1732584193, 4023233417, 2562383102, 271733878, 3285377520]; this.endian = "little"; } - utils.inherits(RIPEMD160, BlockHash); - exports$L.ripemd160 = RIPEMD160; + exports$K.ripemd160 = RIPEMD160; RIPEMD160.blockSize = 512; RIPEMD160.outSize = 160; RIPEMD160.hmacStrength = 192; RIPEMD160.padLength = 64; - RIPEMD160.prototype._update = function update(msg, start) { var A = this.h[0]; var B = this.h[1]; @@ -61253,7 +96992,6 @@ function dew$K() { var Ch = C; var Dh = D; var Eh = E; - for (var j = 0; j < 80; j++) { var T = sum32(rotl32(sum32_4(A, f(j, B, C, D), msg[r[j] + start], K(j)), s[j]), E); A = E; @@ -61268,7 +97006,6 @@ function dew$K() { Ch = Bh; Bh = T; } - T = sum32_3(this.h[1], C, Dh); this.h[1] = sum32_3(this.h[2], D, Eh); this.h[2] = sum32_3(this.h[3], E, Ah); @@ -61276,40 +97013,32 @@ function dew$K() { this.h[4] = sum32_3(this.h[0], B, Ch); this.h[0] = T; }; - RIPEMD160.prototype._digest = function digest(enc) { if (enc === "hex") return utils.toHex32(this.h, "little");else return utils.split32(this.h, "little"); }; - function f(j, x, y, z) { if (j <= 15) return x ^ y ^ z;else if (j <= 31) return x & y | ~x & z;else if (j <= 47) return (x | ~y) ^ z;else if (j <= 63) return x & z | y & ~z;else return x ^ (y | ~z); } - function K(j) { if (j <= 15) return 0;else if (j <= 31) return 1518500249;else if (j <= 47) return 1859775393;else if (j <= 63) return 2400959708;else return 2840853838; } - function Kh(j) { if (j <= 15) return 1352829926;else if (j <= 31) return 1548603684;else if (j <= 47) return 1836072691;else if (j <= 63) return 2053994217;else return 0; } - var r = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 7, 4, 13, 1, 10, 6, 15, 3, 12, 0, 9, 5, 2, 14, 11, 8, 3, 10, 14, 4, 9, 15, 8, 1, 2, 7, 0, 6, 13, 11, 5, 12, 1, 9, 11, 10, 0, 8, 12, 4, 13, 3, 7, 15, 14, 5, 6, 2, 4, 0, 5, 9, 7, 12, 2, 10, 14, 1, 3, 8, 11, 6, 15, 13]; var rh = [5, 14, 7, 0, 9, 2, 11, 4, 13, 6, 15, 8, 1, 10, 3, 12, 6, 11, 3, 7, 0, 13, 5, 10, 14, 15, 8, 12, 4, 9, 1, 2, 15, 5, 1, 3, 7, 14, 6, 9, 11, 8, 12, 2, 10, 0, 4, 13, 8, 6, 4, 1, 3, 11, 15, 0, 5, 12, 2, 13, 9, 7, 10, 14, 12, 15, 10, 4, 1, 5, 8, 7, 6, 2, 13, 14, 0, 3, 9, 11]; var s = [11, 14, 15, 12, 5, 8, 7, 9, 11, 13, 14, 15, 6, 7, 9, 8, 7, 6, 8, 13, 11, 9, 7, 15, 7, 12, 15, 9, 11, 7, 13, 12, 11, 13, 6, 7, 14, 9, 13, 15, 14, 8, 13, 6, 5, 12, 7, 5, 11, 12, 14, 15, 14, 15, 9, 8, 9, 14, 5, 6, 8, 6, 5, 12, 9, 15, 5, 11, 6, 8, 13, 12, 5, 12, 13, 14, 11, 8, 5, 6]; var sh = [8, 9, 9, 11, 13, 15, 15, 5, 7, 7, 8, 11, 14, 14, 12, 6, 9, 13, 15, 7, 12, 8, 9, 11, 7, 7, 12, 7, 6, 15, 13, 11, 9, 7, 15, 11, 8, 6, 6, 14, 12, 13, 5, 14, 13, 13, 7, 5, 15, 5, 8, 11, 14, 14, 6, 14, 6, 9, 12, 9, 12, 5, 15, 8, 8, 5, 12, 9, 12, 5, 14, 6, 8, 13, 6, 5, 15, 13, 11, 11]; - return exports$L; + return exports$K; } -var exports$K = {}, - _dewExec$J = false; -function dew$J() { - if (_dewExec$J) return exports$K; - _dewExec$J = true; - - var utils = dew$N(); - - var assert = dew$2m(); - +var exports$J = {}, + _dewExec$I = false; +function dew$I() { + if (_dewExec$I) return exports$J; + _dewExec$I = true; + var utils = dew$S(); + var assert = dew$3h(); function Hmac(hash, key, enc) { if (!(this instanceof Hmac)) return new Hmac(hash, key, enc); this.Hash = hash; @@ -61317,68 +97046,62 @@ function dew$J() { this.outSize = hash.outSize / 8; this.inner = null; this.outer = null; - this._init(utils.toArray(key, enc)); } - - exports$K = Hmac; - + exports$J = Hmac; Hmac.prototype._init = function init(key) { // Shorten key, if needed if (key.length > this.blockSize) key = new this.Hash().update(key).digest(); - assert(key.length <= this.blockSize); // Add padding to key + assert(key.length <= this.blockSize); + // Add padding to key for (var i = key.length; i < this.blockSize; i++) key.push(0); - for (i = 0; i < key.length; i++) key[i] ^= 54; + this.inner = new this.Hash().update(key); - this.inner = new this.Hash().update(key); // 0x36 ^ 0x5c = 0x6a - + // 0x36 ^ 0x5c = 0x6a for (i = 0; i < key.length; i++) key[i] ^= 106; - this.outer = new this.Hash().update(key); }; - Hmac.prototype.update = function update(msg, enc) { this.inner.update(msg, enc); return this; }; - Hmac.prototype.digest = function digest(enc) { this.outer.update(this.inner.digest()); return this.outer.digest(enc); }; - - return exports$K; + return exports$J; } -var exports$J = {}, - _dewExec$I = false; -function dew$I() { - if (_dewExec$I) return exports$J; - _dewExec$I = true; - var hash = exports$J; - hash.utils = dew$N(); - hash.common = dew$M(); - hash.sha = dew$L(); - hash.ripemd = dew$K(); - hash.hmac = dew$J(); // Proxy hash functions to the main object - +var exports$I = {}, + _dewExec$H = false; +function dew$H() { + if (_dewExec$H) return exports$I; + _dewExec$H = true; + var hash = exports$I; + hash.utils = dew$S(); + hash.common = dew$R(); + hash.sha = dew$K(); + hash.ripemd = dew$J(); + hash.hmac = dew$I(); + + // Proxy hash functions to the main object hash.sha1 = hash.sha.sha1; hash.sha256 = hash.sha.sha256; hash.sha224 = hash.sha.sha224; hash.sha384 = hash.sha.sha384; hash.sha512 = hash.sha.sha512; hash.ripemd160 = hash.ripemd.ripemd160; - return exports$J; + return exports$I; } -var exports$I = {}, - _dewExec$H = false; -function dew$H() { - if (_dewExec$H) return exports$I; - _dewExec$H = true; - exports$I = { +var exports$H = {}, + _dewExec$G = false; +function dew$G() { + if (_dewExec$G) return exports$H; + _dewExec$G = true; + exports$H = { doubles: { step: 4, points: [["e60fce93b59e9ec53011aabc21c23e97b2a31369b87a5ae9c44ee89e2a6dec0a", "f7e3507399e595929db99f34f57937101296891e44d23f0be1f32cce69616821"], ["8282263212c609d9ea2a6e3e172de238d8c39cabd5ac1ca10646e23fd5f51508", "11f8a8098557dfe45e8256e830b60ace62d613ac2f7b17bed31b6eaff6e26caf"], ["175e159f728b865a72f99cc6c6fc846de0b93833fd2222ed73fce5b551e5b739", "d3506e0d9e3c79eba4ef97a51ff71f5eacb5955add24345c6efa6ffee9fed695"], ["363d90d447b00c9c99ceac05b6262ee053441c7e55552ffe526bad8f83ff4640", "4e273adfc732221953b445397f3363145b9a89008199ecb62003c7f3bee9de9"], ["8b4b5f165df3c2be8c6244b5b745638843e4a781a15bcd1b69f79a55dffdf80c", "4aad0a6f68d308b4b3fbd7813ab0da04f9e336546162ee56b3eff0c65fd4fd36"], ["723cbaa6e5db996d6bf771c00bd548c7b700dbffa6c0e77bcb6115925232fcda", "96e867b5595cc498a921137488824d6e2660a0653779494801dc069d9eb39f5f"], ["eebfa4d493bebf98ba5feec812c2d3b50947961237a919839a533eca0e7dd7fa", "5d9a8ca3970ef0f269ee7edaf178089d9ae4cdc3a711f712ddfd4fdae1de8999"], ["100f44da696e71672791d0a09b7bde459f1215a29b3c03bfefd7835b39a48db0", "cdd9e13192a00b772ec8f3300c090666b7ff4a18ff5195ac0fbd5cd62bc65a09"], ["e1031be262c7ed1b1dc9227a4a04c017a77f8d4464f3b3852c8acde6e534fd2d", "9d7061928940405e6bb6a4176597535af292dd419e1ced79a44f18f29456a00d"], ["feea6cae46d55b530ac2839f143bd7ec5cf8b266a41d6af52d5e688d9094696d", "e57c6b6c97dce1bab06e4e12bf3ecd5c981c8957cc41442d3155debf18090088"], ["da67a91d91049cdcb367be4be6ffca3cfeed657d808583de33fa978bc1ec6cb1", "9bacaa35481642bc41f463f7ec9780e5dec7adc508f740a17e9ea8e27a68be1d"], ["53904faa0b334cdda6e000935ef22151ec08d0f7bb11069f57545ccc1a37b7c0", "5bc087d0bc80106d88c9eccac20d3c1c13999981e14434699dcb096b022771c8"], ["8e7bcd0bd35983a7719cca7764ca906779b53a043a9b8bcaeff959f43ad86047", "10b7770b2a3da4b3940310420ca9514579e88e2e47fd68b3ea10047e8460372a"], ["385eed34c1cdff21e6d0818689b81bde71a7f4f18397e6690a841e1599c43862", "283bebc3e8ea23f56701de19e9ebf4576b304eec2086dc8cc0458fe5542e5453"], ["6f9d9b803ecf191637c73a4413dfa180fddf84a5947fbc9c606ed86c3fac3a7", "7c80c68e603059ba69b8e2a30e45c4d47ea4dd2f5c281002d86890603a842160"], ["3322d401243c4e2582a2147c104d6ecbf774d163db0f5e5313b7e0e742d0e6bd", "56e70797e9664ef5bfb019bc4ddaf9b72805f63ea2873af624f3a2e96c28b2a0"], ["85672c7d2de0b7da2bd1770d89665868741b3f9af7643397721d74d28134ab83", "7c481b9b5b43b2eb6374049bfa62c2e5e77f17fcc5298f44c8e3094f790313a6"], ["948bf809b1988a46b06c9f1919413b10f9226c60f668832ffd959af60c82a0a", "53a562856dcb6646dc6b74c5d1c3418c6d4dff08c97cd2bed4cb7f88d8c8e589"], ["6260ce7f461801c34f067ce0f02873a8f1b0e44dfc69752accecd819f38fd8e8", "bc2da82b6fa5b571a7f09049776a1ef7ecd292238051c198c1a84e95b2b4ae17"], ["e5037de0afc1d8d43d8348414bbf4103043ec8f575bfdc432953cc8d2037fa2d", "4571534baa94d3b5f9f98d09fb990bddbd5f5b03ec481f10e0e5dc841d755bda"], ["e06372b0f4a207adf5ea905e8f1771b4e7e8dbd1c6a6c5b725866a0ae4fce725", "7a908974bce18cfe12a27bb2ad5a488cd7484a7787104870b27034f94eee31dd"], ["213c7a715cd5d45358d0bbf9dc0ce02204b10bdde2a3f58540ad6908d0559754", "4b6dad0b5ae462507013ad06245ba190bb4850f5f36a7eeddff2c27534b458f2"], ["4e7c272a7af4b34e8dbb9352a5419a87e2838c70adc62cddf0cc3a3b08fbd53c", "17749c766c9d0b18e16fd09f6def681b530b9614bff7dd33e0b3941817dcaae6"], ["fea74e3dbe778b1b10f238ad61686aa5c76e3db2be43057632427e2840fb27b6", "6e0568db9b0b13297cf674deccb6af93126b596b973f7b77701d3db7f23cb96f"], ["76e64113f677cf0e10a2570d599968d31544e179b760432952c02a4417bdde39", "c90ddf8dee4e95cf577066d70681f0d35e2a33d2b56d2032b4b1752d1901ac01"], ["c738c56b03b2abe1e8281baa743f8f9a8f7cc643df26cbee3ab150242bcbb891", "893fb578951ad2537f718f2eacbfbbbb82314eef7880cfe917e735d9699a84c3"], ["d895626548b65b81e264c7637c972877d1d72e5f3a925014372e9f6588f6c14b", "febfaa38f2bc7eae728ec60818c340eb03428d632bb067e179363ed75d7d991f"], ["b8da94032a957518eb0f6433571e8761ceffc73693e84edd49150a564f676e03", "2804dfa44805a1e4d7c99cc9762808b092cc584d95ff3b511488e4e74efdf6e7"], ["e80fea14441fb33a7d8adab9475d7fab2019effb5156a792f1a11778e3c0df5d", "eed1de7f638e00771e89768ca3ca94472d155e80af322ea9fcb4291b6ac9ec78"], ["a301697bdfcd704313ba48e51d567543f2a182031efd6915ddc07bbcc4e16070", "7370f91cfb67e4f5081809fa25d40f9b1735dbf7c0a11a130c0d1a041e177ea1"], ["90ad85b389d6b936463f9d0512678de208cc330b11307fffab7ac63e3fb04ed4", "e507a3620a38261affdcbd9427222b839aefabe1582894d991d4d48cb6ef150"], ["8f68b9d2f63b5f339239c1ad981f162ee88c5678723ea3351b7b444c9ec4c0da", "662a9f2dba063986de1d90c2b6be215dbbea2cfe95510bfdf23cbf79501fff82"], ["e4f3fb0176af85d65ff99ff9198c36091f48e86503681e3e6686fd5053231e11", "1e63633ad0ef4f1c1661a6d0ea02b7286cc7e74ec951d1c9822c38576feb73bc"], ["8c00fa9b18ebf331eb961537a45a4266c7034f2f0d4e1d0716fb6eae20eae29e", "efa47267fea521a1a9dc343a3736c974c2fadafa81e36c54e7d2a4c66702414b"], ["e7a26ce69dd4829f3e10cec0a9e98ed3143d084f308b92c0997fddfc60cb3e41", "2a758e300fa7984b471b006a1aafbb18d0a6b2c0420e83e20e8a9421cf2cfd51"], ["b6459e0ee3662ec8d23540c223bcbdc571cbcb967d79424f3cf29eb3de6b80ef", "67c876d06f3e06de1dadf16e5661db3c4b3ae6d48e35b2ff30bf0b61a71ba45"], ["d68a80c8280bb840793234aa118f06231d6f1fc67e73c5a5deda0f5b496943e8", "db8ba9fff4b586d00c4b1f9177b0e28b5b0e7b8f7845295a294c84266b133120"], ["324aed7df65c804252dc0270907a30b09612aeb973449cea4095980fc28d3d5d", "648a365774b61f2ff130c0c35aec1f4f19213b0c7e332843967224af96ab7c84"], ["4df9c14919cde61f6d51dfdbe5fee5dceec4143ba8d1ca888e8bd373fd054c96", "35ec51092d8728050974c23a1d85d4b5d506cdc288490192ebac06cad10d5d"], ["9c3919a84a474870faed8a9c1cc66021523489054d7f0308cbfc99c8ac1f98cd", "ddb84f0f4a4ddd57584f044bf260e641905326f76c64c8e6be7e5e03d4fc599d"], ["6057170b1dd12fdf8de05f281d8e06bb91e1493a8b91d4cc5a21382120a959e5", "9a1af0b26a6a4807add9a2daf71df262465152bc3ee24c65e899be932385a2a8"], ["a576df8e23a08411421439a4518da31880cef0fba7d4df12b1a6973eecb94266", "40a6bf20e76640b2c92b97afe58cd82c432e10a7f514d9f3ee8be11ae1b28ec8"], ["7778a78c28dec3e30a05fe9629de8c38bb30d1f5cf9a3a208f763889be58ad71", "34626d9ab5a5b22ff7098e12f2ff580087b38411ff24ac563b513fc1fd9f43ac"], ["928955ee637a84463729fd30e7afd2ed5f96274e5ad7e5cb09eda9c06d903ac", "c25621003d3f42a827b78a13093a95eeac3d26efa8a8d83fc5180e935bcd091f"], ["85d0fef3ec6db109399064f3a0e3b2855645b4a907ad354527aae75163d82751", "1f03648413a38c0be29d496e582cf5663e8751e96877331582c237a24eb1f962"], ["ff2b0dce97eece97c1c9b6041798b85dfdfb6d8882da20308f5404824526087e", "493d13fef524ba188af4c4dc54d07936c7b7ed6fb90e2ceb2c951e01f0c29907"], ["827fbbe4b1e880ea9ed2b2e6301b212b57f1ee148cd6dd28780e5e2cf856e241", "c60f9c923c727b0b71bef2c67d1d12687ff7a63186903166d605b68baec293ec"], ["eaa649f21f51bdbae7be4ae34ce6e5217a58fdce7f47f9aa7f3b58fa2120e2b3", "be3279ed5bbbb03ac69a80f89879aa5a01a6b965f13f7e59d47a5305ba5ad93d"], ["e4a42d43c5cf169d9391df6decf42ee541b6d8f0c9a137401e23632dda34d24f", "4d9f92e716d1c73526fc99ccfb8ad34ce886eedfa8d8e4f13a7f7131deba9414"], ["1ec80fef360cbdd954160fadab352b6b92b53576a88fea4947173b9d4300bf19", "aeefe93756b5340d2f3a4958a7abbf5e0146e77f6295a07b671cdc1cc107cefd"], ["146a778c04670c2f91b00af4680dfa8bce3490717d58ba889ddb5928366642be", "b318e0ec3354028add669827f9d4b2870aaa971d2f7e5ed1d0b297483d83efd0"], ["fa50c0f61d22e5f07e3acebb1aa07b128d0012209a28b9776d76a8793180eef9", "6b84c6922397eba9b72cd2872281a68a5e683293a57a213b38cd8d7d3f4f2811"], ["da1d61d0ca721a11b1a5bf6b7d88e8421a288ab5d5bba5220e53d32b5f067ec2", "8157f55a7c99306c79c0766161c91e2966a73899d279b48a655fba0f1ad836f1"], ["a8e282ff0c9706907215ff98e8fd416615311de0446f1e062a73b0610d064e13", "7f97355b8db81c09abfb7f3c5b2515888b679a3e50dd6bd6cef7c73111f4cc0c"], ["174a53b9c9a285872d39e56e6913cab15d59b1fa512508c022f382de8319497c", "ccc9dc37abfc9c1657b4155f2c47f9e6646b3a1d8cb9854383da13ac079afa73"], ["959396981943785c3d3e57edf5018cdbe039e730e4918b3d884fdff09475b7ba", "2e7e552888c331dd8ba0386a4b9cd6849c653f64c8709385e9b8abf87524f2fd"], ["d2a63a50ae401e56d645a1153b109a8fcca0a43d561fba2dbb51340c9d82b151", "e82d86fb6443fcb7565aee58b2948220a70f750af484ca52d4142174dcf89405"], ["64587e2335471eb890ee7896d7cfdc866bacbdbd3839317b3436f9b45617e073", "d99fcdd5bf6902e2ae96dd6447c299a185b90a39133aeab358299e5e9faf6589"], ["8481bde0e4e4d885b3a546d3e549de042f0aa6cea250e7fd358d6c86dd45e458", "38ee7b8cba5404dd84a25bf39cecb2ca900a79c42b262e556d64b1b59779057e"], ["13464a57a78102aa62b6979ae817f4637ffcfed3c4b1ce30bcd6303f6caf666b", "69be159004614580ef7e433453ccb0ca48f300a81d0942e13f495a907f6ecc27"], ["bc4a9df5b713fe2e9aef430bcc1dc97a0cd9ccede2f28588cada3a0d2d83f366", "d3a81ca6e785c06383937adf4b798caa6e8a9fbfa547b16d758d666581f33c1"], ["8c28a97bf8298bc0d23d8c749452a32e694b65e30a9472a3954ab30fe5324caa", "40a30463a3305193378fedf31f7cc0eb7ae784f0451cb9459e71dc73cbef9482"], ["8ea9666139527a8c1dd94ce4f071fd23c8b350c5a4bb33748c4ba111faccae0", "620efabbc8ee2782e24e7c0cfb95c5d735b783be9cf0f8e955af34a30e62b945"], ["dd3625faef5ba06074669716bbd3788d89bdde815959968092f76cc4eb9a9787", "7a188fa3520e30d461da2501045731ca941461982883395937f68d00c644a573"], ["f710d79d9eb962297e4f6232b40e8f7feb2bc63814614d692c12de752408221e", "ea98e67232d3b3295d3b535532115ccac8612c721851617526ae47a9c77bfc82"]] @@ -61388,24 +97111,19 @@ function dew$H() { points: [["f9308a019258c31049344f85f89d5229b531c845836f99b08601f113bce036f9", "388f7b0f632de8140fe337e62a37f3566500a99934c2231b6cb9fd7584b8e672"], ["2f8bde4d1a07209355b4a7250a5c5128e88b84bddc619ab7cba8d569b240efe4", "d8ac222636e5e3d6d4dba9dda6c9c426f788271bab0d6840dca87d3aa6ac62d6"], ["5cbdf0646e5db4eaa398f365f2ea7a0e3d419b7e0330e39ce92bddedcac4f9bc", "6aebca40ba255960a3178d6d861a54dba813d0b813fde7b5a5082628087264da"], ["acd484e2f0c7f65309ad178a9f559abde09796974c57e714c35f110dfc27ccbe", "cc338921b0a7d9fd64380971763b61e9add888a4375f8e0f05cc262ac64f9c37"], ["774ae7f858a9411e5ef4246b70c65aac5649980be5c17891bbec17895da008cb", "d984a032eb6b5e190243dd56d7b7b365372db1e2dff9d6a8301d74c9c953c61b"], ["f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8", "ab0902e8d880a89758212eb65cdaf473a1a06da521fa91f29b5cb52db03ed81"], ["d7924d4f7d43ea965a465ae3095ff41131e5946f3c85f79e44adbcf8e27e080e", "581e2872a86c72a683842ec228cc6defea40af2bd896d3a5c504dc9ff6a26b58"], ["defdea4cdb677750a420fee807eacf21eb9898ae79b9768766e4faa04a2d4a34", "4211ab0694635168e997b0ead2a93daeced1f4a04a95c0f6cfb199f69e56eb77"], ["2b4ea0a797a443d293ef5cff444f4979f06acfebd7e86d277475656138385b6c", "85e89bc037945d93b343083b5a1c86131a01f60c50269763b570c854e5c09b7a"], ["352bbf4a4cdd12564f93fa332ce333301d9ad40271f8107181340aef25be59d5", "321eb4075348f534d59c18259dda3e1f4a1b3b2e71b1039c67bd3d8bcf81998c"], ["2fa2104d6b38d11b0230010559879124e42ab8dfeff5ff29dc9cdadd4ecacc3f", "2de1068295dd865b64569335bd5dd80181d70ecfc882648423ba76b532b7d67"], ["9248279b09b4d68dab21a9b066edda83263c3d84e09572e269ca0cd7f5453714", "73016f7bf234aade5d1aa71bdea2b1ff3fc0de2a887912ffe54a32ce97cb3402"], ["daed4f2be3a8bf278e70132fb0beb7522f570e144bf615c07e996d443dee8729", "a69dce4a7d6c98e8d4a1aca87ef8d7003f83c230f3afa726ab40e52290be1c55"], ["c44d12c7065d812e8acf28d7cbb19f9011ecd9e9fdf281b0e6a3b5e87d22e7db", "2119a460ce326cdc76c45926c982fdac0e106e861edf61c5a039063f0e0e6482"], ["6a245bf6dc698504c89a20cfded60853152b695336c28063b61c65cbd269e6b4", "e022cf42c2bd4a708b3f5126f16a24ad8b33ba48d0423b6efd5e6348100d8a82"], ["1697ffa6fd9de627c077e3d2fe541084ce13300b0bec1146f95ae57f0d0bd6a5", "b9c398f186806f5d27561506e4557433a2cf15009e498ae7adee9d63d01b2396"], ["605bdb019981718b986d0f07e834cb0d9deb8360ffb7f61df982345ef27a7479", "2972d2de4f8d20681a78d93ec96fe23c26bfae84fb14db43b01e1e9056b8c49"], ["62d14dab4150bf497402fdc45a215e10dcb01c354959b10cfe31c7e9d87ff33d", "80fc06bd8cc5b01098088a1950eed0db01aa132967ab472235f5642483b25eaf"], ["80c60ad0040f27dade5b4b06c408e56b2c50e9f56b9b8b425e555c2f86308b6f", "1c38303f1cc5c30f26e66bad7fe72f70a65eed4cbe7024eb1aa01f56430bd57a"], ["7a9375ad6167ad54aa74c6348cc54d344cc5dc9487d847049d5eabb0fa03c8fb", "d0e3fa9eca8726909559e0d79269046bdc59ea10c70ce2b02d499ec224dc7f7"], ["d528ecd9b696b54c907a9ed045447a79bb408ec39b68df504bb51f459bc3ffc9", "eecf41253136e5f99966f21881fd656ebc4345405c520dbc063465b521409933"], ["49370a4b5f43412ea25f514e8ecdad05266115e4a7ecb1387231808f8b45963", "758f3f41afd6ed428b3081b0512fd62a54c3f3afbb5b6764b653052a12949c9a"], ["77f230936ee88cbbd73df930d64702ef881d811e0e1498e2f1c13eb1fc345d74", "958ef42a7886b6400a08266e9ba1b37896c95330d97077cbbe8eb3c7671c60d6"], ["f2dac991cc4ce4b9ea44887e5c7c0bce58c80074ab9d4dbaeb28531b7739f530", "e0dedc9b3b2f8dad4da1f32dec2531df9eb5fbeb0598e4fd1a117dba703a3c37"], ["463b3d9f662621fb1b4be8fbbe2520125a216cdfc9dae3debcba4850c690d45b", "5ed430d78c296c3543114306dd8622d7c622e27c970a1de31cb377b01af7307e"], ["f16f804244e46e2a09232d4aff3b59976b98fac14328a2d1a32496b49998f247", "cedabd9b82203f7e13d206fcdf4e33d92a6c53c26e5cce26d6579962c4e31df6"], ["caf754272dc84563b0352b7a14311af55d245315ace27c65369e15f7151d41d1", "cb474660ef35f5f2a41b643fa5e460575f4fa9b7962232a5c32f908318a04476"], ["2600ca4b282cb986f85d0f1709979d8b44a09c07cb86d7c124497bc86f082120", "4119b88753c15bd6a693b03fcddbb45d5ac6be74ab5f0ef44b0be9475a7e4b40"], ["7635ca72d7e8432c338ec53cd12220bc01c48685e24f7dc8c602a7746998e435", "91b649609489d613d1d5e590f78e6d74ecfc061d57048bad9e76f302c5b9c61"], ["754e3239f325570cdbbf4a87deee8a66b7f2b33479d468fbc1a50743bf56cc18", "673fb86e5bda30fb3cd0ed304ea49a023ee33d0197a695d0c5d98093c536683"], ["e3e6bd1071a1e96aff57859c82d570f0330800661d1c952f9fe2694691d9b9e8", "59c9e0bba394e76f40c0aa58379a3cb6a5a2283993e90c4167002af4920e37f5"], ["186b483d056a033826ae73d88f732985c4ccb1f32ba35f4b4cc47fdcf04aa6eb", "3b952d32c67cf77e2e17446e204180ab21fb8090895138b4a4a797f86e80888b"], ["df9d70a6b9876ce544c98561f4be4f725442e6d2b737d9c91a8321724ce0963f", "55eb2dafd84d6ccd5f862b785dc39d4ab157222720ef9da217b8c45cf2ba2417"], ["5edd5cc23c51e87a497ca815d5dce0f8ab52554f849ed8995de64c5f34ce7143", "efae9c8dbc14130661e8cec030c89ad0c13c66c0d17a2905cdc706ab7399a868"], ["290798c2b6476830da12fe02287e9e777aa3fba1c355b17a722d362f84614fba", "e38da76dcd440621988d00bcf79af25d5b29c094db2a23146d003afd41943e7a"], ["af3c423a95d9f5b3054754efa150ac39cd29552fe360257362dfdecef4053b45", "f98a3fd831eb2b749a93b0e6f35cfb40c8cd5aa667a15581bc2feded498fd9c6"], ["766dbb24d134e745cccaa28c99bf274906bb66b26dcf98df8d2fed50d884249a", "744b1152eacbe5e38dcc887980da38b897584a65fa06cedd2c924f97cbac5996"], ["59dbf46f8c94759ba21277c33784f41645f7b44f6c596a58ce92e666191abe3e", "c534ad44175fbc300f4ea6ce648309a042ce739a7919798cd85e216c4a307f6e"], ["f13ada95103c4537305e691e74e9a4a8dd647e711a95e73cb62dc6018cfd87b8", "e13817b44ee14de663bf4bc808341f326949e21a6a75c2570778419bdaf5733d"], ["7754b4fa0e8aced06d4167a2c59cca4cda1869c06ebadfb6488550015a88522c", "30e93e864e669d82224b967c3020b8fa8d1e4e350b6cbcc537a48b57841163a2"], ["948dcadf5990e048aa3874d46abef9d701858f95de8041d2a6828c99e2262519", "e491a42537f6e597d5d28a3224b1bc25df9154efbd2ef1d2cbba2cae5347d57e"], ["7962414450c76c1689c7b48f8202ec37fb224cf5ac0bfa1570328a8a3d7c77ab", "100b610ec4ffb4760d5c1fc133ef6f6b12507a051f04ac5760afa5b29db83437"], ["3514087834964b54b15b160644d915485a16977225b8847bb0dd085137ec47ca", "ef0afbb2056205448e1652c48e8127fc6039e77c15c2378b7e7d15a0de293311"], ["d3cc30ad6b483e4bc79ce2c9dd8bc54993e947eb8df787b442943d3f7b527eaf", "8b378a22d827278d89c5e9be8f9508ae3c2ad46290358630afb34db04eede0a4"], ["1624d84780732860ce1c78fcbfefe08b2b29823db913f6493975ba0ff4847610", "68651cf9b6da903e0914448c6cd9d4ca896878f5282be4c8cc06e2a404078575"], ["733ce80da955a8a26902c95633e62a985192474b5af207da6df7b4fd5fc61cd4", "f5435a2bd2badf7d485a4d8b8db9fcce3e1ef8e0201e4578c54673bc1dc5ea1d"], ["15d9441254945064cf1a1c33bbd3b49f8966c5092171e699ef258dfab81c045c", "d56eb30b69463e7234f5137b73b84177434800bacebfc685fc37bbe9efe4070d"], ["a1d0fcf2ec9de675b612136e5ce70d271c21417c9d2b8aaaac138599d0717940", "edd77f50bcb5a3cab2e90737309667f2641462a54070f3d519212d39c197a629"], ["e22fbe15c0af8ccc5780c0735f84dbe9a790badee8245c06c7ca37331cb36980", "a855babad5cd60c88b430a69f53a1a7a38289154964799be43d06d77d31da06"], ["311091dd9860e8e20ee13473c1155f5f69635e394704eaa74009452246cfa9b3", "66db656f87d1f04fffd1f04788c06830871ec5a64feee685bd80f0b1286d8374"], ["34c1fd04d301be89b31c0442d3e6ac24883928b45a9340781867d4232ec2dbdf", "9414685e97b1b5954bd46f730174136d57f1ceeb487443dc5321857ba73abee"], ["f219ea5d6b54701c1c14de5b557eb42a8d13f3abbcd08affcc2a5e6b049b8d63", "4cb95957e83d40b0f73af4544cccf6b1f4b08d3c07b27fb8d8c2962a400766d1"], ["d7b8740f74a8fbaab1f683db8f45de26543a5490bca627087236912469a0b448", "fa77968128d9c92ee1010f337ad4717eff15db5ed3c049b3411e0315eaa4593b"], ["32d31c222f8f6f0ef86f7c98d3a3335ead5bcd32abdd94289fe4d3091aa824bf", "5f3032f5892156e39ccd3d7915b9e1da2e6dac9e6f26e961118d14b8462e1661"], ["7461f371914ab32671045a155d9831ea8793d77cd59592c4340f86cbc18347b5", "8ec0ba238b96bec0cbdddcae0aa442542eee1ff50c986ea6b39847b3cc092ff6"], ["ee079adb1df1860074356a25aa38206a6d716b2c3e67453d287698bad7b2b2d6", "8dc2412aafe3be5c4c5f37e0ecc5f9f6a446989af04c4e25ebaac479ec1c8c1e"], ["16ec93e447ec83f0467b18302ee620f7e65de331874c9dc72bfd8616ba9da6b5", "5e4631150e62fb40d0e8c2a7ca5804a39d58186a50e497139626778e25b0674d"], ["eaa5f980c245f6f038978290afa70b6bd8855897f98b6aa485b96065d537bd99", "f65f5d3e292c2e0819a528391c994624d784869d7e6ea67fb18041024edc07dc"], ["78c9407544ac132692ee1910a02439958ae04877151342ea96c4b6b35a49f51", "f3e0319169eb9b85d5404795539a5e68fa1fbd583c064d2462b675f194a3ddb4"], ["494f4be219a1a77016dcd838431aea0001cdc8ae7a6fc688726578d9702857a5", "42242a969283a5f339ba7f075e36ba2af925ce30d767ed6e55f4b031880d562c"], ["a598a8030da6d86c6bc7f2f5144ea549d28211ea58faa70ebf4c1e665c1fe9b5", "204b5d6f84822c307e4b4a7140737aec23fc63b65b35f86a10026dbd2d864e6b"], ["c41916365abb2b5d09192f5f2dbeafec208f020f12570a184dbadc3e58595997", "4f14351d0087efa49d245b328984989d5caf9450f34bfc0ed16e96b58fa9913"], ["841d6063a586fa475a724604da03bc5b92a2e0d2e0a36acfe4c73a5514742881", "73867f59c0659e81904f9a1c7543698e62562d6744c169ce7a36de01a8d6154"], ["5e95bb399a6971d376026947f89bde2f282b33810928be4ded112ac4d70e20d5", "39f23f366809085beebfc71181313775a99c9aed7d8ba38b161384c746012865"], ["36e4641a53948fd476c39f8a99fd974e5ec07564b5315d8bf99471bca0ef2f66", "d2424b1b1abe4eb8164227b085c9aa9456ea13493fd563e06fd51cf5694c78fc"], ["336581ea7bfbbb290c191a2f507a41cf5643842170e914faeab27c2c579f726", "ead12168595fe1be99252129b6e56b3391f7ab1410cd1e0ef3dcdcabd2fda224"], ["8ab89816dadfd6b6a1f2634fcf00ec8403781025ed6890c4849742706bd43ede", "6fdcef09f2f6d0a044e654aef624136f503d459c3e89845858a47a9129cdd24e"], ["1e33f1a746c9c5778133344d9299fcaa20b0938e8acff2544bb40284b8c5fb94", "60660257dd11b3aa9c8ed618d24edff2306d320f1d03010e33a7d2057f3b3b6"], ["85b7c1dcb3cec1b7ee7f30ded79dd20a0ed1f4cc18cbcfcfa410361fd8f08f31", "3d98a9cdd026dd43f39048f25a8847f4fcafad1895d7a633c6fed3c35e999511"], ["29df9fbd8d9e46509275f4b125d6d45d7fbe9a3b878a7af872a2800661ac5f51", "b4c4fe99c775a606e2d8862179139ffda61dc861c019e55cd2876eb2a27d84b"], ["a0b1cae06b0a847a3fea6e671aaf8adfdfe58ca2f768105c8082b2e449fce252", "ae434102edde0958ec4b19d917a6a28e6b72da1834aff0e650f049503a296cf2"], ["4e8ceafb9b3e9a136dc7ff67e840295b499dfb3b2133e4ba113f2e4c0e121e5", "cf2174118c8b6d7a4b48f6d534ce5c79422c086a63460502b827ce62a326683c"], ["d24a44e047e19b6f5afb81c7ca2f69080a5076689a010919f42725c2b789a33b", "6fb8d5591b466f8fc63db50f1c0f1c69013f996887b8244d2cdec417afea8fa3"], ["ea01606a7a6c9cdd249fdfcfacb99584001edd28abbab77b5104e98e8e3b35d4", "322af4908c7312b0cfbfe369f7a7b3cdb7d4494bc2823700cfd652188a3ea98d"], ["af8addbf2b661c8a6c6328655eb96651252007d8c5ea31be4ad196de8ce2131f", "6749e67c029b85f52a034eafd096836b2520818680e26ac8f3dfbcdb71749700"], ["e3ae1974566ca06cc516d47e0fb165a674a3dabcfca15e722f0e3450f45889", "2aeabe7e4531510116217f07bf4d07300de97e4874f81f533420a72eeb0bd6a4"], ["591ee355313d99721cf6993ffed1e3e301993ff3ed258802075ea8ced397e246", "b0ea558a113c30bea60fc4775460c7901ff0b053d25ca2bdeee98f1a4be5d196"], ["11396d55fda54c49f19aa97318d8da61fa8584e47b084945077cf03255b52984", "998c74a8cd45ac01289d5833a7beb4744ff536b01b257be4c5767bea93ea57a4"], ["3c5d2a1ba39c5a1790000738c9e0c40b8dcdfd5468754b6405540157e017aa7a", "b2284279995a34e2f9d4de7396fc18b80f9b8b9fdd270f6661f79ca4c81bd257"], ["cc8704b8a60a0defa3a99a7299f2e9c3fbc395afb04ac078425ef8a1793cc030", "bdd46039feed17881d1e0862db347f8cf395b74fc4bcdc4e940b74e3ac1f1b13"], ["c533e4f7ea8555aacd9777ac5cad29b97dd4defccc53ee7ea204119b2889b197", "6f0a256bc5efdf429a2fb6242f1a43a2d9b925bb4a4b3a26bb8e0f45eb596096"], ["c14f8f2ccb27d6f109f6d08d03cc96a69ba8c34eec07bbcf566d48e33da6593", "c359d6923bb398f7fd4473e16fe1c28475b740dd098075e6c0e8649113dc3a38"], ["a6cbc3046bc6a450bac24789fa17115a4c9739ed75f8f21ce441f72e0b90e6ef", "21ae7f4680e889bb130619e2c0f95a360ceb573c70603139862afd617fa9b9f"], ["347d6d9a02c48927ebfb86c1359b1caf130a3c0267d11ce6344b39f99d43cc38", "60ea7f61a353524d1c987f6ecec92f086d565ab687870cb12689ff1e31c74448"], ["da6545d2181db8d983f7dcb375ef5866d47c67b1bf31c8cf855ef7437b72656a", "49b96715ab6878a79e78f07ce5680c5d6673051b4935bd897fea824b77dc208a"], ["c40747cc9d012cb1a13b8148309c6de7ec25d6945d657146b9d5994b8feb1111", "5ca560753be2a12fc6de6caf2cb489565db936156b9514e1bb5e83037e0fa2d4"], ["4e42c8ec82c99798ccf3a610be870e78338c7f713348bd34c8203ef4037f3502", "7571d74ee5e0fb92a7a8b33a07783341a5492144cc54bcc40a94473693606437"], ["3775ab7089bc6af823aba2e1af70b236d251cadb0c86743287522a1b3b0dedea", "be52d107bcfa09d8bcb9736a828cfa7fac8db17bf7a76a2c42ad961409018cf7"], ["cee31cbf7e34ec379d94fb814d3d775ad954595d1314ba8846959e3e82f74e26", "8fd64a14c06b589c26b947ae2bcf6bfa0149ef0be14ed4d80f448a01c43b1c6d"], ["b4f9eaea09b6917619f6ea6a4eb5464efddb58fd45b1ebefcdc1a01d08b47986", "39e5c9925b5a54b07433a4f18c61726f8bb131c012ca542eb24a8ac07200682a"], ["d4263dfc3d2df923a0179a48966d30ce84e2515afc3dccc1b77907792ebcc60e", "62dfaf07a0f78feb30e30d6295853ce189e127760ad6cf7fae164e122a208d54"], ["48457524820fa65a4f8d35eb6930857c0032acc0a4a2de422233eeda897612c4", "25a748ab367979d98733c38a1fa1c2e7dc6cc07db2d60a9ae7a76aaa49bd0f77"], ["dfeeef1881101f2cb11644f3a2afdfc2045e19919152923f367a1767c11cceda", "ecfb7056cf1de042f9420bab396793c0c390bde74b4bbdff16a83ae09a9a7517"], ["6d7ef6b17543f8373c573f44e1f389835d89bcbc6062ced36c82df83b8fae859", "cd450ec335438986dfefa10c57fea9bcc521a0959b2d80bbf74b190dca712d10"], ["e75605d59102a5a2684500d3b991f2e3f3c88b93225547035af25af66e04541f", "f5c54754a8f71ee540b9b48728473e314f729ac5308b06938360990e2bfad125"], ["eb98660f4c4dfaa06a2be453d5020bc99a0c2e60abe388457dd43fefb1ed620c", "6cb9a8876d9cb8520609af3add26cd20a0a7cd8a9411131ce85f44100099223e"], ["13e87b027d8514d35939f2e6892b19922154596941888336dc3563e3b8dba942", "fef5a3c68059a6dec5d624114bf1e91aac2b9da568d6abeb2570d55646b8adf1"], ["ee163026e9fd6fe017c38f06a5be6fc125424b371ce2708e7bf4491691e5764a", "1acb250f255dd61c43d94ccc670d0f58f49ae3fa15b96623e5430da0ad6c62b2"], ["b268f5ef9ad51e4d78de3a750c2dc89b1e626d43505867999932e5db33af3d80", "5f310d4b3c99b9ebb19f77d41c1dee018cf0d34fd4191614003e945a1216e423"], ["ff07f3118a9df035e9fad85eb6c7bfe42b02f01ca99ceea3bf7ffdba93c4750d", "438136d603e858a3a5c440c38eccbaddc1d2942114e2eddd4740d098ced1f0d8"], ["8d8b9855c7c052a34146fd20ffb658bea4b9f69e0d825ebec16e8c3ce2b526a1", "cdb559eedc2d79f926baf44fb84ea4d44bcf50fee51d7ceb30e2e7f463036758"], ["52db0b5384dfbf05bfa9d472d7ae26dfe4b851ceca91b1eba54263180da32b63", "c3b997d050ee5d423ebaf66a6db9f57b3180c902875679de924b69d84a7b375"], ["e62f9490d3d51da6395efd24e80919cc7d0f29c3f3fa48c6fff543becbd43352", "6d89ad7ba4876b0b22c2ca280c682862f342c8591f1daf5170e07bfd9ccafa7d"], ["7f30ea2476b399b4957509c88f77d0191afa2ff5cb7b14fd6d8e7d65aaab1193", "ca5ef7d4b231c94c3b15389a5f6311e9daff7bb67b103e9880ef4bff637acaec"], ["5098ff1e1d9f14fb46a210fada6c903fef0fb7b4a1dd1d9ac60a0361800b7a00", "9731141d81fc8f8084d37c6e7542006b3ee1b40d60dfe5362a5b132fd17ddc0"], ["32b78c7de9ee512a72895be6b9cbefa6e2f3c4ccce445c96b9f2c81e2778ad58", "ee1849f513df71e32efc3896ee28260c73bb80547ae2275ba497237794c8753c"], ["e2cb74fddc8e9fbcd076eef2a7c72b0ce37d50f08269dfc074b581550547a4f7", "d3aa2ed71c9dd2247a62df062736eb0baddea9e36122d2be8641abcb005cc4a4"], ["8438447566d4d7bedadc299496ab357426009a35f235cb141be0d99cd10ae3a8", "c4e1020916980a4da5d01ac5e6ad330734ef0d7906631c4f2390426b2edd791f"], ["4162d488b89402039b584c6fc6c308870587d9c46f660b878ab65c82c711d67e", "67163e903236289f776f22c25fb8a3afc1732f2b84b4e95dbda47ae5a0852649"], ["3fad3fa84caf0f34f0f89bfd2dcf54fc175d767aec3e50684f3ba4a4bf5f683d", "cd1bc7cb6cc407bb2f0ca647c718a730cf71872e7d0d2a53fa20efcdfe61826"], ["674f2600a3007a00568c1a7ce05d0816c1fb84bf1370798f1c69532faeb1a86b", "299d21f9413f33b3edf43b257004580b70db57da0b182259e09eecc69e0d38a5"], ["d32f4da54ade74abb81b815ad1fb3b263d82d6c692714bcff87d29bd5ee9f08f", "f9429e738b8e53b968e99016c059707782e14f4535359d582fc416910b3eea87"], ["30e4e670435385556e593657135845d36fbb6931f72b08cb1ed954f1e3ce3ff6", "462f9bce619898638499350113bbc9b10a878d35da70740dc695a559eb88db7b"], ["be2062003c51cc3004682904330e4dee7f3dcd10b01e580bf1971b04d4cad297", "62188bc49d61e5428573d48a74e1c655b1c61090905682a0d5558ed72dccb9bc"], ["93144423ace3451ed29e0fb9ac2af211cb6e84a601df5993c419859fff5df04a", "7c10dfb164c3425f5c71a3f9d7992038f1065224f72bb9d1d902a6d13037b47c"], ["b015f8044f5fcbdcf21ca26d6c34fb8197829205c7b7d2a7cb66418c157b112c", "ab8c1e086d04e813744a655b2df8d5f83b3cdc6faa3088c1d3aea1454e3a1d5f"], ["d5e9e1da649d97d89e4868117a465a3a4f8a18de57a140d36b3f2af341a21b52", "4cb04437f391ed73111a13cc1d4dd0db1693465c2240480d8955e8592f27447a"], ["d3ae41047dd7ca065dbf8ed77b992439983005cd72e16d6f996a5316d36966bb", "bd1aeb21ad22ebb22a10f0303417c6d964f8cdd7df0aca614b10dc14d125ac46"], ["463e2763d885f958fc66cdd22800f0a487197d0a82e377b49f80af87c897b065", "bfefacdb0e5d0fd7df3a311a94de062b26b80c61fbc97508b79992671ef7ca7f"], ["7985fdfd127c0567c6f53ec1bb63ec3158e597c40bfe747c83cddfc910641917", "603c12daf3d9862ef2b25fe1de289aed24ed291e0ec6708703a5bd567f32ed03"], ["74a1ad6b5f76e39db2dd249410eac7f99e74c59cb83d2d0ed5ff1543da7703e9", "cc6157ef18c9c63cd6193d83631bbea0093e0968942e8c33d5737fd790e0db08"], ["30682a50703375f602d416664ba19b7fc9bab42c72747463a71d0896b22f6da3", "553e04f6b018b4fa6c8f39e7f311d3176290d0e0f19ca73f17714d9977a22ff8"], ["9e2158f0d7c0d5f26c3791efefa79597654e7a2b2464f52b1ee6c1347769ef57", "712fcdd1b9053f09003a3481fa7762e9ffd7c8ef35a38509e2fbf2629008373"], ["176e26989a43c9cfeba4029c202538c28172e566e3c4fce7322857f3be327d66", "ed8cc9d04b29eb877d270b4878dc43c19aefd31f4eee09ee7b47834c1fa4b1c3"], ["75d46efea3771e6e68abb89a13ad747ecf1892393dfc4f1b7004788c50374da8", "9852390a99507679fd0b86fd2b39a868d7efc22151346e1a3ca4726586a6bed8"], ["809a20c67d64900ffb698c4c825f6d5f2310fb0451c869345b7319f645605721", "9e994980d9917e22b76b061927fa04143d096ccc54963e6a5ebfa5f3f8e286c1"], ["1b38903a43f7f114ed4500b4eac7083fdefece1cf29c63528d563446f972c180", "4036edc931a60ae889353f77fd53de4a2708b26b6f5da72ad3394119daf408f9"]] } }; - return exports$I; + return exports$H; } -var exports$H = {}, - _dewExec$G = false; -function dew$G() { - if (_dewExec$G) return exports$H; - _dewExec$G = true; - var curves = exports$H; - - var hash = dew$I(); - - var curve = dew$O(); - - var utils = dew$T(); - +var exports$G = {}, + _dewExec$F = false; +function dew$F() { + if (_dewExec$F) return exports$G; + _dewExec$F = true; + var curves = exports$G; + var hash = dew$H(); + var curve = dew$T(); + var utils = dew$Y(); var assert = utils.assert; - function PresetCurve(options) { if (options.type === "short") this.curve = new curve.short(options);else if (options.type === "edwards") this.curve = new curve.edwards(options);else this.curve = new curve.mont(options); this.g = this.curve.g; @@ -61414,9 +97132,7 @@ function dew$G() { assert(this.g.validate(), "Invalid curve"); assert(this.g.mul(this.n).isInfinity(), "Invalid curve, G*N != O"); } - curves.PresetCurve = PresetCurve; - function defineCurve(name, options) { Object.defineProperty(curves, name, { configurable: true, @@ -61432,7 +97148,6 @@ function dew$G() { } }); } - defineCurve("p192", { type: "short", prime: "p192", @@ -61510,17 +97225,16 @@ function dew$G() { n: "1000000000000000 0000000000000000 14def9dea2f79cd6 5812631a5cf5d3ed", hash: hash.sha256, gRed: false, - g: ["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a", // 4/5 + g: ["216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a", + // 4/5 "6666666666666666666666666666666666666666666666666666666666666658"] }); var pre; - try { - pre = dew$H(); + pre = dew$G(); } catch (e) { pre = undefined; } - defineCurve("secp256k1", { type: "short", prime: "k256", @@ -61543,21 +97257,17 @@ function dew$G() { gRed: false, g: ["79be667ef9dcbbac55a06295ce870b07029bfcdb2dce28d959f2815b16f81798", "483ada7726a3c4655da4fbfc0e1108a8fd17b448a68554199c47d08ffb10d4b8", pre] }); - return exports$H; + return exports$G; } -var exports$G = {}, - _dewExec$F = false; -function dew$F() { - if (_dewExec$F) return exports$G; - _dewExec$F = true; - - var hash = dew$I(); - - var utils = dew$U(); - - var assert = dew$2m(); - +var exports$F = {}, + _dewExec$E = false; +function dew$E() { + if (_dewExec$E) return exports$F; + _dewExec$E = true; + var hash = dew$H(); + var utils = dew$Z(); + var assert = dew$3h(); function HmacDRBG(options) { if (!(this instanceof HmacDRBG)) return new HmacDRBG(options); this.hash = options.hash; @@ -61572,35 +97282,26 @@ function dew$F() { var nonce = utils.toArray(options.nonce, options.nonceEnc || "hex"); var pers = utils.toArray(options.pers, options.persEnc || "hex"); assert(entropy.length >= this.minEntropy / 8, "Not enough entropy. Minimum is: " + this.minEntropy + " bits"); - this._init(entropy, nonce, pers); } - - exports$G = HmacDRBG; - + exports$F = HmacDRBG; HmacDRBG.prototype._init = function init(entropy, nonce, pers) { var seed = entropy.concat(nonce).concat(pers); this.K = new Array(this.outLen / 8); this.V = new Array(this.outLen / 8); - for (var i = 0; i < this.V.length; i++) { this.K[i] = 0; this.V[i] = 1; } - this._update(seed); - this._reseed = 1; this.reseedInterval = 281474976710656; // 2^48 }; - HmacDRBG.prototype._hmac = function hmac() { return new hash.hmac(this.hash, this.K); }; - HmacDRBG.prototype._update = function update(seed) { var kmac = this._hmac().update(this.V).update([0]); - if (seed) kmac = kmac.update(seed); this.K = kmac.digest(); this.V = this._hmac().update(this.V).digest(); @@ -61608,7 +97309,6 @@ function dew$F() { this.K = this._hmac().update(this.V).update([1]).update(seed).digest(); this.V = this._hmac().update(this.V).digest(); }; - HmacDRBG.prototype.reseed = function reseed(entropy, entropyEnc, add, addEnc) { // Optional entropy enc if (typeof entropyEnc !== "string") { @@ -61616,73 +97316,58 @@ function dew$F() { add = entropyEnc; entropyEnc = null; } - entropy = utils.toArray(entropy, entropyEnc); add = utils.toArray(add, addEnc); assert(entropy.length >= this.minEntropy / 8, "Not enough entropy. Minimum is: " + this.minEntropy + " bits"); - this._update(entropy.concat(add || [])); - this._reseed = 1; }; - HmacDRBG.prototype.generate = function generate(len, enc, add, addEnc) { - if (this._reseed > this.reseedInterval) throw new Error("Reseed is required"); // Optional encoding + if (this._reseed > this.reseedInterval) throw new Error("Reseed is required"); + // Optional encoding if (typeof enc !== "string") { addEnc = add; add = enc; enc = null; - } // Optional additional data - + } + // Optional additional data if (add) { add = utils.toArray(add, addEnc || "hex"); - this._update(add); } - var temp = []; - while (temp.length < len) { this.V = this._hmac().update(this.V).digest(); temp = temp.concat(this.V); } - var res = temp.slice(0, len); - this._update(add); - this._reseed++; return utils.encode(res, enc); }; - - return exports$G; + return exports$F; } -var exports$F = {}, - _dewExec$E = false; -function dew$E() { - if (_dewExec$E) return exports$F; - _dewExec$E = true; - - var BN = dew$V(); - - var utils = dew$T(); - +var exports$E = {}, + _dewExec$D = false; +function dew$D() { + if (_dewExec$D) return exports$E; + _dewExec$D = true; + var BN = dew$_(); + var utils = dew$Y(); var assert = utils.assert; - function KeyPair(ec, options) { this.ec = ec; this.priv = null; - this.pub = null; // KeyPair(ec, { priv: ..., pub: ... }) + this.pub = null; + // KeyPair(ec, { priv: ..., pub: ... }) if (options.priv) this._importPrivate(options.priv, options.privEnc); if (options.pub) this._importPublic(options.pub, options.pubEnc); } - - exports$F = KeyPair; - + exports$E = KeyPair; KeyPair.fromPublic = function fromPublic(ec, pub, enc) { if (pub instanceof KeyPair) return pub; return new KeyPair(ec, { @@ -61690,7 +97375,6 @@ function dew$E() { pubEnc: enc }); }; - KeyPair.fromPrivate = function fromPrivate(ec, priv, enc) { if (priv instanceof KeyPair) return priv; return new KeyPair(ec, { @@ -61698,7 +97382,6 @@ function dew$E() { privEnc: enc }); }; - KeyPair.prototype.validate = function validate() { var pub = this.getPublic(); if (pub.isInfinity()) return { @@ -61718,30 +97401,26 @@ function dew$E() { reason: null }; }; - KeyPair.prototype.getPublic = function getPublic(compact, enc) { // compact is optional argument if (typeof compact === "string") { enc = compact; compact = null; } - if (!this.pub) this.pub = this.ec.g.mul(this.priv); if (!enc) return this.pub; return this.pub.encode(enc, compact); }; - KeyPair.prototype.getPrivate = function getPrivate(enc) { if (enc === "hex") return this.priv.toString(16, 2);else return this.priv; }; - KeyPair.prototype._importPrivate = function _importPrivate(key, enc) { - this.priv = new BN(key, enc || 16); // Ensure that the priv won't be bigger than n, otherwise we may fail - // in fixed multiplication method + this.priv = new BN(key, enc || 16); + // Ensure that the priv won't be bigger than n, otherwise we may fail + // in fixed multiplication method this.priv = this.priv.umod(this.ec.curve.n); }; - KeyPair.prototype._importPublic = function _importPublic(key, enc) { if (key.x || key.y) { // Montgomery points only have an `x` coordinate. @@ -61752,51 +97431,41 @@ function dew$E() { } else if (this.ec.curve.type === "short" || this.ec.curve.type === "edwards") { assert(key.x && key.y, "Need both x and y coordinate"); } - this.pub = this.ec.curve.point(key.x, key.y); return; } - this.pub = this.ec.curve.decodePoint(key, enc); - }; // ECDH - + }; + // ECDH KeyPair.prototype.derive = function derive(pub) { if (!pub.validate()) { assert(pub.validate(), "public point not validated"); } - return pub.mul(this.priv).getX(); - }; // ECDSA - + }; + // ECDSA KeyPair.prototype.sign = function sign(msg, enc, options) { return this.ec.sign(msg, this, enc, options); }; - KeyPair.prototype.verify = function verify(msg, signature) { return this.ec.verify(msg, signature, this); }; - KeyPair.prototype.inspect = function inspect() { return ""; }; - - return exports$F; + return exports$E; } -var exports$E = {}, - _dewExec$D = false; -function dew$D() { - if (_dewExec$D) return exports$E; - _dewExec$D = true; - - var BN = dew$V(); - - var utils = dew$T(); - +var exports$D = {}, + _dewExec$C = false; +function dew$C() { + if (_dewExec$C) return exports$D; + _dewExec$C = true; + var BN = dew$_(); + var utils = dew$Y(); var assert = utils.assert; - function Signature(options, enc) { if (options instanceof Signature) return options; if (this._importDER(options, enc)) return; @@ -61805,105 +97474,88 @@ function dew$D() { this.s = new BN(options.s, 16); if (options.recoveryParam === undefined) this.recoveryParam = null;else this.recoveryParam = options.recoveryParam; } - - exports$E = Signature; - + exports$D = Signature; function Position() { this.place = 0; } - function getLength(buf, p) { var initial = buf[p.place++]; - if (!(initial & 128)) { return initial; } + var octetLen = initial & 15; - var octetLen = initial & 15; // Indefinite length or overflow - + // Indefinite length or overflow if (octetLen === 0 || octetLen > 4) { return false; } - + if (buf[p.place] === 0) { + return false; + } var val = 0; - for (var i = 0, off = p.place; i < octetLen; i++, off++) { val <<= 8; val |= buf[off]; val >>>= 0; - } // Leading zeroes - + } + // Leading zeroes if (val <= 127) { return false; } - p.place = off; return val; } - function rmPadding(buf) { var i = 0; var len = buf.length - 1; - while (!buf[i] && !(buf[i + 1] & 128) && i < len) { i++; } - if (i === 0) { return buf; } - return buf.slice(i); } - Signature.prototype._importDER = function _importDER(data, enc) { data = utils.toArray(data, enc); var p = new Position(); - if (data[p.place++] !== 48) { return false; } - var len = getLength(data, p); - if (len === false) { return false; } - if (len + p.place !== data.length) { return false; } - if (data[p.place++] !== 2) { return false; } - var rlen = getLength(data, p); - if (rlen === false) { return false; } - + if ((data[p.place] & 128) !== 0) { + return false; + } var r = data.slice(p.place, rlen + p.place); p.place += rlen; - if (data[p.place++] !== 2) { return false; } - var slen = getLength(data, p); - if (slen === false) { return false; } - if (data.length !== slen + p.place) { return false; } - + if ((data[p.place] & 128) !== 0) { + return false; + } var s = data.slice(p.place, slen + p.place); - if (r[0] === 0) { if (r[1] & 128) { r = r.slice(1); @@ -61912,7 +97564,6 @@ function dew$D() { return false; } } - if (s[0] === 0) { if (s[1] & 128) { s = s.slice(1); @@ -61921,43 +97572,36 @@ function dew$D() { return false; } } - this.r = new BN(r); this.s = new BN(s); this.recoveryParam = null; return true; }; - function constructLength(arr, len) { if (len < 128) { arr.push(len); return; } - var octets = 1 + (Math.log(len) / Math.LN2 >>> 3); arr.push(octets | 128); - while (--octets) { arr.push(len >>> (octets << 3) & 255); } - arr.push(len); } - Signature.prototype.toDER = function toDER(enc) { var r = this.r.toArray(); - var s = this.s.toArray(); // Pad values - - if (r[0] & 128) r = [0].concat(r); // Pad values + var s = this.s.toArray(); + // Pad values + if (r[0] & 128) r = [0].concat(r); + // Pad values if (s[0] & 128) s = [0].concat(s); r = rmPadding(r); s = rmPadding(s); - while (!s[0] && !(s[1] & 128)) { s = s.slice(1); } - var arr = [2]; constructLength(arr, r.length); arr = arr.concat(r); @@ -61969,72 +97613,61 @@ function dew$D() { res = res.concat(backHalf); return utils.encode(res, enc); }; - - return exports$E; + return exports$D; } -var exports$D = {}, - _dewExec$C = false; -function dew$C() { - if (_dewExec$C) return exports$D; - _dewExec$C = true; - - var BN = dew$V(); - - var HmacDRBG = dew$F(); - - var utils = dew$T(); - - var curves = dew$G(); - - var rand = dew$11(); - +var exports$C = {}, + _dewExec$B = false; +function dew$B() { + if (_dewExec$B) return exports$C; + _dewExec$B = true; + var BN = dew$_(); + var HmacDRBG = dew$E(); + var utils = dew$Y(); + var curves = dew$F(); + var rand = dew$1i(); var assert = utils.assert; - - var KeyPair = dew$E(); - - var Signature = dew$D(); - + var KeyPair = dew$D(); + var Signature = dew$C(); function EC(options) { - if (!(this instanceof EC)) return new EC(options); // Shortcut `elliptic.ec(curve-name)` + if (!(this instanceof EC)) return new EC(options); + // Shortcut `elliptic.ec(curve-name)` if (typeof options === "string") { assert(Object.prototype.hasOwnProperty.call(curves, options), "Unknown curve " + options); options = curves[options]; - } // Shortcut for `elliptic.ec(elliptic.curves.curveName)` - + } + // Shortcut for `elliptic.ec(elliptic.curves.curveName)` if (options instanceof curves.PresetCurve) options = { curve: options }; this.curve = options.curve.curve; this.n = this.curve.n; this.nh = this.n.ushrn(1); - this.g = this.curve.g; // Point on curve + this.g = this.curve.g; + // Point on curve this.g = options.curve.g; - this.g.precompute(options.curve.n.bitLength() + 1); // Hash for function for DRBG + this.g.precompute(options.curve.n.bitLength() + 1); + // Hash for function for DRBG this.hash = options.hash || options.curve.hash; } - - exports$D = EC; - + exports$C = EC; EC.prototype.keyPair = function keyPair(options) { return new KeyPair(this, options); }; - EC.prototype.keyFromPrivate = function keyFromPrivate(priv, enc) { return KeyPair.fromPrivate(this, priv, enc); }; - EC.prototype.keyFromPublic = function keyFromPublic(pub, enc) { return KeyPair.fromPublic(this, pub, enc); }; - EC.prototype.genKeyPair = function genKeyPair(options) { - if (!options) options = {}; // Instantiate Hmac_DRBG + if (!options) options = {}; + // Instantiate Hmac_DRBG var drbg = new HmacDRBG({ hash: this.hash, pers: options.pers, @@ -62045,7 +97678,6 @@ function dew$C() { }); var bytes = this.n.byteLength(); var ns2 = this.n.sub(new BN(2)); - for (;;) { var priv = new BN(drbg.generate(bytes)); if (priv.cmp(ns2) > 0) continue; @@ -62053,38 +97685,38 @@ function dew$C() { return this.keyFromPrivate(priv); } }; - EC.prototype._truncateToN = function _truncateToN(msg, truncOnly) { var delta = msg.byteLength() * 8 - this.n.bitLength(); if (delta > 0) msg = msg.ushrn(delta); if (!truncOnly && msg.cmp(this.n) >= 0) return msg.sub(this.n);else return msg; }; - EC.prototype.sign = function sign(msg, key, enc, options) { if (typeof enc === "object") { options = enc; enc = null; } - if (!options) options = {}; key = this.keyFromPrivate(key, enc); - msg = this._truncateToN(new BN(msg, 16)); // Zero-extend key to provide enough entropy + msg = this._truncateToN(new BN(msg, 16)); + // Zero-extend key to provide enough entropy var bytes = this.n.byteLength(); - var bkey = key.getPrivate().toArray("be", bytes); // Zero-extend nonce to have the same byte size as N + var bkey = key.getPrivate().toArray("be", bytes); - var nonce = msg.toArray("be", bytes); // Instantiate Hmac_DRBG + // Zero-extend nonce to have the same byte size as N + var nonce = msg.toArray("be", bytes); + // Instantiate Hmac_DRBG var drbg = new HmacDRBG({ hash: this.hash, entropy: bkey, nonce: nonce, pers: options.pers, persEnc: options.persEnc || "utf8" - }); // Number of bytes to generate + }); + // Number of bytes to generate var ns1 = this.n.sub(new BN(1)); - for (var iter = 0;; iter++) { var k = options.k ? options.k(iter) : new BN(drbg.generate(this.n.byteLength())); k = this._truncateToN(k, true); @@ -62097,13 +97729,13 @@ function dew$C() { var s = k.invm(this.n).mul(r.mul(key.getPrivate()).iadd(msg)); s = s.umod(this.n); if (s.cmpn(0) === 0) continue; - var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0); // Use complement of `s`, if it is > `n / 2` + var recoveryParam = (kp.getY().isOdd() ? 1 : 0) | (kpX.cmp(r) !== 0 ? 2 : 0); + // Use complement of `s`, if it is > `n / 2` if (options.canonical && s.cmp(this.nh) > 0) { s = this.n.sub(s); recoveryParam ^= 1; } - return new Signature({ r: r, s: s, @@ -62111,92 +97743,89 @@ function dew$C() { }); } }; - EC.prototype.verify = function verify(msg, signature, key, enc) { msg = this._truncateToN(new BN(msg, 16)); key = this.keyFromPublic(key, enc); - signature = new Signature(signature, "hex"); // Perform primitive values validation + signature = new Signature(signature, "hex"); + // Perform primitive values validation var r = signature.r; var s = signature.s; if (r.cmpn(1) < 0 || r.cmp(this.n) >= 0) return false; - if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false; // Validate signature + if (s.cmpn(1) < 0 || s.cmp(this.n) >= 0) return false; + // Validate signature var sinv = s.invm(this.n); var u1 = sinv.mul(msg).umod(this.n); var u2 = sinv.mul(r).umod(this.n); var p; - if (!this.curve._maxwellTrick) { p = this.g.mulAdd(u1, key.getPublic(), u2); if (p.isInfinity()) return false; return p.getX().umod(this.n).cmp(r) === 0; - } // NOTE: Greg Maxwell's trick, inspired by: - // https://git.io/vad3K + } + // NOTE: Greg Maxwell's trick, inspired by: + // https://git.io/vad3K p = this.g.jmulAdd(u1, key.getPublic(), u2); - if (p.isInfinity()) return false; // Compare `p.x` of Jacobian point with `r`, + if (p.isInfinity()) return false; + + // Compare `p.x` of Jacobian point with `r`, // this will do `p.x == r * p.z^2` instead of multiplying `p.x` by the // inverse of `p.z^2` - return p.eqXToP(r); }; - EC.prototype.recoverPubKey = function (msg, signature, j, enc) { assert((3 & j) === j, "The recovery param is more than two bits"); signature = new Signature(signature, enc); var n = this.n; var e = new BN(msg); var r = signature.r; - var s = signature.s; // A set LSB signifies that the y-coordinate is odd + var s = signature.s; + // A set LSB signifies that the y-coordinate is odd var isYOdd = j & 1; var isSecondKey = j >> 1; - if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) throw new Error("Unable to find sencond key candinate"); // 1.1. Let x = r + jn. + if (r.cmp(this.curve.p.umod(this.curve.n)) >= 0 && isSecondKey) throw new Error("Unable to find sencond key candinate"); + // 1.1. Let x = r + jn. if (isSecondKey) r = this.curve.pointFromX(r.add(this.curve.n), isYOdd);else r = this.curve.pointFromX(r, isYOdd); var rInv = signature.r.invm(n); var s1 = n.sub(e).mul(rInv).umod(n); - var s2 = s.mul(rInv).umod(n); // 1.6.1 Compute Q = r^-1 (sR - eG) - // Q = r^-1 (sR + -eG) + var s2 = s.mul(rInv).umod(n); + // 1.6.1 Compute Q = r^-1 (sR - eG) + // Q = r^-1 (sR + -eG) return this.g.mulAdd(s1, r, s2); }; - EC.prototype.getKeyRecoveryParam = function (e, signature, Q, enc) { signature = new Signature(signature, enc); if (signature.recoveryParam !== null) return signature.recoveryParam; - for (var i = 0; i < 4; i++) { var Qprime; - try { Qprime = this.recoverPubKey(e, signature, i); } catch (e) { continue; } - if (Qprime.eq(Q)) return i; } - throw new Error("Unable to find valid recovery factor"); }; - - return exports$D; + return exports$C; } -var exports$C = {}, - _dewExec$B = false; -function dew$B() { - if (_dewExec$B) return exports$C; - _dewExec$B = true; - - var utils = dew$T(); - +var exports$B = {}, + _dewExec$A = false; +function dew$A() { + if (_dewExec$A) return exports$B; + _dewExec$A = true; + var utils = dew$Y(); var assert = utils.assert; var parseBytes = utils.parseBytes; var cachedProperty = utils.cachedProperty; + /** * @param {EDDSA} eddsa - instance * @param {Object} params - public/private key parameters @@ -62206,31 +97835,26 @@ function dew$B() { * @param {Array} [params.pub] - public key point encoded as bytes * */ - function KeyPair(eddsa, params) { this.eddsa = eddsa; this._secret = parseBytes(params.secret); if (eddsa.isPoint(params.pub)) this._pub = params.pub;else this._pubBytes = parseBytes(params.pub); } - KeyPair.fromPublic = function fromPublic(eddsa, pub) { if (pub instanceof KeyPair) return pub; return new KeyPair(eddsa, { pub: pub }); }; - KeyPair.fromSecret = function fromSecret(eddsa, secret) { if (secret instanceof KeyPair) return secret; return new KeyPair(eddsa, { secret: secret }); }; - KeyPair.prototype.secret = function secret() { return this._secret; }; - cachedProperty(KeyPair, "pubBytes", function pubBytes() { return this.eddsa.encodePoint(this.pub()); }); @@ -62257,42 +97881,35 @@ function dew$B() { cachedProperty(KeyPair, "messagePrefix", function messagePrefix() { return this.hash().slice(this.eddsa.encodingLength); }); - KeyPair.prototype.sign = function sign(message) { assert(this._secret, "KeyPair can only verify"); return this.eddsa.sign(message, this); }; - KeyPair.prototype.verify = function verify(message, sig) { return this.eddsa.verify(message, sig, this); }; - KeyPair.prototype.getSecret = function getSecret(enc) { assert(this._secret, "KeyPair is public only"); return utils.encode(this.secret(), enc); }; - KeyPair.prototype.getPublic = function getPublic(enc) { return utils.encode(this.pubBytes(), enc); }; - - exports$C = KeyPair; - return exports$C; + exports$B = KeyPair; + return exports$B; } -var exports$B = {}, - _dewExec$A = false; -function dew$A() { - if (_dewExec$A) return exports$B; - _dewExec$A = true; - - var BN = dew$V(); - - var utils = dew$T(); - +var exports$A = {}, + _dewExec$z = false; +function dew$z() { + if (_dewExec$z) return exports$A; + _dewExec$z = true; + var BN = dew$_(); + var utils = dew$Y(); var assert = utils.assert; var cachedProperty = utils.cachedProperty; var parseBytes = utils.parseBytes; + /** * @param {EDDSA} eddsa - eddsa instance * @param {Array|Object} sig - @@ -62301,25 +97918,22 @@ function dew$A() { * @param {Array} [sig.Rencoded] - R point encoded * @param {Array} [sig.Sencoded] - S scalar encoded */ - function Signature(eddsa, sig) { this.eddsa = eddsa; if (typeof sig !== "object") sig = parseBytes(sig); - if (Array.isArray(sig)) { + assert(sig.length === eddsa.encodingLength * 2, "Signature has invalid size"); sig = { R: sig.slice(0, eddsa.encodingLength), S: sig.slice(eddsa.encodingLength) }; } - assert(sig.R && sig.S, "Signature without R or S"); if (eddsa.isPoint(sig.R)) this._R = sig.R; if (sig.S instanceof BN) this._S = sig.S; this._Rencoded = Array.isArray(sig.R) ? sig.R : sig.Rencoded; this._Sencoded = Array.isArray(sig.S) ? sig.S : sig.Sencoded; } - cachedProperty(Signature, "S", function S() { return this.eddsa.decodeInt(this.Sencoded()); }); @@ -62332,38 +97946,28 @@ function dew$A() { cachedProperty(Signature, "Sencoded", function Sencoded() { return this.eddsa.encodeInt(this.S()); }); - Signature.prototype.toBytes = function toBytes() { return this.Rencoded().concat(this.Sencoded()); }; - Signature.prototype.toHex = function toHex() { return utils.encode(this.toBytes(), "hex").toUpperCase(); }; - - exports$B = Signature; - return exports$B; + exports$A = Signature; + return exports$A; } -var exports$A = {}, - _dewExec$z = false; -function dew$z() { - if (_dewExec$z) return exports$A; - _dewExec$z = true; - - var hash = dew$I(); - - var curves = dew$G(); - - var utils = dew$T(); - +var exports$z = {}, + _dewExec$y = false; +function dew$y() { + if (_dewExec$y) return exports$z; + _dewExec$y = true; + var hash = dew$H(); + var curves = dew$F(); + var utils = dew$Y(); var assert = utils.assert; var parseBytes = utils.parseBytes; - - var KeyPair = dew$B(); - - var Signature = dew$A(); - + var KeyPair = dew$A(); + var Signature = dew$z(); function EDDSA(curve) { assert(curve === "ed25519", "only tested with ed25519 so far"); if (!(this instanceof EDDSA)) return new EDDSA(curve); @@ -62375,14 +97979,13 @@ function dew$z() { this.encodingLength = Math.ceil(curve.n.bitLength() / 8); this.hash = hash.sha512; } + exports$z = EDDSA; - exports$A = EDDSA; /** * @param {Array|String} message - message bytes * @param {Array|String|KeyPair} secret - secret bytes or a keypair * @returns {Signature} - signature */ - EDDSA.prototype.sign = function sign(message, secret) { message = parseBytes(message); var key = this.keyFromSecret(secret); @@ -62397,44 +98000,41 @@ function dew$z() { Rencoded: Rencoded }); }; + /** * @param {Array} message - message bytes * @param {Array|String|Signature} sig - sig bytes * @param {Array|String|Point|KeyPair} pub - public key * @returns {Boolean} - true if public key matches sig of message */ - - EDDSA.prototype.verify = function verify(message, sig, pub) { message = parseBytes(message); sig = this.makeSignature(sig); + if (sig.S().gte(sig.eddsa.curve.n) || sig.S().isNeg()) { + return false; + } var key = this.keyFromPublic(pub); var h = this.hashInt(sig.Rencoded(), key.pubBytes(), message); var SG = this.g.mul(sig.S()); var RplusAh = sig.R().add(key.pub().mul(h)); return RplusAh.eq(SG); }; - EDDSA.prototype.hashInt = function hashInt() { var hash = this.hash(); - for (var i = 0; i < arguments.length; i++) hash.update(arguments[i]); - return utils.intFromLE(hash.digest()).umod(this.curve.n); }; - EDDSA.prototype.keyFromPublic = function keyFromPublic(pub) { return KeyPair.fromPublic(this, pub); }; - EDDSA.prototype.keyFromSecret = function keyFromSecret(secret) { return KeyPair.fromSecret(this, secret); }; - EDDSA.prototype.makeSignature = function makeSignature(sig) { if (sig instanceof Signature) return sig; return new Signature(this, sig); }; + /** * * https://tools.ietf.org/html/draft-josefsson-eddsa-ed25519-03#section-5.2 * @@ -62443,14 +98043,11 @@ function dew$z() { * parameters. * */ - - EDDSA.prototype.encodePoint = function encodePoint(point) { var enc = point.getY().toArray("le", this.encodingLength); enc[this.encodingLength - 1] |= point.getX().isOdd() ? 128 : 0; return enc; }; - EDDSA.prototype.decodePoint = function decodePoint(bytes) { bytes = utils.parseBytes(bytes); var lastIx = bytes.length - 1; @@ -62459,213 +98056,181 @@ function dew$z() { var y = utils.intFromLE(normed); return this.curve.pointFromY(y, xIsOdd); }; - EDDSA.prototype.encodeInt = function encodeInt(num) { return num.toArray("le", this.encodingLength); }; - EDDSA.prototype.decodeInt = function decodeInt(bytes) { return utils.intFromLE(bytes); }; - EDDSA.prototype.isPoint = function isPoint(val) { return val instanceof this.pointClass; }; - - return exports$A; -} - -var exports$z = {}, - _dewExec$y = false; -function dew$y() { - if (_dewExec$y) return exports$z; - _dewExec$y = true; - var elliptic = exports$z; - elliptic.version = _package.version; - elliptic.utils = dew$T(); - elliptic.rand = dew$11(); - elliptic.curve = dew$O(); - elliptic.curves = dew$G(); // Protocols - - elliptic.ec = dew$C(); - elliptic.eddsa = dew$z(); return exports$z; } var exports$y = {}, - _dewExec$x = false; -var module$2 = { - exports: exports$y -}; - -var _global$5 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - + _dewExec$x = false; function dew$x() { - if (_dewExec$x) return module$2.exports; + if (_dewExec$x) return exports$y; _dewExec$x = true; + var elliptic = exports$y; + elliptic.version = _package.version; + elliptic.utils = dew$Y(); + elliptic.rand = dew$1i(); + elliptic.curve = dew$T(); + elliptic.curves = dew$F(); + + // Protocols + elliptic.ec = dew$B(); + elliptic.eddsa = dew$y(); + return exports$y; +} +var exports$x = {}, + _dewExec$w = false; +var module$2 = { + exports: exports$x +}; +var _global$c = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$w() { + if (_dewExec$w) return module$2.exports; + _dewExec$w = true; (function (module, exports) { + // Utils function assert(val, msg) { if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. - + } + // Could use `inherits` module, but don't want to move from single file + // architecture yet. function inherits(ctor, superCtor) { ctor.super_ = superCtor; - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; - } // BN + } + // BN function BN(number, base, endian) { if (BN.isBN(number)) { return number; } + (this || _global$c).negative = 0; + (this || _global$c).words = null; + (this || _global$c).length = 0; - (this || _global$5).negative = 0; - (this || _global$5).words = null; - (this || _global$5).length = 0; // Reduction context - - (this || _global$5).red = null; - + // Reduction context + (this || _global$c).red = null; if (number !== null) { if (base === "le" || base === "be") { endian = base; base = 10; } - this._init(number || 0, base || 10, endian || "be"); } } - if (typeof module === "object") { module.exports = BN; } else { exports.BN = BN; } - BN.BN = BN; BN.wordSize = 26; var Buffer; - try { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = buffer.Buffer; + Buffer = dew$3J().Buffer; } } catch (e) {} - BN.isBN = function isBN(num) { if (num instanceof BN) { return true; } - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); }; - BN.max = function max(left, right) { if (left.cmp(right) > 0) return left; return right; }; - BN.min = function min(left, right) { if (left.cmp(right) < 0) return left; return right; }; - BN.prototype._init = function init(number, base, endian) { if (typeof number === "number") { return this._initNumber(number, base, endian); } - if (typeof number === "object") { return this._initArray(number, base, endian); } - if (base === "hex") { base = 16; } - assert(base === (base | 0) && base >= 2 && base <= 36); number = number.toString().replace(/\s+/g, ""); var start = 0; - if (number[0] === "-") { start++; - (this || _global$5).negative = 1; + (this || _global$c).negative = 1; } - if (start < number.length) { if (base === 16) { this._parseHex(number, start, endian); } else { this._parseBase(number, base, start); - if (endian === "le") { this._initArray(this.toArray(), base, endian); } } } }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { - (this || _global$5).negative = 1; + (this || _global$c).negative = 1; number = -number; } - if (number < 67108864) { - (this || _global$5).words = [number & 67108863]; - (this || _global$5).length = 1; + (this || _global$c).words = [number & 67108863]; + (this || _global$c).length = 1; } else if (number < 4503599627370496) { - (this || _global$5).words = [number & 67108863, number / 67108864 & 67108863]; - (this || _global$5).length = 2; + (this || _global$c).words = [number & 67108863, number / 67108864 & 67108863]; + (this || _global$c).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - - (this || _global$5).words = [number & 67108863, number / 67108864 & 67108863, 1]; - (this || _global$5).length = 3; + (this || _global$c).words = [number & 67108863, number / 67108864 & 67108863, 1]; + (this || _global$c).length = 3; } + if (endian !== "le") return; - if (endian !== "le") return; // Reverse the bytes - + // Reverse the bytes this._initArray(this.toArray(), base, endian); }; - BN.prototype._initArray = function _initArray(number, base, endian) { // Perhaps a Uint8Array assert(typeof number.length === "number"); - if (number.length <= 0) { - (this || _global$5).words = [0]; - (this || _global$5).length = 1; - return this || _global$5; + (this || _global$c).words = [0]; + (this || _global$c).length = 1; + return this || _global$c; } - - (this || _global$5).length = Math.ceil(number.length / 3); - (this || _global$5).words = new Array((this || _global$5).length); - - for (var i = 0; i < (this || _global$5).length; i++) { - (this || _global$5).words[i] = 0; + (this || _global$c).length = Math.ceil(number.length / 3); + (this || _global$c).words = new Array((this || _global$c).length); + for (var i = 0; i < (this || _global$c).length; i++) { + (this || _global$c).words[i] = 0; } - var j, w; var off = 0; - if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; - (this || _global$5).words[j] |= w << off & 67108863; - (this || _global$5).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$c).words[j] |= w << off & 67108863; + (this || _global$c).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; @@ -62674,203 +98239,177 @@ function dew$x() { } else if (endian === "le") { for (i = 0, j = 0; i < number.length; i += 3) { w = number[i] | number[i + 1] << 8 | number[i + 2] << 16; - (this || _global$5).words[j] |= w << off & 67108863; - (this || _global$5).words[j + 1] = w >>> 26 - off & 67108863; + (this || _global$c).words[j] |= w << off & 67108863; + (this || _global$c).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; } } } - return this.strip(); }; - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // 'A' - 'F' - + var c = string.charCodeAt(index); + // 'A' - 'F' if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' + return c - 55; + // 'a' - 'f' } else if (c >= 97 && c <= 102) { - return c - 87; // '0' - '9' + return c - 87; + // '0' - '9' } else { return c - 48 & 15; } } - function parseHexByte(string, lowerBound, index) { var r = parseHex4Bits(string, index); - if (index - 1 >= lowerBound) { r |= parseHex4Bits(string, index - 1) << 4; } - return r; } - BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number - (this || _global$5).length = Math.ceil((number.length - start) / 6); - (this || _global$5).words = new Array((this || _global$5).length); - - for (var i = 0; i < (this || _global$5).length; i++) { - (this || _global$5).words[i] = 0; - } // 24-bits chunks - + (this || _global$c).length = Math.ceil((number.length - start) / 6); + (this || _global$c).words = new Array((this || _global$c).length); + for (var i = 0; i < (this || _global$c).length; i++) { + (this || _global$c).words[i] = 0; + } + // 24-bits chunks var off = 0; var j = 0; var w; - if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; - (this || _global$5).words[j] |= w & 67108863; - + (this || _global$c).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$5).words[j] |= w >>> 26; + (this || _global$c).words[j] |= w >>> 26; } else { off += 8; } } } else { var parseLength = number.length - start; - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; - (this || _global$5).words[j] |= w & 67108863; - + (this || _global$c).words[j] |= w & 67108863; if (off >= 18) { off -= 18; j += 1; - (this || _global$5).words[j] |= w >>> 26; + (this || _global$c).words[j] |= w >>> 26; } else { off += 8; } } } - this.strip(); }; - function parseBase(str, start, end, mul) { var r = 0; var len = Math.min(str.length, end); - for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + r *= mul; + // 'a' if (c >= 49) { - r += c - 49 + 10; // 'A' + r += c - 49 + 10; + + // 'A' } else if (c >= 17) { - r += c - 17 + 10; // '0' - '9' + r += c - 17 + 10; + + // '0' - '9' } else { r += c; } } - return r; } - BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero - (this || _global$5).words = [0]; - (this || _global$5).length = 1; // Find length of limb in base + (this || _global$c).words = [0]; + (this || _global$c).length = 1; + // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; } - limbLen--; limbPow = limbPow / base | 0; var total = number.length - start; var mod = total % limbLen; var end = Math.min(total, total - mod) + start; var word = 0; - for (var i = start; i < end; i += limbLen) { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - - if ((this || _global$5).words[0] + word < 67108864) { - (this || _global$5).words[0] += word; + if ((this || _global$c).words[0] + word < 67108864) { + (this || _global$c).words[0] += word; } else { this._iaddn(word); } } - if (mod !== 0) { var pow = 1; word = parseBase(number, i, number.length, base); - for (i = 0; i < mod; i++) { pow *= base; } - this.imuln(pow); - - if ((this || _global$5).words[0] + word < 67108864) { - (this || _global$5).words[0] += word; + if ((this || _global$c).words[0] + word < 67108864) { + (this || _global$c).words[0] += word; } else { this._iaddn(word); } } - this.strip(); }; - BN.prototype.copy = function copy(dest) { - dest.words = new Array((this || _global$5).length); - - for (var i = 0; i < (this || _global$5).length; i++) { - dest.words[i] = (this || _global$5).words[i]; + dest.words = new Array((this || _global$c).length); + for (var i = 0; i < (this || _global$c).length; i++) { + dest.words[i] = (this || _global$c).words[i]; } - - dest.length = (this || _global$5).length; - dest.negative = (this || _global$5).negative; - dest.red = (this || _global$5).red; + dest.length = (this || _global$c).length; + dest.negative = (this || _global$c).negative; + dest.red = (this || _global$c).red; }; - BN.prototype.clone = function clone() { var r = new BN(null); this.copy(r); return r; }; - BN.prototype._expand = function _expand(size) { - while ((this || _global$5).length < size) { - (this || _global$5).words[(this || _global$5).length++] = 0; + while ((this || _global$c).length < size) { + (this || _global$c).words[(this || _global$c).length++] = 0; } + return this || _global$c; + }; - return this || _global$5; - }; // Remove leading `0` from `this` - - + // Remove leading `0` from `this` BN.prototype.strip = function strip() { - while ((this || _global$5).length > 1 && (this || _global$5).words[(this || _global$5).length - 1] === 0) { - (this || _global$5).length--; + while ((this || _global$c).length > 1 && (this || _global$c).words[(this || _global$c).length - 1] === 0) { + (this || _global$c).length--; } - return this._normSign(); }; - BN.prototype._normSign = function _normSign() { // -0 = 0 - if ((this || _global$5).length === 1 && (this || _global$5).words[0] === 0) { - (this || _global$5).negative = 0; + if ((this || _global$c).length === 1 && (this || _global$c).words[0] === 0) { + (this || _global$c).negative = 0; } - - return this || _global$5; + return this || _global$c; }; - BN.prototype.inspect = function inspect() { - return ((this || _global$5).red ? ""; + return ((this || _global$c).red ? ""; }; + /* var zeros = []; var groupSizes = []; @@ -62898,121 +98437,95 @@ function dew$x() { } */ - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - BN.prototype.toString = function toString(base, padding) { base = base || 10; padding = padding | 0 || 1; var out; - if (base === 16 || base === "hex") { out = ""; var off = 0; var carry = 0; - - for (var i = 0; i < (this || _global$5).length; i++) { - var w = (this || _global$5).words[i]; + for (var i = 0; i < (this || _global$c).length; i++) { + var w = (this || _global$c).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - - if (carry !== 0 || i !== (this || _global$5).length - 1) { + if (carry !== 0 || i !== (this || _global$c).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; } - off += 2; - if (off >= 26) { off -= 26; i--; } } - if (carry !== 0) { out = carry.toString(16) + out; } - while (out.length % padding !== 0) { out = "0" + out; } - - if ((this || _global$5).negative !== 0) { + if ((this || _global$c).negative !== 0) { out = "-" + out; } - return out; } - if (base === (base | 0) && base >= 2 && base <= 36) { // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); var groupBase = groupBases[base]; out = ""; var c = this.clone(); c.negative = 0; - while (!c.isZero()) { var r = c.modn(groupBase).toString(base); c = c.idivn(groupBase); - if (!c.isZero()) { out = zeros[groupSize - r.length] + r + out; } else { out = r + out; } } - if (this.isZero()) { out = "0" + out; } - while (out.length % padding !== 0) { out = "0" + out; } - - if ((this || _global$5).negative !== 0) { + if ((this || _global$c).negative !== 0) { out = "-" + out; } - return out; } - assert(false, "Base should be between 2 and 36"); }; - BN.prototype.toNumber = function toNumber() { - var ret = (this || _global$5).words[0]; - - if ((this || _global$5).length === 2) { - ret += (this || _global$5).words[1] * 67108864; - } else if ((this || _global$5).length === 3 && (this || _global$5).words[2] === 1) { + var ret = (this || _global$c).words[0]; + if ((this || _global$c).length === 2) { + ret += (this || _global$c).words[1] * 67108864; + } else if ((this || _global$c).length === 3 && (this || _global$c).words[2] === 1) { // NOTE: at this stage it is known that the top bit is set - ret += 4503599627370496 + (this || _global$5).words[1] * 67108864; - } else if ((this || _global$5).length > 2) { + ret += 4503599627370496 + (this || _global$c).words[1] * 67108864; + } else if ((this || _global$c).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - - return (this || _global$5).negative !== 0 ? -ret : ret; + return (this || _global$c).negative !== 0 ? -ret : ret; }; - BN.prototype.toJSON = function toJSON() { return this.toString(16); }; - BN.prototype.toBuffer = function toBuffer(endian, length) { assert(typeof Buffer !== "undefined"); return this.toArrayLike(Buffer, endian, length); }; - BN.prototype.toArray = function toArray(endian, length) { return this.toArrayLike(Array, endian, length); }; - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { var byteLength = this.byteLength(); var reqLength = length || Math.max(1, byteLength); @@ -63023,13 +98536,11 @@ function dew$x() { var res = new ArrayType(reqLength); var b, i; var q = this.clone(); - if (!littleEndian) { // Assume big-endian for (i = 0; i < reqLength - byteLength; i++) { res[i] = 0; } - for (i = 0; !q.isZero(); i++) { b = q.andln(255); q.iushrn(8); @@ -63041,15 +98552,12 @@ function dew$x() { q.iushrn(8); res[i] = b; } - for (; i < reqLength; i++) { res[i] = 0; } } - return res; }; - if (Math.clz32) { BN.prototype._countBits = function _countBits(w) { return 32 - Math.clz32(w); @@ -63058,458 +98566,400 @@ function dew$x() { BN.prototype._countBits = function _countBits(w) { var t = w; var r = 0; - if (t >= 4096) { r += 13; t >>>= 13; } - if (t >= 64) { r += 7; t >>>= 7; } - if (t >= 8) { r += 4; t >>>= 4; } - if (t >= 2) { r += 2; t >>>= 2; } - return r + t; }; } - BN.prototype._zeroBits = function _zeroBits(w) { // Short-cut if (w === 0) return 26; var t = w; var r = 0; - if ((t & 8191) === 0) { r += 13; t >>>= 13; } - if ((t & 127) === 0) { r += 7; t >>>= 7; } - if ((t & 15) === 0) { r += 4; t >>>= 4; } - if ((t & 3) === 0) { r += 2; t >>>= 2; } - if ((t & 1) === 0) { r++; } - return r; - }; // Return number of used bits in a BN - + }; + // Return number of used bits in a BN BN.prototype.bitLength = function bitLength() { - var w = (this || _global$5).words[(this || _global$5).length - 1]; - + var w = (this || _global$c).words[(this || _global$c).length - 1]; var hi = this._countBits(w); - - return ((this || _global$5).length - 1) * 26 + hi; + return ((this || _global$c).length - 1) * 26 + hi; }; - function toBitArray(num) { var w = new Array(num.bitLength()); - for (var bit = 0; bit < w.length; bit++) { var off = bit / 26 | 0; var wbit = bit % 26; w[bit] = (num.words[off] & 1 << wbit) >>> wbit; } - return w; - } // Number of trailing zero bits - + } + // Number of trailing zero bits BN.prototype.zeroBits = function zeroBits() { if (this.isZero()) return 0; var r = 0; - - for (var i = 0; i < (this || _global$5).length; i++) { - var b = this._zeroBits((this || _global$5).words[i]); - + for (var i = 0; i < (this || _global$c).length; i++) { + var b = this._zeroBits((this || _global$c).words[i]); r += b; if (b !== 26) break; } - return r; }; - BN.prototype.byteLength = function byteLength() { return Math.ceil(this.bitLength() / 8); }; - BN.prototype.toTwos = function toTwos(width) { - if ((this || _global$5).negative !== 0) { + if ((this || _global$c).negative !== 0) { return this.abs().inotn(width).iaddn(1); } - return this.clone(); }; - BN.prototype.fromTwos = function fromTwos(width) { if (this.testn(width - 1)) { return this.notn(width).iaddn(1).ineg(); } - return this.clone(); }; - BN.prototype.isNeg = function isNeg() { - return (this || _global$5).negative !== 0; - }; // Return negative clone of `this` - + return (this || _global$c).negative !== 0; + }; + // Return negative clone of `this` BN.prototype.neg = function neg() { return this.clone().ineg(); }; - BN.prototype.ineg = function ineg() { if (!this.isZero()) { - (this || _global$5).negative ^= 1; + (this || _global$c).negative ^= 1; } + return this || _global$c; + }; - return this || _global$5; - }; // Or `num` with `this` in-place - - + // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { - while ((this || _global$5).length < num.length) { - (this || _global$5).words[(this || _global$5).length++] = 0; + while ((this || _global$c).length < num.length) { + (this || _global$c).words[(this || _global$c).length++] = 0; } - for (var i = 0; i < num.length; i++) { - (this || _global$5).words[i] = (this || _global$5).words[i] | num.words[i]; + (this || _global$c).words[i] = (this || _global$c).words[i] | num.words[i]; } - return this.strip(); }; - BN.prototype.ior = function ior(num) { - assert(((this || _global$5).negative | num.negative) === 0); + assert(((this || _global$c).negative | num.negative) === 0); return this.iuor(num); - }; // Or `num` with `this` - + }; + // Or `num` with `this` BN.prototype.or = function or(num) { - if ((this || _global$5).length > num.length) return this.clone().ior(num); - return num.clone().ior(this || _global$5); + if ((this || _global$c).length > num.length) return this.clone().ior(num); + return num.clone().ior(this || _global$c); }; - BN.prototype.uor = function uor(num) { - if ((this || _global$5).length > num.length) return this.clone().iuor(num); - return num.clone().iuor(this || _global$5); - }; // And `num` with `this` in-place - + if ((this || _global$c).length > num.length) return this.clone().iuor(num); + return num.clone().iuor(this || _global$c); + }; + // And `num` with `this` in-place BN.prototype.iuand = function iuand(num) { // b = min-length(num, this) var b; - - if ((this || _global$5).length > num.length) { + if ((this || _global$c).length > num.length) { b = num; } else { - b = this || _global$5; + b = this || _global$c; } - for (var i = 0; i < b.length; i++) { - (this || _global$5).words[i] = (this || _global$5).words[i] & num.words[i]; + (this || _global$c).words[i] = (this || _global$c).words[i] & num.words[i]; } - - (this || _global$5).length = b.length; + (this || _global$c).length = b.length; return this.strip(); }; - BN.prototype.iand = function iand(num) { - assert(((this || _global$5).negative | num.negative) === 0); + assert(((this || _global$c).negative | num.negative) === 0); return this.iuand(num); - }; // And `num` with `this` - + }; + // And `num` with `this` BN.prototype.and = function and(num) { - if ((this || _global$5).length > num.length) return this.clone().iand(num); - return num.clone().iand(this || _global$5); + if ((this || _global$c).length > num.length) return this.clone().iand(num); + return num.clone().iand(this || _global$c); }; - BN.prototype.uand = function uand(num) { - if ((this || _global$5).length > num.length) return this.clone().iuand(num); - return num.clone().iuand(this || _global$5); - }; // Xor `num` with `this` in-place - + if ((this || _global$c).length > num.length) return this.clone().iuand(num); + return num.clone().iuand(this || _global$c); + }; + // Xor `num` with `this` in-place BN.prototype.iuxor = function iuxor(num) { // a.length > b.length var a; var b; - - if ((this || _global$5).length > num.length) { - a = this || _global$5; + if ((this || _global$c).length > num.length) { + a = this || _global$c; b = num; } else { a = num; - b = this || _global$5; + b = this || _global$c; } - for (var i = 0; i < b.length; i++) { - (this || _global$5).words[i] = a.words[i] ^ b.words[i]; + (this || _global$c).words[i] = a.words[i] ^ b.words[i]; } - - if ((this || _global$5) !== a) { + if ((this || _global$c) !== a) { for (; i < a.length; i++) { - (this || _global$5).words[i] = a.words[i]; + (this || _global$c).words[i] = a.words[i]; } } - - (this || _global$5).length = a.length; + (this || _global$c).length = a.length; return this.strip(); }; - BN.prototype.ixor = function ixor(num) { - assert(((this || _global$5).negative | num.negative) === 0); + assert(((this || _global$c).negative | num.negative) === 0); return this.iuxor(num); - }; // Xor `num` with `this` - + }; + // Xor `num` with `this` BN.prototype.xor = function xor(num) { - if ((this || _global$5).length > num.length) return this.clone().ixor(num); - return num.clone().ixor(this || _global$5); + if ((this || _global$c).length > num.length) return this.clone().ixor(num); + return num.clone().ixor(this || _global$c); }; - BN.prototype.uxor = function uxor(num) { - if ((this || _global$5).length > num.length) return this.clone().iuxor(num); - return num.clone().iuxor(this || _global$5); - }; // Not ``this`` with ``width`` bitwidth - + if ((this || _global$c).length > num.length) return this.clone().iuxor(num); + return num.clone().iuxor(this || _global$c); + }; + // Not ``this`` with ``width`` bitwidth BN.prototype.inotn = function inotn(width) { assert(typeof width === "number" && width >= 0); var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + var bitsLeft = width % 26; + // Extend the buffer with leading zeroes this._expand(bytesNeeded); - if (bitsLeft > 0) { bytesNeeded--; - } // Handle complete words - + } + // Handle complete words for (var i = 0; i < bytesNeeded; i++) { - (this || _global$5).words[i] = ~(this || _global$5).words[i] & 67108863; - } // Handle the residue - + (this || _global$c).words[i] = ~(this || _global$c).words[i] & 67108863; + } + // Handle the residue if (bitsLeft > 0) { - (this || _global$5).words[i] = ~(this || _global$5).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes - + (this || _global$c).words[i] = ~(this || _global$c).words[i] & 67108863 >> 26 - bitsLeft; + } + // And remove leading zeroes return this.strip(); }; - BN.prototype.notn = function notn(width) { return this.clone().inotn(width); - }; // Set `bit` of `this` - + }; + // Set `bit` of `this` BN.prototype.setn = function setn(bit, val) { assert(typeof bit === "number" && bit >= 0); var off = bit / 26 | 0; var wbit = bit % 26; - this._expand(off + 1); - if (val) { - (this || _global$5).words[off] = (this || _global$5).words[off] | 1 << wbit; + (this || _global$c).words[off] = (this || _global$c).words[off] | 1 << wbit; } else { - (this || _global$5).words[off] = (this || _global$5).words[off] & ~(1 << wbit); + (this || _global$c).words[off] = (this || _global$c).words[off] & ~(1 << wbit); } - return this.strip(); - }; // Add `num` to `this` in-place - + }; + // Add `num` to `this` in-place BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + var r; - if ((this || _global$5).negative !== 0 && num.negative === 0) { - (this || _global$5).negative = 0; + // negative + positive + if ((this || _global$c).negative !== 0 && num.negative === 0) { + (this || _global$c).negative = 0; r = this.isub(num); - (this || _global$5).negative ^= 1; - return this._normSign(); // positive + negative - } else if ((this || _global$5).negative === 0 && num.negative !== 0) { + (this || _global$c).negative ^= 1; + return this._normSign(); + + // positive + negative + } else if ((this || _global$c).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; return r._normSign(); - } // a.length > b.length - + } + // a.length > b.length var a, b; - - if ((this || _global$5).length > num.length) { - a = this || _global$5; + if ((this || _global$c).length > num.length) { + a = this || _global$c; b = num; } else { a = num; - b = this || _global$5; + b = this || _global$c; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; - (this || _global$5).words[i] = r & 67108863; + (this || _global$c).words[i] = r & 67108863; carry = r >>> 26; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; - (this || _global$5).words[i] = r & 67108863; + (this || _global$c).words[i] = r & 67108863; carry = r >>> 26; } - - (this || _global$5).length = a.length; - + (this || _global$c).length = a.length; if (carry !== 0) { - (this || _global$5).words[(this || _global$5).length] = carry; - (this || _global$5).length++; // Copy the rest of the words - } else if (a !== (this || _global$5)) { + (this || _global$c).words[(this || _global$c).length] = carry; + (this || _global$c).length++; + // Copy the rest of the words + } else if (a !== (this || _global$c)) { for (; i < a.length; i++) { - (this || _global$5).words[i] = a.words[i]; + (this || _global$c).words[i] = a.words[i]; } } + return this || _global$c; + }; - return this || _global$5; - }; // Add `num` to `this` - - + // Add `num` to `this` BN.prototype.add = function add(num) { var res; - - if (num.negative !== 0 && (this || _global$5).negative === 0) { + if (num.negative !== 0 && (this || _global$c).negative === 0) { num.negative = 0; res = this.sub(num); num.negative ^= 1; return res; - } else if (num.negative === 0 && (this || _global$5).negative !== 0) { - (this || _global$5).negative = 0; - res = num.sub(this || _global$5); - (this || _global$5).negative = 1; + } else if (num.negative === 0 && (this || _global$c).negative !== 0) { + (this || _global$c).negative = 0; + res = num.sub(this || _global$c); + (this || _global$c).negative = 1; return res; } + if ((this || _global$c).length > num.length) return this.clone().iadd(num); + return num.clone().iadd(this || _global$c); + }; - if ((this || _global$5).length > num.length) return this.clone().iadd(num); - return num.clone().iadd(this || _global$5); - }; // Subtract `num` from `this` in-place - - + // Subtract `num` from `this` in-place BN.prototype.isub = function isub(num) { // this - (-num) = this + num if (num.negative !== 0) { num.negative = 0; var r = this.iadd(num); num.negative = 1; - return r._normSign(); // -this - num = -(this + num) - } else if ((this || _global$5).negative !== 0) { - (this || _global$5).negative = 0; + return r._normSign(); + + // -this - num = -(this + num) + } else if ((this || _global$c).negative !== 0) { + (this || _global$c).negative = 0; this.iadd(num); - (this || _global$5).negative = 1; + (this || _global$c).negative = 1; return this._normSign(); - } // At this point both numbers are positive - + } - var cmp = this.cmp(num); // Optimization - zeroify + // At this point both numbers are positive + var cmp = this.cmp(num); + // Optimization - zeroify if (cmp === 0) { - (this || _global$5).negative = 0; - (this || _global$5).length = 1; - (this || _global$5).words[0] = 0; - return this || _global$5; - } // a > b - + (this || _global$c).negative = 0; + (this || _global$c).length = 1; + (this || _global$c).words[0] = 0; + return this || _global$c; + } + // a > b var a, b; - if (cmp > 0) { - a = this || _global$5; + a = this || _global$c; b = num; } else { a = num; - b = this || _global$5; + b = this || _global$c; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; - (this || _global$5).words[i] = r & 67108863; + (this || _global$c).words[i] = r & 67108863; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; - (this || _global$5).words[i] = r & 67108863; - } // Copy rest of the words - + (this || _global$c).words[i] = r & 67108863; + } - if (carry === 0 && i < a.length && a !== (this || _global$5)) { + // Copy rest of the words + if (carry === 0 && i < a.length && a !== (this || _global$c)) { for (; i < a.length; i++) { - (this || _global$5).words[i] = a.words[i]; + (this || _global$c).words[i] = a.words[i]; } } - - (this || _global$5).length = Math.max((this || _global$5).length, i); - - if (a !== (this || _global$5)) { - (this || _global$5).negative = 1; + (this || _global$c).length = Math.max((this || _global$c).length, i); + if (a !== (this || _global$c)) { + (this || _global$c).negative = 1; } - return this.strip(); - }; // Subtract `num` from `this` - + }; + // Subtract `num` from `this` BN.prototype.sub = function sub(num) { return this.clone().isub(num); }; - function smallMulTo(self, num, out) { out.negative = num.negative ^ self.negative; var len = self.length + num.length | 0; out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + len = len - 1 | 0; + // Peel one iteration (compiler can't do it, because of code complexity) var a = self.words[0] | 0; var b = num.words[0] | 0; var r = a * b; var lo = r & 67108863; var carry = r / 67108864 | 0; out.words[0] = lo; - for (var k = 1; k < len; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff var ncarry = carry >>> 26; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j | 0; a = self.words[i] | 0; @@ -63518,23 +98968,20 @@ function dew$x() { ncarry += r / 67108864 | 0; rword = r & 67108863; } - out.words[k] = rword | 0; carry = ncarry | 0; } - if (carry !== 0) { out.words[k] = carry | 0; } else { out.length--; } - return out.strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need + } + + // TODO(indutny): it may be reasonable to omit it for users who don't need // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit // multiplication (like elliptic secp256k1). - - var comb10MulTo = function comb10MulTo(self, num, out) { var a = self.words; var b = num.words; @@ -63606,7 +99053,6 @@ function dew$x() { out.negative = self.negative ^ num.negative; out.length = 19; /* k = 0 */ - lo = Math.imul(al0, bl0); mid = Math.imul(al0, bh0); mid = mid + Math.imul(ah0, bl0) | 0; @@ -63615,7 +99061,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; w0 &= 67108863; /* k = 1 */ - lo = Math.imul(al1, bl0); mid = Math.imul(al1, bh0); mid = mid + Math.imul(ah1, bl0) | 0; @@ -63628,7 +99073,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; w1 &= 67108863; /* k = 2 */ - lo = Math.imul(al2, bl0); mid = Math.imul(al2, bh0); mid = mid + Math.imul(ah2, bl0) | 0; @@ -63645,7 +99089,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; w2 &= 67108863; /* k = 3 */ - lo = Math.imul(al3, bl0); mid = Math.imul(al3, bh0); mid = mid + Math.imul(ah3, bl0) | 0; @@ -63666,7 +99109,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; w3 &= 67108863; /* k = 4 */ - lo = Math.imul(al4, bl0); mid = Math.imul(al4, bh0); mid = mid + Math.imul(ah4, bl0) | 0; @@ -63691,7 +99133,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; w4 &= 67108863; /* k = 5 */ - lo = Math.imul(al5, bl0); mid = Math.imul(al5, bh0); mid = mid + Math.imul(ah5, bl0) | 0; @@ -63720,7 +99161,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; w5 &= 67108863; /* k = 6 */ - lo = Math.imul(al6, bl0); mid = Math.imul(al6, bh0); mid = mid + Math.imul(ah6, bl0) | 0; @@ -63753,7 +99193,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; w6 &= 67108863; /* k = 7 */ - lo = Math.imul(al7, bl0); mid = Math.imul(al7, bh0); mid = mid + Math.imul(ah7, bl0) | 0; @@ -63790,7 +99229,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; w7 &= 67108863; /* k = 8 */ - lo = Math.imul(al8, bl0); mid = Math.imul(al8, bh0); mid = mid + Math.imul(ah8, bl0) | 0; @@ -63831,7 +99269,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; w8 &= 67108863; /* k = 9 */ - lo = Math.imul(al9, bl0); mid = Math.imul(al9, bh0); mid = mid + Math.imul(ah9, bl0) | 0; @@ -63876,7 +99313,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; w9 &= 67108863; /* k = 10 */ - lo = Math.imul(al9, bl1); mid = Math.imul(al9, bh1); mid = mid + Math.imul(ah9, bl1) | 0; @@ -63917,7 +99353,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; w10 &= 67108863; /* k = 11 */ - lo = Math.imul(al9, bl2); mid = Math.imul(al9, bh2); mid = mid + Math.imul(ah9, bl2) | 0; @@ -63954,7 +99389,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; w11 &= 67108863; /* k = 12 */ - lo = Math.imul(al9, bl3); mid = Math.imul(al9, bh3); mid = mid + Math.imul(ah9, bl3) | 0; @@ -63987,7 +99421,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; w12 &= 67108863; /* k = 13 */ - lo = Math.imul(al9, bl4); mid = Math.imul(al9, bh4); mid = mid + Math.imul(ah9, bl4) | 0; @@ -64016,7 +99449,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; w13 &= 67108863; /* k = 14 */ - lo = Math.imul(al9, bl5); mid = Math.imul(al9, bh5); mid = mid + Math.imul(ah9, bl5) | 0; @@ -64041,7 +99473,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; w14 &= 67108863; /* k = 15 */ - lo = Math.imul(al9, bl6); mid = Math.imul(al9, bh6); mid = mid + Math.imul(ah9, bl6) | 0; @@ -64062,7 +99493,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; w15 &= 67108863; /* k = 16 */ - lo = Math.imul(al9, bl7); mid = Math.imul(al9, bh7); mid = mid + Math.imul(ah9, bl7) | 0; @@ -64079,7 +99509,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; w16 &= 67108863; /* k = 17 */ - lo = Math.imul(al9, bl8); mid = Math.imul(al9, bh8); mid = mid + Math.imul(ah9, bl8) | 0; @@ -64092,7 +99521,6 @@ function dew$x() { c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; w17 &= 67108863; /* k = 18 */ - lo = Math.imul(al9, bl9); mid = Math.imul(al9, bh9); mid = mid + Math.imul(ah9, bl9) | 0; @@ -64119,26 +99547,22 @@ function dew$x() { o[16] = w16; o[17] = w17; o[18] = w18; - if (c !== 0) { o[19] = c; out.length++; } - return out; - }; // Polyfill comb - + }; + // Polyfill comb if (!Math.imul) { comb10MulTo = smallMulTo; } - function bigMulTo(self, num, out) { out.negative = num.negative ^ self.negative; out.length = self.length + num.length; var carry = 0; var hncarry = 0; - for (var k = 0; k < out.length - 1; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff @@ -64146,7 +99570,6 @@ function dew$x() { hncarry = 0; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j; var a = self.words[i] | 0; @@ -64160,95 +99583,80 @@ function dew$x() { hncarry += ncarry >>> 26; ncarry &= 67108863; } - out.words[k] = rword; carry = ncarry; ncarry = hncarry; } - if (carry !== 0) { out.words[k] = carry; } else { out.length--; } - return out.strip(); } - function jumboMulTo(self, num, out) { var fftm = new FFTM(); return fftm.mulp(self, num, out); } - BN.prototype.mulTo = function mulTo(num, out) { var res; - var len = (this || _global$5).length + num.length; - - if ((this || _global$5).length === 10 && num.length === 10) { - res = comb10MulTo(this || _global$5, num, out); + var len = (this || _global$c).length + num.length; + if ((this || _global$c).length === 10 && num.length === 10) { + res = comb10MulTo(this || _global$c, num, out); } else if (len < 63) { - res = smallMulTo(this || _global$5, num, out); + res = smallMulTo(this || _global$c, num, out); } else if (len < 1024) { - res = bigMulTo(this || _global$5, num, out); + res = bigMulTo(this || _global$c, num, out); } else { - res = jumboMulTo(this || _global$5, num, out); + res = jumboMulTo(this || _global$c, num, out); } - return res; - }; // Cooley-Tukey algorithm for FFT - // slightly revisited to rely on looping instead of recursion + }; + // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion function FFTM(x, y) { - (this || _global$5).x = x; - (this || _global$5).y = y; + (this || _global$c).x = x; + (this || _global$c).y = y; } - FFTM.prototype.makeRBT = function makeRBT(N) { var t = new Array(N); var l = BN.prototype._countBits(N) - 1; - for (var i = 0; i < N; i++) { t[i] = this.revBin(i, l, N); } - return t; - }; // Returns binary-reversed representation of `x` - + }; + // Returns binary-reversed representation of `x` FFTM.prototype.revBin = function revBin(x, l, N) { if (x === 0 || x === N - 1) return x; var rb = 0; - for (var i = 0; i < l; i++) { rb |= (x & 1) << l - i - 1; x >>= 1; } - return rb; - }; // Performs "tweedling" phase, therefore 'emulating' - // behaviour of the recursive algorithm - + }; + // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { for (var i = 0; i < N; i++) { rtws[i] = rws[rbt[i]]; itws[i] = iws[rbt[i]]; } }; - FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { this.permute(rbt, rws, iws, rtws, itws, N); - for (var s = 1; s < N; s <<= 1) { var l = s << 1; var rtwdf = Math.cos(2 * Math.PI / l); var itwdf = Math.sin(2 * Math.PI / l); - for (var p = 0; p < N; p += l) { var rtwdf_ = rtwdf; var itwdf_ = itwdf; - for (var j = 0; j < s; j++) { var re = rtws[p + j]; var ie = itws[p + j]; @@ -64261,8 +99669,8 @@ function dew$x() { itws[p + j] = ie + io; rtws[p + j + s] = re - ro; itws[p + j + s] = ie - io; - /* jshint maxdepth : false */ + /* jshint maxdepth : false */ if (j !== l) { rx = rtwdf * rtwdf_ - itwdf * itwdf_; itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; @@ -64272,22 +99680,17 @@ function dew$x() { } } }; - FFTM.prototype.guessLen13b = function guessLen13b(n, m) { var N = Math.max(m, n) | 1; var odd = N & 1; var i = 0; - for (N = N / 2 | 0; N; N = N >>> 1) { i++; } - return 1 << i + 1 + odd; }; - FFTM.prototype.conjugate = function conjugate(rws, iws, N) { if (N <= 1) return; - for (var i = 0; i < N / 2; i++) { var t = rws[i]; rws[i] = rws[N - i - 1]; @@ -64297,60 +99700,47 @@ function dew$x() { iws[N - i - 1] = -t; } }; - FFTM.prototype.normalize13b = function normalize13b(ws, N) { var carry = 0; - for (var i = 0; i < N / 2; i++) { var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; ws[i] = w & 67108863; - if (w < 67108864) { carry = 0; } else { carry = w / 67108864 | 0; } } - return ws; }; - FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { var carry = 0; - for (var i = 0; i < len; i++) { carry = carry + (ws[i] | 0); rws[2 * i] = carry & 8191; carry = carry >>> 13; rws[2 * i + 1] = carry & 8191; carry = carry >>> 13; - } // Pad with zeroes - + } + // Pad with zeroes for (i = 2 * len; i < N; ++i) { rws[i] = 0; } - assert(carry === 0); assert((carry & ~8191) === 0); }; - FFTM.prototype.stub = function stub(N) { var ph = new Array(N); - for (var i = 0; i < N; i++) { ph[i] = 0; } - return ph; }; - FFTM.prototype.mulp = function mulp(x, y, out) { var N = 2 * this.guessLen13b(x.length, y.length); var rbt = this.makeRBT(N); - var _ = this.stub(N); - var rws = new Array(N); var rwst = new Array(N); var iwst = new Array(N); @@ -64363,13 +99753,11 @@ function dew$x() { this.convert13b(y.words, y.length, nrws, N); this.transform(rws, _, rwst, iwst, N, rbt); this.transform(nrws, _, nrwst, niwst, N, rbt); - for (var i = 0; i < N; i++) { var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; rwst[i] = rx; } - this.conjugate(rwst, iwst, N); this.transform(rwst, iwst, rmws, _, N, rbt); this.conjugate(rmws, _, N); @@ -64377,540 +99765,467 @@ function dew$x() { out.negative = x.negative ^ y.negative; out.length = x.length + y.length; return out.strip(); - }; // Multiply `this` by `num` - + }; + // Multiply `this` by `num` BN.prototype.mul = function mul(num) { var out = new BN(null); - out.words = new Array((this || _global$5).length + num.length); + out.words = new Array((this || _global$c).length + num.length); return this.mulTo(num, out); - }; // Multiply employing FFT - + }; + // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); - out.words = new Array((this || _global$5).length + num.length); - return jumboMulTo(this || _global$5, num, out); - }; // In-place Multiplication - + out.words = new Array((this || _global$c).length + num.length); + return jumboMulTo(this || _global$c, num, out); + }; + // In-place Multiplication BN.prototype.imul = function imul(num) { - return this.clone().mulTo(num, this || _global$5); + return this.clone().mulTo(num, this || _global$c); }; - BN.prototype.imuln = function imuln(num) { assert(typeof num === "number"); - assert(num < 67108864); // Carry + assert(num < 67108864); + // Carry var carry = 0; - - for (var i = 0; i < (this || _global$5).length; i++) { - var w = ((this || _global$5).words[i] | 0) * num; + for (var i = 0; i < (this || _global$c).length; i++) { + var w = ((this || _global$c).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum carry += lo >>> 26; - (this || _global$5).words[i] = lo & 67108863; + (this || _global$c).words[i] = lo & 67108863; } - if (carry !== 0) { - (this || _global$5).words[i] = carry; - (this || _global$5).length++; + (this || _global$c).words[i] = carry; + (this || _global$c).length++; } - - return this || _global$5; + return this || _global$c; }; - BN.prototype.muln = function muln(num) { return this.clone().imuln(num); - }; // `this` * `this` - + }; + // `this` * `this` BN.prototype.sqr = function sqr() { - return this.mul(this || _global$5); - }; // `this` * `this` in-place - + return this.mul(this || _global$c); + }; + // `this` * `this` in-place BN.prototype.isqr = function isqr() { return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) - + }; + // Math.pow(`this`, `num`) BN.prototype.pow = function pow(num) { var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes - - var res = this || _global$5; + if (w.length === 0) return new BN(1); + // Skip leading zeroes + var res = this || _global$c; for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; } - if (++i < w.length) { for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { if (w[i] === 0) continue; res = res.mul(q); } } - return res; - }; // Shift-left in-place - + }; + // Shift-left in-place BN.prototype.iushln = function iushln(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; var carryMask = 67108863 >>> 26 - r << 26 - r; var i; - if (r !== 0) { var carry = 0; - - for (i = 0; i < (this || _global$5).length; i++) { - var newCarry = (this || _global$5).words[i] & carryMask; - var c = ((this || _global$5).words[i] | 0) - newCarry << r; - (this || _global$5).words[i] = c | carry; + for (i = 0; i < (this || _global$c).length; i++) { + var newCarry = (this || _global$c).words[i] & carryMask; + var c = ((this || _global$c).words[i] | 0) - newCarry << r; + (this || _global$c).words[i] = c | carry; carry = newCarry >>> 26 - r; } - if (carry) { - (this || _global$5).words[i] = carry; - (this || _global$5).length++; + (this || _global$c).words[i] = carry; + (this || _global$c).length++; } } - if (s !== 0) { - for (i = (this || _global$5).length - 1; i >= 0; i--) { - (this || _global$5).words[i + s] = (this || _global$5).words[i]; + for (i = (this || _global$c).length - 1; i >= 0; i--) { + (this || _global$c).words[i + s] = (this || _global$c).words[i]; } - for (i = 0; i < s; i++) { - (this || _global$5).words[i] = 0; + (this || _global$c).words[i] = 0; } - - (this || _global$5).length += s; + (this || _global$c).length += s; } - return this.strip(); }; - BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me - assert((this || _global$5).negative === 0); + assert((this || _global$c).negative === 0); return this.iushln(bits); - }; // Shift-right in-place + }; + + // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes // NOTE: if `extended` is present - it will be filled with destroyed bits - - BN.prototype.iushrn = function iushrn(bits, hint, extended) { assert(typeof bits === "number" && bits >= 0); var h; - if (hint) { h = (hint - hint % 26) / 26; } else { h = 0; } - var r = bits % 26; - var s = Math.min((bits - r) / 26, (this || _global$5).length); + var s = Math.min((bits - r) / 26, (this || _global$c).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; - h = Math.max(0, h); // Extended mode, copy masked part + h = Math.max(0, h); + // Extended mode, copy masked part if (maskedWords) { for (var i = 0; i < s; i++) { - maskedWords.words[i] = (this || _global$5).words[i]; + maskedWords.words[i] = (this || _global$c).words[i]; } - maskedWords.length = s; } - - if (s === 0) ; else if ((this || _global$5).length > s) { - (this || _global$5).length -= s; - - for (i = 0; i < (this || _global$5).length; i++) { - (this || _global$5).words[i] = (this || _global$5).words[i + s]; + if (s === 0) ; else if ((this || _global$c).length > s) { + (this || _global$c).length -= s; + for (i = 0; i < (this || _global$c).length; i++) { + (this || _global$c).words[i] = (this || _global$c).words[i + s]; } } else { - (this || _global$5).words[0] = 0; - (this || _global$5).length = 1; + (this || _global$c).words[0] = 0; + (this || _global$c).length = 1; } - var carry = 0; - - for (i = (this || _global$5).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { - var word = (this || _global$5).words[i] | 0; - (this || _global$5).words[i] = carry << 26 - r | word >>> r; + for (i = (this || _global$c).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { + var word = (this || _global$c).words[i] | 0; + (this || _global$c).words[i] = carry << 26 - r | word >>> r; carry = word & mask; - } // Push carried bits as a mask - + } + // Push carried bits as a mask if (maskedWords && carry !== 0) { maskedWords.words[maskedWords.length++] = carry; } - - if ((this || _global$5).length === 0) { - (this || _global$5).words[0] = 0; - (this || _global$5).length = 1; + if ((this || _global$c).length === 0) { + (this || _global$c).words[0] = 0; + (this || _global$c).length = 1; } - return this.strip(); }; - BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me - assert((this || _global$5).negative === 0); + assert((this || _global$c).negative === 0); return this.iushrn(bits, hint, extended); - }; // Shift-left - + }; + // Shift-left BN.prototype.shln = function shln(bits) { return this.clone().ishln(bits); }; - BN.prototype.ushln = function ushln(bits) { return this.clone().iushln(bits); - }; // Shift-right - + }; + // Shift-right BN.prototype.shrn = function shrn(bits) { return this.clone().ishrn(bits); }; - BN.prototype.ushrn = function ushrn(bits) { return this.clone().iushrn(bits); - }; // Test if n bit is set - + }; + // Test if n bit is set BN.prototype.testn = function testn(bit) { assert(typeof bit === "number" && bit >= 0); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$5).length <= s) return false; // Check bit and return + // Fast case: bit is much higher than all existing words + if ((this || _global$c).length <= s) return false; - var w = (this || _global$5).words[s]; + // Check bit and return + var w = (this || _global$c).words[s]; return !!(w & q); - }; // Return only lowers bits of number (in-place) - + }; + // Return only lowers bits of number (in-place) BN.prototype.imaskn = function imaskn(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; - assert((this || _global$5).negative === 0, "imaskn works only with positive numbers"); - - if ((this || _global$5).length <= s) { - return this || _global$5; + assert((this || _global$c).negative === 0, "imaskn works only with positive numbers"); + if ((this || _global$c).length <= s) { + return this || _global$c; } - if (r !== 0) { s++; } - - (this || _global$5).length = Math.min(s, (this || _global$5).length); - + (this || _global$c).length = Math.min(s, (this || _global$c).length); if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; - (this || _global$5).words[(this || _global$5).length - 1] &= mask; + (this || _global$c).words[(this || _global$c).length - 1] &= mask; } - return this.strip(); - }; // Return only lowers bits of number - + }; + // Return only lowers bits of number BN.prototype.maskn = function maskn(bits) { return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` - + }; + // Add plain number `num` to `this` BN.prototype.iaddn = function iaddn(num) { assert(typeof num === "number"); assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + if (num < 0) return this.isubn(-num); - if ((this || _global$5).negative !== 0) { - if ((this || _global$5).length === 1 && ((this || _global$5).words[0] | 0) < num) { - (this || _global$5).words[0] = num - ((this || _global$5).words[0] | 0); - (this || _global$5).negative = 0; - return this || _global$5; + // Possible sign change + if ((this || _global$c).negative !== 0) { + if ((this || _global$c).length === 1 && ((this || _global$c).words[0] | 0) < num) { + (this || _global$c).words[0] = num - ((this || _global$c).words[0] | 0); + (this || _global$c).negative = 0; + return this || _global$c; } - - (this || _global$5).negative = 0; + (this || _global$c).negative = 0; this.isubn(num); - (this || _global$5).negative = 1; - return this || _global$5; - } // Add without checks - + (this || _global$c).negative = 1; + return this || _global$c; + } + // Add without checks return this._iaddn(num); }; - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$5).words[0] += num; // Carry + (this || _global$c).words[0] += num; - for (var i = 0; i < (this || _global$5).length && (this || _global$5).words[i] >= 67108864; i++) { - (this || _global$5).words[i] -= 67108864; - - if (i === (this || _global$5).length - 1) { - (this || _global$5).words[i + 1] = 1; + // Carry + for (var i = 0; i < (this || _global$c).length && (this || _global$c).words[i] >= 67108864; i++) { + (this || _global$c).words[i] -= 67108864; + if (i === (this || _global$c).length - 1) { + (this || _global$c).words[i + 1] = 1; } else { - (this || _global$5).words[i + 1]++; + (this || _global$c).words[i + 1]++; } } + (this || _global$c).length = Math.max((this || _global$c).length, i + 1); + return this || _global$c; + }; - (this || _global$5).length = Math.max((this || _global$5).length, i + 1); - return this || _global$5; - }; // Subtract plain number `num` from `this` - - + // Subtract plain number `num` from `this` BN.prototype.isubn = function isubn(num) { assert(typeof num === "number"); assert(num < 67108864); if (num < 0) return this.iaddn(-num); - - if ((this || _global$5).negative !== 0) { - (this || _global$5).negative = 0; + if ((this || _global$c).negative !== 0) { + (this || _global$c).negative = 0; this.iaddn(num); - (this || _global$5).negative = 1; - return this || _global$5; + (this || _global$c).negative = 1; + return this || _global$c; } - - (this || _global$5).words[0] -= num; - - if ((this || _global$5).length === 1 && (this || _global$5).words[0] < 0) { - (this || _global$5).words[0] = -(this || _global$5).words[0]; - (this || _global$5).negative = 1; + (this || _global$c).words[0] -= num; + if ((this || _global$c).length === 1 && (this || _global$c).words[0] < 0) { + (this || _global$c).words[0] = -(this || _global$c).words[0]; + (this || _global$c).negative = 1; } else { // Carry - for (var i = 0; i < (this || _global$5).length && (this || _global$5).words[i] < 0; i++) { - (this || _global$5).words[i] += 67108864; - (this || _global$5).words[i + 1] -= 1; + for (var i = 0; i < (this || _global$c).length && (this || _global$c).words[i] < 0; i++) { + (this || _global$c).words[i] += 67108864; + (this || _global$c).words[i + 1] -= 1; } } - return this.strip(); }; - BN.prototype.addn = function addn(num) { return this.clone().iaddn(num); }; - BN.prototype.subn = function subn(num) { return this.clone().isubn(num); }; - BN.prototype.iabs = function iabs() { - (this || _global$5).negative = 0; - return this || _global$5; + (this || _global$c).negative = 0; + return this || _global$c; }; - BN.prototype.abs = function abs() { return this.clone().iabs(); }; - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { var len = num.length + shift; var i; - this._expand(len); - var w; var carry = 0; - for (i = 0; i < num.length; i++) { - w = ((this || _global$5).words[i + shift] | 0) + carry; + w = ((this || _global$c).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; w -= right & 67108863; carry = (w >> 26) - (right / 67108864 | 0); - (this || _global$5).words[i + shift] = w & 67108863; + (this || _global$c).words[i + shift] = w & 67108863; } - - for (; i < (this || _global$5).length - shift; i++) { - w = ((this || _global$5).words[i + shift] | 0) + carry; + for (; i < (this || _global$c).length - shift; i++) { + w = ((this || _global$c).words[i + shift] | 0) + carry; carry = w >> 26; - (this || _global$5).words[i + shift] = w & 67108863; + (this || _global$c).words[i + shift] = w & 67108863; } + if (carry === 0) return this.strip(); - if (carry === 0) return this.strip(); // Subtraction overflow - + // Subtraction overflow assert(carry === -1); carry = 0; - - for (i = 0; i < (this || _global$5).length; i++) { - w = -((this || _global$5).words[i] | 0) + carry; + for (i = 0; i < (this || _global$c).length; i++) { + w = -((this || _global$c).words[i] | 0) + carry; carry = w >> 26; - (this || _global$5).words[i] = w & 67108863; + (this || _global$c).words[i] = w & 67108863; } - - (this || _global$5).negative = 1; + (this || _global$c).negative = 1; return this.strip(); }; - BN.prototype._wordDiv = function _wordDiv(num, mode) { - var shift = (this || _global$5).length - num.length; + var shift = (this || _global$c).length - num.length; var a = this.clone(); - var b = num; // Normalize + var b = num; + // Normalize var bhi = b.words[b.length - 1] | 0; - var bhiBits = this._countBits(bhi); - shift = 26 - bhiBits; - if (shift !== 0) { b = b.ushln(shift); a.iushln(shift); bhi = b.words[b.length - 1] | 0; - } // Initialize quotient - + } + // Initialize quotient var m = a.length - b.length; var q; - if (mode !== "mod") { q = new BN(null); q.length = m + 1; q.words = new Array(q.length); - for (var i = 0; i < q.length; i++) { q.words[i] = 0; } } - var diff = a.clone()._ishlnsubmul(b, 1, m); - if (diff.negative === 0) { a = diff; - if (q) { q.words[m] = 1; } } - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) qj = Math.min(qj / bhi | 0, 67108863); - a._ishlnsubmul(b, qj, j); - while (a.negative !== 0) { qj--; a.negative = 0; - a._ishlnsubmul(b, 1, j); - if (!a.isZero()) { a.negative ^= 1; } } - if (q) { q.words[j] = qj; } } - if (q) { q.strip(); } + a.strip(); - a.strip(); // Denormalize - + // Denormalize if (mode !== "div" && shift !== 0) { a.iushrn(shift); } - return { div: q || null, mod: a }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, // to `div` to request div only, or be absent to // request both div & mod // 2) `positive` is true if unsigned mod is requested - - BN.prototype.divmod = function divmod(num, mode, positive) { assert(!num.isZero()); - if (this.isZero()) { return { div: new BN(0), mod: new BN(0) }; } - var div, mod, res; - - if ((this || _global$5).negative !== 0 && num.negative === 0) { + if ((this || _global$c).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); - if (mode !== "mod") { div = res.div.neg(); } - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.iadd(num); } } - return { div: div, mod: mod }; } - - if ((this || _global$5).negative === 0 && num.negative !== 0) { + if ((this || _global$c).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); - if (mode !== "mod") { div = res.div.neg(); } - return { div: div, mod: res.mod }; } - - if (((this || _global$5).negative & num.negative) !== 0) { + if (((this || _global$c).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.isub(num); } } - return { div: res.div, mod: mod }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + } + // Both numbers are positive at this point - if (num.length > (this || _global$5).length || this.cmp(num) < 0) { + // Strip both numbers to approximate shift value + if (num.length > (this || _global$c).length || this.cmp(num) < 0) { return { div: new BN(0), - mod: this || _global$5 + mod: this || _global$c }; - } // Very short reduction - + } + // Very short reduction if (num.length === 1) { if (mode === "div") { return { @@ -64918,144 +100233,125 @@ function dew$x() { mod: null }; } - if (mode === "mod") { return { div: null, mod: new BN(this.modn(num.words[0])) }; } - return { div: this.divn(num.words[0]), mod: new BN(this.modn(num.words[0])) }; } - return this._wordDiv(num, mode); - }; // Find `this` / `num` - + }; + // Find `this` / `num` BN.prototype.div = function div(num) { return this.divmod(num, "div", false).div; - }; // Find `this` % `num` - + }; + // Find `this` % `num` BN.prototype.mod = function mod(num) { return this.divmod(num, "mod", false).mod; }; - BN.prototype.umod = function umod(num) { return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) - + }; + // Find Round(`this` / `num`) BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + var dm = this.divmod(num); + // Fast case - exact division if (dm.mod.isZero()) return dm.div; var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; var half = num.ushrn(1); var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + var cmp = mod.cmp(half); - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + // Round up return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); }; - BN.prototype.modn = function modn(num) { assert(num <= 67108863); var p = (1 << 26) % num; var acc = 0; - - for (var i = (this || _global$5).length - 1; i >= 0; i--) { - acc = (p * acc + ((this || _global$5).words[i] | 0)) % num; + for (var i = (this || _global$c).length - 1; i >= 0; i--) { + acc = (p * acc + ((this || _global$c).words[i] | 0)) % num; } - return acc; - }; // In-place division by number - + }; + // In-place division by number BN.prototype.idivn = function idivn(num) { assert(num <= 67108863); var carry = 0; - - for (var i = (this || _global$5).length - 1; i >= 0; i--) { - var w = ((this || _global$5).words[i] | 0) + carry * 67108864; - (this || _global$5).words[i] = w / num | 0; + for (var i = (this || _global$c).length - 1; i >= 0; i--) { + var w = ((this || _global$c).words[i] | 0) + carry * 67108864; + (this || _global$c).words[i] = w / num | 0; carry = w % num; } - return this.strip(); }; - BN.prototype.divn = function divn(num) { return this.clone().idivn(num); }; - BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); - var x = this || _global$5; + var x = this || _global$c; var y = p.clone(); - if (x.negative !== 0) { x = x.umod(p); } else { x = x.clone(); - } // A * x + B * y = x - + } + // A * x + B * y = x var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + var B = new BN(0); + // C * x + D * y = y var C = new BN(0); var D = new BN(1); var g = 0; - while (x.isEven() && y.isEven()) { x.iushrn(1); y.iushrn(1); ++g; } - var yp = y.clone(); var xp = x.clone(); - while (!x.isZero()) { for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { x.iushrn(i); - while (i-- > 0) { if (A.isOdd() || B.isOdd()) { A.iadd(yp); B.isub(xp); } - A.iushrn(1); B.iushrn(1); } } - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { y.iushrn(j); - while (j-- > 0) { if (C.isOdd() || D.isOdd()) { C.iadd(yp); D.isub(xp); } - C.iushrn(1); D.iushrn(1); } } - if (x.cmp(y) >= 0) { x.isub(y); A.isub(C); @@ -65066,62 +100362,50 @@ function dew$x() { D.isub(B); } } - return { a: C, b: D, gcd: y.iushln(g) }; - }; // This is reduced incarnation of the binary EEA + }; + + // This is reduced incarnation of the binary EEA // above, designated to invert members of the // _prime_ fields F(p) at a maximal speed - - BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); - var a = this || _global$5; + var a = this || _global$c; var b = p.clone(); - if (a.negative !== 0) { a = a.umod(p); } else { a = a.clone(); } - var x1 = new BN(1); var x2 = new BN(0); var delta = b.clone(); - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { a.iushrn(i); - while (i-- > 0) { if (x1.isOdd()) { x1.iadd(delta); } - x1.iushrn(1); } } - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { b.iushrn(j); - while (j-- > 0) { if (x2.isOdd()) { x2.iadd(delta); } - x2.iushrn(1); } } - if (a.cmp(b) >= 0) { a.isub(b); x1.isub(x2); @@ -65130,46 +100414,38 @@ function dew$x() { x2.isub(x1); } } - var res; - if (a.cmpn(1) === 0) { res = x1; } else { res = x2; } - if (res.cmpn(0) < 0) { res.iadd(p); } - return res; }; - BN.prototype.gcd = function gcd(num) { if (this.isZero()) return num.abs(); if (num.isZero()) return this.abs(); var a = this.clone(); var b = num.clone(); a.negative = 0; - b.negative = 0; // Remove common factor of two + b.negative = 0; + // Remove common factor of two for (var shift = 0; a.isEven() && b.isEven(); shift++) { a.iushrn(1); b.iushrn(1); } - do { while (a.isEven()) { a.iushrn(1); } - while (b.isEven()) { b.iushrn(1); } - var r = a.cmp(b); - if (r < 0) { // Swap `a` and `b` to make `a` always bigger than `b` var t = a; @@ -65178,330 +100454,269 @@ function dew$x() { } else if (r === 0 || b.cmpn(1) === 0) { break; } - a.isub(b); } while (true); - return b.iushln(shift); - }; // Invert number in the field F(num) - + }; + // Invert number in the field F(num) BN.prototype.invm = function invm(num) { return this.egcd(num).a.umod(num); }; - BN.prototype.isEven = function isEven() { - return ((this || _global$5).words[0] & 1) === 0; + return ((this || _global$c).words[0] & 1) === 0; }; - BN.prototype.isOdd = function isOdd() { - return ((this || _global$5).words[0] & 1) === 1; - }; // And first word and num - + return ((this || _global$c).words[0] & 1) === 1; + }; + // And first word and num BN.prototype.andln = function andln(num) { - return (this || _global$5).words[0] & num; - }; // Increment at the bit position in-line - + return (this || _global$c).words[0] & num; + }; + // Increment at the bit position in-line BN.prototype.bincn = function bincn(bit) { assert(typeof bit === "number"); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$5).length <= s) { + // Fast case: bit is much higher than all existing words + if ((this || _global$c).length <= s) { this._expand(s + 1); + (this || _global$c).words[s] |= q; + return this || _global$c; + } - (this || _global$5).words[s] |= q; - return this || _global$5; - } // Add bit and propagate, if needed - - + // Add bit and propagate, if needed var carry = q; - - for (var i = s; carry !== 0 && i < (this || _global$5).length; i++) { - var w = (this || _global$5).words[i] | 0; + for (var i = s; carry !== 0 && i < (this || _global$c).length; i++) { + var w = (this || _global$c).words[i] | 0; w += carry; carry = w >>> 26; w &= 67108863; - (this || _global$5).words[i] = w; + (this || _global$c).words[i] = w; } - if (carry !== 0) { - (this || _global$5).words[i] = carry; - (this || _global$5).length++; + (this || _global$c).words[i] = carry; + (this || _global$c).length++; } - - return this || _global$5; + return this || _global$c; }; - BN.prototype.isZero = function isZero() { - return (this || _global$5).length === 1 && (this || _global$5).words[0] === 0; + return (this || _global$c).length === 1 && (this || _global$c).words[0] === 0; }; - BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; - if ((this || _global$5).negative !== 0 && !negative) return -1; - if ((this || _global$5).negative === 0 && negative) return 1; + if ((this || _global$c).negative !== 0 && !negative) return -1; + if ((this || _global$c).negative === 0 && negative) return 1; this.strip(); var res; - - if ((this || _global$5).length > 1) { + if ((this || _global$c).length > 1) { res = 1; } else { if (negative) { num = -num; } - assert(num <= 67108863, "Number is too big"); - var w = (this || _global$5).words[0] | 0; + var w = (this || _global$c).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - - if ((this || _global$5).negative !== 0) return -res | 0; + if ((this || _global$c).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: + }; + + // Compare two numbers and return: // 1 - if `this` > `num` // 0 - if `this` == `num` // -1 - if `this` < `num` - - BN.prototype.cmp = function cmp(num) { - if ((this || _global$5).negative !== 0 && num.negative === 0) return -1; - if ((this || _global$5).negative === 0 && num.negative !== 0) return 1; + if ((this || _global$c).negative !== 0 && num.negative === 0) return -1; + if ((this || _global$c).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); - if ((this || _global$5).negative !== 0) return -res | 0; + if ((this || _global$c).negative !== 0) return -res | 0; return res; - }; // Unsigned comparison - + }; + // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign - if ((this || _global$5).length > num.length) return 1; - if ((this || _global$5).length < num.length) return -1; + if ((this || _global$c).length > num.length) return 1; + if ((this || _global$c).length < num.length) return -1; var res = 0; - - for (var i = (this || _global$5).length - 1; i >= 0; i--) { - var a = (this || _global$5).words[i] | 0; + for (var i = (this || _global$c).length - 1; i >= 0; i--) { + var a = (this || _global$c).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; - if (a < b) { res = -1; } else if (a > b) { res = 1; } - break; } - return res; }; - BN.prototype.gtn = function gtn(num) { return this.cmpn(num) === 1; }; - BN.prototype.gt = function gt(num) { return this.cmp(num) === 1; }; - BN.prototype.gten = function gten(num) { return this.cmpn(num) >= 0; }; - BN.prototype.gte = function gte(num) { return this.cmp(num) >= 0; }; - BN.prototype.ltn = function ltn(num) { return this.cmpn(num) === -1; }; - BN.prototype.lt = function lt(num) { return this.cmp(num) === -1; }; - BN.prototype.lten = function lten(num) { return this.cmpn(num) <= 0; }; - BN.prototype.lte = function lte(num) { return this.cmp(num) <= 0; }; - BN.prototype.eqn = function eqn(num) { return this.cmpn(num) === 0; }; - BN.prototype.eq = function eq(num) { return this.cmp(num) === 0; - }; // + }; + + // // A reduce context, could be using montgomery or something better, depending // on the `m` itself. // - - BN.red = function red(num) { return new Red(num); }; - BN.prototype.toRed = function toRed(ctx) { - assert(!(this || _global$5).red, "Already a number in reduction context"); - assert((this || _global$5).negative === 0, "red works only with positives"); - return ctx.convertTo(this || _global$5)._forceRed(ctx); + assert(!(this || _global$c).red, "Already a number in reduction context"); + assert((this || _global$c).negative === 0, "red works only with positives"); + return ctx.convertTo(this || _global$c)._forceRed(ctx); }; - BN.prototype.fromRed = function fromRed() { - assert((this || _global$5).red, "fromRed works only with numbers in reduction context"); - return (this || _global$5).red.convertFrom(this || _global$5); + assert((this || _global$c).red, "fromRed works only with numbers in reduction context"); + return (this || _global$c).red.convertFrom(this || _global$c); }; - BN.prototype._forceRed = function _forceRed(ctx) { - (this || _global$5).red = ctx; - return this || _global$5; + (this || _global$c).red = ctx; + return this || _global$c; }; - BN.prototype.forceRed = function forceRed(ctx) { - assert(!(this || _global$5).red, "Already a number in reduction context"); + assert(!(this || _global$c).red, "Already a number in reduction context"); return this._forceRed(ctx); }; - BN.prototype.redAdd = function redAdd(num) { - assert((this || _global$5).red, "redAdd works only with red numbers"); - return (this || _global$5).red.add(this || _global$5, num); + assert((this || _global$c).red, "redAdd works only with red numbers"); + return (this || _global$c).red.add(this || _global$c, num); }; - BN.prototype.redIAdd = function redIAdd(num) { - assert((this || _global$5).red, "redIAdd works only with red numbers"); - return (this || _global$5).red.iadd(this || _global$5, num); + assert((this || _global$c).red, "redIAdd works only with red numbers"); + return (this || _global$c).red.iadd(this || _global$c, num); }; - BN.prototype.redSub = function redSub(num) { - assert((this || _global$5).red, "redSub works only with red numbers"); - return (this || _global$5).red.sub(this || _global$5, num); + assert((this || _global$c).red, "redSub works only with red numbers"); + return (this || _global$c).red.sub(this || _global$c, num); }; - BN.prototype.redISub = function redISub(num) { - assert((this || _global$5).red, "redISub works only with red numbers"); - return (this || _global$5).red.isub(this || _global$5, num); + assert((this || _global$c).red, "redISub works only with red numbers"); + return (this || _global$c).red.isub(this || _global$c, num); }; - BN.prototype.redShl = function redShl(num) { - assert((this || _global$5).red, "redShl works only with red numbers"); - return (this || _global$5).red.shl(this || _global$5, num); + assert((this || _global$c).red, "redShl works only with red numbers"); + return (this || _global$c).red.shl(this || _global$c, num); }; - BN.prototype.redMul = function redMul(num) { - assert((this || _global$5).red, "redMul works only with red numbers"); - - (this || _global$5).red._verify2(this || _global$5, num); - - return (this || _global$5).red.mul(this || _global$5, num); + assert((this || _global$c).red, "redMul works only with red numbers"); + (this || _global$c).red._verify2(this || _global$c, num); + return (this || _global$c).red.mul(this || _global$c, num); }; - BN.prototype.redIMul = function redIMul(num) { - assert((this || _global$5).red, "redMul works only with red numbers"); - - (this || _global$5).red._verify2(this || _global$5, num); - - return (this || _global$5).red.imul(this || _global$5, num); + assert((this || _global$c).red, "redMul works only with red numbers"); + (this || _global$c).red._verify2(this || _global$c, num); + return (this || _global$c).red.imul(this || _global$c, num); }; - BN.prototype.redSqr = function redSqr() { - assert((this || _global$5).red, "redSqr works only with red numbers"); - - (this || _global$5).red._verify1(this || _global$5); - - return (this || _global$5).red.sqr(this || _global$5); + assert((this || _global$c).red, "redSqr works only with red numbers"); + (this || _global$c).red._verify1(this || _global$c); + return (this || _global$c).red.sqr(this || _global$c); }; - BN.prototype.redISqr = function redISqr() { - assert((this || _global$5).red, "redISqr works only with red numbers"); - - (this || _global$5).red._verify1(this || _global$5); - - return (this || _global$5).red.isqr(this || _global$5); - }; // Square root over p - + assert((this || _global$c).red, "redISqr works only with red numbers"); + (this || _global$c).red._verify1(this || _global$c); + return (this || _global$c).red.isqr(this || _global$c); + }; + // Square root over p BN.prototype.redSqrt = function redSqrt() { - assert((this || _global$5).red, "redSqrt works only with red numbers"); - - (this || _global$5).red._verify1(this || _global$5); - - return (this || _global$5).red.sqrt(this || _global$5); + assert((this || _global$c).red, "redSqrt works only with red numbers"); + (this || _global$c).red._verify1(this || _global$c); + return (this || _global$c).red.sqrt(this || _global$c); }; - BN.prototype.redInvm = function redInvm() { - assert((this || _global$5).red, "redInvm works only with red numbers"); - - (this || _global$5).red._verify1(this || _global$5); - - return (this || _global$5).red.invm(this || _global$5); - }; // Return negative clone of `this` % `red modulo` - + assert((this || _global$c).red, "redInvm works only with red numbers"); + (this || _global$c).red._verify1(this || _global$c); + return (this || _global$c).red.invm(this || _global$c); + }; + // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { - assert((this || _global$5).red, "redNeg works only with red numbers"); - - (this || _global$5).red._verify1(this || _global$5); - - return (this || _global$5).red.neg(this || _global$5); + assert((this || _global$c).red, "redNeg works only with red numbers"); + (this || _global$c).red._verify1(this || _global$c); + return (this || _global$c).red.neg(this || _global$c); }; - BN.prototype.redPow = function redPow(num) { - assert((this || _global$5).red && !num.red, "redPow(normalNum)"); - - (this || _global$5).red._verify1(this || _global$5); - - return (this || _global$5).red.pow(this || _global$5, num); - }; // Prime numbers with efficient reduction - + assert((this || _global$c).red && !num.red, "redPow(normalNum)"); + (this || _global$c).red._verify1(this || _global$c); + return (this || _global$c).red.pow(this || _global$c, num); + }; + // Prime numbers with efficient reduction var primes = { k256: null, p224: null, p192: null, p25519: null - }; // Pseudo-Mersenne prime + }; + // Pseudo-Mersenne prime function MPrime(name, p) { // P = 2 ^ N - K - (this || _global$5).name = name; - (this || _global$5).p = new BN(p, 16); - (this || _global$5).n = (this || _global$5).p.bitLength(); - (this || _global$5).k = new BN(1).iushln((this || _global$5).n).isub((this || _global$5).p); - (this || _global$5).tmp = this._tmp(); + (this || _global$c).name = name; + (this || _global$c).p = new BN(p, 16); + (this || _global$c).n = (this || _global$c).p.bitLength(); + (this || _global$c).k = new BN(1).iushln((this || _global$c).n).isub((this || _global$c).p); + (this || _global$c).tmp = this._tmp(); } - MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); - tmp.words = new Array(Math.ceil((this || _global$5).n / 13)); + tmp.words = new Array(Math.ceil((this || _global$c).n / 13)); return tmp; }; - MPrime.prototype.ireduce = function ireduce(num) { // Assumes that `num` is less than `P^2` // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) var r = num; var rlen; - do { - this.split(r, (this || _global$5).tmp); + this.split(r, (this || _global$c).tmp); r = this.imulK(r); - r = r.iadd((this || _global$5).tmp); + r = r.iadd((this || _global$c).tmp); rlen = r.bitLength(); - } while (rlen > (this || _global$5).n); - - var cmp = rlen < (this || _global$5).n ? -1 : r.ucmp((this || _global$5).p); - + } while (rlen > (this || _global$c).n); + var cmp = rlen < (this || _global$c).n ? -1 : r.ucmp((this || _global$c).p); if (cmp === 0) { r.words[0] = 0; r.length = 1; } else if (cmp > 0) { - r.isub((this || _global$5).p); + r.isub((this || _global$c).p); } else { if (r.strip !== undefined) { // r is BN v4 instance @@ -65511,111 +100726,88 @@ function dew$x() { r._strip(); } } - return r; }; - MPrime.prototype.split = function split(input, out) { - input.iushrn((this || _global$5).n, 0, out); + input.iushrn((this || _global$c).n, 0, out); }; - MPrime.prototype.imulK = function imulK(num) { - return num.imul((this || _global$5).k); + return num.imul((this || _global$c).k); }; - function K256() { - MPrime.call(this || _global$5, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); + MPrime.call(this || _global$c, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - inherits(K256, MPrime); - K256.prototype.split = function split(input, output) { // 256 = 9 * 26 + 22 var mask = 4194303; var outLen = Math.min(input.length, 9); - for (var i = 0; i < outLen; i++) { output.words[i] = input.words[i]; } - output.length = outLen; - if (input.length <= 9) { input.words[0] = 0; input.length = 1; return; - } // Shift by 9 limbs - + } + // Shift by 9 limbs var prev = input.words[9]; output.words[output.length++] = prev & mask; - for (i = 10; i < input.length; i++) { var next = input.words[i] | 0; input.words[i - 10] = (next & mask) << 4 | prev >>> 22; prev = next; } - prev >>>= 22; input.words[i - 10] = prev; - if (prev === 0 && input.length > 10) { input.length -= 10; } else { input.length -= 9; } }; - K256.prototype.imulK = function imulK(num) { // K = 0x1000003d1 = [ 0x40, 0x3d1 ] num.words[num.length] = 0; num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + num.length += 2; + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 var lo = 0; - for (var i = 0; i < num.length; i++) { var w = num.words[i] | 0; lo += w * 977; num.words[i] = lo & 67108863; lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction - + } + // Fast length reduction if (num.words[num.length - 1] === 0) { num.length--; - if (num.words[num.length - 1] === 0) { num.length--; } } - return num; }; - function P224() { - MPrime.call(this || _global$5, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); + MPrime.call(this || _global$c, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } - inherits(P224, MPrime); - function P192() { - MPrime.call(this || _global$5, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); + MPrime.call(this || _global$c, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } - inherits(P192, MPrime); - function P25519() { // 2 ^ 255 - 19 - MPrime.call(this || _global$5, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); + MPrime.call(this || _global$c, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } - inherits(P25519, MPrime); - P25519.prototype.imulK = function imulK(num) { // K = 0x13 var carry = 0; - for (var i = 0; i < num.length; i++) { var hi = (num.words[i] | 0) * 19 + carry; var lo = hi & 67108863; @@ -65623,20 +100815,17 @@ function dew$x() { num.words[i] = lo; carry = hi; } - if (carry !== 0) { num.words[num.length++] = carry; } - return num; - }; // Exported mostly for testing purposes, use plain name instead - + }; + // Exported mostly for testing purposes, use plain name instead BN._prime = function prime(name) { // Cached version of prime if (primes[name]) return primes[name]; var prime; - if (name === "k256") { prime = new K256(); } else if (name === "p224") { @@ -65648,176 +100837,133 @@ function dew$x() { } else { throw new Error("Unknown prime " + name); } - primes[name] = prime; return prime; - }; // + }; + + // // Base reduction engine // - - function Red(m) { if (typeof m === "string") { var prime = BN._prime(m); - - (this || _global$5).m = prime.p; - (this || _global$5).prime = prime; + (this || _global$c).m = prime.p; + (this || _global$c).prime = prime; } else { assert(m.gtn(1), "modulus must be greater than 1"); - (this || _global$5).m = m; - (this || _global$5).prime = null; + (this || _global$c).m = m; + (this || _global$c).prime = null; } } - Red.prototype._verify1 = function _verify1(a) { assert(a.negative === 0, "red works only with positives"); assert(a.red, "red works only with red numbers"); }; - Red.prototype._verify2 = function _verify2(a, b) { assert((a.negative | b.negative) === 0, "red works only with positives"); assert(a.red && a.red === b.red, "red works only with red numbers"); }; - Red.prototype.imod = function imod(a) { - if ((this || _global$5).prime) return (this || _global$5).prime.ireduce(a)._forceRed(this || _global$5); - return a.umod((this || _global$5).m)._forceRed(this || _global$5); + if ((this || _global$c).prime) return (this || _global$c).prime.ireduce(a)._forceRed(this || _global$c); + return a.umod((this || _global$c).m)._forceRed(this || _global$c); }; - Red.prototype.neg = function neg(a) { if (a.isZero()) { return a.clone(); } - - return (this || _global$5).m.sub(a)._forceRed(this || _global$5); + return (this || _global$c).m.sub(a)._forceRed(this || _global$c); }; - Red.prototype.add = function add(a, b) { this._verify2(a, b); - var res = a.add(b); - - if (res.cmp((this || _global$5).m) >= 0) { - res.isub((this || _global$5).m); + if (res.cmp((this || _global$c).m) >= 0) { + res.isub((this || _global$c).m); } - - return res._forceRed(this || _global$5); + return res._forceRed(this || _global$c); }; - Red.prototype.iadd = function iadd(a, b) { this._verify2(a, b); - var res = a.iadd(b); - - if (res.cmp((this || _global$5).m) >= 0) { - res.isub((this || _global$5).m); + if (res.cmp((this || _global$c).m) >= 0) { + res.isub((this || _global$c).m); } - return res; }; - Red.prototype.sub = function sub(a, b) { this._verify2(a, b); - var res = a.sub(b); - if (res.cmpn(0) < 0) { - res.iadd((this || _global$5).m); + res.iadd((this || _global$c).m); } - - return res._forceRed(this || _global$5); + return res._forceRed(this || _global$c); }; - Red.prototype.isub = function isub(a, b) { this._verify2(a, b); - var res = a.isub(b); - if (res.cmpn(0) < 0) { - res.iadd((this || _global$5).m); + res.iadd((this || _global$c).m); } - return res; }; - Red.prototype.shl = function shl(a, num) { this._verify1(a); - return this.imod(a.ushln(num)); }; - Red.prototype.imul = function imul(a, b) { this._verify2(a, b); - return this.imod(a.imul(b)); }; - Red.prototype.mul = function mul(a, b) { this._verify2(a, b); - return this.imod(a.mul(b)); }; - Red.prototype.isqr = function isqr(a) { return this.imul(a, a.clone()); }; - Red.prototype.sqr = function sqr(a) { return this.mul(a, a); }; - Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); + var mod3 = (this || _global$c).m.andln(3); + assert(mod3 % 2 === 1); - var mod3 = (this || _global$5).m.andln(3); - - assert(mod3 % 2 === 1); // Fast case - + // Fast case if (mod3 === 3) { - var pow = (this || _global$5).m.add(new BN(1)).iushrn(2); - + var pow = (this || _global$c).m.add(new BN(1)).iushrn(2); return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) // // Find Q and S, that Q * 2 ^ S = (P - 1) - - - var q = (this || _global$5).m.subn(1); - + var q = (this || _global$c).m.subn(1); var s = 0; - while (!q.isZero() && q.andln(1) === 0) { s++; q.iushrn(1); } - assert(!q.isZero()); - var one = new BN(1).toRed(this || _global$5); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. - - var lpow = (this || _global$5).m.subn(1).iushrn(1); - - var z = (this || _global$5).m.bitLength(); - - z = new BN(2 * z * z).toRed(this || _global$5); + var one = new BN(1).toRed(this || _global$c); + var nOne = one.redNeg(); + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. + var lpow = (this || _global$c).m.subn(1).iushrn(1); + var z = (this || _global$c).m.bitLength(); + z = new BN(2 * z * z).toRed(this || _global$c); while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); } - var c = this.pow(z, q); var r = this.pow(a, q.addn(1).iushrn(1)); var t = this.pow(a, q); var m = s; - while (t.cmp(one) !== 0) { var tmp = t; - for (var i = 0; tmp.cmp(one) !== 0; i++) { tmp = tmp.redSqr(); } - assert(i < m); var b = this.pow(c, new BN(1).iushln(m - i - 1)); r = r.redMul(b); @@ -65825,13 +100971,10 @@ function dew$x() { t = t.redMul(c); m = i; } - return r; }; - Red.prototype.invm = function invm(a) { - var inv = a._invmp((this || _global$5).m); - + var inv = a._invmp((this || _global$c).m); if (inv.negative !== 0) { inv.negative = 0; return this.imod(inv).redNeg(); @@ -65839,43 +100982,34 @@ function dew$x() { return this.imod(inv); } }; - Red.prototype.pow = function pow(a, num) { - if (num.isZero()) return new BN(1).toRed(this || _global$5); + if (num.isZero()) return new BN(1).toRed(this || _global$c); if (num.cmpn(1) === 0) return a.clone(); var windowSize = 4; var wnd = new Array(1 << windowSize); - wnd[0] = new BN(1).toRed(this || _global$5); + wnd[0] = new BN(1).toRed(this || _global$c); wnd[1] = a; - for (var i = 2; i < wnd.length; i++) { wnd[i] = this.mul(wnd[i - 1], a); } - var res = wnd[0]; var current = 0; var currentLen = 0; var start = num.bitLength() % 26; - if (start === 0) { start = 26; } - for (i = num.length - 1; i >= 0; i--) { var word = num.words[i]; - for (var j = start - 1; j >= 0; j--) { var bit = word >> j & 1; - if (res !== wnd[0]) { res = this.sqr(res); } - if (bit === 0 && current === 0) { currentLen = 0; continue; } - current <<= 1; current |= bit; currentLen++; @@ -65884,268 +101018,204 @@ function dew$x() { currentLen = 0; current = 0; } - start = 26; } - return res; }; - Red.prototype.convertTo = function convertTo(num) { - var r = num.umod((this || _global$5).m); + var r = num.umod((this || _global$c).m); return r === num ? r.clone() : r; }; - Red.prototype.convertFrom = function convertFrom(num) { var res = num.clone(); res.red = null; return res; - }; // + }; + + // // Montgomery method engine // - BN.mont = function mont(num) { return new Mont(num); }; - function Mont(m) { - Red.call(this || _global$5, m); - (this || _global$5).shift = (this || _global$5).m.bitLength(); - - if ((this || _global$5).shift % 26 !== 0) { - (this || _global$5).shift += 26 - (this || _global$5).shift % 26; + Red.call(this || _global$c, m); + (this || _global$c).shift = (this || _global$c).m.bitLength(); + if ((this || _global$c).shift % 26 !== 0) { + (this || _global$c).shift += 26 - (this || _global$c).shift % 26; } - - (this || _global$5).r = new BN(1).iushln((this || _global$5).shift); - (this || _global$5).r2 = this.imod((this || _global$5).r.sqr()); - (this || _global$5).rinv = (this || _global$5).r._invmp((this || _global$5).m); - (this || _global$5).minv = (this || _global$5).rinv.mul((this || _global$5).r).isubn(1).div((this || _global$5).m); - (this || _global$5).minv = (this || _global$5).minv.umod((this || _global$5).r); - (this || _global$5).minv = (this || _global$5).r.sub((this || _global$5).minv); + (this || _global$c).r = new BN(1).iushln((this || _global$c).shift); + (this || _global$c).r2 = this.imod((this || _global$c).r.sqr()); + (this || _global$c).rinv = (this || _global$c).r._invmp((this || _global$c).m); + (this || _global$c).minv = (this || _global$c).rinv.mul((this || _global$c).r).isubn(1).div((this || _global$c).m); + (this || _global$c).minv = (this || _global$c).minv.umod((this || _global$c).r); + (this || _global$c).minv = (this || _global$c).r.sub((this || _global$c).minv); } - inherits(Mont, Red); - Mont.prototype.convertTo = function convertTo(num) { - return this.imod(num.ushln((this || _global$5).shift)); + return this.imod(num.ushln((this || _global$c).shift)); }; - Mont.prototype.convertFrom = function convertFrom(num) { - var r = this.imod(num.mul((this || _global$5).rinv)); + var r = this.imod(num.mul((this || _global$c).rinv)); r.red = null; return r; }; - Mont.prototype.imul = function imul(a, b) { if (a.isZero() || b.isZero()) { a.words[0] = 0; a.length = 1; return a; } - var t = a.imul(b); - var c = t.maskn((this || _global$5).shift).mul((this || _global$5).minv).imaskn((this || _global$5).shift).mul((this || _global$5).m); - var u = t.isub(c).iushrn((this || _global$5).shift); + var c = t.maskn((this || _global$c).shift).mul((this || _global$c).minv).imaskn((this || _global$c).shift).mul((this || _global$c).m); + var u = t.isub(c).iushrn((this || _global$c).shift); var res = u; - - if (u.cmp((this || _global$5).m) >= 0) { - res = u.isub((this || _global$5).m); + if (u.cmp((this || _global$c).m) >= 0) { + res = u.isub((this || _global$c).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$5).m); + res = u.iadd((this || _global$c).m); } - - return res._forceRed(this || _global$5); + return res._forceRed(this || _global$c); }; - Mont.prototype.mul = function mul(a, b) { - if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$5); + if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$c); var t = a.mul(b); - var c = t.maskn((this || _global$5).shift).mul((this || _global$5).minv).imaskn((this || _global$5).shift).mul((this || _global$5).m); - var u = t.isub(c).iushrn((this || _global$5).shift); + var c = t.maskn((this || _global$c).shift).mul((this || _global$c).minv).imaskn((this || _global$c).shift).mul((this || _global$c).m); + var u = t.isub(c).iushrn((this || _global$c).shift); var res = u; - - if (u.cmp((this || _global$5).m) >= 0) { - res = u.isub((this || _global$5).m); + if (u.cmp((this || _global$c).m) >= 0) { + res = u.isub((this || _global$c).m); } else if (u.cmpn(0) < 0) { - res = u.iadd((this || _global$5).m); + res = u.iadd((this || _global$c).m); } - - return res._forceRed(this || _global$5); + return res._forceRed(this || _global$c); }; - Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R - var res = this.imod(a._invmp((this || _global$5).m).mul((this || _global$5).r2)); - return res._forceRed(this || _global$5); + var res = this.imod(a._invmp((this || _global$c).m).mul((this || _global$c).r2)); + return res._forceRed(this || _global$c); }; - })(module$2, exports$y); - + })(module$2, exports$x); return module$2.exports; } -var exports$x = {}, - _dewExec$w = false; -function dew$w() { - if (_dewExec$w) return exports$x; - _dewExec$w = true; - var process$1 = process; - var buffer$1 = buffer; - var Buffer = buffer$1.Buffer; - var safer = {}; - var key; - - for (key in buffer$1) { - if (!buffer$1.hasOwnProperty(key)) continue; - if (key === "SlowBuffer" || key === "Buffer") continue; - safer[key] = buffer$1[key]; - } - - var Safer = safer.Buffer = {}; - - for (key in Buffer) { - if (!Buffer.hasOwnProperty(key)) continue; - if (key === "allocUnsafe" || key === "allocUnsafeSlow") continue; - Safer[key] = Buffer[key]; - } - - safer.Buffer.prototype = Buffer.prototype; - - if (!Safer.from || Safer.from === Uint8Array.from) { - Safer.from = function (value, encodingOrOffset, length) { - if (typeof value === "number") { - throw new TypeError("The \"value\" argument must not be of type number. Received type " + typeof value); - } - - if (value && typeof value.length === "undefined") { - throw new TypeError("The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type " + typeof value); - } - - return Buffer(value, encodingOrOffset, length); - }; - } - - if (!Safer.alloc) { - Safer.alloc = function (size, fill, encoding) { - if (typeof size !== "number") { - throw new TypeError("The \"size\" argument must be of type number. Received type " + typeof size); - } - - if (size < 0 || size >= 2 * (1 << 30)) { - throw new RangeError("The value \"" + size + "\" is invalid for option \"size\""); - } - - var buf = Buffer(size); - - if (!fill || fill.length === 0) { - buf.fill(0); - } else if (typeof encoding === "string") { - buf.fill(fill, encoding); - } else { - buf.fill(fill); - } - - return buf; - }; +var exports$w = {}, + _dewExec$v = false; +var _global$b = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$v() { + if (_dewExec$v) return exports$w; + _dewExec$v = true; + var asn1 = dew$i(); + var inherits = dew$3I(); + var api = exports$w; + api.define = function define(name, body) { + return new Entity(name, body); + }; + function Entity(name, body) { + (this || _global$b).name = name; + (this || _global$b).body = body; + (this || _global$b).decoders = {}; + (this || _global$b).encoders = {}; } - - if (!safer.kStringMaxLength) { + Entity.prototype._createNamed = function createNamed(base) { + var named; try { - safer.kStringMaxLength = process$1.binding("buffer").kStringMaxLength; - } catch (e) {// we can't determine kStringMaxLength in environments where process.binding - // is unsupported, so let's not set it + named = exports$3K.runInThisContext("(function " + (this || _global$b).name + "(entity) {\n" + " this._initNamed(entity);\n" + "})"); + } catch (e) { + named = function (entity) { + this._initNamed(entity); + }; } - } - - if (!safer.constants) { - safer.constants = { - MAX_LENGTH: safer.kMaxLength + inherits(named, base); + named.prototype._initNamed = function initnamed(entity) { + base.call(this || _global$b, entity); }; - - if (safer.kStringMaxLength) { - safer.constants.MAX_STRING_LENGTH = safer.kStringMaxLength; - } - } - - exports$x = safer; - return exports$x; + return new named(this || _global$b); + }; + Entity.prototype._getDecoder = function _getDecoder(enc) { + enc = enc || "der"; + // Lazily create decoder + if (!(this || _global$b).decoders.hasOwnProperty(enc)) (this || _global$b).decoders[enc] = this._createNamed(asn1.decoders[enc]); + return (this || _global$b).decoders[enc]; + }; + Entity.prototype.decode = function decode(data, enc, options) { + return this._getDecoder(enc).decode(data, options); + }; + Entity.prototype._getEncoder = function _getEncoder(enc) { + enc = enc || "der"; + // Lazily create encoder + if (!(this || _global$b).encoders.hasOwnProperty(enc)) (this || _global$b).encoders[enc] = this._createNamed(asn1.encoders[enc]); + return (this || _global$b).encoders[enc]; + }; + Entity.prototype.encode = function encode(data, enc, /* internal */reporter) { + return this._getEncoder(enc).encode(data, reporter); + }; + return exports$w; } -var exports$w = {}, - _dewExec$v = false; -function dew$v() { - if (_dewExec$v) return exports$w; - _dewExec$v = true; - - const inherits = dew$2R(); - +var exports$v = {}, + _dewExec$u = false; +var _global$a = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$u() { + if (_dewExec$u) return exports$v; + _dewExec$u = true; + var inherits = dew$3I(); function Reporter(options) { - this._reporterState = { + (this || _global$a)._reporterState = { obj: null, path: [], options: options || {}, errors: [] }; } - - exports$w.Reporter = Reporter; - + exports$v.Reporter = Reporter; Reporter.prototype.isError = function isError(obj) { return obj instanceof ReporterError; }; - Reporter.prototype.save = function save() { - const state = this._reporterState; + var state = (this || _global$a)._reporterState; return { obj: state.obj, pathLen: state.path.length }; }; - Reporter.prototype.restore = function restore(data) { - const state = this._reporterState; + var state = (this || _global$a)._reporterState; state.obj = data.obj; state.path = state.path.slice(0, data.pathLen); }; - Reporter.prototype.enterKey = function enterKey(key) { - return this._reporterState.path.push(key); + return (this || _global$a)._reporterState.path.push(key); }; - Reporter.prototype.exitKey = function exitKey(index) { - const state = this._reporterState; + var state = (this || _global$a)._reporterState; state.path = state.path.slice(0, index - 1); }; - Reporter.prototype.leaveKey = function leaveKey(index, key, value) { - const state = this._reporterState; + var state = (this || _global$a)._reporterState; this.exitKey(index); if (state.obj !== null) state.obj[key] = value; }; - Reporter.prototype.path = function path() { - return this._reporterState.path.join("/"); + return (this || _global$a)._reporterState.path.join("/"); }; - Reporter.prototype.enterObject = function enterObject() { - const state = this._reporterState; - const prev = state.obj; + var state = (this || _global$a)._reporterState; + var prev = state.obj; state.obj = {}; return prev; }; - Reporter.prototype.leaveObject = function leaveObject(prev) { - const state = this._reporterState; - const now = state.obj; + var state = (this || _global$a)._reporterState; + var now = state.obj; state.obj = prev; return now; }; - Reporter.prototype.error = function error(msg) { - let err; - const state = this._reporterState; - const inherited = msg instanceof ReporterError; - + var err; + var state = (this || _global$a)._reporterState; + var inherited = msg instanceof ReporterError; if (inherited) { err = msg; } else { @@ -66153,210 +101223,163 @@ function dew$v() { return "[" + JSON.stringify(elem) + "]"; }).join(""), msg.message || msg, msg.stack); } - if (!state.options.partial) throw err; if (!inherited) state.errors.push(err); return err; }; - Reporter.prototype.wrapResult = function wrapResult(result) { - const state = this._reporterState; + var state = (this || _global$a)._reporterState; if (!state.options.partial) return result; return { result: this.isError(result) ? null : result, errors: state.errors }; }; - function ReporterError(path, msg) { - this.path = path; + (this || _global$a).path = path; this.rethrow(msg); } - inherits(ReporterError, Error); - ReporterError.prototype.rethrow = function rethrow(msg) { - this.message = msg + " at: " + (this.path || "(shallow)"); - if (Error.captureStackTrace) Error.captureStackTrace(this, ReporterError); - - if (!this.stack) { + (this || _global$a).message = msg + " at: " + ((this || _global$a).path || "(shallow)"); + if (Error.captureStackTrace) Error.captureStackTrace(this || _global$a, ReporterError); + if (!(this || _global$a).stack) { try { // IE only adds stack when thrown - throw new Error(this.message); + throw new Error((this || _global$a).message); } catch (e) { - this.stack = e.stack; + (this || _global$a).stack = e.stack; } } - - return this; + return this || _global$a; }; - - return exports$w; + return exports$v; } -var exports$v = {}, - _dewExec$u = false; -function dew$u() { - if (_dewExec$u) return exports$v; - _dewExec$u = true; - - const inherits = dew$2R(); - - const Reporter = dew$v().Reporter; - - const Buffer = dew$w().Buffer; - +var exports$u = {}, + _dewExec$t = false; +var _global$9 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$t() { + if (_dewExec$t) return exports$u; + _dewExec$t = true; + var inherits = dew$3I(); + var Reporter = dew$r().Reporter; + var Buffer = dew$3J().Buffer; function DecoderBuffer(base, options) { - Reporter.call(this, options); - + Reporter.call(this || _global$9, options); if (!Buffer.isBuffer(base)) { this.error("Input not Buffer"); return; } - - this.base = base; - this.offset = 0; - this.length = base.length; + (this || _global$9).base = base; + (this || _global$9).offset = 0; + (this || _global$9).length = base.length; } - inherits(DecoderBuffer, Reporter); - exports$v.DecoderBuffer = DecoderBuffer; - - DecoderBuffer.isDecoderBuffer = function isDecoderBuffer(data) { - if (data instanceof DecoderBuffer) { - return true; - } // Or accept compatible API - - - const isCompatible = typeof data === "object" && Buffer.isBuffer(data.base) && data.constructor.name === "DecoderBuffer" && typeof data.offset === "number" && typeof data.length === "number" && typeof data.save === "function" && typeof data.restore === "function" && typeof data.isEmpty === "function" && typeof data.readUInt8 === "function" && typeof data.skip === "function" && typeof data.raw === "function"; - return isCompatible; - }; - + exports$u.DecoderBuffer = DecoderBuffer; DecoderBuffer.prototype.save = function save() { return { - offset: this.offset, - reporter: Reporter.prototype.save.call(this) + offset: (this || _global$9).offset, + reporter: Reporter.prototype.save.call(this || _global$9) }; }; - DecoderBuffer.prototype.restore = function restore(save) { // Return skipped data - const res = new DecoderBuffer(this.base); + var res = new DecoderBuffer((this || _global$9).base); res.offset = save.offset; - res.length = this.offset; - this.offset = save.offset; - Reporter.prototype.restore.call(this, save.reporter); + res.length = (this || _global$9).offset; + (this || _global$9).offset = save.offset; + Reporter.prototype.restore.call(this || _global$9, save.reporter); return res; }; - DecoderBuffer.prototype.isEmpty = function isEmpty() { - return this.offset === this.length; + return (this || _global$9).offset === (this || _global$9).length; }; - DecoderBuffer.prototype.readUInt8 = function readUInt8(fail) { - if (this.offset + 1 <= this.length) return this.base.readUInt8(this.offset++, true);else return this.error(fail || "DecoderBuffer overrun"); + if ((this || _global$9).offset + 1 <= (this || _global$9).length) return (this || _global$9).base.readUInt8((this || _global$9).offset++, true);else return this.error(fail || "DecoderBuffer overrun"); }; - DecoderBuffer.prototype.skip = function skip(bytes, fail) { - if (!(this.offset + bytes <= this.length)) return this.error(fail || "DecoderBuffer overrun"); - const res = new DecoderBuffer(this.base); // Share reporter state - - res._reporterState = this._reporterState; - res.offset = this.offset; - res.length = this.offset + bytes; - this.offset += bytes; + if (!((this || _global$9).offset + bytes <= (this || _global$9).length)) return this.error(fail || "DecoderBuffer overrun"); + var res = new DecoderBuffer((this || _global$9).base); + + // Share reporter state + res._reporterState = (this || _global$9)._reporterState; + res.offset = (this || _global$9).offset; + res.length = (this || _global$9).offset + bytes; + (this || _global$9).offset += bytes; return res; }; - DecoderBuffer.prototype.raw = function raw(save) { - return this.base.slice(save ? save.offset : this.offset, this.length); + return (this || _global$9).base.slice(save ? save.offset : (this || _global$9).offset, (this || _global$9).length); }; - function EncoderBuffer(value, reporter) { if (Array.isArray(value)) { - this.length = 0; - this.value = value.map(function (item) { - if (!EncoderBuffer.isEncoderBuffer(item)) item = new EncoderBuffer(item, reporter); - this.length += item.length; + (this || _global$9).length = 0; + (this || _global$9).value = value.map(function (item) { + if (!(item instanceof EncoderBuffer)) item = new EncoderBuffer(item, reporter); + (this || _global$9).length += item.length; return item; - }, this); + }, this || _global$9); } else if (typeof value === "number") { if (!(0 <= value && value <= 255)) return reporter.error("non-byte EncoderBuffer value"); - this.value = value; - this.length = 1; - } else if (typeof value === "string") { - this.value = value; - this.length = Buffer.byteLength(value); - } else if (Buffer.isBuffer(value)) { - this.value = value; - this.length = value.length; - } else { - return reporter.error("Unsupported type: " + typeof value); - } - } - - exports$v.EncoderBuffer = EncoderBuffer; - - EncoderBuffer.isEncoderBuffer = function isEncoderBuffer(data) { - if (data instanceof EncoderBuffer) { - return true; - } // Or accept compatible API - - - const isCompatible = typeof data === "object" && data.constructor.name === "EncoderBuffer" && typeof data.length === "number" && typeof data.join === "function"; - return isCompatible; - }; - + (this || _global$9).value = value; + (this || _global$9).length = 1; + } else if (typeof value === "string") { + (this || _global$9).value = value; + (this || _global$9).length = Buffer.byteLength(value); + } else if (Buffer.isBuffer(value)) { + (this || _global$9).value = value; + (this || _global$9).length = value.length; + } else { + return reporter.error("Unsupported type: " + typeof value); + } + } + exports$u.EncoderBuffer = EncoderBuffer; EncoderBuffer.prototype.join = function join(out, offset) { - if (!out) out = Buffer.alloc(this.length); + if (!out) out = new Buffer((this || _global$9).length); if (!offset) offset = 0; - if (this.length === 0) return out; - - if (Array.isArray(this.value)) { - this.value.forEach(function (item) { + if ((this || _global$9).length === 0) return out; + if (Array.isArray((this || _global$9).value)) { + (this || _global$9).value.forEach(function (item) { item.join(out, offset); offset += item.length; }); } else { - if (typeof this.value === "number") out[offset] = this.value;else if (typeof this.value === "string") out.write(this.value, offset);else if (Buffer.isBuffer(this.value)) this.value.copy(out, offset); - offset += this.length; + if (typeof (this || _global$9).value === "number") out[offset] = (this || _global$9).value;else if (typeof (this || _global$9).value === "string") out.write((this || _global$9).value, offset);else if (Buffer.isBuffer((this || _global$9).value)) (this || _global$9).value.copy(out, offset); + offset += (this || _global$9).length; } - return out; }; - - return exports$v; + return exports$u; } -var exports$u = {}, - _dewExec$t = false; -function dew$t() { - if (_dewExec$t) return exports$u; - _dewExec$t = true; - - const Reporter = dew$v().Reporter; - - const EncoderBuffer = dew$u().EncoderBuffer; - - const DecoderBuffer = dew$u().DecoderBuffer; - - const assert = dew$2m(); // Supported tags - - - const tags = ["seq", "seqof", "set", "setof", "objid", "bool", "gentime", "utctime", "null_", "enum", "int", "objDesc", "bitstr", "bmpstr", "charstr", "genstr", "graphstr", "ia5str", "iso646str", "numstr", "octstr", "printstr", "t61str", "unistr", "utf8str", "videostr"]; // Public methods list - - const methods = ["key", "obj", "use", "optional", "explicit", "implicit", "def", "choice", "any", "contains"].concat(tags); // Overrided methods list - - const overrided = ["_peekTag", "_decodeTag", "_use", "_decodeStr", "_decodeObjid", "_decodeTime", "_decodeNull", "_decodeInt", "_decodeBool", "_decodeList", "_encodeComposite", "_encodeStr", "_encodeObjid", "_encodeTime", "_encodeNull", "_encodeInt", "_encodeBool"]; - - function Node(enc, parent, name) { - const state = {}; - this._baseState = state; - state.name = name; +var exports$t = {}, + _dewExec$s = false; +var _global$8 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$s() { + if (_dewExec$s) return exports$t; + _dewExec$s = true; + var Reporter = dew$r().Reporter; + var EncoderBuffer = dew$r().EncoderBuffer; + var DecoderBuffer = dew$r().DecoderBuffer; + var assert = dew$3h(); + + // Supported tags + var tags = ["seq", "seqof", "set", "setof", "objid", "bool", "gentime", "utctime", "null_", "enum", "int", "objDesc", "bitstr", "bmpstr", "charstr", "genstr", "graphstr", "ia5str", "iso646str", "numstr", "octstr", "printstr", "t61str", "unistr", "utf8str", "videostr"]; + + // Public methods list + var methods = ["key", "obj", "use", "optional", "explicit", "implicit", "def", "choice", "any", "contains"].concat(tags); + + // Overrided methods list + var overrided = ["_peekTag", "_decodeTag", "_use", "_decodeStr", "_decodeObjid", "_decodeTime", "_decodeNull", "_decodeInt", "_decodeBool", "_decodeList", "_encodeComposite", "_encodeStr", "_encodeObjid", "_encodeTime", "_encodeNull", "_encodeInt", "_encodeBool"]; + function Node(enc, parent) { + var state = {}; + (this || _global$8)._baseState = state; state.enc = enc; state.parent = parent || null; - state.children = null; // State + state.children = null; + // State state.tag = null; state.args = null; state.reverseArgs = null; @@ -66370,317 +101393,286 @@ function dew$t() { state["default"] = null; state.explicit = null; state.implicit = null; - state.contains = null; // Should create new instance on each method + state.contains = null; + // Should create new instance on each method if (!state.parent) { state.children = []; - this._wrap(); } } - - exports$u = Node; - const stateProps = ["enc", "parent", "children", "tag", "args", "reverseArgs", "choice", "optional", "any", "obj", "use", "alteredUse", "key", "default", "explicit", "implicit", "contains"]; - + exports$t = Node; + var stateProps = ["enc", "parent", "children", "tag", "args", "reverseArgs", "choice", "optional", "any", "obj", "use", "alteredUse", "key", "default", "explicit", "implicit", "contains"]; Node.prototype.clone = function clone() { - const state = this._baseState; - const cstate = {}; + var state = (this || _global$8)._baseState; + var cstate = {}; stateProps.forEach(function (prop) { cstate[prop] = state[prop]; }); - const res = new this.constructor(cstate.parent); + var res = new (this || _global$8).constructor(cstate.parent); res._baseState = cstate; return res; }; - Node.prototype._wrap = function wrap() { - const state = this._baseState; + var state = (this || _global$8)._baseState; methods.forEach(function (method) { - this[method] = function _wrappedMethod() { - const clone = new this.constructor(this); + (this || _global$8)[method] = function _wrappedMethod() { + var clone = new (this || _global$8).constructor(this || _global$8); state.children.push(clone); return clone[method].apply(clone, arguments); }; - }, this); + }, this || _global$8); }; - Node.prototype._init = function init(body) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.parent === null); - body.call(this); // Filter children + body.call(this || _global$8); + // Filter children state.children = state.children.filter(function (child) { - return child._baseState.parent === this; - }, this); + return child._baseState.parent === (this || _global$8); + }, this || _global$8); assert.equal(state.children.length, 1, "Root node can have only one child"); }; - Node.prototype._useArgs = function useArgs(args) { - const state = this._baseState; // Filter children and args + var state = (this || _global$8)._baseState; - const children = args.filter(function (arg) { - return arg instanceof this.constructor; - }, this); + // Filter children and args + var children = args.filter(function (arg) { + return arg instanceof (this || _global$8).constructor; + }, this || _global$8); args = args.filter(function (arg) { - return !(arg instanceof this.constructor); - }, this); - + return !(arg instanceof (this || _global$8).constructor); + }, this || _global$8); if (children.length !== 0) { assert(state.children === null); - state.children = children; // Replace parent to maintain backward link + state.children = children; + // Replace parent to maintain backward link children.forEach(function (child) { - child._baseState.parent = this; - }, this); + child._baseState.parent = this || _global$8; + }, this || _global$8); } - if (args.length !== 0) { assert(state.args === null); state.args = args; state.reverseArgs = args.map(function (arg) { if (typeof arg !== "object" || arg.constructor !== Object) return arg; - const res = {}; + var res = {}; Object.keys(arg).forEach(function (key) { if (key == (key | 0)) key |= 0; - const value = arg[key]; + var value = arg[key]; res[value] = key; }); return res; }); } - }; // + }; + + // // Overrided methods // - overrided.forEach(function (method) { Node.prototype[method] = function _overrided() { - const state = this._baseState; + var state = (this || _global$8)._baseState; throw new Error(method + " not implemented for encoding: " + state.enc); }; - }); // + }); + + // // Public methods // tags.forEach(function (tag) { Node.prototype[tag] = function _tagMethod() { - const state = this._baseState; - const args = Array.prototype.slice.call(arguments); + var state = (this || _global$8)._baseState; + var args = Array.prototype.slice.call(arguments); assert(state.tag === null); state.tag = tag; - this._useArgs(args); - - return this; + return this || _global$8; }; }); - Node.prototype.use = function use(item) { assert(item); - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.use === null); state.use = item; - return this; + return this || _global$8; }; - Node.prototype.optional = function optional() { - const state = this._baseState; + var state = (this || _global$8)._baseState; state.optional = true; - return this; + return this || _global$8; }; - Node.prototype.def = function def(val) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state["default"] === null); state["default"] = val; state.optional = true; - return this; + return this || _global$8; }; - Node.prototype.explicit = function explicit(num) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.explicit === null && state.implicit === null); state.explicit = num; - return this; + return this || _global$8; }; - Node.prototype.implicit = function implicit(num) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.explicit === null && state.implicit === null); state.implicit = num; - return this; + return this || _global$8; }; - Node.prototype.obj = function obj() { - const state = this._baseState; - const args = Array.prototype.slice.call(arguments); + var state = (this || _global$8)._baseState; + var args = Array.prototype.slice.call(arguments); state.obj = true; if (args.length !== 0) this._useArgs(args); - return this; + return this || _global$8; }; - Node.prototype.key = function key(newKey) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.key === null); state.key = newKey; - return this; + return this || _global$8; }; - Node.prototype.any = function any() { - const state = this._baseState; + var state = (this || _global$8)._baseState; state.any = true; - return this; + return this || _global$8; }; - Node.prototype.choice = function choice(obj) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.choice === null); state.choice = obj; - this._useArgs(Object.keys(obj).map(function (key) { return obj[key]; })); - - return this; + return this || _global$8; }; - Node.prototype.contains = function contains(item) { - const state = this._baseState; + var state = (this || _global$8)._baseState; assert(state.use === null); state.contains = item; - return this; - }; // + return this || _global$8; + }; + + // // Decoding // - Node.prototype._decode = function decode(input, options) { - const state = this._baseState; // Decode root node + var state = (this || _global$8)._baseState; + // Decode root node if (state.parent === null) return input.wrapResult(state.children[0]._decode(input, options)); - let result = state["default"]; - let present = true; - let prevKey = null; - if (state.key !== null) prevKey = input.enterKey(state.key); // Check if tag is there + var result = state["default"]; + var present = true; + var prevKey = null; + if (state.key !== null) prevKey = input.enterKey(state.key); + // Check if tag is there if (state.optional) { - let tag = null; + var tag = null; if (state.explicit !== null) tag = state.explicit;else if (state.implicit !== null) tag = state.implicit;else if (state.tag !== null) tag = state.tag; - if (tag === null && !state.any) { // Trial and Error - const save = input.save(); - + var save = input.save(); try { if (state.choice === null) this._decodeGeneric(state.tag, input, options);else this._decodeChoice(input, options); present = true; } catch (e) { present = false; } - input.restore(save); } else { present = this._peekTag(input, tag, state.any); if (input.isError(present)) return present; } - } // Push object on stack - + } - let prevObj; + // Push object on stack + var prevObj; if (state.obj && present) prevObj = input.enterObject(); - if (present) { // Unwrap explicit values if (state.explicit !== null) { - const explicit = this._decodeTag(input, state.explicit); - + var explicit = this._decodeTag(input, state.explicit); if (input.isError(explicit)) return explicit; input = explicit; } + var start = input.offset; - const start = input.offset; // Unwrap implicit and normal values - + // Unwrap implicit and normal values if (state.use === null && state.choice === null) { - let save; - if (state.any) save = input.save(); - - const body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any); - + if (state.any) var save = input.save(); + var body = this._decodeTag(input, state.implicit !== null ? state.implicit : state.tag, state.any); if (input.isError(body)) return body; if (state.any) result = input.raw(save);else input = body; } - if (options && options.track && state.tag !== null) options.track(input.path(), start, input.length, "tagged"); - if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, "content"); // Select proper method for tag - - if (state.any) ; else if (state.choice === null) { - result = this._decodeGeneric(state.tag, input, options); - } else { - result = this._decodeChoice(input, options); - } + if (options && options.track && state.tag !== null) options.track(input.path(), input.offset, input.length, "content"); - if (input.isError(result)) return result; // Decode children + // Select proper method for tag + if (state.any) result = result;else if (state.choice === null) result = this._decodeGeneric(state.tag, input, options);else result = this._decodeChoice(input, options); + if (input.isError(result)) return result; + // Decode children if (!state.any && state.choice === null && state.children !== null) { state.children.forEach(function decodeChildren(child) { // NOTE: We are ignoring errors here, to let parser continue with other // parts of encoded data child._decode(input, options); }); - } // Decode contained/encoded by schema, only in bit or octet strings - + } + // Decode contained/encoded by schema, only in bit or octet strings if (state.contains && (state.tag === "octstr" || state.tag === "bitstr")) { - const data = new DecoderBuffer(result); + var data = new DecoderBuffer(result); result = this._getUse(state.contains, input._reporterState.obj)._decode(data, options); } - } // Pop object - + } - if (state.obj && present) result = input.leaveObject(prevObj); // Set key + // Pop object + if (state.obj && present) result = input.leaveObject(prevObj); + // Set key if (state.key !== null && (result !== null || present === true)) input.leaveKey(prevKey, state.key, result);else if (prevKey !== null) input.exitKey(prevKey); return result; }; - Node.prototype._decodeGeneric = function decodeGeneric(tag, input, options) { - const state = this._baseState; + var state = (this || _global$8)._baseState; if (tag === "seq" || tag === "set") return null; if (tag === "seqof" || tag === "setof") return this._decodeList(input, tag, state.args[0], options);else if (/str$/.test(tag)) return this._decodeStr(input, tag, options);else if (tag === "objid" && state.args) return this._decodeObjid(input, state.args[0], state.args[1], options);else if (tag === "objid") return this._decodeObjid(input, null, null, options);else if (tag === "gentime" || tag === "utctime") return this._decodeTime(input, tag, options);else if (tag === "null_") return this._decodeNull(input, options);else if (tag === "bool") return this._decodeBool(input, options);else if (tag === "objDesc") return this._decodeStr(input, tag, options);else if (tag === "int" || tag === "enum") return this._decodeInt(input, state.args && state.args[0], options); - if (state.use !== null) { return this._getUse(state.use, input._reporterState.obj)._decode(input, options); } else { return input.error("unknown tag: " + tag); } }; - Node.prototype._getUse = function _getUse(entity, obj) { - const state = this._baseState; // Create altered use decoder if implicit is set - + var state = (this || _global$8)._baseState; + // Create altered use decoder if implicit is set state.useDecoder = this._use(entity, obj); assert(state.useDecoder._baseState.parent === null); state.useDecoder = state.useDecoder._baseState.children[0]; - if (state.implicit !== state.useDecoder._baseState.implicit) { state.useDecoder = state.useDecoder.clone(); state.useDecoder._baseState.implicit = state.implicit; } - return state.useDecoder; }; - Node.prototype._decodeChoice = function decodeChoice(input, options) { - const state = this._baseState; - let result = null; - let match = false; + var state = (this || _global$8)._baseState; + var result = null; + var match = false; Object.keys(state.choice).some(function (key) { - const save = input.save(); - const node = state.choice[key]; - + var save = input.save(); + var node = state.choice[key]; try { - const value = node._decode(input, options); - + var value = node._decode(input, options); if (input.isError(value)) return false; result = { type: key, @@ -66691,47 +101683,45 @@ function dew$t() { input.restore(save); return false; } - return true; - }, this); + }, this || _global$8); if (!match) return input.error("Choice not matched"); return result; - }; // + }; + + // // Encoding // - Node.prototype._createEncoderBuffer = function createEncoderBuffer(data) { - return new EncoderBuffer(data, this.reporter); + return new EncoderBuffer(data, (this || _global$8).reporter); }; - Node.prototype._encode = function encode(data, reporter, parent) { - const state = this._baseState; + var state = (this || _global$8)._baseState; if (state["default"] !== null && state["default"] === data) return; - - const result = this._encodeValue(data, reporter, parent); - + var result = this._encodeValue(data, reporter, parent); if (result === undefined) return; if (this._skipDefault(result, reporter, parent)) return; return result; }; - Node.prototype._encodeValue = function encode(data, reporter, parent) { - const state = this._baseState; // Decode root node + var state = (this || _global$8)._baseState; + // Decode root node if (state.parent === null) return state.children[0]._encode(data, reporter || new Reporter()); - let result = null; // Set reporter to share it with a child class + var result = null; - this.reporter = reporter; // Check if data is there + // Set reporter to share it with a child class + (this || _global$8).reporter = reporter; + // Check if data is there if (state.optional && data === undefined) { if (state["default"] !== null) data = state["default"];else return; - } // Encode children first - - - let content = null; - let primitive = false; + } + // Encode children first + var content = null; + var primitive = false; if (state.any) { // Anything that was given is translated to buffer result = this._createEncoderBuffer(data); @@ -66744,14 +101734,12 @@ function dew$t() { content = state.children.map(function (child) { if (child._baseState.tag === "null_") return child._encode(null, reporter, data); if (child._baseState.key === null) return reporter.error("Child should have a key"); - const prevKey = reporter.enterKey(child._baseState.key); + var prevKey = reporter.enterKey(child._baseState.key); if (typeof data !== "object") return reporter.error("Child expected, but input is not object"); - - const res = child._encode(data[child._baseState.key], reporter, data); - + var res = child._encode(data[child._baseState.key], reporter, data); reporter.leaveKey(prevKey); return res; - }, this).filter(function (child) { + }, this || _global$8).filter(function (child) { return child; }); content = this._createEncoderBuffer(content); @@ -66759,559 +101747,259 @@ function dew$t() { if (state.tag === "seqof" || state.tag === "setof") { // TODO(indutny): this should be thrown on DSL level if (!(state.args && state.args.length === 1)) return reporter.error("Too many args for : " + state.tag); - if (!Array.isArray(data)) return reporter.error("seqof/setof, but data is not Array"); - const child = this.clone(); - child._baseState.implicit = null; - content = this._createEncoderBuffer(data.map(function (item) { - const state = this._baseState; - return this._getUse(state.args[0], data)._encode(item, reporter); - }, child)); - } else if (state.use !== null) { - result = this._getUse(state.use, parent)._encode(data, reporter); - } else { - content = this._encodePrimitive(state.tag, data); - primitive = true; - } - } // Encode data itself - - - if (!state.any && state.choice === null) { - const tag = state.implicit !== null ? state.implicit : state.tag; - const cls = state.implicit === null ? "universal" : "context"; - - if (tag === null) { - if (state.use === null) reporter.error("Tag could be omitted only for .use()"); - } else { - if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content); - } - } // Wrap in explicit - - - if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, "context", result); - return result; - }; - - Node.prototype._encodeChoice = function encodeChoice(data, reporter) { - const state = this._baseState; - const node = state.choice[data.type]; - - if (!node) { - assert(false, data.type + " not found in " + JSON.stringify(Object.keys(state.choice))); - } - - return node._encode(data.value, reporter); - }; - - Node.prototype._encodePrimitive = function encodePrimitive(tag, data) { - const state = this._baseState; - if (/str$/.test(tag)) return this._encodeStr(data, tag);else if (tag === "objid" && state.args) return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);else if (tag === "objid") return this._encodeObjid(data, null, null);else if (tag === "gentime" || tag === "utctime") return this._encodeTime(data, tag);else if (tag === "null_") return this._encodeNull();else if (tag === "int" || tag === "enum") return this._encodeInt(data, state.args && state.reverseArgs[0]);else if (tag === "bool") return this._encodeBool(data);else if (tag === "objDesc") return this._encodeStr(data, tag);else throw new Error("Unsupported tag: " + tag); - }; - - Node.prototype._isNumstr = function isNumstr(str) { - return /^[0-9 ]*$/.test(str); - }; - - Node.prototype._isPrintstr = function isPrintstr(str) { - return /^[A-Za-z0-9 '()+,-./:=?]*$/.test(str); - }; - - return exports$u; -} - -var exports$t = {}, - _dewExec$s = false; -function dew$s() { - if (_dewExec$s) return exports$t; - _dewExec$s = true; - - // Helper - function reverse(map) { - const res = {}; - Object.keys(map).forEach(function (key) { - // Convert key to integer if it is stringified - if ((key | 0) == key) key = key | 0; - const value = map[key]; - res[value] = key; - }); - return res; - } - - exports$t.tagClass = { - 0: "universal", - 1: "application", - 2: "context", - 3: "private" - }; - exports$t.tagClassByName = reverse(exports$t.tagClass); - exports$t.tag = { - 0: "end", - 1: "bool", - 2: "int", - 3: "bitstr", - 4: "octstr", - 5: "null_", - 6: "objid", - 7: "objDesc", - 8: "external", - 9: "real", - 10: "enum", - 11: "embed", - 12: "utf8str", - 13: "relativeOid", - 16: "seq", - 17: "set", - 18: "numstr", - 19: "printstr", - 20: "t61str", - 21: "videostr", - 22: "ia5str", - 23: "utctime", - 24: "gentime", - 25: "graphstr", - 26: "iso646str", - 27: "genstr", - 28: "unistr", - 29: "charstr", - 30: "bmpstr" - }; - exports$t.tagByName = reverse(exports$t.tag); - return exports$t; -} - -var exports$s = {}, - _dewExec$r = false; -function dew$r() { - if (_dewExec$r) return exports$s; - _dewExec$r = true; - - const inherits = dew$2R(); - - const Buffer = dew$w().Buffer; - - const Node = dew$t(); // Import DER constants - - - const der = dew$s(); - - function DEREncoder(entity) { - this.enc = "der"; - this.name = entity.name; - this.entity = entity; // Construct base tree - - this.tree = new DERNode(); - - this.tree._init(entity.body); - } - - exports$s = DEREncoder; - - DEREncoder.prototype.encode = function encode(data, reporter) { - return this.tree._encode(data, reporter).join(); - }; // Tree methods - - - function DERNode(parent) { - Node.call(this, "der", parent); - } - - inherits(DERNode, Node); - - DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) { - const encodedTag = encodeTag(tag, primitive, cls, this.reporter); // Short form - - if (content.length < 128) { - const header = Buffer.alloc(2); - header[0] = encodedTag; - header[1] = content.length; - return this._createEncoderBuffer([header, content]); - } // Long form - // Count octets required to store length - - - let lenOctets = 1; - - for (let i = content.length; i >= 256; i >>= 8) lenOctets++; - - const header = Buffer.alloc(1 + 1 + lenOctets); - header[0] = encodedTag; - header[1] = 128 | lenOctets; - - for (let i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8) header[i] = j & 255; - - return this._createEncoderBuffer([header, content]); - }; - - DERNode.prototype._encodeStr = function encodeStr(str, tag) { - if (tag === "bitstr") { - return this._createEncoderBuffer([str.unused | 0, str.data]); - } else if (tag === "bmpstr") { - const buf = Buffer.alloc(str.length * 2); - - for (let i = 0; i < str.length; i++) { - buf.writeUInt16BE(str.charCodeAt(i), i * 2); - } - - return this._createEncoderBuffer(buf); - } else if (tag === "numstr") { - if (!this._isNumstr(str)) { - return this.reporter.error("Encoding of string type: numstr supports " + "only digits and space"); - } - - return this._createEncoderBuffer(str); - } else if (tag === "printstr") { - if (!this._isPrintstr(str)) { - return this.reporter.error("Encoding of string type: printstr supports " + "only latin upper and lower case letters, " + "digits, space, apostrophe, left and rigth " + "parenthesis, plus sign, comma, hyphen, " + "dot, slash, colon, equal sign, " + "question mark"); - } - - return this._createEncoderBuffer(str); - } else if (/str$/.test(tag)) { - return this._createEncoderBuffer(str); - } else if (tag === "objDesc") { - return this._createEncoderBuffer(str); - } else { - return this.reporter.error("Encoding of string type: " + tag + " unsupported"); - } - }; - - DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) { - if (typeof id === "string") { - if (!values) return this.reporter.error("string objid given, but no values map found"); - if (!values.hasOwnProperty(id)) return this.reporter.error("objid not found in values map"); - id = values[id].split(/[\s.]+/g); - - for (let i = 0; i < id.length; i++) id[i] |= 0; - } else if (Array.isArray(id)) { - id = id.slice(); - - for (let i = 0; i < id.length; i++) id[i] |= 0; - } - - if (!Array.isArray(id)) { - return this.reporter.error("objid() should be either array or string, " + "got: " + JSON.stringify(id)); - } - - if (!relative) { - if (id[1] >= 40) return this.reporter.error("Second objid identifier OOB"); - id.splice(0, 2, id[0] * 40 + id[1]); - } // Count number of octets - - - let size = 0; - - for (let i = 0; i < id.length; i++) { - let ident = id[i]; - - for (size++; ident >= 128; ident >>= 7) size++; - } - - const objid = Buffer.alloc(size); - let offset = objid.length - 1; - - for (let i = id.length - 1; i >= 0; i--) { - let ident = id[i]; - objid[offset--] = ident & 127; - - while ((ident >>= 7) > 0) objid[offset--] = 128 | ident & 127; - } - - return this._createEncoderBuffer(objid); - }; - - function two(num) { - if (num < 10) return "0" + num;else return num; - } - - DERNode.prototype._encodeTime = function encodeTime(time, tag) { - let str; - const date = new Date(time); - - if (tag === "gentime") { - str = [two(date.getUTCFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), "Z"].join(""); - } else if (tag === "utctime") { - str = [two(date.getUTCFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), "Z"].join(""); - } else { - this.reporter.error("Encoding " + tag + " time is not supported yet"); - } - - return this._encodeStr(str, "octstr"); - }; - - DERNode.prototype._encodeNull = function encodeNull() { - return this._createEncoderBuffer(""); - }; - - DERNode.prototype._encodeInt = function encodeInt(num, values) { - if (typeof num === "string") { - if (!values) return this.reporter.error("String int or enum given, but no values map"); - - if (!values.hasOwnProperty(num)) { - return this.reporter.error("Values map doesn't contain: " + JSON.stringify(num)); - } - - num = values[num]; - } // Bignum, assume big endian - - - if (typeof num !== "number" && !Buffer.isBuffer(num)) { - const numArray = num.toArray(); - - if (!num.sign && numArray[0] & 128) { - numArray.unshift(0); + if (!Array.isArray(data)) return reporter.error("seqof/setof, but data is not Array"); + var child = this.clone(); + child._baseState.implicit = null; + content = this._createEncoderBuffer(data.map(function (item) { + var state = (this || _global$8)._baseState; + return this._getUse(state.args[0], data)._encode(item, reporter); + }, child)); + } else if (state.use !== null) { + result = this._getUse(state.use, parent)._encode(data, reporter); + } else { + content = this._encodePrimitive(state.tag, data); + primitive = true; } - - num = Buffer.from(numArray); - } - - if (Buffer.isBuffer(num)) { - let size = num.length; - if (num.length === 0) size++; - const out = Buffer.alloc(size); - num.copy(out); - if (num.length === 0) out[0] = 0; - return this._createEncoderBuffer(out); } - if (num < 128) return this._createEncoderBuffer(num); - if (num < 256) return this._createEncoderBuffer([0, num]); - let size = 1; - - for (let i = num; i >= 256; i >>= 8) size++; - - const out = new Array(size); - - for (let i = out.length - 1; i >= 0; i--) { - out[i] = num & 255; - num >>= 8; + // Encode data itself + var result; + if (!state.any && state.choice === null) { + var tag = state.implicit !== null ? state.implicit : state.tag; + var cls = state.implicit === null ? "universal" : "context"; + if (tag === null) { + if (state.use === null) reporter.error("Tag could be omitted only for .use()"); + } else { + if (state.use === null) result = this._encodeComposite(tag, primitive, cls, content); + } } - if (out[0] & 128) { - out.unshift(0); + // Wrap in explicit + if (state.explicit !== null) result = this._encodeComposite(state.explicit, false, "context", result); + return result; + }; + Node.prototype._encodeChoice = function encodeChoice(data, reporter) { + var state = (this || _global$8)._baseState; + var node = state.choice[data.type]; + if (!node) { + assert(false, data.type + " not found in " + JSON.stringify(Object.keys(state.choice))); } - - return this._createEncoderBuffer(Buffer.from(out)); + return node._encode(data.value, reporter); }; - - DERNode.prototype._encodeBool = function encodeBool(value) { - return this._createEncoderBuffer(value ? 255 : 0); + Node.prototype._encodePrimitive = function encodePrimitive(tag, data) { + var state = (this || _global$8)._baseState; + if (/str$/.test(tag)) return this._encodeStr(data, tag);else if (tag === "objid" && state.args) return this._encodeObjid(data, state.reverseArgs[0], state.args[1]);else if (tag === "objid") return this._encodeObjid(data, null, null);else if (tag === "gentime" || tag === "utctime") return this._encodeTime(data, tag);else if (tag === "null_") return this._encodeNull();else if (tag === "int" || tag === "enum") return this._encodeInt(data, state.args && state.reverseArgs[0]);else if (tag === "bool") return this._encodeBool(data);else if (tag === "objDesc") return this._encodeStr(data, tag);else throw new Error("Unsupported tag: " + tag); }; - - DERNode.prototype._use = function use(entity, obj) { - if (typeof entity === "function") entity = entity(obj); - return entity._getEncoder("der").tree; + Node.prototype._isNumstr = function isNumstr(str) { + return /^[0-9 ]*$/.test(str); }; + Node.prototype._isPrintstr = function isPrintstr(str) { + return /^[A-Za-z0-9 '\(\)\+,\-\.\/:=\?]*$/.test(str); + }; + return exports$t; +} - DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) { - const state = this._baseState; - let i; - if (state["default"] === null) return false; - const data = dataBuffer.join(); - if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state["default"], reporter, parent).join(); - if (data.length !== state.defaultBuffer.length) return false; - - for (i = 0; i < data.length; i++) if (data[i] !== state.defaultBuffer[i]) return false; - - return true; - }; // Utility methods - - - function encodeTag(tag, primitive, cls, reporter) { - let res; - if (tag === "seqof") tag = "seq";else if (tag === "setof") tag = "set"; - if (der.tagByName.hasOwnProperty(tag)) res = der.tagByName[tag];else if (typeof tag === "number" && (tag | 0) === tag) res = tag;else return reporter.error("Unknown tag: " + tag); - if (res >= 31) return reporter.error("Multi-octet tag encoding unsupported"); - if (!primitive) res |= 32; - res |= der.tagClassByName[cls || "universal"] << 6; - return res; - } - +var exports$s = {}, + _dewExec$r = false; +function dew$r() { + if (_dewExec$r) return exports$s; + _dewExec$r = true; + var base = exports$s; + base.Reporter = dew$u().Reporter; + base.DecoderBuffer = dew$t().DecoderBuffer; + base.EncoderBuffer = dew$t().EncoderBuffer; + base.Node = dew$s(); return exports$s; } var exports$r = {}, - _dewExec$q = false; + _dewExec$q = false; function dew$q() { if (_dewExec$q) return exports$r; _dewExec$q = true; - - const inherits = dew$2R(); - - const DEREncoder = dew$r(); - - function PEMEncoder(entity) { - DEREncoder.call(this, entity); - this.enc = "pem"; - } - - inherits(PEMEncoder, DEREncoder); - exports$r = PEMEncoder; - - PEMEncoder.prototype.encode = function encode(data, options) { - const buf = DEREncoder.prototype.encode.call(this, data); - const p = buf.toString("base64"); - const out = ["-----BEGIN " + options.label + "-----"]; - - for (let i = 0; i < p.length; i += 64) out.push(p.slice(i, i + 64)); - - out.push("-----END " + options.label + "-----"); - return out.join("\n"); + var constants = dew$p(); + exports$r.tagClass = { + 0: "universal", + 1: "application", + 2: "context", + 3: "private" }; - + exports$r.tagClassByName = constants._reverse(exports$r.tagClass); + exports$r.tag = { + 0: "end", + 1: "bool", + 2: "int", + 3: "bitstr", + 4: "octstr", + 5: "null_", + 6: "objid", + 7: "objDesc", + 8: "external", + 9: "real", + 10: "enum", + 11: "embed", + 12: "utf8str", + 13: "relativeOid", + 16: "seq", + 17: "set", + 18: "numstr", + 19: "printstr", + 20: "t61str", + 21: "videostr", + 22: "ia5str", + 23: "utctime", + 24: "gentime", + 25: "graphstr", + 26: "iso646str", + 27: "genstr", + 28: "unistr", + 29: "charstr", + 30: "bmpstr" + }; + exports$r.tagByName = constants._reverse(exports$r.tag); return exports$r; } var exports$q = {}, - _dewExec$p = false; + _dewExec$p = false; function dew$p() { if (_dewExec$p) return exports$q; _dewExec$p = true; - const encoders = exports$q; - encoders.der = dew$r(); - encoders.pem = dew$q(); + var constants = exports$q; + + // Helper + constants._reverse = function reverse(map) { + var res = {}; + Object.keys(map).forEach(function (key) { + // Convert key to integer if it is stringified + if ((key | 0) == key) key = key | 0; + var value = map[key]; + res[value] = key; + }); + return res; + }; + constants.der = dew$q(); return exports$q; } var exports$p = {}, - _dewExec$o = false; + _dewExec$o = false; +var _global$7 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; function dew$o() { if (_dewExec$o) return exports$p; _dewExec$o = true; + var inherits = dew$3I(); + var asn1 = dew$i(); + var base = asn1.base; + var bignum = asn1.bignum; - const inherits = dew$2R(); - - const bignum = dew$x(); - - const DecoderBuffer = dew$u().DecoderBuffer; - - const Node = dew$t(); // Import DER constants - - - const der = dew$s(); - + // Import DER constants + var der = asn1.constants.der; function DERDecoder(entity) { - this.enc = "der"; - this.name = entity.name; - this.entity = entity; // Construct base tree - - this.tree = new DERNode(); + (this || _global$7).enc = "der"; + (this || _global$7).name = entity.name; + (this || _global$7).entity = entity; - this.tree._init(entity.body); + // Construct base tree + (this || _global$7).tree = new DERNode(); + (this || _global$7).tree._init(entity.body); } - exports$p = DERDecoder; - DERDecoder.prototype.decode = function decode(data, options) { - if (!DecoderBuffer.isDecoderBuffer(data)) { - data = new DecoderBuffer(data, options); - } - - return this.tree._decode(data, options); - }; // Tree methods + if (!(data instanceof base.DecoderBuffer)) data = new base.DecoderBuffer(data, options); + return (this || _global$7).tree._decode(data, options); + }; + // Tree methods function DERNode(parent) { - Node.call(this, "der", parent); + base.Node.call(this || _global$7, "der", parent); } - - inherits(DERNode, Node); - + inherits(DERNode, base.Node); DERNode.prototype._peekTag = function peekTag(buffer, tag, any) { if (buffer.isEmpty()) return false; - const state = buffer.save(); - const decodedTag = derDecodeTag(buffer, "Failed to peek tag: \"" + tag + "\""); + var state = buffer.save(); + var decodedTag = derDecodeTag(buffer, "Failed to peek tag: \"" + tag + "\""); if (buffer.isError(decodedTag)) return decodedTag; buffer.restore(state); return decodedTag.tag === tag || decodedTag.tagStr === tag || decodedTag.tagStr + "of" === tag || any; }; - DERNode.prototype._decodeTag = function decodeTag(buffer, tag, any) { - const decodedTag = derDecodeTag(buffer, "Failed to decode tag of \"" + tag + "\""); + var decodedTag = derDecodeTag(buffer, "Failed to decode tag of \"" + tag + "\""); if (buffer.isError(decodedTag)) return decodedTag; - let len = derDecodeLen(buffer, decodedTag.primitive, "Failed to get length of \"" + tag + "\""); // Failure + var len = derDecodeLen(buffer, decodedTag.primitive, "Failed to get length of \"" + tag + "\""); + // Failure if (buffer.isError(len)) return len; - if (!any && decodedTag.tag !== tag && decodedTag.tagStr !== tag && decodedTag.tagStr + "of" !== tag) { return buffer.error("Failed to match tag: \"" + tag + "\""); } + if (decodedTag.primitive || len !== null) return buffer.skip(len, "Failed to match body of: \"" + tag + "\""); - if (decodedTag.primitive || len !== null) return buffer.skip(len, "Failed to match body of: \"" + tag + "\""); // Indefinite length... find END tag - - const state = buffer.save(); - - const res = this._skipUntilEnd(buffer, "Failed to skip indefinite length body: \"" + this.tag + "\""); - + // Indefinite length... find END tag + var state = buffer.save(); + var res = this._skipUntilEnd(buffer, "Failed to skip indefinite length body: \"" + (this || _global$7).tag + "\""); if (buffer.isError(res)) return res; len = buffer.offset - state.offset; buffer.restore(state); return buffer.skip(len, "Failed to match body of: \"" + tag + "\""); }; - DERNode.prototype._skipUntilEnd = function skipUntilEnd(buffer, fail) { - for (;;) { - const tag = derDecodeTag(buffer, fail); + while (true) { + var tag = derDecodeTag(buffer, fail); if (buffer.isError(tag)) return tag; - const len = derDecodeLen(buffer, tag.primitive, fail); + var len = derDecodeLen(buffer, tag.primitive, fail); if (buffer.isError(len)) return len; - let res; - if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail); // Failure + var res; + if (tag.primitive || len !== null) res = buffer.skip(len);else res = this._skipUntilEnd(buffer, fail); + // Failure if (buffer.isError(res)) return res; if (tag.tagStr === "end") break; } }; - DERNode.prototype._decodeList = function decodeList(buffer, tag, decoder, options) { - const result = []; - + var result = []; while (!buffer.isEmpty()) { - const possibleEnd = this._peekTag(buffer, "end"); - + var possibleEnd = this._peekTag(buffer, "end"); if (buffer.isError(possibleEnd)) return possibleEnd; - const res = decoder.decode(buffer, "der", options); + var res = decoder.decode(buffer, "der", options); if (buffer.isError(res) && possibleEnd) break; result.push(res); } - return result; }; - DERNode.prototype._decodeStr = function decodeStr(buffer, tag) { if (tag === "bitstr") { - const unused = buffer.readUInt8(); + var unused = buffer.readUInt8(); if (buffer.isError(unused)) return unused; return { unused: unused, data: buffer.raw() }; } else if (tag === "bmpstr") { - const raw = buffer.raw(); + var raw = buffer.raw(); if (raw.length % 2 === 1) return buffer.error("Decoding of string type: bmpstr length mismatch"); - let str = ""; - - for (let i = 0; i < raw.length / 2; i++) { + var str = ""; + for (var i = 0; i < raw.length / 2; i++) { str += String.fromCharCode(raw.readUInt16BE(i * 2)); } - return str; } else if (tag === "numstr") { - const numstr = buffer.raw().toString("ascii"); - + var numstr = buffer.raw().toString("ascii"); if (!this._isNumstr(numstr)) { return buffer.error("Decoding of string type: " + "numstr unsupported characters"); } - return numstr; } else if (tag === "octstr") { return buffer.raw(); } else if (tag === "objDesc") { return buffer.raw(); } else if (tag === "printstr") { - const printstr = buffer.raw().toString("ascii"); - + var printstr = buffer.raw().toString("ascii"); if (!this._isPrintstr(printstr)) { return buffer.error("Decoding of string type: " + "printstr unsupported characters"); } - return printstr; } else if (/str$/.test(tag)) { return buffer.raw().toString(); @@ -67319,102 +102007,83 @@ function dew$o() { return buffer.error("Decoding of string type: " + tag + " unsupported"); } }; - DERNode.prototype._decodeObjid = function decodeObjid(buffer, values, relative) { - let result; - const identifiers = []; - let ident = 0; - let subident = 0; - + var result; + var identifiers = []; + var ident = 0; while (!buffer.isEmpty()) { - subident = buffer.readUInt8(); + var subident = buffer.readUInt8(); ident <<= 7; ident |= subident & 127; - if ((subident & 128) === 0) { identifiers.push(ident); ident = 0; } } - if (subident & 128) identifiers.push(ident); - const first = identifiers[0] / 40 | 0; - const second = identifiers[0] % 40; + var first = identifiers[0] / 40 | 0; + var second = identifiers[0] % 40; if (relative) result = identifiers;else result = [first, second].concat(identifiers.slice(1)); - if (values) { - let tmp = values[result.join(" ")]; + var tmp = values[result.join(" ")]; if (tmp === undefined) tmp = values[result.join(".")]; if (tmp !== undefined) result = tmp; } - return result; }; - DERNode.prototype._decodeTime = function decodeTime(buffer, tag) { - const str = buffer.raw().toString(); - let year; - let mon; - let day; - let hour; - let min; - let sec; - + var str = buffer.raw().toString(); if (tag === "gentime") { - year = str.slice(0, 4) | 0; - mon = str.slice(4, 6) | 0; - day = str.slice(6, 8) | 0; - hour = str.slice(8, 10) | 0; - min = str.slice(10, 12) | 0; - sec = str.slice(12, 14) | 0; + var year = str.slice(0, 4) | 0; + var mon = str.slice(4, 6) | 0; + var day = str.slice(6, 8) | 0; + var hour = str.slice(8, 10) | 0; + var min = str.slice(10, 12) | 0; + var sec = str.slice(12, 14) | 0; } else if (tag === "utctime") { - year = str.slice(0, 2) | 0; - mon = str.slice(2, 4) | 0; - day = str.slice(4, 6) | 0; - hour = str.slice(6, 8) | 0; - min = str.slice(8, 10) | 0; - sec = str.slice(10, 12) | 0; + var year = str.slice(0, 2) | 0; + var mon = str.slice(2, 4) | 0; + var day = str.slice(4, 6) | 0; + var hour = str.slice(6, 8) | 0; + var min = str.slice(8, 10) | 0; + var sec = str.slice(10, 12) | 0; if (year < 70) year = 2000 + year;else year = 1900 + year; } else { return buffer.error("Decoding " + tag + " time is not supported yet"); } - return Date.UTC(year, mon - 1, day, hour, min, sec, 0); }; - - DERNode.prototype._decodeNull = function decodeNull() { + DERNode.prototype._decodeNull = function decodeNull(buffer) { return null; }; - DERNode.prototype._decodeBool = function decodeBool(buffer) { - const res = buffer.readUInt8(); + var res = buffer.readUInt8(); if (buffer.isError(res)) return res;else return res !== 0; }; - DERNode.prototype._decodeInt = function decodeInt(buffer, values) { // Bigint, return as it is (assume big endian) - const raw = buffer.raw(); - let res = new bignum(raw); + var raw = buffer.raw(); + var res = new bignum(raw); if (values) res = values[res.toString(10)] || res; return res; }; - DERNode.prototype._use = function use(entity, obj) { if (typeof entity === "function") entity = entity(obj); return entity._getDecoder("der").tree; - }; // Utility methods + }; + // Utility methods function derDecodeTag(buf, fail) { - let tag = buf.readUInt8(fail); + var tag = buf.readUInt8(fail); if (buf.isError(tag)) return tag; - const cls = der.tagClass[tag >> 6]; - const primitive = (tag & 32) === 0; // Multi-octet tag - load + var cls = der.tagClass[tag >> 6]; + var primitive = (tag & 32) === 0; + // Multi-octet tag - load if ((tag & 31) === 31) { - let oct = tag; + var oct = tag; tag = 0; - while ((oct & 128) === 128) { oct = buf.readUInt8(fail); if (buf.isError(oct)) return oct; @@ -67424,8 +102093,7 @@ function dew$o() { } else { tag &= 31; } - - const tagStr = der.tag[tag]; + var tagStr = der.tag[tag]; return { cls: cls, primitive: primitive, @@ -67433,68 +102101,59 @@ function dew$o() { tagStr: tagStr }; } - function derDecodeLen(buf, primitive, fail) { - let len = buf.readUInt8(fail); - if (buf.isError(len)) return len; // Indefinite form + var len = buf.readUInt8(fail); + if (buf.isError(len)) return len; - if (!primitive && len === 128) return null; // Definite form + // Indefinite form + if (!primitive && len === 128) return null; + // Definite form if ((len & 128) === 0) { // Short form return len; - } // Long form - + } - const num = len & 127; + // Long form + var num = len & 127; if (num > 4) return buf.error("length octect is too long"); len = 0; - - for (let i = 0; i < num; i++) { + for (var i = 0; i < num; i++) { len <<= 8; - const j = buf.readUInt8(fail); + var j = buf.readUInt8(fail); if (buf.isError(j)) return j; len |= j; } - return len; } - return exports$p; } var exports$o = {}, - _dewExec$n = false; + _dewExec$n = false; +var _global$6 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; function dew$n() { if (_dewExec$n) return exports$o; _dewExec$n = true; - - const inherits = dew$2R(); - - const Buffer = dew$w().Buffer; - - const DERDecoder = dew$o(); - + var inherits = dew$3I(); + var Buffer = dew$3J().Buffer; + var DERDecoder = dew$o(); function PEMDecoder(entity) { - DERDecoder.call(this, entity); - this.enc = "pem"; + DERDecoder.call(this || _global$6, entity); + (this || _global$6).enc = "pem"; } - inherits(PEMDecoder, DERDecoder); exports$o = PEMDecoder; - PEMDecoder.prototype.decode = function decode(data, options) { - const lines = data.toString().split(/[\r\n]+/g); - const label = options.label.toUpperCase(); - const re = /^-----(BEGIN|END) ([^-]+)-----$/; - let start = -1; - let end = -1; - - for (let i = 0; i < lines.length; i++) { - const match = lines[i].match(re); + var lines = data.toString().split(/[\r\n]+/g); + var label = options.label.toUpperCase(); + var re = /^-----(BEGIN|END) ([^-]+)-----$/; + var start = -1; + var end = -1; + for (var i = 0; i < lines.length; i++) { + var match = lines[i].match(re); if (match === null) continue; if (match[2] !== label) continue; - if (start === -1) { if (match[1] !== "BEGIN") break; start = i; @@ -67504,155 +102163,287 @@ function dew$n() { break; } } - if (start === -1 || end === -1) throw new Error("PEM section not found for: " + label); - const base64 = lines.slice(start + 1, end).join(""); // Remove excessive symbols - - base64.replace(/[^a-z0-9+/=]+/gi, ""); - const input = Buffer.from(base64, "base64"); - return DERDecoder.prototype.decode.call(this, input, options); + var base64 = lines.slice(start + 1, end).join(""); + // Remove excessive symbols + base64.replace(/[^a-z0-9\+\/=]+/gi, ""); + var input = new Buffer(base64, "base64"); + return DERDecoder.prototype.decode.call(this || _global$6, input, options); }; - return exports$o; } var exports$n = {}, - _dewExec$m = false; + _dewExec$m = false; function dew$m() { if (_dewExec$m) return exports$n; _dewExec$m = true; - const decoders = exports$n; + var decoders = exports$n; decoders.der = dew$o(); decoders.pem = dew$n(); return exports$n; } var exports$m = {}, - _dewExec$l = false; + _dewExec$l = false; +var _global$5 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; function dew$l() { if (_dewExec$l) return exports$m; _dewExec$l = true; + var inherits = dew$3I(); + var Buffer = dew$3J().Buffer; + var asn1 = dew$i(); + var base = asn1.base; - const encoders = dew$p(); - - const decoders = dew$m(); - - const inherits = dew$2R(); - - const api = exports$m; + // Import DER constants + var der = asn1.constants.der; + function DEREncoder(entity) { + (this || _global$5).enc = "der"; + (this || _global$5).name = entity.name; + (this || _global$5).entity = entity; - api.define = function define(name, body) { - return new Entity(name, body); + // Construct base tree + (this || _global$5).tree = new DERNode(); + (this || _global$5).tree._init(entity.body); + } + exports$m = DEREncoder; + DEREncoder.prototype.encode = function encode(data, reporter) { + return (this || _global$5).tree._encode(data, reporter).join(); }; - function Entity(name, body) { - this.name = name; - this.body = body; - this.decoders = {}; - this.encoders = {}; - } + // Tree methods - Entity.prototype._createNamed = function createNamed(Base) { - const name = this.name; + function DERNode(parent) { + base.Node.call(this || _global$5, "der", parent); + } + inherits(DERNode, base.Node); + DERNode.prototype._encodeComposite = function encodeComposite(tag, primitive, cls, content) { + var encodedTag = encodeTag(tag, primitive, cls, (this || _global$5).reporter); - function Generated(entity) { - this._initNamed(entity, name); + // Short form + if (content.length < 128) { + var header = new Buffer(2); + header[0] = encodedTag; + header[1] = content.length; + return this._createEncoderBuffer([header, content]); } - inherits(Generated, Base); - - Generated.prototype._initNamed = function _initNamed(entity, name) { - Base.call(this, entity, name); - }; - - return new Generated(this); + // Long form + // Count octets required to store length + var lenOctets = 1; + for (var i = content.length; i >= 256; i >>= 8) lenOctets++; + var header = new Buffer(1 + 1 + lenOctets); + header[0] = encodedTag; + header[1] = 128 | lenOctets; + for (var i = 1 + lenOctets, j = content.length; j > 0; i--, j >>= 8) header[i] = j & 255; + return this._createEncoderBuffer([header, content]); }; - - Entity.prototype._getDecoder = function _getDecoder(enc) { - enc = enc || "der"; // Lazily create decoder - - if (!this.decoders.hasOwnProperty(enc)) this.decoders[enc] = this._createNamed(decoders[enc]); - return this.decoders[enc]; + DERNode.prototype._encodeStr = function encodeStr(str, tag) { + if (tag === "bitstr") { + return this._createEncoderBuffer([str.unused | 0, str.data]); + } else if (tag === "bmpstr") { + var buf = new Buffer(str.length * 2); + for (var i = 0; i < str.length; i++) { + buf.writeUInt16BE(str.charCodeAt(i), i * 2); + } + return this._createEncoderBuffer(buf); + } else if (tag === "numstr") { + if (!this._isNumstr(str)) { + return (this || _global$5).reporter.error("Encoding of string type: numstr supports " + "only digits and space"); + } + return this._createEncoderBuffer(str); + } else if (tag === "printstr") { + if (!this._isPrintstr(str)) { + return (this || _global$5).reporter.error("Encoding of string type: printstr supports " + "only latin upper and lower case letters, " + "digits, space, apostrophe, left and rigth " + "parenthesis, plus sign, comma, hyphen, " + "dot, slash, colon, equal sign, " + "question mark"); + } + return this._createEncoderBuffer(str); + } else if (/str$/.test(tag)) { + return this._createEncoderBuffer(str); + } else if (tag === "objDesc") { + return this._createEncoderBuffer(str); + } else { + return (this || _global$5).reporter.error("Encoding of string type: " + tag + " unsupported"); + } }; + DERNode.prototype._encodeObjid = function encodeObjid(id, values, relative) { + if (typeof id === "string") { + if (!values) return (this || _global$5).reporter.error("string objid given, but no values map found"); + if (!values.hasOwnProperty(id)) return (this || _global$5).reporter.error("objid not found in values map"); + id = values[id].split(/[\s\.]+/g); + for (var i = 0; i < id.length; i++) id[i] |= 0; + } else if (Array.isArray(id)) { + id = id.slice(); + for (var i = 0; i < id.length; i++) id[i] |= 0; + } + if (!Array.isArray(id)) { + return (this || _global$5).reporter.error("objid() should be either array or string, " + "got: " + JSON.stringify(id)); + } + if (!relative) { + if (id[1] >= 40) return (this || _global$5).reporter.error("Second objid identifier OOB"); + id.splice(0, 2, id[0] * 40 + id[1]); + } - Entity.prototype.decode = function decode(data, enc, options) { - return this._getDecoder(enc).decode(data, options); + // Count number of octets + var size = 0; + for (var i = 0; i < id.length; i++) { + var ident = id[i]; + for (size++; ident >= 128; ident >>= 7) size++; + } + var objid = new Buffer(size); + var offset = objid.length - 1; + for (var i = id.length - 1; i >= 0; i--) { + var ident = id[i]; + objid[offset--] = ident & 127; + while ((ident >>= 7) > 0) objid[offset--] = 128 | ident & 127; + } + return this._createEncoderBuffer(objid); }; - - Entity.prototype._getEncoder = function _getEncoder(enc) { - enc = enc || "der"; // Lazily create encoder - - if (!this.encoders.hasOwnProperty(enc)) this.encoders[enc] = this._createNamed(encoders[enc]); - return this.encoders[enc]; + function two(num) { + if (num < 10) return "0" + num;else return num; + } + DERNode.prototype._encodeTime = function encodeTime(time, tag) { + var str; + var date = new Date(time); + if (tag === "gentime") { + str = [two(date.getFullYear()), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), "Z"].join(""); + } else if (tag === "utctime") { + str = [two(date.getFullYear() % 100), two(date.getUTCMonth() + 1), two(date.getUTCDate()), two(date.getUTCHours()), two(date.getUTCMinutes()), two(date.getUTCSeconds()), "Z"].join(""); + } else { + (this || _global$5).reporter.error("Encoding " + tag + " time is not supported yet"); + } + return this._encodeStr(str, "octstr"); }; + DERNode.prototype._encodeNull = function encodeNull() { + return this._createEncoderBuffer(""); + }; + DERNode.prototype._encodeInt = function encodeInt(num, values) { + if (typeof num === "string") { + if (!values) return (this || _global$5).reporter.error("String int or enum given, but no values map"); + if (!values.hasOwnProperty(num)) { + return (this || _global$5).reporter.error("Values map doesn't contain: " + JSON.stringify(num)); + } + num = values[num]; + } - Entity.prototype.encode = function encode(data, enc, - /* internal */ - reporter) { - return this._getEncoder(enc).encode(data, reporter); + // Bignum, assume big endian + if (typeof num !== "number" && !Buffer.isBuffer(num)) { + var numArray = num.toArray(); + if (!num.sign && numArray[0] & 128) { + numArray.unshift(0); + } + num = new Buffer(numArray); + } + if (Buffer.isBuffer(num)) { + var size = num.length; + if (num.length === 0) size++; + var out = new Buffer(size); + num.copy(out); + if (num.length === 0) out[0] = 0; + return this._createEncoderBuffer(out); + } + if (num < 128) return this._createEncoderBuffer(num); + if (num < 256) return this._createEncoderBuffer([0, num]); + var size = 1; + for (var i = num; i >= 256; i >>= 8) size++; + var out = new Array(size); + for (var i = out.length - 1; i >= 0; i--) { + out[i] = num & 255; + num >>= 8; + } + if (out[0] & 128) { + out.unshift(0); + } + return this._createEncoderBuffer(new Buffer(out)); + }; + DERNode.prototype._encodeBool = function encodeBool(value) { + return this._createEncoderBuffer(value ? 255 : 0); + }; + DERNode.prototype._use = function use(entity, obj) { + if (typeof entity === "function") entity = entity(obj); + return entity._getEncoder("der").tree; + }; + DERNode.prototype._skipDefault = function skipDefault(dataBuffer, reporter, parent) { + var state = (this || _global$5)._baseState; + var i; + if (state["default"] === null) return false; + var data = dataBuffer.join(); + if (state.defaultBuffer === undefined) state.defaultBuffer = this._encodeValue(state["default"], reporter, parent).join(); + if (data.length !== state.defaultBuffer.length) return false; + for (i = 0; i < data.length; i++) if (data[i] !== state.defaultBuffer[i]) return false; + return true; }; + // Utility methods + + function encodeTag(tag, primitive, cls, reporter) { + var res; + if (tag === "seqof") tag = "seq";else if (tag === "setof") tag = "set"; + if (der.tagByName.hasOwnProperty(tag)) res = der.tagByName[tag];else if (typeof tag === "number" && (tag | 0) === tag) res = tag;else return reporter.error("Unknown tag: " + tag); + if (res >= 31) return reporter.error("Multi-octet tag encoding unsupported"); + if (!primitive) res |= 32; + res |= der.tagClassByName[cls || "universal"] << 6; + return res; + } return exports$m; } var exports$l = {}, - _dewExec$k = false; + _dewExec$k = false; +var _global$4 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; function dew$k() { if (_dewExec$k) return exports$l; _dewExec$k = true; - const base = exports$l; - base.Reporter = dew$v().Reporter; - base.DecoderBuffer = dew$u().DecoderBuffer; - base.EncoderBuffer = dew$u().EncoderBuffer; - base.Node = dew$t(); + var inherits = dew$3I(); + var DEREncoder = dew$l(); + function PEMEncoder(entity) { + DEREncoder.call(this || _global$4, entity); + (this || _global$4).enc = "pem"; + } + inherits(PEMEncoder, DEREncoder); + exports$l = PEMEncoder; + PEMEncoder.prototype.encode = function encode(data, options) { + var buf = DEREncoder.prototype.encode.call(this || _global$4, data); + var p = buf.toString("base64"); + var out = ["-----BEGIN " + options.label + "-----"]; + for (var i = 0; i < p.length; i += 64) out.push(p.slice(i, i + 64)); + out.push("-----END " + options.label + "-----"); + return out.join("\n"); + }; return exports$l; } var exports$k = {}, - _dewExec$j = false; + _dewExec$j = false; function dew$j() { if (_dewExec$j) return exports$k; _dewExec$j = true; - const constants = exports$k; // Helper - - constants._reverse = function reverse(map) { - const res = {}; - Object.keys(map).forEach(function (key) { - // Convert key to integer if it is stringified - if ((key | 0) == key) key = key | 0; - const value = map[key]; - res[value] = key; - }); - return res; - }; - - constants.der = dew$s(); + var encoders = exports$k; + encoders.der = dew$l(); + encoders.pem = dew$k(); return exports$k; } var exports$j = {}, - _dewExec$i = false; + _dewExec$i = false; function dew$i() { if (_dewExec$i) return exports$j; _dewExec$i = true; - const asn1 = exports$j; - asn1.bignum = dew$x(); - asn1.define = dew$l().define; - asn1.base = dew$k(); - asn1.constants = dew$j(); + var asn1 = exports$j; + asn1.bignum = dew$w(); + asn1.define = dew$v().define; + asn1.base = dew$r(); + asn1.constants = dew$p(); asn1.decoders = dew$m(); - asn1.encoders = dew$p(); + asn1.encoders = dew$j(); return exports$j; } var exports$i = {}, - _dewExec$h = false; + _dewExec$h = false; function dew$h() { if (_dewExec$h) return exports$i; _dewExec$h = true; - var asn = dew$i(); - var Time = asn.define("Time", function () { this.choice({ utcTime: this.utctime(), @@ -67686,7 +102477,7 @@ function dew$h() { this.seq().obj(this.key("extnID").objid(), this.key("critical").bool().def(false), this.key("extnValue").octstr()); }); var TBSCertificate = asn.define("TBSCertificate", function () { - this.seq().obj(this.key("version").explicit(0).int().optional(), this.key("serialNumber").int(), this.key("signature").use(AlgorithmIdentifier), this.key("issuer").use(Name), this.key("validity").use(Validity), this.key("subject").use(Name), this.key("subjectPublicKeyInfo").use(SubjectPublicKeyInfo), this.key("issuerUniqueID").implicit(1).bitstr().optional(), this.key("subjectUniqueID").implicit(2).bitstr().optional(), this.key("extensions").explicit(3).seqof(Extension).optional()); + this.seq().obj(this.key("version").explicit(0)["int"]().optional(), this.key("serialNumber")["int"](), this.key("signature").use(AlgorithmIdentifier), this.key("issuer").use(Name), this.key("validity").use(Validity), this.key("subject").use(Name), this.key("subjectPublicKeyInfo").use(SubjectPublicKeyInfo), this.key("issuerUniqueID").implicit(1).bitstr().optional(), this.key("subjectUniqueID").implicit(2).bitstr().optional(), this.key("extensions").explicit(3).seqof(Extension).optional()); }); var X509Certificate = asn.define("X509Certificate", function () { this.seq().obj(this.key("tbsCertificate").use(TBSCertificate), this.key("signatureAlgorithm").use(AlgorithmIdentifier), this.key("signatureValue").bitstr()); @@ -67696,55 +102487,53 @@ function dew$h() { } var exports$h = {}, - _dewExec$g = false; + _dewExec$g = false; function dew$g() { if (_dewExec$g) return exports$h; _dewExec$g = true; - var asn1 = dew$i(); - exports$h.certificate = dew$h(); var RSAPrivateKey = asn1.define("RSAPrivateKey", function () { - this.seq().obj(this.key("version").int(), this.key("modulus").int(), this.key("publicExponent").int(), this.key("privateExponent").int(), this.key("prime1").int(), this.key("prime2").int(), this.key("exponent1").int(), this.key("exponent2").int(), this.key("coefficient").int()); + this.seq().obj(this.key("version")["int"](), this.key("modulus")["int"](), this.key("publicExponent")["int"](), this.key("privateExponent")["int"](), this.key("prime1")["int"](), this.key("prime2")["int"](), this.key("exponent1")["int"](), this.key("exponent2")["int"](), this.key("coefficient")["int"]()); }); exports$h.RSAPrivateKey = RSAPrivateKey; var RSAPublicKey = asn1.define("RSAPublicKey", function () { - this.seq().obj(this.key("modulus").int(), this.key("publicExponent").int()); + this.seq().obj(this.key("modulus")["int"](), this.key("publicExponent")["int"]()); }); exports$h.RSAPublicKey = RSAPublicKey; + var AlgorithmIdentifier = asn1.define("AlgorithmIdentifier", function () { + this.seq().obj(this.key("algorithm").objid(), this.key("none").null_().optional(), this.key("curve").objid().optional(), this.key("params").seq().obj(this.key("p")["int"](), this.key("q")["int"](), this.key("g")["int"]()).optional()); + }); var PublicKey = asn1.define("SubjectPublicKeyInfo", function () { this.seq().obj(this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPublicKey").bitstr()); }); exports$h.PublicKey = PublicKey; - var AlgorithmIdentifier = asn1.define("AlgorithmIdentifier", function () { - this.seq().obj(this.key("algorithm").objid(), this.key("none").null_().optional(), this.key("curve").objid().optional(), this.key("params").seq().obj(this.key("p").int(), this.key("q").int(), this.key("g").int()).optional()); - }); var PrivateKeyInfo = asn1.define("PrivateKeyInfo", function () { - this.seq().obj(this.key("version").int(), this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPrivateKey").octstr()); + this.seq().obj(this.key("version")["int"](), this.key("algorithm").use(AlgorithmIdentifier), this.key("subjectPrivateKey").octstr()); }); exports$h.PrivateKey = PrivateKeyInfo; var EncryptedPrivateKeyInfo = asn1.define("EncryptedPrivateKeyInfo", function () { - this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(), this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(), this.key("kdeparams").seq().obj(this.key("salt").octstr(), this.key("iters").int())), this.key("cipher").seq().obj(this.key("algo").objid(), this.key("iv").octstr()))), this.key("subjectPrivateKey").octstr()); + this.seq().obj(this.key("algorithm").seq().obj(this.key("id").objid(), this.key("decrypt").seq().obj(this.key("kde").seq().obj(this.key("id").objid(), this.key("kdeparams").seq().obj(this.key("salt").octstr(), this.key("iters")["int"]())), this.key("cipher").seq().obj(this.key("algo").objid(), this.key("iv").octstr()))), this.key("subjectPrivateKey").octstr()); }); exports$h.EncryptedPrivateKey = EncryptedPrivateKeyInfo; var DSAPrivateKey = asn1.define("DSAPrivateKey", function () { - this.seq().obj(this.key("version").int(), this.key("p").int(), this.key("q").int(), this.key("g").int(), this.key("pub_key").int(), this.key("priv_key").int()); + this.seq().obj(this.key("version")["int"](), this.key("p")["int"](), this.key("q")["int"](), this.key("g")["int"](), this.key("pub_key")["int"](), this.key("priv_key")["int"]()); }); exports$h.DSAPrivateKey = DSAPrivateKey; exports$h.DSAparam = asn1.define("DSAparam", function () { - this.int(); + this["int"](); }); - var ECPrivateKey = asn1.define("ECPrivateKey", function () { - this.seq().obj(this.key("version").int(), this.key("privateKey").octstr(), this.key("parameters").optional().explicit(0).use(ECParameters), this.key("publicKey").optional().explicit(1).bitstr()); - }); - exports$h.ECPrivateKey = ECPrivateKey; var ECParameters = asn1.define("ECParameters", function () { this.choice({ namedCurve: this.objid() }); }); + var ECPrivateKey = asn1.define("ECPrivateKey", function () { + this.seq().obj(this.key("version")["int"](), this.key("privateKey").octstr(), this.key("parameters").optional().explicit(0).use(ECParameters), this.key("publicKey").optional().explicit(1).bitstr()); + }); + exports$h.ECPrivateKey = ECPrivateKey; exports$h.signature = asn1.define("signature", function () { - this.seq().obj(this.key("r").int(), this.key("s").int()); + this.seq().obj(this.key("r")["int"](), this.key("s")["int"]()); }); return exports$h; } @@ -67764,7 +102553,7 @@ var _aesid = {"2.16.840.1.101.3.4.1.1": "aes-128-ecb", }; var exports$g = {}, - _dewExec$f = false; + _dewExec$f = false; function dew$f() { if (_dewExec$f) return exports$g; _dewExec$f = true; @@ -67772,18 +102561,13 @@ function dew$f() { var findProc = /Proc-Type: 4,ENCRYPTED[\n\r]+DEK-Info: AES-((?:128)|(?:192)|(?:256))-CBC,([0-9A-H]+)[\n\r]+([0-9A-z\n\r+/=]+)[\n\r]+/m; var startRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----/m; var fullRegex = /^-----BEGIN ((?:.*? KEY)|CERTIFICATE)-----([0-9A-z\n\r+/=]+)-----END \1-----$/m; - - var evp = dew$21(); - - var ciphers = dew$1_(); - - var Buffer = dew$2P().Buffer; - + var evp = dew$2Y(); + var ciphers = dew$2V(); + var Buffer = dew$3H().Buffer; exports$g = function (okey, password) { var key = okey.toString(); var match = key.match(findProc); var decrypted; - if (!match) { var match2 = key.match(fullRegex); decrypted = Buffer.from(match2[2].replace(/[\r\n]/g, ""), "base64"); @@ -67795,166 +102579,130 @@ function dew$f() { var out = []; var cipher = ciphers.createDecipheriv(suite, cipherKey, iv); out.push(cipher.update(cipherText)); - out.push(cipher.final()); + out.push(cipher["final"]()); decrypted = Buffer.concat(out); } - var tag = key.match(startRegex)[1]; return { tag: tag, data: decrypted }; }; - return exports$g; } var exports$f = {}, - _dewExec$e = false; + _dewExec$e = false; function dew$e() { if (_dewExec$e) return exports$f; _dewExec$e = true; - var asn1 = dew$g(); - var aesid = _aesid; - var fixProc = dew$f(); - - var ciphers = dew$1_(); - - var compat = dew$2o(); - - var Buffer = dew$2P().Buffer; - - exports$f = parseKeys; - + var ciphers = dew$2V(); + var compat = dew$3j(); + var Buffer = dew$3H().Buffer; + function decrypt(data, password) { + var salt = data.algorithm.decrypt.kde.kdeparams.salt; + var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10); + var algo = aesid[data.algorithm.decrypt.cipher.algo.join(".")]; + var iv = data.algorithm.decrypt.cipher.iv; + var cipherText = data.subjectPrivateKey; + var keylen = parseInt(algo.split("-")[1], 10) / 8; + var key = compat.pbkdf2Sync(password, salt, iters, keylen, "sha1"); + var cipher = ciphers.createDecipheriv(algo, key, iv); + var out = []; + out.push(cipher.update(cipherText)); + out.push(cipher["final"]()); + return Buffer.concat(out); + } function parseKeys(buffer) { var password; - if (typeof buffer === "object" && !Buffer.isBuffer(buffer)) { password = buffer.passphrase; buffer = buffer.key; } - if (typeof buffer === "string") { buffer = Buffer.from(buffer); } - var stripped = fixProc(buffer, password); var type = stripped.tag; var data = stripped.data; var subtype, ndata; - switch (type) { case "CERTIFICATE": ndata = asn1.certificate.decode(data, "der").tbsCertificate.subjectPublicKeyInfo; // falls through - case "PUBLIC KEY": if (!ndata) { ndata = asn1.PublicKey.decode(data, "der"); } - subtype = ndata.algorithm.algorithm.join("."); - switch (subtype) { case "1.2.840.113549.1.1.1": return asn1.RSAPublicKey.decode(ndata.subjectPublicKey.data, "der"); - case "1.2.840.10045.2.1": ndata.subjectPrivateKey = ndata.subjectPublicKey; return { type: "ec", data: ndata }; - case "1.2.840.10040.4.1": ndata.algorithm.params.pub_key = asn1.DSAparam.decode(ndata.subjectPublicKey.data, "der"); return { type: "dsa", data: ndata.algorithm.params }; - default: throw new Error("unknown key id " + subtype); } - // throw new Error('unknown key type ' + type) - case "ENCRYPTED PRIVATE KEY": data = asn1.EncryptedPrivateKey.decode(data, "der"); data = decrypt(data, password); // falls through - case "PRIVATE KEY": ndata = asn1.PrivateKey.decode(data, "der"); subtype = ndata.algorithm.algorithm.join("."); - switch (subtype) { case "1.2.840.113549.1.1.1": return asn1.RSAPrivateKey.decode(ndata.subjectPrivateKey, "der"); - case "1.2.840.10045.2.1": return { curve: ndata.algorithm.curve, privateKey: asn1.ECPrivateKey.decode(ndata.subjectPrivateKey, "der").privateKey }; - case "1.2.840.10040.4.1": ndata.algorithm.params.priv_key = asn1.DSAparam.decode(ndata.subjectPrivateKey, "der"); return { type: "dsa", params: ndata.algorithm.params }; - default: throw new Error("unknown key id " + subtype); } - // throw new Error('unknown key type ' + type) - case "RSA PUBLIC KEY": return asn1.RSAPublicKey.decode(data, "der"); - case "RSA PRIVATE KEY": return asn1.RSAPrivateKey.decode(data, "der"); - case "DSA PRIVATE KEY": return { type: "dsa", params: asn1.DSAPrivateKey.decode(data, "der") }; - case "EC PRIVATE KEY": data = asn1.ECPrivateKey.decode(data, "der"); return { curve: data.parameters.value, privateKey: data.privateKey }; - default: throw new Error("unknown key type " + type); } } - parseKeys.signature = asn1.signature; - - function decrypt(data, password) { - var salt = data.algorithm.decrypt.kde.kdeparams.salt; - var iters = parseInt(data.algorithm.decrypt.kde.kdeparams.iters.toString(), 10); - var algo = aesid[data.algorithm.decrypt.cipher.algo.join(".")]; - var iv = data.algorithm.decrypt.cipher.iv; - var cipherText = data.subjectPrivateKey; - var keylen = parseInt(algo.split("-")[1], 10) / 8; - var key = compat.pbkdf2Sync(password, salt, iters, keylen, "sha1"); - var cipher = ciphers.createDecipheriv(algo, key, iv); - var out = []; - out.push(cipher.update(cipherText)); - out.push(cipher.final()); - return Buffer.concat(out); - } - + exports$f = parseKeys; return exports$f; } @@ -67968,64 +102716,63 @@ var _curves = { }; var exports$e = {}, - _dewExec$d = false; + _dewExec$d = false; function dew$d() { if (_dewExec$d) return exports$e; _dewExec$d = true; - // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js - var Buffer = dew$Y().Buffer; - - var createHmac = dew$2v(); - - var crt = dew$W(); - - var EC = dew$y().ec; - - var BN = dew$X(); - + var Buffer = dew$3H().Buffer; + var createHmac = dew$3q(); + var crt = dew$$(); + var EC = dew$x().ec; + var BN = dew$10(); var parseKeys = dew$e(); - var curves = _curves; - + var RSA_PKCS1_PADDING = 1; function sign(hash, key, hashType, signType, tag) { var priv = parseKeys(key); - if (priv.curve) { // rsa keys can be interpreted as ecdsa ones in openssl - if (signType !== "ecdsa" && signType !== "ecdsa/rsa") throw new Error("wrong private key type"); + if (signType !== "ecdsa" && signType !== "ecdsa/rsa") { + throw new Error("wrong private key type"); + } return ecSign(hash, priv); } else if (priv.type === "dsa") { - if (signType !== "dsa") throw new Error("wrong private key type"); + if (signType !== "dsa") { + throw new Error("wrong private key type"); + } return dsaSign(hash, priv, hashType); - } else { - if (signType !== "rsa" && signType !== "ecdsa/rsa") throw new Error("wrong private key type"); } - + if (signType !== "rsa" && signType !== "ecdsa/rsa") { + throw new Error("wrong private key type"); + } + if (key.padding !== undefined && key.padding !== RSA_PKCS1_PADDING) { + throw new Error("illegal or unsupported padding mode"); + } hash = Buffer.concat([tag, hash]); var len = priv.modulus.byteLength(); var pad = [0, 1]; - - while (hash.length + pad.length + 1 < len) pad.push(255); - + while (hash.length + pad.length + 1 < len) { + pad.push(255); + } pad.push(0); var i = -1; - - while (++i < hash.length) pad.push(hash[i]); - + while (++i < hash.length) { + pad.push(hash[i]); + } var out = crt(pad, priv); return out; } - function ecSign(hash, priv) { var curveId = curves[priv.curve.join(".")]; - if (!curveId) throw new Error("unknown curve " + priv.curve.join(".")); + if (!curveId) { + throw new Error("unknown curve " + priv.curve.join(".")); + } var curve = new EC(curveId); var key = curve.keyFromPrivate(priv.privateKey); var out = key.sign(hash); return Buffer.from(out.toDER()); } - function dsaSign(hash, priv, algo) { var x = priv.params.priv_key; var p = priv.params.p; @@ -68036,41 +102783,39 @@ function dew$d() { var H = bits2int(hash, q).mod(q); var s = false; var kv = getKey(x, q, hash, algo); - while (s === false) { k = makeKey(q, kv, algo); r = makeR(g, k, p, q); s = k.invm(q).imul(H.add(x.mul(r))).mod(q); - if (s.cmpn(0) === 0) { s = false; r = new BN(0); } } - return toDER(r, s); } - function toDER(r, s) { r = r.toArray(); - s = s.toArray(); // Pad values + s = s.toArray(); - if (r[0] & 128) r = [0].concat(r); - if (s[0] & 128) s = [0].concat(s); + // Pad values + if (r[0] & 128) { + r = [0].concat(r); + } + if (s[0] & 128) { + s = [0].concat(s); + } var total = r.length + s.length + 4; var res = [48, total, 2, r.length]; res = res.concat(r, [2, s.length], s); return Buffer.from(res); } - function getKey(x, q, hash, algo) { x = Buffer.from(x.toArray()); - if (x.length < q.byteLength()) { var zeros = Buffer.alloc(q.byteLength() - x.length); x = Buffer.concat([zeros, x]); } - var hlen = hash.length; var hbits = bits2octets(hash, q); var v = Buffer.alloc(hlen); @@ -68085,51 +102830,42 @@ function dew$d() { v: v }; } - function bits2int(obits, q) { var bits = new BN(obits); var shift = (obits.length << 3) - q.bitLength(); - if (shift > 0) bits.ishrn(shift); + if (shift > 0) { + bits.ishrn(shift); + } return bits; } - function bits2octets(bits, q) { bits = bits2int(bits, q); bits = bits.mod(q); var out = Buffer.from(bits.toArray()); - if (out.length < q.byteLength()) { var zeros = Buffer.alloc(q.byteLength() - out.length); out = Buffer.concat([zeros, out]); } - return out; } - function makeKey(q, kv, algo) { var t; var k; - do { t = Buffer.alloc(0); - while (t.length * 8 < q.bitLength()) { kv.v = createHmac(algo, kv.k).update(kv.v).digest(); t = Buffer.concat([t, kv.v]); } - k = bits2int(t, q); kv.k = createHmac(algo, kv.k).update(kv.v).update(Buffer.from([0])).digest(); kv.v = createHmac(algo, kv.k).update(kv.v).digest(); } while (k.cmp(q) !== -1); - return k; } - function makeR(g, k, p, q) { return g.toRed(BN.mont(p)).redPow(k).fromRed().mod(q); } - exports$e = sign; exports$e.getKey = getKey; exports$e.makeKey = makeKey; @@ -68137,53 +102873,46 @@ function dew$d() { } var exports$d = {}, - _dewExec$c = false; + _dewExec$c = false; function dew$c() { if (_dewExec$c) return exports$d; _dewExec$c = true; - // much of this based on https://github.com/indutny/self-signed/blob/gh-pages/lib/rsa.js - var Buffer = dew$Y().Buffer; - - var BN = dew$X(); - - var EC = dew$y().ec; - + var Buffer = dew$3H().Buffer; + var BN = dew$10(); + var EC = dew$x().ec; var parseKeys = dew$e(); - var curves = _curves; - function verify(sig, hash, key, signType, tag) { var pub = parseKeys(key); - if (pub.type === "ec") { // rsa keys can be interpreted as ecdsa ones in openssl - if (signType !== "ecdsa" && signType !== "ecdsa/rsa") throw new Error("wrong public key type"); + if (signType !== "ecdsa" && signType !== "ecdsa/rsa") { + throw new Error("wrong public key type"); + } return ecVerify(sig, hash, pub); } else if (pub.type === "dsa") { - if (signType !== "dsa") throw new Error("wrong public key type"); + if (signType !== "dsa") { + throw new Error("wrong public key type"); + } return dsaVerify(sig, hash, pub); - } else { - if (signType !== "rsa" && signType !== "ecdsa/rsa") throw new Error("wrong public key type"); } - + if (signType !== "rsa" && signType !== "ecdsa/rsa") { + throw new Error("wrong public key type"); + } hash = Buffer.concat([tag, hash]); var len = pub.modulus.byteLength(); var pad = [1]; var padNum = 0; - while (hash.length + pad.length + 2 < len) { pad.push(255); - padNum++; + padNum += 1; } - pad.push(0); var i = -1; - while (++i < hash.length) { pad.push(hash[i]); } - pad = Buffer.from(pad); var red = BN.mont(pub.modulus); sig = new BN(sig).toRed(red); @@ -68191,22 +102920,24 @@ function dew$c() { sig = Buffer.from(sig.fromRed().toArray()); var out = padNum < 8 ? 1 : 0; len = Math.min(sig.length, pad.length); - if (sig.length !== pad.length) out = 1; + if (sig.length !== pad.length) { + out = 1; + } i = -1; - - while (++i < len) out |= sig[i] ^ pad[i]; - + while (++i < len) { + out |= sig[i] ^ pad[i]; + } return out === 0; } - function ecVerify(sig, hash, pub) { var curveId = curves[pub.data.algorithm.curve.join(".")]; - if (!curveId) throw new Error("unknown curve " + pub.data.algorithm.curve.join(".")); + if (!curveId) { + throw new Error("unknown curve " + pub.data.algorithm.curve.join(".")); + } var curve = new EC(curveId); var pubkey = pub.data.subjectPrivateKey.data; return curve.verify(hash, sig, pubkey); } - function dsaVerify(sig, hash, pub) { var p = pub.data.p; var q = pub.data.q; @@ -68222,120 +102953,91 @@ function dew$c() { var v = g.toRed(montp).redPow(new BN(hash).mul(w).mod(q)).fromRed().mul(y.toRed(montp).redPow(r.mul(w).mod(q)).fromRed()).mod(p).mod(q); return v.cmp(r) === 0; } - function checkValue(b, q) { - if (b.cmpn(0) <= 0) throw new Error("invalid sig"); - if (b.cmp(q) >= q) throw new Error("invalid sig"); + if (b.cmpn(0) <= 0) { + throw new Error("invalid sig"); + } + if (b.cmp(q) >= 0) { + throw new Error("invalid sig"); + } } - exports$d = verify; return exports$d; } var exports$c = {}, - _dewExec$b = false; - -var _global$4 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - + _dewExec$b = false; function dew$b() { if (_dewExec$b) return exports$c; _dewExec$b = true; - - var Buffer = dew$Y().Buffer; - - var createHash = dew$2y(); - - var stream = dew$2Q(); - - var inherits = dew$2R(); - + var Buffer = dew$3H().Buffer; + var createHash = dew$3t(); + var stream = dew$11(); + var inherits = dew$3I(); var sign = dew$d(); - var verify = dew$c(); - - var algorithms = _algorithms$1; + var algorithms = _algorithms$2; Object.keys(algorithms).forEach(function (key) { algorithms[key].id = Buffer.from(algorithms[key].id, "hex"); algorithms[key.toLowerCase()] = algorithms[key]; }); - function Sign(algorithm) { - stream.Writable.call(this || _global$4); + stream.Writable.call(this); var data = algorithms[algorithm]; - if (!data) throw new Error("Unknown message digest"); - (this || _global$4)._hashType = data.hash; - (this || _global$4)._hash = createHash(data.hash); - (this || _global$4)._tag = data.id; - (this || _global$4)._signType = data.sign; + if (!data) { + throw new Error("Unknown message digest"); + } + this._hashType = data.hash; + this._hash = createHash(data.hash); + this._tag = data.id; + this._signType = data.sign; } - inherits(Sign, stream.Writable); - Sign.prototype._write = function _write(data, _, done) { - (this || _global$4)._hash.update(data); - + this._hash.update(data); done(); }; - Sign.prototype.update = function update(data, enc) { - if (typeof data === "string") data = Buffer.from(data, enc); - - (this || _global$4)._hash.update(data); - - return this || _global$4; + this._hash.update(typeof data === "string" ? Buffer.from(data, enc) : data); + return this; }; - Sign.prototype.sign = function signMethod(key, enc) { this.end(); - - var hash = (this || _global$4)._hash.digest(); - - var sig = sign(hash, key, (this || _global$4)._hashType, (this || _global$4)._signType, (this || _global$4)._tag); + var hash = this._hash.digest(); + var sig = sign(hash, key, this._hashType, this._signType, this._tag); return enc ? sig.toString(enc) : sig; }; - function Verify(algorithm) { - stream.Writable.call(this || _global$4); + stream.Writable.call(this); var data = algorithms[algorithm]; - if (!data) throw new Error("Unknown message digest"); - (this || _global$4)._hash = createHash(data.hash); - (this || _global$4)._tag = data.id; - (this || _global$4)._signType = data.sign; + if (!data) { + throw new Error("Unknown message digest"); + } + this._hash = createHash(data.hash); + this._tag = data.id; + this._signType = data.sign; } - inherits(Verify, stream.Writable); - Verify.prototype._write = function _write(data, _, done) { - (this || _global$4)._hash.update(data); - + this._hash.update(data); done(); }; - Verify.prototype.update = function update(data, enc) { - if (typeof data === "string") data = Buffer.from(data, enc); - - (this || _global$4)._hash.update(data); - - return this || _global$4; + this._hash.update(typeof data === "string" ? Buffer.from(data, enc) : data); + return this; }; - Verify.prototype.verify = function verifyMethod(key, sig, enc) { - if (typeof sig === "string") sig = Buffer.from(sig, enc); + var sigBuffer = typeof sig === "string" ? Buffer.from(sig, enc) : sig; this.end(); - - var hash = (this || _global$4)._hash.digest(); - - return verify(sig, hash, key, (this || _global$4)._signType, (this || _global$4)._tag); + var hash = this._hash.digest(); + return verify(sigBuffer, hash, key, this._signType, this._tag); }; - function createSign(algorithm) { return new Sign(algorithm); } - function createVerify(algorithm) { return new Verify(algorithm); } - exports$c = { Sign: createSign, Verify: createVerify, @@ -68346,134 +103048,113 @@ function dew$b() { } var exports$b = {}, - _dewExec$a = false; + _dewExec$a = false; var module$1 = { exports: exports$b }; - var _global$3 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$a() { if (_dewExec$a) return module$1.exports; _dewExec$a = true; - (function (module, exports) { + // Utils function assert(val, msg) { if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. - + } + // Could use `inherits` module, but don't want to move from single file + // architecture yet. function inherits(ctor, superCtor) { ctor.super_ = superCtor; - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; - } // BN + } + // BN function BN(number, base, endian) { if (BN.isBN(number)) { return number; } - (this || _global$3).negative = 0; (this || _global$3).words = null; - (this || _global$3).length = 0; // Reduction context + (this || _global$3).length = 0; + // Reduction context (this || _global$3).red = null; - if (number !== null) { if (base === "le" || base === "be") { endian = base; base = 10; } - this._init(number || 0, base || 10, endian || "be"); } } - if (typeof module === "object") { module.exports = BN; } else { exports.BN = BN; } - BN.BN = BN; BN.wordSize = 26; var Buffer; - try { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = buffer.Buffer; + Buffer = dew$3J().Buffer; } } catch (e) {} - BN.isBN = function isBN(num) { if (num instanceof BN) { return true; } - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); }; - BN.max = function max(left, right) { if (left.cmp(right) > 0) return left; return right; }; - BN.min = function min(left, right) { if (left.cmp(right) < 0) return left; return right; }; - BN.prototype._init = function init(number, base, endian) { if (typeof number === "number") { return this._initNumber(number, base, endian); } - if (typeof number === "object") { return this._initArray(number, base, endian); } - if (base === "hex") { base = 16; } - assert(base === (base | 0) && base >= 2 && base <= 36); number = number.toString().replace(/\s+/g, ""); var start = 0; - if (number[0] === "-") { start++; (this || _global$3).negative = 1; } - if (start < number.length) { if (base === 16) { this._parseHex(number, start, endian); } else { this._parseBase(number, base, start); - if (endian === "le") { this._initArray(this.toArray(), base, endian); } } } }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { (this || _global$3).negative = 1; number = -number; } - if (number < 67108864) { (this || _global$3).words = [number & 67108863]; (this || _global$3).length = 1; @@ -68482,43 +103163,35 @@ function dew$a() { (this || _global$3).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$3).words = [number & 67108863, number / 67108864 & 67108863, 1]; (this || _global$3).length = 3; } + if (endian !== "le") return; - if (endian !== "le") return; // Reverse the bytes - + // Reverse the bytes this._initArray(this.toArray(), base, endian); }; - BN.prototype._initArray = function _initArray(number, base, endian) { // Perhaps a Uint8Array assert(typeof number.length === "number"); - if (number.length <= 0) { (this || _global$3).words = [0]; (this || _global$3).length = 1; return this || _global$3; } - (this || _global$3).length = Math.ceil(number.length / 3); (this || _global$3).words = new Array((this || _global$3).length); - for (var i = 0; i < (this || _global$3).length; i++) { (this || _global$3).words[i] = 0; } - var j, w; var off = 0; - if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; (this || _global$3).words[j] |= w << off & 67108863; (this || _global$3).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; @@ -68530,58 +103203,50 @@ function dew$a() { (this || _global$3).words[j] |= w << off & 67108863; (this || _global$3).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; } } } - return this.strip(); }; - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // 'A' - 'F' - + var c = string.charCodeAt(index); + // 'A' - 'F' if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' + return c - 55; + // 'a' - 'f' } else if (c >= 97 && c <= 102) { - return c - 87; // '0' - '9' + return c - 87; + // '0' - '9' } else { return c - 48 & 15; } } - function parseHexByte(string, lowerBound, index) { var r = parseHex4Bits(string, index); - if (index - 1 >= lowerBound) { r |= parseHex4Bits(string, index - 1) << 4; } - return r; } - BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number (this || _global$3).length = Math.ceil((number.length - start) / 6); (this || _global$3).words = new Array((this || _global$3).length); - for (var i = 0; i < (this || _global$3).length; i++) { (this || _global$3).words[i] = 0; - } // 24-bits chunks - + } + // 24-bits chunks var off = 0; var j = 0; var w; - if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; (this || _global$3).words[j] |= w & 67108863; - if (off >= 18) { off -= 18; j += 1; @@ -68592,11 +103257,9 @@ function dew$a() { } } else { var parseLength = number.length - start; - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; (this || _global$3).words[j] |= w & 67108863; - if (off >= 18) { off -= 18; j += 1; @@ -68606,124 +103269,108 @@ function dew$a() { } } } - this.strip(); }; - function parseBase(str, start, end, mul) { var r = 0; var len = Math.min(str.length, end); - for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + r *= mul; + // 'a' if (c >= 49) { - r += c - 49 + 10; // 'A' + r += c - 49 + 10; + + // 'A' } else if (c >= 17) { - r += c - 17 + 10; // '0' - '9' + r += c - 17 + 10; + + // '0' - '9' } else { r += c; } } - return r; } - BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero (this || _global$3).words = [0]; - (this || _global$3).length = 1; // Find length of limb in base + (this || _global$3).length = 1; + // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; } - limbLen--; limbPow = limbPow / base | 0; var total = number.length - start; var mod = total % limbLen; var end = Math.min(total, total - mod) + start; var word = 0; - for (var i = start; i < end; i += limbLen) { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$3).words[0] + word < 67108864) { (this || _global$3).words[0] += word; } else { this._iaddn(word); } } - if (mod !== 0) { var pow = 1; word = parseBase(number, i, number.length, base); - for (i = 0; i < mod; i++) { pow *= base; } - this.imuln(pow); - if ((this || _global$3).words[0] + word < 67108864) { (this || _global$3).words[0] += word; } else { this._iaddn(word); } } - this.strip(); }; - BN.prototype.copy = function copy(dest) { dest.words = new Array((this || _global$3).length); - for (var i = 0; i < (this || _global$3).length; i++) { dest.words[i] = (this || _global$3).words[i]; } - dest.length = (this || _global$3).length; dest.negative = (this || _global$3).negative; dest.red = (this || _global$3).red; }; - BN.prototype.clone = function clone() { var r = new BN(null); this.copy(r); return r; }; - BN.prototype._expand = function _expand(size) { while ((this || _global$3).length < size) { (this || _global$3).words[(this || _global$3).length++] = 0; } - return this || _global$3; - }; // Remove leading `0` from `this` - + }; + // Remove leading `0` from `this` BN.prototype.strip = function strip() { while ((this || _global$3).length > 1 && (this || _global$3).words[(this || _global$3).length - 1] === 0) { (this || _global$3).length--; } - return this._normSign(); }; - BN.prototype._normSign = function _normSign() { // -0 = 0 if ((this || _global$3).length === 1 && (this || _global$3).words[0] === 0) { (this || _global$3).negative = 0; } - return this || _global$3; }; - BN.prototype.inspect = function inspect() { return ((this || _global$3).red ? ""; }; + /* var zeros = []; var groupSizes = []; @@ -68751,96 +103398,75 @@ function dew$a() { } */ - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - BN.prototype.toString = function toString(base, padding) { base = base || 10; padding = padding | 0 || 1; var out; - if (base === 16 || base === "hex") { out = ""; var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$3).length; i++) { var w = (this || _global$3).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$3).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; } - off += 2; - if (off >= 26) { off -= 26; i--; } } - if (carry !== 0) { out = carry.toString(16) + out; } - while (out.length % padding !== 0) { out = "0" + out; } - if ((this || _global$3).negative !== 0) { out = "-" + out; } - return out; } - if (base === (base | 0) && base >= 2 && base <= 36) { // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); var groupBase = groupBases[base]; out = ""; var c = this.clone(); c.negative = 0; - while (!c.isZero()) { var r = c.modn(groupBase).toString(base); c = c.idivn(groupBase); - if (!c.isZero()) { out = zeros[groupSize - r.length] + r + out; } else { out = r + out; } } - if (this.isZero()) { out = "0" + out; } - while (out.length % padding !== 0) { out = "0" + out; } - if ((this || _global$3).negative !== 0) { out = "-" + out; } - return out; } - assert(false, "Base should be between 2 and 36"); }; - BN.prototype.toNumber = function toNumber() { var ret = (this || _global$3).words[0]; - if ((this || _global$3).length === 2) { ret += (this || _global$3).words[1] * 67108864; } else if ((this || _global$3).length === 3 && (this || _global$3).words[2] === 1) { @@ -68849,23 +103475,18 @@ function dew$a() { } else if ((this || _global$3).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$3).negative !== 0 ? -ret : ret; }; - BN.prototype.toJSON = function toJSON() { return this.toString(16); }; - BN.prototype.toBuffer = function toBuffer(endian, length) { assert(typeof Buffer !== "undefined"); return this.toArrayLike(Buffer, endian, length); }; - BN.prototype.toArray = function toArray(endian, length) { return this.toArrayLike(Array, endian, length); }; - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { var byteLength = this.byteLength(); var reqLength = length || Math.max(1, byteLength); @@ -68876,13 +103497,11 @@ function dew$a() { var res = new ArrayType(reqLength); var b, i; var q = this.clone(); - if (!littleEndian) { // Assume big-endian for (i = 0; i < reqLength - byteLength; i++) { res[i] = 0; } - for (i = 0; !q.isZero(); i++) { b = q.andln(255); q.iushrn(8); @@ -68894,15 +103513,12 @@ function dew$a() { q.iushrn(8); res[i] = b; } - for (; i < reqLength; i++) { res[i] = 0; } } - return res; }; - if (Math.clz32) { BN.prototype._countBits = function _countBits(w) { return 32 - Math.clz32(w); @@ -68911,207 +103527,169 @@ function dew$a() { BN.prototype._countBits = function _countBits(w) { var t = w; var r = 0; - if (t >= 4096) { r += 13; t >>>= 13; } - if (t >= 64) { r += 7; t >>>= 7; } - if (t >= 8) { r += 4; t >>>= 4; } - if (t >= 2) { r += 2; t >>>= 2; } - return r + t; }; } - BN.prototype._zeroBits = function _zeroBits(w) { // Short-cut if (w === 0) return 26; var t = w; var r = 0; - if ((t & 8191) === 0) { r += 13; t >>>= 13; } - if ((t & 127) === 0) { r += 7; t >>>= 7; } - if ((t & 15) === 0) { r += 4; t >>>= 4; } - if ((t & 3) === 0) { r += 2; t >>>= 2; } - if ((t & 1) === 0) { r++; } - return r; - }; // Return number of used bits in a BN - + }; + // Return number of used bits in a BN BN.prototype.bitLength = function bitLength() { var w = (this || _global$3).words[(this || _global$3).length - 1]; - var hi = this._countBits(w); - return ((this || _global$3).length - 1) * 26 + hi; }; - function toBitArray(num) { var w = new Array(num.bitLength()); - for (var bit = 0; bit < w.length; bit++) { var off = bit / 26 | 0; var wbit = bit % 26; w[bit] = (num.words[off] & 1 << wbit) >>> wbit; } - return w; - } // Number of trailing zero bits - + } + // Number of trailing zero bits BN.prototype.zeroBits = function zeroBits() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$3).length; i++) { var b = this._zeroBits((this || _global$3).words[i]); - r += b; if (b !== 26) break; } - return r; }; - BN.prototype.byteLength = function byteLength() { return Math.ceil(this.bitLength() / 8); }; - BN.prototype.toTwos = function toTwos(width) { if ((this || _global$3).negative !== 0) { return this.abs().inotn(width).iaddn(1); } - return this.clone(); }; - BN.prototype.fromTwos = function fromTwos(width) { if (this.testn(width - 1)) { return this.notn(width).iaddn(1).ineg(); } - return this.clone(); }; - BN.prototype.isNeg = function isNeg() { return (this || _global$3).negative !== 0; - }; // Return negative clone of `this` - + }; + // Return negative clone of `this` BN.prototype.neg = function neg() { return this.clone().ineg(); }; - BN.prototype.ineg = function ineg() { if (!this.isZero()) { (this || _global$3).negative ^= 1; } - return this || _global$3; - }; // Or `num` with `this` in-place - + }; + // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { while ((this || _global$3).length < num.length) { (this || _global$3).words[(this || _global$3).length++] = 0; } - for (var i = 0; i < num.length; i++) { (this || _global$3).words[i] = (this || _global$3).words[i] | num.words[i]; } - return this.strip(); }; - BN.prototype.ior = function ior(num) { assert(((this || _global$3).negative | num.negative) === 0); return this.iuor(num); - }; // Or `num` with `this` - + }; + // Or `num` with `this` BN.prototype.or = function or(num) { if ((this || _global$3).length > num.length) return this.clone().ior(num); return num.clone().ior(this || _global$3); }; - BN.prototype.uor = function uor(num) { if ((this || _global$3).length > num.length) return this.clone().iuor(num); return num.clone().iuor(this || _global$3); - }; // And `num` with `this` in-place - + }; + // And `num` with `this` in-place BN.prototype.iuand = function iuand(num) { // b = min-length(num, this) var b; - if ((this || _global$3).length > num.length) { b = num; } else { b = this || _global$3; } - for (var i = 0; i < b.length; i++) { (this || _global$3).words[i] = (this || _global$3).words[i] & num.words[i]; } - (this || _global$3).length = b.length; return this.strip(); }; - BN.prototype.iand = function iand(num) { assert(((this || _global$3).negative | num.negative) === 0); return this.iuand(num); - }; // And `num` with `this` - + }; + // And `num` with `this` BN.prototype.and = function and(num) { if ((this || _global$3).length > num.length) return this.clone().iand(num); return num.clone().iand(this || _global$3); }; - BN.prototype.uand = function uand(num) { if ((this || _global$3).length > num.length) return this.clone().iuand(num); return num.clone().iuand(this || _global$3); - }; // Xor `num` with `this` in-place - + }; + // Xor `num` with `this` in-place BN.prototype.iuxor = function iuxor(num) { // a.length > b.length var a; var b; - if ((this || _global$3).length > num.length) { a = this || _global$3; b = num; @@ -69119,103 +103697,96 @@ function dew$a() { a = num; b = this || _global$3; } - for (var i = 0; i < b.length; i++) { (this || _global$3).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$3) !== a) { for (; i < a.length; i++) { (this || _global$3).words[i] = a.words[i]; } } - (this || _global$3).length = a.length; return this.strip(); }; - BN.prototype.ixor = function ixor(num) { assert(((this || _global$3).negative | num.negative) === 0); return this.iuxor(num); - }; // Xor `num` with `this` - + }; + // Xor `num` with `this` BN.prototype.xor = function xor(num) { if ((this || _global$3).length > num.length) return this.clone().ixor(num); return num.clone().ixor(this || _global$3); }; - BN.prototype.uxor = function uxor(num) { if ((this || _global$3).length > num.length) return this.clone().iuxor(num); return num.clone().iuxor(this || _global$3); - }; // Not ``this`` with ``width`` bitwidth - + }; + // Not ``this`` with ``width`` bitwidth BN.prototype.inotn = function inotn(width) { assert(typeof width === "number" && width >= 0); var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + var bitsLeft = width % 26; + // Extend the buffer with leading zeroes this._expand(bytesNeeded); - if (bitsLeft > 0) { bytesNeeded--; - } // Handle complete words - + } + // Handle complete words for (var i = 0; i < bytesNeeded; i++) { (this || _global$3).words[i] = ~(this || _global$3).words[i] & 67108863; - } // Handle the residue - + } + // Handle the residue if (bitsLeft > 0) { (this || _global$3).words[i] = ~(this || _global$3).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes - + } + // And remove leading zeroes return this.strip(); }; - BN.prototype.notn = function notn(width) { return this.clone().inotn(width); - }; // Set `bit` of `this` - + }; + // Set `bit` of `this` BN.prototype.setn = function setn(bit, val) { assert(typeof bit === "number" && bit >= 0); var off = bit / 26 | 0; var wbit = bit % 26; - this._expand(off + 1); - if (val) { (this || _global$3).words[off] = (this || _global$3).words[off] | 1 << wbit; } else { (this || _global$3).words[off] = (this || _global$3).words[off] & ~(1 << wbit); } - return this.strip(); - }; // Add `num` to `this` in-place - + }; + // Add `num` to `this` in-place BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + var r; + // negative + positive if ((this || _global$3).negative !== 0 && num.negative === 0) { (this || _global$3).negative = 0; r = this.isub(num); (this || _global$3).negative ^= 1; - return this._normSign(); // positive + negative + return this._normSign(); + + // positive + negative } else if ((this || _global$3).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; return r._normSign(); - } // a.length > b.length - + } + // a.length > b.length var a, b; - if ((this || _global$3).length > num.length) { a = this || _global$3; b = num; @@ -69223,39 +103794,33 @@ function dew$a() { a = num; b = this || _global$3; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; (this || _global$3).words[i] = r & 67108863; carry = r >>> 26; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; (this || _global$3).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$3).length = a.length; - if (carry !== 0) { (this || _global$3).words[(this || _global$3).length] = carry; - (this || _global$3).length++; // Copy the rest of the words + (this || _global$3).length++; + // Copy the rest of the words } else if (a !== (this || _global$3)) { for (; i < a.length; i++) { (this || _global$3).words[i] = a.words[i]; } } - return this || _global$3; - }; // Add `num` to `this` - + }; + // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$3).negative === 0) { num.negative = 0; res = this.sub(num); @@ -69267,39 +103832,40 @@ function dew$a() { (this || _global$3).negative = 1; return res; } - if ((this || _global$3).length > num.length) return this.clone().iadd(num); return num.clone().iadd(this || _global$3); - }; // Subtract `num` from `this` in-place - + }; + // Subtract `num` from `this` in-place BN.prototype.isub = function isub(num) { // this - (-num) = this + num if (num.negative !== 0) { num.negative = 0; var r = this.iadd(num); num.negative = 1; - return r._normSign(); // -this - num = -(this + num) + return r._normSign(); + + // -this - num = -(this + num) } else if ((this || _global$3).negative !== 0) { (this || _global$3).negative = 0; this.iadd(num); (this || _global$3).negative = 1; return this._normSign(); - } // At this point both numbers are positive - + } - var cmp = this.cmp(num); // Optimization - zeroify + // At this point both numbers are positive + var cmp = this.cmp(num); + // Optimization - zeroify if (cmp === 0) { (this || _global$3).negative = 0; (this || _global$3).length = 1; (this || _global$3).words[0] = 0; return this || _global$3; - } // a > b - + } + // a > b var a, b; - if (cmp > 0) { a = this || _global$3; b = num; @@ -69307,62 +103873,54 @@ function dew$a() { a = num; b = this || _global$3; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; (this || _global$3).words[i] = r & 67108863; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; (this || _global$3).words[i] = r & 67108863; - } // Copy rest of the words - + } + // Copy rest of the words if (carry === 0 && i < a.length && a !== (this || _global$3)) { for (; i < a.length; i++) { (this || _global$3).words[i] = a.words[i]; } } - (this || _global$3).length = Math.max((this || _global$3).length, i); - if (a !== (this || _global$3)) { (this || _global$3).negative = 1; } - return this.strip(); - }; // Subtract `num` from `this` - + }; + // Subtract `num` from `this` BN.prototype.sub = function sub(num) { return this.clone().isub(num); }; - function smallMulTo(self, num, out) { out.negative = num.negative ^ self.negative; var len = self.length + num.length | 0; out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + len = len - 1 | 0; + // Peel one iteration (compiler can't do it, because of code complexity) var a = self.words[0] | 0; var b = num.words[0] | 0; var r = a * b; var lo = r & 67108863; var carry = r / 67108864 | 0; out.words[0] = lo; - for (var k = 1; k < len; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff var ncarry = carry >>> 26; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j | 0; a = self.words[i] | 0; @@ -69371,23 +103929,20 @@ function dew$a() { ncarry += r / 67108864 | 0; rword = r & 67108863; } - out.words[k] = rword | 0; carry = ncarry | 0; } - if (carry !== 0) { out.words[k] = carry | 0; } else { out.length--; } - return out.strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need + } + + // TODO(indutny): it may be reasonable to omit it for users who don't need // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit // multiplication (like elliptic secp256k1). - - var comb10MulTo = function comb10MulTo(self, num, out) { var a = self.words; var b = num.words; @@ -69459,7 +104014,6 @@ function dew$a() { out.negative = self.negative ^ num.negative; out.length = 19; /* k = 0 */ - lo = Math.imul(al0, bl0); mid = Math.imul(al0, bh0); mid = mid + Math.imul(ah0, bl0) | 0; @@ -69468,7 +104022,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; w0 &= 67108863; /* k = 1 */ - lo = Math.imul(al1, bl0); mid = Math.imul(al1, bh0); mid = mid + Math.imul(ah1, bl0) | 0; @@ -69481,7 +104034,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; w1 &= 67108863; /* k = 2 */ - lo = Math.imul(al2, bl0); mid = Math.imul(al2, bh0); mid = mid + Math.imul(ah2, bl0) | 0; @@ -69498,7 +104050,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; w2 &= 67108863; /* k = 3 */ - lo = Math.imul(al3, bl0); mid = Math.imul(al3, bh0); mid = mid + Math.imul(ah3, bl0) | 0; @@ -69519,7 +104070,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; w3 &= 67108863; /* k = 4 */ - lo = Math.imul(al4, bl0); mid = Math.imul(al4, bh0); mid = mid + Math.imul(ah4, bl0) | 0; @@ -69544,7 +104094,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; w4 &= 67108863; /* k = 5 */ - lo = Math.imul(al5, bl0); mid = Math.imul(al5, bh0); mid = mid + Math.imul(ah5, bl0) | 0; @@ -69573,7 +104122,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; w5 &= 67108863; /* k = 6 */ - lo = Math.imul(al6, bl0); mid = Math.imul(al6, bh0); mid = mid + Math.imul(ah6, bl0) | 0; @@ -69606,7 +104154,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; w6 &= 67108863; /* k = 7 */ - lo = Math.imul(al7, bl0); mid = Math.imul(al7, bh0); mid = mid + Math.imul(ah7, bl0) | 0; @@ -69643,7 +104190,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; w7 &= 67108863; /* k = 8 */ - lo = Math.imul(al8, bl0); mid = Math.imul(al8, bh0); mid = mid + Math.imul(ah8, bl0) | 0; @@ -69684,7 +104230,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; w8 &= 67108863; /* k = 9 */ - lo = Math.imul(al9, bl0); mid = Math.imul(al9, bh0); mid = mid + Math.imul(ah9, bl0) | 0; @@ -69729,7 +104274,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; w9 &= 67108863; /* k = 10 */ - lo = Math.imul(al9, bl1); mid = Math.imul(al9, bh1); mid = mid + Math.imul(ah9, bl1) | 0; @@ -69770,7 +104314,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; w10 &= 67108863; /* k = 11 */ - lo = Math.imul(al9, bl2); mid = Math.imul(al9, bh2); mid = mid + Math.imul(ah9, bl2) | 0; @@ -69807,7 +104350,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; w11 &= 67108863; /* k = 12 */ - lo = Math.imul(al9, bl3); mid = Math.imul(al9, bh3); mid = mid + Math.imul(ah9, bl3) | 0; @@ -69840,7 +104382,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; w12 &= 67108863; /* k = 13 */ - lo = Math.imul(al9, bl4); mid = Math.imul(al9, bh4); mid = mid + Math.imul(ah9, bl4) | 0; @@ -69869,7 +104410,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; w13 &= 67108863; /* k = 14 */ - lo = Math.imul(al9, bl5); mid = Math.imul(al9, bh5); mid = mid + Math.imul(ah9, bl5) | 0; @@ -69894,7 +104434,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; w14 &= 67108863; /* k = 15 */ - lo = Math.imul(al9, bl6); mid = Math.imul(al9, bh6); mid = mid + Math.imul(ah9, bl6) | 0; @@ -69915,7 +104454,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; w15 &= 67108863; /* k = 16 */ - lo = Math.imul(al9, bl7); mid = Math.imul(al9, bh7); mid = mid + Math.imul(ah9, bl7) | 0; @@ -69932,7 +104470,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; w16 &= 67108863; /* k = 17 */ - lo = Math.imul(al9, bl8); mid = Math.imul(al9, bh8); mid = mid + Math.imul(ah9, bl8) | 0; @@ -69945,7 +104482,6 @@ function dew$a() { c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; w17 &= 67108863; /* k = 18 */ - lo = Math.imul(al9, bl9); mid = Math.imul(al9, bh9); mid = mid + Math.imul(ah9, bl9) | 0; @@ -69972,26 +104508,22 @@ function dew$a() { o[16] = w16; o[17] = w17; o[18] = w18; - if (c !== 0) { o[19] = c; out.length++; } - return out; - }; // Polyfill comb - + }; + // Polyfill comb if (!Math.imul) { comb10MulTo = smallMulTo; } - function bigMulTo(self, num, out) { out.negative = num.negative ^ self.negative; out.length = self.length + num.length; var carry = 0; var hncarry = 0; - for (var k = 0; k < out.length - 1; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff @@ -69999,7 +104531,6 @@ function dew$a() { hncarry = 0; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j; var a = self.words[i] | 0; @@ -70013,30 +104544,24 @@ function dew$a() { hncarry += ncarry >>> 26; ncarry &= 67108863; } - out.words[k] = rword; carry = ncarry; ncarry = hncarry; } - if (carry !== 0) { out.words[k] = carry; } else { out.length--; } - return out.strip(); } - function jumboMulTo(self, num, out) { var fftm = new FFTM(); return fftm.mulp(self, num, out); } - BN.prototype.mulTo = function mulTo(num, out) { var res; var len = (this || _global$3).length + num.length; - if ((this || _global$3).length === 10 && num.length === 10) { res = comb10MulTo(this || _global$3, num, out); } else if (len < 63) { @@ -70046,62 +104571,53 @@ function dew$a() { } else { res = jumboMulTo(this || _global$3, num, out); } - return res; - }; // Cooley-Tukey algorithm for FFT - // slightly revisited to rely on looping instead of recursion + }; + // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion function FFTM(x, y) { (this || _global$3).x = x; (this || _global$3).y = y; } - FFTM.prototype.makeRBT = function makeRBT(N) { var t = new Array(N); var l = BN.prototype._countBits(N) - 1; - for (var i = 0; i < N; i++) { t[i] = this.revBin(i, l, N); } - return t; - }; // Returns binary-reversed representation of `x` - + }; + // Returns binary-reversed representation of `x` FFTM.prototype.revBin = function revBin(x, l, N) { if (x === 0 || x === N - 1) return x; var rb = 0; - for (var i = 0; i < l; i++) { rb |= (x & 1) << l - i - 1; x >>= 1; } - return rb; - }; // Performs "tweedling" phase, therefore 'emulating' - // behaviour of the recursive algorithm - + }; + // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { for (var i = 0; i < N; i++) { rtws[i] = rws[rbt[i]]; itws[i] = iws[rbt[i]]; } }; - FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { this.permute(rbt, rws, iws, rtws, itws, N); - for (var s = 1; s < N; s <<= 1) { var l = s << 1; var rtwdf = Math.cos(2 * Math.PI / l); var itwdf = Math.sin(2 * Math.PI / l); - for (var p = 0; p < N; p += l) { var rtwdf_ = rtwdf; var itwdf_ = itwdf; - for (var j = 0; j < s; j++) { var re = rtws[p + j]; var ie = itws[p + j]; @@ -70114,8 +104630,8 @@ function dew$a() { itws[p + j] = ie + io; rtws[p + j + s] = re - ro; itws[p + j + s] = ie - io; - /* jshint maxdepth : false */ + /* jshint maxdepth : false */ if (j !== l) { rx = rtwdf * rtwdf_ - itwdf * itwdf_; itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; @@ -70125,22 +104641,17 @@ function dew$a() { } } }; - FFTM.prototype.guessLen13b = function guessLen13b(n, m) { var N = Math.max(m, n) | 1; var odd = N & 1; var i = 0; - for (N = N / 2 | 0; N; N = N >>> 1) { i++; } - return 1 << i + 1 + odd; }; - FFTM.prototype.conjugate = function conjugate(rws, iws, N) { if (N <= 1) return; - for (var i = 0; i < N / 2; i++) { var t = rws[i]; rws[i] = rws[N - i - 1]; @@ -70150,60 +104661,47 @@ function dew$a() { iws[N - i - 1] = -t; } }; - FFTM.prototype.normalize13b = function normalize13b(ws, N) { var carry = 0; - for (var i = 0; i < N / 2; i++) { var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; ws[i] = w & 67108863; - if (w < 67108864) { carry = 0; } else { carry = w / 67108864 | 0; } } - return ws; }; - FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { var carry = 0; - for (var i = 0; i < len; i++) { carry = carry + (ws[i] | 0); rws[2 * i] = carry & 8191; carry = carry >>> 13; rws[2 * i + 1] = carry & 8191; carry = carry >>> 13; - } // Pad with zeroes - + } + // Pad with zeroes for (i = 2 * len; i < N; ++i) { rws[i] = 0; } - assert(carry === 0); assert((carry & ~8191) === 0); }; - FFTM.prototype.stub = function stub(N) { var ph = new Array(N); - for (var i = 0; i < N; i++) { ph[i] = 0; } - return ph; }; - FFTM.prototype.mulp = function mulp(x, y, out) { var N = 2 * this.guessLen13b(x.length, y.length); var rbt = this.makeRBT(N); - var _ = this.stub(N); - var rws = new Array(N); var rwst = new Array(N); var iwst = new Array(N); @@ -70216,13 +104714,11 @@ function dew$a() { this.convert13b(y.words, y.length, nrws, N); this.transform(rws, _, rwst, iwst, N, rbt); this.transform(nrws, _, nrwst, niwst, N, rbt); - for (var i = 0; i < N; i++) { var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; rwst[i] = rx; } - this.conjugate(rwst, iwst, N); this.transform(rwst, iwst, rmws, _, N, rbt); this.conjugate(rmws, _, N); @@ -70230,162 +104726,144 @@ function dew$a() { out.negative = x.negative ^ y.negative; out.length = x.length + y.length; return out.strip(); - }; // Multiply `this` by `num` - + }; + // Multiply `this` by `num` BN.prototype.mul = function mul(num) { var out = new BN(null); out.words = new Array((this || _global$3).length + num.length); return this.mulTo(num, out); - }; // Multiply employing FFT - + }; + // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); out.words = new Array((this || _global$3).length + num.length); return jumboMulTo(this || _global$3, num, out); - }; // In-place Multiplication - + }; + // In-place Multiplication BN.prototype.imul = function imul(num) { return this.clone().mulTo(num, this || _global$3); }; - BN.prototype.imuln = function imuln(num) { assert(typeof num === "number"); - assert(num < 67108864); // Carry + assert(num < 67108864); + // Carry var carry = 0; - for (var i = 0; i < (this || _global$3).length; i++) { var w = ((this || _global$3).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum carry += lo >>> 26; (this || _global$3).words[i] = lo & 67108863; } - if (carry !== 0) { (this || _global$3).words[i] = carry; (this || _global$3).length++; } - return this || _global$3; }; - BN.prototype.muln = function muln(num) { return this.clone().imuln(num); - }; // `this` * `this` - + }; + // `this` * `this` BN.prototype.sqr = function sqr() { return this.mul(this || _global$3); - }; // `this` * `this` in-place - + }; + // `this` * `this` in-place BN.prototype.isqr = function isqr() { return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) - + }; + // Math.pow(`this`, `num`) BN.prototype.pow = function pow(num) { var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes + if (w.length === 0) return new BN(1); + // Skip leading zeroes var res = this || _global$3; - for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; } - if (++i < w.length) { for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { if (w[i] === 0) continue; res = res.mul(q); } } - return res; - }; // Shift-left in-place - + }; + // Shift-left in-place BN.prototype.iushln = function iushln(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; var carryMask = 67108863 >>> 26 - r << 26 - r; var i; - if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$3).length; i++) { var newCarry = (this || _global$3).words[i] & carryMask; var c = ((this || _global$3).words[i] | 0) - newCarry << r; (this || _global$3).words[i] = c | carry; carry = newCarry >>> 26 - r; } - if (carry) { (this || _global$3).words[i] = carry; (this || _global$3).length++; } } - if (s !== 0) { for (i = (this || _global$3).length - 1; i >= 0; i--) { (this || _global$3).words[i + s] = (this || _global$3).words[i]; } - for (i = 0; i < s; i++) { (this || _global$3).words[i] = 0; } - (this || _global$3).length += s; } - return this.strip(); }; - BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me assert((this || _global$3).negative === 0); return this.iushln(bits); - }; // Shift-right in-place + }; + + // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes // NOTE: if `extended` is present - it will be filled with destroyed bits - - BN.prototype.iushrn = function iushrn(bits, hint, extended) { assert(typeof bits === "number" && bits >= 0); var h; - if (hint) { h = (hint - hint % 26) / 26; } else { h = 0; } - var r = bits % 26; var s = Math.min((bits - r) / 26, (this || _global$3).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; - h = Math.max(0, h); // Extended mode, copy masked part + h = Math.max(0, h); + // Extended mode, copy masked part if (maskedWords) { for (var i = 0; i < s; i++) { maskedWords.words[i] = (this || _global$3).words[i]; } - maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$3).length > s) { (this || _global$3).length -= s; - for (i = 0; i < (this || _global$3).length; i++) { (this || _global$3).words[i] = (this || _global$3).words[i + s]; } @@ -70393,150 +104871,135 @@ function dew$a() { (this || _global$3).words[0] = 0; (this || _global$3).length = 1; } - var carry = 0; - for (i = (this || _global$3).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { var word = (this || _global$3).words[i] | 0; (this || _global$3).words[i] = carry << 26 - r | word >>> r; carry = word & mask; - } // Push carried bits as a mask - + } + // Push carried bits as a mask if (maskedWords && carry !== 0) { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$3).length === 0) { (this || _global$3).words[0] = 0; (this || _global$3).length = 1; } - return this.strip(); }; - BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me assert((this || _global$3).negative === 0); return this.iushrn(bits, hint, extended); - }; // Shift-left - + }; + // Shift-left BN.prototype.shln = function shln(bits) { return this.clone().ishln(bits); }; - BN.prototype.ushln = function ushln(bits) { return this.clone().iushln(bits); - }; // Shift-right - + }; + // Shift-right BN.prototype.shrn = function shrn(bits) { return this.clone().ishrn(bits); }; - BN.prototype.ushrn = function ushrn(bits) { return this.clone().iushrn(bits); - }; // Test if n bit is set - + }; + // Test if n bit is set BN.prototype.testn = function testn(bit) { assert(typeof bit === "number" && bit >= 0); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$3).length <= s) return false; // Check bit and return + // Fast case: bit is much higher than all existing words + if ((this || _global$3).length <= s) return false; + // Check bit and return var w = (this || _global$3).words[s]; return !!(w & q); - }; // Return only lowers bits of number (in-place) - + }; + // Return only lowers bits of number (in-place) BN.prototype.imaskn = function imaskn(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; assert((this || _global$3).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$3).length <= s) { return this || _global$3; } - if (r !== 0) { s++; } - (this || _global$3).length = Math.min(s, (this || _global$3).length); - if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; (this || _global$3).words[(this || _global$3).length - 1] &= mask; } - return this.strip(); - }; // Return only lowers bits of number - + }; + // Return only lowers bits of number BN.prototype.maskn = function maskn(bits) { return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` - + }; + // Add plain number `num` to `this` BN.prototype.iaddn = function iaddn(num) { assert(typeof num === "number"); assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + if (num < 0) return this.isubn(-num); + // Possible sign change if ((this || _global$3).negative !== 0) { if ((this || _global$3).length === 1 && ((this || _global$3).words[0] | 0) < num) { (this || _global$3).words[0] = num - ((this || _global$3).words[0] | 0); (this || _global$3).negative = 0; return this || _global$3; } - (this || _global$3).negative = 0; this.isubn(num); (this || _global$3).negative = 1; return this || _global$3; - } // Add without checks - + } + // Add without checks return this._iaddn(num); }; - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$3).words[0] += num; // Carry + (this || _global$3).words[0] += num; + // Carry for (var i = 0; i < (this || _global$3).length && (this || _global$3).words[i] >= 67108864; i++) { (this || _global$3).words[i] -= 67108864; - if (i === (this || _global$3).length - 1) { (this || _global$3).words[i + 1] = 1; } else { (this || _global$3).words[i + 1]++; } } - (this || _global$3).length = Math.max((this || _global$3).length, i + 1); return this || _global$3; - }; // Subtract plain number `num` from `this` - + }; + // Subtract plain number `num` from `this` BN.prototype.isubn = function isubn(num) { assert(typeof num === "number"); assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$3).negative !== 0) { (this || _global$3).negative = 0; this.iaddn(num); (this || _global$3).negative = 1; return this || _global$3; } - (this || _global$3).words[0] -= num; - if ((this || _global$3).length === 1 && (this || _global$3).words[0] < 0) { (this || _global$3).words[0] = -(this || _global$3).words[0]; (this || _global$3).negative = 1; @@ -70547,36 +105010,27 @@ function dew$a() { (this || _global$3).words[i + 1] -= 1; } } - return this.strip(); }; - BN.prototype.addn = function addn(num) { return this.clone().iaddn(num); }; - BN.prototype.subn = function subn(num) { return this.clone().isubn(num); }; - BN.prototype.iabs = function iabs() { (this || _global$3).negative = 0; return this || _global$3; }; - BN.prototype.abs = function abs() { return this.clone().iabs(); }; - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { var len = num.length + shift; var i; - this._expand(len); - var w; var carry = 0; - for (i = 0; i < num.length; i++) { w = ((this || _global$3).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; @@ -70584,186 +105038,155 @@ function dew$a() { carry = (w >> 26) - (right / 67108864 | 0); (this || _global$3).words[i + shift] = w & 67108863; } - for (; i < (this || _global$3).length - shift; i++) { w = ((this || _global$3).words[i + shift] | 0) + carry; carry = w >> 26; (this || _global$3).words[i + shift] = w & 67108863; } + if (carry === 0) return this.strip(); - if (carry === 0) return this.strip(); // Subtraction overflow - + // Subtraction overflow assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$3).length; i++) { w = -((this || _global$3).words[i] | 0) + carry; carry = w >> 26; (this || _global$3).words[i] = w & 67108863; } - (this || _global$3).negative = 1; return this.strip(); }; - BN.prototype._wordDiv = function _wordDiv(num, mode) { var shift = (this || _global$3).length - num.length; var a = this.clone(); - var b = num; // Normalize + var b = num; + // Normalize var bhi = b.words[b.length - 1] | 0; - var bhiBits = this._countBits(bhi); - shift = 26 - bhiBits; - if (shift !== 0) { b = b.ushln(shift); a.iushln(shift); bhi = b.words[b.length - 1] | 0; - } // Initialize quotient - + } + // Initialize quotient var m = a.length - b.length; var q; - if (mode !== "mod") { q = new BN(null); q.length = m + 1; q.words = new Array(q.length); - for (var i = 0; i < q.length; i++) { q.words[i] = 0; } } - var diff = a.clone()._ishlnsubmul(b, 1, m); - if (diff.negative === 0) { a = diff; - if (q) { q.words[m] = 1; } } - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) qj = Math.min(qj / bhi | 0, 67108863); - a._ishlnsubmul(b, qj, j); - while (a.negative !== 0) { qj--; a.negative = 0; - a._ishlnsubmul(b, 1, j); - if (!a.isZero()) { a.negative ^= 1; } } - if (q) { q.words[j] = qj; } } - if (q) { q.strip(); } + a.strip(); - a.strip(); // Denormalize - + // Denormalize if (mode !== "div" && shift !== 0) { a.iushrn(shift); } - return { div: q || null, mod: a }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, // to `div` to request div only, or be absent to // request both div & mod // 2) `positive` is true if unsigned mod is requested - - BN.prototype.divmod = function divmod(num, mode, positive) { assert(!num.isZero()); - if (this.isZero()) { return { div: new BN(0), mod: new BN(0) }; } - var div, mod, res; - if ((this || _global$3).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); - if (mode !== "mod") { div = res.div.neg(); } - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.iadd(num); } } - return { div: div, mod: mod }; } - if ((this || _global$3).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); - if (mode !== "mod") { div = res.div.neg(); } - return { div: div, mod: res.mod }; } - if (((this || _global$3).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.isub(num); } } - return { div: res.div, mod: mod }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + } + // Both numbers are positive at this point + // Strip both numbers to approximate shift value if (num.length > (this || _global$3).length || this.cmp(num) < 0) { return { div: new BN(0), mod: this || _global$3 }; - } // Very short reduction - + } + // Very short reduction if (num.length === 1) { if (mode === "div") { return { @@ -70771,144 +105194,125 @@ function dew$a() { mod: null }; } - if (mode === "mod") { return { div: null, mod: new BN(this.modn(num.words[0])) }; } - return { div: this.divn(num.words[0]), mod: new BN(this.modn(num.words[0])) }; } - return this._wordDiv(num, mode); - }; // Find `this` / `num` - + }; + // Find `this` / `num` BN.prototype.div = function div(num) { return this.divmod(num, "div", false).div; - }; // Find `this` % `num` - + }; + // Find `this` % `num` BN.prototype.mod = function mod(num) { return this.divmod(num, "mod", false).mod; }; - BN.prototype.umod = function umod(num) { return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) - + }; + // Find Round(`this` / `num`) BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + var dm = this.divmod(num); + // Fast case - exact division if (dm.mod.isZero()) return dm.div; var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; var half = num.ushrn(1); var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + var cmp = mod.cmp(half); - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + // Round up return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); }; - BN.prototype.modn = function modn(num) { assert(num <= 67108863); var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$3).length - 1; i >= 0; i--) { acc = (p * acc + ((this || _global$3).words[i] | 0)) % num; } - return acc; - }; // In-place division by number - + }; + // In-place division by number BN.prototype.idivn = function idivn(num) { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$3).length - 1; i >= 0; i--) { var w = ((this || _global$3).words[i] | 0) + carry * 67108864; (this || _global$3).words[i] = w / num | 0; carry = w % num; } - return this.strip(); }; - BN.prototype.divn = function divn(num) { return this.clone().idivn(num); }; - BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); var x = this || _global$3; var y = p.clone(); - if (x.negative !== 0) { x = x.umod(p); } else { x = x.clone(); - } // A * x + B * y = x - + } + // A * x + B * y = x var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + var B = new BN(0); + // C * x + D * y = y var C = new BN(0); var D = new BN(1); var g = 0; - while (x.isEven() && y.isEven()) { x.iushrn(1); y.iushrn(1); ++g; } - var yp = y.clone(); var xp = x.clone(); - while (!x.isZero()) { for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { x.iushrn(i); - while (i-- > 0) { if (A.isOdd() || B.isOdd()) { A.iadd(yp); B.isub(xp); } - A.iushrn(1); B.iushrn(1); } } - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { y.iushrn(j); - while (j-- > 0) { if (C.isOdd() || D.isOdd()) { C.iadd(yp); D.isub(xp); } - C.iushrn(1); D.iushrn(1); } } - if (x.cmp(y) >= 0) { x.isub(y); A.isub(C); @@ -70919,62 +105323,50 @@ function dew$a() { D.isub(B); } } - return { a: C, b: D, gcd: y.iushln(g) }; - }; // This is reduced incarnation of the binary EEA + }; + + // This is reduced incarnation of the binary EEA // above, designated to invert members of the // _prime_ fields F(p) at a maximal speed - - BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); var a = this || _global$3; var b = p.clone(); - if (a.negative !== 0) { a = a.umod(p); } else { a = a.clone(); } - var x1 = new BN(1); var x2 = new BN(0); var delta = b.clone(); - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { a.iushrn(i); - while (i-- > 0) { if (x1.isOdd()) { x1.iadd(delta); } - x1.iushrn(1); } } - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { b.iushrn(j); - while (j-- > 0) { if (x2.isOdd()) { x2.iadd(delta); } - x2.iushrn(1); } } - if (a.cmp(b) >= 0) { a.isub(b); x1.isub(x2); @@ -70983,46 +105375,38 @@ function dew$a() { x2.isub(x1); } } - var res; - if (a.cmpn(1) === 0) { res = x1; } else { res = x2; } - if (res.cmpn(0) < 0) { res.iadd(p); } - return res; }; - BN.prototype.gcd = function gcd(num) { if (this.isZero()) return num.abs(); if (num.isZero()) return this.abs(); var a = this.clone(); var b = num.clone(); a.negative = 0; - b.negative = 0; // Remove common factor of two + b.negative = 0; + // Remove common factor of two for (var shift = 0; a.isEven() && b.isEven(); shift++) { a.iushrn(1); b.iushrn(1); } - do { while (a.isEven()) { a.iushrn(1); } - while (b.isEven()) { b.iushrn(1); } - var r = a.cmp(b); - if (r < 0) { // Swap `a` and `b` to make `a` always bigger than `b` var t = a; @@ -71031,48 +105415,43 @@ function dew$a() { } else if (r === 0 || b.cmpn(1) === 0) { break; } - a.isub(b); } while (true); - return b.iushln(shift); - }; // Invert number in the field F(num) - + }; + // Invert number in the field F(num) BN.prototype.invm = function invm(num) { return this.egcd(num).a.umod(num); }; - BN.prototype.isEven = function isEven() { return ((this || _global$3).words[0] & 1) === 0; }; - BN.prototype.isOdd = function isOdd() { return ((this || _global$3).words[0] & 1) === 1; - }; // And first word and num - + }; + // And first word and num BN.prototype.andln = function andln(num) { return (this || _global$3).words[0] & num; - }; // Increment at the bit position in-line - + }; + // Increment at the bit position in-line BN.prototype.bincn = function bincn(bit) { assert(typeof bit === "number"); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; + // Fast case: bit is much higher than all existing words if ((this || _global$3).length <= s) { this._expand(s + 1); - (this || _global$3).words[s] |= q; return this || _global$3; - } // Add bit and propagate, if needed - + } + // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$3).length; i++) { var w = (this || _global$3).words[i] | 0; w += carry; @@ -71080,246 +105459,195 @@ function dew$a() { w &= 67108863; (this || _global$3).words[i] = w; } - if (carry !== 0) { (this || _global$3).words[i] = carry; (this || _global$3).length++; } - return this || _global$3; }; - BN.prototype.isZero = function isZero() { return (this || _global$3).length === 1 && (this || _global$3).words[0] === 0; }; - BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; if ((this || _global$3).negative !== 0 && !negative) return -1; if ((this || _global$3).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$3).length > 1) { res = 1; } else { if (negative) { num = -num; } - assert(num <= 67108863, "Number is too big"); var w = (this || _global$3).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$3).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: + }; + + // Compare two numbers and return: // 1 - if `this` > `num` // 0 - if `this` == `num` // -1 - if `this` < `num` - - BN.prototype.cmp = function cmp(num) { if ((this || _global$3).negative !== 0 && num.negative === 0) return -1; if ((this || _global$3).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); if ((this || _global$3).negative !== 0) return -res | 0; return res; - }; // Unsigned comparison - + }; + // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign if ((this || _global$3).length > num.length) return 1; if ((this || _global$3).length < num.length) return -1; var res = 0; - for (var i = (this || _global$3).length - 1; i >= 0; i--) { var a = (this || _global$3).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; - if (a < b) { res = -1; } else if (a > b) { res = 1; } - break; } - return res; }; - BN.prototype.gtn = function gtn(num) { return this.cmpn(num) === 1; }; - BN.prototype.gt = function gt(num) { return this.cmp(num) === 1; }; - BN.prototype.gten = function gten(num) { return this.cmpn(num) >= 0; }; - BN.prototype.gte = function gte(num) { return this.cmp(num) >= 0; }; - BN.prototype.ltn = function ltn(num) { return this.cmpn(num) === -1; }; - BN.prototype.lt = function lt(num) { return this.cmp(num) === -1; }; - BN.prototype.lten = function lten(num) { return this.cmpn(num) <= 0; }; - BN.prototype.lte = function lte(num) { return this.cmp(num) <= 0; }; - BN.prototype.eqn = function eqn(num) { return this.cmpn(num) === 0; }; - BN.prototype.eq = function eq(num) { return this.cmp(num) === 0; - }; // + }; + + // // A reduce context, could be using montgomery or something better, depending // on the `m` itself. // - - BN.red = function red(num) { return new Red(num); }; - BN.prototype.toRed = function toRed(ctx) { assert(!(this || _global$3).red, "Already a number in reduction context"); assert((this || _global$3).negative === 0, "red works only with positives"); return ctx.convertTo(this || _global$3)._forceRed(ctx); }; - BN.prototype.fromRed = function fromRed() { assert((this || _global$3).red, "fromRed works only with numbers in reduction context"); return (this || _global$3).red.convertFrom(this || _global$3); }; - BN.prototype._forceRed = function _forceRed(ctx) { (this || _global$3).red = ctx; return this || _global$3; }; - BN.prototype.forceRed = function forceRed(ctx) { assert(!(this || _global$3).red, "Already a number in reduction context"); return this._forceRed(ctx); }; - BN.prototype.redAdd = function redAdd(num) { assert((this || _global$3).red, "redAdd works only with red numbers"); return (this || _global$3).red.add(this || _global$3, num); }; - BN.prototype.redIAdd = function redIAdd(num) { assert((this || _global$3).red, "redIAdd works only with red numbers"); return (this || _global$3).red.iadd(this || _global$3, num); }; - BN.prototype.redSub = function redSub(num) { assert((this || _global$3).red, "redSub works only with red numbers"); return (this || _global$3).red.sub(this || _global$3, num); }; - BN.prototype.redISub = function redISub(num) { assert((this || _global$3).red, "redISub works only with red numbers"); return (this || _global$3).red.isub(this || _global$3, num); }; - BN.prototype.redShl = function redShl(num) { assert((this || _global$3).red, "redShl works only with red numbers"); return (this || _global$3).red.shl(this || _global$3, num); }; - BN.prototype.redMul = function redMul(num) { assert((this || _global$3).red, "redMul works only with red numbers"); - (this || _global$3).red._verify2(this || _global$3, num); - return (this || _global$3).red.mul(this || _global$3, num); }; - BN.prototype.redIMul = function redIMul(num) { assert((this || _global$3).red, "redMul works only with red numbers"); - (this || _global$3).red._verify2(this || _global$3, num); - return (this || _global$3).red.imul(this || _global$3, num); }; - BN.prototype.redSqr = function redSqr() { assert((this || _global$3).red, "redSqr works only with red numbers"); - (this || _global$3).red._verify1(this || _global$3); - return (this || _global$3).red.sqr(this || _global$3); }; - BN.prototype.redISqr = function redISqr() { assert((this || _global$3).red, "redISqr works only with red numbers"); - (this || _global$3).red._verify1(this || _global$3); - return (this || _global$3).red.isqr(this || _global$3); - }; // Square root over p - + }; + // Square root over p BN.prototype.redSqrt = function redSqrt() { assert((this || _global$3).red, "redSqrt works only with red numbers"); - (this || _global$3).red._verify1(this || _global$3); - return (this || _global$3).red.sqrt(this || _global$3); }; - BN.prototype.redInvm = function redInvm() { assert((this || _global$3).red, "redInvm works only with red numbers"); - (this || _global$3).red._verify1(this || _global$3); - return (this || _global$3).red.invm(this || _global$3); - }; // Return negative clone of `this` % `red modulo` - + }; + // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { assert((this || _global$3).red, "redNeg works only with red numbers"); - (this || _global$3).red._verify1(this || _global$3); - return (this || _global$3).red.neg(this || _global$3); }; - BN.prototype.redPow = function redPow(num) { assert((this || _global$3).red && !num.red, "redPow(normalNum)"); - (this || _global$3).red._verify1(this || _global$3); - return (this || _global$3).red.pow(this || _global$3, num); - }; // Prime numbers with efficient reduction - + }; + // Prime numbers with efficient reduction var primes = { k256: null, p224: null, p192: null, p25519: null - }; // Pseudo-Mersenne prime + }; + // Pseudo-Mersenne prime function MPrime(name, p) { // P = 2 ^ N - K (this || _global$3).name = name; @@ -71328,28 +105656,23 @@ function dew$a() { (this || _global$3).k = new BN(1).iushln((this || _global$3).n).isub((this || _global$3).p); (this || _global$3).tmp = this._tmp(); } - MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); tmp.words = new Array(Math.ceil((this || _global$3).n / 13)); return tmp; }; - MPrime.prototype.ireduce = function ireduce(num) { // Assumes that `num` is less than `P^2` // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) var r = num; var rlen; - do { this.split(r, (this || _global$3).tmp); r = this.imulK(r); r = r.iadd((this || _global$3).tmp); rlen = r.bitLength(); } while (rlen > (this || _global$3).n); - var cmp = rlen < (this || _global$3).n ? -1 : r.ucmp((this || _global$3).p); - if (cmp === 0) { r.words[0] = 0; r.length = 1; @@ -71364,111 +105687,88 @@ function dew$a() { r._strip(); } } - return r; }; - MPrime.prototype.split = function split(input, out) { input.iushrn((this || _global$3).n, 0, out); }; - MPrime.prototype.imulK = function imulK(num) { return num.imul((this || _global$3).k); }; - function K256() { MPrime.call(this || _global$3, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - inherits(K256, MPrime); - K256.prototype.split = function split(input, output) { // 256 = 9 * 26 + 22 var mask = 4194303; var outLen = Math.min(input.length, 9); - for (var i = 0; i < outLen; i++) { output.words[i] = input.words[i]; } - output.length = outLen; - if (input.length <= 9) { input.words[0] = 0; input.length = 1; return; - } // Shift by 9 limbs - + } + // Shift by 9 limbs var prev = input.words[9]; output.words[output.length++] = prev & mask; - for (i = 10; i < input.length; i++) { var next = input.words[i] | 0; input.words[i - 10] = (next & mask) << 4 | prev >>> 22; prev = next; } - prev >>>= 22; input.words[i - 10] = prev; - if (prev === 0 && input.length > 10) { input.length -= 10; } else { input.length -= 9; } }; - K256.prototype.imulK = function imulK(num) { // K = 0x1000003d1 = [ 0x40, 0x3d1 ] num.words[num.length] = 0; num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + num.length += 2; + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 var lo = 0; - for (var i = 0; i < num.length; i++) { var w = num.words[i] | 0; lo += w * 977; num.words[i] = lo & 67108863; lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction - + } + // Fast length reduction if (num.words[num.length - 1] === 0) { num.length--; - if (num.words[num.length - 1] === 0) { num.length--; } } - return num; }; - function P224() { MPrime.call(this || _global$3, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } - inherits(P224, MPrime); - function P192() { MPrime.call(this || _global$3, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } - inherits(P192, MPrime); - function P25519() { // 2 ^ 255 - 19 MPrime.call(this || _global$3, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } - inherits(P25519, MPrime); - P25519.prototype.imulK = function imulK(num) { // K = 0x13 var carry = 0; - for (var i = 0; i < num.length; i++) { var hi = (num.words[i] | 0) * 19 + carry; var lo = hi & 67108863; @@ -71476,20 +105776,17 @@ function dew$a() { num.words[i] = lo; carry = hi; } - if (carry !== 0) { num.words[num.length++] = carry; } - return num; - }; // Exported mostly for testing purposes, use plain name instead - + }; + // Exported mostly for testing purposes, use plain name instead BN._prime = function prime(name) { // Cached version of prime if (primes[name]) return primes[name]; var prime; - if (name === "k256") { prime = new K256(); } else if (name === "p224") { @@ -71501,18 +105798,16 @@ function dew$a() { } else { throw new Error("Unknown prime " + name); } - primes[name] = prime; return prime; - }; // + }; + + // // Base reduction engine // - - function Red(m) { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$3).m = prime.p; (this || _global$3).prime = prime; } else { @@ -71521,156 +105816,115 @@ function dew$a() { (this || _global$3).prime = null; } } - Red.prototype._verify1 = function _verify1(a) { assert(a.negative === 0, "red works only with positives"); assert(a.red, "red works only with red numbers"); }; - Red.prototype._verify2 = function _verify2(a, b) { assert((a.negative | b.negative) === 0, "red works only with positives"); assert(a.red && a.red === b.red, "red works only with red numbers"); }; - Red.prototype.imod = function imod(a) { if ((this || _global$3).prime) return (this || _global$3).prime.ireduce(a)._forceRed(this || _global$3); return a.umod((this || _global$3).m)._forceRed(this || _global$3); }; - Red.prototype.neg = function neg(a) { if (a.isZero()) { return a.clone(); } - return (this || _global$3).m.sub(a)._forceRed(this || _global$3); }; - Red.prototype.add = function add(a, b) { this._verify2(a, b); - var res = a.add(b); - if (res.cmp((this || _global$3).m) >= 0) { res.isub((this || _global$3).m); } - return res._forceRed(this || _global$3); }; - Red.prototype.iadd = function iadd(a, b) { this._verify2(a, b); - var res = a.iadd(b); - if (res.cmp((this || _global$3).m) >= 0) { res.isub((this || _global$3).m); } - return res; }; - Red.prototype.sub = function sub(a, b) { this._verify2(a, b); - var res = a.sub(b); - if (res.cmpn(0) < 0) { res.iadd((this || _global$3).m); } - return res._forceRed(this || _global$3); }; - Red.prototype.isub = function isub(a, b) { this._verify2(a, b); - var res = a.isub(b); - if (res.cmpn(0) < 0) { res.iadd((this || _global$3).m); } - return res; }; - Red.prototype.shl = function shl(a, num) { this._verify1(a); - return this.imod(a.ushln(num)); }; - Red.prototype.imul = function imul(a, b) { this._verify2(a, b); - return this.imod(a.imul(b)); }; - Red.prototype.mul = function mul(a, b) { this._verify2(a, b); - return this.imod(a.mul(b)); }; - Red.prototype.isqr = function isqr(a) { return this.imul(a, a.clone()); }; - Red.prototype.sqr = function sqr(a) { return this.mul(a, a); }; - Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$3).m.andln(3); + assert(mod3 % 2 === 1); - assert(mod3 % 2 === 1); // Fast case - + // Fast case if (mod3 === 3) { var pow = (this || _global$3).m.add(new BN(1)).iushrn(2); - return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) // // Find Q and S, that Q * 2 ^ S = (P - 1) - - var q = (this || _global$3).m.subn(1); - var s = 0; - while (!q.isZero() && q.andln(1) === 0) { s++; q.iushrn(1); } - assert(!q.isZero()); var one = new BN(1).toRed(this || _global$3); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. + var nOne = one.redNeg(); + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. var lpow = (this || _global$3).m.subn(1).iushrn(1); - var z = (this || _global$3).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$3); - while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); } - var c = this.pow(z, q); var r = this.pow(a, q.addn(1).iushrn(1)); var t = this.pow(a, q); var m = s; - while (t.cmp(one) !== 0) { var tmp = t; - for (var i = 0; tmp.cmp(one) !== 0; i++) { tmp = tmp.redSqr(); } - assert(i < m); var b = this.pow(c, new BN(1).iushln(m - i - 1)); r = r.redMul(b); @@ -71678,13 +105932,10 @@ function dew$a() { t = t.redMul(c); m = i; } - return r; }; - Red.prototype.invm = function invm(a) { var inv = a._invmp((this || _global$3).m); - if (inv.negative !== 0) { inv.negative = 0; return this.imod(inv).redNeg(); @@ -71692,7 +105943,6 @@ function dew$a() { return this.imod(inv); } }; - Red.prototype.pow = function pow(a, num) { if (num.isZero()) return new BN(1).toRed(this || _global$3); if (num.cmpn(1) === 0) return a.clone(); @@ -71700,35 +105950,27 @@ function dew$a() { var wnd = new Array(1 << windowSize); wnd[0] = new BN(1).toRed(this || _global$3); wnd[1] = a; - for (var i = 2; i < wnd.length; i++) { wnd[i] = this.mul(wnd[i - 1], a); } - var res = wnd[0]; var current = 0; var currentLen = 0; var start = num.bitLength() % 26; - if (start === 0) { start = 26; } - for (i = num.length - 1; i >= 0; i--) { var word = num.words[i]; - for (var j = start - 1; j >= 0; j--) { var bit = word >> j & 1; - if (res !== wnd[0]) { res = this.sqr(res); } - if (bit === 0 && current === 0) { currentLen = 0; continue; } - current <<= 1; current |= bit; currentLen++; @@ -71737,39 +105979,33 @@ function dew$a() { currentLen = 0; current = 0; } - start = 26; } - return res; }; - Red.prototype.convertTo = function convertTo(num) { var r = num.umod((this || _global$3).m); return r === num ? r.clone() : r; }; - Red.prototype.convertFrom = function convertFrom(num) { var res = num.clone(); res.red = null; return res; - }; // + }; + + // // Montgomery method engine // - BN.mont = function mont(num) { return new Mont(num); }; - function Mont(m) { Red.call(this || _global$3, m); (this || _global$3).shift = (this || _global$3).m.bitLength(); - if ((this || _global$3).shift % 26 !== 0) { (this || _global$3).shift += 26 - (this || _global$3).shift % 26; } - (this || _global$3).r = new BN(1).iushln((this || _global$3).shift); (this || _global$3).r2 = this.imod((this || _global$3).r.sqr()); (this || _global$3).rinv = (this || _global$3).r._invmp((this || _global$3).m); @@ -71777,84 +106013,66 @@ function dew$a() { (this || _global$3).minv = (this || _global$3).minv.umod((this || _global$3).r); (this || _global$3).minv = (this || _global$3).r.sub((this || _global$3).minv); } - inherits(Mont, Red); - Mont.prototype.convertTo = function convertTo(num) { return this.imod(num.ushln((this || _global$3).shift)); }; - Mont.prototype.convertFrom = function convertFrom(num) { var r = this.imod(num.mul((this || _global$3).rinv)); r.red = null; return r; }; - Mont.prototype.imul = function imul(a, b) { if (a.isZero() || b.isZero()) { a.words[0] = 0; a.length = 1; return a; } - var t = a.imul(b); var c = t.maskn((this || _global$3).shift).mul((this || _global$3).minv).imaskn((this || _global$3).shift).mul((this || _global$3).m); var u = t.isub(c).iushrn((this || _global$3).shift); var res = u; - if (u.cmp((this || _global$3).m) >= 0) { res = u.isub((this || _global$3).m); } else if (u.cmpn(0) < 0) { res = u.iadd((this || _global$3).m); } - return res._forceRed(this || _global$3); }; - Mont.prototype.mul = function mul(a, b) { if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$3); var t = a.mul(b); var c = t.maskn((this || _global$3).shift).mul((this || _global$3).minv).imaskn((this || _global$3).shift).mul((this || _global$3).m); var u = t.isub(c).iushrn((this || _global$3).shift); var res = u; - if (u.cmp((this || _global$3).m) >= 0) { res = u.isub((this || _global$3).m); } else if (u.cmpn(0) < 0) { res = u.iadd((this || _global$3).m); } - return res._forceRed(this || _global$3); }; - Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R var res = this.imod(a._invmp((this || _global$3).m).mul((this || _global$3).r2)); return res._forceRed(this || _global$3); }; })(module$1, exports$b); - return module$1.exports; } var exports$a = {}, - _dewExec$9 = false; - + _dewExec$9 = false; var _global$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$9() { if (_dewExec$9) return exports$a; _dewExec$9 = true; - var Buffer = buffer.Buffer; - - var elliptic = dew$y(); - + var Buffer = dew$3J().Buffer; + var elliptic = dew$x(); var BN = dew$a(); - exports$a = function createECDH(curve) { return new ECDH(curve); }; - var aliases = { secp256k1: { name: "secp256k1", @@ -71890,42 +106108,31 @@ function dew$9() { aliases.p192 = aliases.secp192r1 = aliases.prime192v1; aliases.p384 = aliases.secp384r1; aliases.p521 = aliases.secp521r1; - function ECDH(curve) { (this || _global$2).curveType = aliases[curve]; - if (!(this || _global$2).curveType) { (this || _global$2).curveType = { name: curve }; } - (this || _global$2).curve = new elliptic.ec((this || _global$2).curveType.name); // eslint-disable-line new-cap - (this || _global$2).keys = void 0; } - ECDH.prototype.generateKeys = function (enc, format) { (this || _global$2).keys = (this || _global$2).curve.genKeyPair(); return this.getPublicKey(enc, format); }; - ECDH.prototype.computeSecret = function (other, inenc, enc) { inenc = inenc || "utf8"; - if (!Buffer.isBuffer(other)) { other = new Buffer(other, inenc); } - var otherPub = (this || _global$2).curve.keyFromPublic(other).getPublic(); - var out = otherPub.mul((this || _global$2).keys.getPrivate()).getX(); return formatReturnValue(out, enc, (this || _global$2).curveType.byteLength); }; - ECDH.prototype.getPublicKey = function (enc, format) { var key = (this || _global$2).keys.getPublic(format === "compressed", true); - if (format === "hybrid") { if (key[key.length - 1] % 2) { key[0] = 7; @@ -71933,247 +106140,198 @@ function dew$9() { key[0] = 6; } } - return formatReturnValue(key, enc); }; - ECDH.prototype.getPrivateKey = function (enc) { return formatReturnValue((this || _global$2).keys.getPrivate(), enc); }; - ECDH.prototype.setPublicKey = function (pub, enc) { enc = enc || "utf8"; - if (!Buffer.isBuffer(pub)) { pub = new Buffer(pub, enc); } - (this || _global$2).keys._importPublic(pub); - return this || _global$2; }; - ECDH.prototype.setPrivateKey = function (priv, enc) { enc = enc || "utf8"; - if (!Buffer.isBuffer(priv)) { priv = new Buffer(priv, enc); } - var _priv = new BN(priv); - _priv = _priv.toString(16); (this || _global$2).keys = (this || _global$2).curve.genKeyPair(); - (this || _global$2).keys._importPrivate(_priv); - return this || _global$2; }; - function formatReturnValue(bn, enc, len) { if (!Array.isArray(bn)) { bn = bn.toArray(); } - var buf = new Buffer(bn); - if (len && buf.length < len) { var zeros = new Buffer(len - buf.length); zeros.fill(0); buf = Buffer.concat([zeros, buf]); } - if (!enc) { return buf; } else { return buf.toString(enc); } } - return exports$a; } var exports$9 = {}, - _dewExec$8 = false; + _dewExec$8 = false; function dew$8() { if (_dewExec$8) return exports$9; _dewExec$8 = true; - - var createHash = dew$2y(); - - var Buffer = dew$2P().Buffer; - + var createHash = dew$3t(); + var Buffer = dew$3H().Buffer; exports$9 = function (seed, len) { var t = Buffer.alloc(0); var i = 0; var c; - while (t.length < len) { c = i2ops(i++); t = Buffer.concat([t, createHash("sha1").update(seed).update(c).digest()]); } - return t.slice(0, len); }; - function i2ops(c) { var out = Buffer.allocUnsafe(4); out.writeUInt32BE(c, 0); return out; } - return exports$9; } var exports$8 = {}, - _dewExec$7 = false; + _dewExec$7 = false; function dew$7() { if (_dewExec$7) return exports$8; _dewExec$7 = true; - exports$8 = function xor(a, b) { var len = a.length; var i = -1; - while (++i < len) { a[i] ^= b[i]; } - return a; }; - return exports$8; } var exports$7 = {}, - _dewExec$6 = false; + _dewExec$6 = false; var module = { exports: exports$7 }; - var _global$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$6() { if (_dewExec$6) return module.exports; _dewExec$6 = true; - (function (module, exports) { + // Utils function assert(val, msg) { if (!val) throw new Error(msg || "Assertion failed"); - } // Could use `inherits` module, but don't want to move from single file - // architecture yet. - + } + // Could use `inherits` module, but don't want to move from single file + // architecture yet. function inherits(ctor, superCtor) { ctor.super_ = superCtor; - var TempCtor = function () {}; - TempCtor.prototype = superCtor.prototype; ctor.prototype = new TempCtor(); ctor.prototype.constructor = ctor; - } // BN + } + // BN function BN(number, base, endian) { if (BN.isBN(number)) { return number; } - (this || _global$1).negative = 0; (this || _global$1).words = null; - (this || _global$1).length = 0; // Reduction context + (this || _global$1).length = 0; + // Reduction context (this || _global$1).red = null; - if (number !== null) { if (base === "le" || base === "be") { endian = base; base = 10; } - this._init(number || 0, base || 10, endian || "be"); } } - if (typeof module === "object") { module.exports = BN; } else { exports.BN = BN; } - BN.BN = BN; BN.wordSize = 26; var Buffer; - try { if (typeof window !== "undefined" && typeof window.Buffer !== "undefined") { Buffer = window.Buffer; } else { - Buffer = buffer.Buffer; + Buffer = dew$3J().Buffer; } } catch (e) {} - BN.isBN = function isBN(num) { if (num instanceof BN) { return true; } - return num !== null && typeof num === "object" && num.constructor.wordSize === BN.wordSize && Array.isArray(num.words); }; - BN.max = function max(left, right) { if (left.cmp(right) > 0) return left; return right; }; - BN.min = function min(left, right) { if (left.cmp(right) < 0) return left; return right; }; - BN.prototype._init = function init(number, base, endian) { if (typeof number === "number") { return this._initNumber(number, base, endian); } - if (typeof number === "object") { return this._initArray(number, base, endian); } - if (base === "hex") { base = 16; } - assert(base === (base | 0) && base >= 2 && base <= 36); number = number.toString().replace(/\s+/g, ""); var start = 0; - if (number[0] === "-") { start++; (this || _global$1).negative = 1; } - if (start < number.length) { if (base === 16) { this._parseHex(number, start, endian); } else { this._parseBase(number, base, start); - if (endian === "le") { this._initArray(this.toArray(), base, endian); } } } }; - BN.prototype._initNumber = function _initNumber(number, base, endian) { if (number < 0) { (this || _global$1).negative = 1; number = -number; } - if (number < 67108864) { (this || _global$1).words = [number & 67108863]; (this || _global$1).length = 1; @@ -72182,43 +106340,35 @@ function dew$6() { (this || _global$1).length = 2; } else { assert(number < 9007199254740992); // 2 ^ 53 (unsafe) - (this || _global$1).words = [number & 67108863, number / 67108864 & 67108863, 1]; (this || _global$1).length = 3; } + if (endian !== "le") return; - if (endian !== "le") return; // Reverse the bytes - + // Reverse the bytes this._initArray(this.toArray(), base, endian); }; - BN.prototype._initArray = function _initArray(number, base, endian) { // Perhaps a Uint8Array assert(typeof number.length === "number"); - if (number.length <= 0) { (this || _global$1).words = [0]; (this || _global$1).length = 1; return this || _global$1; } - (this || _global$1).length = Math.ceil(number.length / 3); (this || _global$1).words = new Array((this || _global$1).length); - for (var i = 0; i < (this || _global$1).length; i++) { (this || _global$1).words[i] = 0; } - var j, w; var off = 0; - if (endian === "be") { for (i = number.length - 1, j = 0; i >= 0; i -= 3) { w = number[i] | number[i - 1] << 8 | number[i - 2] << 16; (this || _global$1).words[j] |= w << off & 67108863; (this || _global$1).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; @@ -72230,58 +106380,50 @@ function dew$6() { (this || _global$1).words[j] |= w << off & 67108863; (this || _global$1).words[j + 1] = w >>> 26 - off & 67108863; off += 24; - if (off >= 26) { off -= 26; j++; } } } - return this.strip(); }; - function parseHex4Bits(string, index) { - var c = string.charCodeAt(index); // 'A' - 'F' - + var c = string.charCodeAt(index); + // 'A' - 'F' if (c >= 65 && c <= 70) { - return c - 55; // 'a' - 'f' + return c - 55; + // 'a' - 'f' } else if (c >= 97 && c <= 102) { - return c - 87; // '0' - '9' + return c - 87; + // '0' - '9' } else { return c - 48 & 15; } } - function parseHexByte(string, lowerBound, index) { var r = parseHex4Bits(string, index); - if (index - 1 >= lowerBound) { r |= parseHex4Bits(string, index - 1) << 4; } - return r; } - BN.prototype._parseHex = function _parseHex(number, start, endian) { // Create possibly bigger array to ensure that it fits the number (this || _global$1).length = Math.ceil((number.length - start) / 6); (this || _global$1).words = new Array((this || _global$1).length); - for (var i = 0; i < (this || _global$1).length; i++) { (this || _global$1).words[i] = 0; - } // 24-bits chunks - + } + // 24-bits chunks var off = 0; var j = 0; var w; - if (endian === "be") { for (i = number.length - 1; i >= start; i -= 2) { w = parseHexByte(number, start, i) << off; (this || _global$1).words[j] |= w & 67108863; - if (off >= 18) { off -= 18; j += 1; @@ -72292,11 +106434,9 @@ function dew$6() { } } else { var parseLength = number.length - start; - for (i = parseLength % 2 === 0 ? start + 1 : start; i < number.length; i += 2) { w = parseHexByte(number, start, i) << off; (this || _global$1).words[j] |= w & 67108863; - if (off >= 18) { off -= 18; j += 1; @@ -72306,124 +106446,108 @@ function dew$6() { } } } - this.strip(); }; - function parseBase(str, start, end, mul) { var r = 0; var len = Math.min(str.length, end); - for (var i = start; i < len; i++) { var c = str.charCodeAt(i) - 48; - r *= mul; // 'a' + r *= mul; + // 'a' if (c >= 49) { - r += c - 49 + 10; // 'A' + r += c - 49 + 10; + + // 'A' } else if (c >= 17) { - r += c - 17 + 10; // '0' - '9' + r += c - 17 + 10; + + // '0' - '9' } else { r += c; } } - return r; } - BN.prototype._parseBase = function _parseBase(number, base, start) { // Initialize as zero (this || _global$1).words = [0]; - (this || _global$1).length = 1; // Find length of limb in base + (this || _global$1).length = 1; + // Find length of limb in base for (var limbLen = 0, limbPow = 1; limbPow <= 67108863; limbPow *= base) { limbLen++; } - limbLen--; limbPow = limbPow / base | 0; var total = number.length - start; var mod = total % limbLen; var end = Math.min(total, total - mod) + start; var word = 0; - for (var i = start; i < end; i += limbLen) { word = parseBase(number, i, i + limbLen, base); this.imuln(limbPow); - if ((this || _global$1).words[0] + word < 67108864) { (this || _global$1).words[0] += word; } else { this._iaddn(word); } } - if (mod !== 0) { var pow = 1; word = parseBase(number, i, number.length, base); - for (i = 0; i < mod; i++) { pow *= base; } - this.imuln(pow); - if ((this || _global$1).words[0] + word < 67108864) { (this || _global$1).words[0] += word; } else { this._iaddn(word); } } - this.strip(); }; - BN.prototype.copy = function copy(dest) { dest.words = new Array((this || _global$1).length); - for (var i = 0; i < (this || _global$1).length; i++) { dest.words[i] = (this || _global$1).words[i]; } - dest.length = (this || _global$1).length; dest.negative = (this || _global$1).negative; dest.red = (this || _global$1).red; }; - BN.prototype.clone = function clone() { var r = new BN(null); this.copy(r); return r; }; - BN.prototype._expand = function _expand(size) { while ((this || _global$1).length < size) { (this || _global$1).words[(this || _global$1).length++] = 0; } - return this || _global$1; - }; // Remove leading `0` from `this` - + }; + // Remove leading `0` from `this` BN.prototype.strip = function strip() { while ((this || _global$1).length > 1 && (this || _global$1).words[(this || _global$1).length - 1] === 0) { (this || _global$1).length--; } - return this._normSign(); }; - BN.prototype._normSign = function _normSign() { // -0 = 0 if ((this || _global$1).length === 1 && (this || _global$1).words[0] === 0) { (this || _global$1).negative = 0; } - return this || _global$1; }; - BN.prototype.inspect = function inspect() { return ((this || _global$1).red ? ""; }; + /* var zeros = []; var groupSizes = []; @@ -72451,96 +106575,75 @@ function dew$6() { } */ - var zeros = ["", "0", "00", "000", "0000", "00000", "000000", "0000000", "00000000", "000000000", "0000000000", "00000000000", "000000000000", "0000000000000", "00000000000000", "000000000000000", "0000000000000000", "00000000000000000", "000000000000000000", "0000000000000000000", "00000000000000000000", "000000000000000000000", "0000000000000000000000", "00000000000000000000000", "000000000000000000000000", "0000000000000000000000000"]; var groupSizes = [0, 0, 25, 16, 12, 11, 10, 9, 8, 8, 7, 7, 7, 7, 6, 6, 6, 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5]; var groupBases = [0, 0, 33554432, 43046721, 16777216, 48828125, 60466176, 40353607, 16777216, 43046721, 10000000, 19487171, 35831808, 62748517, 7529536, 11390625, 16777216, 24137569, 34012224, 47045881, 64000000, 4084101, 5153632, 6436343, 7962624, 9765625, 11881376, 14348907, 17210368, 20511149, 24300000, 28629151, 33554432, 39135393, 45435424, 52521875, 60466176]; - BN.prototype.toString = function toString(base, padding) { base = base || 10; padding = padding | 0 || 1; var out; - if (base === 16 || base === "hex") { out = ""; var off = 0; var carry = 0; - for (var i = 0; i < (this || _global$1).length; i++) { var w = (this || _global$1).words[i]; var word = ((w << off | carry) & 16777215).toString(16); carry = w >>> 24 - off & 16777215; - if (carry !== 0 || i !== (this || _global$1).length - 1) { out = zeros[6 - word.length] + word + out; } else { out = word + out; } - off += 2; - if (off >= 26) { off -= 26; i--; } } - if (carry !== 0) { out = carry.toString(16) + out; } - while (out.length % padding !== 0) { out = "0" + out; } - if ((this || _global$1).negative !== 0) { out = "-" + out; } - return out; } - if (base === (base | 0) && base >= 2 && base <= 36) { // var groupSize = Math.floor(BN.wordSize * Math.LN2 / Math.log(base)); - var groupSize = groupSizes[base]; // var groupBase = Math.pow(base, groupSize); - + var groupSize = groupSizes[base]; + // var groupBase = Math.pow(base, groupSize); var groupBase = groupBases[base]; out = ""; var c = this.clone(); c.negative = 0; - while (!c.isZero()) { var r = c.modn(groupBase).toString(base); c = c.idivn(groupBase); - if (!c.isZero()) { out = zeros[groupSize - r.length] + r + out; } else { out = r + out; } } - if (this.isZero()) { out = "0" + out; } - while (out.length % padding !== 0) { out = "0" + out; } - if ((this || _global$1).negative !== 0) { out = "-" + out; } - return out; } - assert(false, "Base should be between 2 and 36"); }; - BN.prototype.toNumber = function toNumber() { var ret = (this || _global$1).words[0]; - if ((this || _global$1).length === 2) { ret += (this || _global$1).words[1] * 67108864; } else if ((this || _global$1).length === 3 && (this || _global$1).words[2] === 1) { @@ -72549,23 +106652,18 @@ function dew$6() { } else if ((this || _global$1).length > 2) { assert(false, "Number can only safely store up to 53 bits"); } - return (this || _global$1).negative !== 0 ? -ret : ret; }; - BN.prototype.toJSON = function toJSON() { return this.toString(16); }; - BN.prototype.toBuffer = function toBuffer(endian, length) { assert(typeof Buffer !== "undefined"); return this.toArrayLike(Buffer, endian, length); }; - BN.prototype.toArray = function toArray(endian, length) { return this.toArrayLike(Array, endian, length); }; - BN.prototype.toArrayLike = function toArrayLike(ArrayType, endian, length) { var byteLength = this.byteLength(); var reqLength = length || Math.max(1, byteLength); @@ -72576,13 +106674,11 @@ function dew$6() { var res = new ArrayType(reqLength); var b, i; var q = this.clone(); - if (!littleEndian) { // Assume big-endian for (i = 0; i < reqLength - byteLength; i++) { res[i] = 0; } - for (i = 0; !q.isZero(); i++) { b = q.andln(255); q.iushrn(8); @@ -72594,15 +106690,12 @@ function dew$6() { q.iushrn(8); res[i] = b; } - for (; i < reqLength; i++) { res[i] = 0; } } - return res; }; - if (Math.clz32) { BN.prototype._countBits = function _countBits(w) { return 32 - Math.clz32(w); @@ -72611,207 +106704,169 @@ function dew$6() { BN.prototype._countBits = function _countBits(w) { var t = w; var r = 0; - if (t >= 4096) { r += 13; t >>>= 13; } - if (t >= 64) { r += 7; t >>>= 7; } - if (t >= 8) { r += 4; t >>>= 4; } - if (t >= 2) { r += 2; t >>>= 2; } - return r + t; }; } - BN.prototype._zeroBits = function _zeroBits(w) { // Short-cut if (w === 0) return 26; var t = w; var r = 0; - if ((t & 8191) === 0) { r += 13; t >>>= 13; } - if ((t & 127) === 0) { r += 7; t >>>= 7; } - if ((t & 15) === 0) { r += 4; t >>>= 4; } - if ((t & 3) === 0) { r += 2; t >>>= 2; } - if ((t & 1) === 0) { r++; } - return r; - }; // Return number of used bits in a BN - + }; + // Return number of used bits in a BN BN.prototype.bitLength = function bitLength() { var w = (this || _global$1).words[(this || _global$1).length - 1]; - var hi = this._countBits(w); - return ((this || _global$1).length - 1) * 26 + hi; }; - function toBitArray(num) { var w = new Array(num.bitLength()); - for (var bit = 0; bit < w.length; bit++) { var off = bit / 26 | 0; var wbit = bit % 26; w[bit] = (num.words[off] & 1 << wbit) >>> wbit; } - return w; - } // Number of trailing zero bits - + } + // Number of trailing zero bits BN.prototype.zeroBits = function zeroBits() { if (this.isZero()) return 0; var r = 0; - for (var i = 0; i < (this || _global$1).length; i++) { var b = this._zeroBits((this || _global$1).words[i]); - r += b; if (b !== 26) break; } - return r; }; - BN.prototype.byteLength = function byteLength() { return Math.ceil(this.bitLength() / 8); }; - BN.prototype.toTwos = function toTwos(width) { if ((this || _global$1).negative !== 0) { return this.abs().inotn(width).iaddn(1); } - return this.clone(); }; - BN.prototype.fromTwos = function fromTwos(width) { if (this.testn(width - 1)) { return this.notn(width).iaddn(1).ineg(); } - return this.clone(); }; - BN.prototype.isNeg = function isNeg() { return (this || _global$1).negative !== 0; - }; // Return negative clone of `this` - + }; + // Return negative clone of `this` BN.prototype.neg = function neg() { return this.clone().ineg(); }; - BN.prototype.ineg = function ineg() { if (!this.isZero()) { (this || _global$1).negative ^= 1; } - return this || _global$1; - }; // Or `num` with `this` in-place - + }; + // Or `num` with `this` in-place BN.prototype.iuor = function iuor(num) { while ((this || _global$1).length < num.length) { (this || _global$1).words[(this || _global$1).length++] = 0; } - for (var i = 0; i < num.length; i++) { (this || _global$1).words[i] = (this || _global$1).words[i] | num.words[i]; } - return this.strip(); }; - BN.prototype.ior = function ior(num) { assert(((this || _global$1).negative | num.negative) === 0); return this.iuor(num); - }; // Or `num` with `this` - + }; + // Or `num` with `this` BN.prototype.or = function or(num) { if ((this || _global$1).length > num.length) return this.clone().ior(num); return num.clone().ior(this || _global$1); }; - BN.prototype.uor = function uor(num) { if ((this || _global$1).length > num.length) return this.clone().iuor(num); return num.clone().iuor(this || _global$1); - }; // And `num` with `this` in-place - + }; + // And `num` with `this` in-place BN.prototype.iuand = function iuand(num) { // b = min-length(num, this) var b; - if ((this || _global$1).length > num.length) { b = num; } else { b = this || _global$1; } - for (var i = 0; i < b.length; i++) { (this || _global$1).words[i] = (this || _global$1).words[i] & num.words[i]; } - (this || _global$1).length = b.length; return this.strip(); }; - BN.prototype.iand = function iand(num) { assert(((this || _global$1).negative | num.negative) === 0); return this.iuand(num); - }; // And `num` with `this` - + }; + // And `num` with `this` BN.prototype.and = function and(num) { if ((this || _global$1).length > num.length) return this.clone().iand(num); return num.clone().iand(this || _global$1); }; - BN.prototype.uand = function uand(num) { if ((this || _global$1).length > num.length) return this.clone().iuand(num); return num.clone().iuand(this || _global$1); - }; // Xor `num` with `this` in-place - + }; + // Xor `num` with `this` in-place BN.prototype.iuxor = function iuxor(num) { // a.length > b.length var a; var b; - if ((this || _global$1).length > num.length) { a = this || _global$1; b = num; @@ -72819,103 +106874,96 @@ function dew$6() { a = num; b = this || _global$1; } - for (var i = 0; i < b.length; i++) { (this || _global$1).words[i] = a.words[i] ^ b.words[i]; } - if ((this || _global$1) !== a) { for (; i < a.length; i++) { (this || _global$1).words[i] = a.words[i]; } } - (this || _global$1).length = a.length; return this.strip(); }; - BN.prototype.ixor = function ixor(num) { assert(((this || _global$1).negative | num.negative) === 0); return this.iuxor(num); - }; // Xor `num` with `this` - + }; + // Xor `num` with `this` BN.prototype.xor = function xor(num) { if ((this || _global$1).length > num.length) return this.clone().ixor(num); return num.clone().ixor(this || _global$1); }; - BN.prototype.uxor = function uxor(num) { if ((this || _global$1).length > num.length) return this.clone().iuxor(num); return num.clone().iuxor(this || _global$1); - }; // Not ``this`` with ``width`` bitwidth - + }; + // Not ``this`` with ``width`` bitwidth BN.prototype.inotn = function inotn(width) { assert(typeof width === "number" && width >= 0); var bytesNeeded = Math.ceil(width / 26) | 0; - var bitsLeft = width % 26; // Extend the buffer with leading zeroes + var bitsLeft = width % 26; + // Extend the buffer with leading zeroes this._expand(bytesNeeded); - if (bitsLeft > 0) { bytesNeeded--; - } // Handle complete words - + } + // Handle complete words for (var i = 0; i < bytesNeeded; i++) { (this || _global$1).words[i] = ~(this || _global$1).words[i] & 67108863; - } // Handle the residue - + } + // Handle the residue if (bitsLeft > 0) { (this || _global$1).words[i] = ~(this || _global$1).words[i] & 67108863 >> 26 - bitsLeft; - } // And remove leading zeroes - + } + // And remove leading zeroes return this.strip(); }; - BN.prototype.notn = function notn(width) { return this.clone().inotn(width); - }; // Set `bit` of `this` - + }; + // Set `bit` of `this` BN.prototype.setn = function setn(bit, val) { assert(typeof bit === "number" && bit >= 0); var off = bit / 26 | 0; var wbit = bit % 26; - this._expand(off + 1); - if (val) { (this || _global$1).words[off] = (this || _global$1).words[off] | 1 << wbit; } else { (this || _global$1).words[off] = (this || _global$1).words[off] & ~(1 << wbit); } - return this.strip(); - }; // Add `num` to `this` in-place - + }; + // Add `num` to `this` in-place BN.prototype.iadd = function iadd(num) { - var r; // negative + positive + var r; + // negative + positive if ((this || _global$1).negative !== 0 && num.negative === 0) { (this || _global$1).negative = 0; r = this.isub(num); (this || _global$1).negative ^= 1; - return this._normSign(); // positive + negative + return this._normSign(); + + // positive + negative } else if ((this || _global$1).negative === 0 && num.negative !== 0) { num.negative = 0; r = this.isub(num); num.negative = 1; return r._normSign(); - } // a.length > b.length - + } + // a.length > b.length var a, b; - if ((this || _global$1).length > num.length) { a = this || _global$1; b = num; @@ -72923,39 +106971,33 @@ function dew$6() { a = num; b = this || _global$1; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) + (b.words[i] | 0) + carry; (this || _global$1).words[i] = r & 67108863; carry = r >>> 26; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; (this || _global$1).words[i] = r & 67108863; carry = r >>> 26; } - (this || _global$1).length = a.length; - if (carry !== 0) { (this || _global$1).words[(this || _global$1).length] = carry; - (this || _global$1).length++; // Copy the rest of the words + (this || _global$1).length++; + // Copy the rest of the words } else if (a !== (this || _global$1)) { for (; i < a.length; i++) { (this || _global$1).words[i] = a.words[i]; } } - return this || _global$1; - }; // Add `num` to `this` - + }; + // Add `num` to `this` BN.prototype.add = function add(num) { var res; - if (num.negative !== 0 && (this || _global$1).negative === 0) { num.negative = 0; res = this.sub(num); @@ -72967,39 +107009,40 @@ function dew$6() { (this || _global$1).negative = 1; return res; } - if ((this || _global$1).length > num.length) return this.clone().iadd(num); return num.clone().iadd(this || _global$1); - }; // Subtract `num` from `this` in-place - + }; + // Subtract `num` from `this` in-place BN.prototype.isub = function isub(num) { // this - (-num) = this + num if (num.negative !== 0) { num.negative = 0; var r = this.iadd(num); num.negative = 1; - return r._normSign(); // -this - num = -(this + num) + return r._normSign(); + + // -this - num = -(this + num) } else if ((this || _global$1).negative !== 0) { (this || _global$1).negative = 0; this.iadd(num); (this || _global$1).negative = 1; return this._normSign(); - } // At this point both numbers are positive - + } - var cmp = this.cmp(num); // Optimization - zeroify + // At this point both numbers are positive + var cmp = this.cmp(num); + // Optimization - zeroify if (cmp === 0) { (this || _global$1).negative = 0; (this || _global$1).length = 1; (this || _global$1).words[0] = 0; return this || _global$1; - } // a > b - + } + // a > b var a, b; - if (cmp > 0) { a = this || _global$1; b = num; @@ -73007,62 +107050,54 @@ function dew$6() { a = num; b = this || _global$1; } - var carry = 0; - for (var i = 0; i < b.length; i++) { r = (a.words[i] | 0) - (b.words[i] | 0) + carry; carry = r >> 26; (this || _global$1).words[i] = r & 67108863; } - for (; carry !== 0 && i < a.length; i++) { r = (a.words[i] | 0) + carry; carry = r >> 26; (this || _global$1).words[i] = r & 67108863; - } // Copy rest of the words - + } + // Copy rest of the words if (carry === 0 && i < a.length && a !== (this || _global$1)) { for (; i < a.length; i++) { (this || _global$1).words[i] = a.words[i]; } } - (this || _global$1).length = Math.max((this || _global$1).length, i); - if (a !== (this || _global$1)) { (this || _global$1).negative = 1; } - return this.strip(); - }; // Subtract `num` from `this` - + }; + // Subtract `num` from `this` BN.prototype.sub = function sub(num) { return this.clone().isub(num); }; - function smallMulTo(self, num, out) { out.negative = num.negative ^ self.negative; var len = self.length + num.length | 0; out.length = len; - len = len - 1 | 0; // Peel one iteration (compiler can't do it, because of code complexity) + len = len - 1 | 0; + // Peel one iteration (compiler can't do it, because of code complexity) var a = self.words[0] | 0; var b = num.words[0] | 0; var r = a * b; var lo = r & 67108863; var carry = r / 67108864 | 0; out.words[0] = lo; - for (var k = 1; k < len; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff var ncarry = carry >>> 26; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j | 0; a = self.words[i] | 0; @@ -73071,23 +107106,20 @@ function dew$6() { ncarry += r / 67108864 | 0; rword = r & 67108863; } - out.words[k] = rword | 0; carry = ncarry | 0; } - if (carry !== 0) { out.words[k] = carry | 0; } else { out.length--; } - return out.strip(); - } // TODO(indutny): it may be reasonable to omit it for users who don't need + } + + // TODO(indutny): it may be reasonable to omit it for users who don't need // to work with 256-bit numbers, otherwise it gives 20% improvement for 256-bit // multiplication (like elliptic secp256k1). - - var comb10MulTo = function comb10MulTo(self, num, out) { var a = self.words; var b = num.words; @@ -73159,7 +107191,6 @@ function dew$6() { out.negative = self.negative ^ num.negative; out.length = 19; /* k = 0 */ - lo = Math.imul(al0, bl0); mid = Math.imul(al0, bh0); mid = mid + Math.imul(ah0, bl0) | 0; @@ -73168,7 +107199,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w0 >>> 26) | 0; w0 &= 67108863; /* k = 1 */ - lo = Math.imul(al1, bl0); mid = Math.imul(al1, bh0); mid = mid + Math.imul(ah1, bl0) | 0; @@ -73181,7 +107211,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w1 >>> 26) | 0; w1 &= 67108863; /* k = 2 */ - lo = Math.imul(al2, bl0); mid = Math.imul(al2, bh0); mid = mid + Math.imul(ah2, bl0) | 0; @@ -73198,7 +107227,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w2 >>> 26) | 0; w2 &= 67108863; /* k = 3 */ - lo = Math.imul(al3, bl0); mid = Math.imul(al3, bh0); mid = mid + Math.imul(ah3, bl0) | 0; @@ -73219,7 +107247,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w3 >>> 26) | 0; w3 &= 67108863; /* k = 4 */ - lo = Math.imul(al4, bl0); mid = Math.imul(al4, bh0); mid = mid + Math.imul(ah4, bl0) | 0; @@ -73244,7 +107271,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w4 >>> 26) | 0; w4 &= 67108863; /* k = 5 */ - lo = Math.imul(al5, bl0); mid = Math.imul(al5, bh0); mid = mid + Math.imul(ah5, bl0) | 0; @@ -73273,7 +107299,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w5 >>> 26) | 0; w5 &= 67108863; /* k = 6 */ - lo = Math.imul(al6, bl0); mid = Math.imul(al6, bh0); mid = mid + Math.imul(ah6, bl0) | 0; @@ -73306,7 +107331,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w6 >>> 26) | 0; w6 &= 67108863; /* k = 7 */ - lo = Math.imul(al7, bl0); mid = Math.imul(al7, bh0); mid = mid + Math.imul(ah7, bl0) | 0; @@ -73343,7 +107367,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w7 >>> 26) | 0; w7 &= 67108863; /* k = 8 */ - lo = Math.imul(al8, bl0); mid = Math.imul(al8, bh0); mid = mid + Math.imul(ah8, bl0) | 0; @@ -73384,7 +107407,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w8 >>> 26) | 0; w8 &= 67108863; /* k = 9 */ - lo = Math.imul(al9, bl0); mid = Math.imul(al9, bh0); mid = mid + Math.imul(ah9, bl0) | 0; @@ -73429,7 +107451,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w9 >>> 26) | 0; w9 &= 67108863; /* k = 10 */ - lo = Math.imul(al9, bl1); mid = Math.imul(al9, bh1); mid = mid + Math.imul(ah9, bl1) | 0; @@ -73470,7 +107491,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w10 >>> 26) | 0; w10 &= 67108863; /* k = 11 */ - lo = Math.imul(al9, bl2); mid = Math.imul(al9, bh2); mid = mid + Math.imul(ah9, bl2) | 0; @@ -73507,7 +107527,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w11 >>> 26) | 0; w11 &= 67108863; /* k = 12 */ - lo = Math.imul(al9, bl3); mid = Math.imul(al9, bh3); mid = mid + Math.imul(ah9, bl3) | 0; @@ -73540,7 +107559,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w12 >>> 26) | 0; w12 &= 67108863; /* k = 13 */ - lo = Math.imul(al9, bl4); mid = Math.imul(al9, bh4); mid = mid + Math.imul(ah9, bl4) | 0; @@ -73569,7 +107587,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w13 >>> 26) | 0; w13 &= 67108863; /* k = 14 */ - lo = Math.imul(al9, bl5); mid = Math.imul(al9, bh5); mid = mid + Math.imul(ah9, bl5) | 0; @@ -73594,7 +107611,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w14 >>> 26) | 0; w14 &= 67108863; /* k = 15 */ - lo = Math.imul(al9, bl6); mid = Math.imul(al9, bh6); mid = mid + Math.imul(ah9, bl6) | 0; @@ -73615,7 +107631,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w15 >>> 26) | 0; w15 &= 67108863; /* k = 16 */ - lo = Math.imul(al9, bl7); mid = Math.imul(al9, bh7); mid = mid + Math.imul(ah9, bl7) | 0; @@ -73632,7 +107647,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w16 >>> 26) | 0; w16 &= 67108863; /* k = 17 */ - lo = Math.imul(al9, bl8); mid = Math.imul(al9, bh8); mid = mid + Math.imul(ah9, bl8) | 0; @@ -73645,7 +107659,6 @@ function dew$6() { c = (hi + (mid >>> 13) | 0) + (w17 >>> 26) | 0; w17 &= 67108863; /* k = 18 */ - lo = Math.imul(al9, bl9); mid = Math.imul(al9, bh9); mid = mid + Math.imul(ah9, bl9) | 0; @@ -73672,26 +107685,22 @@ function dew$6() { o[16] = w16; o[17] = w17; o[18] = w18; - if (c !== 0) { o[19] = c; out.length++; } - return out; - }; // Polyfill comb - + }; + // Polyfill comb if (!Math.imul) { comb10MulTo = smallMulTo; } - function bigMulTo(self, num, out) { out.negative = num.negative ^ self.negative; out.length = self.length + num.length; var carry = 0; var hncarry = 0; - for (var k = 0; k < out.length - 1; k++) { // Sum all words with the same `i + j = k` and accumulate `ncarry`, // note that ncarry could be >= 0x3ffffff @@ -73699,7 +107708,6 @@ function dew$6() { hncarry = 0; var rword = carry & 67108863; var maxJ = Math.min(k, num.length - 1); - for (var j = Math.max(0, k - self.length + 1); j <= maxJ; j++) { var i = k - j; var a = self.words[i] | 0; @@ -73713,30 +107721,24 @@ function dew$6() { hncarry += ncarry >>> 26; ncarry &= 67108863; } - out.words[k] = rword; carry = ncarry; ncarry = hncarry; } - if (carry !== 0) { out.words[k] = carry; } else { out.length--; } - return out.strip(); } - function jumboMulTo(self, num, out) { var fftm = new FFTM(); return fftm.mulp(self, num, out); } - BN.prototype.mulTo = function mulTo(num, out) { var res; var len = (this || _global$1).length + num.length; - if ((this || _global$1).length === 10 && num.length === 10) { res = comb10MulTo(this || _global$1, num, out); } else if (len < 63) { @@ -73746,62 +107748,53 @@ function dew$6() { } else { res = jumboMulTo(this || _global$1, num, out); } - return res; - }; // Cooley-Tukey algorithm for FFT - // slightly revisited to rely on looping instead of recursion + }; + // Cooley-Tukey algorithm for FFT + // slightly revisited to rely on looping instead of recursion function FFTM(x, y) { (this || _global$1).x = x; (this || _global$1).y = y; } - FFTM.prototype.makeRBT = function makeRBT(N) { var t = new Array(N); var l = BN.prototype._countBits(N) - 1; - for (var i = 0; i < N; i++) { t[i] = this.revBin(i, l, N); } - return t; - }; // Returns binary-reversed representation of `x` - + }; + // Returns binary-reversed representation of `x` FFTM.prototype.revBin = function revBin(x, l, N) { if (x === 0 || x === N - 1) return x; var rb = 0; - for (var i = 0; i < l; i++) { rb |= (x & 1) << l - i - 1; x >>= 1; } - return rb; - }; // Performs "tweedling" phase, therefore 'emulating' - // behaviour of the recursive algorithm - + }; + // Performs "tweedling" phase, therefore 'emulating' + // behaviour of the recursive algorithm FFTM.prototype.permute = function permute(rbt, rws, iws, rtws, itws, N) { for (var i = 0; i < N; i++) { rtws[i] = rws[rbt[i]]; itws[i] = iws[rbt[i]]; } }; - FFTM.prototype.transform = function transform(rws, iws, rtws, itws, N, rbt) { this.permute(rbt, rws, iws, rtws, itws, N); - for (var s = 1; s < N; s <<= 1) { var l = s << 1; var rtwdf = Math.cos(2 * Math.PI / l); var itwdf = Math.sin(2 * Math.PI / l); - for (var p = 0; p < N; p += l) { var rtwdf_ = rtwdf; var itwdf_ = itwdf; - for (var j = 0; j < s; j++) { var re = rtws[p + j]; var ie = itws[p + j]; @@ -73814,8 +107807,8 @@ function dew$6() { itws[p + j] = ie + io; rtws[p + j + s] = re - ro; itws[p + j + s] = ie - io; - /* jshint maxdepth : false */ + /* jshint maxdepth : false */ if (j !== l) { rx = rtwdf * rtwdf_ - itwdf * itwdf_; itwdf_ = rtwdf * itwdf_ + itwdf * rtwdf_; @@ -73825,22 +107818,17 @@ function dew$6() { } } }; - FFTM.prototype.guessLen13b = function guessLen13b(n, m) { var N = Math.max(m, n) | 1; var odd = N & 1; var i = 0; - for (N = N / 2 | 0; N; N = N >>> 1) { i++; } - return 1 << i + 1 + odd; }; - FFTM.prototype.conjugate = function conjugate(rws, iws, N) { if (N <= 1) return; - for (var i = 0; i < N / 2; i++) { var t = rws[i]; rws[i] = rws[N - i - 1]; @@ -73850,60 +107838,47 @@ function dew$6() { iws[N - i - 1] = -t; } }; - FFTM.prototype.normalize13b = function normalize13b(ws, N) { var carry = 0; - for (var i = 0; i < N / 2; i++) { var w = Math.round(ws[2 * i + 1] / N) * 8192 + Math.round(ws[2 * i] / N) + carry; ws[i] = w & 67108863; - if (w < 67108864) { carry = 0; } else { carry = w / 67108864 | 0; } } - return ws; }; - FFTM.prototype.convert13b = function convert13b(ws, len, rws, N) { var carry = 0; - for (var i = 0; i < len; i++) { carry = carry + (ws[i] | 0); rws[2 * i] = carry & 8191; carry = carry >>> 13; rws[2 * i + 1] = carry & 8191; carry = carry >>> 13; - } // Pad with zeroes - + } + // Pad with zeroes for (i = 2 * len; i < N; ++i) { rws[i] = 0; } - assert(carry === 0); assert((carry & ~8191) === 0); }; - FFTM.prototype.stub = function stub(N) { var ph = new Array(N); - for (var i = 0; i < N; i++) { ph[i] = 0; } - return ph; }; - FFTM.prototype.mulp = function mulp(x, y, out) { var N = 2 * this.guessLen13b(x.length, y.length); var rbt = this.makeRBT(N); - var _ = this.stub(N); - var rws = new Array(N); var rwst = new Array(N); var iwst = new Array(N); @@ -73916,13 +107891,11 @@ function dew$6() { this.convert13b(y.words, y.length, nrws, N); this.transform(rws, _, rwst, iwst, N, rbt); this.transform(nrws, _, nrwst, niwst, N, rbt); - for (var i = 0; i < N; i++) { var rx = rwst[i] * nrwst[i] - iwst[i] * niwst[i]; iwst[i] = rwst[i] * niwst[i] + iwst[i] * nrwst[i]; rwst[i] = rx; } - this.conjugate(rwst, iwst, N); this.transform(rwst, iwst, rmws, _, N, rbt); this.conjugate(rmws, _, N); @@ -73930,162 +107903,144 @@ function dew$6() { out.negative = x.negative ^ y.negative; out.length = x.length + y.length; return out.strip(); - }; // Multiply `this` by `num` - + }; + // Multiply `this` by `num` BN.prototype.mul = function mul(num) { var out = new BN(null); out.words = new Array((this || _global$1).length + num.length); return this.mulTo(num, out); - }; // Multiply employing FFT - + }; + // Multiply employing FFT BN.prototype.mulf = function mulf(num) { var out = new BN(null); out.words = new Array((this || _global$1).length + num.length); return jumboMulTo(this || _global$1, num, out); - }; // In-place Multiplication - + }; + // In-place Multiplication BN.prototype.imul = function imul(num) { return this.clone().mulTo(num, this || _global$1); }; - BN.prototype.imuln = function imuln(num) { assert(typeof num === "number"); - assert(num < 67108864); // Carry + assert(num < 67108864); + // Carry var carry = 0; - for (var i = 0; i < (this || _global$1).length; i++) { var w = ((this || _global$1).words[i] | 0) * num; var lo = (w & 67108863) + (carry & 67108863); carry >>= 26; - carry += w / 67108864 | 0; // NOTE: lo is 27bit maximum - + carry += w / 67108864 | 0; + // NOTE: lo is 27bit maximum carry += lo >>> 26; (this || _global$1).words[i] = lo & 67108863; } - if (carry !== 0) { (this || _global$1).words[i] = carry; (this || _global$1).length++; } - return this || _global$1; }; - BN.prototype.muln = function muln(num) { return this.clone().imuln(num); - }; // `this` * `this` - + }; + // `this` * `this` BN.prototype.sqr = function sqr() { return this.mul(this || _global$1); - }; // `this` * `this` in-place - + }; + // `this` * `this` in-place BN.prototype.isqr = function isqr() { return this.imul(this.clone()); - }; // Math.pow(`this`, `num`) - + }; + // Math.pow(`this`, `num`) BN.prototype.pow = function pow(num) { var w = toBitArray(num); - if (w.length === 0) return new BN(1); // Skip leading zeroes + if (w.length === 0) return new BN(1); + // Skip leading zeroes var res = this || _global$1; - for (var i = 0; i < w.length; i++, res = res.sqr()) { if (w[i] !== 0) break; } - if (++i < w.length) { for (var q = res.sqr(); i < w.length; i++, q = q.sqr()) { if (w[i] === 0) continue; res = res.mul(q); } } - return res; - }; // Shift-left in-place - + }; + // Shift-left in-place BN.prototype.iushln = function iushln(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; var carryMask = 67108863 >>> 26 - r << 26 - r; var i; - if (r !== 0) { var carry = 0; - for (i = 0; i < (this || _global$1).length; i++) { var newCarry = (this || _global$1).words[i] & carryMask; var c = ((this || _global$1).words[i] | 0) - newCarry << r; (this || _global$1).words[i] = c | carry; carry = newCarry >>> 26 - r; } - if (carry) { (this || _global$1).words[i] = carry; (this || _global$1).length++; } } - if (s !== 0) { for (i = (this || _global$1).length - 1; i >= 0; i--) { (this || _global$1).words[i + s] = (this || _global$1).words[i]; } - for (i = 0; i < s; i++) { (this || _global$1).words[i] = 0; } - (this || _global$1).length += s; } - return this.strip(); }; - BN.prototype.ishln = function ishln(bits) { // TODO(indutny): implement me assert((this || _global$1).negative === 0); return this.iushln(bits); - }; // Shift-right in-place + }; + + // Shift-right in-place // NOTE: `hint` is a lowest bit before trailing zeroes // NOTE: if `extended` is present - it will be filled with destroyed bits - - BN.prototype.iushrn = function iushrn(bits, hint, extended) { assert(typeof bits === "number" && bits >= 0); var h; - if (hint) { h = (hint - hint % 26) / 26; } else { h = 0; } - var r = bits % 26; var s = Math.min((bits - r) / 26, (this || _global$1).length); var mask = 67108863 ^ 67108863 >>> r << r; var maskedWords = extended; h -= s; - h = Math.max(0, h); // Extended mode, copy masked part + h = Math.max(0, h); + // Extended mode, copy masked part if (maskedWords) { for (var i = 0; i < s; i++) { maskedWords.words[i] = (this || _global$1).words[i]; } - maskedWords.length = s; } - if (s === 0) ; else if ((this || _global$1).length > s) { (this || _global$1).length -= s; - for (i = 0; i < (this || _global$1).length; i++) { (this || _global$1).words[i] = (this || _global$1).words[i + s]; } @@ -74093,150 +108048,135 @@ function dew$6() { (this || _global$1).words[0] = 0; (this || _global$1).length = 1; } - var carry = 0; - for (i = (this || _global$1).length - 1; i >= 0 && (carry !== 0 || i >= h); i--) { var word = (this || _global$1).words[i] | 0; (this || _global$1).words[i] = carry << 26 - r | word >>> r; carry = word & mask; - } // Push carried bits as a mask - + } + // Push carried bits as a mask if (maskedWords && carry !== 0) { maskedWords.words[maskedWords.length++] = carry; } - if ((this || _global$1).length === 0) { (this || _global$1).words[0] = 0; (this || _global$1).length = 1; } - return this.strip(); }; - BN.prototype.ishrn = function ishrn(bits, hint, extended) { // TODO(indutny): implement me assert((this || _global$1).negative === 0); return this.iushrn(bits, hint, extended); - }; // Shift-left - + }; + // Shift-left BN.prototype.shln = function shln(bits) { return this.clone().ishln(bits); }; - BN.prototype.ushln = function ushln(bits) { return this.clone().iushln(bits); - }; // Shift-right - + }; + // Shift-right BN.prototype.shrn = function shrn(bits) { return this.clone().ishrn(bits); }; - BN.prototype.ushrn = function ushrn(bits) { return this.clone().iushrn(bits); - }; // Test if n bit is set - + }; + // Test if n bit is set BN.prototype.testn = function testn(bit) { assert(typeof bit === "number" && bit >= 0); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; - if ((this || _global$1).length <= s) return false; // Check bit and return + // Fast case: bit is much higher than all existing words + if ((this || _global$1).length <= s) return false; + // Check bit and return var w = (this || _global$1).words[s]; return !!(w & q); - }; // Return only lowers bits of number (in-place) - + }; + // Return only lowers bits of number (in-place) BN.prototype.imaskn = function imaskn(bits) { assert(typeof bits === "number" && bits >= 0); var r = bits % 26; var s = (bits - r) / 26; assert((this || _global$1).negative === 0, "imaskn works only with positive numbers"); - if ((this || _global$1).length <= s) { return this || _global$1; } - if (r !== 0) { s++; } - (this || _global$1).length = Math.min(s, (this || _global$1).length); - if (r !== 0) { var mask = 67108863 ^ 67108863 >>> r << r; (this || _global$1).words[(this || _global$1).length - 1] &= mask; } - return this.strip(); - }; // Return only lowers bits of number - + }; + // Return only lowers bits of number BN.prototype.maskn = function maskn(bits) { - return this.clone().imaskn(bits); - }; // Add plain number `num` to `this` - + return this.clone().imaskn(bits); + }; + // Add plain number `num` to `this` BN.prototype.iaddn = function iaddn(num) { assert(typeof num === "number"); assert(num < 67108864); - if (num < 0) return this.isubn(-num); // Possible sign change + if (num < 0) return this.isubn(-num); + // Possible sign change if ((this || _global$1).negative !== 0) { if ((this || _global$1).length === 1 && ((this || _global$1).words[0] | 0) < num) { (this || _global$1).words[0] = num - ((this || _global$1).words[0] | 0); (this || _global$1).negative = 0; return this || _global$1; } - (this || _global$1).negative = 0; this.isubn(num); (this || _global$1).negative = 1; return this || _global$1; - } // Add without checks - + } + // Add without checks return this._iaddn(num); }; - BN.prototype._iaddn = function _iaddn(num) { - (this || _global$1).words[0] += num; // Carry + (this || _global$1).words[0] += num; + // Carry for (var i = 0; i < (this || _global$1).length && (this || _global$1).words[i] >= 67108864; i++) { (this || _global$1).words[i] -= 67108864; - if (i === (this || _global$1).length - 1) { (this || _global$1).words[i + 1] = 1; } else { (this || _global$1).words[i + 1]++; } } - (this || _global$1).length = Math.max((this || _global$1).length, i + 1); return this || _global$1; - }; // Subtract plain number `num` from `this` - + }; + // Subtract plain number `num` from `this` BN.prototype.isubn = function isubn(num) { assert(typeof num === "number"); assert(num < 67108864); if (num < 0) return this.iaddn(-num); - if ((this || _global$1).negative !== 0) { (this || _global$1).negative = 0; this.iaddn(num); (this || _global$1).negative = 1; return this || _global$1; } - (this || _global$1).words[0] -= num; - if ((this || _global$1).length === 1 && (this || _global$1).words[0] < 0) { (this || _global$1).words[0] = -(this || _global$1).words[0]; (this || _global$1).negative = 1; @@ -74247,36 +108187,27 @@ function dew$6() { (this || _global$1).words[i + 1] -= 1; } } - return this.strip(); }; - BN.prototype.addn = function addn(num) { return this.clone().iaddn(num); }; - BN.prototype.subn = function subn(num) { return this.clone().isubn(num); }; - BN.prototype.iabs = function iabs() { (this || _global$1).negative = 0; return this || _global$1; }; - BN.prototype.abs = function abs() { return this.clone().iabs(); }; - BN.prototype._ishlnsubmul = function _ishlnsubmul(num, mul, shift) { var len = num.length + shift; var i; - this._expand(len); - var w; var carry = 0; - for (i = 0; i < num.length; i++) { w = ((this || _global$1).words[i + shift] | 0) + carry; var right = (num.words[i] | 0) * mul; @@ -74284,186 +108215,155 @@ function dew$6() { carry = (w >> 26) - (right / 67108864 | 0); (this || _global$1).words[i + shift] = w & 67108863; } - for (; i < (this || _global$1).length - shift; i++) { w = ((this || _global$1).words[i + shift] | 0) + carry; carry = w >> 26; (this || _global$1).words[i + shift] = w & 67108863; } + if (carry === 0) return this.strip(); - if (carry === 0) return this.strip(); // Subtraction overflow - + // Subtraction overflow assert(carry === -1); carry = 0; - for (i = 0; i < (this || _global$1).length; i++) { w = -((this || _global$1).words[i] | 0) + carry; carry = w >> 26; (this || _global$1).words[i] = w & 67108863; } - (this || _global$1).negative = 1; return this.strip(); }; - BN.prototype._wordDiv = function _wordDiv(num, mode) { var shift = (this || _global$1).length - num.length; var a = this.clone(); - var b = num; // Normalize + var b = num; + // Normalize var bhi = b.words[b.length - 1] | 0; - var bhiBits = this._countBits(bhi); - shift = 26 - bhiBits; - if (shift !== 0) { b = b.ushln(shift); a.iushln(shift); bhi = b.words[b.length - 1] | 0; - } // Initialize quotient - + } + // Initialize quotient var m = a.length - b.length; var q; - if (mode !== "mod") { q = new BN(null); q.length = m + 1; q.words = new Array(q.length); - for (var i = 0; i < q.length; i++) { q.words[i] = 0; } } - var diff = a.clone()._ishlnsubmul(b, 1, m); - if (diff.negative === 0) { a = diff; - if (q) { q.words[m] = 1; } } - for (var j = m - 1; j >= 0; j--) { - var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max - // (0x7ffffff) + var qj = (a.words[b.length + j] | 0) * 67108864 + (a.words[b.length + j - 1] | 0); + // NOTE: (qj / bhi) is (0x3ffffff * 0x4000000 + 0x3ffffff) / 0x2000000 max + // (0x7ffffff) qj = Math.min(qj / bhi | 0, 67108863); - a._ishlnsubmul(b, qj, j); - while (a.negative !== 0) { qj--; a.negative = 0; - a._ishlnsubmul(b, 1, j); - if (!a.isZero()) { a.negative ^= 1; } } - if (q) { q.words[j] = qj; } } - if (q) { q.strip(); } + a.strip(); - a.strip(); // Denormalize - + // Denormalize if (mode !== "div" && shift !== 0) { a.iushrn(shift); } - return { div: q || null, mod: a }; - }; // NOTE: 1) `mode` can be set to `mod` to request mod only, + }; + + // NOTE: 1) `mode` can be set to `mod` to request mod only, // to `div` to request div only, or be absent to // request both div & mod // 2) `positive` is true if unsigned mod is requested - - BN.prototype.divmod = function divmod(num, mode, positive) { assert(!num.isZero()); - if (this.isZero()) { return { div: new BN(0), mod: new BN(0) }; } - var div, mod, res; - if ((this || _global$1).negative !== 0 && num.negative === 0) { res = this.neg().divmod(num, mode); - if (mode !== "mod") { div = res.div.neg(); } - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.iadd(num); } } - return { div: div, mod: mod }; } - if ((this || _global$1).negative === 0 && num.negative !== 0) { res = this.divmod(num.neg(), mode); - if (mode !== "mod") { div = res.div.neg(); } - return { div: div, mod: res.mod }; } - if (((this || _global$1).negative & num.negative) !== 0) { res = this.neg().divmod(num.neg(), mode); - if (mode !== "div") { mod = res.mod.neg(); - if (positive && mod.negative !== 0) { mod.isub(num); } } - return { div: res.div, mod: mod }; - } // Both numbers are positive at this point - // Strip both numbers to approximate shift value + } + // Both numbers are positive at this point + // Strip both numbers to approximate shift value if (num.length > (this || _global$1).length || this.cmp(num) < 0) { return { div: new BN(0), mod: this || _global$1 }; - } // Very short reduction - + } + // Very short reduction if (num.length === 1) { if (mode === "div") { return { @@ -74471,144 +108371,125 @@ function dew$6() { mod: null }; } - if (mode === "mod") { return { div: null, mod: new BN(this.modn(num.words[0])) }; } - return { div: this.divn(num.words[0]), mod: new BN(this.modn(num.words[0])) }; } - return this._wordDiv(num, mode); - }; // Find `this` / `num` - + }; + // Find `this` / `num` BN.prototype.div = function div(num) { return this.divmod(num, "div", false).div; - }; // Find `this` % `num` - + }; + // Find `this` % `num` BN.prototype.mod = function mod(num) { return this.divmod(num, "mod", false).mod; }; - BN.prototype.umod = function umod(num) { return this.divmod(num, "mod", true).mod; - }; // Find Round(`this` / `num`) - + }; + // Find Round(`this` / `num`) BN.prototype.divRound = function divRound(num) { - var dm = this.divmod(num); // Fast case - exact division + var dm = this.divmod(num); + // Fast case - exact division if (dm.mod.isZero()) return dm.div; var mod = dm.div.negative !== 0 ? dm.mod.isub(num) : dm.mod; var half = num.ushrn(1); var r2 = num.andln(1); - var cmp = mod.cmp(half); // Round down + var cmp = mod.cmp(half); - if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; // Round up + // Round down + if (cmp < 0 || r2 === 1 && cmp === 0) return dm.div; + // Round up return dm.div.negative !== 0 ? dm.div.isubn(1) : dm.div.iaddn(1); }; - BN.prototype.modn = function modn(num) { assert(num <= 67108863); var p = (1 << 26) % num; var acc = 0; - for (var i = (this || _global$1).length - 1; i >= 0; i--) { acc = (p * acc + ((this || _global$1).words[i] | 0)) % num; } - return acc; - }; // In-place division by number - + }; + // In-place division by number BN.prototype.idivn = function idivn(num) { assert(num <= 67108863); var carry = 0; - for (var i = (this || _global$1).length - 1; i >= 0; i--) { var w = ((this || _global$1).words[i] | 0) + carry * 67108864; (this || _global$1).words[i] = w / num | 0; carry = w % num; } - return this.strip(); }; - BN.prototype.divn = function divn(num) { return this.clone().idivn(num); }; - BN.prototype.egcd = function egcd(p) { assert(p.negative === 0); assert(!p.isZero()); var x = this || _global$1; var y = p.clone(); - if (x.negative !== 0) { x = x.umod(p); } else { x = x.clone(); - } // A * x + B * y = x - + } + // A * x + B * y = x var A = new BN(1); - var B = new BN(0); // C * x + D * y = y + var B = new BN(0); + // C * x + D * y = y var C = new BN(0); var D = new BN(1); var g = 0; - while (x.isEven() && y.isEven()) { x.iushrn(1); y.iushrn(1); ++g; } - var yp = y.clone(); var xp = x.clone(); - while (!x.isZero()) { for (var i = 0, im = 1; (x.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { x.iushrn(i); - while (i-- > 0) { if (A.isOdd() || B.isOdd()) { A.iadd(yp); B.isub(xp); } - A.iushrn(1); B.iushrn(1); } } - for (var j = 0, jm = 1; (y.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { y.iushrn(j); - while (j-- > 0) { if (C.isOdd() || D.isOdd()) { C.iadd(yp); D.isub(xp); } - C.iushrn(1); D.iushrn(1); } } - if (x.cmp(y) >= 0) { x.isub(y); A.isub(C); @@ -74619,62 +108500,50 @@ function dew$6() { D.isub(B); } } - return { a: C, b: D, gcd: y.iushln(g) }; - }; // This is reduced incarnation of the binary EEA + }; + + // This is reduced incarnation of the binary EEA // above, designated to invert members of the // _prime_ fields F(p) at a maximal speed - - BN.prototype._invmp = function _invmp(p) { assert(p.negative === 0); assert(!p.isZero()); var a = this || _global$1; var b = p.clone(); - if (a.negative !== 0) { a = a.umod(p); } else { a = a.clone(); } - var x1 = new BN(1); var x2 = new BN(0); var delta = b.clone(); - while (a.cmpn(1) > 0 && b.cmpn(1) > 0) { for (var i = 0, im = 1; (a.words[0] & im) === 0 && i < 26; ++i, im <<= 1); - if (i > 0) { a.iushrn(i); - while (i-- > 0) { if (x1.isOdd()) { x1.iadd(delta); } - x1.iushrn(1); } } - for (var j = 0, jm = 1; (b.words[0] & jm) === 0 && j < 26; ++j, jm <<= 1); - if (j > 0) { b.iushrn(j); - while (j-- > 0) { if (x2.isOdd()) { x2.iadd(delta); } - x2.iushrn(1); } } - if (a.cmp(b) >= 0) { a.isub(b); x1.isub(x2); @@ -74683,46 +108552,38 @@ function dew$6() { x2.isub(x1); } } - var res; - if (a.cmpn(1) === 0) { res = x1; } else { res = x2; } - if (res.cmpn(0) < 0) { res.iadd(p); } - return res; }; - BN.prototype.gcd = function gcd(num) { if (this.isZero()) return num.abs(); if (num.isZero()) return this.abs(); var a = this.clone(); var b = num.clone(); a.negative = 0; - b.negative = 0; // Remove common factor of two + b.negative = 0; + // Remove common factor of two for (var shift = 0; a.isEven() && b.isEven(); shift++) { a.iushrn(1); b.iushrn(1); } - do { while (a.isEven()) { a.iushrn(1); } - while (b.isEven()) { b.iushrn(1); } - var r = a.cmp(b); - if (r < 0) { // Swap `a` and `b` to make `a` always bigger than `b` var t = a; @@ -74731,48 +108592,43 @@ function dew$6() { } else if (r === 0 || b.cmpn(1) === 0) { break; } - a.isub(b); } while (true); - return b.iushln(shift); - }; // Invert number in the field F(num) - + }; + // Invert number in the field F(num) BN.prototype.invm = function invm(num) { return this.egcd(num).a.umod(num); }; - BN.prototype.isEven = function isEven() { return ((this || _global$1).words[0] & 1) === 0; }; - BN.prototype.isOdd = function isOdd() { return ((this || _global$1).words[0] & 1) === 1; - }; // And first word and num - + }; + // And first word and num BN.prototype.andln = function andln(num) { return (this || _global$1).words[0] & num; - }; // Increment at the bit position in-line - + }; + // Increment at the bit position in-line BN.prototype.bincn = function bincn(bit) { assert(typeof bit === "number"); var r = bit % 26; var s = (bit - r) / 26; - var q = 1 << r; // Fast case: bit is much higher than all existing words + var q = 1 << r; + // Fast case: bit is much higher than all existing words if ((this || _global$1).length <= s) { this._expand(s + 1); - (this || _global$1).words[s] |= q; return this || _global$1; - } // Add bit and propagate, if needed - + } + // Add bit and propagate, if needed var carry = q; - for (var i = s; carry !== 0 && i < (this || _global$1).length; i++) { var w = (this || _global$1).words[i] | 0; w += carry; @@ -74780,246 +108636,195 @@ function dew$6() { w &= 67108863; (this || _global$1).words[i] = w; } - if (carry !== 0) { (this || _global$1).words[i] = carry; (this || _global$1).length++; } - return this || _global$1; }; - BN.prototype.isZero = function isZero() { return (this || _global$1).length === 1 && (this || _global$1).words[0] === 0; }; - BN.prototype.cmpn = function cmpn(num) { var negative = num < 0; if ((this || _global$1).negative !== 0 && !negative) return -1; if ((this || _global$1).negative === 0 && negative) return 1; this.strip(); var res; - if ((this || _global$1).length > 1) { res = 1; } else { if (negative) { num = -num; } - assert(num <= 67108863, "Number is too big"); var w = (this || _global$1).words[0] | 0; res = w === num ? 0 : w < num ? -1 : 1; } - if ((this || _global$1).negative !== 0) return -res | 0; return res; - }; // Compare two numbers and return: + }; + + // Compare two numbers and return: // 1 - if `this` > `num` // 0 - if `this` == `num` // -1 - if `this` < `num` - - BN.prototype.cmp = function cmp(num) { if ((this || _global$1).negative !== 0 && num.negative === 0) return -1; if ((this || _global$1).negative === 0 && num.negative !== 0) return 1; var res = this.ucmp(num); if ((this || _global$1).negative !== 0) return -res | 0; return res; - }; // Unsigned comparison - + }; + // Unsigned comparison BN.prototype.ucmp = function ucmp(num) { // At this point both numbers have the same sign if ((this || _global$1).length > num.length) return 1; if ((this || _global$1).length < num.length) return -1; var res = 0; - for (var i = (this || _global$1).length - 1; i >= 0; i--) { var a = (this || _global$1).words[i] | 0; var b = num.words[i] | 0; if (a === b) continue; - if (a < b) { res = -1; } else if (a > b) { res = 1; } - break; } - return res; }; - BN.prototype.gtn = function gtn(num) { return this.cmpn(num) === 1; }; - BN.prototype.gt = function gt(num) { return this.cmp(num) === 1; }; - BN.prototype.gten = function gten(num) { return this.cmpn(num) >= 0; }; - BN.prototype.gte = function gte(num) { return this.cmp(num) >= 0; }; - BN.prototype.ltn = function ltn(num) { return this.cmpn(num) === -1; }; - BN.prototype.lt = function lt(num) { return this.cmp(num) === -1; }; - BN.prototype.lten = function lten(num) { return this.cmpn(num) <= 0; }; - BN.prototype.lte = function lte(num) { return this.cmp(num) <= 0; }; - BN.prototype.eqn = function eqn(num) { return this.cmpn(num) === 0; }; - BN.prototype.eq = function eq(num) { return this.cmp(num) === 0; - }; // + }; + + // // A reduce context, could be using montgomery or something better, depending // on the `m` itself. // - - BN.red = function red(num) { return new Red(num); }; - BN.prototype.toRed = function toRed(ctx) { assert(!(this || _global$1).red, "Already a number in reduction context"); assert((this || _global$1).negative === 0, "red works only with positives"); return ctx.convertTo(this || _global$1)._forceRed(ctx); }; - BN.prototype.fromRed = function fromRed() { assert((this || _global$1).red, "fromRed works only with numbers in reduction context"); return (this || _global$1).red.convertFrom(this || _global$1); }; - BN.prototype._forceRed = function _forceRed(ctx) { (this || _global$1).red = ctx; return this || _global$1; }; - BN.prototype.forceRed = function forceRed(ctx) { assert(!(this || _global$1).red, "Already a number in reduction context"); return this._forceRed(ctx); }; - BN.prototype.redAdd = function redAdd(num) { assert((this || _global$1).red, "redAdd works only with red numbers"); return (this || _global$1).red.add(this || _global$1, num); }; - BN.prototype.redIAdd = function redIAdd(num) { assert((this || _global$1).red, "redIAdd works only with red numbers"); return (this || _global$1).red.iadd(this || _global$1, num); }; - BN.prototype.redSub = function redSub(num) { assert((this || _global$1).red, "redSub works only with red numbers"); return (this || _global$1).red.sub(this || _global$1, num); }; - BN.prototype.redISub = function redISub(num) { assert((this || _global$1).red, "redISub works only with red numbers"); return (this || _global$1).red.isub(this || _global$1, num); }; - BN.prototype.redShl = function redShl(num) { assert((this || _global$1).red, "redShl works only with red numbers"); return (this || _global$1).red.shl(this || _global$1, num); }; - BN.prototype.redMul = function redMul(num) { assert((this || _global$1).red, "redMul works only with red numbers"); - (this || _global$1).red._verify2(this || _global$1, num); - return (this || _global$1).red.mul(this || _global$1, num); }; - BN.prototype.redIMul = function redIMul(num) { assert((this || _global$1).red, "redMul works only with red numbers"); - (this || _global$1).red._verify2(this || _global$1, num); - return (this || _global$1).red.imul(this || _global$1, num); }; - BN.prototype.redSqr = function redSqr() { assert((this || _global$1).red, "redSqr works only with red numbers"); - (this || _global$1).red._verify1(this || _global$1); - return (this || _global$1).red.sqr(this || _global$1); }; - BN.prototype.redISqr = function redISqr() { assert((this || _global$1).red, "redISqr works only with red numbers"); - (this || _global$1).red._verify1(this || _global$1); - return (this || _global$1).red.isqr(this || _global$1); - }; // Square root over p - + }; + // Square root over p BN.prototype.redSqrt = function redSqrt() { assert((this || _global$1).red, "redSqrt works only with red numbers"); - (this || _global$1).red._verify1(this || _global$1); - return (this || _global$1).red.sqrt(this || _global$1); }; - BN.prototype.redInvm = function redInvm() { assert((this || _global$1).red, "redInvm works only with red numbers"); - (this || _global$1).red._verify1(this || _global$1); - return (this || _global$1).red.invm(this || _global$1); - }; // Return negative clone of `this` % `red modulo` - + }; + // Return negative clone of `this` % `red modulo` BN.prototype.redNeg = function redNeg() { assert((this || _global$1).red, "redNeg works only with red numbers"); - (this || _global$1).red._verify1(this || _global$1); - return (this || _global$1).red.neg(this || _global$1); }; - BN.prototype.redPow = function redPow(num) { assert((this || _global$1).red && !num.red, "redPow(normalNum)"); - (this || _global$1).red._verify1(this || _global$1); - return (this || _global$1).red.pow(this || _global$1, num); - }; // Prime numbers with efficient reduction - + }; + // Prime numbers with efficient reduction var primes = { k256: null, p224: null, p192: null, p25519: null - }; // Pseudo-Mersenne prime + }; + // Pseudo-Mersenne prime function MPrime(name, p) { // P = 2 ^ N - K (this || _global$1).name = name; @@ -75028,28 +108833,23 @@ function dew$6() { (this || _global$1).k = new BN(1).iushln((this || _global$1).n).isub((this || _global$1).p); (this || _global$1).tmp = this._tmp(); } - MPrime.prototype._tmp = function _tmp() { var tmp = new BN(null); tmp.words = new Array(Math.ceil((this || _global$1).n / 13)); return tmp; }; - MPrime.prototype.ireduce = function ireduce(num) { // Assumes that `num` is less than `P^2` // num = HI * (2 ^ N - K) + HI * K + LO = HI * K + LO (mod P) var r = num; var rlen; - do { this.split(r, (this || _global$1).tmp); r = this.imulK(r); r = r.iadd((this || _global$1).tmp); rlen = r.bitLength(); } while (rlen > (this || _global$1).n); - var cmp = rlen < (this || _global$1).n ? -1 : r.ucmp((this || _global$1).p); - if (cmp === 0) { r.words[0] = 0; r.length = 1; @@ -75064,111 +108864,88 @@ function dew$6() { r._strip(); } } - return r; }; - MPrime.prototype.split = function split(input, out) { input.iushrn((this || _global$1).n, 0, out); }; - MPrime.prototype.imulK = function imulK(num) { return num.imul((this || _global$1).k); }; - function K256() { MPrime.call(this || _global$1, "k256", "ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f"); } - inherits(K256, MPrime); - K256.prototype.split = function split(input, output) { // 256 = 9 * 26 + 22 var mask = 4194303; var outLen = Math.min(input.length, 9); - for (var i = 0; i < outLen; i++) { output.words[i] = input.words[i]; } - output.length = outLen; - if (input.length <= 9) { input.words[0] = 0; input.length = 1; return; - } // Shift by 9 limbs - + } + // Shift by 9 limbs var prev = input.words[9]; output.words[output.length++] = prev & mask; - for (i = 10; i < input.length; i++) { var next = input.words[i] | 0; input.words[i - 10] = (next & mask) << 4 | prev >>> 22; prev = next; } - prev >>>= 22; input.words[i - 10] = prev; - if (prev === 0 && input.length > 10) { input.length -= 10; } else { input.length -= 9; } }; - K256.prototype.imulK = function imulK(num) { // K = 0x1000003d1 = [ 0x40, 0x3d1 ] num.words[num.length] = 0; num.words[num.length + 1] = 0; - num.length += 2; // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 + num.length += 2; + // bounded at: 0x40 * 0x3ffffff + 0x3d0 = 0x100000390 var lo = 0; - for (var i = 0; i < num.length; i++) { var w = num.words[i] | 0; lo += w * 977; num.words[i] = lo & 67108863; lo = w * 64 + (lo / 67108864 | 0); - } // Fast length reduction - + } + // Fast length reduction if (num.words[num.length - 1] === 0) { num.length--; - if (num.words[num.length - 1] === 0) { num.length--; } } - return num; }; - function P224() { MPrime.call(this || _global$1, "p224", "ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001"); } - inherits(P224, MPrime); - function P192() { MPrime.call(this || _global$1, "p192", "ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff"); } - inherits(P192, MPrime); - function P25519() { // 2 ^ 255 - 19 MPrime.call(this || _global$1, "25519", "7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed"); } - inherits(P25519, MPrime); - P25519.prototype.imulK = function imulK(num) { // K = 0x13 var carry = 0; - for (var i = 0; i < num.length; i++) { var hi = (num.words[i] | 0) * 19 + carry; var lo = hi & 67108863; @@ -75176,20 +108953,17 @@ function dew$6() { num.words[i] = lo; carry = hi; } - if (carry !== 0) { num.words[num.length++] = carry; } - return num; - }; // Exported mostly for testing purposes, use plain name instead - + }; + // Exported mostly for testing purposes, use plain name instead BN._prime = function prime(name) { // Cached version of prime if (primes[name]) return primes[name]; var prime; - if (name === "k256") { prime = new K256(); } else if (name === "p224") { @@ -75201,18 +108975,16 @@ function dew$6() { } else { throw new Error("Unknown prime " + name); } - primes[name] = prime; return prime; - }; // + }; + + // // Base reduction engine // - - function Red(m) { if (typeof m === "string") { var prime = BN._prime(m); - (this || _global$1).m = prime.p; (this || _global$1).prime = prime; } else { @@ -75221,156 +108993,115 @@ function dew$6() { (this || _global$1).prime = null; } } - Red.prototype._verify1 = function _verify1(a) { assert(a.negative === 0, "red works only with positives"); assert(a.red, "red works only with red numbers"); }; - Red.prototype._verify2 = function _verify2(a, b) { assert((a.negative | b.negative) === 0, "red works only with positives"); assert(a.red && a.red === b.red, "red works only with red numbers"); }; - Red.prototype.imod = function imod(a) { if ((this || _global$1).prime) return (this || _global$1).prime.ireduce(a)._forceRed(this || _global$1); return a.umod((this || _global$1).m)._forceRed(this || _global$1); }; - Red.prototype.neg = function neg(a) { if (a.isZero()) { return a.clone(); } - return (this || _global$1).m.sub(a)._forceRed(this || _global$1); }; - Red.prototype.add = function add(a, b) { this._verify2(a, b); - var res = a.add(b); - if (res.cmp((this || _global$1).m) >= 0) { res.isub((this || _global$1).m); } - return res._forceRed(this || _global$1); }; - Red.prototype.iadd = function iadd(a, b) { this._verify2(a, b); - var res = a.iadd(b); - if (res.cmp((this || _global$1).m) >= 0) { res.isub((this || _global$1).m); } - return res; }; - Red.prototype.sub = function sub(a, b) { this._verify2(a, b); - var res = a.sub(b); - if (res.cmpn(0) < 0) { res.iadd((this || _global$1).m); } - return res._forceRed(this || _global$1); }; - Red.prototype.isub = function isub(a, b) { this._verify2(a, b); - var res = a.isub(b); - if (res.cmpn(0) < 0) { res.iadd((this || _global$1).m); } - return res; }; - Red.prototype.shl = function shl(a, num) { this._verify1(a); - return this.imod(a.ushln(num)); }; - Red.prototype.imul = function imul(a, b) { this._verify2(a, b); - return this.imod(a.imul(b)); }; - Red.prototype.mul = function mul(a, b) { this._verify2(a, b); - return this.imod(a.mul(b)); }; - Red.prototype.isqr = function isqr(a) { return this.imul(a, a.clone()); }; - Red.prototype.sqr = function sqr(a) { return this.mul(a, a); }; - Red.prototype.sqrt = function sqrt(a) { if (a.isZero()) return a.clone(); - var mod3 = (this || _global$1).m.andln(3); + assert(mod3 % 2 === 1); - assert(mod3 % 2 === 1); // Fast case - + // Fast case if (mod3 === 3) { var pow = (this || _global$1).m.add(new BN(1)).iushrn(2); - return this.pow(a, pow); - } // Tonelli-Shanks algorithm (Totally unoptimized and slow) + } + + // Tonelli-Shanks algorithm (Totally unoptimized and slow) // // Find Q and S, that Q * 2 ^ S = (P - 1) - - var q = (this || _global$1).m.subn(1); - var s = 0; - while (!q.isZero() && q.andln(1) === 0) { s++; q.iushrn(1); } - assert(!q.isZero()); var one = new BN(1).toRed(this || _global$1); - var nOne = one.redNeg(); // Find quadratic non-residue - // NOTE: Max is such because of generalized Riemann hypothesis. + var nOne = one.redNeg(); + // Find quadratic non-residue + // NOTE: Max is such because of generalized Riemann hypothesis. var lpow = (this || _global$1).m.subn(1).iushrn(1); - var z = (this || _global$1).m.bitLength(); - z = new BN(2 * z * z).toRed(this || _global$1); - while (this.pow(z, lpow).cmp(nOne) !== 0) { z.redIAdd(nOne); } - var c = this.pow(z, q); var r = this.pow(a, q.addn(1).iushrn(1)); var t = this.pow(a, q); var m = s; - while (t.cmp(one) !== 0) { var tmp = t; - for (var i = 0; tmp.cmp(one) !== 0; i++) { tmp = tmp.redSqr(); } - assert(i < m); var b = this.pow(c, new BN(1).iushln(m - i - 1)); r = r.redMul(b); @@ -75378,13 +109109,10 @@ function dew$6() { t = t.redMul(c); m = i; } - return r; }; - Red.prototype.invm = function invm(a) { var inv = a._invmp((this || _global$1).m); - if (inv.negative !== 0) { inv.negative = 0; return this.imod(inv).redNeg(); @@ -75392,7 +109120,6 @@ function dew$6() { return this.imod(inv); } }; - Red.prototype.pow = function pow(a, num) { if (num.isZero()) return new BN(1).toRed(this || _global$1); if (num.cmpn(1) === 0) return a.clone(); @@ -75400,35 +109127,27 @@ function dew$6() { var wnd = new Array(1 << windowSize); wnd[0] = new BN(1).toRed(this || _global$1); wnd[1] = a; - for (var i = 2; i < wnd.length; i++) { wnd[i] = this.mul(wnd[i - 1], a); } - var res = wnd[0]; var current = 0; var currentLen = 0; var start = num.bitLength() % 26; - if (start === 0) { start = 26; } - for (i = num.length - 1; i >= 0; i--) { var word = num.words[i]; - for (var j = start - 1; j >= 0; j--) { var bit = word >> j & 1; - if (res !== wnd[0]) { res = this.sqr(res); } - if (bit === 0 && current === 0) { currentLen = 0; continue; } - current <<= 1; current |= bit; currentLen++; @@ -75437,39 +109156,33 @@ function dew$6() { currentLen = 0; current = 0; } - start = 26; } - return res; }; - Red.prototype.convertTo = function convertTo(num) { var r = num.umod((this || _global$1).m); return r === num ? r.clone() : r; }; - Red.prototype.convertFrom = function convertFrom(num) { var res = num.clone(); res.red = null; return res; - }; // + }; + + // // Montgomery method engine // - BN.mont = function mont(num) { return new Mont(num); }; - function Mont(m) { Red.call(this || _global$1, m); (this || _global$1).shift = (this || _global$1).m.bitLength(); - if ((this || _global$1).shift % 26 !== 0) { (this || _global$1).shift += 26 - (this || _global$1).shift % 26; } - (this || _global$1).r = new BN(1).iushln((this || _global$1).shift); (this || _global$1).r2 = this.imod((this || _global$1).r.sqr()); (this || _global$1).rinv = (this || _global$1).r._invmp((this || _global$1).m); @@ -75477,111 +109190,84 @@ function dew$6() { (this || _global$1).minv = (this || _global$1).minv.umod((this || _global$1).r); (this || _global$1).minv = (this || _global$1).r.sub((this || _global$1).minv); } - inherits(Mont, Red); - Mont.prototype.convertTo = function convertTo(num) { return this.imod(num.ushln((this || _global$1).shift)); }; - Mont.prototype.convertFrom = function convertFrom(num) { var r = this.imod(num.mul((this || _global$1).rinv)); r.red = null; return r; }; - Mont.prototype.imul = function imul(a, b) { if (a.isZero() || b.isZero()) { a.words[0] = 0; a.length = 1; return a; } - var t = a.imul(b); var c = t.maskn((this || _global$1).shift).mul((this || _global$1).minv).imaskn((this || _global$1).shift).mul((this || _global$1).m); var u = t.isub(c).iushrn((this || _global$1).shift); var res = u; - if (u.cmp((this || _global$1).m) >= 0) { res = u.isub((this || _global$1).m); } else if (u.cmpn(0) < 0) { res = u.iadd((this || _global$1).m); } - return res._forceRed(this || _global$1); }; - Mont.prototype.mul = function mul(a, b) { if (a.isZero() || b.isZero()) return new BN(0)._forceRed(this || _global$1); var t = a.mul(b); var c = t.maskn((this || _global$1).shift).mul((this || _global$1).minv).imaskn((this || _global$1).shift).mul((this || _global$1).m); var u = t.isub(c).iushrn((this || _global$1).shift); var res = u; - if (u.cmp((this || _global$1).m) >= 0) { res = u.isub((this || _global$1).m); } else if (u.cmpn(0) < 0) { res = u.iadd((this || _global$1).m); } - return res._forceRed(this || _global$1); }; - Mont.prototype.invm = function invm(a) { // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R var res = this.imod(a._invmp((this || _global$1).m).mul((this || _global$1).r2)); return res._forceRed(this || _global$1); }; })(module, exports$7); - return module.exports; } var exports$6 = {}, - _dewExec$5 = false; + _dewExec$5 = false; function dew$5() { if (_dewExec$5) return exports$6; _dewExec$5 = true; - var BN = dew$6(); - - var Buffer = dew$2P().Buffer; - + var Buffer = dew$3H().Buffer; function withPublic(paddedMsg, key) { return Buffer.from(paddedMsg.toRed(BN.mont(key.modulus)).redPow(new BN(key.publicExponent)).fromRed().toArray()); } - exports$6 = withPublic; return exports$6; } var exports$5 = {}, - _dewExec$4 = false; + _dewExec$4 = false; function dew$4() { if (_dewExec$4) return exports$5; _dewExec$4 = true; - var parseKeys = dew$e(); - - var randomBytes = dew$2O(); - - var createHash = dew$2y(); - + var randomBytes = dew$3G(); + var createHash = dew$3t(); var mgf = dew$8(); - var xor = dew$7(); - var BN = dew$6(); - var withPublic = dew$5(); - - var crt = dew$W(); - - var Buffer = dew$2P().Buffer; - + var crt = dew$$(); + var Buffer = dew$3H().Buffer; exports$5 = function publicEncrypt(publicKey, msg, reverse) { var padding; - if (publicKey.padding) { padding = publicKey.padding; } else if (reverse) { @@ -75589,42 +109275,35 @@ function dew$4() { } else { padding = 4; } - var key = parseKeys(publicKey); var paddedMsg; - if (padding === 4) { paddedMsg = oaep(key, msg); } else if (padding === 1) { paddedMsg = pkcs1(key, msg, reverse); } else if (padding === 3) { paddedMsg = new BN(msg); - if (paddedMsg.cmp(key.modulus) >= 0) { throw new Error("data too long for modulus"); } } else { throw new Error("unknown padding"); } - if (reverse) { return crt(paddedMsg, key); } else { return withPublic(paddedMsg, key); } }; - function oaep(key, msg) { var k = key.modulus.byteLength(); var mLen = msg.length; var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); var hLen = iHash.length; var hLen2 = 2 * hLen; - if (mLen > k - hLen2 - 2) { throw new Error("message too long"); } - var ps = Buffer.alloc(k - mLen - hLen2 - 2); var dblen = k - hLen - 1; var seed = randomBytes(hLen); @@ -75632,77 +109311,56 @@ function dew$4() { var maskedSeed = xor(seed, mgf(maskedDb, hLen)); return new BN(Buffer.concat([Buffer.alloc(1), maskedSeed, maskedDb], k)); } - function pkcs1(key, msg, reverse) { var mLen = msg.length; var k = key.modulus.byteLength(); - if (mLen > k - 11) { throw new Error("message too long"); } - var ps; - if (reverse) { ps = Buffer.alloc(k - mLen - 3, 255); } else { ps = nonZero(k - mLen - 3); } - return new BN(Buffer.concat([Buffer.from([0, reverse ? 1 : 2]), ps, Buffer.alloc(1), msg], k)); } - function nonZero(len) { var out = Buffer.allocUnsafe(len); var i = 0; var cache = randomBytes(len * 2); var cur = 0; var num; - while (i < len) { if (cur === cache.length) { cache = randomBytes(len * 2); cur = 0; } - num = cache[cur++]; - if (num) { out[i++] = num; } } - return out; } - return exports$5; } var exports$4 = {}, - _dewExec$3 = false; + _dewExec$3 = false; function dew$3() { if (_dewExec$3) return exports$4; _dewExec$3 = true; - var parseKeys = dew$e(); - var mgf = dew$8(); - var xor = dew$7(); - var BN = dew$6(); - - var crt = dew$W(); - - var createHash = dew$2y(); - + var crt = dew$$(); + var createHash = dew$3t(); var withPublic = dew$5(); - - var Buffer = dew$2P().Buffer; - + var Buffer = dew$3H().Buffer; exports$4 = function privateDecrypt(privateKey, enc, reverse) { var padding; - if (privateKey.padding) { padding = privateKey.padding; } else if (reverse) { @@ -75710,25 +109368,19 @@ function dew$3() { } else { padding = 4; } - var key = parseKeys(privateKey); var k = key.modulus.byteLength(); - if (enc.length > k || new BN(enc).cmp(key.modulus) >= 0) { throw new Error("decryption error"); } - var msg; - if (reverse) { msg = withPublic(new BN(enc), key); } else { msg = crt(enc, key); } - var zBuffer = Buffer.alloc(k - msg.length); msg = Buffer.concat([zBuffer, msg], k); - if (padding === 4) { return oaep(key, msg); } else if (padding === 1) { @@ -75739,162 +109391,125 @@ function dew$3() { throw new Error("unknown padding"); } }; - function oaep(key, msg) { var k = key.modulus.byteLength(); var iHash = createHash("sha1").update(Buffer.alloc(0)).digest(); var hLen = iHash.length; - if (msg[0] !== 0) { throw new Error("decryption error"); } - var maskedSeed = msg.slice(1, hLen + 1); var maskedDb = msg.slice(hLen + 1); var seed = xor(maskedSeed, mgf(maskedDb, hLen)); var db = xor(maskedDb, mgf(seed, k - hLen - 1)); - if (compare(iHash, db.slice(0, hLen))) { throw new Error("decryption error"); } - var i = hLen; - while (db[i] === 0) { i++; } - if (db[i++] !== 1) { throw new Error("decryption error"); } - return db.slice(i); } - function pkcs1(key, msg, reverse) { var p1 = msg.slice(0, 2); var i = 2; var status = 0; - while (msg[i++] !== 0) { if (i >= msg.length) { status++; break; } } - var ps = msg.slice(2, i - 1); - if (p1.toString("hex") !== "0002" && !reverse || p1.toString("hex") !== "0001" && reverse) { status++; } - if (ps.length < 8) { status++; } - if (status) { throw new Error("decryption error"); } - return msg.slice(i); } - function compare(a, b) { a = Buffer.from(a); b = Buffer.from(b); var dif = 0; var len = a.length; - if (a.length !== b.length) { dif++; len = Math.min(a.length, b.length); } - var i = -1; - while (++i < len) { dif += a[i] ^ b[i]; } - return dif; } - return exports$4; } var exports$3 = {}, - _dewExec$2 = false; + _dewExec$2 = false; function dew$2() { if (_dewExec$2) return exports$3; _dewExec$2 = true; exports$3.publicEncrypt = dew$4(); exports$3.privateDecrypt = dew$3(); - exports$3.privateEncrypt = function privateEncrypt(key, buf) { return exports$3.publicEncrypt(key, buf, true); }; - exports$3.publicDecrypt = function publicDecrypt(key, buf) { return exports$3.privateDecrypt(key, buf, true); }; - return exports$3; } var exports$2 = {}, - _dewExec$1 = false; - + _dewExec$1 = false; var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$1() { if (_dewExec$1) return exports$2; _dewExec$1 = true; var process$1 = process; - function oldBrowser() { throw new Error("secure random number generation not supported by this browser\nuse chrome, FireFox or Internet Explorer 11"); } - - var safeBuffer = dew$2P(); - - var randombytes = dew$2O(); - + var safeBuffer = dew$3H(); + var randombytes = dew$3G(); var Buffer = safeBuffer.Buffer; var kBufferMaxLength = safeBuffer.kMaxLength; var crypto = _global.crypto || _global.msCrypto; var kMaxUint32 = Math.pow(2, 32) - 1; - function assertOffset(offset, length) { if (typeof offset !== "number" || offset !== offset) { // eslint-disable-line no-self-compare throw new TypeError("offset must be a number"); } - if (offset > kMaxUint32 || offset < 0) { throw new TypeError("offset must be a uint32"); } - if (offset > kBufferMaxLength || offset > length) { throw new RangeError("offset out of range"); } } - function assertSize(size, offset, length) { if (typeof size !== "number" || size !== size) { // eslint-disable-line no-self-compare throw new TypeError("size must be a number"); } - if (size > kMaxUint32 || size < 0) { throw new TypeError("size must be a uint32"); } - if (size + offset > length || size > kBufferMaxLength) { throw new RangeError("buffer too small"); } } - if (crypto && crypto.getRandomValues || !process$1.browser) { exports$2.randomFill = randomFill; exports$2.randomFillSync = randomFillSync; @@ -75902,12 +109517,10 @@ function dew$1() { exports$2.randomFill = oldBrowser; exports$2.randomFillSync = oldBrowser; } - function randomFill(buf, offset, size, cb) { if (!Buffer.isBuffer(buf) && !(buf instanceof _global.Uint8Array)) { throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); } - if (typeof offset === "function") { cb = offset; offset = 0; @@ -75918,88 +109531,70 @@ function dew$1() { } else if (typeof cb !== "function") { throw new TypeError("\"cb\" argument must be a function"); } - assertOffset(offset, buf.length); assertSize(size, offset, buf.length); return actualFill(buf, offset, size, cb); } - function actualFill(buf, offset, size, cb) { if (process$1.browser) { var ourBuf = buf.buffer; var uint = new Uint8Array(ourBuf, offset, size); crypto.getRandomValues(uint); - if (cb) { process$1.nextTick(function () { cb(null, buf); }); return; } - return buf; } - if (cb) { randombytes(size, function (err, bytes) { if (err) { return cb(err); } - bytes.copy(buf, offset); cb(null, buf); }); return; } - var bytes = randombytes(size); bytes.copy(buf, offset); return buf; } - function randomFillSync(buf, offset, size) { if (typeof offset === "undefined") { offset = 0; } - if (!Buffer.isBuffer(buf) && !(buf instanceof _global.Uint8Array)) { throw new TypeError("\"buf\" argument must be a Buffer or Uint8Array"); } - assertOffset(offset, buf.length); if (size === undefined) size = buf.length - offset; assertSize(size, offset, buf.length); return actualFill(buf, offset, size); } - return exports$2; } var exports$1 = {}, - _dewExec = false; + _dewExec = false; function dew() { if (_dewExec) return exports$1; _dewExec = true; - exports$1.randomBytes = exports$1.rng = exports$1.pseudoRandomBytes = exports$1.prng = dew$2O(); - exports$1.createHash = exports$1.Hash = dew$2y(); - exports$1.createHmac = exports$1.Hmac = dew$2v(); - - var algos = dew$2u(); - + exports$1.randomBytes = exports$1.rng = exports$1.pseudoRandomBytes = exports$1.prng = dew$3G(); + exports$1.createHash = exports$1.Hash = dew$3t(); + exports$1.createHmac = exports$1.Hmac = dew$3q(); + var algos = dew$3p(); var algoKeys = Object.keys(algos); var hashes = ["sha1", "sha224", "sha256", "sha384", "sha512", "md5", "rmd160"].concat(algoKeys); - exports$1.getHashes = function () { return hashes; }; - - var p = dew$2o(); - + var p = dew$3j(); exports$1.pbkdf2 = p.pbkdf2; exports$1.pbkdf2Sync = p.pbkdf2Sync; - - var aes = dew$1Y(); - + var aes = dew$2T(); exports$1.Cipher = aes.Cipher; exports$1.createCipher = aes.createCipher; exports$1.Cipheriv = aes.Cipheriv; @@ -76010,29 +109605,25 @@ function dew() { exports$1.createDecipheriv = aes.createDecipheriv; exports$1.getCiphers = aes.getCiphers; exports$1.listCiphers = aes.listCiphers; - - var dh = dew$Z(); - + var dh = dew$1e(); exports$1.DiffieHellmanGroup = dh.DiffieHellmanGroup; exports$1.createDiffieHellmanGroup = dh.createDiffieHellmanGroup; exports$1.getDiffieHellman = dh.getDiffieHellman; exports$1.createDiffieHellman = dh.createDiffieHellman; exports$1.DiffieHellman = dh.DiffieHellman; - var sign = dew$b(); - exports$1.createSign = sign.createSign; exports$1.Sign = sign.Sign; exports$1.createVerify = sign.createVerify; exports$1.Verify = sign.Verify; exports$1.createECDH = dew$9(); - var publicEncrypt = dew$2(); - exports$1.publicEncrypt = publicEncrypt.publicEncrypt; exports$1.privateEncrypt = publicEncrypt.privateEncrypt; exports$1.publicDecrypt = publicEncrypt.publicDecrypt; - exports$1.privateDecrypt = publicEncrypt.privateDecrypt; // the least I can do is make error messages for the rest of the node.js/crypto api. + exports$1.privateDecrypt = publicEncrypt.privateDecrypt; + + // the least I can do is make error messages for the rest of the node.js/crypto api. // ;[ // 'createCredentials' // ].forEach(function (name) { @@ -76046,14 +109637,11 @@ function dew() { // }) var rf = dew$1(); - exports$1.randomFill = rf.randomFill; exports$1.randomFillSync = rf.randomFillSync; - exports$1.createCredentials = function () { throw new Error(["sorry, createCredentials is not implemented yet", "we accept pull requests", "https://github.com/crypto-browserify/crypto-browserify"].join("\n")); }; - exports$1.constants = { "DH_CHECK_P_NOT_SAFE_PRIME": 2, "DH_CHECK_P_NOT_PRIME": 1, diff --git a/nodelibs/browser/diagnostics_channel.js b/nodelibs/browser/diagnostics_channel.js index cfbee10..5b8c622 100644 --- a/nodelibs/browser/diagnostics_channel.js +++ b/nodelibs/browser/diagnostics_channel.js @@ -1,21 +1,20 @@ -import './util.js'; -import { p as process } from './chunk-b0rmRow7.js'; -import { X } from './chunk-D04hy_Cu.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-DEckhzyo.js'; +import exports$2 from './util.js'; +import { p as process } from './chunk-DEMDiNwt.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; var exports$1 = {}, - _dewExec = false; + _dewExec = false; function dew() { if (_dewExec) return exports$1; _dewExec = true; var process$1 = process; - const util = X; // Port from node core lib/internal/errors.js + const util = exports$2; + // Port from node core lib/internal/errors.js class ERR_INVALID_ARG_TYPE extends TypeError { constructor(message, actual) { super(); - if (actual == null) { message += `. Received ${actual}`; } else if (typeof actual === "function" && actual.name) { @@ -33,14 +32,11 @@ function dew() { let inspected = util.inspect(actual, { colors: false }); - if (inspected.length > 25) { inspected = `${inspected.slice(0, 25)}...`; } - message += `. Received type ${typeof actual} (${inspected})`; } - this.code = this.constructor.name; Object.defineProperties(this, { message: { @@ -53,45 +49,35 @@ function dew() { value() { return `${this.name} [${this.code}]: ${this.message}`; }, - enumerable: false, writable: true, configurable: true } }); } - } - class ActiveChannel { subscribe(subscription) { if (typeof subscription !== "function") { throw new ERR_INVALID_ARG_TYPE("The \"subscription\" argument must be of type function", subscription); } - this._subscribers.push(subscription); } - unsubscribe(subscription) { const index = this._subscribers.indexOf(subscription); - if (index === -1) return false; + this._subscribers.splice(index, 1); - this._subscribers.splice(index, 1); // When there are no more active subscribers, restore to fast prototype. - - + // When there are no more active subscribers, restore to fast prototype. if (!this._subscribers.length) { // eslint-disable-next-line no-use-before-define Object.setPrototypeOf(this, Channel.prototype); } - return true; } - get hasSubscribers() { return true; } - publish(data) { for (let i = 0; i < this._subscribers.length; i++) { try { @@ -104,70 +90,52 @@ function dew() { } } } - } - class Channel { constructor(name) { this._subscribers = undefined; this.name = name; } - static [Symbol.hasInstance](instance) { const prototype = Object.getPrototypeOf(instance); return prototype === Channel.prototype || prototype === ActiveChannel.prototype; } - subscribe(subscription) { Object.setPrototypeOf(this, ActiveChannel.prototype); this._subscribers = []; this.subscribe(subscription); } - unsubscribe() { return false; } - get hasSubscribers() { return false; } - publish() {} - } - const channels = {}; - function channel(name) { const channel = channels[name]; if (channel) return channel; - if (typeof name !== "string" && typeof name !== "symbol") { throw new ERR_INVALID_ARG_TYPE("The \"channel\" argument must be one of type string or symbol", name); } - return channels[name] = new Channel(name); } - function hasSubscribers(name) { const channel = channels[name]; - if (!channel) { return false; } - return channel.hasSubscribers; } - function deleteChannel(name) { if (channels[name]) { channels[name] = null; return true; } - return false; } - exports$1 = { channel, hasSubscribers, diff --git a/nodelibs/browser/domain.js b/nodelibs/browser/domain.js index e2078a1..1cf4ddc 100644 --- a/nodelibs/browser/domain.js +++ b/nodelibs/browser/domain.js @@ -1,37 +1,31 @@ -import './events.js'; +import './chunk-DtDiafJB.js'; import { y } from './chunk-tHuMsdT0.js'; var exports$1 = {}, - _dewExec = false; + _dewExec = false; function dew() { if (_dewExec) return exports$1; _dewExec = true; - exports$1 = function () { // Import Events - var events = y; // Export Domain + var events = y; + // Export Domain var domain = {}; - domain.createDomain = domain.create = function () { var d = new events.EventEmitter(); - function emitError(e) { d.emit("error", e); } - d.add = function (emitter) { emitter.on("error", emitError); }; - d.remove = function (emitter) { emitter.removeListener("error", emitError); }; - d.bind = function (fn) { return function () { var args = Array.prototype.slice.call(arguments); - try { fn.apply(null, args); } catch (err) { @@ -39,14 +33,12 @@ function dew() { } }; }; - d.intercept = function (fn) { return function (err) { if (err) { emitError(err); } else { var args = Array.prototype.slice.call(arguments, 1); - try { fn.apply(null, args); } catch (err) { @@ -55,32 +47,25 @@ function dew() { } }; }; - d.run = function (fn) { try { fn(); } catch (err) { emitError(err); } - return this; }; - d.dispose = function () { this.removeAllListeners(); return this; }; - d.enter = d.exit = function () { return this; }; - return d; }; - return domain; }.call(exports$1); - return exports$1; } diff --git a/nodelibs/browser/events.js b/nodelibs/browser/events.js index 18ce564..95ae3fc 100644 --- a/nodelibs/browser/events.js +++ b/nodelibs/browser/events.js @@ -1,7 +1,392 @@ -import { y } from './chunk-tHuMsdT0.js'; +var exports$1 = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports$1; + _dewExec = true; + var R = typeof Reflect === "object" ? Reflect : null; + var ReflectApply = R && typeof R.apply === "function" ? R.apply : function ReflectApply(target, receiver, args) { + return Function.prototype.apply.call(target, receiver, args); + }; + var ReflectOwnKeys; + if (R && typeof R.ownKeys === "function") { + ReflectOwnKeys = R.ownKeys; + } else if (Object.getOwnPropertySymbols) { + ReflectOwnKeys = function ReflectOwnKeys(target) { + return Object.getOwnPropertyNames(target).concat(Object.getOwnPropertySymbols(target)); + }; + } else { + ReflectOwnKeys = function ReflectOwnKeys(target) { + return Object.getOwnPropertyNames(target); + }; + } + function ProcessEmitWarning(warning) { + if (console && console.warn) console.warn(warning); + } + var NumberIsNaN = Number.isNaN || function NumberIsNaN(value) { + return value !== value; + }; + function EventEmitter() { + EventEmitter.init.call(this); + } + exports$1 = EventEmitter; + exports$1.once = once; + + // Backwards-compat with node 0.10.x + EventEmitter.EventEmitter = EventEmitter; + EventEmitter.prototype._events = undefined; + EventEmitter.prototype._eventsCount = 0; + EventEmitter.prototype._maxListeners = undefined; + + // By default EventEmitters will print a warning if more than 10 listeners are + // added to it. This is a useful default which helps finding memory leaks. + var defaultMaxListeners = 10; + function checkListener(listener) { + if (typeof listener !== "function") { + throw new TypeError("The \"listener\" argument must be of type Function. Received type " + typeof listener); + } + } + Object.defineProperty(EventEmitter, "defaultMaxListeners", { + enumerable: true, + get: function () { + return defaultMaxListeners; + }, + set: function (arg) { + if (typeof arg !== "number" || arg < 0 || NumberIsNaN(arg)) { + throw new RangeError("The value of \"defaultMaxListeners\" is out of range. It must be a non-negative number. Received " + arg + "."); + } + defaultMaxListeners = arg; + } + }); + EventEmitter.init = function () { + if (this._events === undefined || this._events === Object.getPrototypeOf(this)._events) { + this._events = Object.create(null); + this._eventsCount = 0; + } + this._maxListeners = this._maxListeners || undefined; + }; + + // Obviously not all Emitters should be limited to 10. This function allows + // that to be increased. Set to zero for unlimited. + EventEmitter.prototype.setMaxListeners = function setMaxListeners(n) { + if (typeof n !== "number" || n < 0 || NumberIsNaN(n)) { + throw new RangeError("The value of \"n\" is out of range. It must be a non-negative number. Received " + n + "."); + } + this._maxListeners = n; + return this; + }; + function _getMaxListeners(that) { + if (that._maxListeners === undefined) return EventEmitter.defaultMaxListeners; + return that._maxListeners; + } + EventEmitter.prototype.getMaxListeners = function getMaxListeners() { + return _getMaxListeners(this); + }; + EventEmitter.prototype.emit = function emit(type) { + var args = []; + for (var i = 1; i < arguments.length; i++) args.push(arguments[i]); + var doError = type === "error"; + var events = this._events; + if (events !== undefined) doError = doError && events.error === undefined;else if (!doError) return false; + + // If there is no 'error' event listener then throw. + if (doError) { + var er; + if (args.length > 0) er = args[0]; + if (er instanceof Error) { + // Note: The comments on the `throw` lines are intentional, they show + // up in Node's output if this results in an unhandled exception. + throw er; // Unhandled 'error' event + } + // At least give some kind of context to the user + var err = new Error("Unhandled error." + (er ? " (" + er.message + ")" : "")); + err.context = er; + throw err; // Unhandled 'error' event + } + var handler = events[type]; + if (handler === undefined) return false; + if (typeof handler === "function") { + ReflectApply(handler, this, args); + } else { + var len = handler.length; + var listeners = arrayClone(handler, len); + for (var i = 0; i < len; ++i) ReflectApply(listeners[i], this, args); + } + return true; + }; + function _addListener(target, type, listener, prepend) { + var m; + var events; + var existing; + checkListener(listener); + events = target._events; + if (events === undefined) { + events = target._events = Object.create(null); + target._eventsCount = 0; + } else { + // To avoid recursion in the case that type === "newListener"! Before + // adding it to the listeners, first emit "newListener". + if (events.newListener !== undefined) { + target.emit("newListener", type, listener.listener ? listener.listener : listener); + + // Re-assign `events` because a newListener handler could have caused the + // this._events to be assigned to a new object + events = target._events; + } + existing = events[type]; + } + if (existing === undefined) { + // Optimize the case of one listener. Don't need the extra array object. + existing = events[type] = listener; + ++target._eventsCount; + } else { + if (typeof existing === "function") { + // Adding the second element, need to change to array. + existing = events[type] = prepend ? [listener, existing] : [existing, listener]; + // If we've already got an array, just append. + } else if (prepend) { + existing.unshift(listener); + } else { + existing.push(listener); + } + + // Check for listener leak + m = _getMaxListeners(target); + if (m > 0 && existing.length > m && !existing.warned) { + existing.warned = true; + // No error code for this since it is a Warning + // eslint-disable-next-line no-restricted-syntax + var w = new Error("Possible EventEmitter memory leak detected. " + existing.length + " " + String(type) + " listeners " + "added. Use emitter.setMaxListeners() to " + "increase limit"); + w.name = "MaxListenersExceededWarning"; + w.emitter = target; + w.type = type; + w.count = existing.length; + ProcessEmitWarning(w); + } + } + return target; + } + EventEmitter.prototype.addListener = function addListener(type, listener) { + return _addListener(this, type, listener, false); + }; + EventEmitter.prototype.on = EventEmitter.prototype.addListener; + EventEmitter.prototype.prependListener = function prependListener(type, listener) { + return _addListener(this, type, listener, true); + }; + function onceWrapper() { + if (!this.fired) { + this.target.removeListener(this.type, this.wrapFn); + this.fired = true; + if (arguments.length === 0) return this.listener.call(this.target); + return this.listener.apply(this.target, arguments); + } + } + function _onceWrap(target, type, listener) { + var state = { + fired: false, + wrapFn: undefined, + target: target, + type: type, + listener: listener + }; + var wrapped = onceWrapper.bind(state); + wrapped.listener = listener; + state.wrapFn = wrapped; + return wrapped; + } + EventEmitter.prototype.once = function once(type, listener) { + checkListener(listener); + this.on(type, _onceWrap(this, type, listener)); + return this; + }; + EventEmitter.prototype.prependOnceListener = function prependOnceListener(type, listener) { + checkListener(listener); + this.prependListener(type, _onceWrap(this, type, listener)); + return this; + }; + + // Emits a 'removeListener' event if and only if the listener was removed. + EventEmitter.prototype.removeListener = function removeListener(type, listener) { + var list, events, position, i, originalListener; + checkListener(listener); + events = this._events; + if (events === undefined) return this; + list = events[type]; + if (list === undefined) return this; + if (list === listener || list.listener === listener) { + if (--this._eventsCount === 0) this._events = Object.create(null);else { + delete events[type]; + if (events.removeListener) this.emit("removeListener", type, list.listener || listener); + } + } else if (typeof list !== "function") { + position = -1; + for (i = list.length - 1; i >= 0; i--) { + if (list[i] === listener || list[i].listener === listener) { + originalListener = list[i].listener; + position = i; + break; + } + } + if (position < 0) return this; + if (position === 0) list.shift();else { + spliceOne(list, position); + } + if (list.length === 1) events[type] = list[0]; + if (events.removeListener !== undefined) this.emit("removeListener", type, originalListener || listener); + } + return this; + }; + EventEmitter.prototype.off = EventEmitter.prototype.removeListener; + EventEmitter.prototype.removeAllListeners = function removeAllListeners(type) { + var listeners, events, i; + events = this._events; + if (events === undefined) return this; + + // not listening for removeListener, no need to emit + if (events.removeListener === undefined) { + if (arguments.length === 0) { + this._events = Object.create(null); + this._eventsCount = 0; + } else if (events[type] !== undefined) { + if (--this._eventsCount === 0) this._events = Object.create(null);else delete events[type]; + } + return this; + } + + // emit removeListener for all listeners on all events + if (arguments.length === 0) { + var keys = Object.keys(events); + var key; + for (i = 0; i < keys.length; ++i) { + key = keys[i]; + if (key === "removeListener") continue; + this.removeAllListeners(key); + } + this.removeAllListeners("removeListener"); + this._events = Object.create(null); + this._eventsCount = 0; + return this; + } + listeners = events[type]; + if (typeof listeners === "function") { + this.removeListener(type, listeners); + } else if (listeners !== undefined) { + // LIFO order + for (i = listeners.length - 1; i >= 0; i--) { + this.removeListener(type, listeners[i]); + } + } + return this; + }; + function _listeners(target, type, unwrap) { + var events = target._events; + if (events === undefined) return []; + var evlistener = events[type]; + if (evlistener === undefined) return []; + if (typeof evlistener === "function") return unwrap ? [evlistener.listener || evlistener] : [evlistener]; + return unwrap ? unwrapListeners(evlistener) : arrayClone(evlistener, evlistener.length); + } + EventEmitter.prototype.listeners = function listeners(type) { + return _listeners(this, type, true); + }; + EventEmitter.prototype.rawListeners = function rawListeners(type) { + return _listeners(this, type, false); + }; + EventEmitter.listenerCount = function (emitter, type) { + if (typeof emitter.listenerCount === "function") { + return emitter.listenerCount(type); + } else { + return listenerCount.call(emitter, type); + } + }; + EventEmitter.prototype.listenerCount = listenerCount; + function listenerCount(type) { + var events = this._events; + if (events !== undefined) { + var evlistener = events[type]; + if (typeof evlistener === "function") { + return 1; + } else if (evlistener !== undefined) { + return evlistener.length; + } + } + return 0; + } + EventEmitter.prototype.eventNames = function eventNames() { + return this._eventsCount > 0 ? ReflectOwnKeys(this._events) : []; + }; + function arrayClone(arr, n) { + var copy = new Array(n); + for (var i = 0; i < n; ++i) copy[i] = arr[i]; + return copy; + } + function spliceOne(list, index) { + for (; index + 1 < list.length; index++) list[index] = list[index + 1]; + list.pop(); + } + function unwrapListeners(arr) { + var ret = new Array(arr.length); + for (var i = 0; i < ret.length; ++i) { + ret[i] = arr[i].listener || arr[i]; + } + return ret; + } + function once(emitter, name) { + return new Promise(function (resolve, reject) { + function errorListener(err) { + emitter.removeListener(name, resolver); + reject(err); + } + function resolver() { + if (typeof emitter.removeListener === "function") { + emitter.removeListener("error", errorListener); + } + resolve([].slice.call(arguments)); + } + eventTargetAgnosticAddListener(emitter, name, resolver, { + once: true + }); + if (name !== "error") { + addErrorHandlerIfEventEmitter(emitter, errorListener, { + once: true + }); + } + }); + } + function addErrorHandlerIfEventEmitter(emitter, handler, flags) { + if (typeof emitter.on === "function") { + eventTargetAgnosticAddListener(emitter, "error", handler, flags); + } + } + function eventTargetAgnosticAddListener(emitter, name, listener, flags) { + if (typeof emitter.on === "function") { + if (flags.once) { + emitter.once(name, listener); + } else { + emitter.on(name, listener); + } + } else if (typeof emitter.addEventListener === "function") { + // EventTarget does not have `error` event semantics like Node + // EventEmitters, we do not listen for `error` events here. + emitter.addEventListener(name, function wrapListener(arg) { + // IE does not have builtin `{ once: true }` support so we + // have to do it manually. + if (flags.once) { + emitter.removeEventListener(name, wrapListener); + } + listener(arg); + }); + } else { + throw new TypeError("The \"emitter\" argument must be of type EventEmitter. Received type " + typeof emitter); + } + } + return exports$1; +} + +const exports = dew(); +exports['once']; // https://github.com/denoland/deno_std/blob/d005433c709054af87aca54f57a446b4f7966f11/node/events.ts#L501-L638 -y.once = function (emitter, event) { +exports.once = function (emitter, event) { return new Promise((resolve, reject) => { function eventListener(...args) { if (errorListener !== undefined) { @@ -23,7 +408,7 @@ y.once = function (emitter, event) { emitter.once(event, eventListener); }); }; -y.on = function (emitter, event) { +exports.on = function (emitter, event) { const unconsumedEventValues = []; const unconsumedPromises = []; let error = null; @@ -101,6 +486,6 @@ const { listenerCount, on, once, -} = y; +} = exports; -export { EventEmitter, y as default, defaultMaxListeners, init, listenerCount, on, once }; +export { EventEmitter, exports as default, defaultMaxListeners, init, listenerCount, on, once }; diff --git a/nodelibs/browser/fs.js b/nodelibs/browser/fs.js index 3066409..2009d7d 100644 --- a/nodelibs/browser/fs.js +++ b/nodelibs/browser/fs.js @@ -1,24 +1,22 @@ -import { b as buffer } from './chunk-CU2hd6BF.js'; -import et from './assert.js'; -import './util.js'; -import { X } from './chunk-D04hy_Cu.js'; -import './chunk-BZgdGiNw.js'; -import './path.js'; -import { p as process } from './chunk-b0rmRow7.js'; -import './events.js'; +import { d as dew$g } from './chunk-DtuTasat.js'; +import { e as et } from './chunk-CjPlbOtt.js'; +import './chunk-CbQqNoLO.js'; +import { X } from './chunk-D3uu3VYh.js'; +import { e as exports$i, h } from './chunk-DHWh-hmB.js'; +import './chunk-b0rmRow7.js'; +import { p as process } from './chunk-DEMDiNwt.js'; +import './chunk-DtDiafJB.js'; import { y } from './chunk-tHuMsdT0.js'; -import './stream.js'; -import h, { fileURLToPath } from './url.js'; -import { e as exports$i } from './chunk-DppJZDIM.js'; -import { e as exports$j } from './chunk-gkrMq4sQ.js'; +import { e as exports$j } from './chunk-B6-G-Ftj.js'; import { Buffer } from './buffer.js'; -import './chunk-C9hMJ5VR.js'; -import './chunk-DEckhzyo.js'; -import './chunk-CKeAujU-.js'; -import './chunk-D5E0hY9V.js'; +import { fileURLToPath } from './url.js'; +import './chunk-B738Er4n.js'; +import './punycode.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-BlJi4mNy.js'; var exports$h = {}, - _dewExec$f = false; + _dewExec$f = false; function dew$f() { if (_dewExec$f) return exports$h; _dewExec$f = true; @@ -78,7 +76,7 @@ function dew$f() { } var exports$g = {}, - _dewExec$e = false; + _dewExec$e = false; function dew$e() { if (_dewExec$e) return exports$g; _dewExec$e = true; @@ -89,7 +87,7 @@ function dew$e() { } var exports$f = {}, - _dewExec$d = false; + _dewExec$d = false; function dew$d() { if (_dewExec$d) return exports$f; _dewExec$d = true; @@ -97,43 +95,37 @@ function dew$d() { value: true }); exports$f.Stats = void 0; - var constants_1 = dew$f(); - var getBigInt_1 = dew$e(); - var S_IFMT = constants_1.constants.S_IFMT, - S_IFDIR = constants_1.constants.S_IFDIR, - S_IFREG = constants_1.constants.S_IFREG, - S_IFBLK = constants_1.constants.S_IFBLK, - S_IFCHR = constants_1.constants.S_IFCHR, - S_IFLNK = constants_1.constants.S_IFLNK, - S_IFIFO = constants_1.constants.S_IFIFO, - S_IFSOCK = constants_1.constants.S_IFSOCK; + S_IFDIR = constants_1.constants.S_IFDIR, + S_IFREG = constants_1.constants.S_IFREG, + S_IFBLK = constants_1.constants.S_IFBLK, + S_IFCHR = constants_1.constants.S_IFCHR, + S_IFLNK = constants_1.constants.S_IFLNK, + S_IFIFO = constants_1.constants.S_IFIFO, + S_IFSOCK = constants_1.constants.S_IFSOCK; /** * Statistics about a file/directory, like `fs.Stats`. */ - - var Stats = function () { + var Stats = /** @class */function () { function Stats() {} - Stats.build = function (node, bigint) { if (bigint === void 0) { bigint = false; } - var stats = new Stats(); var uid = node.uid, - gid = node.gid, - atime = node.atime, - mtime = node.mtime, - ctime = node.ctime; + gid = node.gid, + atime = node.atime, + mtime = node.mtime, + ctime = node.ctime; var getStatNumber = !bigint ? function (number) { return number; - } : getBigInt_1.default; // Copy all values on Stats from Node, so that if Node values + } : getBigInt_1.default; + // Copy all values on Stats from Node, so that if Node values // change, values on Stats would still be the old ones, // just like in Node fs. - stats.uid = getStatNumber(uid); stats.gid = getStatNumber(gid); stats.rdev = getStatNumber(0); @@ -155,53 +147,42 @@ function dew$d() { stats.nlink = getStatNumber(node.nlink); return stats; }; - Stats.prototype._checkModeProperty = function (property) { return (Number(this.mode) & S_IFMT) === property; }; - Stats.prototype.isDirectory = function () { return this._checkModeProperty(S_IFDIR); }; - Stats.prototype.isFile = function () { return this._checkModeProperty(S_IFREG); }; - Stats.prototype.isBlockDevice = function () { return this._checkModeProperty(S_IFBLK); }; - Stats.prototype.isCharacterDevice = function () { return this._checkModeProperty(S_IFCHR); }; - Stats.prototype.isSymbolicLink = function () { return this._checkModeProperty(S_IFLNK); }; - Stats.prototype.isFIFO = function () { return this._checkModeProperty(S_IFIFO); }; - Stats.prototype.isSocket = function () { return this._checkModeProperty(S_IFSOCK); }; - return Stats; }(); - exports$f.Stats = Stats; exports$f.default = Stats; return exports$f; } var exports$e = {}, - _dewExec$c = false; + _dewExec$c = false; function dew$c() { if (_dewExec$c) return exports$e; _dewExec$c = true; - var __spreadArray = exports$e && exports$e.__spreadArray || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { @@ -211,29 +192,24 @@ function dew$c() { } return to.concat(ar || Array.prototype.slice.call(from)); }; - Object.defineProperty(exports$e, "__esModule", { value: true }); exports$e.bufferFrom = exports$e.bufferAllocUnsafe = exports$e.Buffer = void 0; - var buffer_1 = buffer; + var buffer_1 = dew$g(); Object.defineProperty(exports$e, "Buffer", { enumerable: true, get: function () { return buffer_1.Buffer; } }); - function bufferV0P12Ponyfill(arg0) { var args = []; - for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } - return new (buffer_1.Buffer.bind.apply(buffer_1.Buffer, __spreadArray([void 0, arg0], args, false)))(); } - var bufferAllocUnsafe = buffer_1.Buffer.allocUnsafe || bufferV0P12Ponyfill; exports$e.bufferAllocUnsafe = bufferAllocUnsafe; var bufferFrom = buffer_1.Buffer.from || bufferV0P12Ponyfill; @@ -242,14 +218,11 @@ function dew$c() { } var exports$d = {}, - _dewExec$b = false; - + _dewExec$b = false; var _global$3 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$b() { if (_dewExec$b) return exports$d; _dewExec$b = true; - // The whole point behind this internal module is to allow Node.js to no // longer be forced to treat every error message change as a semver-major // change. The NodeError classes here all expose a `code` property whose @@ -264,22 +237,17 @@ function dew$b() { } || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); }; - return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); - Object.defineProperty(exports$d, "__esModule", { value: true }); @@ -288,48 +256,36 @@ function dew$b() { var util = X; var kCode = typeof Symbol === "undefined" ? "_kCode" : Symbol("code"); var messages = {}; // new Map(); - function makeNodeError(Base) { - return function (_super) { + return /** @class */function (_super) { __extends(NodeError, _super); - function NodeError(key) { var args = []; - for (var _i = 1; _i < arguments.length; _i++) { args[_i - 1] = arguments[_i]; } - var _this = _super.call(this, message(key, args)) || this; - _this.code = key; _this[kCode] = key; - _this.name = _super.prototype.name + " [" + _this[kCode] + "]"; + _this.name = "".concat(_super.prototype.name, " [").concat(_this[kCode], "]"); return _this; } - return NodeError; }(Base); } - var g = typeof globalThis !== "undefined" ? globalThis : _global$3; - - var AssertionError = function (_super) { + var AssertionError = /** @class */function (_super) { __extends(AssertionError, _super); - function AssertionError(options) { var _this = this; - if (typeof options !== "object" || options === null) { throw new exports$d.TypeError("ERR_INVALID_ARG_TYPE", "options", "object"); } - if (options.message) { _this = _super.call(this, options.message) || this; } else { - _this = _super.call(this, util.inspect(options.actual).slice(0, 128) + " " + (options.operator + " " + util.inspect(options.expected).slice(0, 128))) || this; + _this = _super.call(this, "".concat(util.inspect(options.actual).slice(0, 128), " ") + "".concat(options.operator, " ").concat(util.inspect(options.expected).slice(0, 128))) || this; } - _this.generatedMessage = !options.message; _this.name = "AssertionError [ERR_ASSERTION]"; _this.code = "ERR_ASSERTION"; @@ -339,19 +295,15 @@ function dew$b() { exports$d.Error.captureStackTrace(_this, options.stackStartFunction); return _this; } - return AssertionError; }(g.Error); - exports$d.AssertionError = AssertionError; - function message(key, args) { - assert.strictEqual(typeof key, "string"); // const msg = messages.get(key); - + assert.strictEqual(typeof key, "string"); + // const msg = messages.get(key); var msg = messages[key]; - assert(msg, "An invalid error message key was used: " + key + "."); + assert(msg, "An invalid error message key was used: ".concat(key, ".")); var fmt; - if (typeof msg === "function") { fmt = msg; } else { @@ -359,21 +311,19 @@ function dew$b() { if (args === undefined || args.length === 0) return msg; args.unshift(msg); } - return String(fmt.apply(null, args)); } - - exports$d.message = message; // Utility function for registering the error codes. Only used here. Exported + exports$d.message = message; + // Utility function for registering the error codes. Only used here. Exported // *only* to allow for testing. - function E(sym, val) { messages[sym] = typeof val === "function" ? val : String(val); } - exports$d.E = E; exports$d.Error = makeNodeError(g.Error); exports$d.TypeError = makeNodeError(g.TypeError); - exports$d.RangeError = makeNodeError(g.RangeError); // To declare an error message, use the E(sym, val) function above. The sym + exports$d.RangeError = makeNodeError(g.RangeError); + // To declare an error message, use the E(sym, val) function above. The sym // must be an upper case string. The val can be either a function or a string. // The return value of the function must be a string. // Examples: @@ -386,7 +336,6 @@ function dew$b() { // Any error code added here should also be added to the documentation // // Note: Please try to keep these in alphabetical order - E("ERR_ARG_NOT_ITERABLE", "%s must be iterable"); E("ERR_ASSERTION", "%s"); E("ERR_BUFFER_OUT_OF_BOUNDS", bufferOutOfBounds); @@ -394,14 +343,14 @@ function dew$b() { E("ERR_CONSOLE_WRITABLE_STREAM", "Console expects a writable stream instance for %s"); E("ERR_CPU_USAGE", "Unable to obtain cpu usage %s"); E("ERR_DNS_SET_SERVERS_FAILED", function (err, servers) { - return "c-ares failed to set servers: \"" + err + "\" [" + servers + "]"; + return "c-ares failed to set servers: \"".concat(err, "\" [").concat(servers, "]"); }); E("ERR_FALSY_VALUE_REJECTION", "Promise was rejected with falsy value"); E("ERR_ENCODING_NOT_SUPPORTED", function (enc) { - return "The \"" + enc + "\" encoding is not supported"; + return "The \"".concat(enc, "\" encoding is not supported"); }); E("ERR_ENCODING_INVALID_ENCODED_DATA", function (enc) { - return "The encoded data was not valid for encoding " + enc; + return "The encoded data was not valid for encoding ".concat(enc); }); E("ERR_HTTP_HEADERS_SENT", "Cannot render headers after they are sent to the client"); E("ERR_HTTP_INVALID_STATUS_CODE", "Invalid status code: %s"); @@ -410,7 +359,7 @@ function dew$b() { E("ERR_INVALID_ARG_TYPE", invalidArgType); E("ERR_INVALID_ARRAY_LENGTH", function (name, len, actual) { assert.strictEqual(typeof actual, "number"); - return "The array \"" + name + "\" (length " + actual + ") must be of length " + len + "."; + return "The array \"".concat(name, "\" (length ").concat(actual, ") must be of length ").concat(len, "."); }); E("ERR_INVALID_BUFFER_SIZE", "Buffer size must be a multiple of %s"); E("ERR_INVALID_CALLBACK", "Callback must be a function"); @@ -422,10 +371,10 @@ function dew$b() { E("ERR_INVALID_HANDLE_TYPE", "This handle type cannot be sent"); E("ERR_INVALID_IP_ADDRESS", "Invalid IP address: %s"); E("ERR_INVALID_OPT_VALUE", function (name, value) { - return "The value \"" + String(value) + "\" is invalid for option \"" + name + "\""; + return "The value \"".concat(String(value), "\" is invalid for option \"").concat(name, "\""); }); E("ERR_INVALID_OPT_VALUE_ENCODING", function (value) { - return "The value \"" + String(value) + "\" is invalid for option \"encoding\""; + return "The value \"".concat(String(value), "\" is invalid for option \"encoding\""); }); E("ERR_INVALID_REPL_EVAL_CONFIG", "Cannot specify both \"breakEvalOnSigint\" and \"eval\" for REPL"); E("ERR_INVALID_SYNC_FORK_INPUT", "Asynchronous forks do not support Buffer, Uint8Array or string input: %s"); @@ -433,7 +382,7 @@ function dew$b() { E("ERR_INVALID_TUPLE", "%s must be an iterable %s tuple"); E("ERR_INVALID_URL", "Invalid URL: %s"); E("ERR_INVALID_URL_SCHEME", function (expected) { - return "The URL must be " + oneOf(expected, "scheme"); + return "The URL must be ".concat(oneOf(expected, "scheme")); }); E("ERR_IPC_CHANNEL_CLOSED", "Channel closed"); E("ERR_IPC_DISCONNECTED", "IPC channel is already disconnected"); @@ -457,7 +406,7 @@ function dew$b() { E("ERR_STREAM_WRAP", "Stream has StringDecoder set or is in objectMode"); E("ERR_TLS_CERT_ALTNAME_INVALID", "Hostname/IP does not match certificate's altnames: %s"); E("ERR_TLS_DH_PARAM_SIZE", function (size) { - return "DH parameter size " + size + " is less than 2048"; + return "DH parameter size ".concat(size, " is less than 2048"); }); E("ERR_TLS_HANDSHAKE_TIMEOUT", "TLS handshake timeout"); E("ERR_TLS_RENEGOTIATION_FAILED", "Failed to renegotiate"); @@ -470,111 +419,93 @@ function dew$b() { E("ERR_UNKNOWN_STDIN_TYPE", "Unknown stdin file type"); E("ERR_UNKNOWN_STREAM_TYPE", "Unknown stream file type"); E("ERR_V8BREAKITERATOR", "Full ICU data not installed. " + "See https://github.com/nodejs/node/wiki/Intl"); - function invalidArgType(name, expected, actual) { - assert(name, "name is required"); // determiner: 'must be' or 'must not be' - + assert(name, "name is required"); + // determiner: 'must be' or 'must not be' var determiner; - if (expected.includes("not ")) { determiner = "must not be"; expected = expected.split("not ")[1]; } else { determiner = "must be"; } - var msg; - if (Array.isArray(name)) { var names = name.map(function (val) { - return "\"" + val + "\""; + return "\"".concat(val, "\""); }).join(", "); - msg = "The " + names + " arguments " + determiner + " " + oneOf(expected, "type"); + msg = "The ".concat(names, " arguments ").concat(determiner, " ").concat(oneOf(expected, "type")); } else if (name.includes(" argument")) { // for the case like 'first argument' - msg = "The " + name + " " + determiner + " " + oneOf(expected, "type"); + msg = "The ".concat(name, " ").concat(determiner, " ").concat(oneOf(expected, "type")); } else { var type = name.includes(".") ? "property" : "argument"; - msg = "The \"" + name + "\" " + type + " " + determiner + " " + oneOf(expected, "type"); - } // if actual value received, output it - - + msg = "The \"".concat(name, "\" ").concat(type, " ").concat(determiner, " ").concat(oneOf(expected, "type")); + } + // if actual value received, output it if (arguments.length >= 3) { - msg += ". Received type " + (actual !== null ? typeof actual : "null"); + msg += ". Received type ".concat(actual !== null ? typeof actual : "null"); } - return msg; } - function missingArgs() { var args = []; - for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - assert(args.length > 0, "At least one arg needs to be specified"); var msg = "The "; var len = args.length; args = args.map(function (a) { - return "\"" + a + "\""; + return "\"".concat(a, "\""); }); - switch (len) { case 1: - msg += args[0] + " argument"; + msg += "".concat(args[0], " argument"); break; - case 2: - msg += args[0] + " and " + args[1] + " arguments"; + msg += "".concat(args[0], " and ").concat(args[1], " arguments"); break; - default: msg += args.slice(0, len - 1).join(", "); - msg += ", and " + args[len - 1] + " arguments"; + msg += ", and ".concat(args[len - 1], " arguments"); break; } - - return msg + " must be specified"; + return "".concat(msg, " must be specified"); } - function oneOf(expected, thing) { assert(expected, "expected is required"); assert(typeof thing === "string", "thing is required"); - if (Array.isArray(expected)) { var len = expected.length; - assert(len > 0, "At least one expected value needs to be specified"); // tslint:disable-next-line - + assert(len > 0, "At least one expected value needs to be specified"); + // tslint:disable-next-line expected = expected.map(function (i) { return String(i); }); - if (len > 2) { - return "one of " + thing + " " + expected.slice(0, len - 1).join(", ") + ", or " + expected[len - 1]; + return "one of ".concat(thing, " ").concat(expected.slice(0, len - 1).join(", "), ", or ") + expected[len - 1]; } else if (len === 2) { - return "one of " + thing + " " + expected[0] + " or " + expected[1]; + return "one of ".concat(thing, " ").concat(expected[0], " or ").concat(expected[1]); } else { - return "of " + thing + " " + expected[0]; + return "of ".concat(thing, " ").concat(expected[0]); } } else { - return "of " + thing + " " + String(expected); + return "of ".concat(thing, " ").concat(String(expected)); } } - function bufferOutOfBounds(name, isWriting) { if (isWriting) { return "Attempt to write outside buffer bounds"; } else { - return "\"" + name + "\" is outside of buffer bounds"; + return "\"".concat(name, "\" is outside of buffer bounds"); } } - return exports$d; } var exports$c = {}, - _dewExec$a = false; + _dewExec$a = false; function dew$a() { if (_dewExec$a) return exports$c; _dewExec$a = true; @@ -582,33 +513,24 @@ function dew$a() { value: true }); exports$c.strToEncoding = exports$c.assertEncoding = exports$c.ENCODING_UTF8 = void 0; - var buffer_1 = dew$c(); - var errors = dew$b(); - exports$c.ENCODING_UTF8 = "utf8"; - function assertEncoding(encoding) { if (encoding && !buffer_1.Buffer.isEncoding(encoding)) throw new errors.TypeError("ERR_INVALID_OPT_VALUE_ENCODING", encoding); } - exports$c.assertEncoding = assertEncoding; - function strToEncoding(str, encoding) { if (!encoding || encoding === exports$c.ENCODING_UTF8) return str; // UTF-8 - if (encoding === "buffer") return new buffer_1.Buffer(str); // `buffer` encoding - return new buffer_1.Buffer(str).toString(encoding); // Custom encoding } - exports$c.strToEncoding = strToEncoding; return exports$c; } var exports$b = {}, - _dewExec$9 = false; + _dewExec$9 = false; function dew$9() { if (_dewExec$9) return exports$b; _dewExec$9 = true; @@ -616,29 +538,24 @@ function dew$9() { value: true }); exports$b.Dirent = void 0; - var constants_1 = dew$f(); - var encoding_1 = dew$a(); - var S_IFMT = constants_1.constants.S_IFMT, - S_IFDIR = constants_1.constants.S_IFDIR, - S_IFREG = constants_1.constants.S_IFREG, - S_IFBLK = constants_1.constants.S_IFBLK, - S_IFCHR = constants_1.constants.S_IFCHR, - S_IFLNK = constants_1.constants.S_IFLNK, - S_IFIFO = constants_1.constants.S_IFIFO, - S_IFSOCK = constants_1.constants.S_IFSOCK; + S_IFDIR = constants_1.constants.S_IFDIR, + S_IFREG = constants_1.constants.S_IFREG, + S_IFBLK = constants_1.constants.S_IFBLK, + S_IFCHR = constants_1.constants.S_IFCHR, + S_IFLNK = constants_1.constants.S_IFLNK, + S_IFIFO = constants_1.constants.S_IFIFO, + S_IFSOCK = constants_1.constants.S_IFSOCK; /** * A directory entry, like `fs.Dirent`. */ - - var Dirent = function () { + var Dirent = /** @class */function () { function Dirent() { this.name = ""; this.mode = 0; } - Dirent.build = function (link, encoding) { var dirent = new Dirent(); var mode = link.getNode().mode; @@ -646,52 +563,56 @@ function dew$9() { dirent.mode = mode; return dirent; }; - Dirent.prototype._checkModeProperty = function (property) { return (this.mode & S_IFMT) === property; }; - Dirent.prototype.isDirectory = function () { return this._checkModeProperty(S_IFDIR); }; - Dirent.prototype.isFile = function () { return this._checkModeProperty(S_IFREG); }; - Dirent.prototype.isBlockDevice = function () { return this._checkModeProperty(S_IFBLK); }; - Dirent.prototype.isCharacterDevice = function () { return this._checkModeProperty(S_IFCHR); }; - Dirent.prototype.isSymbolicLink = function () { return this._checkModeProperty(S_IFLNK); }; - Dirent.prototype.isFIFO = function () { return this._checkModeProperty(S_IFIFO); }; - Dirent.prototype.isSocket = function () { return this._checkModeProperty(S_IFSOCK); }; - return Dirent; }(); - exports$b.Dirent = Dirent; exports$b.default = Dirent; return exports$b; } -var exports$a = {}, - _dewExec$8 = false; +exports$i._makeLong; +exports$i.basename; +exports$i.delimiter; +exports$i.dirname; +exports$i.extname; +exports$i.format; +exports$i.isAbsolute; +exports$i.join; +exports$i.normalize; +exports$i.parse; +exports$i.posix; +exports$i.relative; +exports$i.resolve; +exports$i.sep; +exports$i.win32; +var exports$a = {}, + _dewExec$8 = false; var _global$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$8() { if (_dewExec$8) return exports$a; _dewExec$8 = true; @@ -699,16 +620,14 @@ function dew$8() { Object.defineProperty(exports$a, "__esModule", { value: true }); - var _setImmediate; - if (typeof process$1.nextTick === "function") _setImmediate = process$1.nextTick.bind(typeof globalThis !== "undefined" ? globalThis : _global$2);else _setImmediate = setTimeout.bind(typeof globalThis !== "undefined" ? globalThis : _global$2); exports$a.default = _setImmediate; return exports$a; } var exports$9 = {}, - _dewExec$7 = false; + _dewExec$7 = false; function dew$7() { if (_dewExec$7) return exports$9; _dewExec$7 = true; @@ -728,50 +647,39 @@ function dew$7() { * * @return {IProcess | undefined} */ - var maybeReturnProcess = function () { if (typeof process$1 !== "undefined") { return process$1; } - try { return process; } catch (_a) { return undefined; } }; - function createProcess() { var p = maybeReturnProcess() || {}; - if (!p.getuid) p.getuid = function () { - return 0; - }; - if (!p.getgid) p.getgid = function () { - return 0; - }; if (!p.cwd) p.cwd = function () { return "/"; }; if (!p.nextTick) p.nextTick = dew$8().default; if (!p.emitWarning) p.emitWarning = function (message, type) { // tslint:disable-next-line:no-console - console.warn("" + type + (type ? ": " : "") + message); + console.warn("".concat(type).concat(type ? ": " : "").concat(message)); }; if (!p.env) p.env = {}; return p; } - exports$9.createProcess = createProcess; exports$9.default = createProcess(); return exports$9; } var exports$8 = {}, - _dewExec$6 = false; + _dewExec$6 = false; function dew$6() { if (_dewExec$6) return exports$8; _dewExec$6 = true; - var __extends = exports$8 && exports$8.__extends || function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { @@ -781,301 +689,312 @@ function dew$6() { } || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); }; - return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); - Object.defineProperty(exports$8, "__esModule", { value: true }); exports$8.File = exports$8.Link = exports$8.Node = exports$8.SEP = void 0; - var process_1 = dew$7(); - var buffer_1 = dew$c(); - var constants_1 = dew$f(); - var events_1 = y; - var Stats_1 = dew$d(); - var S_IFMT = constants_1.constants.S_IFMT, - S_IFDIR = constants_1.constants.S_IFDIR, - S_IFREG = constants_1.constants.S_IFREG, - S_IFLNK = constants_1.constants.S_IFLNK, - O_APPEND = constants_1.constants.O_APPEND; + S_IFDIR = constants_1.constants.S_IFDIR, + S_IFREG = constants_1.constants.S_IFREG, + S_IFLNK = constants_1.constants.S_IFLNK, + O_APPEND = constants_1.constants.O_APPEND; + var getuid = function () { + var _a, _b; + return (_b = (_a = process_1.default.getuid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0; + }; + var getgid = function () { + var _a, _b; + return (_b = (_a = process_1.default.getgid) === null || _a === void 0 ? void 0 : _a.call(process_1.default)) !== null && _b !== void 0 ? _b : 0; + }; exports$8.SEP = "/"; /** * Node in a file system (like i-node, v-node). */ - - var Node = function (_super) { + var Node = /** @class */function (_super) { __extends(Node, _super); - function Node(ino, perm) { if (perm === void 0) { perm = 438; } - - var _this = _super.call(this) || this; // User ID and group ID. - - - _this.uid = process_1.default.getuid(); - _this.gid = process_1.default.getgid(); - _this.atime = new Date(); - _this.mtime = new Date(); - _this.ctime = new Date(); - _this.perm = 438; // Permissions `chmod`, `fchmod` - + var _this = _super.call(this) || this; + // User ID and group ID. + _this._uid = getuid(); + _this._gid = getgid(); + _this._atime = new Date(); + _this._mtime = new Date(); + _this._ctime = new Date(); + _this._perm = 438; // Permissions `chmod`, `fchmod` _this.mode = S_IFREG; // S_IFDIR, S_IFREG, etc.. (file by default?) // Number of hard links pointing at this Node. - - _this.nlink = 1; - _this.perm = perm; + _this._nlink = 1; + _this._perm = perm; _this.mode |= perm; _this.ino = ino; return _this; } - + Object.defineProperty(Node.prototype, "ctime", { + get: function () { + return this._ctime; + }, + set: function (ctime) { + this._ctime = ctime; + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Node.prototype, "uid", { + get: function () { + return this._uid; + }, + set: function (uid) { + this._uid = uid; + this.ctime = new Date(); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Node.prototype, "gid", { + get: function () { + return this._gid; + }, + set: function (gid) { + this._gid = gid; + this.ctime = new Date(); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Node.prototype, "atime", { + get: function () { + return this._atime; + }, + set: function (atime) { + this._atime = atime; + this.ctime = new Date(); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Node.prototype, "mtime", { + get: function () { + return this._mtime; + }, + set: function (mtime) { + this._mtime = mtime; + this.ctime = new Date(); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Node.prototype, "perm", { + get: function () { + return this._perm; + }, + set: function (perm) { + this._perm = perm; + this.ctime = new Date(); + }, + enumerable: false, + configurable: true + }); + Object.defineProperty(Node.prototype, "nlink", { + get: function () { + return this._nlink; + }, + set: function (nlink) { + this._nlink = nlink; + this.ctime = new Date(); + }, + enumerable: false, + configurable: true + }); Node.prototype.getString = function (encoding) { if (encoding === void 0) { encoding = "utf8"; } - + this.atime = new Date(); return this.getBuffer().toString(encoding); }; - Node.prototype.setString = function (str) { // this.setBuffer(bufferFrom(str, 'utf8')); this.buf = (0, buffer_1.bufferFrom)(str, "utf8"); this.touch(); }; - Node.prototype.getBuffer = function () { + this.atime = new Date(); if (!this.buf) this.setBuffer((0, buffer_1.bufferAllocUnsafe)(0)); return (0, buffer_1.bufferFrom)(this.buf); // Return a copy. }; - Node.prototype.setBuffer = function (buf) { this.buf = (0, buffer_1.bufferFrom)(buf); // Creates a copy of data. - this.touch(); }; - Node.prototype.getSize = function () { return this.buf ? this.buf.length : 0; }; - Node.prototype.setModeProperty = function (property) { this.mode = this.mode & ~S_IFMT | property; }; - Node.prototype.setIsFile = function () { this.setModeProperty(S_IFREG); }; - Node.prototype.setIsDirectory = function () { this.setModeProperty(S_IFDIR); }; - Node.prototype.setIsSymlink = function () { this.setModeProperty(S_IFLNK); }; - Node.prototype.isFile = function () { return (this.mode & S_IFMT) === S_IFREG; }; - Node.prototype.isDirectory = function () { return (this.mode & S_IFMT) === S_IFDIR; }; - Node.prototype.isSymlink = function () { // return !!this.symlink; return (this.mode & S_IFMT) === S_IFLNK; }; - Node.prototype.makeSymlink = function (steps) { this.symlink = steps; this.setIsSymlink(); }; - Node.prototype.write = function (buf, off, len, pos) { if (off === void 0) { off = 0; } - if (len === void 0) { len = buf.length; } - if (pos === void 0) { pos = 0; } - if (!this.buf) this.buf = (0, buffer_1.bufferAllocUnsafe)(0); - if (pos + len > this.buf.length) { var newBuf = (0, buffer_1.bufferAllocUnsafe)(pos + len); this.buf.copy(newBuf, 0, 0, this.buf.length); this.buf = newBuf; } - buf.copy(this.buf, pos, off, off + len); this.touch(); return len; - }; // Returns the number of bytes read. - - + }; + // Returns the number of bytes read. Node.prototype.read = function (buf, off, len, pos) { if (off === void 0) { off = 0; } - if (len === void 0) { len = buf.byteLength; } - if (pos === void 0) { pos = 0; } - + this.atime = new Date(); if (!this.buf) this.buf = (0, buffer_1.bufferAllocUnsafe)(0); var actualLen = len; - if (actualLen > buf.byteLength) { actualLen = buf.byteLength; } - if (actualLen + pos > this.buf.length) { actualLen = this.buf.length - pos; } - this.buf.copy(buf, off, pos, pos + actualLen); return actualLen; }; - Node.prototype.truncate = function (len) { if (len === void 0) { len = 0; } - if (!len) this.buf = (0, buffer_1.bufferAllocUnsafe)(0);else { if (!this.buf) this.buf = (0, buffer_1.bufferAllocUnsafe)(0); - if (len <= this.buf.length) { this.buf = this.buf.slice(0, len); } else { - var buf = (0, buffer_1.bufferAllocUnsafe)(0); + var buf = (0, buffer_1.bufferAllocUnsafe)(len); this.buf.copy(buf); - buf.fill(0, len); + buf.fill(0, this.buf.length); + this.buf = buf; } } this.touch(); }; - Node.prototype.chmod = function (perm) { this.perm = perm; this.mode = this.mode & ~511 | perm; this.touch(); }; - Node.prototype.chown = function (uid, gid) { this.uid = uid; this.gid = gid; this.touch(); }; - Node.prototype.touch = function () { this.mtime = new Date(); this.emit("change", this); }; - Node.prototype.canRead = function (uid, gid) { if (uid === void 0) { - uid = process_1.default.getuid(); + uid = getuid(); } - if (gid === void 0) { - gid = process_1.default.getgid(); + gid = getgid(); } - - if (this.perm & 4 - /* IROTH */ - ) { + if (this.perm & 4 /* S.IROTH */) { return true; } - if (gid === this.gid) { - if (this.perm & 32 - /* IRGRP */ - ) { + if (this.perm & 32 /* S.IRGRP */) { return true; } } - if (uid === this.uid) { - if (this.perm & 256 - /* IRUSR */ - ) { + if (this.perm & 256 /* S.IRUSR */) { return true; } } - return false; }; - Node.prototype.canWrite = function (uid, gid) { if (uid === void 0) { - uid = process_1.default.getuid(); + uid = getuid(); } - if (gid === void 0) { - gid = process_1.default.getgid(); + gid = getgid(); } - - if (this.perm & 2 - /* IWOTH */ - ) { + if (this.perm & 2 /* S.IWOTH */) { return true; } - if (gid === this.gid) { - if (this.perm & 16 - /* IWGRP */ - ) { + if (this.perm & 16 /* S.IWGRP */) { return true; } } - if (uid === this.uid) { - if (this.perm & 128 - /* IWUSR */ - ) { + if (this.perm & 128 /* S.IWUSR */) { return true; } } - return false; }; - Node.prototype.del = function () { this.emit("delete", this); }; - Node.prototype.toJSON = function () { return { ino: this.ino, @@ -1091,88 +1010,109 @@ function dew$6() { data: this.getString() }; }; - return Node; }(events_1.EventEmitter); - exports$8.Node = Node; /** * Represents a hard link that points to an i-node `node`. */ - - var Link = function (_super) { + var Link = /** @class */function (_super) { __extends(Link, _super); - function Link(vol, parent, name) { var _this = _super.call(this) || this; - - _this.children = {}; // Path to this node as Array: ['usr', 'bin', 'node']. - - _this.steps = []; // "i-node" number of the node. - - _this.ino = 0; // Number of children. - + _this.children = {}; + // Path to this node as Array: ['usr', 'bin', 'node']. + _this._steps = []; + // "i-node" number of the node. + _this.ino = 0; + // Number of children. _this.length = 0; _this.vol = vol; _this.parent = parent; - _this.steps = parent ? parent.steps.concat([name]) : [name]; + _this.name = name; + _this.syncSteps(); return _this; } - + Object.defineProperty(Link.prototype, "steps", { + get: function () { + return this._steps; + }, + // Recursively sync children steps, e.g. in case of dir rename + set: function (val) { + this._steps = val; + for (var _i = 0, _a = Object.entries(this.children); _i < _a.length; _i++) { + var _b = _a[_i], + child = _b[0], + link = _b[1]; + if (child === "." || child === "..") { + continue; + } + link === null || link === void 0 ? void 0 : link.syncSteps(); + } + }, + enumerable: false, + configurable: true + }); Link.prototype.setNode = function (node) { this.node = node; this.ino = node.ino; }; - Link.prototype.getNode = function () { return this.node; }; - Link.prototype.createChild = function (name, node) { if (node === void 0) { node = this.vol.createNode(); } - var link = new Link(this.vol, this, name); link.setNode(node); - - if (node.isDirectory()) ; - + if (node.isDirectory()) { + link.children["."] = link; + link.getNode().nlink++; + } this.setChild(name, link); return link; }; - Link.prototype.setChild = function (name, link) { if (link === void 0) { link = new Link(this.vol, this, name); } - this.children[name] = link; link.parent = this; this.length++; + var node = link.getNode(); + if (node.isDirectory()) { + link.children[".."] = this; + this.getNode().nlink++; + } + this.getNode().mtime = new Date(); this.emit("child:add", link, this); return link; }; - Link.prototype.deleteChild = function (link) { - delete this.children[link.getName()]; + var node = link.getNode(); + if (node.isDirectory()) { + delete link.children[".."]; + this.getNode().nlink--; + } + delete this.children[link.getName()]; this.length--; + this.getNode().mtime = new Date(); this.emit("child:delete", link, this); }; - Link.prototype.getChild = function (name) { + this.getNode().mtime = new Date(); if (Object.hasOwnProperty.call(this.children, name)) { return this.children[name]; } }; - Link.prototype.getPath = function () { return this.steps.join(exports$8.SEP); }; - Link.prototype.getName = function () { return this.steps[this.steps.length - 1]; - }; // del() { + }; + // del() { // const parent = this.parent; // if(parent) { // parent.deleteChild(link); @@ -1180,7 +1120,6 @@ function dew$6() { // this.parent = null; // this.vol = null; // } - /** * Walk the tree path and return the `Link` at that location, if any. * @param steps {string[]} Desired location. @@ -1189,17 +1128,13 @@ function dew$6() { * * @return {Link|null} */ - - Link.prototype.walk = function (steps, stop, i) { if (stop === void 0) { stop = steps.length; } - if (i === void 0) { i = 0; } - if (i >= steps.length) return this; if (i >= stop) return this; var step = steps[i]; @@ -1207,7 +1142,6 @@ function dew$6() { if (!link) return null; return link.walk(steps, stop, i + 1); }; - Link.prototype.toJSON = function () { return { steps: this.steps, @@ -1215,16 +1149,16 @@ function dew$6() { children: Object.keys(this.children) }; }; - + Link.prototype.syncSteps = function () { + this.steps = this.parent ? this.parent.steps.concat([this.name]) : [this.name]; + }; return Link; }(events_1.EventEmitter); - exports$8.Link = Link; /** * Represents an open file (file descriptor) that points to a `Link` (Hard-link) and a `Node`. */ - - var File = function () { + var File = /** @class */function () { /** * Open a Link-Node pair. `node` is provided separately as that might be a different node * rather the one `link` points to, because it might be a symlink. @@ -1244,91 +1178,70 @@ function dew$6() { this.flags = flags; this.fd = fd; } - File.prototype.getString = function (encoding) { - return this.node.getString(); }; - File.prototype.setString = function (str) { this.node.setString(str); }; - File.prototype.getBuffer = function () { return this.node.getBuffer(); }; - File.prototype.setBuffer = function (buf) { this.node.setBuffer(buf); }; - File.prototype.getSize = function () { return this.node.getSize(); }; - File.prototype.truncate = function (len) { this.node.truncate(len); }; - File.prototype.seekTo = function (position) { this.position = position; }; - File.prototype.stats = function () { return Stats_1.default.build(this.node); }; - File.prototype.write = function (buf, offset, length, position) { if (offset === void 0) { offset = 0; } - if (length === void 0) { length = buf.length; } - if (typeof position !== "number") position = this.position; if (this.flags & O_APPEND) position = this.getSize(); var bytes = this.node.write(buf, offset, length, position); this.position = position + bytes; return bytes; }; - File.prototype.read = function (buf, offset, length, position) { if (offset === void 0) { offset = 0; } - if (length === void 0) { length = buf.byteLength; } - if (typeof position !== "number") position = this.position; var bytes = this.node.read(buf, offset, length, position); this.position = position + bytes; return bytes; }; - File.prototype.chmod = function (perm) { this.node.chmod(perm); }; - File.prototype.chown = function (uid, gid) { this.node.chown(uid, gid); }; - return File; }(); - exports$8.File = File; return exports$8; } var exports$7 = {}, - _dewExec$5 = false; - + _dewExec$5 = false; var _global$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$5() { if (_dewExec$5) return exports$7; _dewExec$5 = true; @@ -1339,23 +1252,20 @@ function dew$5() { * `setTimeoutUnref` is just like `setTimeout`, * only in Node's environment it will "unref" its macro task. */ - function setTimeoutUnref(callback, time, args) { var ref = setTimeout.apply(typeof globalThis !== "undefined" ? globalThis : _global$1, arguments); if (ref && typeof ref === "object" && typeof ref.unref === "function") ref.unref(); return ref; } - exports$7.default = setTimeoutUnref; return exports$7; } var exports$6 = {}, - _dewExec$4 = false; + _dewExec$4 = false; function dew$4() { if (_dewExec$4) return exports$6; _dewExec$4 = true; - var __spreadArray = exports$6 && exports$6.__spreadArray || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { @@ -1365,26 +1275,21 @@ function dew$4() { } return to.concat(ar || Array.prototype.slice.call(from)); }; - Object.defineProperty(exports$6, "__esModule", { value: true }); exports$6.FileHandle = void 0; - function promisify(vol, fn, getResult) { if (getResult === void 0) { getResult = function (input) { return input; }; } - return function () { var args = []; - for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - return new Promise(function (resolve, reject) { vol[fn].bind(vol).apply(void 0, __spreadArray(__spreadArray([], args, false), [function (error, result) { if (error) return reject(error); @@ -1393,33 +1298,26 @@ function dew$4() { }); }; } - - var FileHandle = function () { + var FileHandle = /** @class */function () { function FileHandle(vol, fd) { this.vol = vol; this.fd = fd; } - FileHandle.prototype.appendFile = function (data, options) { return promisify(this.vol, "appendFile")(this.fd, data, options); }; - FileHandle.prototype.chmod = function (mode) { return promisify(this.vol, "fchmod")(this.fd, mode); }; - FileHandle.prototype.chown = function (uid, gid) { return promisify(this.vol, "fchown")(this.fd, uid, gid); }; - FileHandle.prototype.close = function () { return promisify(this.vol, "close")(this.fd); }; - FileHandle.prototype.datasync = function () { return promisify(this.vol, "fdatasync")(this.fd); }; - FileHandle.prototype.read = function (buffer, offset, length, position) { return promisify(this.vol, "read", function (bytesRead) { return { @@ -1428,27 +1326,21 @@ function dew$4() { }; })(this.fd, buffer, offset, length, position); }; - FileHandle.prototype.readFile = function (options) { return promisify(this.vol, "readFile")(this.fd, options); }; - FileHandle.prototype.stat = function (options) { return promisify(this.vol, "fstat")(this.fd, options); }; - FileHandle.prototype.sync = function () { return promisify(this.vol, "fsync")(this.fd); }; - FileHandle.prototype.truncate = function (len) { return promisify(this.vol, "ftruncate")(this.fd, len); }; - FileHandle.prototype.utimes = function (atime, mtime) { return promisify(this.vol, "futimes")(this.fd, atime, mtime); }; - FileHandle.prototype.write = function (buffer, offset, length, position) { return promisify(this.vol, "write", function (bytesWritten) { return { @@ -1457,16 +1349,12 @@ function dew$4() { }; })(this.fd, buffer, offset, length, position); }; - FileHandle.prototype.writeFile = function (data, options) { return promisify(this.vol, "writeFile")(this.fd, data, options); }; - return FileHandle; }(); - exports$6.FileHandle = FileHandle; - function createPromisesApi(vol) { if (typeof Promise === "undefined") return null; return { @@ -1527,6 +1415,9 @@ function dew$4() { rmdir: function (path) { return promisify(vol, "rmdir")(path); }, + rm: function (path, options) { + return promisify(vol, "rm")(path, options); + }, stat: function (path, options) { return promisify(vol, "stat")(path, options); }, @@ -1547,13 +1438,12 @@ function dew$4() { } }; } - exports$6.default = createPromisesApi; return exports$6; } var exports$5 = {}, - _dewExec$3 = false; + _dewExec$3 = false; function dew$3() { if (_dewExec$3) return exports$5; _dewExec$3 = true; @@ -1561,70 +1451,53 @@ function dew$3() { Object.defineProperty(exports$5, "__esModule", { value: true }); - exports$5.unixify = unixify; exports$5.correctPath = correctPath; + exports$5.unixify = unixify; var isWin = process$1.platform === "win32"; - function removeTrailingSeparator(str) { var i = str.length - 1; - if (i < 2) { return str; } - while (isSeparator(str, i)) { i--; } - return str.substr(0, i + 1); } - function isSeparator(str, i) { var _char = str[i]; return i > 0 && (_char === "/" || isWin && _char === "\\"); } - function normalizePath(str, stripTrailing) { if (typeof str !== "string") { throw new TypeError("expected a string"); } - str = str.replace(/[\\\/]+/g, "/"); - if (stripTrailing !== false) { str = removeTrailingSeparator(str); } - return str; } - function unixify(filepath) { var stripTrailing = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true; - if (isWin) { filepath = normalizePath(filepath, stripTrailing); return filepath.replace(/^([a-zA-Z]+:|\.\/)/, ""); } - return filepath; } - function correctPath(filepath) { return unixify(filepath.replace(/^\\\\\?\\.:\\/, "\\")); } - return exports$5; } var exports$4 = {}, - _dewExec$2 = false; - + _dewExec$2 = false; var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$2() { if (_dewExec$2) return exports$4; _dewExec$2 = true; - var __extends = exports$4 && exports$4.__extends || function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || { @@ -1634,22 +1507,17 @@ function dew$2() { } || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; - return extendStatics(d, b); }; - return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); - function __() { this.constructor = d; } - d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; }(); - var __spreadArray = exports$4 && exports$4.__spreadArray || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { @@ -1659,66 +1527,48 @@ function dew$2() { } return to.concat(ar || Array.prototype.slice.call(from)); }; - Object.defineProperty(exports$4, "__esModule", { value: true }); exports$4.FSWatcher = exports$4.StatWatcher = exports$4.Volume = exports$4.toUnixTimestamp = exports$4.bufferToEncoding = exports$4.dataToBuffer = exports$4.dataToStr = exports$4.pathToSteps = exports$4.filenameToSteps = exports$4.pathToFilename = exports$4.flagsToNumber = exports$4.FLAGS = void 0; var pathModule = exports$i; - var node_1 = dew$6(); - var Stats_1 = dew$d(); - var Dirent_1 = dew$9(); - var buffer_1 = dew$c(); - var setImmediate_1 = dew$8(); - var process_1 = dew$7(); - var setTimeoutUnref_1 = dew$5(); - var stream_1 = exports$j; - var constants_1 = dew$f(); - var events_1 = y; - var encoding_1 = dew$a(); - var errors = dew$b(); - var util = X; - var promises_1 = dew$4(); - var resolveCrossPlatform = pathModule.resolve; var O_RDONLY = constants_1.constants.O_RDONLY, - O_WRONLY = constants_1.constants.O_WRONLY, - O_RDWR = constants_1.constants.O_RDWR, - O_CREAT = constants_1.constants.O_CREAT, - O_EXCL = constants_1.constants.O_EXCL, - O_TRUNC = constants_1.constants.O_TRUNC, - O_APPEND = constants_1.constants.O_APPEND, - O_SYNC = constants_1.constants.O_SYNC, - O_DIRECTORY = constants_1.constants.O_DIRECTORY, - F_OK = constants_1.constants.F_OK, - COPYFILE_EXCL = constants_1.constants.COPYFILE_EXCL, - COPYFILE_FICLONE_FORCE = constants_1.constants.COPYFILE_FICLONE_FORCE; - + O_WRONLY = constants_1.constants.O_WRONLY, + O_RDWR = constants_1.constants.O_RDWR, + O_CREAT = constants_1.constants.O_CREAT, + O_EXCL = constants_1.constants.O_EXCL, + O_TRUNC = constants_1.constants.O_TRUNC, + O_APPEND = constants_1.constants.O_APPEND, + O_SYNC = constants_1.constants.O_SYNC, + O_DIRECTORY = constants_1.constants.O_DIRECTORY, + F_OK = constants_1.constants.F_OK, + COPYFILE_EXCL = constants_1.constants.COPYFILE_EXCL, + COPYFILE_FICLONE_FORCE = constants_1.constants.COPYFILE_FICLONE_FORCE; var _a = pathModule.posix ? pathModule.posix : pathModule, - sep = _a.sep, - relative = _a.relative, - join = _a.join, - dirname = _a.dirname; - + sep = _a.sep, + relative = _a.relative, + join = _a.join, + dirname = _a.dirname; var isWin = process_1.default.platform === "win32"; - var kMinPoolSpace = 128; // const kMaxLength = require('buffer').kMaxLength; + var kMinPoolSpace = 128; + // const kMaxLength = require('buffer').kMaxLength; // ---------------------------------------- Error messages // TODO: Use `internal/errors.js` in the future. - var ERRSTR = { PATH_STR: "path must be a string or Buffer", // FD: 'file descriptor must be a unsigned 32-bit integer', @@ -1736,12 +1586,10 @@ function dew$2() { LENGTH: "length must be an integer", POSITION: "position must be an integer" }; - var ERRSTR_OPTS = function (tipeof) { - return "Expected options to be either an object or a string, but got " + tipeof + " instead"; - }; // const ERRSTR_FLAG = flag => `Unknown file open flag: ${flag}`; - - + return "Expected options to be either an object or a string, but got ".concat(tipeof, " instead"); + }; + // const ERRSTR_FLAG = flag => `Unknown file open flag: ${flag}`; var ENOENT = "ENOENT"; var EBADF = "EBADF"; var EINVAL = "EINVAL"; @@ -1754,155 +1602,130 @@ function dew$2() { var EISDIR = "EISDIR"; var ENOTEMPTY = "ENOTEMPTY"; var ENOSYS = "ENOSYS"; - + var ERR_FS_EISDIR = "ERR_FS_EISDIR"; function formatError(errorCode, func, path, path2) { if (func === void 0) { func = ""; } - if (path === void 0) { path = ""; } - if (path2 === void 0) { path2 = ""; } - var pathFormatted = ""; - if (path) pathFormatted = " '" + path + "'"; - if (path2) pathFormatted += " -> '" + path2 + "'"; - + if (path) pathFormatted = " '".concat(path, "'"); + if (path2) pathFormatted += " -> '".concat(path2, "'"); switch (errorCode) { case ENOENT: - return "ENOENT: no such file or directory, " + func + pathFormatted; - + return "ENOENT: no such file or directory, ".concat(func).concat(pathFormatted); case EBADF: - return "EBADF: bad file descriptor, " + func + pathFormatted; - + return "EBADF: bad file descriptor, ".concat(func).concat(pathFormatted); case EINVAL: - return "EINVAL: invalid argument, " + func + pathFormatted; - + return "EINVAL: invalid argument, ".concat(func).concat(pathFormatted); case EPERM: - return "EPERM: operation not permitted, " + func + pathFormatted; - + return "EPERM: operation not permitted, ".concat(func).concat(pathFormatted); case EPROTO: - return "EPROTO: protocol error, " + func + pathFormatted; - + return "EPROTO: protocol error, ".concat(func).concat(pathFormatted); case EEXIST: - return "EEXIST: file already exists, " + func + pathFormatted; - + return "EEXIST: file already exists, ".concat(func).concat(pathFormatted); case ENOTDIR: - return "ENOTDIR: not a directory, " + func + pathFormatted; - + return "ENOTDIR: not a directory, ".concat(func).concat(pathFormatted); case EISDIR: - return "EISDIR: illegal operation on a directory, " + func + pathFormatted; - + return "EISDIR: illegal operation on a directory, ".concat(func).concat(pathFormatted); case EACCES: - return "EACCES: permission denied, " + func + pathFormatted; - + return "EACCES: permission denied, ".concat(func).concat(pathFormatted); case ENOTEMPTY: - return "ENOTEMPTY: directory not empty, " + func + pathFormatted; - + return "ENOTEMPTY: directory not empty, ".concat(func).concat(pathFormatted); case EMFILE: - return "EMFILE: too many open files, " + func + pathFormatted; - + return "EMFILE: too many open files, ".concat(func).concat(pathFormatted); case ENOSYS: - return "ENOSYS: function not implemented, " + func + pathFormatted; - + return "ENOSYS: function not implemented, ".concat(func).concat(pathFormatted); + case ERR_FS_EISDIR: + return "[ERR_FS_EISDIR]: Path is a directory: ".concat(func, " returned EISDIR (is a directory) ").concat(path); default: - return errorCode + ": error occurred, " + func + pathFormatted; + return "".concat(errorCode, ": error occurred, ").concat(func).concat(pathFormatted); } } - function createError(errorCode, func, path, path2, Constructor) { if (func === void 0) { func = ""; } - if (path === void 0) { path = ""; } - if (path2 === void 0) { path2 = ""; } - if (Constructor === void 0) { Constructor = Error; } - var error = new Constructor(formatError(errorCode, func, path, path2)); error.code = errorCode; + if (path) { + error.path = path; + } return error; - } // ---------------------------------------- Flags + } + // ---------------------------------------- Flags // List of file `flags` as defined by Node. - - var FLAGS; - (function (FLAGS) { // Open file for reading. An exception occurs if the file does not exist. - FLAGS[FLAGS["r"] = O_RDONLY] = "r"; // Open file for reading and writing. An exception occurs if the file does not exist. - - FLAGS[FLAGS["r+"] = O_RDWR] = "r+"; // Open file for reading in synchronous mode. Instructs the operating system to bypass the local file system cache. - + FLAGS[FLAGS["r"] = O_RDONLY] = "r"; + // Open file for reading and writing. An exception occurs if the file does not exist. + FLAGS[FLAGS["r+"] = O_RDWR] = "r+"; + // Open file for reading in synchronous mode. Instructs the operating system to bypass the local file system cache. FLAGS[FLAGS["rs"] = O_RDONLY | O_SYNC] = "rs"; - FLAGS[FLAGS["sr"] = FLAGS.rs] = "sr"; // Open file for reading and writing, telling the OS to open it synchronously. See notes for 'rs' about using this with caution. - + FLAGS[FLAGS["sr"] = FLAGS.rs] = "sr"; + // Open file for reading and writing, telling the OS to open it synchronously. See notes for 'rs' about using this with caution. FLAGS[FLAGS["rs+"] = O_RDWR | O_SYNC] = "rs+"; - FLAGS[FLAGS["sr+"] = FLAGS["rs+"]] = "sr+"; // Open file for writing. The file is created (if it does not exist) or truncated (if it exists). - - FLAGS[FLAGS["w"] = O_WRONLY | O_CREAT | O_TRUNC] = "w"; // Like 'w' but fails if path exists. - + FLAGS[FLAGS["sr+"] = FLAGS["rs+"]] = "sr+"; + // Open file for writing. The file is created (if it does not exist) or truncated (if it exists). + FLAGS[FLAGS["w"] = O_WRONLY | O_CREAT | O_TRUNC] = "w"; + // Like 'w' but fails if path exists. FLAGS[FLAGS["wx"] = O_WRONLY | O_CREAT | O_TRUNC | O_EXCL] = "wx"; - FLAGS[FLAGS["xw"] = FLAGS.wx] = "xw"; // Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). - - FLAGS[FLAGS["w+"] = O_RDWR | O_CREAT | O_TRUNC] = "w+"; // Like 'w+' but fails if path exists. - + FLAGS[FLAGS["xw"] = FLAGS.wx] = "xw"; + // Open file for reading and writing. The file is created (if it does not exist) or truncated (if it exists). + FLAGS[FLAGS["w+"] = O_RDWR | O_CREAT | O_TRUNC] = "w+"; + // Like 'w+' but fails if path exists. FLAGS[FLAGS["wx+"] = O_RDWR | O_CREAT | O_TRUNC | O_EXCL] = "wx+"; - FLAGS[FLAGS["xw+"] = FLAGS["wx+"]] = "xw+"; // Open file for appending. The file is created if it does not exist. - - FLAGS[FLAGS["a"] = O_WRONLY | O_APPEND | O_CREAT] = "a"; // Like 'a' but fails if path exists. - + FLAGS[FLAGS["xw+"] = FLAGS["wx+"]] = "xw+"; + // Open file for appending. The file is created if it does not exist. + FLAGS[FLAGS["a"] = O_WRONLY | O_APPEND | O_CREAT] = "a"; + // Like 'a' but fails if path exists. FLAGS[FLAGS["ax"] = O_WRONLY | O_APPEND | O_CREAT | O_EXCL] = "ax"; - FLAGS[FLAGS["xa"] = FLAGS.ax] = "xa"; // Open file for reading and appending. The file is created if it does not exist. - - FLAGS[FLAGS["a+"] = O_RDWR | O_APPEND | O_CREAT] = "a+"; // Like 'a+' but fails if path exists. - + FLAGS[FLAGS["xa"] = FLAGS.ax] = "xa"; + // Open file for reading and appending. The file is created if it does not exist. + FLAGS[FLAGS["a+"] = O_RDWR | O_APPEND | O_CREAT] = "a+"; + // Like 'a+' but fails if path exists. FLAGS[FLAGS["ax+"] = O_RDWR | O_APPEND | O_CREAT | O_EXCL] = "ax+"; FLAGS[FLAGS["xa+"] = FLAGS["ax+"]] = "xa+"; })(FLAGS = exports$4.FLAGS || (exports$4.FLAGS = {})); - function flagsToNumber(flags) { if (typeof flags === "number") return flags; - if (typeof flags === "string") { var flagsNum = FLAGS[flags]; if (typeof flagsNum !== "undefined") return flagsNum; - } // throw new TypeError(formatError(ERRSTR_FLAG(flags))); - - + } + // throw new TypeError(formatError(ERRSTR_FLAG(flags))); throw new errors.TypeError("ERR_INVALID_OPT_VALUE", "flags", flags); } - - exports$4.flagsToNumber = flagsToNumber; // ---------------------------------------- Options - + exports$4.flagsToNumber = flagsToNumber; + // ---------------------------------------- Options function getOptions(defaults, options) { var opts; if (!options) return defaults;else { var tipeof = typeof options; - switch (tipeof) { case "string": opts = Object.assign({}, defaults, { encoding: options }); break; - case "object": opts = Object.assign({}, defaults, options); break; - default: throw TypeError(ERRSTR_OPTS(tipeof)); } @@ -1910,24 +1733,20 @@ function dew$2() { if (opts.encoding !== "buffer") (0, encoding_1.assertEncoding)(opts.encoding); return opts; } - function optsGenerator(defaults) { return function (options) { return getOptions(defaults, options); }; } - function validateCallback(callback) { if (typeof callback !== "function") throw TypeError(ERRSTR.CB); return callback; } - function optsAndCbGenerator(getOpts) { return function (options, callback) { return typeof options === "function" ? [getOpts(), options] : [getOpts(options), validateCallback(callback)]; }; } - var optsDefaults = { encoding: "utf8" }; @@ -1939,17 +1758,13 @@ function dew$2() { var getReadFileOptions = optsGenerator(readFileOptsDefaults); var writeFileDefaults = { encoding: "utf8", - mode: 438 - /* DEFAULT */ - , + mode: 438 /* MODE.DEFAULT */, flag: FLAGS[FLAGS.w] }; var getWriteFileOptions = optsGenerator(writeFileDefaults); var appendFileDefaults = { encoding: "utf8", - mode: 438 - /* DEFAULT */ - , + mode: 438 /* MODE.DEFAULT */, flag: FLAGS[FLAGS.a] }; var getAppendFileOpts = optsGenerator(appendFileDefaults); @@ -1958,27 +1773,23 @@ function dew$2() { var getRealpathOptions = optsGenerator(realpathDefaults); var getRealpathOptsAndCb = optsAndCbGenerator(getRealpathOptions); var mkdirDefaults = { - mode: 511 - /* DIR */ - , + mode: 511 /* MODE.DIR */, recursive: false }; - var getMkdirOptions = function (options) { if (typeof options === "number") return Object.assign({}, mkdirDefaults, { mode: options }); return Object.assign({}, mkdirDefaults, options); }; - var rmdirDefaults = { recursive: false }; - var getRmdirOptions = function (options) { return Object.assign({}, rmdirDefaults, options); }; - + var getRmOpts = optsGenerator(optsDefaults); + var getRmOptsAndCb = optsAndCbGenerator(getRmOpts); var readdirDefaults = { encoding: "utf8", withFileTypes: false @@ -1988,40 +1799,31 @@ function dew$2() { var statDefaults = { bigint: false }; - var getStatOptions = function (options) { if (options === void 0) { options = {}; } - return Object.assign({}, statDefaults, options); }; - var getStatOptsAndCb = function (options, callback) { return typeof options === "function" ? [getStatOptions(), options] : [getStatOptions(options), validateCallback(callback)]; - }; // ---------------------------------------- Utility functions - - + }; + // ---------------------------------------- Utility functions function getPathFromURLPosix(url) { if (url.hostname !== "") { throw new errors.TypeError("ERR_INVALID_FILE_URL_HOST", process_1.default.platform); } - var pathname = url.pathname; - for (var n = 0; n < pathname.length; n++) { if (pathname[n] === "%") { var third = pathname.codePointAt(n + 2) | 32; - if (pathname[n + 1] === "2" && third === 102) { throw new errors.TypeError("ERR_INVALID_FILE_URL_PATH", "must not include encoded / characters"); } } } - return decodeURIComponent(pathname); } - function pathToFilename(path) { if (typeof path !== "string" && !buffer_1.Buffer.isBuffer(path)) { try { @@ -2029,149 +1831,111 @@ function dew$2() { } catch (err) { throw new TypeError(ERRSTR.PATH_STR); } - path = getPathFromURLPosix(path); } - var pathString = String(path); - nullCheck(pathString); // return slash(pathString); - + nullCheck(pathString); + // return slash(pathString); return pathString; } - exports$4.pathToFilename = pathToFilename; - var resolve = function (filename, base) { if (base === void 0) { base = process_1.default.cwd(); } - return resolveCrossPlatform(base, filename); }; - if (isWin) { var _resolve_1 = resolve; - var unixify_1 = dew$3().unixify; - resolve = function (filename, base) { return unixify_1(_resolve_1(filename, base)); }; } - function filenameToSteps(filename, base) { var fullPath = resolve(filename, base); - var fullPathSansSlash = fullPath.substr(1); + var fullPathSansSlash = fullPath.substring(1); if (!fullPathSansSlash) return []; return fullPathSansSlash.split(sep); } - exports$4.filenameToSteps = filenameToSteps; - function pathToSteps(path) { return filenameToSteps(pathToFilename(path)); } - exports$4.pathToSteps = pathToSteps; - function dataToStr(data, encoding) { if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; } - if (buffer_1.Buffer.isBuffer(data)) return data.toString(encoding);else if (data instanceof Uint8Array) return (0, buffer_1.bufferFrom)(data).toString(encoding);else return String(data); } - exports$4.dataToStr = dataToStr; - function dataToBuffer(data, encoding) { if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; } - if (buffer_1.Buffer.isBuffer(data)) return data;else if (data instanceof Uint8Array) return (0, buffer_1.bufferFrom)(data);else return (0, buffer_1.bufferFrom)(String(data), encoding); } - exports$4.dataToBuffer = dataToBuffer; - function bufferToEncoding(buffer, encoding) { if (!encoding || encoding === "buffer") return buffer;else return buffer.toString(encoding); } - exports$4.bufferToEncoding = bufferToEncoding; - function nullCheck(path, callback) { if (("" + path).indexOf("\0") !== -1) { var er = new Error("Path must be a string without null bytes"); er.code = ENOENT; throw er; } - return true; } - function _modeToNumber(mode, def) { if (typeof mode === "number") return mode; if (typeof mode === "string") return parseInt(mode, 8); if (def) return modeToNumber(def); return undefined; } - function modeToNumber(mode, def) { var result = _modeToNumber(mode, def); - if (typeof result !== "number" || isNaN(result)) throw new TypeError(ERRSTR.MODE_INT); return result; } - function isFd(path) { return path >>> 0 === path; } - function validateFd(fd) { if (!isFd(fd)) throw TypeError(ERRSTR.FD); - } // converts Date or number to a fractional UNIX timestamp - - + } + // converts Date or number to a fractional UNIX timestamp function toUnixTimestamp(time) { // tslint:disable-next-line triple-equals if (typeof time === "string" && +time == time) { return +time; } - if (time instanceof Date) { return time.getTime() / 1000; } - if (isFinite(time)) { if (time < 0) { return Date.now() / 1000; } - return time; } - throw new Error("Cannot parse time: " + time); } - exports$4.toUnixTimestamp = toUnixTimestamp; - function validateUid(uid) { if (typeof uid !== "number") throw TypeError(ERRSTR.UID); } - function validateGid(gid) { if (typeof gid !== "number") throw TypeError(ERRSTR.GID); } - function flattenJSON(nestedJSON) { var flatJSON = {}; - function flatten(pathPrefix, node) { for (var path in node) { var contentOrNode = node[path]; var joinedPath = join(pathPrefix, path); - if (typeof contentOrNode === "string") { flatJSON[joinedPath] = contentOrNode; } else if (typeof contentOrNode === "object" && contentOrNode !== null && Object.keys(contentOrNode).length > 0) { @@ -2184,35 +1948,31 @@ function dew$2() { } } } - flatten("", nestedJSON); return flatJSON; } /** * `Volume` represents a file system. */ - - - var Volume = function () { + var Volume = /** @class */function () { function Volume(props) { if (props === void 0) { props = {}; - } // I-node number counter. - - - this.ino = 0; // A mapping for i-node numbers to i-nodes (`Node`); - - this.inodes = {}; // List of released i-node numbers, for reuse. - - this.releasedInos = []; // A mapping for file descriptors to `File`s. - - this.fds = {}; // A list of reusable (opened and closed) file descriptors, that should be + } + // I-node number counter. + this.ino = 0; + // A mapping for i-node numbers to i-nodes (`Node`); + this.inodes = {}; + // List of released i-node numbers, for reuse. + this.releasedInos = []; + // A mapping for file descriptors to `File`s. + this.fds = {}; + // A list of reusable (opened and closed) file descriptors, that should be // used first before creating a new file descriptor. - - this.releasedFds = []; // Max number of open files. - - this.maxFiles = 10000; // Current number of open files. - + this.releasedFds = []; + // Max number of open files. + this.maxFiles = 10000; + // Current number of open files. this.openFiles = 0; this.promisesApi = (0, promises_1.default)(this); this.statWatchers = {}; @@ -2224,82 +1984,60 @@ function dew$2() { var root = this.createLink(); root.setNode(this.createNode(true)); var self = this; // tslint:disable-line no-this-assignment - - this.StatWatcher = function (_super) { + this.StatWatcher = /** @class */function (_super) { __extends(StatWatcher, _super); - function StatWatcher() { return _super.call(this, self) || this; } - return StatWatcher; }(StatWatcher); - var _ReadStream = FsReadStream; - - this.ReadStream = function (_super) { + this.ReadStream = /** @class */function (_super) { __extends(class_1, _super); - function class_1() { var args = []; - for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - return _super.apply(this, __spreadArray([self], args, false)) || this; } - return class_1; }(_ReadStream); - var _WriteStream = FsWriteStream; - - this.WriteStream = function (_super) { + this.WriteStream = /** @class */function (_super) { __extends(class_2, _super); - function class_2() { var args = []; - for (var _i = 0; _i < arguments.length; _i++) { args[_i] = arguments[_i]; } - return _super.apply(this, __spreadArray([self], args, false)) || this; } - return class_2; }(_WriteStream); - - this.FSWatcher = function (_super) { + this.FSWatcher = /** @class */function (_super) { __extends(FSWatcher, _super); - function FSWatcher() { return _super.call(this, self) || this; } - return FSWatcher; - }(FSWatcher); // root.setChild('.', root); - // root.getNode().nlink++; - // root.setChild('..', root); - // root.getNode().nlink++; - - + }(FSWatcher); + root.setChild(".", root); + root.getNode().nlink++; + root.setChild("..", root); + root.getNode().nlink++; this.root = root; } - Volume.fromJSON = function (json, cwd) { var vol = new Volume(); vol.fromJSON(json, cwd); return vol; }; - Volume.fromNestedJSON = function (json, cwd) { var vol = new Volume(); vol.fromNestedJSON(json, cwd); return vol; }; - Object.defineProperty(Volume.prototype, "promises", { get: function () { if (this.promisesApi === null) throw new Error("Promise is not supported in this environment."); @@ -2308,34 +2046,26 @@ function dew$2() { enumerable: false, configurable: true }); - Volume.prototype.createLink = function (parent, name, isDirectory, perm) { if (isDirectory === void 0) { isDirectory = false; } - if (!parent) { return new this.props.Link(this, null, ""); } - if (!name) { throw new Error("createLink: name cannot be empty"); } - return parent.createChild(name, this.createNode(isDirectory, perm)); }; - Volume.prototype.deleteLink = function (link) { var parent = link.parent; - if (parent) { parent.deleteChild(link); return true; } - return false; }; - Volume.prototype.newInoNumber = function () { var releasedFd = this.releasedInos.pop(); if (releasedFd) return releasedFd;else { @@ -2343,84 +2073,69 @@ function dew$2() { return this.ino; } }; - Volume.prototype.newFdNumber = function () { var releasedFd = this.releasedFds.pop(); return typeof releasedFd === "number" ? releasedFd : Volume.fd--; }; - Volume.prototype.createNode = function (isDirectory, perm) { if (isDirectory === void 0) { isDirectory = false; } - var node = new this.props.Node(this.newInoNumber(), perm); if (isDirectory) node.setIsDirectory(); this.inodes[node.ino] = node; return node; }; - Volume.prototype.getNode = function (ino) { return this.inodes[ino]; }; - Volume.prototype.deleteNode = function (node) { node.del(); delete this.inodes[node.ino]; this.releasedInos.push(node.ino); - }; // Generates 6 character long random string, used by `mkdtemp`. - - + }; + // Generates 6 character long random string, used by `mkdtemp`. Volume.prototype.genRndStr = function () { - var str = (Math.random() + 1).toString(36).substr(2, 6); + var str = (Math.random() + 1).toString(36).substring(2, 8); if (str.length === 6) return str;else return this.genRndStr(); - }; // Returns a `Link` (hard link) referenced by path "split" into steps. - - + }; + // Returns a `Link` (hard link) referenced by path "split" into steps. Volume.prototype.getLink = function (steps) { return this.root.walk(steps); - }; // Just link `getLink`, but throws a correct user error, if link to found. - - + }; + // Just link `getLink`, but throws a correct user error, if link to found. Volume.prototype.getLinkOrThrow = function (filename, funcName) { var steps = filenameToSteps(filename); var link = this.getLink(steps); if (!link) throw createError(ENOENT, funcName, filename); return link; - }; // Just like `getLink`, but also dereference/resolves symbolic links. - - + }; + // Just like `getLink`, but also dereference/resolves symbolic links. Volume.prototype.getResolvedLink = function (filenameOrSteps) { var steps = typeof filenameOrSteps === "string" ? filenameToSteps(filenameOrSteps) : filenameOrSteps; var link = this.root; var i = 0; - while (i < steps.length) { var step = steps[i]; link = link.getChild(step); if (!link) return null; var node = link.getNode(); - if (node.isSymlink()) { steps = node.symlink.concat(steps.slice(i + 1)); link = this.root; i = 0; continue; } - i++; } - return link; - }; // Just like `getLinkOrThrow`, but also dereference/resolves symbolic links. - - + }; + // Just like `getLinkOrThrow`, but also dereference/resolves symbolic links. Volume.prototype.getResolvedLinkOrThrow = function (filename, funcName) { var link = this.getResolvedLink(filename); if (!link) throw createError(ENOENT, funcName, filename); return link; }; - Volume.prototype.resolveSymlinks = function (link) { // let node: Node = link.getNode(); // while(link && node.isSymlink()) { @@ -2430,20 +2145,17 @@ function dew$2() { // } // return link; return this.getResolvedLink(link.steps.slice(1)); - }; // Just like `getLinkOrThrow`, but also verifies that the link is a directory. - - + }; + // Just like `getLinkOrThrow`, but also verifies that the link is a directory. Volume.prototype.getLinkAsDirOrThrow = function (filename, funcName) { var link = this.getLinkOrThrow(filename, funcName); if (!link.getNode().isDirectory()) throw createError(ENOTDIR, funcName, filename); return link; - }; // Get the immediate parent directory of the link. - - + }; + // Get the immediate parent directory of the link. Volume.prototype.getLinkParent = function (steps) { return this.root.walk(steps, steps.length - 1); }; - Volume.prototype.getLinkParentAsDirOrThrow = function (filenameOrSteps, funcName) { var steps = filenameOrSteps instanceof Array ? filenameOrSteps : filenameToSteps(filenameOrSteps); var link = this.getLinkParent(steps); @@ -2451,89 +2163,79 @@ function dew$2() { if (!link.getNode().isDirectory()) throw createError(ENOTDIR, funcName, sep + steps.join(sep)); return link; }; - Volume.prototype.getFileByFd = function (fd) { return this.fds[String(fd)]; }; - Volume.prototype.getFileByFdOrThrow = function (fd, funcName) { if (!isFd(fd)) throw TypeError(ERRSTR.FD); var file = this.getFileByFd(fd); if (!file) throw createError(EBADF, funcName); return file; }; - - Volume.prototype.getNodeByIdOrCreate = function (id, flags, perm) { - if (typeof id === "number") { - var file = this.getFileByFd(id); - if (!file) throw Error("File nto found"); + /** + * @todo This is not used anymore. Remove. + */ + /* + private getNodeByIdOrCreate(id: TFileId, flags: number, perm: number): Node { + if (typeof id === 'number') { + const file = this.getFileByFd(id); + if (!file) throw Error('File nto found'); return file.node; } else { - var steps = pathToSteps(id); - var link = this.getLink(steps); - if (link) return link.getNode(); // Try creating a node if not found. - + const steps = pathToSteps(id as PathLike); + let link = this.getLink(steps); + if (link) return link.getNode(); + // Try creating a node if not found. if (flags & O_CREAT) { - var dirLink = this.getLinkParent(steps); - + const dirLink = this.getLinkParent(steps); if (dirLink) { - var name_1 = steps[steps.length - 1]; - link = this.createLink(dirLink, name_1, false, perm); + const name = steps[steps.length - 1]; + link = this.createLink(dirLink, name, false, perm); return link.getNode(); } } - - throw createError(ENOENT, "getNodeByIdOrCreate", pathToFilename(id)); + throw createError(ENOENT, 'getNodeByIdOrCreate', pathToFilename(id)); } - }; - + } + */ Volume.prototype.wrapAsync = function (method, args, callback) { var _this = this; - validateCallback(callback); (0, setImmediate_1.default)(function () { var result; - try { result = method.apply(_this, args); } catch (err) { callback(err); return; } - callback(null, result); }); }; - Volume.prototype._toJSON = function (link, json, path) { var _a; - if (link === void 0) { link = this.root; } - if (json === void 0) { json = {}; } - var isEmpty = true; var children = link.children; - if (link.getNode().isFile()) { children = (_a = {}, _a[link.getName()] = link.parent.getChild(link.getName()), _a); link = link.parent; } - - for (var name_2 in children) { + for (var name_1 in children) { + if (name_1 === "." || name_1 === "..") { + continue; + } isEmpty = false; - var child = link.getChild(name_2); - + var child = link.getChild(name_1); if (!child) { throw new Error("_toJSON: unexpected undefined"); } - var node = child.getNode(); - if (node.isFile()) { var filename = child.getPath(); if (path) filename = relative(path, filename); @@ -2542,31 +2244,23 @@ function dew$2() { this._toJSON(child, json, path); } } - var dirPath = link.getPath(); if (path) dirPath = relative(path, dirPath); - if (dirPath && isEmpty) { json[dirPath] = null; } - return json; }; - Volume.prototype.toJSON = function (paths, json, isRelative) { if (json === void 0) { json = {}; } - if (isRelative === void 0) { isRelative = false; } - var links = []; - if (paths) { if (!(paths instanceof Array)) paths = [paths]; - for (var _i = 0, paths_1 = paths; _i < paths_1.length; _i++) { var path = paths_1[_i]; var filename = pathToFilename(path); @@ -2577,45 +2271,32 @@ function dew$2() { } else { links.push(this.root); } - if (!links.length) return json; - for (var _a = 0, links_1 = links; _a < links_1.length; _a++) { var link = links_1[_a]; - this._toJSON(link, json, isRelative ? link.getPath() : ""); } - return json; }; - Volume.prototype.fromJSON = function (json, cwd) { if (cwd === void 0) { cwd = process_1.default.cwd(); } - for (var filename in json) { var data = json[filename]; filename = resolve(filename, cwd); - if (typeof data === "string") { var dir = dirname(filename); - this.mkdirpBase(dir, 511 - /* DIR */ - ); + this.mkdirpBase(dir, 511 /* MODE.DIR */); this.writeFileSync(filename, data); } else { - this.mkdirpBase(filename, 511 - /* DIR */ - ); + this.mkdirpBase(filename, 511 /* MODE.DIR */); } } }; - Volume.prototype.fromNestedJSON = function (json, cwd) { this.fromJSON(flattenJSON(json), cwd); }; - Volume.prototype.reset = function () { this.ino = 0; this.inodes = {}; @@ -2625,134 +2306,108 @@ function dew$2() { this.openFiles = 0; this.root = this.createLink(); this.root.setNode(this.createNode(true)); - }; // Legacy interface - - + }; + // Legacy interface Volume.prototype.mountSync = function (mountpoint, json) { this.fromJSON(json, mountpoint); }; - Volume.prototype.openLink = function (link, flagsNum, resolveSymlinks) { if (resolveSymlinks === void 0) { resolveSymlinks = true; } - if (this.openFiles >= this.maxFiles) { // Too many open files. throw createError(EMFILE, "open", link.getPath()); - } // Resolve symlinks. - - + } + // Resolve symlinks. var realLink = link; if (resolveSymlinks) realLink = this.resolveSymlinks(link); if (!realLink) throw createError(ENOENT, "open", link.getPath()); - var node = realLink.getNode(); // Check whether node is a directory - + var node = realLink.getNode(); + // Check whether node is a directory if (node.isDirectory()) { if ((flagsNum & (O_RDONLY | O_RDWR | O_WRONLY)) !== O_RDONLY) throw createError(EISDIR, "open", link.getPath()); } else { if (flagsNum & O_DIRECTORY) throw createError(ENOTDIR, "open", link.getPath()); - } // Check node permissions - - + } + // Check node permissions if (!(flagsNum & O_WRONLY)) { if (!node.canRead()) { throw createError(EACCES, "open", link.getPath()); } } - var file = new this.props.File(link, node, flagsNum, this.newFdNumber()); this.fds[file.fd] = file; this.openFiles++; if (flagsNum & O_TRUNC) file.truncate(); return file; }; - Volume.prototype.openFile = function (filename, flagsNum, modeNum, resolveSymlinks) { if (resolveSymlinks === void 0) { resolveSymlinks = true; } - var steps = filenameToSteps(filename); - var link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps); // Try creating a new file, if it does not exist. - + var link = resolveSymlinks ? this.getResolvedLink(steps) : this.getLink(steps); + if (link && flagsNum & O_EXCL) throw createError(EEXIST, "open", filename); + // Try creating a new file, if it does not exist. if (!link && flagsNum & O_CREAT) { // const dirLink: Link = this.getLinkParent(steps); - var dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1)); // if(!dirLink) throw createError(ENOENT, 'open', filename); - + var dirLink = this.getResolvedLink(steps.slice(0, steps.length - 1)); + // if(!dirLink) throw createError(ENOENT, 'open', filename); if (!dirLink) throw createError(ENOENT, "open", sep + steps.join(sep)); - if (flagsNum & O_CREAT && typeof modeNum === "number") { link = this.createLink(dirLink, steps[steps.length - 1], false, modeNum); } } - if (link) return this.openLink(link, flagsNum, resolveSymlinks); throw createError(ENOENT, "open", filename); }; - Volume.prototype.openBase = function (filename, flagsNum, modeNum, resolveSymlinks) { if (resolveSymlinks === void 0) { resolveSymlinks = true; } - var file = this.openFile(filename, flagsNum, modeNum, resolveSymlinks); if (!file) throw createError(ENOENT, "open", filename); return file.fd; }; - Volume.prototype.openSync = function (path, flags, mode) { if (mode === void 0) { - mode = 438 - /* DEFAULT */ - ; - } // Validate (1) mode; (2) path; (3) flags - in that order. - - + mode = 438 /* MODE.DEFAULT */; + } + // Validate (1) mode; (2) path; (3) flags - in that order. var modeNum = modeToNumber(mode); var fileName = pathToFilename(path); var flagsNum = flagsToNumber(flags); return this.openBase(fileName, flagsNum, modeNum); }; - Volume.prototype.open = function (path, flags, a, b) { var mode = a; var callback = b; - if (typeof a === "function") { - mode = 438 - /* DEFAULT */ - ; + mode = 438 /* MODE.DEFAULT */; callback = a; } - - mode = mode || 438 - /* DEFAULT */ - ; + mode = mode || 438 /* MODE.DEFAULT */; var modeNum = modeToNumber(mode); var fileName = pathToFilename(path); var flagsNum = flagsToNumber(flags); this.wrapAsync(this.openBase, [fileName, flagsNum, modeNum], callback); }; - Volume.prototype.closeFile = function (file) { if (!this.fds[file.fd]) return; this.openFiles--; delete this.fds[file.fd]; this.releasedFds.push(file.fd); }; - Volume.prototype.closeSync = function (fd) { validateFd(fd); var file = this.getFileByFdOrThrow(fd, "close"); this.closeFile(file); }; - Volume.prototype.close = function (fd, callback) { validateFd(fd); this.wrapAsync(this.closeSync, [fd], callback); }; - Volume.prototype.openFileOrGetById = function (id, flagsNum, modeNum) { if (typeof id === "number") { var file = this.fds[id]; @@ -2762,39 +2417,32 @@ function dew$2() { return this.openFile(pathToFilename(id), flagsNum, modeNum); } }; - Volume.prototype.readBase = function (fd, buffer, offset, length, position) { var file = this.getFileByFdOrThrow(fd); return file.read(buffer, Number(offset), Number(length), position); }; - Volume.prototype.readSync = function (fd, buffer, offset, length, position) { validateFd(fd); return this.readBase(fd, buffer, offset, length, position); }; - Volume.prototype.read = function (fd, buffer, offset, length, position, callback) { var _this = this; - - validateCallback(callback); // This `if` branch is from Node.js - + validateCallback(callback); + // This `if` branch is from Node.js if (length === 0) { return process_1.default.nextTick(function () { if (callback) callback(null, 0, buffer); }); } - (0, setImmediate_1.default)(function () { try { var bytes = _this.readBase(fd, buffer, offset, length, position); - callback(null, bytes, buffer); } catch (err) { callback(err); } }); }; - Volume.prototype.readFileBase = function (id, flagsNum, encoding) { var result; var isUserFd = typeof id === "number"; @@ -2804,15 +2452,12 @@ function dew$2() { var filename = pathToFilename(id); var steps = filenameToSteps(filename); var link = this.getResolvedLink(steps); - if (link) { var node = link.getNode(); if (node.isDirectory()) throw createError(EISDIR, "open", link.getPath()); } - fd = this.openSync(id, flagsNum); } - try { result = bufferToEncoding(this.getFileByFdOrThrow(fd).getBuffer(), encoding); } finally { @@ -2820,30 +2465,24 @@ function dew$2() { this.closeSync(fd); } } - return result; }; - Volume.prototype.readFileSync = function (file, options) { var opts = getReadFileOptions(options); var flagsNum = flagsToNumber(opts.flag); return this.readFileBase(file, flagsNum, opts.encoding); }; - Volume.prototype.readFile = function (id, a, b) { var _a = optsAndCbGenerator(getReadFileOptions)(a, b), - opts = _a[0], - callback = _a[1]; - + opts = _a[0], + callback = _a[1]; var flagsNum = flagsToNumber(opts.flag); this.wrapAsync(this.readFileBase, [id, flagsNum, opts.encoding], callback); }; - Volume.prototype.writeBase = function (fd, buf, offset, length, position) { var file = this.getFileByFdOrThrow(fd, "write"); return file.write(buf, offset, length, position); }; - Volume.prototype.writeSync = function (fd, a, b, c, d) { validateFd(fd); var encoding; @@ -2851,7 +2490,6 @@ function dew$2() { var length; var position; var isBuffer = typeof a !== "string"; - if (isBuffer) { offset = (b || 0) | 0; length = c; @@ -2860,9 +2498,7 @@ function dew$2() { position = b; encoding = c; } - var buf = dataToBuffer(a, encoding); - if (isBuffer) { if (typeof length === "undefined") { length = buf.length; @@ -2871,13 +2507,10 @@ function dew$2() { offset = 0; length = buf.length; } - return this.writeBase(fd, buf, offset, length, position); }; - Volume.prototype.write = function (fd, a, b, c, d, e) { var _this = this; - validateFd(fd); var offset; var length; @@ -2888,7 +2521,6 @@ function dew$2() { var tipb = typeof b; var tipc = typeof c; var tipd = typeof d; - if (tipa !== "string") { if (tipb === "function") { callback = b; @@ -2917,21 +2549,17 @@ function dew$2() { callback = d; } } - var buf = dataToBuffer(a, encoding); - if (tipa !== "string") { if (typeof length === "undefined") length = buf.length; } else { offset = 0; length = buf.length; } - var cb = validateCallback(callback); (0, setImmediate_1.default)(function () { try { var bytes = _this.writeBase(fd, buf, offset, length, position); - if (tipa !== "string") { cb(null, bytes, buf); } else { @@ -2942,7 +2570,6 @@ function dew$2() { } }); }; - Volume.prototype.writeFileBase = function (id, buf, flagsNum, modeNum) { // console.log('writeFileBase', id, buf, flagsNum, modeNum); // const node = this.getNodeByIdOrCreate(id, flagsNum, modeNum); @@ -2950,12 +2577,12 @@ function dew$2() { var isUserFd = typeof id === "number"; var fd; if (isUserFd) fd = id;else { - fd = this.openBase(pathToFilename(id), flagsNum, modeNum); // fd = this.openSync(id as PathLike, flagsNum, modeNum); + fd = this.openBase(pathToFilename(id), flagsNum, modeNum); + // fd = this.openSync(id as PathLike, flagsNum, modeNum); } var offset = 0; var length = buf.length; var position = flagsNum & O_APPEND ? undefined : 0; - try { while (length > 0) { var written = this.writeSync(fd, buf, offset, length, position); @@ -2967,7 +2594,6 @@ function dew$2() { if (!isUserFd) this.closeSync(fd); } }; - Volume.prototype.writeFileSync = function (id, data, options) { var opts = getWriteFileOptions(options); var flagsNum = flagsToNumber(opts.flag); @@ -2975,16 +2601,13 @@ function dew$2() { var buf = dataToBuffer(data, opts.encoding); this.writeFileBase(id, buf, flagsNum, modeNum); }; - Volume.prototype.writeFile = function (id, data, a, b) { var options = a; var callback = b; - if (typeof a === "function") { options = writeFileDefaults; callback = a; } - var cb = validateCallback(callback); var opts = getWriteFileOptions(options); var flagsNum = flagsToNumber(opts.flag); @@ -2992,53 +2615,43 @@ function dew$2() { var buf = dataToBuffer(data, opts.encoding); this.wrapAsync(this.writeFileBase, [id, buf, flagsNum, modeNum], cb); }; - Volume.prototype.linkBase = function (filename1, filename2) { var steps1 = filenameToSteps(filename1); var link1 = this.getLink(steps1); if (!link1) throw createError(ENOENT, "link", filename1, filename2); - var steps2 = filenameToSteps(filename2); // Check new link directory exists. - + var steps2 = filenameToSteps(filename2); + // Check new link directory exists. var dir2 = this.getLinkParent(steps2); if (!dir2) throw createError(ENOENT, "link", filename1, filename2); - var name = steps2[steps2.length - 1]; // Check if new file already exists. - + var name = steps2[steps2.length - 1]; + // Check if new file already exists. if (dir2.getChild(name)) throw createError(EEXIST, "link", filename1, filename2); var node = link1.getNode(); node.nlink++; dir2.createChild(name, node); }; - Volume.prototype.copyFileBase = function (src, dest, flags) { var buf = this.readFileSync(src); - if (flags & COPYFILE_EXCL) { if (this.existsSync(dest)) { throw createError(EEXIST, "copyFile", src, dest); } } - if (flags & COPYFILE_FICLONE_FORCE) { throw createError(ENOSYS, "copyFile", src, dest); } - - this.writeFileBase(dest, buf, FLAGS.w, 438 - /* DEFAULT */ - ); + this.writeFileBase(dest, buf, FLAGS.w, 438 /* MODE.DEFAULT */); }; - Volume.prototype.copyFileSync = function (src, dest, flags) { var srcFilename = pathToFilename(src); var destFilename = pathToFilename(dest); return this.copyFileBase(srcFilename, destFilename, (flags || 0) | 0); }; - Volume.prototype.copyFile = function (src, dest, a, b) { var srcFilename = pathToFilename(src); var destFilename = pathToFilename(dest); var flags; var callback; - if (typeof a === "function") { flags = 0; callback = a; @@ -3046,201 +2659,201 @@ function dew$2() { flags = a; callback = b; } - validateCallback(callback); this.wrapAsync(this.copyFileBase, [srcFilename, destFilename, flags], callback); }; - Volume.prototype.linkSync = function (existingPath, newPath) { var existingPathFilename = pathToFilename(existingPath); var newPathFilename = pathToFilename(newPath); this.linkBase(existingPathFilename, newPathFilename); }; - Volume.prototype.link = function (existingPath, newPath, callback) { var existingPathFilename = pathToFilename(existingPath); var newPathFilename = pathToFilename(newPath); this.wrapAsync(this.linkBase, [existingPathFilename, newPathFilename], callback); }; - Volume.prototype.unlinkBase = function (filename) { var steps = filenameToSteps(filename); var link = this.getLink(steps); - if (!link) throw createError(ENOENT, "unlink", filename); // TODO: Check if it is file, dir, other... - + if (!link) throw createError(ENOENT, "unlink", filename); + // TODO: Check if it is file, dir, other... if (link.length) throw Error("Dir not empty..."); this.deleteLink(link); var node = link.getNode(); - node.nlink--; // When all hard links to i-node are deleted, remove the i-node, too. - + node.nlink--; + // When all hard links to i-node are deleted, remove the i-node, too. if (node.nlink <= 0) { this.deleteNode(node); } }; - Volume.prototype.unlinkSync = function (path) { var filename = pathToFilename(path); this.unlinkBase(filename); }; - Volume.prototype.unlink = function (path, callback) { var filename = pathToFilename(path); this.wrapAsync(this.unlinkBase, [filename], callback); }; - Volume.prototype.symlinkBase = function (targetFilename, pathFilename) { - var pathSteps = filenameToSteps(pathFilename); // Check if directory exists, where we about to create a symlink. - + var pathSteps = filenameToSteps(pathFilename); + // Check if directory exists, where we about to create a symlink. var dirLink = this.getLinkParent(pathSteps); if (!dirLink) throw createError(ENOENT, "symlink", targetFilename, pathFilename); - var name = pathSteps[pathSteps.length - 1]; // Check if new file already exists. - - if (dirLink.getChild(name)) throw createError(EEXIST, "symlink", targetFilename, pathFilename); // Create symlink. - + var name = pathSteps[pathSteps.length - 1]; + // Check if new file already exists. + if (dirLink.getChild(name)) throw createError(EEXIST, "symlink", targetFilename, pathFilename); + // Create symlink. var symlink = dirLink.createChild(name); symlink.getNode().makeSymlink(filenameToSteps(targetFilename)); return symlink; - }; // `type` argument works only on Windows. - - + }; + // `type` argument works only on Windows. Volume.prototype.symlinkSync = function (target, path, type) { var targetFilename = pathToFilename(target); var pathFilename = pathToFilename(path); this.symlinkBase(targetFilename, pathFilename); }; - Volume.prototype.symlink = function (target, path, a, b) { var callback = validateCallback(typeof a === "function" ? a : b); var targetFilename = pathToFilename(target); var pathFilename = pathToFilename(path); this.wrapAsync(this.symlinkBase, [targetFilename, pathFilename], callback); }; - Volume.prototype.realpathBase = function (filename, encoding) { var steps = filenameToSteps(filename); var realLink = this.getResolvedLink(steps); if (!realLink) throw createError(ENOENT, "realpath", filename); - return (0, encoding_1.strToEncoding)(realLink.getPath(), encoding); + return (0, encoding_1.strToEncoding)(realLink.getPath() || "/", encoding); }; - Volume.prototype.realpathSync = function (path, options) { return this.realpathBase(pathToFilename(path), getRealpathOptions(options).encoding); }; - Volume.prototype.realpath = function (path, a, b) { var _a = getRealpathOptsAndCb(a, b), - opts = _a[0], - callback = _a[1]; - + opts = _a[0], + callback = _a[1]; var pathFilename = pathToFilename(path); this.wrapAsync(this.realpathBase, [pathFilename, opts.encoding], callback); }; - - Volume.prototype.lstatBase = function (filename, bigint) { + Volume.prototype.lstatBase = function (filename, bigint, throwIfNoEntry) { if (bigint === void 0) { bigint = false; } - + if (throwIfNoEntry === void 0) { + throwIfNoEntry = false; + } var link = this.getLink(filenameToSteps(filename)); - if (!link) throw createError(ENOENT, "lstat", filename); - return Stats_1.default.build(link.getNode(), bigint); + if (link) { + return Stats_1.default.build(link.getNode(), bigint); + } else if (!throwIfNoEntry) { + return undefined; + } else { + throw createError(ENOENT, "lstat", filename); + } }; - Volume.prototype.lstatSync = function (path, options) { - return this.lstatBase(pathToFilename(path), getStatOptions(options).bigint); + var _a = getStatOptions(options), + _b = _a.throwIfNoEntry, + throwIfNoEntry = _b === void 0 ? true : _b, + _c = _a.bigint, + bigint = _c === void 0 ? false : _c; + return this.lstatBase(pathToFilename(path), bigint, throwIfNoEntry); }; - Volume.prototype.lstat = function (path, a, b) { var _a = getStatOptsAndCb(a, b), - opts = _a[0], - callback = _a[1]; - - this.wrapAsync(this.lstatBase, [pathToFilename(path), opts.bigint], callback); - }; - - Volume.prototype.statBase = function (filename, bigint) { + _b = _a[0], + _c = _b.throwIfNoEntry, + throwIfNoEntry = _c === void 0 ? true : _c, + _d = _b.bigint, + bigint = _d === void 0 ? false : _d, + callback = _a[1]; + this.wrapAsync(this.lstatBase, [pathToFilename(path), bigint, throwIfNoEntry], callback); + }; + Volume.prototype.statBase = function (filename, bigint, throwIfNoEntry) { if (bigint === void 0) { bigint = false; } - + if (throwIfNoEntry === void 0) { + throwIfNoEntry = true; + } var link = this.getResolvedLink(filenameToSteps(filename)); - if (!link) throw createError(ENOENT, "stat", filename); - return Stats_1.default.build(link.getNode(), bigint); + if (link) { + return Stats_1.default.build(link.getNode(), bigint); + } else if (!throwIfNoEntry) { + return undefined; + } else { + throw createError(ENOENT, "stat", filename); + } }; - Volume.prototype.statSync = function (path, options) { - return this.statBase(pathToFilename(path), getStatOptions(options).bigint); + var _a = getStatOptions(options), + _b = _a.bigint, + bigint = _b === void 0 ? true : _b, + _c = _a.throwIfNoEntry, + throwIfNoEntry = _c === void 0 ? true : _c; + return this.statBase(pathToFilename(path), bigint, throwIfNoEntry); }; - Volume.prototype.stat = function (path, a, b) { var _a = getStatOptsAndCb(a, b), - opts = _a[0], - callback = _a[1]; - - this.wrapAsync(this.statBase, [pathToFilename(path), opts.bigint], callback); + _b = _a[0], + _c = _b.bigint, + bigint = _c === void 0 ? false : _c, + _d = _b.throwIfNoEntry, + throwIfNoEntry = _d === void 0 ? true : _d, + callback = _a[1]; + this.wrapAsync(this.statBase, [pathToFilename(path), bigint, throwIfNoEntry], callback); }; - Volume.prototype.fstatBase = function (fd, bigint) { if (bigint === void 0) { bigint = false; } - var file = this.getFileByFd(fd); if (!file) throw createError(EBADF, "fstat"); return Stats_1.default.build(file.node, bigint); }; - Volume.prototype.fstatSync = function (fd, options) { return this.fstatBase(fd, getStatOptions(options).bigint); }; - Volume.prototype.fstat = function (fd, a, b) { var _a = getStatOptsAndCb(a, b), - opts = _a[0], - callback = _a[1]; - + opts = _a[0], + callback = _a[1]; this.wrapAsync(this.fstatBase, [fd, opts.bigint], callback); }; - Volume.prototype.renameBase = function (oldPathFilename, newPathFilename) { var link = this.getLink(filenameToSteps(oldPathFilename)); - if (!link) throw createError(ENOENT, "rename", oldPathFilename, newPathFilename); // TODO: Check if it is directory, if non-empty, we cannot move it, right? - - var newPathSteps = filenameToSteps(newPathFilename); // Check directory exists for the new location. - + if (!link) throw createError(ENOENT, "rename", oldPathFilename, newPathFilename); + // TODO: Check if it is directory, if non-empty, we cannot move it, right? + var newPathSteps = filenameToSteps(newPathFilename); + // Check directory exists for the new location. var newPathDirLink = this.getLinkParent(newPathSteps); - if (!newPathDirLink) throw createError(ENOENT, "rename", oldPathFilename, newPathFilename); // TODO: Also treat cases with directories and symbolic links. + if (!newPathDirLink) throw createError(ENOENT, "rename", oldPathFilename, newPathFilename); + // TODO: Also treat cases with directories and symbolic links. // TODO: See: http://man7.org/linux/man-pages/man2/rename.2.html // Remove hard link from old folder. - var oldLinkParent = link.parent; - if (oldLinkParent) { oldLinkParent.deleteChild(link); - } // Rename should overwrite the new path, if that exists. - - + } + // Rename should overwrite the new path, if that exists. var name = newPathSteps[newPathSteps.length - 1]; + link.name = name; link.steps = __spreadArray(__spreadArray([], newPathDirLink.steps, true), [name], false); newPathDirLink.setChild(link.getName(), link); }; - Volume.prototype.renameSync = function (oldPath, newPath) { var oldPathFilename = pathToFilename(oldPath); var newPathFilename = pathToFilename(newPath); this.renameBase(oldPathFilename, newPathFilename); }; - Volume.prototype.rename = function (oldPath, newPath, callback) { var oldPathFilename = pathToFilename(oldPath); var newPathFilename = pathToFilename(newPath); this.wrapAsync(this.renameBase, [oldPathFilename, newPathFilename], callback); }; - Volume.prototype.existsBase = function (filename) { return !!this.statBase(filename); }; - Volume.prototype.existsSync = function (path) { try { return this.existsBase(pathToFilename(path)); @@ -3248,10 +2861,8 @@ function dew$2() { return false; } }; - Volume.prototype.exists = function (path, callback) { var _this = this; - var filename = pathToFilename(path); if (typeof callback !== "function") throw Error(ERRSTR.CB); (0, setImmediate_1.default)(function () { @@ -3262,78 +2873,62 @@ function dew$2() { } }); }; - Volume.prototype.accessBase = function (filename, mode) { - this.getLinkOrThrow(filename, "access"); // TODO: Verify permissions + this.getLinkOrThrow(filename, "access"); + // TODO: Verify permissions }; - Volume.prototype.accessSync = function (path, mode) { if (mode === void 0) { mode = F_OK; } - var filename = pathToFilename(path); mode = mode | 0; this.accessBase(filename, mode); }; - Volume.prototype.access = function (path, a, b) { var mode = F_OK; var callback; - if (typeof a !== "function") { mode = a | 0; // cast to number - callback = validateCallback(b); } else { callback = a; } - var filename = pathToFilename(path); this.wrapAsync(this.accessBase, [filename, mode], callback); }; - Volume.prototype.appendFileSync = function (id, data, options) { if (options === void 0) { options = appendFileDefaults; } - - var opts = getAppendFileOpts(options); // force append behavior when using a supplied file descriptor - + var opts = getAppendFileOpts(options); + // force append behavior when using a supplied file descriptor if (!opts.flag || isFd(id)) opts.flag = "a"; this.writeFileSync(id, data, opts); }; - Volume.prototype.appendFile = function (id, data, a, b) { var _a = getAppendFileOptsAndCb(a, b), - opts = _a[0], - callback = _a[1]; // force append behavior when using a supplied file descriptor - - + opts = _a[0], + callback = _a[1]; + // force append behavior when using a supplied file descriptor if (!opts.flag || isFd(id)) opts.flag = "a"; this.writeFile(id, data, opts, callback); }; - Volume.prototype.readdirBase = function (filename, options) { var steps = filenameToSteps(filename); var link = this.getResolvedLink(steps); if (!link) throw createError(ENOENT, "readdir", filename); var node = link.getNode(); if (!node.isDirectory()) throw createError(ENOTDIR, "scandir", filename); - if (options.withFileTypes) { var list_1 = []; - - for (var name_3 in link.children) { - var child = link.getChild(name_3); - - if (!child) { + for (var name_2 in link.children) { + var child = link.getChild(name_2); + if (!child || name_2 === "." || name_2 === "..") { continue; } - list_1.push(Dirent_1.default.build(child, options.encoding)); } - if (!isWin && options.encoding !== "buffer") list_1.sort(function (a, b) { if (a.name < b.name) return -1; if (a.name > b.name) return 1; @@ -3341,32 +2936,28 @@ function dew$2() { }); return list_1; } - var list = []; - - for (var name_4 in link.children) { - list.push((0, encoding_1.strToEncoding)(name_4, options.encoding)); + for (var name_3 in link.children) { + if (name_3 === "." || name_3 === "..") { + continue; + } + list.push((0, encoding_1.strToEncoding)(name_3, options.encoding)); } - if (!isWin && options.encoding !== "buffer") list.sort(); return list; }; - Volume.prototype.readdirSync = function (path, options) { var opts = getReaddirOptions(options); var filename = pathToFilename(path); return this.readdirBase(filename, opts); }; - Volume.prototype.readdir = function (path, a, b) { var _a = getReaddirOptsAndCb(a, b), - options = _a[0], - callback = _a[1]; - + options = _a[0], + callback = _a[1]; var filename = pathToFilename(path); this.wrapAsync(this.readdirBase, [filename, options], callback); }; - Volume.prototype.readlinkBase = function (filename, encoding) { var link = this.getLinkOrThrow(filename, "readlink"); var node = link.getNode(); @@ -3374,125 +2965,100 @@ function dew$2() { var str = sep + node.symlink.join(sep); return (0, encoding_1.strToEncoding)(str, encoding); }; - Volume.prototype.readlinkSync = function (path, options) { var opts = getDefaultOpts(options); var filename = pathToFilename(path); return this.readlinkBase(filename, opts.encoding); }; - Volume.prototype.readlink = function (path, a, b) { var _a = getDefaultOptsAndCb(a, b), - opts = _a[0], - callback = _a[1]; - + opts = _a[0], + callback = _a[1]; var filename = pathToFilename(path); this.wrapAsync(this.readlinkBase, [filename, opts.encoding], callback); }; - Volume.prototype.fsyncBase = function (fd) { this.getFileByFdOrThrow(fd, "fsync"); }; - Volume.prototype.fsyncSync = function (fd) { this.fsyncBase(fd); }; - Volume.prototype.fsync = function (fd, callback) { this.wrapAsync(this.fsyncBase, [fd], callback); }; - Volume.prototype.fdatasyncBase = function (fd) { this.getFileByFdOrThrow(fd, "fdatasync"); }; - Volume.prototype.fdatasyncSync = function (fd) { this.fdatasyncBase(fd); }; - Volume.prototype.fdatasync = function (fd, callback) { this.wrapAsync(this.fdatasyncBase, [fd], callback); }; - Volume.prototype.ftruncateBase = function (fd, len) { var file = this.getFileByFdOrThrow(fd, "ftruncate"); file.truncate(len); }; - Volume.prototype.ftruncateSync = function (fd, len) { this.ftruncateBase(fd, len); }; - Volume.prototype.ftruncate = function (fd, a, b) { var len = typeof a === "number" ? a : 0; var callback = validateCallback(typeof a === "number" ? b : a); this.wrapAsync(this.ftruncateBase, [fd, len], callback); }; - Volume.prototype.truncateBase = function (path, len) { var fd = this.openSync(path, "r+"); - try { this.ftruncateSync(fd, len); } finally { this.closeSync(fd); } }; - Volume.prototype.truncateSync = function (id, len) { if (isFd(id)) return this.ftruncateSync(id, len); this.truncateBase(id, len); }; - Volume.prototype.truncate = function (id, a, b) { var len = typeof a === "number" ? a : 0; var callback = validateCallback(typeof a === "number" ? b : a); if (isFd(id)) return this.ftruncate(id, len, callback); this.wrapAsync(this.truncateBase, [id, len], callback); }; - Volume.prototype.futimesBase = function (fd, atime, mtime) { var file = this.getFileByFdOrThrow(fd, "futimes"); var node = file.node; node.atime = new Date(atime * 1000); node.mtime = new Date(mtime * 1000); }; - Volume.prototype.futimesSync = function (fd, atime, mtime) { this.futimesBase(fd, toUnixTimestamp(atime), toUnixTimestamp(mtime)); }; - Volume.prototype.futimes = function (fd, atime, mtime, callback) { this.wrapAsync(this.futimesBase, [fd, toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback); }; - Volume.prototype.utimesBase = function (filename, atime, mtime) { - var fd = this.openSync(filename, "r+"); - + var fd = this.openSync(filename, "r"); try { this.futimesBase(fd, atime, mtime); } finally { this.closeSync(fd); } }; - Volume.prototype.utimesSync = function (path, atime, mtime) { this.utimesBase(pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)); }; - Volume.prototype.utimes = function (path, atime, mtime, callback) { this.wrapAsync(this.utimesBase, [pathToFilename(path), toUnixTimestamp(atime), toUnixTimestamp(mtime)], callback); }; - Volume.prototype.mkdirBase = function (filename, modeNum) { - var steps = filenameToSteps(filename); // This will throw if user tries to create root dir `fs.mkdirSync('/')`. - + var steps = filenameToSteps(filename); + // This will throw if user tries to create root dir `fs.mkdirSync('/')`. if (!steps.length) { throw createError(EEXIST, "mkdir", filename); } - - var dir = this.getLinkParentAsDirOrThrow(filename, "mkdir"); // Check path already exists. - + var dir = this.getLinkParentAsDirOrThrow(filename, "mkdir"); + // Check path already exists. var name = steps[steps.length - 1]; if (dir.getChild(name)) throw createError(EEXIST, "mkdir", filename); dir.createChild(name, this.createNode(true, modeNum)); @@ -3502,48 +3068,46 @@ function dew$2() { * @param filename * @param modeNum */ - - Volume.prototype.mkdirpBase = function (filename, modeNum) { - var steps = filenameToSteps(filename); + var fullPath = resolve(filename); + var fullPathSansSlash = fullPath.substring(1); + var steps = !fullPathSansSlash ? [] : fullPathSansSlash.split(sep); var link = this.root; - + var created = false; for (var i = 0; i < steps.length; i++) { var step = steps[i]; if (!link.getNode().isDirectory()) throw createError(ENOTDIR, "mkdir", link.getPath()); var child = link.getChild(step); - if (child) { if (child.getNode().isDirectory()) link = child;else throw createError(ENOTDIR, "mkdir", child.getPath()); } else { link = link.createChild(step, this.createNode(true, modeNum)); + created = true; } } + return created ? fullPath : undefined; }; - Volume.prototype.mkdirSync = function (path, options) { var opts = getMkdirOptions(options); var modeNum = modeToNumber(opts.mode, 511); var filename = pathToFilename(path); - if (opts.recursive) this.mkdirpBase(filename, modeNum);else this.mkdirBase(filename, modeNum); + if (opts.recursive) return this.mkdirpBase(filename, modeNum); + this.mkdirBase(filename, modeNum); }; - Volume.prototype.mkdir = function (path, a, b) { var opts = getMkdirOptions(a); var callback = validateCallback(typeof a === "function" ? a : b); var modeNum = modeToNumber(opts.mode, 511); var filename = pathToFilename(path); if (opts.recursive) this.wrapAsync(this.mkdirpBase, [filename, modeNum], callback);else this.wrapAsync(this.mkdirBase, [filename, modeNum], callback); - }; // legacy interface - - + }; + // legacy interface Volume.prototype.mkdirpSync = function (path, mode) { - this.mkdirSync(path, { + return this.mkdirSync(path, { mode: mode, recursive: true }); }; - Volume.prototype.mkdirp = function (path, a, b) { var mode = typeof a === "function" ? undefined : a; var callback = validateCallback(typeof a === "function" ? a : b); @@ -3552,18 +3116,13 @@ function dew$2() { recursive: true }, callback); }; - Volume.prototype.mkdtempBase = function (prefix, encoding, retry) { if (retry === void 0) { retry = 5; } - var filename = prefix + this.genRndStr(); - try { - this.mkdirBase(filename, 511 - /* DIR */ - ); + this.mkdirBase(filename, 511 /* MODE.DIR */); return (0, encoding_1.strToEncoding)(filename, encoding); } catch (err) { if (err.code === EEXIST) { @@ -3571,119 +3130,125 @@ function dew$2() { } else throw err; } }; - Volume.prototype.mkdtempSync = function (prefix, options) { var encoding = getDefaultOpts(options).encoding; if (!prefix || typeof prefix !== "string") throw new TypeError("filename prefix is required"); nullCheck(prefix); return this.mkdtempBase(prefix, encoding); }; - Volume.prototype.mkdtemp = function (prefix, a, b) { var _a = getDefaultOptsAndCb(a, b), - encoding = _a[0].encoding, - callback = _a[1]; - + encoding = _a[0].encoding, + callback = _a[1]; if (!prefix || typeof prefix !== "string") throw new TypeError("filename prefix is required"); if (!nullCheck(prefix)) return; this.wrapAsync(this.mkdtempBase, [prefix, encoding], callback); }; - Volume.prototype.rmdirBase = function (filename, options) { var opts = getRmdirOptions(options); - var link = this.getLinkAsDirOrThrow(filename, "rmdir"); // Check directory is empty. - + var link = this.getLinkAsDirOrThrow(filename, "rmdir"); + // Check directory is empty. if (link.length && !opts.recursive) throw createError(ENOTEMPTY, "rmdir", filename); this.deleteLink(link); }; - Volume.prototype.rmdirSync = function (path, options) { this.rmdirBase(pathToFilename(path), options); }; - Volume.prototype.rmdir = function (path, a, b) { var opts = getRmdirOptions(a); var callback = validateCallback(typeof a === "function" ? a : b); this.wrapAsync(this.rmdirBase, [pathToFilename(path), opts], callback); }; - + Volume.prototype.rmBase = function (filename, options) { + if (options === void 0) { + options = {}; + } + var link = this.getResolvedLink(filename); + if (!link) { + // "stat" is used to match Node's native error message. + if (!options.force) throw createError(ENOENT, "stat", filename); + return; + } + if (link.getNode().isDirectory()) { + if (!options.recursive) { + throw createError(ERR_FS_EISDIR, "rm", filename); + } + } + this.deleteLink(link); + }; + Volume.prototype.rmSync = function (path, options) { + this.rmBase(pathToFilename(path), options); + }; + Volume.prototype.rm = function (path, a, b) { + var _a = getRmOptsAndCb(a, b), + opts = _a[0], + callback = _a[1]; + this.wrapAsync(this.rmBase, [pathToFilename(path), opts], callback); + }; Volume.prototype.fchmodBase = function (fd, modeNum) { var file = this.getFileByFdOrThrow(fd, "fchmod"); file.chmod(modeNum); }; - Volume.prototype.fchmodSync = function (fd, mode) { this.fchmodBase(fd, modeToNumber(mode)); }; - Volume.prototype.fchmod = function (fd, mode, callback) { this.wrapAsync(this.fchmodBase, [fd, modeToNumber(mode)], callback); }; - Volume.prototype.chmodBase = function (filename, modeNum) { - var fd = this.openSync(filename, "r+"); - + var fd = this.openSync(filename, "r"); try { this.fchmodBase(fd, modeNum); } finally { this.closeSync(fd); } }; - Volume.prototype.chmodSync = function (path, mode) { var modeNum = modeToNumber(mode); var filename = pathToFilename(path); this.chmodBase(filename, modeNum); }; - Volume.prototype.chmod = function (path, mode, callback) { var modeNum = modeToNumber(mode); var filename = pathToFilename(path); this.wrapAsync(this.chmodBase, [filename, modeNum], callback); }; - Volume.prototype.lchmodBase = function (filename, modeNum) { var fd = this.openBase(filename, O_RDWR, 0, false); - try { this.fchmodBase(fd, modeNum); } finally { this.closeSync(fd); } }; - Volume.prototype.lchmodSync = function (path, mode) { var modeNum = modeToNumber(mode); var filename = pathToFilename(path); this.lchmodBase(filename, modeNum); }; - Volume.prototype.lchmod = function (path, mode, callback) { var modeNum = modeToNumber(mode); var filename = pathToFilename(path); this.wrapAsync(this.lchmodBase, [filename, modeNum], callback); }; - Volume.prototype.fchownBase = function (fd, uid, gid) { this.getFileByFdOrThrow(fd, "fchown").chown(uid, gid); }; - Volume.prototype.fchownSync = function (fd, uid, gid) { validateUid(uid); validateGid(gid); this.fchownBase(fd, uid, gid); }; - Volume.prototype.fchown = function (fd, uid, gid, callback) { validateUid(uid); validateGid(gid); this.wrapAsync(this.fchownBase, [fd, uid, gid], callback); }; - Volume.prototype.chownBase = function (filename, uid, gid) { var link = this.getResolvedLinkOrThrow(filename, "chown"); var node = link.getNode(); - node.chown(uid, gid); // if(node.isFile() || node.isSymlink()) { + node.chown(uid, gid); + // if(node.isFile() || node.isSymlink()) { // // } else if(node.isDirectory()) { // @@ -3691,120 +3256,96 @@ function dew$2() { // TODO: What do we do here? // } }; - Volume.prototype.chownSync = function (path, uid, gid) { validateUid(uid); validateGid(gid); this.chownBase(pathToFilename(path), uid, gid); }; - Volume.prototype.chown = function (path, uid, gid, callback) { validateUid(uid); validateGid(gid); this.wrapAsync(this.chownBase, [pathToFilename(path), uid, gid], callback); }; - Volume.prototype.lchownBase = function (filename, uid, gid) { this.getLinkOrThrow(filename, "lchown").getNode().chown(uid, gid); }; - Volume.prototype.lchownSync = function (path, uid, gid) { validateUid(uid); validateGid(gid); this.lchownBase(pathToFilename(path), uid, gid); }; - Volume.prototype.lchown = function (path, uid, gid, callback) { validateUid(uid); validateGid(gid); this.wrapAsync(this.lchownBase, [pathToFilename(path), uid, gid], callback); }; - Volume.prototype.watchFile = function (path, a, b) { var filename = pathToFilename(path); var options = a; var listener = b; - if (typeof options === "function") { listener = a; options = null; } - if (typeof listener !== "function") { throw Error("\"watchFile()\" requires a listener function"); } - var interval = 5007; var persistent = true; - if (options && typeof options === "object") { if (typeof options.interval === "number") interval = options.interval; if (typeof options.persistent === "boolean") persistent = options.persistent; } - var watcher = this.statWatchers[filename]; - if (!watcher) { watcher = new this.StatWatcher(); watcher.start(filename, persistent, interval); this.statWatchers[filename] = watcher; } - watcher.addListener("change", listener); return watcher; }; - Volume.prototype.unwatchFile = function (path, listener) { var filename = pathToFilename(path); var watcher = this.statWatchers[filename]; if (!watcher) return; - if (typeof listener === "function") { watcher.removeListener("change", listener); } else { watcher.removeAllListeners("change"); } - if (watcher.listenerCount("change") === 0) { watcher.stop(); delete this.statWatchers[filename]; } }; - Volume.prototype.createReadStream = function (path, options) { return new this.ReadStream(path, options); }; - Volume.prototype.createWriteStream = function (path, options) { return new this.WriteStream(path, options); - }; // watch(path: PathLike): FSWatcher; + }; + // watch(path: PathLike): FSWatcher; // watch(path: PathLike, options?: IWatchOptions | string): FSWatcher; - - Volume.prototype.watch = function (path, options, listener) { var filename = pathToFilename(path); var givenOptions = options; - if (typeof options === "function") { listener = options; givenOptions = null; - } // tslint:disable-next-line prefer-const - - + } + // tslint:disable-next-line prefer-const var _a = getDefaultOpts(givenOptions), - persistent = _a.persistent, - recursive = _a.recursive, - encoding = _a.encoding; - + persistent = _a.persistent, + recursive = _a.recursive, + encoding = _a.encoding; if (persistent === undefined) persistent = true; if (recursive === undefined) recursive = false; var watcher = new this.FSWatcher(); watcher.start(filename, persistent, recursive, encoding); - if (listener) { watcher.addListener("change", listener); } - return watcher; }; /** @@ -3814,92 +3355,71 @@ function dew$2() { * @type {number} * @todo This should not be static, right? */ - - Volume.fd = 2147483647; return Volume; }(); - exports$4.Volume = Volume; - function emitStop(self) { self.emit("stop"); } - - var StatWatcher = function (_super) { + var StatWatcher = /** @class */function (_super) { __extends(StatWatcher, _super); - function StatWatcher(vol) { var _this = _super.call(this) || this; - _this.onInterval = function () { try { var stats = _this.vol.statSync(_this.filename); - if (_this.hasChanged(stats)) { _this.emit("change", stats, _this.prev); - _this.prev = stats; } } finally { _this.loop(); } }; - _this.vol = vol; return _this; } - StatWatcher.prototype.loop = function () { this.timeoutRef = this.setTimeout(this.onInterval, this.interval); }; - StatWatcher.prototype.hasChanged = function (stats) { // if(!this.prev) return false; if (stats.mtimeMs > this.prev.mtimeMs) return true; if (stats.nlink !== this.prev.nlink) return true; return false; }; - StatWatcher.prototype.start = function (path, persistent, interval) { if (persistent === void 0) { persistent = true; } - if (interval === void 0) { interval = 5007; } - this.filename = pathToFilename(path); this.setTimeout = persistent ? setTimeout.bind(typeof globalThis !== "undefined" ? globalThis : _global) : setTimeoutUnref_1.default; this.interval = interval; this.prev = this.vol.statSync(this.filename); this.loop(); }; - StatWatcher.prototype.stop = function () { clearTimeout(this.timeoutRef); process_1.default.nextTick(emitStop, this); }; - return StatWatcher; }(events_1.EventEmitter); - exports$4.StatWatcher = StatWatcher; var pool; - function allocNewPool(poolSize) { pool = (0, buffer_1.bufferAllocUnsafe)(poolSize); pool.used = 0; } - util.inherits(FsReadStream, stream_1.Readable); exports$4.ReadStream = FsReadStream; - function FsReadStream(vol, path, options) { if (!(this instanceof FsReadStream)) return new FsReadStream(vol, path, options); - this._vol = vol; // a little bit bigger buffer and water marks by default - + this._vol = vol; + // a little bit bigger buffer and water marks by default options = Object.assign({}, getOptions(options, {})); if (options.highWaterMark === undefined) options.highWaterMark = 64 * 1024; stream_1.Readable.call(this, options); @@ -3912,25 +3432,20 @@ function dew$2() { this.autoClose = options.autoClose === undefined ? true : options.autoClose; this.pos = undefined; this.bytesRead = 0; - if (this.start !== undefined) { if (typeof this.start !== "number") { throw new TypeError("\"start\" option must be a Number"); } - if (this.end === undefined) { this.end = Infinity; } else if (typeof this.end !== "number") { throw new TypeError("\"end\" option must be a Number"); } - if (this.start > this.end) { throw new Error("\"start\" option must be <= \"end\" option"); } - this.pos = this.start; } - if (typeof this.fd !== "number") this.open(); this.on("end", function () { if (this.autoClose) { @@ -3938,120 +3453,103 @@ function dew$2() { } }); } - FsReadStream.prototype.open = function () { var self = this; // tslint:disable-line no-this-assignment - this._vol.open(this.path, this.flags, this.mode, function (er, fd) { if (er) { if (self.autoClose) { if (self.destroy) self.destroy(); } - self.emit("error", er); return; } - self.fd = fd; - self.emit("open", fd); // start the flow of data. - + self.emit("open", fd); + // start the flow of data. self.read(); }); }; - FsReadStream.prototype._read = function (n) { if (typeof this.fd !== "number") { return this.once("open", function () { this._read(n); }); } - if (this.destroyed) return; - if (!pool || pool.length - pool.used < kMinPoolSpace) { // discard the old pool. allocNewPool(this._readableState.highWaterMark); - } // Grab another reference to the pool in the case that while we're + } + // Grab another reference to the pool in the case that while we're // in the thread pool another read() finishes up the pool, and // allocates a new one. - - var thisPool = pool; var toRead = Math.min(pool.length - pool.used, n); var start = pool.used; - if (this.pos !== undefined) toRead = Math.min(this.end - this.pos + 1, toRead); // already read everything we were supposed to read! + if (this.pos !== undefined) toRead = Math.min(this.end - this.pos + 1, toRead); + // already read everything we were supposed to read! // treat as EOF. - - if (toRead <= 0) return this.push(null); // the actual read. - + if (toRead <= 0) return this.push(null); + // the actual read. var self = this; // tslint:disable-line no-this-assignment - - this._vol.read(this.fd, pool, pool.used, toRead, this.pos, onread); // move the pool positions, and internal position for reading. - - + this._vol.read(this.fd, pool, pool.used, toRead, this.pos, onread); + // move the pool positions, and internal position for reading. if (this.pos !== undefined) this.pos += toRead; pool.used += toRead; - function onread(er, bytesRead) { if (er) { if (self.autoClose && self.destroy) { self.destroy(); } - self.emit("error", er); } else { var b = null; - if (bytesRead > 0) { self.bytesRead += bytesRead; b = thisPool.slice(start, start + bytesRead); } - self.push(b); } } }; - FsReadStream.prototype._destroy = function (err, cb) { this.close(function (err2) { cb(err || err2); }); }; - FsReadStream.prototype.close = function (cb) { var _this = this; - + var _a; if (cb) this.once("close", cb); - if (this.closed || typeof this.fd !== "number") { if (typeof this.fd !== "number") { this.once("open", closeOnOpen); return; } - return process_1.default.nextTick(function () { return _this.emit("close"); }); } - - this.closed = true; - + // Since Node 18, there is only a getter for '.closed'. + // The first branch mimics other setters from Readable. + // See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/readable.js#L1243 + if (typeof ((_a = this._readableState) === null || _a === void 0 ? void 0 : _a.closed) === "boolean") { + this._readableState.closed = true; + } else { + this.closed = true; + } this._vol.close(this.fd, function (er) { if (er) _this.emit("error", er);else _this.emit("close"); }); - this.fd = null; - }; // needed because as it will be called with arguments + }; + // needed because as it will be called with arguments // that does not match this.close() signature - - function closeOnOpen(fd) { this.close(); } - util.inherits(FsWriteStream, stream_1.Writable); exports$4.WriteStream = FsWriteStream; - function FsWriteStream(vol, path, options) { if (!(this instanceof FsWriteStream)) return new FsWriteStream(vol, path, options); this._vol = vol; @@ -4065,143 +3563,138 @@ function dew$2() { this.autoClose = options.autoClose === undefined ? true : !!options.autoClose; this.pos = undefined; this.bytesWritten = 0; - if (this.start !== undefined) { if (typeof this.start !== "number") { throw new TypeError("\"start\" option must be a Number"); } - if (this.start < 0) { throw new Error("\"start\" must be >= zero"); } - this.pos = this.start; } - if (options.encoding) this.setDefaultEncoding(options.encoding); - if (typeof this.fd !== "number") this.open(); // dispose on finish. - + if (typeof this.fd !== "number") this.open(); + // dispose on finish. this.once("finish", function () { if (this.autoClose) { this.close(); } }); } - FsWriteStream.prototype.open = function () { this._vol.open(this.path, this.flags, this.mode, function (er, fd) { if (er) { if (this.autoClose && this.destroy) { this.destroy(); } - this.emit("error", er); return; } - this.fd = fd; this.emit("open", fd); }.bind(this)); }; - FsWriteStream.prototype._write = function (data, encoding, cb) { - if (!(data instanceof buffer_1.Buffer)) return this.emit("error", new Error("Invalid data")); - + if (!(data instanceof buffer_1.Buffer || data instanceof Uint8Array)) return this.emit("error", new Error("Invalid data")); if (typeof this.fd !== "number") { return this.once("open", function () { this._write(data, encoding, cb); }); } - var self = this; // tslint:disable-line no-this-assignment - this._vol.write(this.fd, data, 0, data.length, this.pos, function (er, bytes) { if (er) { if (self.autoClose && self.destroy) { self.destroy(); } - return cb(er); } - self.bytesWritten += bytes; cb(); }); - if (this.pos !== undefined) this.pos += data.length; }; - FsWriteStream.prototype._writev = function (data, cb) { if (typeof this.fd !== "number") { return this.once("open", function () { this._writev(data, cb); }); } - var self = this; // tslint:disable-line no-this-assignment - var len = data.length; var chunks = new Array(len); var size = 0; - for (var i = 0; i < len; i++) { var chunk = data[i].chunk; chunks[i] = chunk; size += chunk.length; } - var buf = buffer_1.Buffer.concat(chunks); - this._vol.write(this.fd, buf, 0, buf.length, this.pos, function (er, bytes) { if (er) { if (self.destroy) self.destroy(); return cb(er); } - self.bytesWritten += bytes; cb(); }); - if (this.pos !== undefined) this.pos += size; }; - + FsWriteStream.prototype.close = function (cb) { + var _this = this; + var _a; + if (cb) this.once("close", cb); + if (this.closed || typeof this.fd !== "number") { + if (typeof this.fd !== "number") { + this.once("open", closeOnOpen); + return; + } + return process_1.default.nextTick(function () { + return _this.emit("close"); + }); + } + // Since Node 18, there is only a getter for '.closed'. + // The first branch mimics other setters from Writable. + // See https://github.com/nodejs/node/blob/v18.0.0/lib/internal/streams/writable.js#L766 + if (typeof ((_a = this._writableState) === null || _a === void 0 ? void 0 : _a.closed) === "boolean") { + this._writableState.closed = true; + } else { + this.closed = true; + } + this._vol.close(this.fd, function (er) { + if (er) _this.emit("error", er);else _this.emit("close"); + }); + this.fd = null; + }; FsWriteStream.prototype._destroy = FsReadStream.prototype._destroy; - FsWriteStream.prototype.close = FsReadStream.prototype.close; // There is no shutdown() for files. - - FsWriteStream.prototype.destroySoon = FsWriteStream.prototype.end; // ---------------------------------------- FSWatcher - - var FSWatcher = function (_super) { + // There is no shutdown() for files. + FsWriteStream.prototype.destroySoon = FsWriteStream.prototype.end; + // ---------------------------------------- FSWatcher + var FSWatcher = /** @class */function (_super) { __extends(FSWatcher, _super); - function FSWatcher(vol) { var _this = _super.call(this) || this; - _this._filename = ""; - _this._filenameEncoded = ""; // _persistent: boolean = true; - + _this._filenameEncoded = ""; + // _persistent: boolean = true; _this._recursive = false; _this._encoding = encoding_1.ENCODING_UTF8; - - _this._onNodeChange = function () { - _this._emit("change"); - }; - + // inode -> removers + _this._listenerRemovers = new Map(); _this._onParentChild = function (link) { if (link.getName() === _this._getName()) { _this._emit("rename"); } }; - _this._emit = function (type) { _this.emit("change", type, _this._filenameEncoded); }; - _this._persist = function () { _this._timer = setTimeout(_this._persist, 1000000); }; - _this._vol = vol; - return _this; // TODO: Emit "error" messages when watching. + return _this; + // TODO: Emit "error" messages when watching. // this._handle.onchange = function(status, eventType, filename) { // if (status < 0) { // self._handle.close(); @@ -4215,140 +3708,190 @@ function dew$2() { // } // }; } - FSWatcher.prototype._getName = function () { return this._steps[this._steps.length - 1]; }; - FSWatcher.prototype.start = function (path, persistent, recursive, encoding) { + var _this = this; if (persistent === void 0) { persistent = true; } - if (recursive === void 0) { recursive = false; } - if (encoding === void 0) { encoding = encoding_1.ENCODING_UTF8; } - this._filename = pathToFilename(path); this._steps = filenameToSteps(this._filename); - this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename); // this._persistent = persistent; - + this._filenameEncoded = (0, encoding_1.strToEncoding)(this._filename); + // this._persistent = persistent; this._recursive = recursive; this._encoding = encoding; - try { this._link = this._vol.getLinkOrThrow(this._filename, "FSWatcher"); } catch (err) { - var error = new Error("watch " + this._filename + " " + err.code); + var error = new Error("watch ".concat(this._filename, " ").concat(err.code)); error.code = err.code; error.errno = err.code; throw error; } - - this._link.getNode().on("change", this._onNodeChange); - - this._link.on("child:add", this._onNodeChange); - - this._link.on("child:delete", this._onNodeChange); - + var watchLinkNodeChanged = function (link) { + var _a; + var filepath = link.getPath(); + var node = link.getNode(); + var onNodeChange = function () { + var filename = relative(_this._filename, filepath); + if (!filename) { + filename = _this._getName(); + } + return _this.emit("change", "change", filename); + }; + node.on("change", onNodeChange); + var removers = (_a = _this._listenerRemovers.get(node.ino)) !== null && _a !== void 0 ? _a : []; + removers.push(function () { + return node.removeListener("change", onNodeChange); + }); + _this._listenerRemovers.set(node.ino, removers); + }; + var watchLinkChildrenChanged = function (link) { + var _a; + var node = link.getNode(); + // when a new link added + var onLinkChildAdd = function (l) { + _this.emit("change", "rename", relative(_this._filename, l.getPath())); + setTimeout(function () { + // 1. watch changes of the new link-node + watchLinkNodeChanged(l); + // 2. watch changes of the new link-node's children + watchLinkChildrenChanged(l); + }); + }; + // when a new link deleted + var onLinkChildDelete = function (l) { + // remove the listeners of the children nodes + var removeLinkNodeListeners = function (curLink) { + var ino = curLink.getNode().ino; + var removers = _this._listenerRemovers.get(ino); + if (removers) { + removers.forEach(function (r) { + return r(); + }); + _this._listenerRemovers.delete(ino); + } + Object.values(curLink.children).forEach(function (childLink) { + if (childLink) { + removeLinkNodeListeners(childLink); + } + }); + }; + removeLinkNodeListeners(l); + _this.emit("change", "rename", relative(_this._filename, l.getPath())); + }; + // children nodes changed + Object.entries(link.children).forEach(function (_a) { + var name = _a[0], + childLink = _a[1]; + if (childLink && name !== "." && name !== "..") { + watchLinkNodeChanged(childLink); + } + }); + // link children add/remove + link.on("child:add", onLinkChildAdd); + link.on("child:delete", onLinkChildDelete); + var removers = (_a = _this._listenerRemovers.get(node.ino)) !== null && _a !== void 0 ? _a : []; + removers.push(function () { + link.removeListener("child:add", onLinkChildAdd); + link.removeListener("child:delete", onLinkChildDelete); + }); + if (recursive) { + Object.entries(link.children).forEach(function (_a) { + var name = _a[0], + childLink = _a[1]; + if (childLink && name !== "." && name !== "..") { + watchLinkChildrenChanged(childLink); + } + }); + } + }; + watchLinkNodeChanged(this._link); + watchLinkChildrenChanged(this._link); var parent = this._link.parent; - if (parent) { // parent.on('child:add', this._onParentChild); parent.setMaxListeners(parent.getMaxListeners() + 1); parent.on("child:delete", this._onParentChild); } - if (persistent) this._persist(); }; - FSWatcher.prototype.close = function () { clearTimeout(this._timer); - - this._link.getNode().removeListener("change", this._onNodeChange); - + this._listenerRemovers.forEach(function (removers) { + removers.forEach(function (r) { + return r(); + }); + }); + this._listenerRemovers.clear(); var parent = this._link.parent; - if (parent) { // parent.removeListener('child:add', this._onParentChild); parent.removeListener("child:delete", this._onParentChild); } }; - return FSWatcher; }(events_1.EventEmitter); - exports$4.FSWatcher = FSWatcher; return exports$4; } var exports$3 = {}, - _dewExec$1 = false; + _dewExec$1 = false; function dew$1() { if (_dewExec$1) return exports$3; _dewExec$1 = true; Object.defineProperty(exports$3, "__esModule", { value: true }); - exports$3.fsAsyncMethods = exports$3.fsSyncMethods = exports$3.fsProps = void 0; - var fsProps = ["constants", "F_OK", "R_OK", "W_OK", "X_OK", "Stats"]; - exports$3.fsProps = fsProps; - var fsSyncMethods = ["renameSync", "ftruncateSync", "truncateSync", "chownSync", "fchownSync", "lchownSync", "chmodSync", "fchmodSync", "lchmodSync", "statSync", "lstatSync", "fstatSync", "linkSync", "symlinkSync", "readlinkSync", "realpathSync", "unlinkSync", "rmdirSync", "mkdirSync", "mkdirpSync", "readdirSync", "closeSync", "openSync", "utimesSync", "futimesSync", "fsyncSync", "writeSync", "readSync", "readFileSync", "writeFileSync", "appendFileSync", "existsSync", "accessSync", "fdatasyncSync", "mkdtempSync", "copyFileSync", "createReadStream", "createWriteStream"]; - exports$3.fsSyncMethods = fsSyncMethods; - var fsAsyncMethods = ["rename", "ftruncate", "truncate", "chown", "fchown", "lchown", "chmod", "fchmod", "lchmod", "stat", "lstat", "fstat", "link", "symlink", "readlink", "realpath", "unlink", "rmdir", "mkdir", "mkdirp", "readdir", "close", "open", "utimes", "futimes", "fsync", "write", "read", "readFile", "writeFile", "appendFile", "exists", "access", "fdatasync", "mkdtemp", "copyFile", "watchFile", "unwatchFile", "watch"]; - exports$3.fsAsyncMethods = fsAsyncMethods; + exports$3.fsSyncMethods = exports$3.fsProps = exports$3.fsAsyncMethods = void 0; + exports$3.fsProps = ["constants", "F_OK", "R_OK", "W_OK", "X_OK", "Stats"]; + exports$3.fsSyncMethods = ["renameSync", "ftruncateSync", "truncateSync", "chownSync", "fchownSync", "lchownSync", "chmodSync", "fchmodSync", "lchmodSync", "statSync", "lstatSync", "fstatSync", "linkSync", "symlinkSync", "readlinkSync", "realpathSync", "unlinkSync", "rmdirSync", "mkdirSync", "mkdirpSync", "readdirSync", "closeSync", "openSync", "utimesSync", "futimesSync", "fsyncSync", "writeSync", "readSync", "readFileSync", "writeFileSync", "appendFileSync", "existsSync", "accessSync", "fdatasyncSync", "mkdtempSync", "copyFileSync", "rmSync", "createReadStream", "createWriteStream"]; + exports$3.fsAsyncMethods = ["rename", "ftruncate", "truncate", "chown", "fchown", "lchown", "chmod", "fchmod", "lchmod", "stat", "lstat", "fstat", "link", "symlink", "readlink", "realpath", "unlink", "rmdir", "mkdir", "mkdirp", "readdir", "close", "open", "utimes", "futimes", "fsync", "write", "read", "readFile", "writeFile", "appendFile", "exists", "access", "fdatasync", "mkdtemp", "copyFile", "rm", "watchFile", "unwatchFile", "watch"]; return exports$3; } var exports$2 = {}, - _dewExec = false; + _dewExec = false; function dew() { if (_dewExec) return exports$2; _dewExec = true; - var __assign = exports$2 && exports$2.__assign || function () { __assign = Object.assign || function (t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; - for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } - return t; }; - return __assign.apply(this, arguments); }; - Object.defineProperty(exports$2, "__esModule", { value: true }); exports$2.fs = exports$2.createFsFromVolume = exports$2.vol = exports$2.Volume = void 0; - var Stats_1 = dew$d(); - var Dirent_1 = dew$9(); - var volume_1 = dew$2(); - var _a = dew$1(), - fsSyncMethods = _a.fsSyncMethods, - fsAsyncMethods = _a.fsAsyncMethods; - + fsSyncMethods = _a.fsSyncMethods, + fsAsyncMethods = _a.fsAsyncMethods; var constants_1 = dew$f(); - var F_OK = constants_1.constants.F_OK, - R_OK = constants_1.constants.R_OK, - W_OK = constants_1.constants.W_OK, - X_OK = constants_1.constants.X_OK; - exports$2.Volume = volume_1.Volume; // Default volume. - + R_OK = constants_1.constants.R_OK, + W_OK = constants_1.constants.W_OK, + X_OK = constants_1.constants.X_OK; + exports$2.Volume = volume_1.Volume; + // Default volume. exports$2.vol = new volume_1.Volume(); - function createFsFromVolume(vol) { var fs = { F_OK: F_OK, @@ -4358,18 +3901,16 @@ function dew() { constants: constants_1.constants, Stats: Stats_1.default, Dirent: Dirent_1.default - }; // Bind FS methods. - + }; + // Bind FS methods. for (var _i = 0, fsSyncMethods_1 = fsSyncMethods; _i < fsSyncMethods_1.length; _i++) { var method = fsSyncMethods_1[_i]; if (typeof vol[method] === "function") fs[method] = vol[method].bind(vol); } - for (var _a = 0, fsAsyncMethods_1 = fsAsyncMethods; _a < fsAsyncMethods_1.length; _a++) { var method = fsAsyncMethods_1[_a]; if (typeof vol[method] === "function") fs[method] = vol[method].bind(vol); } - fs.StatWatcher = vol.StatWatcher; fs.FSWatcher = vol.FSWatcher; fs.WriteStream = vol.WriteStream; @@ -4378,7 +3919,6 @@ function dew() { fs._toUnixTimestamp = volume_1.toUnixTimestamp; return fs; } - exports$2.createFsFromVolume = createFsFromVolume; exports$2.fs = createFsFromVolume(exports$2.vol); exports$2 = __assign(__assign({}, exports$2), exports$2.fs); diff --git a/nodelibs/browser/fs/promises.js b/nodelibs/browser/fs/promises.js index 58428b5..1b84a89 100644 --- a/nodelibs/browser/fs/promises.js +++ b/nodelibs/browser/fs/promises.js @@ -1,22 +1,20 @@ import { promises } from '../fs.js'; -import '../chunk-CU2hd6BF.js'; -import '../chunk-tHuMsdT0.js'; -import '../chunk-BZgdGiNw.js'; -import '../chunk-D04hy_Cu.js'; -import '../chunk-DEckhzyo.js'; +import '../chunk-DtuTasat.js'; +import '../chunk-CjPlbOtt.js'; +import '../chunk-D3uu3VYh.js'; +import '../chunk-CbQqNoLO.js'; +import '../chunk-DHWh-hmB.js'; import '../chunk-b0rmRow7.js'; -import '../chunk-C9hMJ5VR.js'; -import '../assert.js'; -import '../util.js'; -import '../path.js'; -import '../chunk-DppJZDIM.js'; -import '../events.js'; -import '../stream.js'; -import '../chunk-gkrMq4sQ.js'; -import '../url.js'; -import '../chunk-CKeAujU-.js'; -import '../chunk-D5E0hY9V.js'; +import '../chunk-DEMDiNwt.js'; +import '../chunk-DtDiafJB.js'; +import '../chunk-tHuMsdT0.js'; +import '../chunk-B6-G-Ftj.js'; +import '../chunk-B738Er4n.js'; import '../buffer.js'; +import '../url.js'; +import '../punycode.js'; +import '../chunk-DtcTpLWz.js'; +import '../chunk-BlJi4mNy.js'; const { access, diff --git a/nodelibs/browser/http.js b/nodelibs/browser/http.js index 25fcc55..58c8468 100644 --- a/nodelibs/browser/http.js +++ b/nodelibs/browser/http.js @@ -1,103 +1,2896 @@ -import { b as buffer, d as dew$7 } from './chunk-CU2hd6BF.js'; -import { d as dew$6 } from './chunk-aBeyrThb.js'; -import { p as process } from './chunk-b0rmRow7.js'; -import h from './url.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-C9hMJ5VR.js'; -import './chunk-CKeAujU-.js'; -import './chunk-D5E0hY9V.js'; -import './chunk-DppJZDIM.js'; +import { d as dew$m } from './chunk-CkFCi-G1.js'; +import './chunk-DtDiafJB.js'; +import { y } from './chunk-tHuMsdT0.js'; +import { d as dew$l } from './chunk-DtuTasat.js'; +import './chunk-CbQqNoLO.js'; +import { X } from './chunk-D3uu3VYh.js'; +import { p as process } from './chunk-DEMDiNwt.js'; +import { d as dew$n } from './chunk-BsRZ0PEC.js'; +import { e as exports$m } from './chunk-CcCWfKp1.js'; +import { h } from './chunk-DHWh-hmB.js'; +import './chunk-b0rmRow7.js'; + +var exports$l = {}, + _dewExec$k = false; +var _global$5 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$k() { + if (_dewExec$k) return exports$l; + _dewExec$k = true; + exports$l.fetch = isFunction(_global$5.fetch) && isFunction(_global$5.ReadableStream); + exports$l.writableStream = isFunction(_global$5.WritableStream); + exports$l.abortController = isFunction(_global$5.AbortController); + + // The xhr request to example.com may violate some restrictive CSP configurations, + // so if we're running in a browser that supports `fetch`, avoid calling getXHR() + // and assume support for certain features below. + var xhr; + function getXHR() { + // Cache the xhr value + if (xhr !== undefined) return xhr; + if (_global$5.XMLHttpRequest) { + xhr = new _global$5.XMLHttpRequest(); + // If XDomainRequest is available (ie only, where xhr might not work + // cross domain), use the page location. Otherwise use example.com + // Note: this doesn't actually make an http request. + try { + xhr.open("GET", _global$5.XDomainRequest ? "/" : "https://example.com"); + } catch (e) { + xhr = null; + } + } else { + // Service workers don't have XHR + xhr = null; + } + return xhr; + } + function checkTypeSupport(type) { + var xhr = getXHR(); + if (!xhr) return false; + try { + xhr.responseType = type; + return xhr.responseType === type; + } catch (e) {} + return false; + } -var exports$6 = {}, - _dewExec$5 = false; + // If fetch is supported, then arraybuffer will be supported too. Skip calling + // checkTypeSupport(), since that calls getXHR(). + exports$l.arraybuffer = exports$l.fetch || checkTypeSupport("arraybuffer"); + + // These next two tests unavoidably show warnings in Chrome. Since fetch will always + // be used if it's available, just return false for these to avoid the warnings. + exports$l.msstream = !exports$l.fetch && checkTypeSupport("ms-stream"); + exports$l.mozchunkedarraybuffer = !exports$l.fetch && checkTypeSupport("moz-chunked-arraybuffer"); + + // If fetch is supported, then overrideMimeType will be supported too. Skip calling + // getXHR(). + exports$l.overrideMimeType = exports$l.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false); + function isFunction(value) { + return typeof value === "function"; + } + xhr = null; // Help gc + return exports$l; +} + +var exports$k = {}, + _dewExec$j = false; +function dew$j() { + if (_dewExec$j) return exports$k; + _dewExec$j = true; + exports$k = y.EventEmitter; + return exports$k; +} + +var exports$j = {}, + _dewExec$i = false; +function dew$i() { + if (_dewExec$i) return exports$j; + _dewExec$i = true; + function ownKeys(object, enumerableOnly) { + var keys = Object.keys(object); + if (Object.getOwnPropertySymbols) { + var symbols = Object.getOwnPropertySymbols(object); + enumerableOnly && (symbols = symbols.filter(function (sym) { + return Object.getOwnPropertyDescriptor(object, sym).enumerable; + })), keys.push.apply(keys, symbols); + } + return keys; + } + function _objectSpread(target) { + for (var i = 1; i < arguments.length; i++) { + var source = null != arguments[i] ? arguments[i] : {}; + i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { + _defineProperty(target, key, source[key]); + }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { + Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); + }); + } + return target; + } + function _defineProperty(obj, key, value) { + key = _toPropertyKey(key); + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; + } + function _classCallCheck(instance, Constructor) { + if (!(instance instanceof Constructor)) { + throw new TypeError("Cannot call a class as a function"); + } + } + function _defineProperties(target, props) { + for (var i = 0; i < props.length; i++) { + var descriptor = props[i]; + descriptor.enumerable = descriptor.enumerable || false; + descriptor.configurable = true; + if ("value" in descriptor) descriptor.writable = true; + Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); + } + } + function _createClass(Constructor, protoProps, staticProps) { + if (protoProps) _defineProperties(Constructor.prototype, protoProps); + Object.defineProperty(Constructor, "prototype", { + writable: false + }); + return Constructor; + } + function _toPropertyKey(arg) { + var key = _toPrimitive(arg, "string"); + return typeof key === "symbol" ? key : String(key); + } + function _toPrimitive(input, hint) { + if (typeof input !== "object" || input === null) return input; + var prim = input[Symbol.toPrimitive]; + if (prim !== undefined) { + var res = prim.call(input, hint || "default"); + if (typeof res !== "object") return res; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return (hint === "string" ? String : Number)(input); + } + var _require = dew$l(), + Buffer = _require.Buffer; + var _require2 = X, + inspect = _require2.inspect; + var custom = inspect && inspect.custom || "inspect"; + function copyBuffer(src, target, offset) { + Buffer.prototype.copy.call(src, target, offset); + } + exports$j = /*#__PURE__*/function () { + function BufferList() { + _classCallCheck(this, BufferList); + this.head = null; + this.tail = null; + this.length = 0; + } + _createClass(BufferList, [{ + key: "push", + value: function push(v) { + var entry = { + data: v, + next: null + }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + } + }, { + key: "unshift", + value: function unshift(v) { + var entry = { + data: v, + next: this.head + }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + } + }, { + key: "shift", + value: function shift() { + if (this.length === 0) return; + var ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + } + }, { + key: "clear", + value: function clear() { + this.head = this.tail = null; + this.length = 0; + } + }, { + key: "join", + value: function join(s) { + if (this.length === 0) return ""; + var p = this.head; + var ret = "" + p.data; + while (p = p.next) ret += s + p.data; + return ret; + } + }, { + key: "concat", + value: function concat(n) { + if (this.length === 0) return Buffer.alloc(0); + var ret = Buffer.allocUnsafe(n >>> 0); + var p = this.head; + var i = 0; + while (p) { + copyBuffer(p.data, ret, i); + i += p.data.length; + p = p.next; + } + return ret; + } + + // Consumes a specified amount of bytes or characters from the buffered data. + }, { + key: "consume", + value: function consume(n, hasStrings) { + var ret; + if (n < this.head.data.length) { + // `slice` is the same for buffers and strings. + ret = this.head.data.slice(0, n); + this.head.data = this.head.data.slice(n); + } else if (n === this.head.data.length) { + // First chunk is a perfect match. + ret = this.shift(); + } else { + // Result spans more than one buffer. + ret = hasStrings ? this._getString(n) : this._getBuffer(n); + } + return ret; + } + }, { + key: "first", + value: function first() { + return this.head.data; + } + + // Consumes a specified amount of characters from the buffered data. + }, { + key: "_getString", + value: function _getString(n) { + var p = this.head; + var c = 1; + var ret = p.data; + n -= ret.length; + while (p = p.next) { + var str = p.data; + var nb = n > str.length ? str.length : n; + if (nb === str.length) ret += str;else ret += str.slice(0, n); + n -= nb; + if (n === 0) { + if (nb === str.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = str.slice(nb); + } + break; + } + ++c; + } + this.length -= c; + return ret; + } + + // Consumes a specified amount of bytes from the buffered data. + }, { + key: "_getBuffer", + value: function _getBuffer(n) { + var ret = Buffer.allocUnsafe(n); + var p = this.head; + var c = 1; + p.data.copy(ret); + n -= p.data.length; + while (p = p.next) { + var buf = p.data; + var nb = n > buf.length ? buf.length : n; + buf.copy(ret, ret.length - n, 0, nb); + n -= nb; + if (n === 0) { + if (nb === buf.length) { + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + this.head = p; + p.data = buf.slice(nb); + } + break; + } + ++c; + } + this.length -= c; + return ret; + } + + // Make sure the linked list only shows the minimal necessary information. + }, { + key: custom, + value: function value(_, options) { + return inspect(this, _objectSpread(_objectSpread({}, options), {}, { + // Only inspect one level. + depth: 0, + // It should not recurse. + customInspect: false + })); + } + }]); + return BufferList; + }(); + return exports$j; +} + +var exports$i = {}, + _dewExec$h = false; +function dew$h() { + if (_dewExec$h) return exports$i; + _dewExec$h = true; + var process$1 = process; + // undocumented cb() API, needed for core, not for public API + function destroy(err, cb) { + var _this = this; + var readableDestroyed = this._readableState && this._readableState.destroyed; + var writableDestroyed = this._writableState && this._writableState.destroyed; + if (readableDestroyed || writableDestroyed) { + if (cb) { + cb(err); + } else if (err) { + if (!this._writableState) { + process$1.nextTick(emitErrorNT, this, err); + } else if (!this._writableState.errorEmitted) { + this._writableState.errorEmitted = true; + process$1.nextTick(emitErrorNT, this, err); + } + } + return this; + } + + // we set destroyed to true before firing error callbacks in order + // to make it re-entrance safe in case destroy() is called within callbacks + + if (this._readableState) { + this._readableState.destroyed = true; + } + + // if this is a duplex stream mark the writable part as destroyed as well + if (this._writableState) { + this._writableState.destroyed = true; + } + this._destroy(err || null, function (err) { + if (!cb && err) { + if (!_this._writableState) { + process$1.nextTick(emitErrorAndCloseNT, _this, err); + } else if (!_this._writableState.errorEmitted) { + _this._writableState.errorEmitted = true; + process$1.nextTick(emitErrorAndCloseNT, _this, err); + } else { + process$1.nextTick(emitCloseNT, _this); + } + } else if (cb) { + process$1.nextTick(emitCloseNT, _this); + cb(err); + } else { + process$1.nextTick(emitCloseNT, _this); + } + }); + return this; + } + function emitErrorAndCloseNT(self, err) { + emitErrorNT(self, err); + emitCloseNT(self); + } + function emitCloseNT(self) { + if (self._writableState && !self._writableState.emitClose) return; + if (self._readableState && !self._readableState.emitClose) return; + self.emit("close"); + } + function undestroy() { + if (this._readableState) { + this._readableState.destroyed = false; + this._readableState.reading = false; + this._readableState.ended = false; + this._readableState.endEmitted = false; + } + if (this._writableState) { + this._writableState.destroyed = false; + this._writableState.ended = false; + this._writableState.ending = false; + this._writableState.finalCalled = false; + this._writableState.prefinished = false; + this._writableState.finished = false; + this._writableState.errorEmitted = false; + } + } + function emitErrorNT(self, err) { + self.emit("error", err); + } + function errorOrDestroy(stream, err) { + // We have tests that rely on errors being emitted + // in the same tick, so changing this is semver major. + // For now when you opt-in to autoDestroy we allow + // the error to be emitted nextTick. In a future + // semver major update we should change the default to this. + + var rState = stream._readableState; + var wState = stream._writableState; + if (rState && rState.autoDestroy || wState && wState.autoDestroy) stream.destroy(err);else stream.emit("error", err); + } + exports$i = { + destroy: destroy, + undestroy: undestroy, + errorOrDestroy: errorOrDestroy + }; + return exports$i; +} + +var exports$h = {}, + _dewExec$g = false; +function dew$g() { + if (_dewExec$g) return exports$h; + _dewExec$g = true; + const codes = {}; + function createErrorType(code, message, Base) { + if (!Base) { + Base = Error; + } + function getMessage(arg1, arg2, arg3) { + if (typeof message === "string") { + return message; + } else { + return message(arg1, arg2, arg3); + } + } + class NodeError extends Base { + constructor(arg1, arg2, arg3) { + super(getMessage(arg1, arg2, arg3)); + } + } + NodeError.prototype.name = Base.name; + NodeError.prototype.code = code; + codes[code] = NodeError; + } + + // https://github.com/nodejs/node/blob/v10.8.0/lib/internal/errors.js + function oneOf(expected, thing) { + if (Array.isArray(expected)) { + const len = expected.length; + expected = expected.map(i => String(i)); + if (len > 2) { + return `one of ${thing} ${expected.slice(0, len - 1).join(", ")}, or ` + expected[len - 1]; + } else if (len === 2) { + return `one of ${thing} ${expected[0]} or ${expected[1]}`; + } else { + return `of ${thing} ${expected[0]}`; + } + } else { + return `of ${thing} ${String(expected)}`; + } + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/startsWith + function startsWith(str, search, pos) { + return str.substr(0 , search.length) === search; + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/endsWith + function endsWith(str, search, this_len) { + if (this_len === undefined || this_len > str.length) { + this_len = str.length; + } + return str.substring(this_len - search.length, this_len) === search; + } + + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/includes + function includes(str, search, start) { + if (typeof start !== "number") { + start = 0; + } + if (start + search.length > str.length) { + return false; + } else { + return str.indexOf(search, start) !== -1; + } + } + createErrorType("ERR_INVALID_OPT_VALUE", function (name, value) { + return "The value \"" + value + "\" is invalid for option \"" + name + "\""; + }, TypeError); + createErrorType("ERR_INVALID_ARG_TYPE", function (name, expected, actual) { + // determiner: 'must be' or 'must not be' + let determiner; + if (typeof expected === "string" && startsWith(expected, "not ")) { + determiner = "must not be"; + expected = expected.replace(/^not /, ""); + } else { + determiner = "must be"; + } + let msg; + if (endsWith(name, " argument")) { + // For cases like 'first argument' + msg = `The ${name} ${determiner} ${oneOf(expected, "type")}`; + } else { + const type = includes(name, ".") ? "property" : "argument"; + msg = `The "${name}" ${type} ${determiner} ${oneOf(expected, "type")}`; + } + msg += `. Received type ${typeof actual}`; + return msg; + }, TypeError); + createErrorType("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF"); + createErrorType("ERR_METHOD_NOT_IMPLEMENTED", function (name) { + return "The " + name + " method is not implemented"; + }); + createErrorType("ERR_STREAM_PREMATURE_CLOSE", "Premature close"); + createErrorType("ERR_STREAM_DESTROYED", function (name) { + return "Cannot call " + name + " after a stream was destroyed"; + }); + createErrorType("ERR_MULTIPLE_CALLBACK", "Callback called multiple times"); + createErrorType("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable"); + createErrorType("ERR_STREAM_WRITE_AFTER_END", "write after end"); + createErrorType("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError); + createErrorType("ERR_UNKNOWN_ENCODING", function (arg) { + return "Unknown encoding: " + arg; + }, TypeError); + createErrorType("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event"); + exports$h.codes = codes; + return exports$h; +} + +var exports$g = {}, + _dewExec$f = false; +function dew$f() { + if (_dewExec$f) return exports$g; + _dewExec$f = true; + var ERR_INVALID_OPT_VALUE = dew$g().codes.ERR_INVALID_OPT_VALUE; + function highWaterMarkFrom(options, isDuplex, duplexKey) { + return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; + } + function getHighWaterMark(state, options, duplexKey, isDuplex) { + var hwm = highWaterMarkFrom(options, isDuplex, duplexKey); + if (hwm != null) { + if (!(isFinite(hwm) && Math.floor(hwm) === hwm) || hwm < 0) { + var name = isDuplex ? duplexKey : "highWaterMark"; + throw new ERR_INVALID_OPT_VALUE(name, hwm); + } + return Math.floor(hwm); + } + + // Default value + return state.objectMode ? 16 : 16 * 1024; + } + exports$g = { + getHighWaterMark: getHighWaterMark + }; + return exports$g; +} + +var exports$f = {}, + _dewExec$e = false; +var _global$4 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$e() { + if (_dewExec$e) return exports$f; + _dewExec$e = true; + var process$1 = process; + exports$f = Writable; + + // It seems a linked list but it is not + // there will be only 2 of these for each stream + function CorkedRequest(state) { + var _this = this; + this.next = null; + this.entry = null; + this.finish = function () { + onCorkedFinish(_this, state); + }; + } + /* */ + + /**/ + var Duplex; + /**/ + + Writable.WritableState = WritableState; + + /**/ + var internalUtil = { + deprecate: dew$n() + }; + /**/ + + /**/ + var Stream = dew$j(); + /**/ + + var Buffer = dew$l().Buffer; + var OurUint8Array = (typeof _global$4 !== "undefined" ? _global$4 : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function () {}; + function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); + } + function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + } + var destroyImpl = dew$h(); + var _require = dew$f(), + getHighWaterMark = _require.getHighWaterMark; + var _require$codes = dew$g().codes, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, + ERR_STREAM_CANNOT_PIPE = _require$codes.ERR_STREAM_CANNOT_PIPE, + ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED, + ERR_STREAM_NULL_VALUES = _require$codes.ERR_STREAM_NULL_VALUES, + ERR_STREAM_WRITE_AFTER_END = _require$codes.ERR_STREAM_WRITE_AFTER_END, + ERR_UNKNOWN_ENCODING = _require$codes.ERR_UNKNOWN_ENCODING; + var errorOrDestroy = destroyImpl.errorOrDestroy; + dew$m()(Writable, Stream); + function nop() {} + function WritableState(options, stream, isDuplex) { + Duplex = Duplex || dew$d(); + options = options || {}; + + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream, + // e.g. options.readableObjectMode vs. options.writableObjectMode, etc. + if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex; + + // object stream flag to indicate whether or not this stream + // contains buffers or objects. + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.writableObjectMode; + + // the point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write() + this.highWaterMark = getHighWaterMark(this, options, "writableHighWaterMark", isDuplex); + + // if _final has been called + this.finalCalled = false; + + // drain event flag. + this.needDrain = false; + // at the start of calling end() + this.ending = false; + // when end() has been called, and returned + this.ended = false; + // when 'finish' is emitted + this.finished = false; + + // has it been destroyed + this.destroyed = false; + + // should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + var noDecode = options.decodeStrings === false; + this.decodeStrings = !noDecode; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || "utf8"; + + // not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + this.length = 0; + + // a flag to see when we're in the middle of a write. + this.writing = false; + + // when true all writes will be buffered until .uncork() call + this.corked = 0; + + // a flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + this.sync = true; + + // a flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + this.bufferProcessing = false; + + // the callback that's passed to _write(chunk,cb) + this.onwrite = function (er) { + onwrite(stream, er); + }; + + // the callback that the user supplies to write(chunk,encoding,cb) + this.writecb = null; + + // the amount that is being written when _write is called. + this.writelen = 0; + this.bufferedRequest = null; + this.lastBufferedRequest = null; + + // number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted + this.pendingcb = 0; + + // emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams + this.prefinished = false; + + // True if the error was already emitted and should not be thrown again + this.errorEmitted = false; + + // Should close be emitted on destroy. Defaults to true. + this.emitClose = options.emitClose !== false; + + // Should .destroy() be called after 'finish' (and potentially 'end') + this.autoDestroy = !!options.autoDestroy; + + // count buffered requests + this.bufferedRequestCount = 0; + + // allocate the first CorkedRequest, there is always + // one allocated and free to use, and we maintain at most two + this.corkedRequestsFree = new CorkedRequest(this); + } + WritableState.prototype.getBuffer = function getBuffer() { + var current = this.bufferedRequest; + var out = []; + while (current) { + out.push(current); + current = current.next; + } + return out; + }; + (function () { + try { + Object.defineProperty(WritableState.prototype, "buffer", { + get: internalUtil.deprecate(function writableStateBufferGetter() { + return this.getBuffer(); + }, "_writableState.buffer is deprecated. Use _writableState.getBuffer " + "instead.", "DEP0003") + }); + } catch (_) {} + })(); + + // Test _writableState for inheritance to account for Duplex streams, + // whose prototype chain only points to Readable. + var realHasInstance; + if (typeof Symbol === "function" && Symbol.hasInstance && typeof Function.prototype[Symbol.hasInstance] === "function") { + realHasInstance = Function.prototype[Symbol.hasInstance]; + Object.defineProperty(Writable, Symbol.hasInstance, { + value: function value(object) { + if (realHasInstance.call(this, object)) return true; + if (this !== Writable) return false; + return object && object._writableState instanceof WritableState; + } + }); + } else { + realHasInstance = function realHasInstance(object) { + return object instanceof this; + }; + } + function Writable(options) { + Duplex = Duplex || dew$d(); + + // Writable ctor is applied to Duplexes, too. + // `realHasInstance` is necessary because using plain `instanceof` + // would return false, as no `_writableState` property is attached. + + // Trying to use the custom `instanceof` for Writable here will also break the + // Node.js LazyTransform implementation, which has a non-trivial getter for + // `_writableState` that would lead to infinite recursion. + + // Checking for a Stream.Duplex instance is faster here instead of inside + // the WritableState constructor, at least with V8 6.5 + var isDuplex = this instanceof Duplex; + if (!isDuplex && !realHasInstance.call(Writable, this)) return new Writable(options); + this._writableState = new WritableState(options, this, isDuplex); + + // legacy. + this.writable = true; + if (options) { + if (typeof options.write === "function") this._write = options.write; + if (typeof options.writev === "function") this._writev = options.writev; + if (typeof options.destroy === "function") this._destroy = options.destroy; + if (typeof options.final === "function") this._final = options.final; + } + Stream.call(this); + } + // Otherwise people can pipe Writable streams, which is just wrong. + Writable.prototype.pipe = function () { + errorOrDestroy(this, new ERR_STREAM_CANNOT_PIPE()); + }; + function writeAfterEnd(stream, cb) { + var er = new ERR_STREAM_WRITE_AFTER_END(); + // TODO: defer error events consistently everywhere, not just the cb + errorOrDestroy(stream, er); + process$1.nextTick(cb, er); + } + + // Checks that a user-supplied chunk is valid, especially for the particular + // mode the stream is in. Currently this means that `null` is never accepted + // and undefined/non-string values are only allowed in object mode. + function validChunk(stream, state, chunk, cb) { + var er; + if (chunk === null) { + er = new ERR_STREAM_NULL_VALUES(); + } else if (typeof chunk !== "string" && !state.objectMode) { + er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer"], chunk); + } + if (er) { + errorOrDestroy(stream, er); + process$1.nextTick(cb, er); + return false; + } + return true; + } + Writable.prototype.write = function (chunk, encoding, cb) { + var state = this._writableState; + var ret = false; + var isBuf = !state.objectMode && _isUint8Array(chunk); + if (isBuf && !Buffer.isBuffer(chunk)) { + chunk = _uint8ArrayToBuffer(chunk); + } + if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + if (isBuf) encoding = "buffer";else if (!encoding) encoding = state.defaultEncoding; + if (typeof cb !== "function") cb = nop; + if (state.ending) writeAfterEnd(this, cb);else if (isBuf || validChunk(this, state, chunk, cb)) { + state.pendingcb++; + ret = writeOrBuffer(this, state, isBuf, chunk, encoding, cb); + } + return ret; + }; + Writable.prototype.cork = function () { + this._writableState.corked++; + }; + Writable.prototype.uncork = function () { + var state = this._writableState; + if (state.corked) { + state.corked--; + if (!state.writing && !state.corked && !state.bufferProcessing && state.bufferedRequest) clearBuffer(this, state); + } + }; + Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === "string") encoding = encoding.toLowerCase(); + if (!(["hex", "utf8", "utf-8", "ascii", "binary", "base64", "ucs2", "ucs-2", "utf16le", "utf-16le", "raw"].indexOf((encoding + "").toLowerCase()) > -1)) throw new ERR_UNKNOWN_ENCODING(encoding); + this._writableState.defaultEncoding = encoding; + return this; + }; + Object.defineProperty(Writable.prototype, "writableBuffer", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState && this._writableState.getBuffer(); + } + }); + function decodeChunk(state, chunk, encoding) { + if (!state.objectMode && state.decodeStrings !== false && typeof chunk === "string") { + chunk = Buffer.from(chunk, encoding); + } + return chunk; + } + Object.defineProperty(Writable.prototype, "writableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.highWaterMark; + } + }); + + // if we're already writing something, then just put this + // in the queue, and wait our turn. Otherwise, call _write + // If we return false, then we need a drain event, so set that flag. + function writeOrBuffer(stream, state, isBuf, chunk, encoding, cb) { + if (!isBuf) { + var newChunk = decodeChunk(state, chunk, encoding); + if (chunk !== newChunk) { + isBuf = true; + encoding = "buffer"; + chunk = newChunk; + } + } + var len = state.objectMode ? 1 : chunk.length; + state.length += len; + var ret = state.length < state.highWaterMark; + // we must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; + if (state.writing || state.corked) { + var last = state.lastBufferedRequest; + state.lastBufferedRequest = { + chunk: chunk, + encoding: encoding, + isBuf: isBuf, + callback: cb, + next: null + }; + if (last) { + last.next = state.lastBufferedRequest; + } else { + state.bufferedRequest = state.lastBufferedRequest; + } + state.bufferedRequestCount += 1; + } else { + doWrite(stream, state, false, len, chunk, encoding, cb); + } + return ret; + } + function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED("write"));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } + function onwriteError(stream, state, sync, er, cb) { + --state.pendingcb; + if (sync) { + // defer the callback if we are being called synchronously + // to avoid piling up things on the stack + process$1.nextTick(cb, er); + // this can emit finish, and it will always happen + // after error + process$1.nextTick(finishMaybe, stream, state); + stream._writableState.errorEmitted = true; + errorOrDestroy(stream, er); + } else { + // the caller expect this to happen before if + // it is async + cb(er); + stream._writableState.errorEmitted = true; + errorOrDestroy(stream, er); + // this can emit finish, but finish must + // always follow error + finishMaybe(stream, state); + } + } + function onwriteStateUpdate(state) { + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; + } + function onwrite(stream, er) { + var state = stream._writableState; + var sync = state.sync; + var cb = state.writecb; + if (typeof cb !== "function") throw new ERR_MULTIPLE_CALLBACK(); + onwriteStateUpdate(state); + if (er) onwriteError(stream, state, sync, er, cb);else { + // Check if we're actually ready to finish, but don't emit yet + var finished = needFinish(state) || stream.destroyed; + if (!finished && !state.corked && !state.bufferProcessing && state.bufferedRequest) { + clearBuffer(stream, state); + } + if (sync) { + process$1.nextTick(afterWrite, stream, state, finished, cb); + } else { + afterWrite(stream, state, finished, cb); + } + } + } + function afterWrite(stream, state, finished, cb) { + if (!finished) onwriteDrain(stream, state); + state.pendingcb--; + cb(); + finishMaybe(stream, state); + } + + // Must force callback to be called on nextTick, so that we don't + // emit 'drain' before the write() consumer gets the 'false' return + // value, and has a chance to attach a 'drain' listener. + function onwriteDrain(stream, state) { + if (state.length === 0 && state.needDrain) { + state.needDrain = false; + stream.emit("drain"); + } + } + + // if there's something in the buffer waiting, then process it + function clearBuffer(stream, state) { + state.bufferProcessing = true; + var entry = state.bufferedRequest; + if (stream._writev && entry && entry.next) { + // Fast case, write everything using _writev() + var l = state.bufferedRequestCount; + var buffer = new Array(l); + var holder = state.corkedRequestsFree; + holder.entry = entry; + var count = 0; + var allBuffers = true; + while (entry) { + buffer[count] = entry; + if (!entry.isBuf) allBuffers = false; + entry = entry.next; + count += 1; + } + buffer.allBuffers = allBuffers; + doWrite(stream, state, true, state.length, buffer, "", holder.finish); + + // doWrite is almost always async, defer these to save a bit of time + // as the hot path ends with doWrite + state.pendingcb++; + state.lastBufferedRequest = null; + if (holder.next) { + state.corkedRequestsFree = holder.next; + holder.next = null; + } else { + state.corkedRequestsFree = new CorkedRequest(state); + } + state.bufferedRequestCount = 0; + } else { + // Slow case, write chunks one-by-one + while (entry) { + var chunk = entry.chunk; + var encoding = entry.encoding; + var cb = entry.callback; + var len = state.objectMode ? 1 : chunk.length; + doWrite(stream, state, false, len, chunk, encoding, cb); + entry = entry.next; + state.bufferedRequestCount--; + // if we didn't call the onwrite immediately, then + // it means that we need to wait until it does. + // also, that means that the chunk and cb are currently + // being processed, so move the buffer counter past them. + if (state.writing) { + break; + } + } + if (entry === null) state.lastBufferedRequest = null; + } + state.bufferedRequest = entry; + state.bufferProcessing = false; + } + Writable.prototype._write = function (chunk, encoding, cb) { + cb(new ERR_METHOD_NOT_IMPLEMENTED("_write()")); + }; + Writable.prototype._writev = null; + Writable.prototype.end = function (chunk, encoding, cb) { + var state = this._writableState; + if (typeof chunk === "function") { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + if (chunk !== null && chunk !== undefined) this.write(chunk, encoding); + + // .end() fully uncorks + if (state.corked) { + state.corked = 1; + this.uncork(); + } + + // ignore unnecessary end() calls. + if (!state.ending) endWritable(this, state, cb); + return this; + }; + Object.defineProperty(Writable.prototype, "writableLength", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.length; + } + }); + function needFinish(state) { + return state.ending && state.length === 0 && state.bufferedRequest === null && !state.finished && !state.writing; + } + function callFinal(stream, state) { + stream._final(function (err) { + state.pendingcb--; + if (err) { + errorOrDestroy(stream, err); + } + state.prefinished = true; + stream.emit("prefinish"); + finishMaybe(stream, state); + }); + } + function prefinish(stream, state) { + if (!state.prefinished && !state.finalCalled) { + if (typeof stream._final === "function" && !state.destroyed) { + state.pendingcb++; + state.finalCalled = true; + process$1.nextTick(callFinal, stream, state); + } else { + state.prefinished = true; + stream.emit("prefinish"); + } + } + } + function finishMaybe(stream, state) { + var need = needFinish(state); + if (need) { + prefinish(stream, state); + if (state.pendingcb === 0) { + state.finished = true; + stream.emit("finish"); + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the readable side is ready for autoDestroy as well + var rState = stream._readableState; + if (!rState || rState.autoDestroy && rState.endEmitted) { + stream.destroy(); + } + } + } + } + return need; + } + function endWritable(stream, state, cb) { + state.ending = true; + finishMaybe(stream, state); + if (cb) { + if (state.finished) process$1.nextTick(cb);else stream.once("finish", cb); + } + state.ended = true; + stream.writable = false; + } + function onCorkedFinish(corkReq, state, err) { + var entry = corkReq.entry; + corkReq.entry = null; + while (entry) { + var cb = entry.callback; + state.pendingcb--; + cb(err); + entry = entry.next; + } + + // reuse the free corkReq. + state.corkedRequestsFree.next = corkReq; + } + Object.defineProperty(Writable.prototype, "destroyed", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._writableState === undefined) { + return false; + } + return this._writableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._writableState) { + return; + } + + // backward compatibility, the user is explicitly + // managing destroyed + this._writableState.destroyed = value; + } + }); + Writable.prototype.destroy = destroyImpl.destroy; + Writable.prototype._undestroy = destroyImpl.undestroy; + Writable.prototype._destroy = function (err, cb) { + cb(err); + }; + return exports$f; +} + +var exports$e = {}, + _dewExec$d = false; +function dew$d() { + if (_dewExec$d) return exports$e; + _dewExec$d = true; + var process$1 = process; + /**/ + var objectKeys = Object.keys || function (obj) { + var keys = []; + for (var key in obj) keys.push(key); + return keys; + }; + /**/ + + exports$e = Duplex; + var Readable = dew$9(); + var Writable = dew$e(); + dew$m()(Duplex, Readable); + { + // Allow the keys array to be GC'ed. + var keys = objectKeys(Writable.prototype); + for (var v = 0; v < keys.length; v++) { + var method = keys[v]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + } + } + function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + Readable.call(this, options); + Writable.call(this, options); + this.allowHalfOpen = true; + if (options) { + if (options.readable === false) this.readable = false; + if (options.writable === false) this.writable = false; + if (options.allowHalfOpen === false) { + this.allowHalfOpen = false; + this.once("end", onend); + } + } + } + Object.defineProperty(Duplex.prototype, "writableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.highWaterMark; + } + }); + Object.defineProperty(Duplex.prototype, "writableBuffer", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState && this._writableState.getBuffer(); + } + }); + Object.defineProperty(Duplex.prototype, "writableLength", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._writableState.length; + } + }); + + // the no-half-open enforcer + function onend() { + // If the writable side ended, then we're ok. + if (this._writableState.ended) return; + + // no more data can be written. + // But allow more writes to happen in this tick. + process$1.nextTick(onEndNT, this); + } + function onEndNT(self) { + self.end(); + } + Object.defineProperty(Duplex.prototype, "destroyed", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._readableState === undefined || this._writableState === undefined) { + return false; + } + return this._readableState.destroyed && this._writableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (this._readableState === undefined || this._writableState === undefined) { + return; + } + + // backward compatibility, the user is explicitly + // managing destroyed + this._readableState.destroyed = value; + this._writableState.destroyed = value; + } + }); + return exports$e; +} + +var exports$d = {}, + _dewExec$c = false; +function dew$c() { + if (_dewExec$c) return exports$d; + _dewExec$c = true; + var ERR_STREAM_PREMATURE_CLOSE = dew$g().codes.ERR_STREAM_PREMATURE_CLOSE; + function once(callback) { + var called = false; + return function () { + if (called) return; + called = true; + for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + callback.apply(this, args); + }; + } + function noop() {} + function isRequest(stream) { + return stream.setHeader && typeof stream.abort === "function"; + } + function eos(stream, opts, callback) { + if (typeof opts === "function") return eos(stream, null, opts); + if (!opts) opts = {}; + callback = once(callback || noop); + var readable = opts.readable || opts.readable !== false && stream.readable; + var writable = opts.writable || opts.writable !== false && stream.writable; + var onlegacyfinish = function onlegacyfinish() { + if (!stream.writable) onfinish(); + }; + var writableEnded = stream._writableState && stream._writableState.finished; + var onfinish = function onfinish() { + writable = false; + writableEnded = true; + if (!readable) callback.call(stream); + }; + var readableEnded = stream._readableState && stream._readableState.endEmitted; + var onend = function onend() { + readable = false; + readableEnded = true; + if (!writable) callback.call(stream); + }; + var onerror = function onerror(err) { + callback.call(stream, err); + }; + var onclose = function onclose() { + var err; + if (readable && !readableEnded) { + if (!stream._readableState || !stream._readableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); + return callback.call(stream, err); + } + if (writable && !writableEnded) { + if (!stream._writableState || !stream._writableState.ended) err = new ERR_STREAM_PREMATURE_CLOSE(); + return callback.call(stream, err); + } + }; + var onrequest = function onrequest() { + stream.req.on("finish", onfinish); + }; + if (isRequest(stream)) { + stream.on("complete", onfinish); + stream.on("abort", onclose); + if (stream.req) onrequest();else stream.on("request", onrequest); + } else if (writable && !stream._writableState) { + // legacy streams + stream.on("end", onlegacyfinish); + stream.on("close", onlegacyfinish); + } + stream.on("end", onend); + stream.on("finish", onfinish); + if (opts.error !== false) stream.on("error", onerror); + stream.on("close", onclose); + return function () { + stream.removeListener("complete", onfinish); + stream.removeListener("abort", onclose); + stream.removeListener("request", onrequest); + if (stream.req) stream.req.removeListener("finish", onfinish); + stream.removeListener("end", onlegacyfinish); + stream.removeListener("close", onlegacyfinish); + stream.removeListener("finish", onfinish); + stream.removeListener("end", onend); + stream.removeListener("error", onerror); + stream.removeListener("close", onclose); + }; + } + exports$d = eos; + return exports$d; +} + +var exports$c = {}, + _dewExec$b = false; +function dew$b() { + if (_dewExec$b) return exports$c; + _dewExec$b = true; + var process$1 = process; + var _Object$setPrototypeO; + function _defineProperty(obj, key, value) { + key = _toPropertyKey(key); + if (key in obj) { + Object.defineProperty(obj, key, { + value: value, + enumerable: true, + configurable: true, + writable: true + }); + } else { + obj[key] = value; + } + return obj; + } + function _toPropertyKey(arg) { + var key = _toPrimitive(arg, "string"); + return typeof key === "symbol" ? key : String(key); + } + function _toPrimitive(input, hint) { + if (typeof input !== "object" || input === null) return input; + var prim = input[Symbol.toPrimitive]; + if (prim !== undefined) { + var res = prim.call(input, hint || "default"); + if (typeof res !== "object") return res; + throw new TypeError("@@toPrimitive must return a primitive value."); + } + return (hint === "string" ? String : Number)(input); + } + var finished = dew$c(); + var kLastResolve = Symbol("lastResolve"); + var kLastReject = Symbol("lastReject"); + var kError = Symbol("error"); + var kEnded = Symbol("ended"); + var kLastPromise = Symbol("lastPromise"); + var kHandlePromise = Symbol("handlePromise"); + var kStream = Symbol("stream"); + function createIterResult(value, done) { + return { + value: value, + done: done + }; + } + function readAndResolve(iter) { + var resolve = iter[kLastResolve]; + if (resolve !== null) { + var data = iter[kStream].read(); + // we defer if data is null + // we can be expecting either 'end' or + // 'error' + if (data !== null) { + iter[kLastPromise] = null; + iter[kLastResolve] = null; + iter[kLastReject] = null; + resolve(createIterResult(data, false)); + } + } + } + function onReadable(iter) { + // we wait for the next tick, because it might + // emit an error with process.nextTick + process$1.nextTick(readAndResolve, iter); + } + function wrapForNext(lastPromise, iter) { + return function (resolve, reject) { + lastPromise.then(function () { + if (iter[kEnded]) { + resolve(createIterResult(undefined, true)); + return; + } + iter[kHandlePromise](resolve, reject); + }, reject); + }; + } + var AsyncIteratorPrototype = Object.getPrototypeOf(function () {}); + var ReadableStreamAsyncIteratorPrototype = Object.setPrototypeOf((_Object$setPrototypeO = { + get stream() { + return this[kStream]; + }, + next: function next() { + var _this = this; + // if we have detected an error in the meanwhile + // reject straight away + var error = this[kError]; + if (error !== null) { + return Promise.reject(error); + } + if (this[kEnded]) { + return Promise.resolve(createIterResult(undefined, true)); + } + if (this[kStream].destroyed) { + // We need to defer via nextTick because if .destroy(err) is + // called, the error will be emitted via nextTick, and + // we cannot guarantee that there is no error lingering around + // waiting to be emitted. + return new Promise(function (resolve, reject) { + process$1.nextTick(function () { + if (_this[kError]) { + reject(_this[kError]); + } else { + resolve(createIterResult(undefined, true)); + } + }); + }); + } + + // if we have multiple next() calls + // we will wait for the previous Promise to finish + // this logic is optimized to support for await loops, + // where next() is only called once at a time + var lastPromise = this[kLastPromise]; + var promise; + if (lastPromise) { + promise = new Promise(wrapForNext(lastPromise, this)); + } else { + // fast path needed to support multiple this.push() + // without triggering the next() queue + var data = this[kStream].read(); + if (data !== null) { + return Promise.resolve(createIterResult(data, false)); + } + promise = new Promise(this[kHandlePromise]); + } + this[kLastPromise] = promise; + return promise; + } + }, _defineProperty(_Object$setPrototypeO, Symbol.asyncIterator, function () { + return this; + }), _defineProperty(_Object$setPrototypeO, "return", function _return() { + var _this2 = this; + // destroy(err, cb) is a private API + // we can guarantee we have that here, because we control the + // Readable class this is attached to + return new Promise(function (resolve, reject) { + _this2[kStream].destroy(null, function (err) { + if (err) { + reject(err); + return; + } + resolve(createIterResult(undefined, true)); + }); + }); + }), _Object$setPrototypeO), AsyncIteratorPrototype); + var createReadableStreamAsyncIterator = function createReadableStreamAsyncIterator(stream) { + var _Object$create; + var iterator = Object.create(ReadableStreamAsyncIteratorPrototype, (_Object$create = {}, _defineProperty(_Object$create, kStream, { + value: stream, + writable: true + }), _defineProperty(_Object$create, kLastResolve, { + value: null, + writable: true + }), _defineProperty(_Object$create, kLastReject, { + value: null, + writable: true + }), _defineProperty(_Object$create, kError, { + value: null, + writable: true + }), _defineProperty(_Object$create, kEnded, { + value: stream._readableState.endEmitted, + writable: true + }), _defineProperty(_Object$create, kHandlePromise, { + value: function value(resolve, reject) { + var data = iterator[kStream].read(); + if (data) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(data, false)); + } else { + iterator[kLastResolve] = resolve; + iterator[kLastReject] = reject; + } + }, + writable: true + }), _Object$create)); + iterator[kLastPromise] = null; + finished(stream, function (err) { + if (err && err.code !== "ERR_STREAM_PREMATURE_CLOSE") { + var reject = iterator[kLastReject]; + // reject if we are waiting for data in the Promise + // returned by next() and store the error + if (reject !== null) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + reject(err); + } + iterator[kError] = err; + return; + } + var resolve = iterator[kLastResolve]; + if (resolve !== null) { + iterator[kLastPromise] = null; + iterator[kLastResolve] = null; + iterator[kLastReject] = null; + resolve(createIterResult(undefined, true)); + } + iterator[kEnded] = true; + }); + stream.on("readable", onReadable.bind(null, iterator)); + return iterator; + }; + exports$c = createReadableStreamAsyncIterator; + return exports$c; +} + +var exports$b = {}, + _dewExec$a = false; +function dew$a() { + if (_dewExec$a) return exports$b; + _dewExec$a = true; + exports$b = function () { + throw new Error("Readable.from is not available in the browser"); + }; + return exports$b; +} + +var exports$a = {}, + _dewExec$9 = false; var _global$3 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$9() { + if (_dewExec$9) return exports$a; + _dewExec$9 = true; + var process$1 = process; + exports$a = Readable; -function dew$5() { - if (_dewExec$5) return exports$6; - _dewExec$5 = true; - exports$6.fetch = isFunction(_global$3.fetch) && isFunction(_global$3.ReadableStream); - exports$6.writableStream = isFunction(_global$3.WritableStream); - exports$6.abortController = isFunction(_global$3.AbortController); // The xhr request to example.com may violate some restrictive CSP configurations, - // so if we're running in a browser that supports `fetch`, avoid calling getXHR() - // and assume support for certain features below. + /**/ + var Duplex; + /**/ + + Readable.ReadableState = ReadableState; + + /**/ + y.EventEmitter; + var EElistenerCount = function EElistenerCount(emitter, type) { + return emitter.listeners(type).length; + }; + /**/ + + /**/ + var Stream = dew$j(); + /**/ + + var Buffer = dew$l().Buffer; + var OurUint8Array = (typeof _global$3 !== "undefined" ? _global$3 : typeof window !== "undefined" ? window : typeof self !== "undefined" ? self : {}).Uint8Array || function () {}; + function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk); + } + function _isUint8Array(obj) { + return Buffer.isBuffer(obj) || obj instanceof OurUint8Array; + } + + /**/ + var debugUtil = X; + var debug; + if (debugUtil && debugUtil.debuglog) { + debug = debugUtil.debuglog("stream"); + } else { + debug = function debug() {}; + } + /**/ + + var BufferList = dew$i(); + var destroyImpl = dew$h(); + var _require = dew$f(), + getHighWaterMark = _require.getHighWaterMark; + var _require$codes = dew$g().codes, + ERR_INVALID_ARG_TYPE = _require$codes.ERR_INVALID_ARG_TYPE, + ERR_STREAM_PUSH_AFTER_EOF = _require$codes.ERR_STREAM_PUSH_AFTER_EOF, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_STREAM_UNSHIFT_AFTER_END_EVENT = _require$codes.ERR_STREAM_UNSHIFT_AFTER_END_EVENT; + + // Lazy loaded to improve the startup performance. + var StringDecoder; + var createReadableStreamAsyncIterator; + var from; + dew$m()(Readable, Stream); + var errorOrDestroy = destroyImpl.errorOrDestroy; + var kProxyEvents = ["error", "close", "destroy", "pause", "resume"]; + function prependListener(emitter, event, fn) { + // Sadly this is not cacheable as some libraries bundle their own + // event emitter implementation with them. + if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn); + + // This is a hack to make sure that our error handler is attached before any + // userland ones. NEVER DO THIS. This is here only because this code needs + // to continue to work with older versions of Node.js that do not include + // the prependListener() method. The goal is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (Array.isArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; + } + function ReadableState(options, stream, isDuplex) { + Duplex = Duplex || dew$d(); + options = options || {}; + + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream. + // These options can be provided separately as readableXXX and writableXXX. + if (typeof isDuplex !== "boolean") isDuplex = stream instanceof Duplex; + + // object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away + this.objectMode = !!options.objectMode; + if (isDuplex) this.objectMode = this.objectMode || !!options.readableObjectMode; + + // the point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + this.highWaterMark = getHighWaterMark(this, options, "readableHighWaterMark", isDuplex); + + // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift() + this.buffer = new BufferList(); + this.length = 0; + this.pipes = null; + this.pipesCount = 0; + this.flowing = null; + this.ended = false; + this.endEmitted = false; + this.reading = false; + + // a flag to be able to tell if the event 'readable'/'data' is emitted + // immediately, or on a later tick. We set this to true at first, because + // any actions that shouldn't happen until "later" should generally also + // not happen before the first read call. + this.sync = true; + + // whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + this.needReadable = false; + this.emittedReadable = false; + this.readableListening = false; + this.resumeScheduled = false; + this.paused = true; + + // Should close be emitted on destroy. Defaults to true. + this.emitClose = options.emitClose !== false; + + // Should .destroy() be called after 'end' (and potentially 'finish') + this.autoDestroy = !!options.autoDestroy; + + // has it been destroyed + this.destroyed = false; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + this.defaultEncoding = options.defaultEncoding || "utf8"; + + // the number of writers that are awaiting a drain event in .pipe()s + this.awaitDrain = 0; + + // if true, a maybeReadMore has been scheduled + this.readingMore = false; + this.decoder = null; + this.encoding = null; + if (options.encoding) { + if (!StringDecoder) StringDecoder = exports$m.StringDecoder; + this.decoder = new StringDecoder(options.encoding); + this.encoding = options.encoding; + } + } + function Readable(options) { + Duplex = Duplex || dew$d(); + if (!(this instanceof Readable)) return new Readable(options); + + // Checking for a Stream.Duplex instance is faster here instead of inside + // the ReadableState constructor, at least with V8 6.5 + var isDuplex = this instanceof Duplex; + this._readableState = new ReadableState(options, this, isDuplex); + + // legacy + this.readable = true; + if (options) { + if (typeof options.read === "function") this._read = options.read; + if (typeof options.destroy === "function") this._destroy = options.destroy; + } + Stream.call(this); + } + Object.defineProperty(Readable.prototype, "destroyed", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + if (this._readableState === undefined) { + return false; + } + return this._readableState.destroyed; + }, + set: function set(value) { + // we ignore the value if the stream + // has not been initialized yet + if (!this._readableState) { + return; + } + + // backward compatibility, the user is explicitly + // managing destroyed + this._readableState.destroyed = value; + } + }); + Readable.prototype.destroy = destroyImpl.destroy; + Readable.prototype._undestroy = destroyImpl.undestroy; + Readable.prototype._destroy = function (err, cb) { + cb(err); + }; + + // Manually shove something into the read() buffer. + // This returns true if the highWaterMark has not been hit yet, + // similar to how Writable.write() returns true if you should + // write() some more. + Readable.prototype.push = function (chunk, encoding) { + var state = this._readableState; + var skipChunkCheck; + if (!state.objectMode) { + if (typeof chunk === "string") { + encoding = encoding || state.defaultEncoding; + if (encoding !== state.encoding) { + chunk = Buffer.from(chunk, encoding); + encoding = ""; + } + skipChunkCheck = true; + } + } else { + skipChunkCheck = true; + } + return readableAddChunk(this, chunk, encoding, false, skipChunkCheck); + }; + + // Unshift should *always* be something directly out of read() + Readable.prototype.unshift = function (chunk) { + return readableAddChunk(this, chunk, null, true, false); + }; + function readableAddChunk(stream, chunk, encoding, addToFront, skipChunkCheck) { + debug("readableAddChunk", chunk); + var state = stream._readableState; + if (chunk === null) { + state.reading = false; + onEofChunk(stream, state); + } else { + var er; + if (!skipChunkCheck) er = chunkInvalid(state, chunk); + if (er) { + errorOrDestroy(stream, er); + } else if (state.objectMode || chunk && chunk.length > 0) { + if (typeof chunk !== "string" && !state.objectMode && Object.getPrototypeOf(chunk) !== Buffer.prototype) { + chunk = _uint8ArrayToBuffer(chunk); + } + if (addToFront) { + if (state.endEmitted) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else addChunk(stream, state, chunk, true); + } else if (state.ended) { + errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF()); + } else if (state.destroyed) { + return false; + } else { + state.reading = false; + if (state.decoder && !encoding) { + chunk = state.decoder.write(chunk); + if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); + } else { + addChunk(stream, state, chunk, false); + } + } + } else if (!addToFront) { + state.reading = false; + maybeReadMore(stream, state); + } + } + + // We can push more data if we are below the highWaterMark. + // Also, if we have no data yet, we can stand some more bytes. + // This is to work around cases where hwm=0, such as the repl. + return !state.ended && (state.length < state.highWaterMark || state.length === 0); + } + function addChunk(stream, state, chunk, addToFront) { + if (state.flowing && state.length === 0 && !state.sync) { + state.awaitDrain = 0; + stream.emit("data", chunk); + } else { + // update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + if (state.needReadable) emitReadable(stream); + } + maybeReadMore(stream, state); + } + function chunkInvalid(state, chunk) { + var er; + if (!_isUint8Array(chunk) && typeof chunk !== "string" && chunk !== undefined && !state.objectMode) { + er = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk); + } + return er; + } + Readable.prototype.isPaused = function () { + return this._readableState.flowing === false; + }; + + // backwards compatibility. + Readable.prototype.setEncoding = function (enc) { + if (!StringDecoder) StringDecoder = exports$m.StringDecoder; + var decoder = new StringDecoder(enc); + this._readableState.decoder = decoder; + // If setEncoding(null), decoder.encoding equals utf8 + this._readableState.encoding = this._readableState.decoder.encoding; + + // Iterate over current buffer to convert already stored Buffers: + var p = this._readableState.buffer.head; + var content = ""; + while (p !== null) { + content += decoder.write(p.data); + p = p.next; + } + this._readableState.buffer.clear(); + if (content !== "") this._readableState.buffer.push(content); + this._readableState.length = content.length; + return this; + }; + + // Don't raise the hwm > 1GB + var MAX_HWM = 1073741824; + function computeNewHighWaterMark(n) { + if (n >= MAX_HWM) { + // TODO(ronag): Throw ERR_VALUE_OUT_OF_RANGE. + n = MAX_HWM; + } else { + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; + } + + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function howMuchToRead(n, state) { + if (n <= 0 || state.length === 0 && state.ended) return 0; + if (state.objectMode) return 1; + if (n !== n) { + // Only flow one buffer at a time + if (state.flowing && state.length) return state.buffer.head.data.length;else return state.length; + } + // If we're asking for more than the current hwm, then raise the hwm. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + if (n <= state.length) return n; + // Don't have enough + if (!state.ended) { + state.needReadable = true; + return 0; + } + return state.length; + } + + // you can override either this method, or the async _read(n) below. + Readable.prototype.read = function (n) { + debug("read", n); + n = parseInt(n, 10); + var state = this._readableState; + var nOrig = n; + if (n !== 0) state.emittedReadable = false; + + // if we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) { + debug("read: emitReadable", state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this);else emitReadable(this); + return null; + } + n = howMuchToRead(n, state); + + // if we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this); + return null; + } + + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. + + // if we need a readable event, then we need to do some reading. + var doRead = state.needReadable; + debug("need readable", doRead); + + // if we currently have less than the highWaterMark, then also read some + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug("length less than watermark", doRead); + } + + // however, if we've ended, then there's no point, and if we're already + // reading, then it's unnecessary. + if (state.ended || state.reading) { + doRead = false; + debug("reading or ended", doRead); + } else if (doRead) { + debug("do read"); + state.reading = true; + state.sync = true; + // if the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.needReadable = true; + // call internal read method + this._read(state.highWaterMark); + state.sync = false; + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (!state.reading) n = howMuchToRead(nOrig, state); + } + var ret; + if (n > 0) ret = fromList(n, state);else ret = null; + if (ret === null) { + state.needReadable = state.length <= state.highWaterMark; + n = 0; + } else { + state.length -= n; + state.awaitDrain = 0; + } + if (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!state.ended) state.needReadable = true; + + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended) endReadable(this); + } + if (ret !== null) this.emit("data", ret); + return ret; + }; + function onEofChunk(stream, state) { + debug("onEofChunk"); + if (state.ended) return; + if (state.decoder) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + state.ended = true; + if (state.sync) { + // if we are sync, wait until next tick to emit the data. + // Otherwise we risk emitting data in the flow() + // the readable code triggers during a read() call + emitReadable(stream); + } else { + // emit 'readable' now to make sure it gets picked up. + state.needReadable = false; + if (!state.emittedReadable) { + state.emittedReadable = true; + emitReadable_(stream); + } + } + } + + // Don't emit readable right away in sync mode, because this can trigger + // another read() call => stack overflow. This way, it might trigger + // a nextTick recursion warning, but that's not so bad. + function emitReadable(stream) { + var state = stream._readableState; + debug("emitReadable", state.needReadable, state.emittedReadable); + state.needReadable = false; + if (!state.emittedReadable) { + debug("emitReadable", state.flowing); + state.emittedReadable = true; + process$1.nextTick(emitReadable_, stream); + } + } + function emitReadable_(stream) { + var state = stream._readableState; + debug("emitReadable_", state.destroyed, state.length, state.ended); + if (!state.destroyed && (state.length || state.ended)) { + stream.emit("readable"); + state.emittedReadable = false; + } + + // The stream needs another readable event if + // 1. It is not flowing, as the flow mechanism will take + // care of it. + // 2. It is not ended. + // 3. It is below the highWaterMark, so we can schedule + // another readable later. + state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark; + flow(stream); + } + + // at this point, the user has presumably seen the 'readable' event, + // and called read() to consume some data. that may have triggered + // in turn another _read(n) call, in which case reading = true if + // it's in progress. + // However, if we're not ended, or reading, and the length < hwm, + // then go ahead and try to read some more preemptively. + function maybeReadMore(stream, state) { + if (!state.readingMore) { + state.readingMore = true; + process$1.nextTick(maybeReadMore_, stream, state); + } + } + function maybeReadMore_(stream, state) { + // Attempt to read more data if we should. + // + // The conditions for reading more data are (one of): + // - Not enough data buffered (state.length < state.highWaterMark). The loop + // is responsible for filling the buffer with enough data if such data + // is available. If highWaterMark is 0 and we are not in the flowing mode + // we should _not_ attempt to buffer any extra data. We'll get more data + // when the stream consumer calls read() instead. + // - No data in the buffer, and the stream is in flowing mode. In this mode + // the loop below is responsible for ensuring read() is called. Failing to + // call read here would abort the flow and there's no other mechanism for + // continuing the flow if the stream consumer has just subscribed to the + // 'data' event. + // + // In addition to the above conditions to keep reading data, the following + // conditions prevent the data from being read: + // - The stream has ended (state.ended). + // - There is already a pending 'read' operation (state.reading). This is a + // case where the the stream has called the implementation defined _read() + // method, but they are processing the call asynchronously and have _not_ + // called push() with new data. In this case we skip performing more + // read()s. The execution ends in this method again after the _read() ends + // up calling push() with more data. + while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { + var len = state.length; + debug("maybeReadMore read 0"); + stream.read(0); + if (len === state.length) + // didn't get any data, stop spinning. + break; + } + state.readingMore = false; + } + + // abstract method. to be overridden in specific implementation classes. + // call cb(er, data) where data is <= n in length. + // for virtual (non-string, non-buffer) streams, "length" is somewhat + // arbitrary, and perhaps not very meaningful. + Readable.prototype._read = function (n) { + errorOrDestroy(this, new ERR_METHOD_NOT_IMPLEMENTED("_read()")); + }; + Readable.prototype.pipe = function (dest, pipeOpts) { + var src = this; + var state = this._readableState; + switch (state.pipesCount) { + case 0: + state.pipes = dest; + break; + case 1: + state.pipes = [state.pipes, dest]; + break; + default: + state.pipes.push(dest); + break; + } + state.pipesCount += 1; + debug("pipe count=%d opts=%j", state.pipesCount, pipeOpts); + var doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process$1.stdout && dest !== process$1.stderr; + var endFn = doEnd ? onend : unpipe; + if (state.endEmitted) process$1.nextTick(endFn);else src.once("end", endFn); + dest.on("unpipe", onunpipe); + function onunpipe(readable, unpipeInfo) { + debug("onunpipe"); + if (readable === src) { + if (unpipeInfo && unpipeInfo.hasUnpiped === false) { + unpipeInfo.hasUnpiped = true; + cleanup(); + } + } + } + function onend() { + debug("onend"); + dest.end(); + } + + // when the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + var ondrain = pipeOnDrain(src); + dest.on("drain", ondrain); + var cleanedUp = false; + function cleanup() { + debug("cleanup"); + // cleanup event handlers once the pipe is broken + dest.removeListener("close", onclose); + dest.removeListener("finish", onfinish); + dest.removeListener("drain", ondrain); + dest.removeListener("error", onerror); + dest.removeListener("unpipe", onunpipe); + src.removeListener("end", onend); + src.removeListener("end", unpipe); + src.removeListener("data", ondata); + cleanedUp = true; + + // if the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (state.awaitDrain && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + src.on("data", ondata); + function ondata(chunk) { + debug("ondata"); + var ret = dest.write(chunk); + debug("dest.write", ret); + if (ret === false) { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + // => Check whether `dest` is still a piping destination. + if ((state.pipesCount === 1 && state.pipes === dest || state.pipesCount > 1 && indexOf(state.pipes, dest) !== -1) && !cleanedUp) { + debug("false write response, pause", state.awaitDrain); + state.awaitDrain++; + } + src.pause(); + } + } + + // if the dest has an error, then stop piping into it. + // however, don't suppress the throwing behavior for this. + function onerror(er) { + debug("onerror", er); + unpipe(); + dest.removeListener("error", onerror); + if (EElistenerCount(dest, "error") === 0) errorOrDestroy(dest, er); + } + + // Make sure our error handler is attached before userland ones. + prependListener(dest, "error", onerror); + + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener("finish", onfinish); + unpipe(); + } + dest.once("close", onclose); + function onfinish() { + debug("onfinish"); + dest.removeListener("close", onclose); + unpipe(); + } + dest.once("finish", onfinish); + function unpipe() { + debug("unpipe"); + src.unpipe(dest); + } + + // tell the dest that it's being piped to + dest.emit("pipe", src); + + // start the flow if it hasn't been started already. + if (!state.flowing) { + debug("pipe resume"); + src.resume(); + } + return dest; + }; + function pipeOnDrain(src) { + return function pipeOnDrainFunctionResult() { + var state = src._readableState; + debug("pipeOnDrain", state.awaitDrain); + if (state.awaitDrain) state.awaitDrain--; + if (state.awaitDrain === 0 && EElistenerCount(src, "data")) { + state.flowing = true; + flow(src); + } + }; + } + Readable.prototype.unpipe = function (dest) { + var state = this._readableState; + var unpipeInfo = { + hasUnpiped: false + }; + + // if we're not piping anywhere, then do nothing. + if (state.pipesCount === 0) return this; + + // just one destination. most common case. + if (state.pipesCount === 1) { + // passed in one, but it's not the right one. + if (dest && dest !== state.pipes) return this; + if (!dest) dest = state.pipes; + + // got a match. + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + if (dest) dest.emit("unpipe", this, unpipeInfo); + return this; + } + + // slow case. multiple pipe destinations. + + if (!dest) { + // remove all. + var dests = state.pipes; + var len = state.pipesCount; + state.pipes = null; + state.pipesCount = 0; + state.flowing = false; + for (var i = 0; i < len; i++) dests[i].emit("unpipe", this, { + hasUnpiped: false + }); + return this; + } + + // try to find the right one. + var index = indexOf(state.pipes, dest); + if (index === -1) return this; + state.pipes.splice(index, 1); + state.pipesCount -= 1; + if (state.pipesCount === 1) state.pipes = state.pipes[0]; + dest.emit("unpipe", this, unpipeInfo); + return this; + }; + + // set up data events if they are asked for + // Ensure readable listeners eventually get something + Readable.prototype.on = function (ev, fn) { + var res = Stream.prototype.on.call(this, ev, fn); + var state = this._readableState; + if (ev === "data") { + // update readableListening so that resume() may be a no-op + // a few lines down. This is needed to support once('readable'). + state.readableListening = this.listenerCount("readable") > 0; + + // Try start flowing on next tick if stream isn't explicitly paused + if (state.flowing !== false) this.resume(); + } else if (ev === "readable") { + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; + state.flowing = false; + state.emittedReadable = false; + debug("on readable", state.length, state.reading); + if (state.length) { + emitReadable(this); + } else if (!state.reading) { + process$1.nextTick(nReadingNextTick, this); + } + } + } + return res; + }; + Readable.prototype.addListener = Readable.prototype.on; + Readable.prototype.removeListener = function (ev, fn) { + var res = Stream.prototype.removeListener.call(this, ev, fn); + if (ev === "readable") { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process$1.nextTick(updateReadableListening, this); + } + return res; + }; + Readable.prototype.removeAllListeners = function (ev) { + var res = Stream.prototype.removeAllListeners.apply(this, arguments); + if (ev === "readable" || ev === undefined) { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process$1.nextTick(updateReadableListening, this); + } + return res; + }; + function updateReadableListening(self) { + var state = self._readableState; + state.readableListening = self.listenerCount("readable") > 0; + if (state.resumeScheduled && !state.paused) { + // flowing needs to be set to true now, otherwise + // the upcoming resume will not flow. + state.flowing = true; + + // crude way to check if we should resume + } else if (self.listenerCount("data") > 0) { + self.resume(); + } + } + function nReadingNextTick(self) { + debug("readable nexttick read 0"); + self.read(0); + } - var xhr; + // pause() and resume() are remnants of the legacy readable stream API + // If the user uses them, then switch into old mode. + Readable.prototype.resume = function () { + var state = this._readableState; + if (!state.flowing) { + debug("resume"); + // we flow only if there is no one listening + // for readable, but we still have to call + // resume() + state.flowing = !state.readableListening; + resume(this, state); + } + state.paused = false; + return this; + }; + function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + process$1.nextTick(resume_, stream, state); + } + } + function resume_(stream, state) { + debug("resume", state.reading); + if (!state.reading) { + stream.read(0); + } + state.resumeScheduled = false; + stream.emit("resume"); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); + } + Readable.prototype.pause = function () { + debug("call pause flowing=%j", this._readableState.flowing); + if (this._readableState.flowing !== false) { + debug("pause"); + this._readableState.flowing = false; + this.emit("pause"); + } + this._readableState.paused = true; + return this; + }; + function flow(stream) { + var state = stream._readableState; + debug("flow", state.flowing); + while (state.flowing && stream.read() !== null); + } - function getXHR() { - // Cache the xhr value - if (xhr !== undefined) return xhr; + // wrap an old-style stream as the async data source. + // This is *not* part of the readable stream interface. + // It is an ugly unfortunate mess of history. + Readable.prototype.wrap = function (stream) { + var _this = this; + var state = this._readableState; + var paused = false; + stream.on("end", function () { + debug("wrapped end"); + if (state.decoder && !state.ended) { + var chunk = state.decoder.end(); + if (chunk && chunk.length) _this.push(chunk); + } + _this.push(null); + }); + stream.on("data", function (chunk) { + debug("wrapped data"); + if (state.decoder) chunk = state.decoder.write(chunk); + + // don't skip over falsy values in objectMode + if (state.objectMode && (chunk === null || chunk === undefined)) return;else if (!state.objectMode && (!chunk || !chunk.length)) return; + var ret = _this.push(chunk); + if (!ret) { + paused = true; + stream.pause(); + } + }); - if (_global$3.XMLHttpRequest) { - xhr = new _global$3.XMLHttpRequest(); // If XDomainRequest is available (ie only, where xhr might not work - // cross domain), use the page location. Otherwise use example.com - // Note: this doesn't actually make an http request. + // proxy all the other methods. + // important when wrapping filters and duplexes. + for (var i in stream) { + if (this[i] === undefined && typeof stream[i] === "function") { + this[i] = function methodWrap(method) { + return function methodWrapReturnFunction() { + return stream[method].apply(stream, arguments); + }; + }(i); + } + } - try { - xhr.open("GET", _global$3.XDomainRequest ? "/" : "https://example.com"); - } catch (e) { - xhr = null; + // proxy certain important events. + for (var n = 0; n < kProxyEvents.length; n++) { + stream.on(kProxyEvents[n], this.emit.bind(this, kProxyEvents[n])); + } + + // when we try to consume some more bytes, simply unpause the + // underlying stream. + this._read = function (n) { + debug("wrapped _read", n); + if (paused) { + paused = false; + stream.resume(); + } + }; + return this; + }; + if (typeof Symbol === "function") { + Readable.prototype[Symbol.asyncIterator] = function () { + if (createReadableStreamAsyncIterator === undefined) { + createReadableStreamAsyncIterator = dew$b(); + } + return createReadableStreamAsyncIterator(this); + }; + } + Object.defineProperty(Readable.prototype, "readableHighWaterMark", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.highWaterMark; + } + }); + Object.defineProperty(Readable.prototype, "readableBuffer", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState && this._readableState.buffer; + } + }); + Object.defineProperty(Readable.prototype, "readableFlowing", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.flowing; + }, + set: function set(state) { + if (this._readableState) { + this._readableState.flowing = state; } + } + }); + + // exposed for testing purposes only. + Readable._fromList = fromList; + Object.defineProperty(Readable.prototype, "readableLength", { + // making it explicit this property is not enumerable + // because otherwise some prototype manipulation in + // userland will fail + enumerable: false, + get: function get() { + return this._readableState.length; + } + }); + + // Pluck off n bytes from an array of buffers. + // Length is the combined lengths of all the buffers in the list. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function fromList(n, state) { + // nothing buffered + if (state.length === 0) return null; + var ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // read it all, truncate the list + if (state.decoder) ret = state.buffer.join("");else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length); + state.buffer.clear(); } else { - // Service workers don't have XHR - xhr = null; + // read part of list + ret = state.buffer.consume(n, state.decoder); } - - return xhr; + return ret; } + function endReadable(stream) { + var state = stream._readableState; + debug("endReadable", state.endEmitted); + if (!state.endEmitted) { + state.ended = true; + process$1.nextTick(endReadableNT, state, stream); + } + } + function endReadableNT(state, stream) { + debug("endReadableNT", state.endEmitted, state.length); + + // Check that we didn't get one last unshift. + if (!state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.readable = false; + stream.emit("end"); + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the writable side is ready for autoDestroy as well + var wState = stream._writableState; + if (!wState || wState.autoDestroy && wState.finished) { + stream.destroy(); + } + } + } + } + if (typeof Symbol === "function") { + Readable.from = function (iterable, opts) { + if (from === undefined) { + from = dew$a(); + } + return from(Readable, iterable, opts); + }; + } + function indexOf(xs, x) { + for (var i = 0, l = xs.length; i < l; i++) { + if (xs[i] === x) return i; + } + return -1; + } + return exports$a; +} - function checkTypeSupport(type) { - var xhr = getXHR(); - if (!xhr) return false; - - try { - xhr.responseType = type; - return xhr.responseType === type; - } catch (e) {} +var exports$9 = {}, + _dewExec$8 = false; +function dew$8() { + if (_dewExec$8) return exports$9; + _dewExec$8 = true; + exports$9 = Transform; + var _require$codes = dew$g().codes, + ERR_METHOD_NOT_IMPLEMENTED = _require$codes.ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK = _require$codes.ERR_MULTIPLE_CALLBACK, + ERR_TRANSFORM_ALREADY_TRANSFORMING = _require$codes.ERR_TRANSFORM_ALREADY_TRANSFORMING, + ERR_TRANSFORM_WITH_LENGTH_0 = _require$codes.ERR_TRANSFORM_WITH_LENGTH_0; + var Duplex = dew$d(); + dew$m()(Transform, Duplex); + function afterTransform(er, data) { + var ts = this._transformState; + ts.transforming = false; + var cb = ts.writecb; + if (cb === null) { + return this.emit("error", new ERR_MULTIPLE_CALLBACK()); + } + ts.writechunk = null; + ts.writecb = null; + if (data != null) + // single equals check for both `null` and `undefined` + this.push(data); + cb(er); + var rs = this._readableState; + rs.reading = false; + if (rs.needReadable || rs.length < rs.highWaterMark) { + this._read(rs.highWaterMark); + } + } + function Transform(options) { + if (!(this instanceof Transform)) return new Transform(options); + Duplex.call(this, options); + this._transformState = { + afterTransform: afterTransform.bind(this), + needTransform: false, + transforming: false, + writecb: null, + writechunk: null, + writeencoding: null + }; - return false; - } // If fetch is supported, then arraybuffer will be supported too. Skip calling - // checkTypeSupport(), since that calls getXHR(). + // start out asking for a readable event once data is transformed. + this._readableState.needReadable = true; + // we have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + if (options) { + if (typeof options.transform === "function") this._transform = options.transform; + if (typeof options.flush === "function") this._flush = options.flush; + } - exports$6.arraybuffer = exports$6.fetch || checkTypeSupport("arraybuffer"); // These next two tests unavoidably show warnings in Chrome. Since fetch will always - // be used if it's available, just return false for these to avoid the warnings. + // When the writable side finishes, then flush out anything remaining. + this.on("prefinish", prefinish); + } + function prefinish() { + var _this = this; + if (typeof this._flush === "function" && !this._readableState.destroyed) { + this._flush(function (er, data) { + done(_this, er, data); + }); + } else { + done(this, null, null); + } + } + Transform.prototype.push = function (chunk, encoding) { + this._transformState.needTransform = false; + return Duplex.prototype.push.call(this, chunk, encoding); + }; - exports$6.msstream = !exports$6.fetch && checkTypeSupport("ms-stream"); - exports$6.mozchunkedarraybuffer = !exports$6.fetch && checkTypeSupport("moz-chunked-arraybuffer"); // If fetch is supported, then overrideMimeType will be supported too. Skip calling - // getXHR(). + // This is the part where you do stuff! + // override this function in implementation classes. + // 'chunk' is an input chunk. + // + // Call `push(newChunk)` to pass along transformed output + // to the readable side. You may call 'push' zero or more times. + // + // Call `cb(err)` when you are done with this chunk. If you pass + // an error, then that'll put the hurt on the whole operation. If you + // never call cb(), then you'll never get another chunk. + Transform.prototype._transform = function (chunk, encoding, cb) { + cb(new ERR_METHOD_NOT_IMPLEMENTED("_transform()")); + }; + Transform.prototype._write = function (chunk, encoding, cb) { + var ts = this._transformState; + ts.writecb = cb; + ts.writechunk = chunk; + ts.writeencoding = encoding; + if (!ts.transforming) { + var rs = this._readableState; + if (ts.needTransform || rs.needReadable || rs.length < rs.highWaterMark) this._read(rs.highWaterMark); + } + }; - exports$6.overrideMimeType = exports$6.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false); + // Doesn't matter what the args are here. + // _transform does all the work. + // That we got here means that the readable side wants more data. + Transform.prototype._read = function (n) { + var ts = this._transformState; + if (ts.writechunk !== null && !ts.transforming) { + ts.transforming = true; + this._transform(ts.writechunk, ts.writeencoding, ts.afterTransform); + } else { + // mark that we need a transform, so that any data that comes in + // will get processed, now that we've asked for it. + ts.needTransform = true; + } + }; + Transform.prototype._destroy = function (err, cb) { + Duplex.prototype._destroy.call(this, err, function (err2) { + cb(err2); + }); + }; + function done(stream, er, data) { + if (er) return stream.emit("error", er); + if (data != null) + // single equals check for both `null` and `undefined` + stream.push(data); + + // TODO(BridgeAR): Write a test for these two error cases + // if there's nothing in the write buffer, then that means + // that nothing more will ever be provided + if (stream._writableState.length) throw new ERR_TRANSFORM_WITH_LENGTH_0(); + if (stream._transformState.transforming) throw new ERR_TRANSFORM_ALREADY_TRANSFORMING(); + return stream.push(null); + } + return exports$9; +} - function isFunction(value) { - return typeof value === "function"; +var exports$8 = {}, + _dewExec$7 = false; +function dew$7() { + if (_dewExec$7) return exports$8; + _dewExec$7 = true; + exports$8 = PassThrough; + var Transform = dew$8(); + dew$m()(PassThrough, Transform); + function PassThrough(options) { + if (!(this instanceof PassThrough)) return new PassThrough(options); + Transform.call(this, options); } + PassThrough.prototype._transform = function (chunk, encoding, cb) { + cb(null, chunk); + }; + return exports$8; +} - xhr = null; // Help gc +var exports$7 = {}, + _dewExec$6 = false; +function dew$6() { + if (_dewExec$6) return exports$7; + _dewExec$6 = true; + var eos; + function once(callback) { + var called = false; + return function () { + if (called) return; + called = true; + callback.apply(void 0, arguments); + }; + } + var _require$codes = dew$g().codes, + ERR_MISSING_ARGS = _require$codes.ERR_MISSING_ARGS, + ERR_STREAM_DESTROYED = _require$codes.ERR_STREAM_DESTROYED; + function noop(err) { + // Rethrow the error if it exists to avoid swallowing it + if (err) throw err; + } + function isRequest(stream) { + return stream.setHeader && typeof stream.abort === "function"; + } + function destroyer(stream, reading, writing, callback) { + callback = once(callback); + var closed = false; + stream.on("close", function () { + closed = true; + }); + if (eos === undefined) eos = dew$c(); + eos(stream, { + readable: reading, + writable: writing + }, function (err) { + if (err) return callback(err); + closed = true; + callback(); + }); + var destroyed = false; + return function (err) { + if (closed) return; + if (destroyed) return; + destroyed = true; + + // request.destroy just do .end - .abort is what we want + if (isRequest(stream)) return stream.abort(); + if (typeof stream.destroy === "function") return stream.destroy(); + callback(err || new ERR_STREAM_DESTROYED("pipe")); + }; + } + function call(fn) { + fn(); + } + function pipe(from, to) { + return from.pipe(to); + } + function popCallback(streams) { + if (!streams.length) return noop; + if (typeof streams[streams.length - 1] !== "function") return noop; + return streams.pop(); + } + function pipeline() { + for (var _len = arguments.length, streams = new Array(_len), _key = 0; _key < _len; _key++) { + streams[_key] = arguments[_key]; + } + var callback = popCallback(streams); + if (Array.isArray(streams[0])) streams = streams[0]; + if (streams.length < 2) { + throw new ERR_MISSING_ARGS("streams"); + } + var error; + var destroys = streams.map(function (stream, i) { + var reading = i < streams.length - 1; + var writing = i > 0; + return destroyer(stream, reading, writing, function (err) { + if (!error) error = err; + if (err) destroys.forEach(call); + if (reading) return; + destroys.forEach(call); + callback(error); + }); + }); + return streams.reduce(pipe); + } + exports$7 = pipeline; + return exports$7; +} +var exports$6 = {}, + _dewExec$5 = false; +function dew$5() { + if (_dewExec$5) return exports$6; + _dewExec$5 = true; + exports$6 = exports$6 = dew$9(); + exports$6.Stream = exports$6; + exports$6.Readable = exports$6; + exports$6.Writable = dew$e(); + exports$6.Duplex = dew$d(); + exports$6.Transform = dew$8(); + exports$6.PassThrough = dew$7(); + exports$6.finished = dew$c(); + exports$6.pipeline = dew$6(); return exports$6; } var exports$5 = {}, - _dewExec$4 = false; - + _dewExec$4 = false; var _global$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$4() { if (_dewExec$4) return exports$5; _dewExec$4 = true; - var Buffer = buffer.Buffer; + var Buffer = dew$l().Buffer; var process$1 = process; - - var capability = dew$5(); - - var inherits = dew$7(); - - var stream = dew$6(); - + var capability = dew$k(); + var inherits = dew$m(); + var stream = dew$5(); var rStates = exports$5.readyStates = { UNSENT: 0, OPENED: 1, @@ -105,7 +2898,6 @@ function dew$4() { LOADING: 3, DONE: 4 }; - var IncomingMessage = exports$5.IncomingMessage = function (xhr, response, mode, resetTimers) { var self = this || _global$2; stream.Readable.call(self); @@ -113,15 +2905,15 @@ function dew$4() { self.headers = {}; self.rawHeaders = []; self.trailers = {}; - self.rawTrailers = []; // Fake the 'close' event, but only once 'end' fires + self.rawTrailers = []; + // Fake the 'close' event, but only once 'end' fires self.on("end", function () { // The nextTick is necessary to prevent the 'request' module from causing an infinite loop process$1.nextTick(function () { self.emit("close"); }); }); - if (mode === "fetch") { self._fetchResponse = response; self.url = response.url; @@ -131,7 +2923,6 @@ function dew$4() { self.headers[key.toLowerCase()] = header; self.rawHeaders.push(key, header); }); - if (capability.writableStream) { var writable = new WritableStream({ write: function (chunk) { @@ -155,7 +2946,6 @@ function dew$4() { if (!self._destroyed) self.emit("error", err); } }); - try { response.body.pipeTo(writable).catch(function (err) { resetTimers(true); @@ -163,22 +2953,17 @@ function dew$4() { }); return; } catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this - - } // fallback for when writableStream or pipeTo aren't available - - + } + // fallback for when writableStream or pipeTo aren't available var reader = response.body.getReader(); - function read() { reader.read().then(function (result) { if (self._destroyed) return; resetTimers(result.done); - if (result.done) { self.push(null); return; } - self.push(Buffer.from(result.value)); read(); }).catch(function (err) { @@ -186,7 +2971,6 @@ function dew$4() { if (!self._destroyed) self.emit("error", err); }); } - read(); } else { self._xhr = xhr; @@ -197,149 +2981,115 @@ function dew$4() { var headers = xhr.getAllResponseHeaders().split(/\r?\n/); headers.forEach(function (header) { var matches = header.match(/^([^:]+):\s*(.*)/); - if (matches) { var key = matches[1].toLowerCase(); - if (key === "set-cookie") { if (self.headers[key] === undefined) { self.headers[key] = []; } - self.headers[key].push(matches[2]); } else if (self.headers[key] !== undefined) { self.headers[key] += ", " + matches[2]; } else { self.headers[key] = matches[2]; } - self.rawHeaders.push(matches[1], matches[2]); } }); self._charset = "x-user-defined"; - if (!capability.overrideMimeType) { var mimeType = self.rawHeaders["mime-type"]; - if (mimeType) { var charsetMatch = mimeType.match(/;\s*charset=([^;])(;|$)/); - if (charsetMatch) { self._charset = charsetMatch[1].toLowerCase(); } } - if (!self._charset) self._charset = "utf-8"; // best guess } } }; - inherits(IncomingMessage, stream.Readable); - IncomingMessage.prototype._read = function () { var self = this || _global$2; var resolve = self._resumeFetch; - if (resolve) { self._resumeFetch = null; resolve(); } }; - IncomingMessage.prototype._onXHRProgress = function (resetTimers) { var self = this || _global$2; var xhr = self._xhr; var response = null; - switch (self._mode) { case "text": response = xhr.responseText; - if (response.length > self._pos) { var newData = response.substr(self._pos); - if (self._charset === "x-user-defined") { var buffer = Buffer.alloc(newData.length); - for (var i = 0; i < newData.length; i++) buffer[i] = newData.charCodeAt(i) & 255; - self.push(buffer); } else { self.push(newData, self._charset); } - self._pos = response.length; } - break; - case "arraybuffer": if (xhr.readyState !== rStates.DONE || !xhr.response) break; response = xhr.response; self.push(Buffer.from(new Uint8Array(response))); break; - case "moz-chunked-arraybuffer": // take whole response = xhr.response; if (xhr.readyState !== rStates.LOADING || !response) break; self.push(Buffer.from(new Uint8Array(response))); break; - case "ms-stream": response = xhr.response; if (xhr.readyState !== rStates.LOADING) break; var reader = new _global$2.MSStreamReader(); - reader.onprogress = function () { if (reader.result.byteLength > self._pos) { self.push(Buffer.from(new Uint8Array(reader.result.slice(self._pos)))); self._pos = reader.result.byteLength; } }; - reader.onload = function () { resetTimers(true); self.push(null); - }; // reader.onerror = ??? // TODO: this - - + }; + // reader.onerror = ??? // TODO: this reader.readAsArrayBuffer(response); break; - } // The ms-stream case handles end separately in reader.onload() - + } + // The ms-stream case handles end separately in reader.onload() if (self._xhr.readyState === rStates.DONE && self._mode !== "ms-stream") { resetTimers(true); self.push(null); } }; - return exports$5; } var exports$4 = {}, - _dewExec$3 = false; - + _dewExec$3 = false; var _global$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$3() { if (_dewExec$3) return exports$4; _dewExec$3 = true; - var Buffer = buffer.Buffer; + var Buffer = dew$l().Buffer; var process$1 = process; - - var capability = dew$5(); - - var inherits = dew$7(); - + var capability = dew$k(); + var inherits = dew$m(); var response = dew$4(); - - var stream = dew$6(); - + var stream = dew$5(); var IncomingMessage = response.IncomingMessage; var rStates = response.readyStates; - function decideMode(preferBinary, useFetch) { if (capability.fetch && useFetch) { return "fetch"; @@ -353,7 +3103,6 @@ function dew$3() { return "text"; } } - var ClientRequest = exports$4 = function (opts) { var self = this || _global$1; stream.Writable.call(self); @@ -366,7 +3115,6 @@ function dew$3() { }); var preferBinary; var useFetch = true; - if (opts.mode === "disable-fetch" || "requestTimeout" in opts && !capability.abortController) { // If the use of XHR should be preferred. Not typically needed. useFetch = false; @@ -384,7 +3132,6 @@ function dew$3() { } else { throw new Error("Invalid value for opts.mode"); } - self._mode = decideMode(preferBinary, useFetch); self._fetchTimer = null; self._socketTimeout = null; @@ -393,58 +3140,48 @@ function dew$3() { self._onFinish(); }); }; - inherits(ClientRequest, stream.Writable); - ClientRequest.prototype.setHeader = function (name, value) { var self = this || _global$1; - var lowerName = name.toLowerCase(); // This check is not necessary, but it prevents warnings from browsers about setting unsafe + var lowerName = name.toLowerCase(); + // This check is not necessary, but it prevents warnings from browsers about setting unsafe // headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but // http-browserify did it, so I will too. - if (unsafeHeaders.indexOf(lowerName) !== -1) return; self._headers[lowerName] = { name: name, value: value }; }; - ClientRequest.prototype.getHeader = function (name) { var header = (this || _global$1)._headers[name.toLowerCase()]; - if (header) return header.value; return null; }; - ClientRequest.prototype.removeHeader = function (name) { var self = this || _global$1; delete self._headers[name.toLowerCase()]; }; - ClientRequest.prototype._onFinish = function () { var self = this || _global$1; if (self._destroyed) return; var opts = self._opts; - if ("timeout" in opts && opts.timeout !== 0) { self.setTimeout(opts.timeout); } - var headersObj = self._headers; var body = null; - if (opts.method !== "GET" && opts.method !== "HEAD") { body = new Blob(self._body, { type: (headersObj["content-type"] || {}).value || "" }); - } // create flattened list of headers - + } + // create flattened list of headers var headersList = []; Object.keys(headersObj).forEach(function (keyName) { var name = headersObj[keyName].name; var value = headersObj[keyName].value; - if (Array.isArray(value)) { value.forEach(function (v) { headersList.push([name, v]); @@ -453,15 +3190,12 @@ function dew$3() { headersList.push([name, value]); } }); - if (self._mode === "fetch") { var signal = null; - if (capability.abortController) { var controller = new AbortController(); signal = controller.signal; self._fetchAbortController = controller; - if ("requestTimeout" in opts && opts.requestTimeout !== 0) { self._fetchTimer = _global$1.setTimeout(function () { self.emit("requestTimeout"); @@ -469,7 +3203,6 @@ function dew$3() { }, opts.requestTimeout); } } - _global$1.fetch(self._opts.url, { method: self._opts.method, headers: headersList, @@ -479,18 +3212,14 @@ function dew$3() { signal: signal }).then(function (response) { self._fetchResponse = response; - self._resetTimers(false); - self._connect(); }, function (reason) { self._resetTimers(true); - if (!self._destroyed) self.emit("error", reason); }); } else { var xhr = self._xhr = new _global$1.XMLHttpRequest(); - try { xhr.open(self._opts.method, self._opts.url, true); } catch (err) { @@ -498,52 +3227,42 @@ function dew$3() { self.emit("error", err); }); return; - } // Can't set responseType on really old browsers - + } + // Can't set responseType on really old browsers if ("responseType" in xhr) xhr.responseType = self._mode; if ("withCredentials" in xhr) xhr.withCredentials = !!opts.withCredentials; if (self._mode === "text" && "overrideMimeType" in xhr) xhr.overrideMimeType("text/plain; charset=x-user-defined"); - if ("requestTimeout" in opts) { xhr.timeout = opts.requestTimeout; - xhr.ontimeout = function () { self.emit("requestTimeout"); }; } - headersList.forEach(function (header) { xhr.setRequestHeader(header[0], header[1]); }); self._response = null; - xhr.onreadystatechange = function () { switch (xhr.readyState) { case rStates.LOADING: case rStates.DONE: self._onXHRProgress(); - break; } - }; // Necessary for streaming in Firefox, since xhr.response is ONLY defined + }; + // Necessary for streaming in Firefox, since xhr.response is ONLY defined // in onprogress, not in onreadystatechange with xhr.readyState = 3 - - if (self._mode === "moz-chunked-arraybuffer") { xhr.onprogress = function () { self._onXHRProgress(); }; } - xhr.onerror = function () { if (self._destroyed) return; - self._resetTimers(true); - self.emit("error", new Error("XHR error")); }; - try { xhr.send(body); } catch (err) { @@ -554,13 +3273,12 @@ function dew$3() { } } }; + /** * Checks if xhr.status is readable and non-zero, indicating no error. * Even though the spec says it should be available in readyState 3, * accessing it throws an exception in IE8 */ - - function statusValid(xhr) { try { var status = xhr.status; @@ -569,48 +3287,33 @@ function dew$3() { return false; } } - ClientRequest.prototype._onXHRProgress = function () { var self = this || _global$1; - self._resetTimers(false); - if (!statusValid(self._xhr) || self._destroyed) return; if (!self._response) self._connect(); - self._response._onXHRProgress(self._resetTimers.bind(self)); }; - ClientRequest.prototype._connect = function () { var self = this || _global$1; if (self._destroyed) return; self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self)); - self._response.on("error", function (err) { self.emit("error", err); }); - self.emit("response", self._response); }; - ClientRequest.prototype._write = function (chunk, encoding, cb) { var self = this || _global$1; - self._body.push(chunk); - cb(); }; - ClientRequest.prototype._resetTimers = function (done) { var self = this || _global$1; - _global$1.clearTimeout(self._socketTimer); - self._socketTimer = null; - if (done) { _global$1.clearTimeout(self._fetchTimer); - self._fetchTimer = null; } else if (self._socketTimeout) { self._socketTimer = _global$1.setTimeout(function () { @@ -618,77 +3321,61 @@ function dew$3() { }, self._socketTimeout); } }; - ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) { var self = this || _global$1; self._destroyed = true; - self._resetTimers(true); - if (self._response) self._response._destroyed = true; if (self._xhr) self._xhr.abort();else if (self._fetchAbortController) self._fetchAbortController.abort(); if (err) self.emit("error", err); }; - ClientRequest.prototype.end = function (data, encoding, cb) { var self = this || _global$1; - if (typeof data === "function") { cb = data; data = undefined; } - stream.Writable.prototype.end.call(self, data, encoding, cb); }; - ClientRequest.prototype.setTimeout = function (timeout, cb) { var self = this || _global$1; if (cb) self.once("timeout", cb); self._socketTimeout = timeout; - self._resetTimers(false); }; - ClientRequest.prototype.flushHeaders = function () {}; - ClientRequest.prototype.setNoDelay = function () {}; + ClientRequest.prototype.setSocketKeepAlive = function () {}; - ClientRequest.prototype.setSocketKeepAlive = function () {}; // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method - - + // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method var unsafeHeaders = ["accept-charset", "accept-encoding", "access-control-request-headers", "access-control-request-method", "connection", "content-length", "cookie", "cookie2", "date", "dnt", "expect", "host", "keep-alive", "origin", "referer", "te", "trailer", "transfer-encoding", "upgrade", "via"]; return exports$4; } var exports$3 = {}, - _dewExec$2 = false; + _dewExec$2 = false; function dew$2() { if (_dewExec$2) return exports$3; _dewExec$2 = true; exports$3 = extend; var hasOwnProperty = Object.prototype.hasOwnProperty; - function extend() { var target = {}; - for (var i = 0; i < arguments.length; i++) { var source = arguments[i]; - for (var key in source) { if (hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } - return target; } - return exports$3; } var exports$2 = {}, - _dewExec$1 = false; + _dewExec$1 = false; function dew$1() { if (_dewExec$1) return exports$2; _dewExec$1 = true; @@ -760,58 +3447,51 @@ function dew$1() { } var exports$1 = {}, - _dewExec = false; - + _dewExec = false; var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew() { if (_dewExec) return exports$1; _dewExec = true; - var ClientRequest = dew$3(); - var response = dew$4(); - var extend = dew$2(); - var statusCodes = dew$1(); - var url = h; var http = exports$1; - http.request = function (opts, cb) { - if (typeof opts === "string") opts = url.parse(opts);else opts = extend(opts); // Normally, the page is loaded from http or https, so not specifying a protocol + if (typeof opts === "string") opts = url.parse(opts);else opts = extend(opts); + + // Normally, the page is loaded from http or https, so not specifying a protocol // will result in a (valid) protocol-relative url. However, this won't work if // the protocol is something else, like 'file:' - var defaultProtocol = _global.location.protocol.search(/^https?:$/) === -1 ? "http:" : ""; var protocol = opts.protocol || defaultProtocol; var host = opts.hostname || opts.host; var port = opts.port; - var path = opts.path || "/"; // Necessary for IPv6 addresses + var path = opts.path || "/"; - if (host && host.indexOf(":") !== -1) host = "[" + host + "]"; // This may be a relative url. The browser should always be able to interpret it correctly. + // Necessary for IPv6 addresses + if (host && host.indexOf(":") !== -1) host = "[" + host + "]"; + // This may be a relative url. The browser should always be able to interpret it correctly. opts.url = (host ? protocol + "//" + host : "") + (port ? ":" + port : "") + path; opts.method = (opts.method || "GET").toUpperCase(); - opts.headers = opts.headers || {}; // Also valid opts.auth, opts.mode + opts.headers = opts.headers || {}; + + // Also valid opts.auth, opts.mode var req = new ClientRequest(opts); if (cb) req.on("response", cb); return req; }; - http.get = function get(opts, cb) { var req = http.request(opts, cb); req.end(); return req; }; - http.ClientRequest = ClientRequest; http.IncomingMessage = response.IncomingMessage; - http.Agent = function () {}; - http.Agent.defaultMaxSockets = 4; http.globalAgent = new http.Agent(); http.STATUS_CODES = statusCodes; diff --git a/nodelibs/browser/https.js b/nodelibs/browser/https.js index 969ad87..16b1e6a 100644 --- a/nodelibs/browser/https.js +++ b/nodelibs/browser/https.js @@ -1,59 +1,861 @@ -import exports$2 from './http.js'; -import h from './url.js'; -import './chunk-CU2hd6BF.js'; +import { b as buffer, d as dew$f } from './chunk-B738Er4n.js'; +import { d as dew$7 } from './chunk-C4rKjYLo.js'; +import { p as process } from './chunk-b0rmRow7.js'; +import { h } from './chunk-DHWh-hmB.js'; import './chunk-tHuMsdT0.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; -import './chunk-aBeyrThb.js'; -import './chunk-CKeAujU-.js'; -import './chunk-D5E0hY9V.js'; -import './chunk-DppJZDIM.js'; +import './chunk-D3uu3VYh.js'; -var exports$1 = {}, - _dewExec = false; +var exports$6 = {}, + _dewExec$5 = false; -var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +var _global$3 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$5() { + if (_dewExec$5) return exports$6; + _dewExec$5 = true; + exports$6.fetch = isFunction(_global$3.fetch) && isFunction(_global$3.ReadableStream); + exports$6.writableStream = isFunction(_global$3.WritableStream); + exports$6.abortController = isFunction(_global$3.AbortController); // The xhr request to example.com may violate some restrictive CSP configurations, + // so if we're running in a browser that supports `fetch`, avoid calling getXHR() + // and assume support for certain features below. + + var xhr; + + function getXHR() { + // Cache the xhr value + if (xhr !== undefined) return xhr; + + if (_global$3.XMLHttpRequest) { + xhr = new _global$3.XMLHttpRequest(); // If XDomainRequest is available (ie only, where xhr might not work + // cross domain), use the page location. Otherwise use example.com + // Note: this doesn't actually make an http request. + + try { + xhr.open("GET", _global$3.XDomainRequest ? "/" : "https://example.com"); + } catch (e) { + xhr = null; + } + } else { + // Service workers don't have XHR + xhr = null; + } + + return xhr; + } + + function checkTypeSupport(type) { + var xhr = getXHR(); + if (!xhr) return false; + + try { + xhr.responseType = type; + return xhr.responseType === type; + } catch (e) {} + + return false; + } // If fetch is supported, then arraybuffer will be supported too. Skip calling + // checkTypeSupport(), since that calls getXHR(). + + + exports$6.arraybuffer = exports$6.fetch || checkTypeSupport("arraybuffer"); // These next two tests unavoidably show warnings in Chrome. Since fetch will always + // be used if it's available, just return false for these to avoid the warnings. + + exports$6.msstream = !exports$6.fetch && checkTypeSupport("ms-stream"); + exports$6.mozchunkedarraybuffer = !exports$6.fetch && checkTypeSupport("moz-chunked-arraybuffer"); // If fetch is supported, then overrideMimeType will be supported too. Skip calling + // getXHR(). + + exports$6.overrideMimeType = exports$6.fetch || (getXHR() ? isFunction(getXHR().overrideMimeType) : false); + + function isFunction(value) { + return typeof value === "function"; + } + + xhr = null; // Help gc + + return exports$6; +} + +var exports$5 = {}, + _dewExec$4 = false; + +var _global$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$4() { + if (_dewExec$4) return exports$5; + _dewExec$4 = true; + var Buffer = buffer.Buffer; + var process$1 = process; + + var capability = dew$5(); + + var inherits = dew$f(); + + var stream = dew$7(); + + var rStates = exports$5.readyStates = { + UNSENT: 0, + OPENED: 1, + HEADERS_RECEIVED: 2, + LOADING: 3, + DONE: 4 + }; + + var IncomingMessage = exports$5.IncomingMessage = function (xhr, response, mode, resetTimers) { + var self = this || _global$2; + stream.Readable.call(self); + self._mode = mode; + self.headers = {}; + self.rawHeaders = []; + self.trailers = {}; + self.rawTrailers = []; // Fake the 'close' event, but only once 'end' fires + + self.on("end", function () { + // The nextTick is necessary to prevent the 'request' module from causing an infinite loop + process$1.nextTick(function () { + self.emit("close"); + }); + }); + + if (mode === "fetch") { + self._fetchResponse = response; + self.url = response.url; + self.statusCode = response.status; + self.statusMessage = response.statusText; + response.headers.forEach(function (header, key) { + self.headers[key.toLowerCase()] = header; + self.rawHeaders.push(key, header); + }); + + if (capability.writableStream) { + var writable = new WritableStream({ + write: function (chunk) { + resetTimers(false); + return new Promise(function (resolve, reject) { + if (self._destroyed) { + reject(); + } else if (self.push(Buffer.from(chunk))) { + resolve(); + } else { + self._resumeFetch = resolve; + } + }); + }, + close: function () { + resetTimers(true); + if (!self._destroyed) self.push(null); + }, + abort: function (err) { + resetTimers(true); + if (!self._destroyed) self.emit("error", err); + } + }); + + try { + response.body.pipeTo(writable).catch(function (err) { + resetTimers(true); + if (!self._destroyed) self.emit("error", err); + }); + return; + } catch (e) {} // pipeTo method isn't defined. Can't find a better way to feature test this + + } // fallback for when writableStream or pipeTo aren't available + + + var reader = response.body.getReader(); + + function read() { + reader.read().then(function (result) { + if (self._destroyed) return; + resetTimers(result.done); + + if (result.done) { + self.push(null); + return; + } + + self.push(Buffer.from(result.value)); + read(); + }).catch(function (err) { + resetTimers(true); + if (!self._destroyed) self.emit("error", err); + }); + } + + read(); + } else { + self._xhr = xhr; + self._pos = 0; + self.url = xhr.responseURL; + self.statusCode = xhr.status; + self.statusMessage = xhr.statusText; + var headers = xhr.getAllResponseHeaders().split(/\r?\n/); + headers.forEach(function (header) { + var matches = header.match(/^([^:]+):\s*(.*)/); + + if (matches) { + var key = matches[1].toLowerCase(); + + if (key === "set-cookie") { + if (self.headers[key] === undefined) { + self.headers[key] = []; + } + + self.headers[key].push(matches[2]); + } else if (self.headers[key] !== undefined) { + self.headers[key] += ", " + matches[2]; + } else { + self.headers[key] = matches[2]; + } + + self.rawHeaders.push(matches[1], matches[2]); + } + }); + self._charset = "x-user-defined"; + + if (!capability.overrideMimeType) { + var mimeType = self.rawHeaders["mime-type"]; + + if (mimeType) { + var charsetMatch = mimeType.match(/;\s*charset=([^;])(;|$)/); + + if (charsetMatch) { + self._charset = charsetMatch[1].toLowerCase(); + } + } + + if (!self._charset) self._charset = "utf-8"; // best guess + } + } + }; + + inherits(IncomingMessage, stream.Readable); + + IncomingMessage.prototype._read = function () { + var self = this || _global$2; + var resolve = self._resumeFetch; + + if (resolve) { + self._resumeFetch = null; + resolve(); + } + }; + + IncomingMessage.prototype._onXHRProgress = function (resetTimers) { + var self = this || _global$2; + var xhr = self._xhr; + var response = null; + + switch (self._mode) { + case "text": + response = xhr.responseText; + + if (response.length > self._pos) { + var newData = response.substr(self._pos); + + if (self._charset === "x-user-defined") { + var buffer = Buffer.alloc(newData.length); + + for (var i = 0; i < newData.length; i++) buffer[i] = newData.charCodeAt(i) & 255; + + self.push(buffer); + } else { + self.push(newData, self._charset); + } + + self._pos = response.length; + } + + break; + + case "arraybuffer": + if (xhr.readyState !== rStates.DONE || !xhr.response) break; + response = xhr.response; + self.push(Buffer.from(new Uint8Array(response))); + break; + + case "moz-chunked-arraybuffer": + // take whole + response = xhr.response; + if (xhr.readyState !== rStates.LOADING || !response) break; + self.push(Buffer.from(new Uint8Array(response))); + break; + + case "ms-stream": + response = xhr.response; + if (xhr.readyState !== rStates.LOADING) break; + var reader = new _global$2.MSStreamReader(); + + reader.onprogress = function () { + if (reader.result.byteLength > self._pos) { + self.push(Buffer.from(new Uint8Array(reader.result.slice(self._pos)))); + self._pos = reader.result.byteLength; + } + }; + + reader.onload = function () { + resetTimers(true); + self.push(null); + }; // reader.onerror = ??? // TODO: this + + + reader.readAsArrayBuffer(response); + break; + } // The ms-stream case handles end separately in reader.onload() + + + if (self._xhr.readyState === rStates.DONE && self._mode !== "ms-stream") { + resetTimers(true); + self.push(null); + } + }; + + return exports$5; +} + +var exports$4 = {}, + _dewExec$3 = false; + +var _global$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$3() { + if (_dewExec$3) return exports$4; + _dewExec$3 = true; + var Buffer = buffer.Buffer; + var process$1 = process; + + var capability = dew$5(); + + var inherits = dew$f(); + + var response = dew$4(); + + var stream = dew$7(); + + var IncomingMessage = response.IncomingMessage; + var rStates = response.readyStates; + + function decideMode(preferBinary, useFetch) { + if (capability.fetch && useFetch) { + return "fetch"; + } else if (capability.mozchunkedarraybuffer) { + return "moz-chunked-arraybuffer"; + } else if (capability.msstream) { + return "ms-stream"; + } else if (capability.arraybuffer && preferBinary) { + return "arraybuffer"; + } else { + return "text"; + } + } + + var ClientRequest = exports$4 = function (opts) { + var self = this || _global$1; + stream.Writable.call(self); + self._opts = opts; + self._body = []; + self._headers = {}; + if (opts.auth) self.setHeader("Authorization", "Basic " + Buffer.from(opts.auth).toString("base64")); + Object.keys(opts.headers).forEach(function (name) { + self.setHeader(name, opts.headers[name]); + }); + var preferBinary; + var useFetch = true; + + if (opts.mode === "disable-fetch" || "requestTimeout" in opts && !capability.abortController) { + // If the use of XHR should be preferred. Not typically needed. + useFetch = false; + preferBinary = true; + } else if (opts.mode === "prefer-streaming") { + // If streaming is a high priority but binary compatibility and + // the accuracy of the 'content-type' header aren't + preferBinary = false; + } else if (opts.mode === "allow-wrong-content-type") { + // If streaming is more important than preserving the 'content-type' header + preferBinary = !capability.overrideMimeType; + } else if (!opts.mode || opts.mode === "default" || opts.mode === "prefer-fast") { + // Use binary if text streaming may corrupt data or the content-type header, or for speed + preferBinary = true; + } else { + throw new Error("Invalid value for opts.mode"); + } + + self._mode = decideMode(preferBinary, useFetch); + self._fetchTimer = null; + self._socketTimeout = null; + self._socketTimer = null; + self.on("finish", function () { + self._onFinish(); + }); + }; + + inherits(ClientRequest, stream.Writable); + + ClientRequest.prototype.setHeader = function (name, value) { + var self = this || _global$1; + var lowerName = name.toLowerCase(); // This check is not necessary, but it prevents warnings from browsers about setting unsafe + // headers. To be honest I'm not entirely sure hiding these warnings is a good thing, but + // http-browserify did it, so I will too. + + if (unsafeHeaders.indexOf(lowerName) !== -1) return; + self._headers[lowerName] = { + name: name, + value: value + }; + }; + + ClientRequest.prototype.getHeader = function (name) { + var header = (this || _global$1)._headers[name.toLowerCase()]; + + if (header) return header.value; + return null; + }; + + ClientRequest.prototype.removeHeader = function (name) { + var self = this || _global$1; + delete self._headers[name.toLowerCase()]; + }; + + ClientRequest.prototype._onFinish = function () { + var self = this || _global$1; + if (self._destroyed) return; + var opts = self._opts; + + if ("timeout" in opts && opts.timeout !== 0) { + self.setTimeout(opts.timeout); + } + + var headersObj = self._headers; + var body = null; + + if (opts.method !== "GET" && opts.method !== "HEAD") { + body = new Blob(self._body, { + type: (headersObj["content-type"] || {}).value || "" + }); + } // create flattened list of headers + + + var headersList = []; + Object.keys(headersObj).forEach(function (keyName) { + var name = headersObj[keyName].name; + var value = headersObj[keyName].value; + + if (Array.isArray(value)) { + value.forEach(function (v) { + headersList.push([name, v]); + }); + } else { + headersList.push([name, value]); + } + }); + if (self._mode === "fetch") { + var signal = null; + + if (capability.abortController) { + var controller = new AbortController(); + signal = controller.signal; + self._fetchAbortController = controller; + + if ("requestTimeout" in opts && opts.requestTimeout !== 0) { + self._fetchTimer = _global$1.setTimeout(function () { + self.emit("requestTimeout"); + if (self._fetchAbortController) self._fetchAbortController.abort(); + }, opts.requestTimeout); + } + } + + _global$1.fetch(self._opts.url, { + method: self._opts.method, + headers: headersList, + body: body || undefined, + mode: "cors", + credentials: opts.withCredentials ? "include" : "same-origin", + signal: signal + }).then(function (response) { + self._fetchResponse = response; + + self._resetTimers(false); + + self._connect(); + }, function (reason) { + self._resetTimers(true); + + if (!self._destroyed) self.emit("error", reason); + }); + } else { + var xhr = self._xhr = new _global$1.XMLHttpRequest(); + + try { + xhr.open(self._opts.method, self._opts.url, true); + } catch (err) { + process$1.nextTick(function () { + self.emit("error", err); + }); + return; + } // Can't set responseType on really old browsers + + + if ("responseType" in xhr) xhr.responseType = self._mode; + if ("withCredentials" in xhr) xhr.withCredentials = !!opts.withCredentials; + if (self._mode === "text" && "overrideMimeType" in xhr) xhr.overrideMimeType("text/plain; charset=x-user-defined"); + + if ("requestTimeout" in opts) { + xhr.timeout = opts.requestTimeout; + + xhr.ontimeout = function () { + self.emit("requestTimeout"); + }; + } + + headersList.forEach(function (header) { + xhr.setRequestHeader(header[0], header[1]); + }); + self._response = null; + + xhr.onreadystatechange = function () { + switch (xhr.readyState) { + case rStates.LOADING: + case rStates.DONE: + self._onXHRProgress(); + + break; + } + }; // Necessary for streaming in Firefox, since xhr.response is ONLY defined + // in onprogress, not in onreadystatechange with xhr.readyState = 3 + + + if (self._mode === "moz-chunked-arraybuffer") { + xhr.onprogress = function () { + self._onXHRProgress(); + }; + } + + xhr.onerror = function () { + if (self._destroyed) return; + + self._resetTimers(true); + + self.emit("error", new Error("XHR error")); + }; + + try { + xhr.send(body); + } catch (err) { + process$1.nextTick(function () { + self.emit("error", err); + }); + return; + } + } + }; + /** + * Checks if xhr.status is readable and non-zero, indicating no error. + * Even though the spec says it should be available in readyState 3, + * accessing it throws an exception in IE8 + */ + + + function statusValid(xhr) { + try { + var status = xhr.status; + return status !== null && status !== 0; + } catch (e) { + return false; + } + } + + ClientRequest.prototype._onXHRProgress = function () { + var self = this || _global$1; + + self._resetTimers(false); + + if (!statusValid(self._xhr) || self._destroyed) return; + if (!self._response) self._connect(); + + self._response._onXHRProgress(self._resetTimers.bind(self)); + }; + + ClientRequest.prototype._connect = function () { + var self = this || _global$1; + if (self._destroyed) return; + self._response = new IncomingMessage(self._xhr, self._fetchResponse, self._mode, self._resetTimers.bind(self)); + + self._response.on("error", function (err) { + self.emit("error", err); + }); + + self.emit("response", self._response); + }; + + ClientRequest.prototype._write = function (chunk, encoding, cb) { + var self = this || _global$1; + + self._body.push(chunk); + + cb(); + }; + + ClientRequest.prototype._resetTimers = function (done) { + var self = this || _global$1; + + _global$1.clearTimeout(self._socketTimer); + + self._socketTimer = null; + + if (done) { + _global$1.clearTimeout(self._fetchTimer); + + self._fetchTimer = null; + } else if (self._socketTimeout) { + self._socketTimer = _global$1.setTimeout(function () { + self.emit("timeout"); + }, self._socketTimeout); + } + }; + + ClientRequest.prototype.abort = ClientRequest.prototype.destroy = function (err) { + var self = this || _global$1; + self._destroyed = true; + + self._resetTimers(true); + + if (self._response) self._response._destroyed = true; + if (self._xhr) self._xhr.abort();else if (self._fetchAbortController) self._fetchAbortController.abort(); + if (err) self.emit("error", err); + }; + + ClientRequest.prototype.end = function (data, encoding, cb) { + var self = this || _global$1; + + if (typeof data === "function") { + cb = data; + data = undefined; + } + + stream.Writable.prototype.end.call(self, data, encoding, cb); + }; + + ClientRequest.prototype.setTimeout = function (timeout, cb) { + var self = this || _global$1; + if (cb) self.once("timeout", cb); + self._socketTimeout = timeout; + + self._resetTimers(false); + }; + + ClientRequest.prototype.flushHeaders = function () {}; + + ClientRequest.prototype.setNoDelay = function () {}; + + ClientRequest.prototype.setSocketKeepAlive = function () {}; // Taken from http://www.w3.org/TR/XMLHttpRequest/#the-setrequestheader%28%29-method + + + var unsafeHeaders = ["accept-charset", "accept-encoding", "access-control-request-headers", "access-control-request-method", "connection", "content-length", "cookie", "cookie2", "date", "dnt", "expect", "host", "keep-alive", "origin", "referer", "te", "trailer", "transfer-encoding", "upgrade", "via"]; + return exports$4; +} + +var exports$3 = {}, + _dewExec$2 = false; +function dew$2() { + if (_dewExec$2) return exports$3; + _dewExec$2 = true; + exports$3 = extend; + var hasOwnProperty = Object.prototype.hasOwnProperty; + + function extend() { + var target = {}; + + for (var i = 0; i < arguments.length; i++) { + var source = arguments[i]; + + for (var key in source) { + if (hasOwnProperty.call(source, key)) { + target[key] = source[key]; + } + } + } + + return target; + } + + return exports$3; +} + +var exports$2 = {}, + _dewExec$1 = false; +function dew$1() { + if (_dewExec$1) return exports$2; + _dewExec$1 = true; + exports$2 = { + "100": "Continue", + "101": "Switching Protocols", + "102": "Processing", + "200": "OK", + "201": "Created", + "202": "Accepted", + "203": "Non-Authoritative Information", + "204": "No Content", + "205": "Reset Content", + "206": "Partial Content", + "207": "Multi-Status", + "208": "Already Reported", + "226": "IM Used", + "300": "Multiple Choices", + "301": "Moved Permanently", + "302": "Found", + "303": "See Other", + "304": "Not Modified", + "305": "Use Proxy", + "307": "Temporary Redirect", + "308": "Permanent Redirect", + "400": "Bad Request", + "401": "Unauthorized", + "402": "Payment Required", + "403": "Forbidden", + "404": "Not Found", + "405": "Method Not Allowed", + "406": "Not Acceptable", + "407": "Proxy Authentication Required", + "408": "Request Timeout", + "409": "Conflict", + "410": "Gone", + "411": "Length Required", + "412": "Precondition Failed", + "413": "Payload Too Large", + "414": "URI Too Long", + "415": "Unsupported Media Type", + "416": "Range Not Satisfiable", + "417": "Expectation Failed", + "418": "I'm a teapot", + "421": "Misdirected Request", + "422": "Unprocessable Entity", + "423": "Locked", + "424": "Failed Dependency", + "425": "Unordered Collection", + "426": "Upgrade Required", + "428": "Precondition Required", + "429": "Too Many Requests", + "431": "Request Header Fields Too Large", + "451": "Unavailable For Legal Reasons", + "500": "Internal Server Error", + "501": "Not Implemented", + "502": "Bad Gateway", + "503": "Service Unavailable", + "504": "Gateway Timeout", + "505": "HTTP Version Not Supported", + "506": "Variant Also Negotiates", + "507": "Insufficient Storage", + "508": "Loop Detected", + "509": "Bandwidth Limit Exceeded", + "510": "Not Extended", + "511": "Network Authentication Required" + }; + return exports$2; +} + +var exports$1$1 = {}, + _dewExec$6 = false; + +var _global$4 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; + +function dew$6() { + if (_dewExec$6) return exports$1$1; + _dewExec$6 = true; + + var ClientRequest = dew$3(); + + var response = dew$4(); + + var extend = dew$2(); + + var statusCodes = dew$1(); + + var url = h; + var http = exports$1$1; + + http.request = function (opts, cb) { + if (typeof opts === "string") opts = url.parse(opts);else opts = extend(opts); // Normally, the page is loaded from http or https, so not specifying a protocol + // will result in a (valid) protocol-relative url. However, this won't work if + // the protocol is something else, like 'file:' + + var defaultProtocol = _global$4.location.protocol.search(/^https?:$/) === -1 ? "http:" : ""; + var protocol = opts.protocol || defaultProtocol; + var host = opts.hostname || opts.host; + var port = opts.port; + var path = opts.path || "/"; // Necessary for IPv6 addresses + + if (host && host.indexOf(":") !== -1) host = "[" + host + "]"; // This may be a relative url. The browser should always be able to interpret it correctly. + + opts.url = (host ? protocol + "//" + host : "") + (port ? ":" + port : "") + path; + opts.method = (opts.method || "GET").toUpperCase(); + opts.headers = opts.headers || {}; // Also valid opts.auth, opts.mode + + var req = new ClientRequest(opts); + if (cb) req.on("response", cb); + return req; + }; + + http.get = function get(opts, cb) { + var req = http.request(opts, cb); + req.end(); + return req; + }; + + http.ClientRequest = ClientRequest; + http.IncomingMessage = response.IncomingMessage; + + http.Agent = function () {}; + + http.Agent.defaultMaxSockets = 4; + http.globalAgent = new http.Agent(); + http.STATUS_CODES = statusCodes; + http.METHODS = ["CHECKOUT", "CONNECT", "COPY", "DELETE", "GET", "HEAD", "LOCK", "M-SEARCH", "MERGE", "MKACTIVITY", "MKCOL", "MOVE", "NOTIFY", "OPTIONS", "PATCH", "POST", "PROPFIND", "PROPPATCH", "PURGE", "PUT", "REPORT", "SEARCH", "SUBSCRIBE", "TRACE", "UNLOCK", "UNSUBSCRIBE"]; + return exports$1$1; +} + +const exports$7 = dew$6(); + +exports$7.Agent; +exports$7.ClientRequest; +exports$7.IncomingMessage; +exports$7.METHODS; +exports$7.STATUS_CODES; +exports$7.get; +exports$7.globalAgent; +exports$7.request; + +var exports$1 = {}, + _dewExec = false; +var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; function dew() { if (_dewExec) return exports$1; _dewExec = true; - var http = exports$2; + var http = exports$7; var url = h; var https = exports$1; - for (var key in http) { if (http.hasOwnProperty(key)) https[key] = http[key]; } - https.request = function (params, cb) { params = validateParams(params); return http.request.call(this || _global, params, cb); }; - https.get = function (params, cb) { params = validateParams(params); return http.get.call(this || _global, params, cb); }; - function validateParams(params) { if (typeof params === "string") { params = url.parse(params); } - if (!params.protocol) { params.protocol = "https:"; } - if (params.protocol !== "https:") { throw new Error("Protocol \"" + params.protocol + "\" not supported. Expected \"https:\""); } - return params; } - return exports$1; } diff --git a/nodelibs/browser/os.js b/nodelibs/browser/os.js index a671867..6864350 100644 --- a/nodelibs/browser/os.js +++ b/nodelibs/browser/os.js @@ -1,75 +1,58 @@ import { uptime } from './process.js'; var exports$1 = {}, - _dewExec = false; + _dewExec = false; function dew() { if (_dewExec) return exports$1; _dewExec = true; - exports$1.endianness = function () { return "LE"; }; - exports$1.hostname = function () { if (typeof location !== "undefined") { return location.hostname; } else return ""; }; - exports$1.loadavg = function () { return []; }; - exports$1.uptime = function () { return 0; }; - exports$1.freemem = function () { return Number.MAX_VALUE; }; - exports$1.totalmem = function () { return Number.MAX_VALUE; }; - exports$1.cpus = function () { return []; }; - exports$1.type = function () { return "Browser"; }; - exports$1.release = function () { if (typeof navigator !== "undefined") { return navigator.appVersion; } - return ""; }; - exports$1.networkInterfaces = exports$1.getNetworkInterfaces = function () { return {}; }; - exports$1.arch = function () { return "javascript"; }; - exports$1.platform = function () { return "browser"; }; - exports$1.tmpdir = exports$1.tmpDir = function () { return "/tmp"; }; - exports$1.EOL = "\n"; - exports$1.homedir = function () { return "/"; }; - return exports$1; } diff --git a/nodelibs/browser/path.js b/nodelibs/browser/path.js index 700a6fa..53ed944 100644 --- a/nodelibs/browser/path.js +++ b/nodelibs/browser/path.js @@ -1,5 +1,5 @@ -import { e as exports } from './chunk-DppJZDIM.js'; -import './chunk-b0rmRow7.js'; +import { e as exports } from './chunk-BlJi4mNy.js'; +import './chunk-DEMDiNwt.js'; var _makeLong = exports._makeLong; var basename = exports.basename; diff --git a/nodelibs/browser/path/posix.js b/nodelibs/browser/path/posix.js index 86bbf0f..27ba7d5 100644 --- a/nodelibs/browser/path/posix.js +++ b/nodelibs/browser/path/posix.js @@ -1,6 +1,6 @@ import { posix as posix$1 } from '../path.js'; -import '../chunk-DppJZDIM.js'; -import '../chunk-b0rmRow7.js'; +import '../chunk-BlJi4mNy.js'; +import '../chunk-DEMDiNwt.js'; const { resolve, diff --git a/nodelibs/browser/path/win32.js b/nodelibs/browser/path/win32.js index bf5024a..b333e8a 100644 --- a/nodelibs/browser/path/win32.js +++ b/nodelibs/browser/path/win32.js @@ -1,6 +1,6 @@ import { posix } from '../path.js'; -import '../chunk-DppJZDIM.js'; -import '../chunk-b0rmRow7.js'; +import '../chunk-BlJi4mNy.js'; +import '../chunk-DEMDiNwt.js'; function unimplemented () { throw new Error('Node.js path/win32 module is not supported by JSPM core in the browser'); diff --git a/nodelibs/browser/process-production.js b/nodelibs/browser/process-production.js index db29b10..022d949 100644 --- a/nodelibs/browser/process-production.js +++ b/nodelibs/browser/process-production.js @@ -94,6 +94,7 @@ var release = { function noop() {} +var browser = true; var _rawDebug = noop; var moduleLoadList = []; var _linkedBinding = null; @@ -202,6 +203,7 @@ var process = { versions, arch, platform, + browser, release, _rawDebug, moduleLoadList, @@ -269,4 +271,4 @@ var process = { setSourceMapsEnabled, }; -export { _debugEnd, _debugProcess, _events, _eventsCount, _exiting, _fatalExceptions, _getActiveHandles, _getActiveRequests, _kill, _linkedBinding, _maxListeners, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, binding, chdir, config, cpuUsage, cwd, debugPort, process as default, dlopen, domain, emit, emitWarning, env, execArgv, execPath, exit, features, hasUncaughtExceptionCaptureCallback, hrtime, kill, listeners, memoryUsage, moduleLoadList, nextTick, off, on, once, openStdin, pid, platform, ppid, prependListener, prependOnceListener, reallyExit, release, removeAllListeners, removeListener, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, stderr, stdin, stdout, title, umask, uptime, version, versions }; +export { _debugEnd, _debugProcess, _events, _eventsCount, _exiting, _fatalExceptions, _getActiveHandles, _getActiveRequests, _kill, _linkedBinding, _maxListeners, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, binding, browser, chdir, config, cpuUsage, cwd, debugPort, process as default, dlopen, domain, emit, emitWarning, env, execArgv, execPath, exit, features, hasUncaughtExceptionCaptureCallback, hrtime, kill, listeners, memoryUsage, moduleLoadList, nextTick, off, on, once, openStdin, pid, platform, ppid, prependListener, prependOnceListener, reallyExit, release, removeAllListeners, removeListener, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, stderr, stdin, stdout, title, umask, uptime, version, versions }; diff --git a/nodelibs/browser/process.js b/nodelibs/browser/process.js index 156d403..7ed971f 100644 --- a/nodelibs/browser/process.js +++ b/nodelibs/browser/process.js @@ -97,6 +97,7 @@ var release = { function noop() {} +var browser = true; var _rawDebug = noop; var moduleLoadList = []; function _linkedBinding(name) { unimplemented('_linkedBinding'); } @@ -205,6 +206,7 @@ var process = { versions, arch, platform, + browser, release, _rawDebug, moduleLoadList, @@ -272,4 +274,4 @@ var process = { setSourceMapsEnabled, }; -export { _debugEnd, _debugProcess, _events, _eventsCount, _exiting, _fatalExceptions, _getActiveHandles, _getActiveRequests, _kill, _linkedBinding, _maxListeners, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, binding, chdir, config, cpuUsage, cwd, debugPort, process as default, dlopen, domain, emit, emitWarning, env, execArgv, execPath, exit, features, hasUncaughtExceptionCaptureCallback, hrtime, kill, listeners, memoryUsage, moduleLoadList, nextTick, off, on, once, openStdin, pid, platform, ppid, prependListener, prependOnceListener, reallyExit, release, removeAllListeners, removeListener, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, stderr, stdin, stdout, title, umask, uptime, version, versions }; +export { _debugEnd, _debugProcess, _events, _eventsCount, _exiting, _fatalExceptions, _getActiveHandles, _getActiveRequests, _kill, _linkedBinding, _maxListeners, _preload_modules, _rawDebug, _startProfilerIdleNotifier, _stopProfilerIdleNotifier, _tickCallback, abort, addListener, allowedNodeEnvironmentFlags, arch, argv, argv0, assert, binding, browser, chdir, config, cpuUsage, cwd, debugPort, process as default, dlopen, domain, emit, emitWarning, env, execArgv, execPath, exit, features, hasUncaughtExceptionCaptureCallback, hrtime, kill, listeners, memoryUsage, moduleLoadList, nextTick, off, on, once, openStdin, pid, platform, ppid, prependListener, prependOnceListener, reallyExit, release, removeAllListeners, removeListener, resourceUsage, setSourceMapsEnabled, setUncaughtExceptionCaptureCallback, stderr, stdin, stdout, title, umask, uptime, version, versions }; diff --git a/nodelibs/browser/punycode.js b/nodelibs/browser/punycode.js index 39f0dd4..42ae3e7 100644 --- a/nodelibs/browser/punycode.js +++ b/nodelibs/browser/punycode.js @@ -1,17 +1,436 @@ -import { p } from './chunk-CKeAujU-.js'; - -p.decode; -p.encode; -p.toASCII; -p.toUnicode; -p.ucs2; -p.version; - -var decode = p.decode; -var encode = p.encode; -var toASCII = p.toASCII; -var toUnicode = p.toUnicode; -var ucs2 = p.ucs2; -var version = p.version; - -export { decode, p as default, encode, toASCII, toUnicode, ucs2, version }; +var exports$1 = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports$1; + _dewExec = true; + /** Highest positive signed 32-bit float value */ + const maxInt = 2147483647; // aka. 0x7FFFFFFF or 2^31-1 + + /** Bootstring parameters */ + const base = 36; + const tMin = 1; + const tMax = 26; + const skew = 38; + const damp = 700; + const initialBias = 72; + const initialN = 128; // 0x80 + const delimiter = "-"; // '\x2D' + + /** Regular expressions */ + const regexPunycode = /^xn--/; + const regexNonASCII = /[^\0-\x7F]/; // Note: U+007F DEL is excluded too. + const regexSeparators = /[\x2E\u3002\uFF0E\uFF61]/g; // RFC 3490 separators + + /** Error messages */ + const errors = { + "overflow": "Overflow: input needs wider integers to process", + "not-basic": "Illegal input >= 0x80 (not a basic code point)", + "invalid-input": "Invalid input" + }; + + /** Convenience shortcuts */ + const baseMinusTMin = base - tMin; + const floor = Math.floor; + const stringFromCharCode = String.fromCharCode; + + /*--------------------------------------------------------------------------*/ + + /** + * A generic error utility function. + * @private + * @param {String} type The error type. + * @returns {Error} Throws a `RangeError` with the applicable error message. + */ + function error(type) { + throw new RangeError(errors[type]); + } + + /** + * A generic `Array#map` utility function. + * @private + * @param {Array} array The array to iterate over. + * @param {Function} callback The function that gets called for every array + * item. + * @returns {Array} A new array of values returned by the callback function. + */ + function map(array, callback) { + const result = []; + let length = array.length; + while (length--) { + result[length] = callback(array[length]); + } + return result; + } + + /** + * A simple `Array#map`-like wrapper to work with domain name strings or email + * addresses. + * @private + * @param {String} domain The domain name or email address. + * @param {Function} callback The function that gets called for every + * character. + * @returns {String} A new string of characters returned by the callback + * function. + */ + function mapDomain(domain, callback) { + const parts = domain.split("@"); + let result = ""; + if (parts.length > 1) { + // In email addresses, only the domain name should be punycoded. Leave + // the local part (i.e. everything up to `@`) intact. + result = parts[0] + "@"; + domain = parts[1]; + } + // Avoid `split(regex)` for IE8 compatibility. See #17. + domain = domain.replace(regexSeparators, "."); + const labels = domain.split("."); + const encoded = map(labels, callback).join("."); + return result + encoded; + } + + /** + * Creates an array containing the numeric code points of each Unicode + * character in the string. While JavaScript uses UCS-2 internally, + * this function will convert a pair of surrogate halves (each of which + * UCS-2 exposes as separate characters) into a single code point, + * matching UTF-16. + * @see `punycode.ucs2.encode` + * @see + * @memberOf punycode.ucs2 + * @name decode + * @param {String} string The Unicode input string (UCS-2). + * @returns {Array} The new array of code points. + */ + function ucs2decode(string) { + const output = []; + let counter = 0; + const length = string.length; + while (counter < length) { + const value = string.charCodeAt(counter++); + if (value >= 55296 && value <= 56319 && counter < length) { + // It's a high surrogate, and there is a next character. + const extra = string.charCodeAt(counter++); + if ((extra & 64512) == 56320) { + // Low surrogate. + output.push(((value & 1023) << 10) + (extra & 1023) + 65536); + } else { + // It's an unmatched surrogate; only append this code unit, in case the + // next code unit is the high surrogate of a surrogate pair. + output.push(value); + counter--; + } + } else { + output.push(value); + } + } + return output; + } + + /** + * Creates a string based on an array of numeric code points. + * @see `punycode.ucs2.decode` + * @memberOf punycode.ucs2 + * @name encode + * @param {Array} codePoints The array of numeric code points. + * @returns {String} The new Unicode string (UCS-2). + */ + const ucs2encode = codePoints => String.fromCodePoint(...codePoints); + + /** + * Converts a basic code point into a digit/integer. + * @see `digitToBasic()` + * @private + * @param {Number} codePoint The basic numeric code point value. + * @returns {Number} The numeric value of a basic code point (for use in + * representing integers) in the range `0` to `base - 1`, or `base` if + * the code point does not represent a value. + */ + const basicToDigit = function (codePoint) { + if (codePoint >= 48 && codePoint < 58) { + return 26 + (codePoint - 48); + } + if (codePoint >= 65 && codePoint < 91) { + return codePoint - 65; + } + if (codePoint >= 97 && codePoint < 123) { + return codePoint - 97; + } + return base; + }; + + /** + * Converts a digit/integer into a basic code point. + * @see `basicToDigit()` + * @private + * @param {Number} digit The numeric value of a basic code point. + * @returns {Number} The basic code point whose value (when used for + * representing integers) is `digit`, which needs to be in the range + * `0` to `base - 1`. If `flag` is non-zero, the uppercase form is + * used; else, the lowercase form is used. The behavior is undefined + * if `flag` is non-zero and `digit` has no uppercase form. + */ + const digitToBasic = function (digit, flag) { + // 0..25 map to ASCII a..z or A..Z + // 26..35 map to ASCII 0..9 + return digit + 22 + 75 * (digit < 26) - ((flag != 0) << 5); + }; + + /** + * Bias adaptation function as per section 3.4 of RFC 3492. + * https://tools.ietf.org/html/rfc3492#section-3.4 + * @private + */ + const adapt = function (delta, numPoints, firstTime) { + let k = 0; + delta = firstTime ? floor(delta / damp) : delta >> 1; + delta += floor(delta / numPoints); + for /* no initialization */ + (; delta > baseMinusTMin * tMax >> 1; k += base) { + delta = floor(delta / baseMinusTMin); + } + return floor(k + (baseMinusTMin + 1) * delta / (delta + skew)); + }; + + /** + * Converts a Punycode string of ASCII-only symbols to a string of Unicode + * symbols. + * @memberOf punycode + * @param {String} input The Punycode string of ASCII-only symbols. + * @returns {String} The resulting string of Unicode symbols. + */ + const decode = function (input) { + // Don't use UCS-2. + const output = []; + const inputLength = input.length; + let i = 0; + let n = initialN; + let bias = initialBias; + + // Handle the basic code points: let `basic` be the number of input code + // points before the last delimiter, or `0` if there is none, then copy + // the first basic code points to the output. + + let basic = input.lastIndexOf(delimiter); + if (basic < 0) { + basic = 0; + } + for (let j = 0; j < basic; ++j) { + // if it's not a basic code point + if (input.charCodeAt(j) >= 128) { + error("not-basic"); + } + output.push(input.charCodeAt(j)); + } + + // Main decoding loop: start just after the last delimiter if any basic code + // points were copied; start at the beginning otherwise. + + for /* no final expression */ + (let index = basic > 0 ? basic + 1 : 0; index < inputLength;) { + // `index` is the index of the next character to be consumed. + // Decode a generalized variable-length integer into `delta`, + // which gets added to `i`. The overflow checking is easier + // if we increase `i` as we go, then subtract off its starting + // value at the end to obtain `delta`. + const oldi = i; + for /* no condition */ + (let w = 1, k = base;; k += base) { + if (index >= inputLength) { + error("invalid-input"); + } + const digit = basicToDigit(input.charCodeAt(index++)); + if (digit >= base) { + error("invalid-input"); + } + if (digit > floor((maxInt - i) / w)) { + error("overflow"); + } + i += digit * w; + const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; + if (digit < t) { + break; + } + const baseMinusT = base - t; + if (w > floor(maxInt / baseMinusT)) { + error("overflow"); + } + w *= baseMinusT; + } + const out = output.length + 1; + bias = adapt(i - oldi, out, oldi == 0); + + // `i` was supposed to wrap around from `out` to `0`, + // incrementing `n` each time, so we'll fix that now: + if (floor(i / out) > maxInt - n) { + error("overflow"); + } + n += floor(i / out); + i %= out; + + // Insert `n` at position `i` of the output. + output.splice(i++, 0, n); + } + return String.fromCodePoint(...output); + }; + + /** + * Converts a string of Unicode symbols (e.g. a domain name label) to a + * Punycode string of ASCII-only symbols. + * @memberOf punycode + * @param {String} input The string of Unicode symbols. + * @returns {String} The resulting Punycode string of ASCII-only symbols. + */ + const encode = function (input) { + const output = []; + + // Convert the input in UCS-2 to an array of Unicode code points. + input = ucs2decode(input); + + // Cache the length. + const inputLength = input.length; + + // Initialize the state. + let n = initialN; + let delta = 0; + let bias = initialBias; + + // Handle the basic code points. + for (const currentValue of input) { + if (currentValue < 128) { + output.push(stringFromCharCode(currentValue)); + } + } + const basicLength = output.length; + let handledCPCount = basicLength; + + // `handledCPCount` is the number of code points that have been handled; + // `basicLength` is the number of basic code points. + + // Finish the basic string with a delimiter unless it's empty. + if (basicLength) { + output.push(delimiter); + } + + // Main encoding loop: + while (handledCPCount < inputLength) { + // All non-basic code points < n have been handled already. Find the next + // larger one: + let m = maxInt; + for (const currentValue of input) { + if (currentValue >= n && currentValue < m) { + m = currentValue; + } + } + + // Increase `delta` enough to advance the decoder's state to , + // but guard against overflow. + const handledCPCountPlusOne = handledCPCount + 1; + if (m - n > floor((maxInt - delta) / handledCPCountPlusOne)) { + error("overflow"); + } + delta += (m - n) * handledCPCountPlusOne; + n = m; + for (const currentValue of input) { + if (currentValue < n && ++delta > maxInt) { + error("overflow"); + } + if (currentValue === n) { + // Represent delta as a generalized variable-length integer. + let q = delta; + for /* no condition */ + (let k = base;; k += base) { + const t = k <= bias ? tMin : k >= bias + tMax ? tMax : k - bias; + if (q < t) { + break; + } + const qMinusT = q - t; + const baseMinusT = base - t; + output.push(stringFromCharCode(digitToBasic(t + qMinusT % baseMinusT, 0))); + q = floor(qMinusT / baseMinusT); + } + output.push(stringFromCharCode(digitToBasic(q, 0))); + bias = adapt(delta, handledCPCountPlusOne, handledCPCount === basicLength); + delta = 0; + ++handledCPCount; + } + } + ++delta; + ++n; + } + return output.join(""); + }; + + /** + * Converts a Punycode string representing a domain name or an email address + * to Unicode. Only the Punycoded parts of the input will be converted, i.e. + * it doesn't matter if you call it on a string that has already been + * converted to Unicode. + * @memberOf punycode + * @param {String} input The Punycoded domain name or email address to + * convert to Unicode. + * @returns {String} The Unicode representation of the given Punycode + * string. + */ + const toUnicode = function (input) { + return mapDomain(input, function (string) { + return regexPunycode.test(string) ? decode(string.slice(4).toLowerCase()) : string; + }); + }; + + /** + * Converts a Unicode string representing a domain name or an email address to + * Punycode. Only the non-ASCII parts of the domain name will be converted, + * i.e. it doesn't matter if you call it with a domain that's already in + * ASCII. + * @memberOf punycode + * @param {String} input The domain name or email address to convert, as a + * Unicode string. + * @returns {String} The Punycode representation of the given domain name or + * email address. + */ + const toASCII = function (input) { + return mapDomain(input, function (string) { + return regexNonASCII.test(string) ? "xn--" + encode(string) : string; + }); + }; + + /*--------------------------------------------------------------------------*/ + + /** Define the public API */ + const punycode = { + /** + * A string representing the current Punycode.js version number. + * @memberOf punycode + * @type String + */ + "version": "2.3.1", + /** + * An object of methods to convert from JavaScript's internal character + * representation (UCS-2) to Unicode code points, and back. + * @see + * @memberOf punycode + * @type Object + */ + "ucs2": { + "decode": ucs2decode, + "encode": ucs2encode + }, + "decode": decode, + "encode": encode, + "toASCII": toASCII, + "toUnicode": toUnicode + }; + exports$1 = punycode; + return exports$1; +} + +const exports = dew(); + +var decode = exports.decode; +var encode = exports.encode; +var toASCII = exports.toASCII; +var toUnicode = exports.toUnicode; +var ucs2 = exports.ucs2; +var version = exports.version; + +export { decode, exports as default, encode, toASCII, toUnicode, ucs2, version }; diff --git a/nodelibs/browser/querystring.js b/nodelibs/browser/querystring.js index 0353849..e5a3c83 100644 --- a/nodelibs/browser/querystring.js +++ b/nodelibs/browser/querystring.js @@ -1,13 +1,118 @@ -import { o } from './chunk-D5E0hY9V.js'; +var exports$3 = {}, + _dewExec$2 = false; +function dew$2() { + if (_dewExec$2) return exports$3; + _dewExec$2 = true; + // If obj.hasOwnProperty has been overridden, then calling + // obj.hasOwnProperty(prop) will break. + // See: https://github.com/joyent/node/issues/1707 + function hasOwnProperty(obj, prop) { + return Object.prototype.hasOwnProperty.call(obj, prop); + } + exports$3 = function (qs, sep, eq, options) { + sep = sep || "&"; + eq = eq || "="; + var obj = {}; + if (typeof qs !== "string" || qs.length === 0) { + return obj; + } + var regexp = /\+/g; + qs = qs.split(sep); + var maxKeys = 1000; + if (options && typeof options.maxKeys === "number") { + maxKeys = options.maxKeys; + } + var len = qs.length; + // maxKeys <= 0 means that we should not limit keys count + if (maxKeys > 0 && len > maxKeys) { + len = maxKeys; + } + for (var i = 0; i < len; ++i) { + var x = qs[i].replace(regexp, "%20"), + idx = x.indexOf(eq), + kstr, + vstr, + k, + v; + if (idx >= 0) { + kstr = x.substr(0, idx); + vstr = x.substr(idx + 1); + } else { + kstr = x; + vstr = ""; + } + k = decodeURIComponent(kstr); + v = decodeURIComponent(vstr); + if (!hasOwnProperty(obj, k)) { + obj[k] = v; + } else if (Array.isArray(obj[k])) { + obj[k].push(v); + } else { + obj[k] = [obj[k], v]; + } + } + return obj; + }; + return exports$3; +} -o.decode; -o.encode; -o.parse; -o.stringify; +var exports$2 = {}, + _dewExec$1 = false; +function dew$1() { + if (_dewExec$1) return exports$2; + _dewExec$1 = true; + var stringifyPrimitive = function (v) { + switch (typeof v) { + case "string": + return v; + case "boolean": + return v ? "true" : "false"; + case "number": + return isFinite(v) ? v : ""; + default: + return ""; + } + }; + exports$2 = function (obj, sep, eq, name) { + sep = sep || "&"; + eq = eq || "="; + if (obj === null) { + obj = undefined; + } + if (typeof obj === "object") { + return Object.keys(obj).map(function (k) { + var ks = encodeURIComponent(stringifyPrimitive(k)) + eq; + if (Array.isArray(obj[k])) { + return obj[k].map(function (v) { + return ks + encodeURIComponent(stringifyPrimitive(v)); + }).join(sep); + } else { + return ks + encodeURIComponent(stringifyPrimitive(obj[k])); + } + }).filter(Boolean).join(sep); + } + if (!name) return ""; + return encodeURIComponent(stringifyPrimitive(name)) + eq + encodeURIComponent(stringifyPrimitive(obj)); + }; + return exports$2; +} -var decode = o.decode; -var encode = o.encode; -var parse = o.parse; -var stringify = o.stringify; +var exports$1 = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports$1; + _dewExec = true; + exports$1.decode = exports$1.parse = dew$2(); + exports$1.encode = exports$1.stringify = dew$1(); + return exports$1; +} -export { decode, o as default, encode, parse, stringify }; +const exports = dew(); +exports['decode']; exports['parse']; exports['encode']; exports['stringify']; + +var decode = exports.decode; +var encode = exports.encode; +var parse = exports.parse; +var stringify = exports.stringify; + +export { decode, exports as default, encode, parse, stringify }; diff --git a/nodelibs/browser/stream.js b/nodelibs/browser/stream.js index 956c1f8..7fd89ce 100644 --- a/nodelibs/browser/stream.js +++ b/nodelibs/browser/stream.js @@ -1,13 +1,6552 @@ -import { e as exports } from './chunk-gkrMq4sQ.js'; +import { d as dew$p } from './chunk-DtuTasat.js'; +import exports$q from './events.js'; +import { p as process } from './chunk-DEMDiNwt.js'; +import { e as exports$r } from './chunk-CcCWfKp1.js'; import { promisify } from './util.js'; -import './events.js'; -import './chunk-tHuMsdT0.js'; -import './chunk-CU2hd6BF.js'; -import './chunk-BZgdGiNw.js'; -import './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; -import './chunk-b0rmRow7.js'; -import './chunk-C9hMJ5VR.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; + +var exports$p = {}, + _dewExec$o = false; +function dew$o() { + if (_dewExec$o) return exports$p; + _dewExec$o = true; + /* + This file is a reduced and adapted version of the main lib/internal/per_context/primordials.js file defined at + + https://github.com/nodejs/node/blob/master/lib/internal/per_context/primordials.js + + Don't try to replace with the original file and keep it up to date with the upstream file. + */ + exports$p = { + ArrayIsArray(self) { + return Array.isArray(self); + }, + ArrayPrototypeIncludes(self, el) { + return self.includes(el); + }, + ArrayPrototypeIndexOf(self, el) { + return self.indexOf(el); + }, + ArrayPrototypeJoin(self, sep) { + return self.join(sep); + }, + ArrayPrototypeMap(self, fn) { + return self.map(fn); + }, + ArrayPrototypePop(self, el) { + return self.pop(el); + }, + ArrayPrototypePush(self, el) { + return self.push(el); + }, + ArrayPrototypeSlice(self, start, end) { + return self.slice(start, end); + }, + Error, + FunctionPrototypeCall(fn, thisArgs, ...args) { + return fn.call(thisArgs, ...args); + }, + FunctionPrototypeSymbolHasInstance(self, instance) { + return Function.prototype[Symbol.hasInstance].call(self, instance); + }, + MathFloor: Math.floor, + Number, + NumberIsInteger: Number.isInteger, + NumberIsNaN: Number.isNaN, + NumberMAX_SAFE_INTEGER: Number.MAX_SAFE_INTEGER, + NumberMIN_SAFE_INTEGER: Number.MIN_SAFE_INTEGER, + NumberParseInt: Number.parseInt, + ObjectDefineProperties(self, props) { + return Object.defineProperties(self, props); + }, + ObjectDefineProperty(self, name, prop) { + return Object.defineProperty(self, name, prop); + }, + ObjectGetOwnPropertyDescriptor(self, name) { + return Object.getOwnPropertyDescriptor(self, name); + }, + ObjectKeys(obj) { + return Object.keys(obj); + }, + ObjectSetPrototypeOf(target, proto) { + return Object.setPrototypeOf(target, proto); + }, + Promise, + PromisePrototypeCatch(self, fn) { + return self.catch(fn); + }, + PromisePrototypeThen(self, thenFn, catchFn) { + return self.then(thenFn, catchFn); + }, + PromiseReject(err) { + return Promise.reject(err); + }, + PromiseResolve(val) { + return Promise.resolve(val); + }, + ReflectApply: Reflect.apply, + RegExpPrototypeTest(self, value) { + return self.test(value); + }, + SafeSet: Set, + String, + StringPrototypeSlice(self, start, end) { + return self.slice(start, end); + }, + StringPrototypeToLowerCase(self) { + return self.toLowerCase(); + }, + StringPrototypeToUpperCase(self) { + return self.toUpperCase(); + }, + StringPrototypeTrim(self) { + return self.trim(); + }, + Symbol, + SymbolFor: Symbol.for, + SymbolAsyncIterator: Symbol.asyncIterator, + SymbolHasInstance: Symbol.hasInstance, + SymbolIterator: Symbol.iterator, + SymbolDispose: Symbol.dispose || Symbol("Symbol.dispose"), + SymbolAsyncDispose: Symbol.asyncDispose || Symbol("Symbol.asyncDispose"), + TypedArrayPrototypeSet(self, buf, len) { + return self.set(buf, len); + }, + Boolean: Boolean, + Uint8Array + }; + return exports$p; +} + +var exports$o = {}, + _dewExec$n = false; +function dew$n() { + if (_dewExec$n) return exports$o; + _dewExec$n = true; + /*eslint-disable @mysticatea/prettier */ + const { + AbortController, + AbortSignal + } = typeof self !== "undefined" ? self : typeof window !== "undefined" ? window : /* otherwise */undefined; + /*eslint-enable @mysticatea/prettier */ + + exports$o = AbortController; + exports$o.AbortSignal = AbortSignal; + exports$o.default = AbortController; + return exports$o; +} + +var exports$n = {}, + _dewExec$m = false; +function dew$m() { + if (_dewExec$m) return exports$n; + _dewExec$m = true; + const bufferModule = dew$p(); + const { + kResistStopPropagation, + SymbolDispose + } = dew$o(); + const AbortSignal = globalThis.AbortSignal || dew$n().AbortSignal; + const AbortController = globalThis.AbortController || dew$n().AbortController; + const AsyncFunction = Object.getPrototypeOf(async function () {}).constructor; + const Blob = globalThis.Blob || bufferModule.Blob; + /* eslint-disable indent */ + const isBlob = typeof Blob !== "undefined" ? function isBlob(b) { + // eslint-disable-next-line indent + return b instanceof Blob; + } : function isBlob(b) { + return false; + }; + /* eslint-enable indent */ + + const validateAbortSignal = (signal, name) => { + if (signal !== undefined && (signal === null || typeof signal !== "object" || !("aborted" in signal))) { + throw new ERR_INVALID_ARG_TYPE(name, "AbortSignal", signal); + } + }; + const validateFunction = (value, name) => { + if (typeof value !== "function") throw new ERR_INVALID_ARG_TYPE(name, "Function", value); + }; + + // This is a simplified version of AggregateError + class AggregateError extends Error { + constructor(errors) { + if (!Array.isArray(errors)) { + throw new TypeError(`Expected input to be an Array, got ${typeof errors}`); + } + let message = ""; + for (let i = 0; i < errors.length; i++) { + message += ` ${errors[i].stack}\n`; + } + super(message); + this.name = "AggregateError"; + this.errors = errors; + } + } + exports$n = { + AggregateError, + kEmptyObject: Object.freeze({}), + once(callback) { + let called = false; + return function (...args) { + if (called) { + return; + } + called = true; + callback.apply(this, args); + }; + }, + createDeferredPromise: function () { + let resolve; + let reject; + + // eslint-disable-next-line promise/param-names + const promise = new Promise((res, rej) => { + resolve = res; + reject = rej; + }); + return { + promise, + resolve, + reject + }; + }, + promisify(fn) { + return new Promise((resolve, reject) => { + fn((err, ...args) => { + if (err) { + return reject(err); + } + return resolve(...args); + }); + }); + }, + debuglog() { + return function () {}; + }, + format(format, ...args) { + // Simplified version of https://nodejs.org/api/util.html#utilformatformat-args + return format.replace(/%([sdifj])/g, function (...[_unused, type]) { + const replacement = args.shift(); + if (type === "f") { + return replacement.toFixed(6); + } else if (type === "j") { + return JSON.stringify(replacement); + } else if (type === "s" && typeof replacement === "object") { + const ctor = replacement.constructor !== Object ? replacement.constructor.name : ""; + return `${ctor} {}`.trim(); + } else { + return replacement.toString(); + } + }); + }, + inspect(value) { + // Vastly simplified version of https://nodejs.org/api/util.html#utilinspectobject-options + switch (typeof value) { + case "string": + if (value.includes("'")) { + if (!value.includes("\"")) { + return `"${value}"`; + } else if (!value.includes("`") && !value.includes("${")) { + return `\`${value}\``; + } + } + return `'${value}'`; + case "number": + if (isNaN(value)) { + return "NaN"; + } else if (Object.is(value, -0)) { + return String(value); + } + return value; + case "bigint": + return `${String(value)}n`; + case "boolean": + case "undefined": + return String(value); + case "object": + return "{}"; + } + }, + types: { + isAsyncFunction(fn) { + return fn instanceof AsyncFunction; + }, + isArrayBufferView(arr) { + return ArrayBuffer.isView(arr); + } + }, + isBlob, + deprecate(fn, message) { + return fn; + }, + addAbortListener: exports$q.addAbortListener || function addAbortListener(signal, listener) { + if (signal === undefined) { + throw new ERR_INVALID_ARG_TYPE("signal", "AbortSignal", signal); + } + validateAbortSignal(signal, "signal"); + validateFunction(listener, "listener"); + let removeEventListener; + if (signal.aborted) { + queueMicrotask(() => listener()); + } else { + signal.addEventListener("abort", listener, { + __proto__: null, + once: true, + [kResistStopPropagation]: true + }); + removeEventListener = () => { + signal.removeEventListener("abort", listener); + }; + } + return { + __proto__: null, + [SymbolDispose]() { + var _removeEventListener; + (_removeEventListener = removeEventListener) === null || _removeEventListener === undefined ? undefined : _removeEventListener(); + } + }; + }, + AbortSignalAny: AbortSignal.any || function AbortSignalAny(signals) { + // Fast path if there is only one signal. + if (signals.length === 1) { + return signals[0]; + } + const ac = new AbortController(); + const abort = () => ac.abort(); + signals.forEach(signal => { + validateAbortSignal(signal, "signals"); + signal.addEventListener("abort", abort, { + once: true + }); + }); + ac.signal.addEventListener("abort", () => { + signals.forEach(signal => signal.removeEventListener("abort", abort)); + }, { + once: true + }); + return ac.signal; + } + }; + exports$n.promisify.custom = Symbol.for("nodejs.util.promisify.custom"); + return exports$n; +} + +var exports$m = {}, + _dewExec$l = false; +function dew$l() { + if (_dewExec$l) return exports$m; + _dewExec$l = true; + const { + format, + inspect, + AggregateError: CustomAggregateError + } = dew$m(); + + /* + This file is a reduced and adapted version of the main lib/internal/errors.js file defined at + + https://github.com/nodejs/node/blob/master/lib/internal/errors.js + + Don't try to replace with the original file and keep it up to date (starting from E(...) definitions) + with the upstream file. + */ + + const AggregateError = globalThis.AggregateError || CustomAggregateError; + const kIsNodeError = Symbol("kIsNodeError"); + const kTypes = ["string", "function", "number", "object", + // Accept 'Function' and 'Object' as alternative to the lower cased version. + "Function", "Object", "boolean", "bigint", "symbol"]; + const classRegExp = /^([A-Z][a-z0-9]*)+$/; + const nodeInternalPrefix = "__node_internal_"; + const codes = {}; + function assert(value, message) { + if (!value) { + throw new codes.ERR_INTERNAL_ASSERTION(message); + } + } + + // Only use this for integers! Decimal numbers do not work with this function. + function addNumericalSeparator(val) { + let res = ""; + let i = val.length; + const start = val[0] === "-" ? 1 : 0; + for (; i >= start + 4; i -= 3) { + res = `_${val.slice(i - 3, i)}${res}`; + } + return `${val.slice(0, i)}${res}`; + } + function getMessage(key, msg, args) { + if (typeof msg === "function") { + assert(msg.length <= args.length, + // Default options do not count. + `Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${msg.length}).`); + return msg(...args); + } + const expectedLength = (msg.match(/%[dfijoOs]/g) || []).length; + assert(expectedLength === args.length, `Code: ${key}; The provided arguments length (${args.length}) does not match the required ones (${expectedLength}).`); + if (args.length === 0) { + return msg; + } + return format(msg, ...args); + } + function E(code, message, Base) { + if (!Base) { + Base = Error; + } + class NodeError extends Base { + constructor(...args) { + super(getMessage(code, message, args)); + } + toString() { + return `${this.name} [${code}]: ${this.message}`; + } + } + Object.defineProperties(NodeError.prototype, { + name: { + value: Base.name, + writable: true, + enumerable: false, + configurable: true + }, + toString: { + value() { + return `${this.name} [${code}]: ${this.message}`; + }, + writable: true, + enumerable: false, + configurable: true + } + }); + NodeError.prototype.code = code; + NodeError.prototype[kIsNodeError] = true; + codes[code] = NodeError; + } + function hideStackFrames(fn) { + // We rename the functions that will be hidden to cut off the stacktrace + // at the outermost one + const hidden = nodeInternalPrefix + fn.name; + Object.defineProperty(fn, "name", { + value: hidden + }); + return fn; + } + function aggregateTwoErrors(innerError, outerError) { + if (innerError && outerError && innerError !== outerError) { + if (Array.isArray(outerError.errors)) { + // If `outerError` is already an `AggregateError`. + outerError.errors.push(innerError); + return outerError; + } + const err = new AggregateError([outerError, innerError], outerError.message); + err.code = outerError.code; + return err; + } + return innerError || outerError; + } + class AbortError extends Error { + constructor(message = "The operation was aborted", options = undefined) { + if (options !== undefined && typeof options !== "object") { + throw new codes.ERR_INVALID_ARG_TYPE("options", "Object", options); + } + super(message, options); + this.code = "ABORT_ERR"; + this.name = "AbortError"; + } + } + E("ERR_ASSERTION", "%s", Error); + E("ERR_INVALID_ARG_TYPE", (name, expected, actual) => { + assert(typeof name === "string", "'name' must be a string"); + if (!Array.isArray(expected)) { + expected = [expected]; + } + let msg = "The "; + if (name.endsWith(" argument")) { + // For cases like 'first argument' + msg += `${name} `; + } else { + msg += `"${name}" ${name.includes(".") ? "property" : "argument"} `; + } + msg += "must be "; + const types = []; + const instances = []; + const other = []; + for (const value of expected) { + assert(typeof value === "string", "All expected entries have to be of type string"); + if (kTypes.includes(value)) { + types.push(value.toLowerCase()); + } else if (classRegExp.test(value)) { + instances.push(value); + } else { + assert(value !== "object", "The value \"object\" should be written as \"Object\""); + other.push(value); + } + } + + // Special handle `object` in case other instances are allowed to outline + // the differences between each other. + if (instances.length > 0) { + const pos = types.indexOf("object"); + if (pos !== -1) { + types.splice(types, pos, 1); + instances.push("Object"); + } + } + if (types.length > 0) { + switch (types.length) { + case 1: + msg += `of type ${types[0]}`; + break; + case 2: + msg += `one of type ${types[0]} or ${types[1]}`; + break; + default: + { + const last = types.pop(); + msg += `one of type ${types.join(", ")}, or ${last}`; + } + } + if (instances.length > 0 || other.length > 0) { + msg += " or "; + } + } + if (instances.length > 0) { + switch (instances.length) { + case 1: + msg += `an instance of ${instances[0]}`; + break; + case 2: + msg += `an instance of ${instances[0]} or ${instances[1]}`; + break; + default: + { + const last = instances.pop(); + msg += `an instance of ${instances.join(", ")}, or ${last}`; + } + } + if (other.length > 0) { + msg += " or "; + } + } + switch (other.length) { + case 0: + break; + case 1: + if (other[0].toLowerCase() !== other[0]) { + msg += "an "; + } + msg += `${other[0]}`; + break; + case 2: + msg += `one of ${other[0]} or ${other[1]}`; + break; + default: + { + const last = other.pop(); + msg += `one of ${other.join(", ")}, or ${last}`; + } + } + if (actual == null) { + msg += `. Received ${actual}`; + } else if (typeof actual === "function" && actual.name) { + msg += `. Received function ${actual.name}`; + } else if (typeof actual === "object") { + var _actual$constructor; + if ((_actual$constructor = actual.constructor) !== null && _actual$constructor !== undefined && _actual$constructor.name) { + msg += `. Received an instance of ${actual.constructor.name}`; + } else { + const inspected = inspect(actual, { + depth: -1 + }); + msg += `. Received ${inspected}`; + } + } else { + let inspected = inspect(actual, { + colors: false + }); + if (inspected.length > 25) { + inspected = `${inspected.slice(0, 25)}...`; + } + msg += `. Received type ${typeof actual} (${inspected})`; + } + return msg; + }, TypeError); + E("ERR_INVALID_ARG_VALUE", (name, value, reason = "is invalid") => { + let inspected = inspect(value); + if (inspected.length > 128) { + inspected = inspected.slice(0, 128) + "..."; + } + const type = name.includes(".") ? "property" : "argument"; + return `The ${type} '${name}' ${reason}. Received ${inspected}`; + }, TypeError); + E("ERR_INVALID_RETURN_VALUE", (input, name, value) => { + var _value$constructor; + const type = value !== null && value !== undefined && (_value$constructor = value.constructor) !== null && _value$constructor !== undefined && _value$constructor.name ? `instance of ${value.constructor.name}` : `type ${typeof value}`; + return `Expected ${input} to be returned from the "${name}"` + ` function but got ${type}.`; + }, TypeError); + E("ERR_MISSING_ARGS", (...args) => { + assert(args.length > 0, "At least one arg needs to be specified"); + let msg; + const len = args.length; + args = (Array.isArray(args) ? args : [args]).map(a => `"${a}"`).join(" or "); + switch (len) { + case 1: + msg += `The ${args[0]} argument`; + break; + case 2: + msg += `The ${args[0]} and ${args[1]} arguments`; + break; + default: + { + const last = args.pop(); + msg += `The ${args.join(", ")}, and ${last} arguments`; + } + break; + } + return `${msg} must be specified`; + }, TypeError); + E("ERR_OUT_OF_RANGE", (str, range, input) => { + assert(range, "Missing \"range\" argument"); + let received; + if (Number.isInteger(input) && Math.abs(input) > 2 ** 32) { + received = addNumericalSeparator(String(input)); + } else if (typeof input === "bigint") { + received = String(input); + if (input > 2n ** 32n || input < -(2n ** 32n)) { + received = addNumericalSeparator(received); + } + received += "n"; + } else { + received = inspect(input); + } + return `The value of "${str}" is out of range. It must be ${range}. Received ${received}`; + }, RangeError); + E("ERR_MULTIPLE_CALLBACK", "Callback called multiple times", Error); + E("ERR_METHOD_NOT_IMPLEMENTED", "The %s method is not implemented", Error); + E("ERR_STREAM_ALREADY_FINISHED", "Cannot call %s after a stream was finished", Error); + E("ERR_STREAM_CANNOT_PIPE", "Cannot pipe, not readable", Error); + E("ERR_STREAM_DESTROYED", "Cannot call %s after a stream was destroyed", Error); + E("ERR_STREAM_NULL_VALUES", "May not write null values to stream", TypeError); + E("ERR_STREAM_PREMATURE_CLOSE", "Premature close", Error); + E("ERR_STREAM_PUSH_AFTER_EOF", "stream.push() after EOF", Error); + E("ERR_STREAM_UNSHIFT_AFTER_END_EVENT", "stream.unshift() after end event", Error); + E("ERR_STREAM_WRITE_AFTER_END", "write after end", Error); + E("ERR_UNKNOWN_ENCODING", "Unknown encoding: %s", TypeError); + exports$m = { + AbortError, + aggregateTwoErrors: hideStackFrames(aggregateTwoErrors), + hideStackFrames, + codes + }; + return exports$m; +} + +var exports$l = {}, + _dewExec$k = false; +function dew$k() { + if (_dewExec$k) return exports$l; + _dewExec$k = true; + const { + ArrayIsArray, + ArrayPrototypeIncludes, + ArrayPrototypeJoin, + ArrayPrototypeMap, + NumberIsInteger, + NumberIsNaN, + NumberMAX_SAFE_INTEGER, + NumberMIN_SAFE_INTEGER, + NumberParseInt, + ObjectPrototypeHasOwnProperty, + RegExpPrototypeExec, + String, + StringPrototypeToUpperCase, + StringPrototypeTrim + } = dew$o(); + const { + hideStackFrames, + codes: { + ERR_SOCKET_BAD_PORT, + ERR_INVALID_ARG_TYPE, + ERR_INVALID_ARG_VALUE, + ERR_OUT_OF_RANGE, + ERR_UNKNOWN_SIGNAL + } + } = dew$l(); + const { + normalizeEncoding + } = dew$m(); + const { + isAsyncFunction, + isArrayBufferView + } = dew$m().types; + const signals = {}; + + /** + * @param {*} value + * @returns {boolean} + */ + function isInt32(value) { + return value === (value | 0); + } + + /** + * @param {*} value + * @returns {boolean} + */ + function isUint32(value) { + return value === value >>> 0; + } + const octalReg = /^[0-7]+$/; + const modeDesc = "must be a 32-bit unsigned integer or an octal string"; + + /** + * Parse and validate values that will be converted into mode_t (the S_* + * constants). Only valid numbers and octal strings are allowed. They could be + * converted to 32-bit unsigned integers or non-negative signed integers in the + * C++ land, but any value higher than 0o777 will result in platform-specific + * behaviors. + * @param {*} value Values to be validated + * @param {string} name Name of the argument + * @param {number} [def] If specified, will be returned for invalid values + * @returns {number} + */ + function parseFileMode(value, name, def) { + if (typeof value === "undefined") { + value = def; + } + if (typeof value === "string") { + if (RegExpPrototypeExec(octalReg, value) === null) { + throw new ERR_INVALID_ARG_VALUE(name, value, modeDesc); + } + value = NumberParseInt(value, 8); + } + validateUint32(value, name); + return value; + } + + /** + * @callback validateInteger + * @param {*} value + * @param {string} name + * @param {number} [min] + * @param {number} [max] + * @returns {asserts value is number} + */ + + /** @type {validateInteger} */ + const validateInteger = hideStackFrames((value, name, min = NumberMIN_SAFE_INTEGER, max = NumberMAX_SAFE_INTEGER) => { + if (typeof value !== "number") throw new ERR_INVALID_ARG_TYPE(name, "number", value); + if (!NumberIsInteger(value)) throw new ERR_OUT_OF_RANGE(name, "an integer", value); + if (value < min || value > max) throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); + }); + + /** + * @callback validateInt32 + * @param {*} value + * @param {string} name + * @param {number} [min] + * @param {number} [max] + * @returns {asserts value is number} + */ + + /** @type {validateInt32} */ + const validateInt32 = hideStackFrames((value, name, min = -2147483648, max = 2147483647) => { + // The defaults for min and max correspond to the limits of 32-bit integers. + if (typeof value !== "number") { + throw new ERR_INVALID_ARG_TYPE(name, "number", value); + } + if (!NumberIsInteger(value)) { + throw new ERR_OUT_OF_RANGE(name, "an integer", value); + } + if (value < min || value > max) { + throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); + } + }); + + /** + * @callback validateUint32 + * @param {*} value + * @param {string} name + * @param {number|boolean} [positive=false] + * @returns {asserts value is number} + */ + + /** @type {validateUint32} */ + const validateUint32 = hideStackFrames((value, name, positive = false) => { + if (typeof value !== "number") { + throw new ERR_INVALID_ARG_TYPE(name, "number", value); + } + if (!NumberIsInteger(value)) { + throw new ERR_OUT_OF_RANGE(name, "an integer", value); + } + const min = positive ? 1 : 0; + // 2 ** 32 === 4294967296 + const max = 4294967295; + if (value < min || value > max) { + throw new ERR_OUT_OF_RANGE(name, `>= ${min} && <= ${max}`, value); + } + }); + + /** + * @callback validateString + * @param {*} value + * @param {string} name + * @returns {asserts value is string} + */ + + /** @type {validateString} */ + function validateString(value, name) { + if (typeof value !== "string") throw new ERR_INVALID_ARG_TYPE(name, "string", value); + } + + /** + * @callback validateNumber + * @param {*} value + * @param {string} name + * @param {number} [min] + * @param {number} [max] + * @returns {asserts value is number} + */ + + /** @type {validateNumber} */ + function validateNumber(value, name, min = undefined, max) { + if (typeof value !== "number") throw new ERR_INVALID_ARG_TYPE(name, "number", value); + if (min != null && value < min || max != null && value > max || (min != null || max != null) && NumberIsNaN(value)) { + throw new ERR_OUT_OF_RANGE(name, `${min != null ? `>= ${min}` : ""}${min != null && max != null ? " && " : ""}${max != null ? `<= ${max}` : ""}`, value); + } + } + + /** + * @callback validateOneOf + * @template T + * @param {T} value + * @param {string} name + * @param {T[]} oneOf + */ + + /** @type {validateOneOf} */ + const validateOneOf = hideStackFrames((value, name, oneOf) => { + if (!ArrayPrototypeIncludes(oneOf, value)) { + const allowed = ArrayPrototypeJoin(ArrayPrototypeMap(oneOf, v => typeof v === "string" ? `'${v}'` : String(v)), ", "); + const reason = "must be one of: " + allowed; + throw new ERR_INVALID_ARG_VALUE(name, value, reason); + } + }); + + /** + * @callback validateBoolean + * @param {*} value + * @param {string} name + * @returns {asserts value is boolean} + */ + + /** @type {validateBoolean} */ + function validateBoolean(value, name) { + if (typeof value !== "boolean") throw new ERR_INVALID_ARG_TYPE(name, "boolean", value); + } + + /** + * @param {any} options + * @param {string} key + * @param {boolean} defaultValue + * @returns {boolean} + */ + function getOwnPropertyValueOrDefault(options, key, defaultValue) { + return options == null || !ObjectPrototypeHasOwnProperty(options, key) ? defaultValue : options[key]; + } + + /** + * @callback validateObject + * @param {*} value + * @param {string} name + * @param {{ + * allowArray?: boolean, + * allowFunction?: boolean, + * nullable?: boolean + * }} [options] + */ + + /** @type {validateObject} */ + const validateObject = hideStackFrames((value, name, options = null) => { + const allowArray = getOwnPropertyValueOrDefault(options, "allowArray", false); + const allowFunction = getOwnPropertyValueOrDefault(options, "allowFunction", false); + const nullable = getOwnPropertyValueOrDefault(options, "nullable", false); + if (!nullable && value === null || !allowArray && ArrayIsArray(value) || typeof value !== "object" && (!allowFunction || typeof value !== "function")) { + throw new ERR_INVALID_ARG_TYPE(name, "Object", value); + } + }); + + /** + * @callback validateDictionary - We are using the Web IDL Standard definition + * of "dictionary" here, which means any value + * whose Type is either Undefined, Null, or + * Object (which includes functions). + * @param {*} value + * @param {string} name + * @see https://webidl.spec.whatwg.org/#es-dictionary + * @see https://tc39.es/ecma262/#table-typeof-operator-results + */ + + /** @type {validateDictionary} */ + const validateDictionary = hideStackFrames((value, name) => { + if (value != null && typeof value !== "object" && typeof value !== "function") { + throw new ERR_INVALID_ARG_TYPE(name, "a dictionary", value); + } + }); + + /** + * @callback validateArray + * @param {*} value + * @param {string} name + * @param {number} [minLength] + * @returns {asserts value is any[]} + */ + + /** @type {validateArray} */ + const validateArray = hideStackFrames((value, name, minLength = 0) => { + if (!ArrayIsArray(value)) { + throw new ERR_INVALID_ARG_TYPE(name, "Array", value); + } + if (value.length < minLength) { + const reason = `must be longer than ${minLength}`; + throw new ERR_INVALID_ARG_VALUE(name, value, reason); + } + }); + + /** + * @callback validateStringArray + * @param {*} value + * @param {string} name + * @returns {asserts value is string[]} + */ + + /** @type {validateStringArray} */ + function validateStringArray(value, name) { + validateArray(value, name); + for (let i = 0; i < value.length; i++) { + validateString(value[i], `${name}[${i}]`); + } + } + + /** + * @callback validateBooleanArray + * @param {*} value + * @param {string} name + * @returns {asserts value is boolean[]} + */ + + /** @type {validateBooleanArray} */ + function validateBooleanArray(value, name) { + validateArray(value, name); + for (let i = 0; i < value.length; i++) { + validateBoolean(value[i], `${name}[${i}]`); + } + } + + /** + * @callback validateAbortSignalArray + * @param {*} value + * @param {string} name + * @returns {asserts value is AbortSignal[]} + */ + + /** @type {validateAbortSignalArray} */ + function validateAbortSignalArray(value, name) { + validateArray(value, name); + for (let i = 0; i < value.length; i++) { + const signal = value[i]; + const indexedName = `${name}[${i}]`; + if (signal == null) { + throw new ERR_INVALID_ARG_TYPE(indexedName, "AbortSignal", signal); + } + validateAbortSignal(signal, indexedName); + } + } + + /** + * @param {*} signal + * @param {string} [name='signal'] + * @returns {asserts signal is keyof signals} + */ + function validateSignalName(signal, name = "signal") { + validateString(signal, name); + if (signals[signal] === undefined) { + if (signals[StringPrototypeToUpperCase(signal)] !== undefined) { + throw new ERR_UNKNOWN_SIGNAL(signal + " (signals must use all capital letters)"); + } + throw new ERR_UNKNOWN_SIGNAL(signal); + } + } + + /** + * @callback validateBuffer + * @param {*} buffer + * @param {string} [name='buffer'] + * @returns {asserts buffer is ArrayBufferView} + */ + + /** @type {validateBuffer} */ + const validateBuffer = hideStackFrames((buffer, name = "buffer") => { + if (!isArrayBufferView(buffer)) { + throw new ERR_INVALID_ARG_TYPE(name, ["Buffer", "TypedArray", "DataView"], buffer); + } + }); + + /** + * @param {string} data + * @param {string} encoding + */ + function validateEncoding(data, encoding) { + const normalizedEncoding = normalizeEncoding(encoding); + const length = data.length; + if (normalizedEncoding === "hex" && length % 2 !== 0) { + throw new ERR_INVALID_ARG_VALUE("encoding", encoding, `is invalid for data of length ${length}`); + } + } + + /** + * Check that the port number is not NaN when coerced to a number, + * is an integer and that it falls within the legal range of port numbers. + * @param {*} port + * @param {string} [name='Port'] + * @param {boolean} [allowZero=true] + * @returns {number} + */ + function validatePort(port, name = "Port", allowZero = true) { + if (typeof port !== "number" && typeof port !== "string" || typeof port === "string" && StringPrototypeTrim(port).length === 0 || +port !== +port >>> 0 || port > 65535 || port === 0 && !allowZero) { + throw new ERR_SOCKET_BAD_PORT(name, port, allowZero); + } + return port | 0; + } + + /** + * @callback validateAbortSignal + * @param {*} signal + * @param {string} name + */ + + /** @type {validateAbortSignal} */ + const validateAbortSignal = hideStackFrames((signal, name) => { + if (signal !== undefined && (signal === null || typeof signal !== "object" || !("aborted" in signal))) { + throw new ERR_INVALID_ARG_TYPE(name, "AbortSignal", signal); + } + }); + + /** + * @callback validateFunction + * @param {*} value + * @param {string} name + * @returns {asserts value is Function} + */ + + /** @type {validateFunction} */ + const validateFunction = hideStackFrames((value, name) => { + if (typeof value !== "function") throw new ERR_INVALID_ARG_TYPE(name, "Function", value); + }); + + /** + * @callback validatePlainFunction + * @param {*} value + * @param {string} name + * @returns {asserts value is Function} + */ + + /** @type {validatePlainFunction} */ + const validatePlainFunction = hideStackFrames((value, name) => { + if (typeof value !== "function" || isAsyncFunction(value)) throw new ERR_INVALID_ARG_TYPE(name, "Function", value); + }); + + /** + * @callback validateUndefined + * @param {*} value + * @param {string} name + * @returns {asserts value is undefined} + */ + + /** @type {validateUndefined} */ + const validateUndefined = hideStackFrames((value, name) => { + if (value !== undefined) throw new ERR_INVALID_ARG_TYPE(name, "undefined", value); + }); + + /** + * @template T + * @param {T} value + * @param {string} name + * @param {T[]} union + */ + function validateUnion(value, name, union) { + if (!ArrayPrototypeIncludes(union, value)) { + throw new ERR_INVALID_ARG_TYPE(name, `('${ArrayPrototypeJoin(union, "|")}')`, value); + } + } + + /* + The rules for the Link header field are described here: + https://www.rfc-editor.org/rfc/rfc8288.html#section-3 + + This regex validates any string surrounded by angle brackets + (not necessarily a valid URI reference) followed by zero or more + link-params separated by semicolons. + */ + const linkValueRegExp = /^(?:<[^>]*>)(?:\s*;\s*[^;"\s]+(?:=(")?[^;"\s]*\1)?)*$/; + + /** + * @param {any} value + * @param {string} name + */ + function validateLinkHeaderFormat(value, name) { + if (typeof value === "undefined" || !RegExpPrototypeExec(linkValueRegExp, value)) { + throw new ERR_INVALID_ARG_VALUE(name, value, "must be an array or string of format \"; rel=preload; as=style\""); + } + } + + /** + * @param {any} hints + * @return {string} + */ + function validateLinkHeaderValue(hints) { + if (typeof hints === "string") { + validateLinkHeaderFormat(hints, "hints"); + return hints; + } else if (ArrayIsArray(hints)) { + const hintsLength = hints.length; + let result = ""; + if (hintsLength === 0) { + return result; + } + for (let i = 0; i < hintsLength; i++) { + const link = hints[i]; + validateLinkHeaderFormat(link, "hints"); + result += link; + if (i !== hintsLength - 1) { + result += ", "; + } + } + return result; + } + throw new ERR_INVALID_ARG_VALUE("hints", hints, "must be an array or string of format \"; rel=preload; as=style\""); + } + exports$l = { + isInt32, + isUint32, + parseFileMode, + validateArray, + validateStringArray, + validateBooleanArray, + validateAbortSignalArray, + validateBoolean, + validateBuffer, + validateDictionary, + validateEncoding, + validateFunction, + validateInt32, + validateInteger, + validateNumber, + validateObject, + validateOneOf, + validatePlainFunction, + validatePort, + validateSignalName, + validateString, + validateUint32, + validateUndefined, + validateUnion, + validateAbortSignal, + validateLinkHeaderValue + }; + return exports$l; +} + +var exports$k = {}, + _dewExec$j = false; +function dew$j() { + if (_dewExec$j) return exports$k; + _dewExec$j = true; + const { + SymbolAsyncIterator, + SymbolIterator, + SymbolFor + } = dew$o(); + + // We need to use SymbolFor to make these globally available + // for interopt with readable-stream, i.e. readable-stream + // and node core needs to be able to read/write private state + // from each other for proper interoperability. + const kIsDestroyed = SymbolFor("nodejs.stream.destroyed"); + const kIsErrored = SymbolFor("nodejs.stream.errored"); + const kIsReadable = SymbolFor("nodejs.stream.readable"); + const kIsWritable = SymbolFor("nodejs.stream.writable"); + const kIsDisturbed = SymbolFor("nodejs.stream.disturbed"); + const kIsClosedPromise = SymbolFor("nodejs.webstream.isClosedPromise"); + const kControllerErrorFunction = SymbolFor("nodejs.webstream.controllerErrorFunction"); + function isReadableNodeStream(obj, strict = false) { + var _obj$_readableState; + return !!(obj && typeof obj.pipe === "function" && typeof obj.on === "function" && (!strict || typeof obj.pause === "function" && typeof obj.resume === "function") && (!obj._writableState || ((_obj$_readableState = obj._readableState) === null || _obj$_readableState === undefined ? undefined : _obj$_readableState.readable) !== false) && ( + // Duplex + !obj._writableState || obj._readableState) + // Writable has .pipe. + ); + } + function isWritableNodeStream(obj) { + var _obj$_writableState; + return !!(obj && typeof obj.write === "function" && typeof obj.on === "function" && (!obj._readableState || ((_obj$_writableState = obj._writableState) === null || _obj$_writableState === undefined ? undefined : _obj$_writableState.writable) !== false) + // Duplex + ); + } + function isDuplexNodeStream(obj) { + return !!(obj && typeof obj.pipe === "function" && obj._readableState && typeof obj.on === "function" && typeof obj.write === "function"); + } + function isNodeStream(obj) { + return obj && (obj._readableState || obj._writableState || typeof obj.write === "function" && typeof obj.on === "function" || typeof obj.pipe === "function" && typeof obj.on === "function"); + } + function isReadableStream(obj) { + return !!(obj && !isNodeStream(obj) && typeof obj.pipeThrough === "function" && typeof obj.getReader === "function" && typeof obj.cancel === "function"); + } + function isWritableStream(obj) { + return !!(obj && !isNodeStream(obj) && typeof obj.getWriter === "function" && typeof obj.abort === "function"); + } + function isTransformStream(obj) { + return !!(obj && !isNodeStream(obj) && typeof obj.readable === "object" && typeof obj.writable === "object"); + } + function isWebStream(obj) { + return isReadableStream(obj) || isWritableStream(obj) || isTransformStream(obj); + } + function isIterable(obj, isAsync) { + if (obj == null) return false; + if (isAsync === true) return typeof obj[SymbolAsyncIterator] === "function"; + if (isAsync === false) return typeof obj[SymbolIterator] === "function"; + return typeof obj[SymbolAsyncIterator] === "function" || typeof obj[SymbolIterator] === "function"; + } + function isDestroyed(stream) { + if (!isNodeStream(stream)) return null; + const wState = stream._writableState; + const rState = stream._readableState; + const state = wState || rState; + return !!(stream.destroyed || stream[kIsDestroyed] || state !== null && state !== undefined && state.destroyed); + } + + // Have been end():d. + function isWritableEnded(stream) { + if (!isWritableNodeStream(stream)) return null; + if (stream.writableEnded === true) return true; + const wState = stream._writableState; + if (wState !== null && wState !== undefined && wState.errored) return false; + if (typeof (wState === null || wState === undefined ? undefined : wState.ended) !== "boolean") return null; + return wState.ended; + } + + // Have emitted 'finish'. + function isWritableFinished(stream, strict) { + if (!isWritableNodeStream(stream)) return null; + if (stream.writableFinished === true) return true; + const wState = stream._writableState; + if (wState !== null && wState !== undefined && wState.errored) return false; + if (typeof (wState === null || wState === undefined ? undefined : wState.finished) !== "boolean") return null; + return !!(wState.finished || strict === false && wState.ended === true && wState.length === 0); + } + + // Have been push(null):d. + function isReadableEnded(stream) { + if (!isReadableNodeStream(stream)) return null; + if (stream.readableEnded === true) return true; + const rState = stream._readableState; + if (!rState || rState.errored) return false; + if (typeof (rState === null || rState === undefined ? undefined : rState.ended) !== "boolean") return null; + return rState.ended; + } + + // Have emitted 'end'. + function isReadableFinished(stream, strict) { + if (!isReadableNodeStream(stream)) return null; + const rState = stream._readableState; + if (rState !== null && rState !== undefined && rState.errored) return false; + if (typeof (rState === null || rState === undefined ? undefined : rState.endEmitted) !== "boolean") return null; + return !!(rState.endEmitted || strict === false && rState.ended === true && rState.length === 0); + } + function isReadable(stream) { + if (stream && stream[kIsReadable] != null) return stream[kIsReadable]; + if (typeof (stream === null || stream === undefined ? undefined : stream.readable) !== "boolean") return null; + if (isDestroyed(stream)) return false; + return isReadableNodeStream(stream) && stream.readable && !isReadableFinished(stream); + } + function isWritable(stream) { + if (stream && stream[kIsWritable] != null) return stream[kIsWritable]; + if (typeof (stream === null || stream === undefined ? undefined : stream.writable) !== "boolean") return null; + if (isDestroyed(stream)) return false; + return isWritableNodeStream(stream) && stream.writable && !isWritableEnded(stream); + } + function isFinished(stream, opts) { + if (!isNodeStream(stream)) { + return null; + } + if (isDestroyed(stream)) { + return true; + } + if ((opts === null || opts === undefined ? undefined : opts.readable) !== false && isReadable(stream)) { + return false; + } + if ((opts === null || opts === undefined ? undefined : opts.writable) !== false && isWritable(stream)) { + return false; + } + return true; + } + function isWritableErrored(stream) { + var _stream$_writableStat, _stream$_writableStat2; + if (!isNodeStream(stream)) { + return null; + } + if (stream.writableErrored) { + return stream.writableErrored; + } + return (_stream$_writableStat = (_stream$_writableStat2 = stream._writableState) === null || _stream$_writableStat2 === undefined ? undefined : _stream$_writableStat2.errored) !== null && _stream$_writableStat !== undefined ? _stream$_writableStat : null; + } + function isReadableErrored(stream) { + var _stream$_readableStat, _stream$_readableStat2; + if (!isNodeStream(stream)) { + return null; + } + if (stream.readableErrored) { + return stream.readableErrored; + } + return (_stream$_readableStat = (_stream$_readableStat2 = stream._readableState) === null || _stream$_readableStat2 === undefined ? undefined : _stream$_readableStat2.errored) !== null && _stream$_readableStat !== undefined ? _stream$_readableStat : null; + } + function isClosed(stream) { + if (!isNodeStream(stream)) { + return null; + } + if (typeof stream.closed === "boolean") { + return stream.closed; + } + const wState = stream._writableState; + const rState = stream._readableState; + if (typeof (wState === null || wState === undefined ? undefined : wState.closed) === "boolean" || typeof (rState === null || rState === undefined ? undefined : rState.closed) === "boolean") { + return (wState === null || wState === undefined ? undefined : wState.closed) || (rState === null || rState === undefined ? undefined : rState.closed); + } + if (typeof stream._closed === "boolean" && isOutgoingMessage(stream)) { + return stream._closed; + } + return null; + } + function isOutgoingMessage(stream) { + return typeof stream._closed === "boolean" && typeof stream._defaultKeepAlive === "boolean" && typeof stream._removedConnection === "boolean" && typeof stream._removedContLen === "boolean"; + } + function isServerResponse(stream) { + return typeof stream._sent100 === "boolean" && isOutgoingMessage(stream); + } + function isServerRequest(stream) { + var _stream$req; + return typeof stream._consuming === "boolean" && typeof stream._dumped === "boolean" && ((_stream$req = stream.req) === null || _stream$req === undefined ? undefined : _stream$req.upgradeOrConnect) === undefined; + } + function willEmitClose(stream) { + if (!isNodeStream(stream)) return null; + const wState = stream._writableState; + const rState = stream._readableState; + const state = wState || rState; + return !state && isServerResponse(stream) || !!(state && state.autoDestroy && state.emitClose && state.closed === false); + } + function isDisturbed(stream) { + var _stream$kIsDisturbed; + return !!(stream && ((_stream$kIsDisturbed = stream[kIsDisturbed]) !== null && _stream$kIsDisturbed !== undefined ? _stream$kIsDisturbed : stream.readableDidRead || stream.readableAborted)); + } + function isErrored(stream) { + var _ref, _ref2, _ref3, _ref4, _ref5, _stream$kIsErrored, _stream$_readableStat3, _stream$_writableStat3, _stream$_readableStat4, _stream$_writableStat4; + return !!(stream && ((_ref = (_ref2 = (_ref3 = (_ref4 = (_ref5 = (_stream$kIsErrored = stream[kIsErrored]) !== null && _stream$kIsErrored !== undefined ? _stream$kIsErrored : stream.readableErrored) !== null && _ref5 !== undefined ? _ref5 : stream.writableErrored) !== null && _ref4 !== undefined ? _ref4 : (_stream$_readableStat3 = stream._readableState) === null || _stream$_readableStat3 === undefined ? undefined : _stream$_readableStat3.errorEmitted) !== null && _ref3 !== undefined ? _ref3 : (_stream$_writableStat3 = stream._writableState) === null || _stream$_writableStat3 === undefined ? undefined : _stream$_writableStat3.errorEmitted) !== null && _ref2 !== undefined ? _ref2 : (_stream$_readableStat4 = stream._readableState) === null || _stream$_readableStat4 === undefined ? undefined : _stream$_readableStat4.errored) !== null && _ref !== undefined ? _ref : (_stream$_writableStat4 = stream._writableState) === null || _stream$_writableStat4 === undefined ? undefined : _stream$_writableStat4.errored)); + } + exports$k = { + isDestroyed, + kIsDestroyed, + isDisturbed, + kIsDisturbed, + isErrored, + kIsErrored, + isReadable, + kIsReadable, + kIsClosedPromise, + kControllerErrorFunction, + kIsWritable, + isClosed, + isDuplexNodeStream, + isFinished, + isIterable, + isReadableNodeStream, + isReadableStream, + isReadableEnded, + isReadableFinished, + isReadableErrored, + isNodeStream, + isWebStream, + isWritable, + isWritableNodeStream, + isWritableStream, + isWritableEnded, + isWritableFinished, + isWritableErrored, + isServerRequest, + isServerResponse, + willEmitClose, + isTransformStream + }; + return exports$k; +} + +var exports$j = {}, + _dewExec$i = false; +function dew$i() { + if (_dewExec$i) return exports$j; + _dewExec$i = true; + /* replacement start */ + + const process$1 = process + + /* replacement end */ + // Ported from https://github.com/mafintosh/end-of-stream with + // permission from the author, Mathias Buus (@mafintosh). + ; + const { + AbortError, + codes + } = dew$l(); + const { + ERR_INVALID_ARG_TYPE, + ERR_STREAM_PREMATURE_CLOSE + } = codes; + const { + kEmptyObject, + once + } = dew$m(); + const { + validateAbortSignal, + validateFunction, + validateObject, + validateBoolean + } = dew$k(); + const { + Promise, + PromisePrototypeThen, + SymbolDispose + } = dew$o(); + const { + isClosed, + isReadable, + isReadableNodeStream, + isReadableStream, + isReadableFinished, + isReadableErrored, + isWritable, + isWritableNodeStream, + isWritableStream, + isWritableFinished, + isWritableErrored, + isNodeStream, + willEmitClose: _willEmitClose, + kIsClosedPromise + } = dew$j(); + let addAbortListener; + function isRequest(stream) { + return stream.setHeader && typeof stream.abort === "function"; + } + const nop = () => {}; + function eos(stream, options, callback) { + var _options$readable, _options$writable; + if (arguments.length === 2) { + callback = options; + options = kEmptyObject; + } else if (options == null) { + options = kEmptyObject; + } else { + validateObject(options, "options"); + } + validateFunction(callback, "callback"); + validateAbortSignal(options.signal, "options.signal"); + callback = once(callback); + if (isReadableStream(stream) || isWritableStream(stream)) { + return eosWeb(stream, options, callback); + } + if (!isNodeStream(stream)) { + throw new ERR_INVALID_ARG_TYPE("stream", ["ReadableStream", "WritableStream", "Stream"], stream); + } + const readable = (_options$readable = options.readable) !== null && _options$readable !== undefined ? _options$readable : isReadableNodeStream(stream); + const writable = (_options$writable = options.writable) !== null && _options$writable !== undefined ? _options$writable : isWritableNodeStream(stream); + const wState = stream._writableState; + const rState = stream._readableState; + const onlegacyfinish = () => { + if (!stream.writable) { + onfinish(); + } + }; + + // TODO (ronag): Improve soft detection to include core modules and + // common ecosystem modules that do properly emit 'close' but fail + // this generic check. + let willEmitClose = _willEmitClose(stream) && isReadableNodeStream(stream) === readable && isWritableNodeStream(stream) === writable; + let writableFinished = isWritableFinished(stream, false); + const onfinish = () => { + writableFinished = true; + // Stream should not be destroyed here. If it is that + // means that user space is doing something differently and + // we cannot trust willEmitClose. + if (stream.destroyed) { + willEmitClose = false; + } + if (willEmitClose && (!stream.readable || readable)) { + return; + } + if (!readable || readableFinished) { + callback.call(stream); + } + }; + let readableFinished = isReadableFinished(stream, false); + const onend = () => { + readableFinished = true; + // Stream should not be destroyed here. If it is that + // means that user space is doing something differently and + // we cannot trust willEmitClose. + if (stream.destroyed) { + willEmitClose = false; + } + if (willEmitClose && (!stream.writable || writable)) { + return; + } + if (!writable || writableFinished) { + callback.call(stream); + } + }; + const onerror = err => { + callback.call(stream, err); + }; + let closed = isClosed(stream); + const onclose = () => { + closed = true; + const errored = isWritableErrored(stream) || isReadableErrored(stream); + if (errored && typeof errored !== "boolean") { + return callback.call(stream, errored); + } + if (readable && !readableFinished && isReadableNodeStream(stream, true)) { + if (!isReadableFinished(stream, false)) return callback.call(stream, new ERR_STREAM_PREMATURE_CLOSE()); + } + if (writable && !writableFinished) { + if (!isWritableFinished(stream, false)) return callback.call(stream, new ERR_STREAM_PREMATURE_CLOSE()); + } + callback.call(stream); + }; + const onclosed = () => { + closed = true; + const errored = isWritableErrored(stream) || isReadableErrored(stream); + if (errored && typeof errored !== "boolean") { + return callback.call(stream, errored); + } + callback.call(stream); + }; + const onrequest = () => { + stream.req.on("finish", onfinish); + }; + if (isRequest(stream)) { + stream.on("complete", onfinish); + if (!willEmitClose) { + stream.on("abort", onclose); + } + if (stream.req) { + onrequest(); + } else { + stream.on("request", onrequest); + } + } else if (writable && !wState) { + // legacy streams + stream.on("end", onlegacyfinish); + stream.on("close", onlegacyfinish); + } + + // Not all streams will emit 'close' after 'aborted'. + if (!willEmitClose && typeof stream.aborted === "boolean") { + stream.on("aborted", onclose); + } + stream.on("end", onend); + stream.on("finish", onfinish); + if (options.error !== false) { + stream.on("error", onerror); + } + stream.on("close", onclose); + if (closed) { + process$1.nextTick(onclose); + } else if (wState !== null && wState !== undefined && wState.errorEmitted || rState !== null && rState !== undefined && rState.errorEmitted) { + if (!willEmitClose) { + process$1.nextTick(onclosed); + } + } else if (!readable && (!willEmitClose || isReadable(stream)) && (writableFinished || isWritable(stream) === false)) { + process$1.nextTick(onclosed); + } else if (!writable && (!willEmitClose || isWritable(stream)) && (readableFinished || isReadable(stream) === false)) { + process$1.nextTick(onclosed); + } else if (rState && stream.req && stream.aborted) { + process$1.nextTick(onclosed); + } + const cleanup = () => { + callback = nop; + stream.removeListener("aborted", onclose); + stream.removeListener("complete", onfinish); + stream.removeListener("abort", onclose); + stream.removeListener("request", onrequest); + if (stream.req) stream.req.removeListener("finish", onfinish); + stream.removeListener("end", onlegacyfinish); + stream.removeListener("close", onlegacyfinish); + stream.removeListener("finish", onfinish); + stream.removeListener("end", onend); + stream.removeListener("error", onerror); + stream.removeListener("close", onclose); + }; + if (options.signal && !closed) { + const abort = () => { + // Keep it because cleanup removes it. + const endCallback = callback; + cleanup(); + endCallback.call(stream, new AbortError(undefined, { + cause: options.signal.reason + })); + }; + if (options.signal.aborted) { + process$1.nextTick(abort); + } else { + addAbortListener = addAbortListener || dew$m().addAbortListener; + const disposable = addAbortListener(options.signal, abort); + const originalCallback = callback; + callback = once((...args) => { + disposable[SymbolDispose](); + originalCallback.apply(stream, args); + }); + } + } + return cleanup; + } + function eosWeb(stream, options, callback) { + let isAborted = false; + let abort = nop; + if (options.signal) { + abort = () => { + isAborted = true; + callback.call(stream, new AbortError(undefined, { + cause: options.signal.reason + })); + }; + if (options.signal.aborted) { + process$1.nextTick(abort); + } else { + addAbortListener = addAbortListener || dew$m().addAbortListener; + const disposable = addAbortListener(options.signal, abort); + const originalCallback = callback; + callback = once((...args) => { + disposable[SymbolDispose](); + originalCallback.apply(stream, args); + }); + } + } + const resolverFn = (...args) => { + if (!isAborted) { + process$1.nextTick(() => callback.apply(stream, args)); + } + }; + PromisePrototypeThen(stream[kIsClosedPromise].promise, resolverFn, resolverFn); + return nop; + } + function finished(stream, opts) { + var _opts; + let autoCleanup = false; + if (opts === null) { + opts = kEmptyObject; + } + if ((_opts = opts) !== null && _opts !== undefined && _opts.cleanup) { + validateBoolean(opts.cleanup, "cleanup"); + autoCleanup = opts.cleanup; + } + return new Promise((resolve, reject) => { + const cleanup = eos(stream, opts, err => { + if (autoCleanup) { + cleanup(); + } + if (err) { + reject(err); + } else { + resolve(); + } + }); + }); + } + exports$j = eos; + exports$j.finished = finished; + return exports$j; +} + +var exports$i = {}, + _dewExec$h = false; +function dew$h() { + if (_dewExec$h) return exports$i; + _dewExec$h = true; + /* replacement start */ + + const process$1 = process; + + /* replacement end */ + + const { + aggregateTwoErrors, + codes: { + ERR_MULTIPLE_CALLBACK + }, + AbortError + } = dew$l(); + const { + Symbol + } = dew$o(); + const { + kIsDestroyed, + isDestroyed, + isFinished, + isServerRequest + } = dew$j(); + const kDestroy = Symbol("kDestroy"); + const kConstruct = Symbol("kConstruct"); + function checkError(err, w, r) { + if (err) { + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 + err.stack; // eslint-disable-line no-unused-expressions + + if (w && !w.errored) { + w.errored = err; + } + if (r && !r.errored) { + r.errored = err; + } + } + } + + // Backwards compat. cb() is undocumented and unused in core but + // unfortunately might be used by modules. + function destroy(err, cb) { + const r = this._readableState; + const w = this._writableState; + // With duplex streams we use the writable side for state. + const s = w || r; + if (w !== null && w !== undefined && w.destroyed || r !== null && r !== undefined && r.destroyed) { + if (typeof cb === "function") { + cb(); + } + return this; + } + + // We set destroyed to true before firing error callbacks in order + // to make it re-entrance safe in case destroy() is called within callbacks + checkError(err, w, r); + if (w) { + w.destroyed = true; + } + if (r) { + r.destroyed = true; + } + + // If still constructing then defer calling _destroy. + if (!s.constructed) { + this.once(kDestroy, function (er) { + _destroy(this, aggregateTwoErrors(er, err), cb); + }); + } else { + _destroy(this, err, cb); + } + return this; + } + function _destroy(self, err, cb) { + let called = false; + function onDestroy(err) { + if (called) { + return; + } + called = true; + const r = self._readableState; + const w = self._writableState; + checkError(err, w, r); + if (w) { + w.closed = true; + } + if (r) { + r.closed = true; + } + if (typeof cb === "function") { + cb(err); + } + if (err) { + process$1.nextTick(emitErrorCloseNT, self, err); + } else { + process$1.nextTick(emitCloseNT, self); + } + } + try { + self._destroy(err || null, onDestroy); + } catch (err) { + onDestroy(err); + } + } + function emitErrorCloseNT(self, err) { + emitErrorNT(self, err); + emitCloseNT(self); + } + function emitCloseNT(self) { + const r = self._readableState; + const w = self._writableState; + if (w) { + w.closeEmitted = true; + } + if (r) { + r.closeEmitted = true; + } + if (w !== null && w !== undefined && w.emitClose || r !== null && r !== undefined && r.emitClose) { + self.emit("close"); + } + } + function emitErrorNT(self, err) { + const r = self._readableState; + const w = self._writableState; + if (w !== null && w !== undefined && w.errorEmitted || r !== null && r !== undefined && r.errorEmitted) { + return; + } + if (w) { + w.errorEmitted = true; + } + if (r) { + r.errorEmitted = true; + } + self.emit("error", err); + } + function undestroy() { + const r = this._readableState; + const w = this._writableState; + if (r) { + r.constructed = true; + r.closed = false; + r.closeEmitted = false; + r.destroyed = false; + r.errored = null; + r.errorEmitted = false; + r.reading = false; + r.ended = r.readable === false; + r.endEmitted = r.readable === false; + } + if (w) { + w.constructed = true; + w.destroyed = false; + w.closed = false; + w.closeEmitted = false; + w.errored = null; + w.errorEmitted = false; + w.finalCalled = false; + w.prefinished = false; + w.ended = w.writable === false; + w.ending = w.writable === false; + w.finished = w.writable === false; + } + } + function errorOrDestroy(stream, err, sync) { + // We have tests that rely on errors being emitted + // in the same tick, so changing this is semver major. + // For now when you opt-in to autoDestroy we allow + // the error to be emitted nextTick. In a future + // semver major update we should change the default to this. + + const r = stream._readableState; + const w = stream._writableState; + if (w !== null && w !== undefined && w.destroyed || r !== null && r !== undefined && r.destroyed) { + return this; + } + if (r !== null && r !== undefined && r.autoDestroy || w !== null && w !== undefined && w.autoDestroy) stream.destroy(err);else if (err) { + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 + err.stack; // eslint-disable-line no-unused-expressions + + if (w && !w.errored) { + w.errored = err; + } + if (r && !r.errored) { + r.errored = err; + } + if (sync) { + process$1.nextTick(emitErrorNT, stream, err); + } else { + emitErrorNT(stream, err); + } + } + } + function construct(stream, cb) { + if (typeof stream._construct !== "function") { + return; + } + const r = stream._readableState; + const w = stream._writableState; + if (r) { + r.constructed = false; + } + if (w) { + w.constructed = false; + } + stream.once(kConstruct, cb); + if (stream.listenerCount(kConstruct) > 1) { + // Duplex + return; + } + process$1.nextTick(constructNT, stream); + } + function constructNT(stream) { + let called = false; + function onConstruct(err) { + if (called) { + errorOrDestroy(stream, err !== null && err !== undefined ? err : new ERR_MULTIPLE_CALLBACK()); + return; + } + called = true; + const r = stream._readableState; + const w = stream._writableState; + const s = w || r; + if (r) { + r.constructed = true; + } + if (w) { + w.constructed = true; + } + if (s.destroyed) { + stream.emit(kDestroy, err); + } else if (err) { + errorOrDestroy(stream, err, true); + } else { + process$1.nextTick(emitConstructNT, stream); + } + } + try { + stream._construct(err => { + process$1.nextTick(onConstruct, err); + }); + } catch (err) { + process$1.nextTick(onConstruct, err); + } + } + function emitConstructNT(stream) { + stream.emit(kConstruct); + } + function isRequest(stream) { + return (stream === null || stream === undefined ? undefined : stream.setHeader) && typeof stream.abort === "function"; + } + function emitCloseLegacy(stream) { + stream.emit("close"); + } + function emitErrorCloseLegacy(stream, err) { + stream.emit("error", err); + process$1.nextTick(emitCloseLegacy, stream); + } + + // Normalize destroy for legacy. + function destroyer(stream, err) { + if (!stream || isDestroyed(stream)) { + return; + } + if (!err && !isFinished(stream)) { + err = new AbortError(); + } + + // TODO: Remove isRequest branches. + if (isServerRequest(stream)) { + stream.socket = null; + stream.destroy(err); + } else if (isRequest(stream)) { + stream.abort(); + } else if (isRequest(stream.req)) { + stream.req.abort(); + } else if (typeof stream.destroy === "function") { + stream.destroy(err); + } else if (typeof stream.close === "function") { + // TODO: Don't lose err? + stream.close(); + } else if (err) { + process$1.nextTick(emitErrorCloseLegacy, stream, err); + } else { + process$1.nextTick(emitCloseLegacy, stream); + } + if (!stream.destroyed) { + stream[kIsDestroyed] = true; + } + } + exports$i = { + construct, + destroyer, + destroy, + undestroy, + errorOrDestroy + }; + return exports$i; +} + +var exports$h = {}, + _dewExec$g = false; +function dew$g() { + if (_dewExec$g) return exports$h; + _dewExec$g = true; + const { + ArrayIsArray, + ObjectSetPrototypeOf + } = dew$o(); + const { + EventEmitter: EE + } = exports$q; + function Stream(opts) { + EE.call(this, opts); + } + ObjectSetPrototypeOf(Stream.prototype, EE.prototype); + ObjectSetPrototypeOf(Stream, EE); + Stream.prototype.pipe = function (dest, options) { + const source = this; + function ondata(chunk) { + if (dest.writable && dest.write(chunk) === false && source.pause) { + source.pause(); + } + } + source.on("data", ondata); + function ondrain() { + if (source.readable && source.resume) { + source.resume(); + } + } + dest.on("drain", ondrain); + + // If the 'end' option is not supplied, dest.end() will be called when + // source gets the 'end' or 'close' events. Only dest.end() once. + if (!dest._isStdio && (!options || options.end !== false)) { + source.on("end", onend); + source.on("close", onclose); + } + let didOnEnd = false; + function onend() { + if (didOnEnd) return; + didOnEnd = true; + dest.end(); + } + function onclose() { + if (didOnEnd) return; + didOnEnd = true; + if (typeof dest.destroy === "function") dest.destroy(); + } + + // Don't leave dangling pipes when there are errors. + function onerror(er) { + cleanup(); + if (EE.listenerCount(this, "error") === 0) { + this.emit("error", er); + } + } + prependListener(source, "error", onerror); + prependListener(dest, "error", onerror); + + // Remove all the event listeners that were added. + function cleanup() { + source.removeListener("data", ondata); + dest.removeListener("drain", ondrain); + source.removeListener("end", onend); + source.removeListener("close", onclose); + source.removeListener("error", onerror); + dest.removeListener("error", onerror); + source.removeListener("end", cleanup); + source.removeListener("close", cleanup); + dest.removeListener("close", cleanup); + } + source.on("end", cleanup); + source.on("close", cleanup); + dest.on("close", cleanup); + dest.emit("pipe", source); + + // Allow for unix-like usage: A.pipe(B).pipe(C) + return dest; + }; + function prependListener(emitter, event, fn) { + // Sadly this is not cacheable as some libraries bundle their own + // event emitter implementation with them. + if (typeof emitter.prependListener === "function") return emitter.prependListener(event, fn); + + // This is a hack to make sure that our error handler is attached before any + // userland ones. NEVER DO THIS. This is here only because this code needs + // to continue to work with older versions of Node.js that do not include + // the prependListener() method. The goal is to eventually remove this hack. + if (!emitter._events || !emitter._events[event]) emitter.on(event, fn);else if (ArrayIsArray(emitter._events[event])) emitter._events[event].unshift(fn);else emitter._events[event] = [fn, emitter._events[event]]; + } + exports$h = { + Stream, + prependListener + }; + return exports$h; +} + +var exports$g = {}, + _dewExec$f = false; +function dew$f() { + if (_dewExec$f) return exports$g; + _dewExec$f = true; + const { + SymbolDispose + } = dew$o(); + const { + AbortError, + codes + } = dew$l(); + const { + isNodeStream, + isWebStream, + kControllerErrorFunction + } = dew$j(); + const eos = dew$i(); + const { + ERR_INVALID_ARG_TYPE + } = codes; + let addAbortListener; + + // This method is inlined here for readable-stream + // It also does not allow for signal to not exist on the stream + // https://github.com/nodejs/node/pull/36061#discussion_r533718029 + const validateAbortSignal = (signal, name) => { + if (typeof signal !== "object" || !("aborted" in signal)) { + throw new ERR_INVALID_ARG_TYPE(name, "AbortSignal", signal); + } + }; + exports$g.addAbortSignal = function addAbortSignal(signal, stream) { + validateAbortSignal(signal, "signal"); + if (!isNodeStream(stream) && !isWebStream(stream)) { + throw new ERR_INVALID_ARG_TYPE("stream", ["ReadableStream", "WritableStream", "Stream"], stream); + } + return exports$g.addAbortSignalNoValidate(signal, stream); + }; + exports$g.addAbortSignalNoValidate = function (signal, stream) { + if (typeof signal !== "object" || !("aborted" in signal)) { + return stream; + } + const onAbort = isNodeStream(stream) ? () => { + stream.destroy(new AbortError(undefined, { + cause: signal.reason + })); + } : () => { + stream[kControllerErrorFunction](new AbortError(undefined, { + cause: signal.reason + })); + }; + if (signal.aborted) { + onAbort(); + } else { + addAbortListener = addAbortListener || dew$m().addAbortListener; + const disposable = addAbortListener(signal, onAbort); + eos(stream, disposable[SymbolDispose]); + } + return stream; + }; + return exports$g; +} + +var exports$f = {}, + _dewExec$e = false; +function dew$e() { + if (_dewExec$e) return exports$f; + _dewExec$e = true; + const { + StringPrototypeSlice, + SymbolIterator, + TypedArrayPrototypeSet, + Uint8Array + } = dew$o(); + const { + Buffer + } = dew$p(); + const { + inspect + } = dew$m(); + exports$f = class BufferList { + constructor() { + this.head = null; + this.tail = null; + this.length = 0; + } + push(v) { + const entry = { + data: v, + next: null + }; + if (this.length > 0) this.tail.next = entry;else this.head = entry; + this.tail = entry; + ++this.length; + } + unshift(v) { + const entry = { + data: v, + next: this.head + }; + if (this.length === 0) this.tail = entry; + this.head = entry; + ++this.length; + } + shift() { + if (this.length === 0) return; + const ret = this.head.data; + if (this.length === 1) this.head = this.tail = null;else this.head = this.head.next; + --this.length; + return ret; + } + clear() { + this.head = this.tail = null; + this.length = 0; + } + join(s) { + if (this.length === 0) return ""; + let p = this.head; + let ret = "" + p.data; + while ((p = p.next) !== null) ret += s + p.data; + return ret; + } + concat(n) { + if (this.length === 0) return Buffer.alloc(0); + const ret = Buffer.allocUnsafe(n >>> 0); + let p = this.head; + let i = 0; + while (p) { + TypedArrayPrototypeSet(ret, p.data, i); + i += p.data.length; + p = p.next; + } + return ret; + } + + // Consumes a specified amount of bytes or characters from the buffered data. + consume(n, hasStrings) { + const data = this.head.data; + if (n < data.length) { + // `slice` is the same for buffers and strings. + const slice = data.slice(0, n); + this.head.data = data.slice(n); + return slice; + } + if (n === data.length) { + // First chunk is a perfect match. + return this.shift(); + } + // Result spans more than one buffer. + return hasStrings ? this._getString(n) : this._getBuffer(n); + } + first() { + return this.head.data; + } + *[SymbolIterator]() { + for (let p = this.head; p; p = p.next) { + yield p.data; + } + } + + // Consumes a specified amount of characters from the buffered data. + _getString(n) { + let ret = ""; + let p = this.head; + let c = 0; + do { + const str = p.data; + if (n > str.length) { + ret += str; + n -= str.length; + } else { + if (n === str.length) { + ret += str; + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + ret += StringPrototypeSlice(str, 0, n); + this.head = p; + p.data = StringPrototypeSlice(str, n); + } + break; + } + ++c; + } while ((p = p.next) !== null); + this.length -= c; + return ret; + } + + // Consumes a specified amount of bytes from the buffered data. + _getBuffer(n) { + const ret = Buffer.allocUnsafe(n); + const retLen = n; + let p = this.head; + let c = 0; + do { + const buf = p.data; + if (n > buf.length) { + TypedArrayPrototypeSet(ret, buf, retLen - n); + n -= buf.length; + } else { + if (n === buf.length) { + TypedArrayPrototypeSet(ret, buf, retLen - n); + ++c; + if (p.next) this.head = p.next;else this.head = this.tail = null; + } else { + TypedArrayPrototypeSet(ret, new Uint8Array(buf.buffer, buf.byteOffset, n), retLen - n); + this.head = p; + p.data = buf.slice(n); + } + break; + } + ++c; + } while ((p = p.next) !== null); + this.length -= c; + return ret; + } + + // Make sure the linked list only shows the minimal necessary information. + [Symbol.for("nodejs.util.inspect.custom")](_, options) { + return inspect(this, { + ...options, + // Only inspect one level. + depth: 0, + // It should not recurse. + customInspect: false + }); + } + }; + return exports$f; +} + +var exports$e = {}, + _dewExec$d = false; +function dew$d() { + if (_dewExec$d) return exports$e; + _dewExec$d = true; + const { + MathFloor, + NumberIsInteger + } = dew$o(); + const { + validateInteger + } = dew$k(); + const { + ERR_INVALID_ARG_VALUE + } = dew$l().codes; + let defaultHighWaterMarkBytes = 16 * 1024; + let defaultHighWaterMarkObjectMode = 16; + function highWaterMarkFrom(options, isDuplex, duplexKey) { + return options.highWaterMark != null ? options.highWaterMark : isDuplex ? options[duplexKey] : null; + } + function getDefaultHighWaterMark(objectMode) { + return objectMode ? defaultHighWaterMarkObjectMode : defaultHighWaterMarkBytes; + } + function setDefaultHighWaterMark(objectMode, value) { + validateInteger(value, "value", 0); + if (objectMode) { + defaultHighWaterMarkObjectMode = value; + } else { + defaultHighWaterMarkBytes = value; + } + } + function getHighWaterMark(state, options, duplexKey, isDuplex) { + const hwm = highWaterMarkFrom(options, isDuplex, duplexKey); + if (hwm != null) { + if (!NumberIsInteger(hwm) || hwm < 0) { + const name = isDuplex ? `options.${duplexKey}` : "options.highWaterMark"; + throw new ERR_INVALID_ARG_VALUE(name, hwm); + } + return MathFloor(hwm); + } + + // Default value + return getDefaultHighWaterMark(state.objectMode); + } + exports$e = { + getHighWaterMark, + getDefaultHighWaterMark, + setDefaultHighWaterMark + }; + return exports$e; +} + +var exports$d = {}, + _dewExec$c = false; +function dew$c() { + if (_dewExec$c) return exports$d; + _dewExec$c = true; + /* replacement start */ + + const process$1 = process; + + /* replacement end */ + + const { + PromisePrototypeThen, + SymbolAsyncIterator, + SymbolIterator + } = dew$o(); + const { + Buffer + } = dew$p(); + const { + ERR_INVALID_ARG_TYPE, + ERR_STREAM_NULL_VALUES + } = dew$l().codes; + function from(Readable, iterable, opts) { + let iterator; + if (typeof iterable === "string" || iterable instanceof Buffer) { + return new Readable({ + objectMode: true, + ...opts, + read() { + this.push(iterable); + this.push(null); + } + }); + } + let isAsync; + if (iterable && iterable[SymbolAsyncIterator]) { + isAsync = true; + iterator = iterable[SymbolAsyncIterator](); + } else if (iterable && iterable[SymbolIterator]) { + isAsync = false; + iterator = iterable[SymbolIterator](); + } else { + throw new ERR_INVALID_ARG_TYPE("iterable", ["Iterable"], iterable); + } + const readable = new Readable({ + objectMode: true, + highWaterMark: 1, + // TODO(ronag): What options should be allowed? + ...opts + }); + + // Flag to protect against _read + // being called before last iteration completion. + let reading = false; + readable._read = function () { + if (!reading) { + reading = true; + next(); + } + }; + readable._destroy = function (error, cb) { + PromisePrototypeThen(close(error), () => process$1.nextTick(cb, error), + // nextTick is here in case cb throws + e => process$1.nextTick(cb, e || error)); + }; + async function close(error) { + const hadError = error !== undefined && error !== null; + const hasThrow = typeof iterator.throw === "function"; + if (hadError && hasThrow) { + const { + value, + done + } = await iterator.throw(error); + await value; + if (done) { + return; + } + } + if (typeof iterator.return === "function") { + const { + value + } = await iterator.return(); + await value; + } + } + async function next() { + for (;;) { + try { + const { + value, + done + } = isAsync ? await iterator.next() : iterator.next(); + if (done) { + readable.push(null); + } else { + const res = value && typeof value.then === "function" ? await value : value; + if (res === null) { + reading = false; + throw new ERR_STREAM_NULL_VALUES(); + } else if (readable.push(res)) { + continue; + } else { + reading = false; + } + } + } catch (err) { + readable.destroy(err); + } + break; + } + } + return readable; + } + exports$d = from; + return exports$d; +} + +var exports$c = {}, + _dewExec$b = false; +var _global$2 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$b() { + if (_dewExec$b) return exports$c; + _dewExec$b = true; + /* replacement start */ + + const process$1 = process + + /* replacement end */ + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + ; + const { + ArrayPrototypeIndexOf, + NumberIsInteger, + NumberIsNaN, + NumberParseInt, + ObjectDefineProperties, + ObjectKeys, + ObjectSetPrototypeOf, + Promise, + SafeSet, + SymbolAsyncDispose, + SymbolAsyncIterator, + Symbol + } = dew$o(); + exports$c = Readable; + Readable.ReadableState = ReadableState; + const { + EventEmitter: EE + } = exports$q; + const { + Stream, + prependListener + } = dew$g(); + const { + Buffer + } = dew$p(); + const { + addAbortSignal + } = dew$f(); + const eos = dew$i(); + let debug = dew$m().debuglog("stream", fn => { + debug = fn; + }); + const BufferList = dew$e(); + const destroyImpl = dew$h(); + const { + getHighWaterMark, + getDefaultHighWaterMark + } = dew$d(); + const { + aggregateTwoErrors, + codes: { + ERR_INVALID_ARG_TYPE, + ERR_METHOD_NOT_IMPLEMENTED, + ERR_OUT_OF_RANGE, + ERR_STREAM_PUSH_AFTER_EOF, + ERR_STREAM_UNSHIFT_AFTER_END_EVENT + }, + AbortError + } = dew$l(); + const { + validateObject + } = dew$k(); + const kPaused = Symbol("kPaused"); + const { + StringDecoder + } = exports$r; + const from = dew$c(); + ObjectSetPrototypeOf(Readable.prototype, Stream.prototype); + ObjectSetPrototypeOf(Readable, Stream); + const nop = () => {}; + const { + errorOrDestroy + } = destroyImpl; + const kObjectMode = 1 << 0; + const kEnded = 1 << 1; + const kEndEmitted = 1 << 2; + const kReading = 1 << 3; + const kConstructed = 1 << 4; + const kSync = 1 << 5; + const kNeedReadable = 1 << 6; + const kEmittedReadable = 1 << 7; + const kReadableListening = 1 << 8; + const kResumeScheduled = 1 << 9; + const kErrorEmitted = 1 << 10; + const kEmitClose = 1 << 11; + const kAutoDestroy = 1 << 12; + const kDestroyed = 1 << 13; + const kClosed = 1 << 14; + const kCloseEmitted = 1 << 15; + const kMultiAwaitDrain = 1 << 16; + const kReadingMore = 1 << 17; + const kDataEmitted = 1 << 18; + + // TODO(benjamingr) it is likely slower to do it this way than with free functions + function makeBitMapDescriptor(bit) { + return { + enumerable: false, + get() { + return ((this || _global$2).state & bit) !== 0; + }, + set(value) { + if (value) (this || _global$2).state |= bit;else (this || _global$2).state &= ~bit; + } + }; + } + ObjectDefineProperties(ReadableState.prototype, { + objectMode: makeBitMapDescriptor(kObjectMode), + ended: makeBitMapDescriptor(kEnded), + endEmitted: makeBitMapDescriptor(kEndEmitted), + reading: makeBitMapDescriptor(kReading), + // Stream is still being constructed and cannot be + // destroyed until construction finished or failed. + // Async construction is opt in, therefore we start as + // constructed. + constructed: makeBitMapDescriptor(kConstructed), + // A flag to be able to tell if the event 'readable'/'data' is emitted + // immediately, or on a later tick. We set this to true at first, because + // any actions that shouldn't happen until "later" should generally also + // not happen before the first read call. + sync: makeBitMapDescriptor(kSync), + // Whenever we return null, then we set a flag to say + // that we're awaiting a 'readable' event emission. + needReadable: makeBitMapDescriptor(kNeedReadable), + emittedReadable: makeBitMapDescriptor(kEmittedReadable), + readableListening: makeBitMapDescriptor(kReadableListening), + resumeScheduled: makeBitMapDescriptor(kResumeScheduled), + // True if the error was already emitted and should not be thrown again. + errorEmitted: makeBitMapDescriptor(kErrorEmitted), + emitClose: makeBitMapDescriptor(kEmitClose), + autoDestroy: makeBitMapDescriptor(kAutoDestroy), + // Has it been destroyed. + destroyed: makeBitMapDescriptor(kDestroyed), + // Indicates whether the stream has finished destroying. + closed: makeBitMapDescriptor(kClosed), + // True if close has been emitted or would have been emitted + // depending on emitClose. + closeEmitted: makeBitMapDescriptor(kCloseEmitted), + multiAwaitDrain: makeBitMapDescriptor(kMultiAwaitDrain), + // If true, a maybeReadMore has been scheduled. + readingMore: makeBitMapDescriptor(kReadingMore), + dataEmitted: makeBitMapDescriptor(kDataEmitted) + }); + function ReadableState(options, stream, isDuplex) { + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream. + // These options can be provided separately as readableXXX and writableXXX. + if (typeof isDuplex !== "boolean") isDuplex = stream instanceof dew$8(); + + // Bit map field to store ReadableState more effciently with 1 bit per field + // instead of a V8 slot per field. + (this || _global$2).state = kEmitClose | kAutoDestroy | kConstructed | kSync; + // Object stream flag. Used to make read(n) ignore n and to + // make all the buffer merging and length checks go away. + if (options && options.objectMode) (this || _global$2).state |= kObjectMode; + if (isDuplex && options && options.readableObjectMode) (this || _global$2).state |= kObjectMode; + + // The point at which it stops calling _read() to fill the buffer + // Note: 0 is a valid value, means "don't call _read preemptively ever" + (this || _global$2).highWaterMark = options ? getHighWaterMark(this || _global$2, options, "readableHighWaterMark", isDuplex) : getDefaultHighWaterMark(false); + + // A linked list is used to store data chunks instead of an array because the + // linked list can remove elements from the beginning faster than + // array.shift(). + (this || _global$2).buffer = new BufferList(); + (this || _global$2).length = 0; + (this || _global$2).pipes = []; + (this || _global$2).flowing = null; + (this || _global$2)[kPaused] = null; + + // Should close be emitted on destroy. Defaults to true. + if (options && options.emitClose === false) (this || _global$2).state &= ~kEmitClose; + + // Should .destroy() be called after 'end' (and potentially 'finish'). + if (options && options.autoDestroy === false) (this || _global$2).state &= ~kAutoDestroy; + + // Indicates whether the stream has errored. When true no further + // _read calls, 'data' or 'readable' events should occur. This is needed + // since when autoDestroy is disabled we need a way to tell whether the + // stream has failed. + (this || _global$2).errored = null; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + (this || _global$2).defaultEncoding = options && options.defaultEncoding || "utf8"; + + // Ref the piped dest which we need a drain event on it + // type: null | Writable | Set. + (this || _global$2).awaitDrainWriters = null; + (this || _global$2).decoder = null; + (this || _global$2).encoding = null; + if (options && options.encoding) { + (this || _global$2).decoder = new StringDecoder(options.encoding); + (this || _global$2).encoding = options.encoding; + } + } + function Readable(options) { + if (!((this || _global$2) instanceof Readable)) return new Readable(options); + + // Checking for a Stream.Duplex instance is faster here instead of inside + // the ReadableState constructor, at least with V8 6.5. + const isDuplex = (this || _global$2) instanceof dew$8(); + (this || _global$2)._readableState = new ReadableState(options, this || _global$2, isDuplex); + if (options) { + if (typeof options.read === "function") (this || _global$2)._read = options.read; + if (typeof options.destroy === "function") (this || _global$2)._destroy = options.destroy; + if (typeof options.construct === "function") (this || _global$2)._construct = options.construct; + if (options.signal && !isDuplex) addAbortSignal(options.signal, this || _global$2); + } + Stream.call(this || _global$2, options); + destroyImpl.construct(this || _global$2, () => { + if ((this || _global$2)._readableState.needReadable) { + maybeReadMore(this || _global$2, (this || _global$2)._readableState); + } + }); + } + Readable.prototype.destroy = destroyImpl.destroy; + Readable.prototype._undestroy = destroyImpl.undestroy; + Readable.prototype._destroy = function (err, cb) { + cb(err); + }; + Readable.prototype[EE.captureRejectionSymbol] = function (err) { + this.destroy(err); + }; + Readable.prototype[SymbolAsyncDispose] = function () { + let error; + if (!(this || _global$2).destroyed) { + error = (this || _global$2).readableEnded ? null : new AbortError(); + this.destroy(error); + } + return new Promise((resolve, reject) => eos(this || _global$2, err => err && err !== error ? reject(err) : resolve(null))); + }; + + // Manually shove something into the read() buffer. + // This returns true if the highWaterMark has not been hit yet, + // similar to how Writable.write() returns true if you should + // write() some more. + Readable.prototype.push = function (chunk, encoding) { + return readableAddChunk(this || _global$2, chunk, encoding, false); + }; + + // Unshift should *always* be something directly out of read(). + Readable.prototype.unshift = function (chunk, encoding) { + return readableAddChunk(this || _global$2, chunk, encoding, true); + }; + function readableAddChunk(stream, chunk, encoding, addToFront) { + debug("readableAddChunk", chunk); + const state = stream._readableState; + let err; + if ((state.state & kObjectMode) === 0) { + if (typeof chunk === "string") { + encoding = encoding || state.defaultEncoding; + if (state.encoding !== encoding) { + if (addToFront && state.encoding) { + // When unshifting, if state.encoding is set, we have to save + // the string in the BufferList with the state encoding. + chunk = Buffer.from(chunk, encoding).toString(state.encoding); + } else { + chunk = Buffer.from(chunk, encoding); + encoding = ""; + } + } + } else if (chunk instanceof Buffer) { + encoding = ""; + } else if (Stream._isUint8Array(chunk)) { + chunk = Stream._uint8ArrayToBuffer(chunk); + encoding = ""; + } else if (chunk != null) { + err = new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk); + } + } + if (err) { + errorOrDestroy(stream, err); + } else if (chunk === null) { + state.state &= ~kReading; + onEofChunk(stream, state); + } else if ((state.state & kObjectMode) !== 0 || chunk && chunk.length > 0) { + if (addToFront) { + if ((state.state & kEndEmitted) !== 0) errorOrDestroy(stream, new ERR_STREAM_UNSHIFT_AFTER_END_EVENT());else if (state.destroyed || state.errored) return false;else addChunk(stream, state, chunk, true); + } else if (state.ended) { + errorOrDestroy(stream, new ERR_STREAM_PUSH_AFTER_EOF()); + } else if (state.destroyed || state.errored) { + return false; + } else { + state.state &= ~kReading; + if (state.decoder && !encoding) { + chunk = state.decoder.write(chunk); + if (state.objectMode || chunk.length !== 0) addChunk(stream, state, chunk, false);else maybeReadMore(stream, state); + } else { + addChunk(stream, state, chunk, false); + } + } + } else if (!addToFront) { + state.state &= ~kReading; + maybeReadMore(stream, state); + } + + // We can push more data if we are below the highWaterMark. + // Also, if we have no data yet, we can stand some more bytes. + // This is to work around cases where hwm=0, such as the repl. + return !state.ended && (state.length < state.highWaterMark || state.length === 0); + } + function addChunk(stream, state, chunk, addToFront) { + if (state.flowing && state.length === 0 && !state.sync && stream.listenerCount("data") > 0) { + // Use the guard to avoid creating `Set()` repeatedly + // when we have multiple pipes. + if ((state.state & kMultiAwaitDrain) !== 0) { + state.awaitDrainWriters.clear(); + } else { + state.awaitDrainWriters = null; + } + state.dataEmitted = true; + stream.emit("data", chunk); + } else { + // Update the buffer info. + state.length += state.objectMode ? 1 : chunk.length; + if (addToFront) state.buffer.unshift(chunk);else state.buffer.push(chunk); + if ((state.state & kNeedReadable) !== 0) emitReadable(stream); + } + maybeReadMore(stream, state); + } + Readable.prototype.isPaused = function () { + const state = (this || _global$2)._readableState; + return state[kPaused] === true || state.flowing === false; + }; + + // Backwards compatibility. + Readable.prototype.setEncoding = function (enc) { + const decoder = new StringDecoder(enc); + (this || _global$2)._readableState.decoder = decoder; + // If setEncoding(null), decoder.encoding equals utf8. + (this || _global$2)._readableState.encoding = (this || _global$2)._readableState.decoder.encoding; + const buffer = (this || _global$2)._readableState.buffer; + // Iterate over current buffer to convert already stored Buffers: + let content = ""; + for (const data of buffer) { + content += decoder.write(data); + } + buffer.clear(); + if (content !== "") buffer.push(content); + (this || _global$2)._readableState.length = content.length; + return this || _global$2; + }; + + // Don't raise the hwm > 1GB. + const MAX_HWM = 1073741824; + function computeNewHighWaterMark(n) { + if (n > MAX_HWM) { + throw new ERR_OUT_OF_RANGE("size", "<= 1GiB", n); + } else { + // Get the next highest power of 2 to prevent increasing hwm excessively in + // tiny amounts. + n--; + n |= n >>> 1; + n |= n >>> 2; + n |= n >>> 4; + n |= n >>> 8; + n |= n >>> 16; + n++; + } + return n; + } + + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function howMuchToRead(n, state) { + if (n <= 0 || state.length === 0 && state.ended) return 0; + if ((state.state & kObjectMode) !== 0) return 1; + if (NumberIsNaN(n)) { + // Only flow one buffer at a time. + if (state.flowing && state.length) return state.buffer.first().length; + return state.length; + } + if (n <= state.length) return n; + return state.ended ? state.length : 0; + } + + // You can override either this method, or the async _read(n) below. + Readable.prototype.read = function (n) { + debug("read", n); + // Same as parseInt(undefined, 10), however V8 7.3 performance regressed + // in this scenario, so we are doing it manually. + if (n === undefined) { + n = NaN; + } else if (!NumberIsInteger(n)) { + n = NumberParseInt(n, 10); + } + const state = (this || _global$2)._readableState; + const nOrig = n; + + // If we're asking for more than the current hwm, then raise the hwm. + if (n > state.highWaterMark) state.highWaterMark = computeNewHighWaterMark(n); + if (n !== 0) state.state &= ~kEmittedReadable; + + // If we're doing read(0) to trigger a readable event, but we + // already have a bunch of data in the buffer, then just trigger + // the 'readable' event and move on. + if (n === 0 && state.needReadable && ((state.highWaterMark !== 0 ? state.length >= state.highWaterMark : state.length > 0) || state.ended)) { + debug("read: emitReadable", state.length, state.ended); + if (state.length === 0 && state.ended) endReadable(this || _global$2);else emitReadable(this || _global$2); + return null; + } + n = howMuchToRead(n, state); + + // If we've ended, and we're now clear, then finish it up. + if (n === 0 && state.ended) { + if (state.length === 0) endReadable(this || _global$2); + return null; + } + + // All the actual chunk generation logic needs to be + // *below* the call to _read. The reason is that in certain + // synthetic stream cases, such as passthrough streams, _read + // may be a completely synchronous operation which may change + // the state of the read buffer, providing enough data when + // before there was *not* enough. + // + // So, the steps are: + // 1. Figure out what the state of things will be after we do + // a read from the buffer. + // + // 2. If that resulting state will trigger a _read, then call _read. + // Note that this may be asynchronous, or synchronous. Yes, it is + // deeply ugly to write APIs this way, but that still doesn't mean + // that the Readable class should behave improperly, as streams are + // designed to be sync/async agnostic. + // Take note if the _read call is sync or async (ie, if the read call + // has returned yet), so that we know whether or not it's safe to emit + // 'readable' etc. + // + // 3. Actually pull the requested chunks out of the buffer and return. + + // if we need a readable event, then we need to do some reading. + let doRead = (state.state & kNeedReadable) !== 0; + debug("need readable", doRead); + + // If we currently have less than the highWaterMark, then also read some. + if (state.length === 0 || state.length - n < state.highWaterMark) { + doRead = true; + debug("length less than watermark", doRead); + } + + // However, if we've ended, then there's no point, if we're already + // reading, then it's unnecessary, if we're constructing we have to wait, + // and if we're destroyed or errored, then it's not allowed, + if (state.ended || state.reading || state.destroyed || state.errored || !state.constructed) { + doRead = false; + debug("reading, ended or constructing", doRead); + } else if (doRead) { + debug("do read"); + state.state |= kReading | kSync; + // If the length is currently zero, then we *need* a readable event. + if (state.length === 0) state.state |= kNeedReadable; + + // Call internal read method + try { + this._read(state.highWaterMark); + } catch (err) { + errorOrDestroy(this || _global$2, err); + } + state.state &= ~kSync; + + // If _read pushed data synchronously, then `reading` will be false, + // and we need to re-evaluate how much data we can return to the user. + if (!state.reading) n = howMuchToRead(nOrig, state); + } + let ret; + if (n > 0) ret = fromList(n, state);else ret = null; + if (ret === null) { + state.needReadable = state.length <= state.highWaterMark; + n = 0; + } else { + state.length -= n; + if (state.multiAwaitDrain) { + state.awaitDrainWriters.clear(); + } else { + state.awaitDrainWriters = null; + } + } + if (state.length === 0) { + // If we have nothing in the buffer, then we want to know + // as soon as we *do* get something into the buffer. + if (!state.ended) state.needReadable = true; + + // If we tried to read() past the EOF, then emit end on the next tick. + if (nOrig !== n && state.ended) endReadable(this || _global$2); + } + if (ret !== null && !state.errorEmitted && !state.closeEmitted) { + state.dataEmitted = true; + this.emit("data", ret); + } + return ret; + }; + function onEofChunk(stream, state) { + debug("onEofChunk"); + if (state.ended) return; + if (state.decoder) { + const chunk = state.decoder.end(); + if (chunk && chunk.length) { + state.buffer.push(chunk); + state.length += state.objectMode ? 1 : chunk.length; + } + } + state.ended = true; + if (state.sync) { + // If we are sync, wait until next tick to emit the data. + // Otherwise we risk emitting data in the flow() + // the readable code triggers during a read() call. + emitReadable(stream); + } else { + // Emit 'readable' now to make sure it gets picked up. + state.needReadable = false; + state.emittedReadable = true; + // We have to emit readable now that we are EOF. Modules + // in the ecosystem (e.g. dicer) rely on this event being sync. + emitReadable_(stream); + } + } + + // Don't emit readable right away in sync mode, because this can trigger + // another read() call => stack overflow. This way, it might trigger + // a nextTick recursion warning, but that's not so bad. + function emitReadable(stream) { + const state = stream._readableState; + debug("emitReadable", state.needReadable, state.emittedReadable); + state.needReadable = false; + if (!state.emittedReadable) { + debug("emitReadable", state.flowing); + state.emittedReadable = true; + process$1.nextTick(emitReadable_, stream); + } + } + function emitReadable_(stream) { + const state = stream._readableState; + debug("emitReadable_", state.destroyed, state.length, state.ended); + if (!state.destroyed && !state.errored && (state.length || state.ended)) { + stream.emit("readable"); + state.emittedReadable = false; + } + + // The stream needs another readable event if: + // 1. It is not flowing, as the flow mechanism will take + // care of it. + // 2. It is not ended. + // 3. It is below the highWaterMark, so we can schedule + // another readable later. + state.needReadable = !state.flowing && !state.ended && state.length <= state.highWaterMark; + flow(stream); + } + + // At this point, the user has presumably seen the 'readable' event, + // and called read() to consume some data. that may have triggered + // in turn another _read(n) call, in which case reading = true if + // it's in progress. + // However, if we're not ended, or reading, and the length < hwm, + // then go ahead and try to read some more preemptively. + function maybeReadMore(stream, state) { + if (!state.readingMore && state.constructed) { + state.readingMore = true; + process$1.nextTick(maybeReadMore_, stream, state); + } + } + function maybeReadMore_(stream, state) { + // Attempt to read more data if we should. + // + // The conditions for reading more data are (one of): + // - Not enough data buffered (state.length < state.highWaterMark). The loop + // is responsible for filling the buffer with enough data if such data + // is available. If highWaterMark is 0 and we are not in the flowing mode + // we should _not_ attempt to buffer any extra data. We'll get more data + // when the stream consumer calls read() instead. + // - No data in the buffer, and the stream is in flowing mode. In this mode + // the loop below is responsible for ensuring read() is called. Failing to + // call read here would abort the flow and there's no other mechanism for + // continuing the flow if the stream consumer has just subscribed to the + // 'data' event. + // + // In addition to the above conditions to keep reading data, the following + // conditions prevent the data from being read: + // - The stream has ended (state.ended). + // - There is already a pending 'read' operation (state.reading). This is a + // case where the stream has called the implementation defined _read() + // method, but they are processing the call asynchronously and have _not_ + // called push() with new data. In this case we skip performing more + // read()s. The execution ends in this method again after the _read() ends + // up calling push() with more data. + while (!state.reading && !state.ended && (state.length < state.highWaterMark || state.flowing && state.length === 0)) { + const len = state.length; + debug("maybeReadMore read 0"); + stream.read(0); + if (len === state.length) + // Didn't get any data, stop spinning. + break; + } + state.readingMore = false; + } + + // Abstract method. to be overridden in specific implementation classes. + // call cb(er, data) where data is <= n in length. + // for virtual (non-string, non-buffer) streams, "length" is somewhat + // arbitrary, and perhaps not very meaningful. + Readable.prototype._read = function (n) { + throw new ERR_METHOD_NOT_IMPLEMENTED("_read()"); + }; + Readable.prototype.pipe = function (dest, pipeOpts) { + const src = this || _global$2; + const state = (this || _global$2)._readableState; + if (state.pipes.length === 1) { + if (!state.multiAwaitDrain) { + state.multiAwaitDrain = true; + state.awaitDrainWriters = new SafeSet(state.awaitDrainWriters ? [state.awaitDrainWriters] : []); + } + } + state.pipes.push(dest); + debug("pipe count=%d opts=%j", state.pipes.length, pipeOpts); + const doEnd = (!pipeOpts || pipeOpts.end !== false) && dest !== process$1.stdout && dest !== process$1.stderr; + const endFn = doEnd ? onend : unpipe; + if (state.endEmitted) process$1.nextTick(endFn);else src.once("end", endFn); + dest.on("unpipe", onunpipe); + function onunpipe(readable, unpipeInfo) { + debug("onunpipe"); + if (readable === src) { + if (unpipeInfo && unpipeInfo.hasUnpiped === false) { + unpipeInfo.hasUnpiped = true; + cleanup(); + } + } + } + function onend() { + debug("onend"); + dest.end(); + } + let ondrain; + let cleanedUp = false; + function cleanup() { + debug("cleanup"); + // Cleanup event handlers once the pipe is broken. + dest.removeListener("close", onclose); + dest.removeListener("finish", onfinish); + if (ondrain) { + dest.removeListener("drain", ondrain); + } + dest.removeListener("error", onerror); + dest.removeListener("unpipe", onunpipe); + src.removeListener("end", onend); + src.removeListener("end", unpipe); + src.removeListener("data", ondata); + cleanedUp = true; + + // If the reader is waiting for a drain event from this + // specific writer, then it would cause it to never start + // flowing again. + // So, if this is awaiting a drain, then we just call it now. + // If we don't know, then assume that we are waiting for one. + if (ondrain && state.awaitDrainWriters && (!dest._writableState || dest._writableState.needDrain)) ondrain(); + } + function pause() { + // If the user unpiped during `dest.write()`, it is possible + // to get stuck in a permanently paused state if that write + // also returned false. + // => Check whether `dest` is still a piping destination. + if (!cleanedUp) { + if (state.pipes.length === 1 && state.pipes[0] === dest) { + debug("false write response, pause", 0); + state.awaitDrainWriters = dest; + state.multiAwaitDrain = false; + } else if (state.pipes.length > 1 && state.pipes.includes(dest)) { + debug("false write response, pause", state.awaitDrainWriters.size); + state.awaitDrainWriters.add(dest); + } + src.pause(); + } + if (!ondrain) { + // When the dest drains, it reduces the awaitDrain counter + // on the source. This would be more elegant with a .once() + // handler in flow(), but adding and removing repeatedly is + // too slow. + ondrain = pipeOnDrain(src, dest); + dest.on("drain", ondrain); + } + } + src.on("data", ondata); + function ondata(chunk) { + debug("ondata"); + const ret = dest.write(chunk); + debug("dest.write", ret); + if (ret === false) { + pause(); + } + } + + // If the dest has an error, then stop piping into it. + // However, don't suppress the throwing behavior for this. + function onerror(er) { + debug("onerror", er); + unpipe(); + dest.removeListener("error", onerror); + if (dest.listenerCount("error") === 0) { + const s = dest._writableState || dest._readableState; + if (s && !s.errorEmitted) { + // User incorrectly emitted 'error' directly on the stream. + errorOrDestroy(dest, er); + } else { + dest.emit("error", er); + } + } + } + + // Make sure our error handler is attached before userland ones. + prependListener(dest, "error", onerror); + + // Both close and finish should trigger unpipe, but only once. + function onclose() { + dest.removeListener("finish", onfinish); + unpipe(); + } + dest.once("close", onclose); + function onfinish() { + debug("onfinish"); + dest.removeListener("close", onclose); + unpipe(); + } + dest.once("finish", onfinish); + function unpipe() { + debug("unpipe"); + src.unpipe(dest); + } + + // Tell the dest that it's being piped to. + dest.emit("pipe", src); + + // Start the flow if it hasn't been started already. + + if (dest.writableNeedDrain === true) { + pause(); + } else if (!state.flowing) { + debug("pipe resume"); + src.resume(); + } + return dest; + }; + function pipeOnDrain(src, dest) { + return function pipeOnDrainFunctionResult() { + const state = src._readableState; + + // `ondrain` will call directly, + // `this` maybe not a reference to dest, + // so we use the real dest here. + if (state.awaitDrainWriters === dest) { + debug("pipeOnDrain", 1); + state.awaitDrainWriters = null; + } else if (state.multiAwaitDrain) { + debug("pipeOnDrain", state.awaitDrainWriters.size); + state.awaitDrainWriters.delete(dest); + } + if ((!state.awaitDrainWriters || state.awaitDrainWriters.size === 0) && src.listenerCount("data")) { + src.resume(); + } + }; + } + Readable.prototype.unpipe = function (dest) { + const state = (this || _global$2)._readableState; + const unpipeInfo = { + hasUnpiped: false + }; + + // If we're not piping anywhere, then do nothing. + if (state.pipes.length === 0) return this || _global$2; + if (!dest) { + // remove all. + const dests = state.pipes; + state.pipes = []; + this.pause(); + for (let i = 0; i < dests.length; i++) dests[i].emit("unpipe", this || _global$2, { + hasUnpiped: false + }); + return this || _global$2; + } + + // Try to find the right one. + const index = ArrayPrototypeIndexOf(state.pipes, dest); + if (index === -1) return this || _global$2; + state.pipes.splice(index, 1); + if (state.pipes.length === 0) this.pause(); + dest.emit("unpipe", this || _global$2, unpipeInfo); + return this || _global$2; + }; + + // Set up data events if they are asked for + // Ensure readable listeners eventually get something. + Readable.prototype.on = function (ev, fn) { + const res = Stream.prototype.on.call(this || _global$2, ev, fn); + const state = (this || _global$2)._readableState; + if (ev === "data") { + // Update readableListening so that resume() may be a no-op + // a few lines down. This is needed to support once('readable'). + state.readableListening = this.listenerCount("readable") > 0; + + // Try start flowing on next tick if stream isn't explicitly paused. + if (state.flowing !== false) this.resume(); + } else if (ev === "readable") { + if (!state.endEmitted && !state.readableListening) { + state.readableListening = state.needReadable = true; + state.flowing = false; + state.emittedReadable = false; + debug("on readable", state.length, state.reading); + if (state.length) { + emitReadable(this || _global$2); + } else if (!state.reading) { + process$1.nextTick(nReadingNextTick, this || _global$2); + } + } + } + return res; + }; + Readable.prototype.addListener = Readable.prototype.on; + Readable.prototype.removeListener = function (ev, fn) { + const res = Stream.prototype.removeListener.call(this || _global$2, ev, fn); + if (ev === "readable") { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process$1.nextTick(updateReadableListening, this || _global$2); + } + return res; + }; + Readable.prototype.off = Readable.prototype.removeListener; + Readable.prototype.removeAllListeners = function (ev) { + const res = Stream.prototype.removeAllListeners.apply(this || _global$2, arguments); + if (ev === "readable" || ev === undefined) { + // We need to check if there is someone still listening to + // readable and reset the state. However this needs to happen + // after readable has been emitted but before I/O (nextTick) to + // support once('readable', fn) cycles. This means that calling + // resume within the same tick will have no + // effect. + process$1.nextTick(updateReadableListening, this || _global$2); + } + return res; + }; + function updateReadableListening(self) { + const state = self._readableState; + state.readableListening = self.listenerCount("readable") > 0; + if (state.resumeScheduled && state[kPaused] === false) { + // Flowing needs to be set to true now, otherwise + // the upcoming resume will not flow. + state.flowing = true; + + // Crude way to check if we should resume. + } else if (self.listenerCount("data") > 0) { + self.resume(); + } else if (!state.readableListening) { + state.flowing = null; + } + } + function nReadingNextTick(self) { + debug("readable nexttick read 0"); + self.read(0); + } + + // pause() and resume() are remnants of the legacy readable stream API + // If the user uses them, then switch into old mode. + Readable.prototype.resume = function () { + const state = (this || _global$2)._readableState; + if (!state.flowing) { + debug("resume"); + // We flow only if there is no one listening + // for readable, but we still have to call + // resume(). + state.flowing = !state.readableListening; + resume(this || _global$2, state); + } + state[kPaused] = false; + return this || _global$2; + }; + function resume(stream, state) { + if (!state.resumeScheduled) { + state.resumeScheduled = true; + process$1.nextTick(resume_, stream, state); + } + } + function resume_(stream, state) { + debug("resume", state.reading); + if (!state.reading) { + stream.read(0); + } + state.resumeScheduled = false; + stream.emit("resume"); + flow(stream); + if (state.flowing && !state.reading) stream.read(0); + } + Readable.prototype.pause = function () { + debug("call pause flowing=%j", (this || _global$2)._readableState.flowing); + if ((this || _global$2)._readableState.flowing !== false) { + debug("pause"); + (this || _global$2)._readableState.flowing = false; + this.emit("pause"); + } + (this || _global$2)._readableState[kPaused] = true; + return this || _global$2; + }; + function flow(stream) { + const state = stream._readableState; + debug("flow", state.flowing); + while (state.flowing && stream.read() !== null); + } + + // Wrap an old-style stream as the async data source. + // This is *not* part of the readable stream interface. + // It is an ugly unfortunate mess of history. + Readable.prototype.wrap = function (stream) { + let paused = false; + + // TODO (ronag): Should this.destroy(err) emit + // 'error' on the wrapped stream? Would require + // a static factory method, e.g. Readable.wrap(stream). + + stream.on("data", chunk => { + if (!this.push(chunk) && stream.pause) { + paused = true; + stream.pause(); + } + }); + stream.on("end", () => { + this.push(null); + }); + stream.on("error", err => { + errorOrDestroy(this || _global$2, err); + }); + stream.on("close", () => { + this.destroy(); + }); + stream.on("destroy", () => { + this.destroy(); + }); + (this || _global$2)._read = () => { + if (paused && stream.resume) { + paused = false; + stream.resume(); + } + }; + + // Proxy all the other methods. Important when wrapping filters and duplexes. + const streamKeys = ObjectKeys(stream); + for (let j = 1; j < streamKeys.length; j++) { + const i = streamKeys[j]; + if ((this || _global$2)[i] === undefined && typeof stream[i] === "function") { + (this || _global$2)[i] = stream[i].bind(stream); + } + } + return this || _global$2; + }; + Readable.prototype[SymbolAsyncIterator] = function () { + return streamToAsyncIterator(this || _global$2); + }; + Readable.prototype.iterator = function (options) { + if (options !== undefined) { + validateObject(options, "options"); + } + return streamToAsyncIterator(this || _global$2, options); + }; + function streamToAsyncIterator(stream, options) { + if (typeof stream.read !== "function") { + stream = Readable.wrap(stream, { + objectMode: true + }); + } + const iter = createAsyncIterator(stream, options); + iter.stream = stream; + return iter; + } + async function* createAsyncIterator(stream, options) { + let callback = nop; + function next(resolve) { + if ((this || _global$2) === stream) { + callback(); + callback = nop; + } else { + callback = resolve; + } + } + stream.on("readable", next); + let error; + const cleanup = eos(stream, { + writable: false + }, err => { + error = err ? aggregateTwoErrors(error, err) : null; + callback(); + callback = nop; + }); + try { + while (true) { + const chunk = stream.destroyed ? null : stream.read(); + if (chunk !== null) { + yield chunk; + } else if (error) { + throw error; + } else if (error === null) { + return; + } else { + await new Promise(next); + } + } + } catch (err) { + error = aggregateTwoErrors(error, err); + throw error; + } finally { + if ((error || (options === null || options === undefined ? undefined : options.destroyOnReturn) !== false) && (error === undefined || stream._readableState.autoDestroy)) { + destroyImpl.destroyer(stream, null); + } else { + stream.off("readable", next); + cleanup(); + } + } + } + + // Making it explicit these properties are not enumerable + // because otherwise some prototype manipulation in + // userland will fail. + ObjectDefineProperties(Readable.prototype, { + readable: { + __proto__: null, + get() { + const r = (this || _global$2)._readableState; + // r.readable === false means that this is part of a Duplex stream + // where the readable side was disabled upon construction. + // Compat. The user might manually disable readable side through + // deprecated setter. + return !!r && r.readable !== false && !r.destroyed && !r.errorEmitted && !r.endEmitted; + }, + set(val) { + // Backwards compat. + if ((this || _global$2)._readableState) { + (this || _global$2)._readableState.readable = !!val; + } + } + }, + readableDidRead: { + __proto__: null, + enumerable: false, + get: function () { + return (this || _global$2)._readableState.dataEmitted; + } + }, + readableAborted: { + __proto__: null, + enumerable: false, + get: function () { + return !!((this || _global$2)._readableState.readable !== false && ((this || _global$2)._readableState.destroyed || (this || _global$2)._readableState.errored) && !(this || _global$2)._readableState.endEmitted); + } + }, + readableHighWaterMark: { + __proto__: null, + enumerable: false, + get: function () { + return (this || _global$2)._readableState.highWaterMark; + } + }, + readableBuffer: { + __proto__: null, + enumerable: false, + get: function () { + return (this || _global$2)._readableState && (this || _global$2)._readableState.buffer; + } + }, + readableFlowing: { + __proto__: null, + enumerable: false, + get: function () { + return (this || _global$2)._readableState.flowing; + }, + set: function (state) { + if ((this || _global$2)._readableState) { + (this || _global$2)._readableState.flowing = state; + } + } + }, + readableLength: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$2)._readableState.length; + } + }, + readableObjectMode: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$2)._readableState ? (this || _global$2)._readableState.objectMode : false; + } + }, + readableEncoding: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$2)._readableState ? (this || _global$2)._readableState.encoding : null; + } + }, + errored: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$2)._readableState ? (this || _global$2)._readableState.errored : null; + } + }, + closed: { + __proto__: null, + get() { + return (this || _global$2)._readableState ? (this || _global$2)._readableState.closed : false; + } + }, + destroyed: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$2)._readableState ? (this || _global$2)._readableState.destroyed : false; + }, + set(value) { + // We ignore the value if the stream + // has not been initialized yet. + if (!(this || _global$2)._readableState) { + return; + } + + // Backward compatibility, the user is explicitly + // managing destroyed. + (this || _global$2)._readableState.destroyed = value; + } + }, + readableEnded: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$2)._readableState ? (this || _global$2)._readableState.endEmitted : false; + } + } + }); + ObjectDefineProperties(ReadableState.prototype, { + // Legacy getter for `pipesCount`. + pipesCount: { + __proto__: null, + get() { + return (this || _global$2).pipes.length; + } + }, + // Legacy property for `paused`. + paused: { + __proto__: null, + get() { + return (this || _global$2)[kPaused] !== false; + }, + set(value) { + (this || _global$2)[kPaused] = !!value; + } + } + }); + + // Exposed for testing purposes only. + Readable._fromList = fromList; + + // Pluck off n bytes from an array of buffers. + // Length is the combined lengths of all the buffers in the list. + // This function is designed to be inlinable, so please take care when making + // changes to the function body. + function fromList(n, state) { + // nothing buffered. + if (state.length === 0) return null; + let ret; + if (state.objectMode) ret = state.buffer.shift();else if (!n || n >= state.length) { + // Read it all, truncate the list. + if (state.decoder) ret = state.buffer.join("");else if (state.buffer.length === 1) ret = state.buffer.first();else ret = state.buffer.concat(state.length); + state.buffer.clear(); + } else { + // read part of list. + ret = state.buffer.consume(n, state.decoder); + } + return ret; + } + function endReadable(stream) { + const state = stream._readableState; + debug("endReadable", state.endEmitted); + if (!state.endEmitted) { + state.ended = true; + process$1.nextTick(endReadableNT, state, stream); + } + } + function endReadableNT(state, stream) { + debug("endReadableNT", state.endEmitted, state.length); + + // Check that we didn't get one last unshift. + if (!state.errored && !state.closeEmitted && !state.endEmitted && state.length === 0) { + state.endEmitted = true; + stream.emit("end"); + if (stream.writable && stream.allowHalfOpen === false) { + process$1.nextTick(endWritableNT, stream); + } else if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the writable side is ready for autoDestroy as well. + const wState = stream._writableState; + const autoDestroy = !wState || wState.autoDestroy && ( + // We don't expect the writable to ever 'finish' + // if writable is explicitly set to false. + wState.finished || wState.writable === false); + if (autoDestroy) { + stream.destroy(); + } + } + } + } + function endWritableNT(stream) { + const writable = stream.writable && !stream.writableEnded && !stream.destroyed; + if (writable) { + stream.end(); + } + } + Readable.from = function (iterable, opts) { + return from(Readable, iterable, opts); + }; + let webStreamsAdapters; + + // Lazy to avoid circular references + function lazyWebStreams() { + if (webStreamsAdapters === undefined) webStreamsAdapters = {}; + return webStreamsAdapters; + } + Readable.fromWeb = function (readableStream, options) { + return lazyWebStreams().newStreamReadableFromReadableStream(readableStream, options); + }; + Readable.toWeb = function (streamReadable, options) { + return lazyWebStreams().newReadableStreamFromStreamReadable(streamReadable, options); + }; + Readable.wrap = function (src, options) { + var _ref, _src$readableObjectMo; + return new Readable({ + objectMode: (_ref = (_src$readableObjectMo = src.readableObjectMode) !== null && _src$readableObjectMo !== undefined ? _src$readableObjectMo : src.objectMode) !== null && _ref !== undefined ? _ref : true, + ...options, + destroy(err, callback) { + destroyImpl.destroyer(src, err); + callback(err); + } + }).wrap(src); + }; + return exports$c; +} + +var exports$b = {}, + _dewExec$a = false; +var _global$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$a() { + if (_dewExec$a) return exports$b; + _dewExec$a = true; + /* replacement start */ + + const process$1 = process + + /* replacement end */ + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + + // A bit simpler than readable streams. + // Implement an async ._write(chunk, encoding, cb), and it'll handle all + // the drain event emission and buffering. + ; + const { + ArrayPrototypeSlice, + Error, + FunctionPrototypeSymbolHasInstance, + ObjectDefineProperty, + ObjectDefineProperties, + ObjectSetPrototypeOf, + StringPrototypeToLowerCase, + Symbol, + SymbolHasInstance + } = dew$o(); + exports$b = Writable; + Writable.WritableState = WritableState; + const { + EventEmitter: EE + } = exports$q; + const Stream = dew$g().Stream; + const { + Buffer + } = dew$p(); + const destroyImpl = dew$h(); + const { + addAbortSignal + } = dew$f(); + const { + getHighWaterMark, + getDefaultHighWaterMark + } = dew$d(); + const { + ERR_INVALID_ARG_TYPE, + ERR_METHOD_NOT_IMPLEMENTED, + ERR_MULTIPLE_CALLBACK, + ERR_STREAM_CANNOT_PIPE, + ERR_STREAM_DESTROYED, + ERR_STREAM_ALREADY_FINISHED, + ERR_STREAM_NULL_VALUES, + ERR_STREAM_WRITE_AFTER_END, + ERR_UNKNOWN_ENCODING + } = dew$l().codes; + const { + errorOrDestroy + } = destroyImpl; + ObjectSetPrototypeOf(Writable.prototype, Stream.prototype); + ObjectSetPrototypeOf(Writable, Stream); + function nop() {} + const kOnFinished = Symbol("kOnFinished"); + function WritableState(options, stream, isDuplex) { + // Duplex streams are both readable and writable, but share + // the same options object. + // However, some cases require setting options to different + // values for the readable and the writable sides of the duplex stream, + // e.g. options.readableObjectMode vs. options.writableObjectMode, etc. + if (typeof isDuplex !== "boolean") isDuplex = stream instanceof dew$8(); + + // Object stream flag to indicate whether or not this stream + // contains buffers or objects. + (this || _global$1).objectMode = !!(options && options.objectMode); + if (isDuplex) (this || _global$1).objectMode = (this || _global$1).objectMode || !!(options && options.writableObjectMode); + + // The point at which write() starts returning false + // Note: 0 is a valid value, means that we always return false if + // the entire buffer is not flushed immediately on write(). + (this || _global$1).highWaterMark = options ? getHighWaterMark(this || _global$1, options, "writableHighWaterMark", isDuplex) : getDefaultHighWaterMark(false); + + // if _final has been called. + (this || _global$1).finalCalled = false; + + // drain event flag. + (this || _global$1).needDrain = false; + // At the start of calling end() + (this || _global$1).ending = false; + // When end() has been called, and returned. + (this || _global$1).ended = false; + // When 'finish' is emitted. + (this || _global$1).finished = false; + + // Has it been destroyed + (this || _global$1).destroyed = false; + + // Should we decode strings into buffers before passing to _write? + // this is here so that some node-core streams can optimize string + // handling at a lower level. + const noDecode = !!(options && options.decodeStrings === false); + (this || _global$1).decodeStrings = !noDecode; + + // Crypto is kind of old and crusty. Historically, its default string + // encoding is 'binary' so we have to make this configurable. + // Everything else in the universe uses 'utf8', though. + (this || _global$1).defaultEncoding = options && options.defaultEncoding || "utf8"; + + // Not an actual buffer we keep track of, but a measurement + // of how much we're waiting to get pushed to some underlying + // socket or file. + (this || _global$1).length = 0; + + // A flag to see when we're in the middle of a write. + (this || _global$1).writing = false; + + // When true all writes will be buffered until .uncork() call. + (this || _global$1).corked = 0; + + // A flag to be able to tell if the onwrite cb is called immediately, + // or on a later tick. We set this to true at first, because any + // actions that shouldn't happen until "later" should generally also + // not happen before the first write call. + (this || _global$1).sync = true; + + // A flag to know if we're processing previously buffered items, which + // may call the _write() callback in the same tick, so that we don't + // end up in an overlapped onwrite situation. + (this || _global$1).bufferProcessing = false; + + // The callback that's passed to _write(chunk, cb). + (this || _global$1).onwrite = onwrite.bind(undefined, stream); + + // The callback that the user supplies to write(chunk, encoding, cb). + (this || _global$1).writecb = null; + + // The amount that is being written when _write is called. + (this || _global$1).writelen = 0; + + // Storage for data passed to the afterWrite() callback in case of + // synchronous _write() completion. + (this || _global$1).afterWriteTickInfo = null; + resetBuffer(this || _global$1); + + // Number of pending user-supplied write callbacks + // this must be 0 before 'finish' can be emitted. + (this || _global$1).pendingcb = 0; + + // Stream is still being constructed and cannot be + // destroyed until construction finished or failed. + // Async construction is opt in, therefore we start as + // constructed. + (this || _global$1).constructed = true; + + // Emit prefinish if the only thing we're waiting for is _write cbs + // This is relevant for synchronous Transform streams. + (this || _global$1).prefinished = false; + + // True if the error was already emitted and should not be thrown again. + (this || _global$1).errorEmitted = false; + + // Should close be emitted on destroy. Defaults to true. + (this || _global$1).emitClose = !options || options.emitClose !== false; + + // Should .destroy() be called after 'finish' (and potentially 'end'). + (this || _global$1).autoDestroy = !options || options.autoDestroy !== false; + + // Indicates whether the stream has errored. When true all write() calls + // should return false. This is needed since when autoDestroy + // is disabled we need a way to tell whether the stream has failed. + (this || _global$1).errored = null; + + // Indicates whether the stream has finished destroying. + (this || _global$1).closed = false; + + // True if close has been emitted or would have been emitted + // depending on emitClose. + (this || _global$1).closeEmitted = false; + (this || _global$1)[kOnFinished] = []; + } + function resetBuffer(state) { + state.buffered = []; + state.bufferedIndex = 0; + state.allBuffers = true; + state.allNoop = true; + } + WritableState.prototype.getBuffer = function getBuffer() { + return ArrayPrototypeSlice((this || _global$1).buffered, (this || _global$1).bufferedIndex); + }; + ObjectDefineProperty(WritableState.prototype, "bufferedRequestCount", { + __proto__: null, + get() { + return (this || _global$1).buffered.length - (this || _global$1).bufferedIndex; + } + }); + function Writable(options) { + // Writable ctor is applied to Duplexes, too. + // `realHasInstance` is necessary because using plain `instanceof` + // would return false, as no `_writableState` property is attached. + + // Trying to use the custom `instanceof` for Writable here will also break the + // Node.js LazyTransform implementation, which has a non-trivial getter for + // `_writableState` that would lead to infinite recursion. + + // Checking for a Stream.Duplex instance is faster here instead of inside + // the WritableState constructor, at least with V8 6.5. + const isDuplex = (this || _global$1) instanceof dew$8(); + if (!isDuplex && !FunctionPrototypeSymbolHasInstance(Writable, this || _global$1)) return new Writable(options); + (this || _global$1)._writableState = new WritableState(options, this || _global$1, isDuplex); + if (options) { + if (typeof options.write === "function") (this || _global$1)._write = options.write; + if (typeof options.writev === "function") (this || _global$1)._writev = options.writev; + if (typeof options.destroy === "function") (this || _global$1)._destroy = options.destroy; + if (typeof options.final === "function") (this || _global$1)._final = options.final; + if (typeof options.construct === "function") (this || _global$1)._construct = options.construct; + if (options.signal) addAbortSignal(options.signal, this || _global$1); + } + Stream.call(this || _global$1, options); + destroyImpl.construct(this || _global$1, () => { + const state = (this || _global$1)._writableState; + if (!state.writing) { + clearBuffer(this || _global$1, state); + } + finishMaybe(this || _global$1, state); + }); + } + ObjectDefineProperty(Writable, SymbolHasInstance, { + __proto__: null, + value: function (object) { + if (FunctionPrototypeSymbolHasInstance(this || _global$1, object)) return true; + if ((this || _global$1) !== Writable) return false; + return object && object._writableState instanceof WritableState; + } + }); + + // Otherwise people can pipe Writable streams, which is just wrong. + Writable.prototype.pipe = function () { + errorOrDestroy(this || _global$1, new ERR_STREAM_CANNOT_PIPE()); + }; + function _write(stream, chunk, encoding, cb) { + const state = stream._writableState; + if (typeof encoding === "function") { + cb = encoding; + encoding = state.defaultEncoding; + } else { + if (!encoding) encoding = state.defaultEncoding;else if (encoding !== "buffer" && !Buffer.isEncoding(encoding)) throw new ERR_UNKNOWN_ENCODING(encoding); + if (typeof cb !== "function") cb = nop; + } + if (chunk === null) { + throw new ERR_STREAM_NULL_VALUES(); + } else if (!state.objectMode) { + if (typeof chunk === "string") { + if (state.decodeStrings !== false) { + chunk = Buffer.from(chunk, encoding); + encoding = "buffer"; + } + } else if (chunk instanceof Buffer) { + encoding = "buffer"; + } else if (Stream._isUint8Array(chunk)) { + chunk = Stream._uint8ArrayToBuffer(chunk); + encoding = "buffer"; + } else { + throw new ERR_INVALID_ARG_TYPE("chunk", ["string", "Buffer", "Uint8Array"], chunk); + } + } + let err; + if (state.ending) { + err = new ERR_STREAM_WRITE_AFTER_END(); + } else if (state.destroyed) { + err = new ERR_STREAM_DESTROYED("write"); + } + if (err) { + process$1.nextTick(cb, err); + errorOrDestroy(stream, err, true); + return err; + } + state.pendingcb++; + return writeOrBuffer(stream, state, chunk, encoding, cb); + } + Writable.prototype.write = function (chunk, encoding, cb) { + return _write(this || _global$1, chunk, encoding, cb) === true; + }; + Writable.prototype.cork = function () { + (this || _global$1)._writableState.corked++; + }; + Writable.prototype.uncork = function () { + const state = (this || _global$1)._writableState; + if (state.corked) { + state.corked--; + if (!state.writing) clearBuffer(this || _global$1, state); + } + }; + Writable.prototype.setDefaultEncoding = function setDefaultEncoding(encoding) { + // node::ParseEncoding() requires lower case. + if (typeof encoding === "string") encoding = StringPrototypeToLowerCase(encoding); + if (!Buffer.isEncoding(encoding)) throw new ERR_UNKNOWN_ENCODING(encoding); + (this || _global$1)._writableState.defaultEncoding = encoding; + return this || _global$1; + }; + + // If we're already writing something, then just put this + // in the queue, and wait our turn. Otherwise, call _write + // If we return false, then we need a drain event, so set that flag. + function writeOrBuffer(stream, state, chunk, encoding, callback) { + const len = state.objectMode ? 1 : chunk.length; + state.length += len; + + // stream._write resets state.length + const ret = state.length < state.highWaterMark; + // We must ensure that previous needDrain will not be reset to false. + if (!ret) state.needDrain = true; + if (state.writing || state.corked || state.errored || !state.constructed) { + state.buffered.push({ + chunk, + encoding, + callback + }); + if (state.allBuffers && encoding !== "buffer") { + state.allBuffers = false; + } + if (state.allNoop && callback !== nop) { + state.allNoop = false; + } + } else { + state.writelen = len; + state.writecb = callback; + state.writing = true; + state.sync = true; + stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } + + // Return false if errored or destroyed in order to break + // any synchronous while(stream.write(data)) loops. + return ret && !state.errored && !state.destroyed; + } + function doWrite(stream, state, writev, len, chunk, encoding, cb) { + state.writelen = len; + state.writecb = cb; + state.writing = true; + state.sync = true; + if (state.destroyed) state.onwrite(new ERR_STREAM_DESTROYED("write"));else if (writev) stream._writev(chunk, state.onwrite);else stream._write(chunk, encoding, state.onwrite); + state.sync = false; + } + function onwriteError(stream, state, er, cb) { + --state.pendingcb; + cb(er); + // Ensure callbacks are invoked even when autoDestroy is + // not enabled. Passing `er` here doesn't make sense since + // it's related to one specific write, not to the buffered + // writes. + errorBuffer(state); + // This can emit error, but error must always follow cb. + errorOrDestroy(stream, er); + } + function onwrite(stream, er) { + const state = stream._writableState; + const sync = state.sync; + const cb = state.writecb; + if (typeof cb !== "function") { + errorOrDestroy(stream, new ERR_MULTIPLE_CALLBACK()); + return; + } + state.writing = false; + state.writecb = null; + state.length -= state.writelen; + state.writelen = 0; + if (er) { + // Avoid V8 leak, https://github.com/nodejs/node/pull/34103#issuecomment-652002364 + er.stack; // eslint-disable-line no-unused-expressions + + if (!state.errored) { + state.errored = er; + } + + // In case of duplex streams we need to notify the readable side of the + // error. + if (stream._readableState && !stream._readableState.errored) { + stream._readableState.errored = er; + } + if (sync) { + process$1.nextTick(onwriteError, stream, state, er, cb); + } else { + onwriteError(stream, state, er, cb); + } + } else { + if (state.buffered.length > state.bufferedIndex) { + clearBuffer(stream, state); + } + if (sync) { + // It is a common case that the callback passed to .write() is always + // the same. In that case, we do not schedule a new nextTick(), but + // rather just increase a counter, to improve performance and avoid + // memory allocations. + if (state.afterWriteTickInfo !== null && state.afterWriteTickInfo.cb === cb) { + state.afterWriteTickInfo.count++; + } else { + state.afterWriteTickInfo = { + count: 1, + cb, + stream, + state + }; + process$1.nextTick(afterWriteTick, state.afterWriteTickInfo); + } + } else { + afterWrite(stream, state, 1, cb); + } + } + } + function afterWriteTick({ + stream, + state, + count, + cb + }) { + state.afterWriteTickInfo = null; + return afterWrite(stream, state, count, cb); + } + function afterWrite(stream, state, count, cb) { + const needDrain = !state.ending && !stream.destroyed && state.length === 0 && state.needDrain; + if (needDrain) { + state.needDrain = false; + stream.emit("drain"); + } + while (count-- > 0) { + state.pendingcb--; + cb(); + } + if (state.destroyed) { + errorBuffer(state); + } + finishMaybe(stream, state); + } + + // If there's something in the buffer waiting, then invoke callbacks. + function errorBuffer(state) { + if (state.writing) { + return; + } + for (let n = state.bufferedIndex; n < state.buffered.length; ++n) { + var _state$errored; + const { + chunk, + callback + } = state.buffered[n]; + const len = state.objectMode ? 1 : chunk.length; + state.length -= len; + callback((_state$errored = state.errored) !== null && _state$errored !== undefined ? _state$errored : new ERR_STREAM_DESTROYED("write")); + } + const onfinishCallbacks = state[kOnFinished].splice(0); + for (let i = 0; i < onfinishCallbacks.length; i++) { + var _state$errored2; + onfinishCallbacks[i]((_state$errored2 = state.errored) !== null && _state$errored2 !== undefined ? _state$errored2 : new ERR_STREAM_DESTROYED("end")); + } + resetBuffer(state); + } + + // If there's something in the buffer waiting, then process it. + function clearBuffer(stream, state) { + if (state.corked || state.bufferProcessing || state.destroyed || !state.constructed) { + return; + } + const { + buffered, + bufferedIndex, + objectMode + } = state; + const bufferedLength = buffered.length - bufferedIndex; + if (!bufferedLength) { + return; + } + let i = bufferedIndex; + state.bufferProcessing = true; + if (bufferedLength > 1 && stream._writev) { + state.pendingcb -= bufferedLength - 1; + const callback = state.allNoop ? nop : err => { + for (let n = i; n < buffered.length; ++n) { + buffered[n].callback(err); + } + }; + // Make a copy of `buffered` if it's going to be used by `callback` above, + // since `doWrite` will mutate the array. + const chunks = state.allNoop && i === 0 ? buffered : ArrayPrototypeSlice(buffered, i); + chunks.allBuffers = state.allBuffers; + doWrite(stream, state, true, state.length, chunks, "", callback); + resetBuffer(state); + } else { + do { + const { + chunk, + encoding, + callback + } = buffered[i]; + buffered[i++] = null; + const len = objectMode ? 1 : chunk.length; + doWrite(stream, state, false, len, chunk, encoding, callback); + } while (i < buffered.length && !state.writing); + if (i === buffered.length) { + resetBuffer(state); + } else if (i > 256) { + buffered.splice(0, i); + state.bufferedIndex = 0; + } else { + state.bufferedIndex = i; + } + } + state.bufferProcessing = false; + } + Writable.prototype._write = function (chunk, encoding, cb) { + if ((this || _global$1)._writev) { + this._writev([{ + chunk, + encoding + }], cb); + } else { + throw new ERR_METHOD_NOT_IMPLEMENTED("_write()"); + } + }; + Writable.prototype._writev = null; + Writable.prototype.end = function (chunk, encoding, cb) { + const state = (this || _global$1)._writableState; + if (typeof chunk === "function") { + cb = chunk; + chunk = null; + encoding = null; + } else if (typeof encoding === "function") { + cb = encoding; + encoding = null; + } + let err; + if (chunk !== null && chunk !== undefined) { + const ret = _write(this || _global$1, chunk, encoding); + if (ret instanceof Error) { + err = ret; + } + } + + // .end() fully uncorks. + if (state.corked) { + state.corked = 1; + this.uncork(); + } + if (err) ; else if (!state.errored && !state.ending) { + // This is forgiving in terms of unnecessary calls to end() and can hide + // logic errors. However, usually such errors are harmless and causing a + // hard error can be disproportionately destructive. It is not always + // trivial for the user to determine whether end() needs to be called + // or not. + + state.ending = true; + finishMaybe(this || _global$1, state, true); + state.ended = true; + } else if (state.finished) { + err = new ERR_STREAM_ALREADY_FINISHED("end"); + } else if (state.destroyed) { + err = new ERR_STREAM_DESTROYED("end"); + } + if (typeof cb === "function") { + if (err || state.finished) { + process$1.nextTick(cb, err); + } else { + state[kOnFinished].push(cb); + } + } + return this || _global$1; + }; + function needFinish(state) { + return state.ending && !state.destroyed && state.constructed && state.length === 0 && !state.errored && state.buffered.length === 0 && !state.finished && !state.writing && !state.errorEmitted && !state.closeEmitted; + } + function callFinal(stream, state) { + let called = false; + function onFinish(err) { + if (called) { + errorOrDestroy(stream, err !== null && err !== undefined ? err : ERR_MULTIPLE_CALLBACK()); + return; + } + called = true; + state.pendingcb--; + if (err) { + const onfinishCallbacks = state[kOnFinished].splice(0); + for (let i = 0; i < onfinishCallbacks.length; i++) { + onfinishCallbacks[i](err); + } + errorOrDestroy(stream, err, state.sync); + } else if (needFinish(state)) { + state.prefinished = true; + stream.emit("prefinish"); + // Backwards compat. Don't check state.sync here. + // Some streams assume 'finish' will be emitted + // asynchronously relative to _final callback. + state.pendingcb++; + process$1.nextTick(finish, stream, state); + } + } + state.sync = true; + state.pendingcb++; + try { + stream._final(onFinish); + } catch (err) { + onFinish(err); + } + state.sync = false; + } + function prefinish(stream, state) { + if (!state.prefinished && !state.finalCalled) { + if (typeof stream._final === "function" && !state.destroyed) { + state.finalCalled = true; + callFinal(stream, state); + } else { + state.prefinished = true; + stream.emit("prefinish"); + } + } + } + function finishMaybe(stream, state, sync) { + if (needFinish(state)) { + prefinish(stream, state); + if (state.pendingcb === 0) { + if (sync) { + state.pendingcb++; + process$1.nextTick((stream, state) => { + if (needFinish(state)) { + finish(stream, state); + } else { + state.pendingcb--; + } + }, stream, state); + } else if (needFinish(state)) { + state.pendingcb++; + finish(stream, state); + } + } + } + } + function finish(stream, state) { + state.pendingcb--; + state.finished = true; + const onfinishCallbacks = state[kOnFinished].splice(0); + for (let i = 0; i < onfinishCallbacks.length; i++) { + onfinishCallbacks[i](); + } + stream.emit("finish"); + if (state.autoDestroy) { + // In case of duplex streams we need a way to detect + // if the readable side is ready for autoDestroy as well. + const rState = stream._readableState; + const autoDestroy = !rState || rState.autoDestroy && ( + // We don't expect the readable to ever 'end' + // if readable is explicitly set to false. + rState.endEmitted || rState.readable === false); + if (autoDestroy) { + stream.destroy(); + } + } + } + ObjectDefineProperties(Writable.prototype, { + closed: { + __proto__: null, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.closed : false; + } + }, + destroyed: { + __proto__: null, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.destroyed : false; + }, + set(value) { + // Backward compatibility, the user is explicitly managing destroyed. + if ((this || _global$1)._writableState) { + (this || _global$1)._writableState.destroyed = value; + } + } + }, + writable: { + __proto__: null, + get() { + const w = (this || _global$1)._writableState; + // w.writable === false means that this is part of a Duplex stream + // where the writable side was disabled upon construction. + // Compat. The user might manually disable writable side through + // deprecated setter. + return !!w && w.writable !== false && !w.destroyed && !w.errored && !w.ending && !w.ended; + }, + set(val) { + // Backwards compatible. + if ((this || _global$1)._writableState) { + (this || _global$1)._writableState.writable = !!val; + } + } + }, + writableFinished: { + __proto__: null, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.finished : false; + } + }, + writableObjectMode: { + __proto__: null, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.objectMode : false; + } + }, + writableBuffer: { + __proto__: null, + get() { + return (this || _global$1)._writableState && (this || _global$1)._writableState.getBuffer(); + } + }, + writableEnded: { + __proto__: null, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.ending : false; + } + }, + writableNeedDrain: { + __proto__: null, + get() { + const wState = (this || _global$1)._writableState; + if (!wState) return false; + return !wState.destroyed && !wState.ending && wState.needDrain; + } + }, + writableHighWaterMark: { + __proto__: null, + get() { + return (this || _global$1)._writableState && (this || _global$1)._writableState.highWaterMark; + } + }, + writableCorked: { + __proto__: null, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.corked : 0; + } + }, + writableLength: { + __proto__: null, + get() { + return (this || _global$1)._writableState && (this || _global$1)._writableState.length; + } + }, + errored: { + __proto__: null, + enumerable: false, + get() { + return (this || _global$1)._writableState ? (this || _global$1)._writableState.errored : null; + } + }, + writableAborted: { + __proto__: null, + enumerable: false, + get: function () { + return !!((this || _global$1)._writableState.writable !== false && ((this || _global$1)._writableState.destroyed || (this || _global$1)._writableState.errored) && !(this || _global$1)._writableState.finished); + } + } + }); + const destroy = destroyImpl.destroy; + Writable.prototype.destroy = function (err, cb) { + const state = (this || _global$1)._writableState; + + // Invoke pending callbacks. + if (!state.destroyed && (state.bufferedIndex < state.buffered.length || state[kOnFinished].length)) { + process$1.nextTick(errorBuffer, state); + } + destroy.call(this || _global$1, err, cb); + return this || _global$1; + }; + Writable.prototype._undestroy = destroyImpl.undestroy; + Writable.prototype._destroy = function (err, cb) { + cb(err); + }; + Writable.prototype[EE.captureRejectionSymbol] = function (err) { + this.destroy(err); + }; + let webStreamsAdapters; + + // Lazy to avoid circular references + function lazyWebStreams() { + if (webStreamsAdapters === undefined) webStreamsAdapters = {}; + return webStreamsAdapters; + } + Writable.fromWeb = function (writableStream, options) { + return lazyWebStreams().newStreamWritableFromWritableStream(writableStream, options); + }; + Writable.toWeb = function (streamWritable) { + return lazyWebStreams().newWritableStreamFromStreamWritable(streamWritable); + }; + return exports$b; +} + +var exports$a = {}, + _dewExec$9 = false; +function dew$9() { + if (_dewExec$9) return exports$a; + _dewExec$9 = true; + /* replacement start */ + + const process$1 = process + + /* replacement end */; + const bufferModule = dew$p(); + const { + isReadable, + isWritable, + isIterable, + isNodeStream, + isReadableNodeStream, + isWritableNodeStream, + isDuplexNodeStream, + isReadableStream, + isWritableStream + } = dew$j(); + const eos = dew$i(); + const { + AbortError, + codes: { + ERR_INVALID_ARG_TYPE, + ERR_INVALID_RETURN_VALUE + } + } = dew$l(); + const { + destroyer + } = dew$h(); + const Duplex = dew$8(); + const Readable = dew$b(); + const Writable = dew$a(); + const { + createDeferredPromise + } = dew$m(); + const from = dew$c(); + const Blob = globalThis.Blob || bufferModule.Blob; + const isBlob = typeof Blob !== "undefined" ? function isBlob(b) { + return b instanceof Blob; + } : function isBlob(b) { + return false; + }; + const AbortController = globalThis.AbortController || dew$n().AbortController; + const { + FunctionPrototypeCall + } = dew$o(); + + // This is needed for pre node 17. + class Duplexify extends Duplex { + constructor(options) { + super(options); + + // https://github.com/nodejs/node/pull/34385 + + if ((options === null || options === undefined ? undefined : options.readable) === false) { + this._readableState.readable = false; + this._readableState.ended = true; + this._readableState.endEmitted = true; + } + if ((options === null || options === undefined ? undefined : options.writable) === false) { + this._writableState.writable = false; + this._writableState.ending = true; + this._writableState.ended = true; + this._writableState.finished = true; + } + } + } + exports$a = function duplexify(body, name) { + if (isDuplexNodeStream(body)) { + return body; + } + if (isReadableNodeStream(body)) { + return _duplexify({ + readable: body + }); + } + if (isWritableNodeStream(body)) { + return _duplexify({ + writable: body + }); + } + if (isNodeStream(body)) { + return _duplexify({ + writable: false, + readable: false + }); + } + if (isReadableStream(body)) { + return _duplexify({ + readable: Readable.fromWeb(body) + }); + } + if (isWritableStream(body)) { + return _duplexify({ + writable: Writable.fromWeb(body) + }); + } + if (typeof body === "function") { + const { + value, + write, + final, + destroy + } = fromAsyncGen(body); + if (isIterable(value)) { + return from(Duplexify, value, { + // TODO (ronag): highWaterMark? + objectMode: true, + write, + final, + destroy + }); + } + const then = value === null || value === undefined ? undefined : value.then; + if (typeof then === "function") { + let d; + const promise = FunctionPrototypeCall(then, value, val => { + if (val != null) { + throw new ERR_INVALID_RETURN_VALUE("nully", "body", val); + } + }, err => { + destroyer(d, err); + }); + return d = new Duplexify({ + // TODO (ronag): highWaterMark? + objectMode: true, + readable: false, + write, + final(cb) { + final(async () => { + try { + await promise; + process$1.nextTick(cb, null); + } catch (err) { + process$1.nextTick(cb, err); + } + }); + }, + destroy + }); + } + throw new ERR_INVALID_RETURN_VALUE("Iterable, AsyncIterable or AsyncFunction", name, value); + } + if (isBlob(body)) { + return duplexify(body.arrayBuffer()); + } + if (isIterable(body)) { + return from(Duplexify, body, { + // TODO (ronag): highWaterMark? + objectMode: true, + writable: false + }); + } + if (isReadableStream(body === null || body === undefined ? undefined : body.readable) && isWritableStream(body === null || body === undefined ? undefined : body.writable)) { + return Duplexify.fromWeb(body); + } + if (typeof (body === null || body === undefined ? undefined : body.writable) === "object" || typeof (body === null || body === undefined ? undefined : body.readable) === "object") { + const readable = body !== null && body !== undefined && body.readable ? isReadableNodeStream(body === null || body === undefined ? undefined : body.readable) ? body === null || body === undefined ? undefined : body.readable : duplexify(body.readable) : undefined; + const writable = body !== null && body !== undefined && body.writable ? isWritableNodeStream(body === null || body === undefined ? undefined : body.writable) ? body === null || body === undefined ? undefined : body.writable : duplexify(body.writable) : undefined; + return _duplexify({ + readable, + writable + }); + } + const then = body === null || body === undefined ? undefined : body.then; + if (typeof then === "function") { + let d; + FunctionPrototypeCall(then, body, val => { + if (val != null) { + d.push(val); + } + d.push(null); + }, err => { + destroyer(d, err); + }); + return d = new Duplexify({ + objectMode: true, + writable: false, + read() {} + }); + } + throw new ERR_INVALID_ARG_TYPE(name, ["Blob", "ReadableStream", "WritableStream", "Stream", "Iterable", "AsyncIterable", "Function", "{ readable, writable } pair", "Promise"], body); + }; + function fromAsyncGen(fn) { + let { + promise, + resolve + } = createDeferredPromise(); + const ac = new AbortController(); + const signal = ac.signal; + const value = fn(async function* () { + while (true) { + const _promise = promise; + promise = null; + const { + chunk, + done, + cb + } = await _promise; + process$1.nextTick(cb); + if (done) return; + if (signal.aborted) throw new AbortError(undefined, { + cause: signal.reason + }); + ({ + promise, + resolve + } = createDeferredPromise()); + yield chunk; + } + }(), { + signal + }); + return { + value, + write(chunk, encoding, cb) { + const _resolve = resolve; + resolve = null; + _resolve({ + chunk, + done: false, + cb + }); + }, + final(cb) { + const _resolve = resolve; + resolve = null; + _resolve({ + done: true, + cb + }); + }, + destroy(err, cb) { + ac.abort(); + cb(err); + } + }; + } + function _duplexify(pair) { + const r = pair.readable && typeof pair.readable.read !== "function" ? Readable.wrap(pair.readable) : pair.readable; + const w = pair.writable; + let readable = !!isReadable(r); + let writable = !!isWritable(w); + let ondrain; + let onfinish; + let onreadable; + let onclose; + let d; + function onfinished(err) { + const cb = onclose; + onclose = null; + if (cb) { + cb(err); + } else if (err) { + d.destroy(err); + } + } + + // TODO(ronag): Avoid double buffering. + // Implement Writable/Readable/Duplex traits. + // See, https://github.com/nodejs/node/pull/33515. + d = new Duplexify({ + // TODO (ronag): highWaterMark? + readableObjectMode: !!(r !== null && r !== undefined && r.readableObjectMode), + writableObjectMode: !!(w !== null && w !== undefined && w.writableObjectMode), + readable, + writable + }); + if (writable) { + eos(w, err => { + writable = false; + if (err) { + destroyer(r, err); + } + onfinished(err); + }); + d._write = function (chunk, encoding, callback) { + if (w.write(chunk, encoding)) { + callback(); + } else { + ondrain = callback; + } + }; + d._final = function (callback) { + w.end(); + onfinish = callback; + }; + w.on("drain", function () { + if (ondrain) { + const cb = ondrain; + ondrain = null; + cb(); + } + }); + w.on("finish", function () { + if (onfinish) { + const cb = onfinish; + onfinish = null; + cb(); + } + }); + } + if (readable) { + eos(r, err => { + readable = false; + if (err) { + destroyer(r, err); + } + onfinished(err); + }); + r.on("readable", function () { + if (onreadable) { + const cb = onreadable; + onreadable = null; + cb(); + } + }); + r.on("end", function () { + d.push(null); + }); + d._read = function () { + while (true) { + const buf = r.read(); + if (buf === null) { + onreadable = d._read; + return; + } + if (!d.push(buf)) { + return; + } + } + }; + } + d._destroy = function (err, callback) { + if (!err && onclose !== null) { + err = new AbortError(); + } + onreadable = null; + ondrain = null; + onfinish = null; + if (onclose === null) { + callback(err); + } else { + onclose = callback; + destroyer(w, err); + destroyer(r, err); + } + }; + return d; + } + return exports$a; +} + +var exports$9 = {}, + _dewExec$8 = false; +function dew$8() { + if (_dewExec$8) return exports$9; + _dewExec$8 = true; + const { + ObjectDefineProperties, + ObjectGetOwnPropertyDescriptor, + ObjectKeys, + ObjectSetPrototypeOf + } = dew$o(); + exports$9 = Duplex; + const Readable = dew$b(); + const Writable = dew$a(); + ObjectSetPrototypeOf(Duplex.prototype, Readable.prototype); + ObjectSetPrototypeOf(Duplex, Readable); + { + const keys = ObjectKeys(Writable.prototype); + // Allow the keys array to be GC'ed. + for (let i = 0; i < keys.length; i++) { + const method = keys[i]; + if (!Duplex.prototype[method]) Duplex.prototype[method] = Writable.prototype[method]; + } + } + function Duplex(options) { + if (!(this instanceof Duplex)) return new Duplex(options); + Readable.call(this, options); + Writable.call(this, options); + if (options) { + this.allowHalfOpen = options.allowHalfOpen !== false; + if (options.readable === false) { + this._readableState.readable = false; + this._readableState.ended = true; + this._readableState.endEmitted = true; + } + if (options.writable === false) { + this._writableState.writable = false; + this._writableState.ending = true; + this._writableState.ended = true; + this._writableState.finished = true; + } + } else { + this.allowHalfOpen = true; + } + } + ObjectDefineProperties(Duplex.prototype, { + writable: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writable") + }, + writableHighWaterMark: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableHighWaterMark") + }, + writableObjectMode: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableObjectMode") + }, + writableBuffer: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableBuffer") + }, + writableLength: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableLength") + }, + writableFinished: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableFinished") + }, + writableCorked: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableCorked") + }, + writableEnded: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableEnded") + }, + writableNeedDrain: { + __proto__: null, + ...ObjectGetOwnPropertyDescriptor(Writable.prototype, "writableNeedDrain") + }, + destroyed: { + __proto__: null, + get() { + if (this._readableState === undefined || this._writableState === undefined) { + return false; + } + return this._readableState.destroyed && this._writableState.destroyed; + }, + set(value) { + // Backward compatibility, the user is explicitly + // managing destroyed. + if (this._readableState && this._writableState) { + this._readableState.destroyed = value; + this._writableState.destroyed = value; + } + } + } + }); + let webStreamsAdapters; + + // Lazy to avoid circular references + function lazyWebStreams() { + if (webStreamsAdapters === undefined) webStreamsAdapters = {}; + return webStreamsAdapters; + } + Duplex.fromWeb = function (pair, options) { + return lazyWebStreams().newStreamDuplexFromReadableWritablePair(pair, options); + }; + Duplex.toWeb = function (duplex) { + return lazyWebStreams().newReadableWritablePairFromDuplex(duplex); + }; + let duplexify; + Duplex.from = function (body) { + if (!duplexify) { + duplexify = dew$9(); + } + return duplexify(body, "body"); + }; + return exports$9; +} + +var exports$8 = {}, + _dewExec$7 = false; +function dew$7() { + if (_dewExec$7) return exports$8; + _dewExec$7 = true; + const { + ObjectSetPrototypeOf, + Symbol + } = dew$o(); + exports$8 = Transform; + const { + ERR_METHOD_NOT_IMPLEMENTED + } = dew$l().codes; + const Duplex = dew$8(); + const { + getHighWaterMark + } = dew$d(); + ObjectSetPrototypeOf(Transform.prototype, Duplex.prototype); + ObjectSetPrototypeOf(Transform, Duplex); + const kCallback = Symbol("kCallback"); + function Transform(options) { + if (!(this instanceof Transform)) return new Transform(options); + + // TODO (ronag): This should preferably always be + // applied but would be semver-major. Or even better; + // make Transform a Readable with the Writable interface. + const readableHighWaterMark = options ? getHighWaterMark(this, options, "readableHighWaterMark", true) : null; + if (readableHighWaterMark === 0) { + // A Duplex will buffer both on the writable and readable side while + // a Transform just wants to buffer hwm number of elements. To avoid + // buffering twice we disable buffering on the writable side. + options = { + ...options, + highWaterMark: null, + readableHighWaterMark, + // TODO (ronag): 0 is not optimal since we have + // a "bug" where we check needDrain before calling _write and not after. + // Refs: https://github.com/nodejs/node/pull/32887 + // Refs: https://github.com/nodejs/node/pull/35941 + writableHighWaterMark: options.writableHighWaterMark || 0 + }; + } + Duplex.call(this, options); + + // We have implemented the _read method, and done the other things + // that Readable wants before the first _read call, so unset the + // sync guard flag. + this._readableState.sync = false; + this[kCallback] = null; + if (options) { + if (typeof options.transform === "function") this._transform = options.transform; + if (typeof options.flush === "function") this._flush = options.flush; + } + + // When the writable side finishes, then flush out anything remaining. + // Backwards compat. Some Transform streams incorrectly implement _final + // instead of or in addition to _flush. By using 'prefinish' instead of + // implementing _final we continue supporting this unfortunate use case. + this.on("prefinish", prefinish); + } + function final(cb) { + if (typeof this._flush === "function" && !this.destroyed) { + this._flush((er, data) => { + if (er) { + if (cb) { + cb(er); + } else { + this.destroy(er); + } + return; + } + if (data != null) { + this.push(data); + } + this.push(null); + if (cb) { + cb(); + } + }); + } else { + this.push(null); + if (cb) { + cb(); + } + } + } + function prefinish() { + if (this._final !== final) { + final.call(this); + } + } + Transform.prototype._final = final; + Transform.prototype._transform = function (chunk, encoding, callback) { + throw new ERR_METHOD_NOT_IMPLEMENTED("_transform()"); + }; + Transform.prototype._write = function (chunk, encoding, callback) { + const rState = this._readableState; + const wState = this._writableState; + const length = rState.length; + this._transform(chunk, encoding, (err, val) => { + if (err) { + callback(err); + return; + } + if (val != null) { + this.push(val); + } + if (wState.ended || + // Backwards compat. + length === rState.length || + // Backwards compat. + rState.length < rState.highWaterMark) { + callback(); + } else { + this[kCallback] = callback; + } + }); + }; + Transform.prototype._read = function () { + if (this[kCallback]) { + const callback = this[kCallback]; + this[kCallback] = null; + callback(); + } + }; + return exports$8; +} + +var exports$7 = {}, + _dewExec$6 = false; +function dew$6() { + if (_dewExec$6) return exports$7; + _dewExec$6 = true; + const { + ObjectSetPrototypeOf + } = dew$o(); + exports$7 = PassThrough; + const Transform = dew$7(); + ObjectSetPrototypeOf(PassThrough.prototype, Transform.prototype); + ObjectSetPrototypeOf(PassThrough, Transform); + function PassThrough(options) { + if (!(this instanceof PassThrough)) return new PassThrough(options); + Transform.call(this, options); + } + PassThrough.prototype._transform = function (chunk, encoding, cb) { + cb(null, chunk); + }; + return exports$7; +} + +var exports$6 = {}, + _dewExec$5 = false; +function dew$5() { + if (_dewExec$5) return exports$6; + _dewExec$5 = true; + /* replacement start */ + + const process$1 = process + + /* replacement end */ + // Ported from https://github.com/mafintosh/pump with + // permission from the author, Mathias Buus (@mafintosh). + ; + const { + ArrayIsArray, + Promise, + SymbolAsyncIterator, + SymbolDispose + } = dew$o(); + const eos = dew$i(); + const { + once + } = dew$m(); + const destroyImpl = dew$h(); + const Duplex = dew$8(); + const { + aggregateTwoErrors, + codes: { + ERR_INVALID_ARG_TYPE, + ERR_INVALID_RETURN_VALUE, + ERR_MISSING_ARGS, + ERR_STREAM_DESTROYED, + ERR_STREAM_PREMATURE_CLOSE + }, + AbortError + } = dew$l(); + const { + validateFunction, + validateAbortSignal + } = dew$k(); + const { + isIterable, + isReadable, + isReadableNodeStream, + isNodeStream, + isTransformStream, + isWebStream, + isReadableStream, + isReadableFinished + } = dew$j(); + const AbortController = globalThis.AbortController || dew$n().AbortController; + let PassThrough; + let Readable; + let addAbortListener; + function destroyer(stream, reading, writing) { + let finished = false; + stream.on("close", () => { + finished = true; + }); + const cleanup = eos(stream, { + readable: reading, + writable: writing + }, err => { + finished = !err; + }); + return { + destroy: err => { + if (finished) return; + finished = true; + destroyImpl.destroyer(stream, err || new ERR_STREAM_DESTROYED("pipe")); + }, + cleanup + }; + } + function popCallback(streams) { + // Streams should never be an empty array. It should always contain at least + // a single stream. Therefore optimize for the average case instead of + // checking for length === 0 as well. + validateFunction(streams[streams.length - 1], "streams[stream.length - 1]"); + return streams.pop(); + } + function makeAsyncIterable(val) { + if (isIterable(val)) { + return val; + } else if (isReadableNodeStream(val)) { + // Legacy streams are not Iterable. + return fromReadable(val); + } + throw new ERR_INVALID_ARG_TYPE("val", ["Readable", "Iterable", "AsyncIterable"], val); + } + async function* fromReadable(val) { + if (!Readable) { + Readable = dew$b(); + } + yield* Readable.prototype[SymbolAsyncIterator].call(val); + } + async function pumpToNode(iterable, writable, finish, { + end + }) { + let error; + let onresolve = null; + const resume = err => { + if (err) { + error = err; + } + if (onresolve) { + const callback = onresolve; + onresolve = null; + callback(); + } + }; + const wait = () => new Promise((resolve, reject) => { + if (error) { + reject(error); + } else { + onresolve = () => { + if (error) { + reject(error); + } else { + resolve(); + } + }; + } + }); + writable.on("drain", resume); + const cleanup = eos(writable, { + readable: false + }, resume); + try { + if (writable.writableNeedDrain) { + await wait(); + } + for await (const chunk of iterable) { + if (!writable.write(chunk)) { + await wait(); + } + } + if (end) { + writable.end(); + await wait(); + } + finish(); + } catch (err) { + finish(error !== err ? aggregateTwoErrors(error, err) : err); + } finally { + cleanup(); + writable.off("drain", resume); + } + } + async function pumpToWeb(readable, writable, finish, { + end + }) { + if (isTransformStream(writable)) { + writable = writable.writable; + } + // https://streams.spec.whatwg.org/#example-manual-write-with-backpressure + const writer = writable.getWriter(); + try { + for await (const chunk of readable) { + await writer.ready; + writer.write(chunk).catch(() => {}); + } + await writer.ready; + if (end) { + await writer.close(); + } + finish(); + } catch (err) { + try { + await writer.abort(err); + finish(err); + } catch (err) { + finish(err); + } + } + } + function pipeline(...streams) { + return pipelineImpl(streams, once(popCallback(streams))); + } + function pipelineImpl(streams, callback, opts) { + if (streams.length === 1 && ArrayIsArray(streams[0])) { + streams = streams[0]; + } + if (streams.length < 2) { + throw new ERR_MISSING_ARGS("streams"); + } + const ac = new AbortController(); + const signal = ac.signal; + const outerSignal = opts === null || opts === undefined ? undefined : opts.signal; + + // Need to cleanup event listeners if last stream is readable + // https://github.com/nodejs/node/issues/35452 + const lastStreamCleanup = []; + validateAbortSignal(outerSignal, "options.signal"); + function abort() { + finishImpl(new AbortError()); + } + addAbortListener = addAbortListener || dew$m().addAbortListener; + let disposable; + if (outerSignal) { + disposable = addAbortListener(outerSignal, abort); + } + let error; + let value; + const destroys = []; + let finishCount = 0; + function finish(err) { + finishImpl(err, --finishCount === 0); + } + function finishImpl(err, final) { + var _disposable; + if (err && (!error || error.code === "ERR_STREAM_PREMATURE_CLOSE")) { + error = err; + } + if (!error && !final) { + return; + } + while (destroys.length) { + destroys.shift()(error); + } + (_disposable = disposable) === null || _disposable === undefined ? undefined : _disposable[SymbolDispose](); + ac.abort(); + if (final) { + if (!error) { + lastStreamCleanup.forEach(fn => fn()); + } + process$1.nextTick(callback, error, value); + } + } + let ret; + for (let i = 0; i < streams.length; i++) { + const stream = streams[i]; + const reading = i < streams.length - 1; + const writing = i > 0; + const end = reading || (opts === null || opts === undefined ? undefined : opts.end) !== false; + const isLastStream = i === streams.length - 1; + if (isNodeStream(stream)) { + if (end) { + const { + destroy, + cleanup + } = destroyer(stream, reading, writing); + destroys.push(destroy); + if (isReadable(stream) && isLastStream) { + lastStreamCleanup.push(cleanup); + } + } + + // Catch stream errors that occur after pipe/pump has completed. + function onError(err) { + if (err && err.name !== "AbortError" && err.code !== "ERR_STREAM_PREMATURE_CLOSE") { + finish(err); + } + } + stream.on("error", onError); + if (isReadable(stream) && isLastStream) { + lastStreamCleanup.push(() => { + stream.removeListener("error", onError); + }); + } + } + if (i === 0) { + if (typeof stream === "function") { + ret = stream({ + signal + }); + if (!isIterable(ret)) { + throw new ERR_INVALID_RETURN_VALUE("Iterable, AsyncIterable or Stream", "source", ret); + } + } else if (isIterable(stream) || isReadableNodeStream(stream) || isTransformStream(stream)) { + ret = stream; + } else { + ret = Duplex.from(stream); + } + } else if (typeof stream === "function") { + if (isTransformStream(ret)) { + var _ret; + ret = makeAsyncIterable((_ret = ret) === null || _ret === undefined ? undefined : _ret.readable); + } else { + ret = makeAsyncIterable(ret); + } + ret = stream(ret, { + signal + }); + if (reading) { + if (!isIterable(ret, true)) { + throw new ERR_INVALID_RETURN_VALUE("AsyncIterable", `transform[${i - 1}]`, ret); + } + } else { + var _ret2; + if (!PassThrough) { + PassThrough = dew$6(); + } + + // If the last argument to pipeline is not a stream + // we must create a proxy stream so that pipeline(...) + // always returns a stream which can be further + // composed through `.pipe(stream)`. + + const pt = new PassThrough({ + objectMode: true + }); + + // Handle Promises/A+ spec, `then` could be a getter that throws on + // second use. + const then = (_ret2 = ret) === null || _ret2 === undefined ? undefined : _ret2.then; + if (typeof then === "function") { + finishCount++; + then.call(ret, val => { + value = val; + if (val != null) { + pt.write(val); + } + if (end) { + pt.end(); + } + process$1.nextTick(finish); + }, err => { + pt.destroy(err); + process$1.nextTick(finish, err); + }); + } else if (isIterable(ret, true)) { + finishCount++; + pumpToNode(ret, pt, finish, { + end + }); + } else if (isReadableStream(ret) || isTransformStream(ret)) { + const toRead = ret.readable || ret; + finishCount++; + pumpToNode(toRead, pt, finish, { + end + }); + } else { + throw new ERR_INVALID_RETURN_VALUE("AsyncIterable or Promise", "destination", ret); + } + ret = pt; + const { + destroy, + cleanup + } = destroyer(ret, false, true); + destroys.push(destroy); + if (isLastStream) { + lastStreamCleanup.push(cleanup); + } + } + } else if (isNodeStream(stream)) { + if (isReadableNodeStream(ret)) { + finishCount += 2; + const cleanup = pipe(ret, stream, finish, { + end + }); + if (isReadable(stream) && isLastStream) { + lastStreamCleanup.push(cleanup); + } + } else if (isTransformStream(ret) || isReadableStream(ret)) { + const toRead = ret.readable || ret; + finishCount++; + pumpToNode(toRead, stream, finish, { + end + }); + } else if (isIterable(ret)) { + finishCount++; + pumpToNode(ret, stream, finish, { + end + }); + } else { + throw new ERR_INVALID_ARG_TYPE("val", ["Readable", "Iterable", "AsyncIterable", "ReadableStream", "TransformStream"], ret); + } + ret = stream; + } else if (isWebStream(stream)) { + if (isReadableNodeStream(ret)) { + finishCount++; + pumpToWeb(makeAsyncIterable(ret), stream, finish, { + end + }); + } else if (isReadableStream(ret) || isIterable(ret)) { + finishCount++; + pumpToWeb(ret, stream, finish, { + end + }); + } else if (isTransformStream(ret)) { + finishCount++; + pumpToWeb(ret.readable, stream, finish, { + end + }); + } else { + throw new ERR_INVALID_ARG_TYPE("val", ["Readable", "Iterable", "AsyncIterable", "ReadableStream", "TransformStream"], ret); + } + ret = stream; + } else { + ret = Duplex.from(stream); + } + } + if (signal !== null && signal !== undefined && signal.aborted || outerSignal !== null && outerSignal !== undefined && outerSignal.aborted) { + process$1.nextTick(abort); + } + return ret; + } + function pipe(src, dst, finish, { + end + }) { + let ended = false; + dst.on("close", () => { + if (!ended) { + // Finish if the destination closes before the source has completed. + finish(new ERR_STREAM_PREMATURE_CLOSE()); + } + }); + src.pipe(dst, { + end: false + }); // If end is true we already will have a listener to end dst. + + if (end) { + // Compat. Before node v10.12.0 stdio used to throw an error so + // pipe() did/does not end() stdio destinations. + // Now they allow it but "secretly" don't close the underlying fd. + + function endFn() { + ended = true; + dst.end(); + } + if (isReadableFinished(src)) { + // End the destination if the source has already ended. + process$1.nextTick(endFn); + } else { + src.once("end", endFn); + } + } else { + finish(); + } + eos(src, { + readable: true, + writable: false + }, err => { + const rState = src._readableState; + if (err && err.code === "ERR_STREAM_PREMATURE_CLOSE" && rState && rState.ended && !rState.errored && !rState.errorEmitted) { + // Some readable streams will emit 'close' before 'end'. However, since + // this is on the readable side 'end' should still be emitted if the + // stream has been ended and no error emitted. This should be allowed in + // favor of backwards compatibility. Since the stream is piped to a + // destination this should not result in any observable difference. + // We don't need to check if this is a writable premature close since + // eos will only fail with premature close on the reading side for + // duplex streams. + src.once("end", finish).once("error", finish); + } else { + finish(err); + } + }); + return eos(dst, { + readable: false, + writable: true + }, finish); + } + exports$6 = { + pipelineImpl, + pipeline + }; + return exports$6; +} + +var exports$5 = {}, + _dewExec$4 = false; +function dew$4() { + if (_dewExec$4) return exports$5; + _dewExec$4 = true; + const { + pipeline + } = dew$5(); + const Duplex = dew$8(); + const { + destroyer + } = dew$h(); + const { + isNodeStream, + isReadable, + isWritable, + isWebStream, + isTransformStream, + isWritableStream, + isReadableStream + } = dew$j(); + const { + AbortError, + codes: { + ERR_INVALID_ARG_VALUE, + ERR_MISSING_ARGS + } + } = dew$l(); + const eos = dew$i(); + exports$5 = function compose(...streams) { + if (streams.length === 0) { + throw new ERR_MISSING_ARGS("streams"); + } + if (streams.length === 1) { + return Duplex.from(streams[0]); + } + const orgStreams = [...streams]; + if (typeof streams[0] === "function") { + streams[0] = Duplex.from(streams[0]); + } + if (typeof streams[streams.length - 1] === "function") { + const idx = streams.length - 1; + streams[idx] = Duplex.from(streams[idx]); + } + for (let n = 0; n < streams.length; ++n) { + if (!isNodeStream(streams[n]) && !isWebStream(streams[n])) { + // TODO(ronag): Add checks for non streams. + continue; + } + if (n < streams.length - 1 && !(isReadable(streams[n]) || isReadableStream(streams[n]) || isTransformStream(streams[n]))) { + throw new ERR_INVALID_ARG_VALUE(`streams[${n}]`, orgStreams[n], "must be readable"); + } + if (n > 0 && !(isWritable(streams[n]) || isWritableStream(streams[n]) || isTransformStream(streams[n]))) { + throw new ERR_INVALID_ARG_VALUE(`streams[${n}]`, orgStreams[n], "must be writable"); + } + } + let ondrain; + let onfinish; + let onreadable; + let onclose; + let d; + function onfinished(err) { + const cb = onclose; + onclose = null; + if (cb) { + cb(err); + } else if (err) { + d.destroy(err); + } else if (!readable && !writable) { + d.destroy(); + } + } + const head = streams[0]; + const tail = pipeline(streams, onfinished); + const writable = !!(isWritable(head) || isWritableStream(head) || isTransformStream(head)); + const readable = !!(isReadable(tail) || isReadableStream(tail) || isTransformStream(tail)); + + // TODO(ronag): Avoid double buffering. + // Implement Writable/Readable/Duplex traits. + // See, https://github.com/nodejs/node/pull/33515. + d = new Duplex({ + // TODO (ronag): highWaterMark? + writableObjectMode: !!(head !== null && head !== undefined && head.writableObjectMode), + readableObjectMode: !!(tail !== null && tail !== undefined && tail.readableObjectMode), + writable, + readable + }); + if (writable) { + if (isNodeStream(head)) { + d._write = function (chunk, encoding, callback) { + if (head.write(chunk, encoding)) { + callback(); + } else { + ondrain = callback; + } + }; + d._final = function (callback) { + head.end(); + onfinish = callback; + }; + head.on("drain", function () { + if (ondrain) { + const cb = ondrain; + ondrain = null; + cb(); + } + }); + } else if (isWebStream(head)) { + const writable = isTransformStream(head) ? head.writable : head; + const writer = writable.getWriter(); + d._write = async function (chunk, encoding, callback) { + try { + await writer.ready; + writer.write(chunk).catch(() => {}); + callback(); + } catch (err) { + callback(err); + } + }; + d._final = async function (callback) { + try { + await writer.ready; + writer.close().catch(() => {}); + onfinish = callback; + } catch (err) { + callback(err); + } + }; + } + const toRead = isTransformStream(tail) ? tail.readable : tail; + eos(toRead, () => { + if (onfinish) { + const cb = onfinish; + onfinish = null; + cb(); + } + }); + } + if (readable) { + if (isNodeStream(tail)) { + tail.on("readable", function () { + if (onreadable) { + const cb = onreadable; + onreadable = null; + cb(); + } + }); + tail.on("end", function () { + d.push(null); + }); + d._read = function () { + while (true) { + const buf = tail.read(); + if (buf === null) { + onreadable = d._read; + return; + } + if (!d.push(buf)) { + return; + } + } + }; + } else if (isWebStream(tail)) { + const readable = isTransformStream(tail) ? tail.readable : tail; + const reader = readable.getReader(); + d._read = async function () { + while (true) { + try { + const { + value, + done + } = await reader.read(); + if (!d.push(value)) { + return; + } + if (done) { + d.push(null); + return; + } + } catch { + return; + } + } + }; + } + } + d._destroy = function (err, callback) { + if (!err && onclose !== null) { + err = new AbortError(); + } + onreadable = null; + ondrain = null; + onfinish = null; + if (onclose === null) { + callback(err); + } else { + onclose = callback; + if (isNodeStream(tail)) { + destroyer(tail, err); + } + } + }; + return d; + }; + return exports$5; +} + +var exports$4 = {}, + _dewExec$3 = false; +function dew$3() { + if (_dewExec$3) return exports$4; + _dewExec$3 = true; + const AbortController = globalThis.AbortController || dew$n().AbortController; + const { + codes: { + ERR_INVALID_ARG_VALUE, + ERR_INVALID_ARG_TYPE, + ERR_MISSING_ARGS, + ERR_OUT_OF_RANGE + }, + AbortError + } = dew$l(); + const { + validateAbortSignal, + validateInteger, + validateObject + } = dew$k(); + const kWeakHandler = dew$o().Symbol("kWeak"); + const kResistStopPropagation = dew$o().Symbol("kResistStopPropagation"); + const { + finished + } = dew$i(); + const staticCompose = dew$4(); + const { + addAbortSignalNoValidate + } = dew$f(); + const { + isWritable, + isNodeStream + } = dew$j(); + const { + deprecate + } = dew$m(); + const { + ArrayPrototypePush, + Boolean, + MathFloor, + Number, + NumberIsNaN, + Promise, + PromiseReject, + PromiseResolve, + PromisePrototypeThen, + Symbol + } = dew$o(); + const kEmpty = Symbol("kEmpty"); + const kEof = Symbol("kEof"); + function compose(stream, options) { + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + if (isNodeStream(stream) && !isWritable(stream)) { + throw new ERR_INVALID_ARG_VALUE("stream", stream, "must be writable"); + } + const composedStream = staticCompose(this, stream); + if (options !== null && options !== undefined && options.signal) { + // Not validating as we already validated before + addAbortSignalNoValidate(options.signal, composedStream); + } + return composedStream; + } + function map(fn, options) { + if (typeof fn !== "function") { + throw new ERR_INVALID_ARG_TYPE("fn", ["Function", "AsyncFunction"], fn); + } + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + let concurrency = 1; + if ((options === null || options === undefined ? undefined : options.concurrency) != null) { + concurrency = MathFloor(options.concurrency); + } + let highWaterMark = concurrency - 1; + if ((options === null || options === undefined ? undefined : options.highWaterMark) != null) { + highWaterMark = MathFloor(options.highWaterMark); + } + validateInteger(concurrency, "options.concurrency", 1); + validateInteger(highWaterMark, "options.highWaterMark", 0); + highWaterMark += concurrency; + return async function* map() { + const signal = dew$m().AbortSignalAny([options === null || options === undefined ? undefined : options.signal].filter(Boolean)); + const stream = this; + const queue = []; + const signalOpt = { + signal + }; + let next; + let resume; + let done = false; + let cnt = 0; + function onCatch() { + done = true; + afterItemProcessed(); + } + function afterItemProcessed() { + cnt -= 1; + maybeResume(); + } + function maybeResume() { + if (resume && !done && cnt < concurrency && queue.length < highWaterMark) { + resume(); + resume = null; + } + } + async function pump() { + try { + for await (let val of stream) { + if (done) { + return; + } + if (signal.aborted) { + throw new AbortError(); + } + try { + val = fn(val, signalOpt); + if (val === kEmpty) { + continue; + } + val = PromiseResolve(val); + } catch (err) { + val = PromiseReject(err); + } + cnt += 1; + PromisePrototypeThen(val, afterItemProcessed, onCatch); + queue.push(val); + if (next) { + next(); + next = null; + } + if (!done && (queue.length >= highWaterMark || cnt >= concurrency)) { + await new Promise(resolve => { + resume = resolve; + }); + } + } + queue.push(kEof); + } catch (err) { + const val = PromiseReject(err); + PromisePrototypeThen(val, afterItemProcessed, onCatch); + queue.push(val); + } finally { + done = true; + if (next) { + next(); + next = null; + } + } + } + pump(); + try { + while (true) { + while (queue.length > 0) { + const val = await queue[0]; + if (val === kEof) { + return; + } + if (signal.aborted) { + throw new AbortError(); + } + if (val !== kEmpty) { + yield val; + } + queue.shift(); + maybeResume(); + } + await new Promise(resolve => { + next = resolve; + }); + } + } finally { + done = true; + if (resume) { + resume(); + resume = null; + } + } + }.call(this); + } + function asIndexedPairs(options = undefined) { + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + return async function* asIndexedPairs() { + let index = 0; + for await (const val of this) { + var _options$signal; + if (options !== null && options !== undefined && (_options$signal = options.signal) !== null && _options$signal !== undefined && _options$signal.aborted) { + throw new AbortError({ + cause: options.signal.reason + }); + } + yield [index++, val]; + } + }.call(this); + } + async function some(fn, options = undefined) { + for await (const unused of filter.call(this, fn, options)) { + return true; + } + return false; + } + async function every(fn, options = undefined) { + if (typeof fn !== "function") { + throw new ERR_INVALID_ARG_TYPE("fn", ["Function", "AsyncFunction"], fn); + } + // https://en.wikipedia.org/wiki/De_Morgan%27s_laws + return !(await some.call(this, async (...args) => { + return !(await fn(...args)); + }, options)); + } + async function find(fn, options) { + for await (const result of filter.call(this, fn, options)) { + return result; + } + return undefined; + } + async function forEach(fn, options) { + if (typeof fn !== "function") { + throw new ERR_INVALID_ARG_TYPE("fn", ["Function", "AsyncFunction"], fn); + } + async function forEachFn(value, options) { + await fn(value, options); + return kEmpty; + } + // eslint-disable-next-line no-unused-vars + for await (const unused of map.call(this, forEachFn, options)); + } + function filter(fn, options) { + if (typeof fn !== "function") { + throw new ERR_INVALID_ARG_TYPE("fn", ["Function", "AsyncFunction"], fn); + } + async function filterFn(value, options) { + if (await fn(value, options)) { + return value; + } + return kEmpty; + } + return map.call(this, filterFn, options); + } + + // Specific to provide better error to reduce since the argument is only + // missing if the stream has no items in it - but the code is still appropriate + class ReduceAwareErrMissingArgs extends ERR_MISSING_ARGS { + constructor() { + super("reduce"); + this.message = "Reduce of an empty stream requires an initial value"; + } + } + async function reduce(reducer, initialValue, options) { + var _options$signal2; + if (typeof reducer !== "function") { + throw new ERR_INVALID_ARG_TYPE("reducer", ["Function", "AsyncFunction"], reducer); + } + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + let hasInitialValue = arguments.length > 1; + if (options !== null && options !== undefined && (_options$signal2 = options.signal) !== null && _options$signal2 !== undefined && _options$signal2.aborted) { + const err = new AbortError(undefined, { + cause: options.signal.reason + }); + this.once("error", () => {}); // The error is already propagated + await finished(this.destroy(err)); + throw err; + } + const ac = new AbortController(); + const signal = ac.signal; + if (options !== null && options !== undefined && options.signal) { + const opts = { + once: true, + [kWeakHandler]: this, + [kResistStopPropagation]: true + }; + options.signal.addEventListener("abort", () => ac.abort(), opts); + } + let gotAnyItemFromStream = false; + try { + for await (const value of this) { + var _options$signal3; + gotAnyItemFromStream = true; + if (options !== null && options !== undefined && (_options$signal3 = options.signal) !== null && _options$signal3 !== undefined && _options$signal3.aborted) { + throw new AbortError(); + } + if (!hasInitialValue) { + initialValue = value; + hasInitialValue = true; + } else { + initialValue = await reducer(initialValue, value, { + signal + }); + } + } + if (!gotAnyItemFromStream && !hasInitialValue) { + throw new ReduceAwareErrMissingArgs(); + } + } finally { + ac.abort(); + } + return initialValue; + } + async function toArray(options) { + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + const result = []; + for await (const val of this) { + var _options$signal4; + if (options !== null && options !== undefined && (_options$signal4 = options.signal) !== null && _options$signal4 !== undefined && _options$signal4.aborted) { + throw new AbortError(undefined, { + cause: options.signal.reason + }); + } + ArrayPrototypePush(result, val); + } + return result; + } + function flatMap(fn, options) { + const values = map.call(this, fn, options); + return async function* flatMap() { + for await (const val of values) { + yield* val; + } + }.call(this); + } + function toIntegerOrInfinity(number) { + // We coerce here to align with the spec + // https://github.com/tc39/proposal-iterator-helpers/issues/169 + number = Number(number); + if (NumberIsNaN(number)) { + return 0; + } + if (number < 0) { + throw new ERR_OUT_OF_RANGE("number", ">= 0", number); + } + return number; + } + function drop(number, options = undefined) { + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + number = toIntegerOrInfinity(number); + return async function* drop() { + var _options$signal5; + if (options !== null && options !== undefined && (_options$signal5 = options.signal) !== null && _options$signal5 !== undefined && _options$signal5.aborted) { + throw new AbortError(); + } + for await (const val of this) { + var _options$signal6; + if (options !== null && options !== undefined && (_options$signal6 = options.signal) !== null && _options$signal6 !== undefined && _options$signal6.aborted) { + throw new AbortError(); + } + if (number-- <= 0) { + yield val; + } + } + }.call(this); + } + function take(number, options = undefined) { + if (options != null) { + validateObject(options, "options"); + } + if ((options === null || options === undefined ? undefined : options.signal) != null) { + validateAbortSignal(options.signal, "options.signal"); + } + number = toIntegerOrInfinity(number); + return async function* take() { + var _options$signal7; + if (options !== null && options !== undefined && (_options$signal7 = options.signal) !== null && _options$signal7 !== undefined && _options$signal7.aborted) { + throw new AbortError(); + } + for await (const val of this) { + var _options$signal8; + if (options !== null && options !== undefined && (_options$signal8 = options.signal) !== null && _options$signal8 !== undefined && _options$signal8.aborted) { + throw new AbortError(); + } + if (number-- > 0) { + yield val; + } + + // Don't get another item from iterator in case we reached the end + if (number <= 0) { + return; + } + } + }.call(this); + } + exports$4.streamReturningOperators = { + asIndexedPairs: deprecate(asIndexedPairs, "readable.asIndexedPairs will be removed in a future version."), + drop, + filter, + flatMap, + map, + take, + compose + }; + exports$4.promiseReturningOperators = { + every, + forEach, + reduce, + toArray, + some, + find + }; + return exports$4; +} + +var exports$3 = {}, + _dewExec$2 = false; +function dew$2() { + if (_dewExec$2) return exports$3; + _dewExec$2 = true; + const { + ArrayPrototypePop, + Promise + } = dew$o(); + const { + isIterable, + isNodeStream, + isWebStream + } = dew$j(); + const { + pipelineImpl: pl + } = dew$5(); + const { + finished + } = dew$i(); + dew$1(); + function pipeline(...streams) { + return new Promise((resolve, reject) => { + let signal; + let end; + const lastArg = streams[streams.length - 1]; + if (lastArg && typeof lastArg === "object" && !isNodeStream(lastArg) && !isIterable(lastArg) && !isWebStream(lastArg)) { + const options = ArrayPrototypePop(streams); + signal = options.signal; + end = options.end; + } + pl(streams, (err, value) => { + if (err) { + reject(err); + } else { + resolve(value); + } + }, { + signal, + end + }); + }); + } + exports$3 = { + finished, + pipeline + }; + return exports$3; +} + +var exports$2 = {}, + _dewExec$1 = false; +var _global = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; +function dew$1() { + if (_dewExec$1) return exports$2; + _dewExec$1 = true; + /* replacement start */ + + const { + Buffer + } = dew$p() + + /* replacement end */ + // Copyright Joyent, Inc. and other Node contributors. + // + // Permission is hereby granted, free of charge, to any person obtaining a + // copy of this software and associated documentation files (the + // "Software"), to deal in the Software without restriction, including + // without limitation the rights to use, copy, modify, merge, publish, + // distribute, sublicense, and/or sell copies of the Software, and to permit + // persons to whom the Software is furnished to do so, subject to the + // following conditions: + // + // The above copyright notice and this permission notice shall be included + // in all copies or substantial portions of the Software. + // + // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN + // NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + // DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR + // OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE + // USE OR OTHER DEALINGS IN THE SOFTWARE. + ; + const { + ObjectDefineProperty, + ObjectKeys, + ReflectApply + } = dew$o(); + const { + promisify: { + custom: customPromisify + } + } = dew$m(); + const { + streamReturningOperators, + promiseReturningOperators + } = dew$3(); + const { + codes: { + ERR_ILLEGAL_CONSTRUCTOR + } + } = dew$l(); + const compose = dew$4(); + const { + setDefaultHighWaterMark, + getDefaultHighWaterMark + } = dew$d(); + const { + pipeline + } = dew$5(); + const { + destroyer + } = dew$h(); + const eos = dew$i(); + const promises = dew$2(); + const utils = dew$j(); + const Stream = exports$2 = dew$g().Stream; + Stream.isDestroyed = utils.isDestroyed; + Stream.isDisturbed = utils.isDisturbed; + Stream.isErrored = utils.isErrored; + Stream.isReadable = utils.isReadable; + Stream.isWritable = utils.isWritable; + Stream.Readable = dew$b(); + for (const key of ObjectKeys(streamReturningOperators)) { + const op = streamReturningOperators[key]; + function fn(...args) { + if (new.target) { + throw ERR_ILLEGAL_CONSTRUCTOR(); + } + return Stream.Readable.from(ReflectApply(op, this || _global, args)); + } + ObjectDefineProperty(fn, "name", { + __proto__: null, + value: op.name + }); + ObjectDefineProperty(fn, "length", { + __proto__: null, + value: op.length + }); + ObjectDefineProperty(Stream.Readable.prototype, key, { + __proto__: null, + value: fn, + enumerable: false, + configurable: true, + writable: true + }); + } + for (const key of ObjectKeys(promiseReturningOperators)) { + const op = promiseReturningOperators[key]; + function fn(...args) { + if (new.target) { + throw ERR_ILLEGAL_CONSTRUCTOR(); + } + return ReflectApply(op, this || _global, args); + } + ObjectDefineProperty(fn, "name", { + __proto__: null, + value: op.name + }); + ObjectDefineProperty(fn, "length", { + __proto__: null, + value: op.length + }); + ObjectDefineProperty(Stream.Readable.prototype, key, { + __proto__: null, + value: fn, + enumerable: false, + configurable: true, + writable: true + }); + } + Stream.Writable = dew$a(); + Stream.Duplex = dew$8(); + Stream.Transform = dew$7(); + Stream.PassThrough = dew$6(); + Stream.pipeline = pipeline; + const { + addAbortSignal + } = dew$f(); + Stream.addAbortSignal = addAbortSignal; + Stream.finished = eos; + Stream.destroy = destroyer; + Stream.compose = compose; + Stream.setDefaultHighWaterMark = setDefaultHighWaterMark; + Stream.getDefaultHighWaterMark = getDefaultHighWaterMark; + ObjectDefineProperty(Stream, "promises", { + __proto__: null, + configurable: true, + enumerable: true, + get() { + return promises; + } + }); + ObjectDefineProperty(pipeline, customPromisify, { + __proto__: null, + enumerable: true, + get() { + return promises.pipeline; + } + }); + ObjectDefineProperty(eos, customPromisify, { + __proto__: null, + enumerable: true, + get() { + return promises.finished; + } + }); + + // Backwards-compat with node 0.4.x + Stream.Stream = Stream; + Stream._isUint8Array = function isUint8Array(value) { + return value instanceof Uint8Array; + }; + Stream._uint8ArrayToBuffer = function _uint8ArrayToBuffer(chunk) { + return Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength); + }; + return exports$2; +} + +var exports$1 = {}, + _dewExec = false; +function dew() { + if (_dewExec) return exports$1; + _dewExec = true; + const CustomStream = dew$1(); + const promises = dew$2(); + const originalDestroy = CustomStream.Readable.destroy; + exports$1 = CustomStream.Readable; + + // Explicit export naming is needed for ESM + exports$1._uint8ArrayToBuffer = CustomStream._uint8ArrayToBuffer; + exports$1._isUint8Array = CustomStream._isUint8Array; + exports$1.isDisturbed = CustomStream.isDisturbed; + exports$1.isErrored = CustomStream.isErrored; + exports$1.isReadable = CustomStream.isReadable; + exports$1.Readable = CustomStream.Readable; + exports$1.Writable = CustomStream.Writable; + exports$1.Duplex = CustomStream.Duplex; + exports$1.Transform = CustomStream.Transform; + exports$1.PassThrough = CustomStream.PassThrough; + exports$1.addAbortSignal = CustomStream.addAbortSignal; + exports$1.finished = CustomStream.finished; + exports$1.destroy = CustomStream.destroy; + exports$1.destroy = originalDestroy; + exports$1.pipeline = CustomStream.pipeline; + exports$1.compose = CustomStream.compose; + Object.defineProperty(CustomStream, "promises", { + configurable: true, + enumerable: true, + get() { + return promises; + } + }); + exports$1.Stream = CustomStream.Stream; + + // Allow default importing + exports$1.default = exports$1; + return exports$1; +} + +const exports = dew(); +exports['_uint8ArrayToBuffer']; exports['_isUint8Array']; exports['isDisturbed']; exports['isErrored']; exports['isReadable']; exports['Readable']; exports['Writable']; exports['Duplex']; exports['Transform']; exports['PassThrough']; exports['addAbortSignal']; exports['finished']; exports['destroy']; exports['pipeline']; exports['compose']; exports['Stream']; var Readable = exports.Readable; Readable.wrap = function(src, options) { diff --git a/nodelibs/browser/stream/consumers.js b/nodelibs/browser/stream/consumers.js new file mode 100644 index 0000000..f7a5cea --- /dev/null +++ b/nodelibs/browser/stream/consumers.js @@ -0,0 +1,61 @@ +import { Buffer } from '../buffer.js'; +import '../chunk-DtuTasat.js'; + +// no need to lazy load this, because if stream/consumers are used, buffer has necessarily already been imported. + +// https://github.com/nodejs/node/blob/449147ebab8d91e5326b839a1ae61e45b1e73582/lib/stream/consumers.js + +async function blob(stream) { + const chunks = []; + for await (const chunk of stream) + chunks.push(chunk); + return new Blob(chunks); +} + +async function arrayBuffer(stream) { + if (Blob.prototype.arrayBuffer) { + const blob = await blob(stream); + return blob.arrayBuffer(); + } + // Firefox Android or Opera don't support arrayBuffer() + const chunks = []; + for await (const chunk of stream) { + try { + chunks.push(Buffer.from(chunk)); + } catch (_) { + chanks.push(Buffer.from(`${chunk}`)); + } + } + return Buffer.concat(chunks).buffer; +} + +async function buffer(stream) { + return Buffer.from(await arrayBuffer(stream)); +} + +async function text(stream) { + const dec = new TextDecoder(); + let str = ''; + for await (const chunk of stream) { + if (typeof chunk === 'string') + str += chunk; + else + str += dec.decode(chunk, { stream: true }); + } + str += dec.decode(undefined, { stream: false }); + return str; +} + +async function json(stream) { + return JSON.parse(await text(stream)); +} + +var consumers = { + blob, + arrayBuffer, + buffer, + text, + json, +}; + +export { arrayBuffer, blob, buffer, consumers as default, json, text }; diff --git a/nodelibs/browser/stream/promises.js b/nodelibs/browser/stream/promises.js index 53393af..2cd7c72 100644 --- a/nodelibs/browser/stream/promises.js +++ b/nodelibs/browser/stream/promises.js @@ -1,14 +1,11 @@ import { promises } from '../stream.js'; -import '../chunk-gkrMq4sQ.js'; +import '../chunk-DtuTasat.js'; import '../events.js'; -import '../chunk-tHuMsdT0.js'; -import '../chunk-CU2hd6BF.js'; -import '../chunk-BZgdGiNw.js'; -import '../chunk-D04hy_Cu.js'; -import '../chunk-DEckhzyo.js'; -import '../chunk-b0rmRow7.js'; -import '../chunk-C9hMJ5VR.js'; +import '../chunk-DEMDiNwt.js'; +import '../chunk-CcCWfKp1.js'; import '../util.js'; +import '../chunk-DtcTpLWz.js'; +import '../chunk-CkFCi-G1.js'; const { finished, pipeline } = promises; diff --git a/nodelibs/browser/string_decoder.js b/nodelibs/browser/string_decoder.js index 459f6c8..31329ed 100644 --- a/nodelibs/browser/string_decoder.js +++ b/nodelibs/browser/string_decoder.js @@ -1,5 +1,2 @@ -import { a as e$1 } from './chunk-C9hMJ5VR.js'; - -var StringDecoder = e$1.StringDecoder; - -export { StringDecoder, e$1 as default }; +export { S as StringDecoder, e as default } from './chunk-CcCWfKp1.js'; +import './chunk-DtuTasat.js'; diff --git a/nodelibs/browser/sys.js b/nodelibs/browser/sys.js index d7153ee..f8c5f51 100644 --- a/nodelibs/browser/sys.js +++ b/nodelibs/browser/sys.js @@ -1,7 +1,9 @@ -export { T as TextDecoder, a as TextEncoder, _ as _extend, c as callbackify, d as debuglog, b as deprecate, f as format, i as inherits, e as inspect, g as isArray, h as isBoolean, j as isBuffer, k as isDate, l as isError, m as isFunction, n as isNull, o as isNullOrUndefined, q as isNumber, r as isObject, s as isPrimitive, t as isRegExp, u as isString, v as isSymbol, w as isUndefined, x as log, p as promisify, y as types } from './chunk-BZgdGiNw.js'; -import { X } from './chunk-D04hy_Cu.js'; -import './chunk-DEckhzyo.js'; +import exports from './util.js'; +export { TextDecoder, TextEncoder, _extend, callbackify, debuglog, deprecate, format, inherits, inspect, isArray, isBoolean, isBuffer, isDate, isError, isFunction, isNull, isNullOrUndefined, isNumber, isObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, log, promisify, types } from './util.js'; +import './chunk-DtcTpLWz.js'; +import './chunk-CkFCi-G1.js'; +import './chunk-DEMDiNwt.js'; -export { X as default }; +export { exports as default }; diff --git a/nodelibs/browser/timers.js b/nodelibs/browser/timers.js index 6cd3618..3e0d80e 100644 --- a/nodelibs/browser/timers.js +++ b/nodelibs/browser/timers.js @@ -1,42 +1,33 @@ -import { p as process } from './chunk-b0rmRow7.js'; +import { p as process } from './chunk-DEMDiNwt.js'; var exports$2 = {}, - _dewExec$1 = false; - + _dewExec$1 = false; var _global$1 = typeof globalThis !== "undefined" ? globalThis : typeof self !== "undefined" ? self : global; - function dew$1() { if (_dewExec$1) return exports$2; _dewExec$1 = true; var process$1 = process; - (function (global, undefined$1) { if (global.setImmediate) { return; } - var nextHandle = 1; // Spec says greater than zero - var tasksByHandle = {}; var currentlyRunningATask = false; var doc = global.document; var registerImmediate; - function setImmediate(callback) { // Callback can either be a function or a string if (typeof callback !== "function") { callback = new Function("" + callback); - } // Copy function arguments - - + } + // Copy function arguments var args = new Array(arguments.length - 1); - for (var i = 0; i < args.length; i++) { args[i] = arguments[i + 1]; - } // Store and register the task - - + } + // Store and register the task var task = { callback: callback, args: args @@ -45,38 +36,30 @@ function dew$1() { registerImmediate(nextHandle); return nextHandle++; } - function clearImmediate(handle) { delete tasksByHandle[handle]; } - function run(task) { var callback = task.callback; var args = task.args; - switch (args.length) { case 0: callback(); break; - case 1: callback(args[0]); break; - case 2: callback(args[0], args[1]); break; - case 3: callback(args[0], args[1], args[2]); break; - default: callback.apply(undefined$1, args); break; } } - function runIfPresent(handle) { // From the spec: "Wait until any invocations of this algorithm started before this one have completed." // So if we're currently running a task, we'll need to delay this invocation. @@ -86,10 +69,8 @@ function dew$1() { setTimeout(runIfPresent, 0, handle); } else { var task = tasksByHandle[handle]; - if (task) { currentlyRunningATask = true; - try { run(task); } finally { @@ -99,7 +80,6 @@ function dew$1() { } } } - function installNextTickImplementation() { registerImmediate = function (handle) { process$1.nextTick(function () { @@ -107,89 +87,76 @@ function dew$1() { }); }; } - function canUsePostMessage() { // The test against `importScripts` prevents this implementation from being installed inside a web worker, // where `global.postMessage` means something completely different and can't be used for this purpose. if (global.postMessage && !global.importScripts) { var postMessageIsAsynchronous = true; var oldOnMessage = global.onmessage; - global.onmessage = function () { postMessageIsAsynchronous = false; }; - global.postMessage("", "*"); global.onmessage = oldOnMessage; return postMessageIsAsynchronous; } } - function installPostMessageImplementation() { // Installs an event handler on `global` for the `message` event: see // * https://developer.mozilla.org/en/DOM/window.postMessage // * http://www.whatwg.org/specs/web-apps/current-work/multipage/comms.html#crossDocumentMessages - var messagePrefix = "setImmediate$" + Math.random() + "$"; + var messagePrefix = "setImmediate$" + Math.random() + "$"; var onGlobalMessage = function (event) { if (event.source === global && typeof event.data === "string" && event.data.indexOf(messagePrefix) === 0) { runIfPresent(+event.data.slice(messagePrefix.length)); } }; - if (global.addEventListener) { global.addEventListener("message", onGlobalMessage, false); } else { global.attachEvent("onmessage", onGlobalMessage); } - registerImmediate = function (handle) { global.postMessage(messagePrefix + handle, "*"); }; } - function installMessageChannelImplementation() { var channel = new MessageChannel(); - channel.port1.onmessage = function (event) { var handle = event.data; runIfPresent(handle); }; - registerImmediate = function (handle) { channel.port2.postMessage(handle); }; } - function installReadyStateChangeImplementation() { var html = doc.documentElement; - registerImmediate = function (handle) { // Create a