@socketsecurity/cli-with-sentry 1.1.14 → 1.1.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/dist/cli.js +114 -32
- package/dist/cli.js.map +1 -1
- package/dist/constants.js +35 -37
- package/dist/constants.js.map +1 -1
- package/dist/shadow-npm-bin.js +6 -6
- package/dist/shadow-npm-bin.js.map +1 -1
- package/dist/shadow-pnpm-bin.js +3 -5
- package/dist/shadow-pnpm-bin.js.map +1 -1
- package/dist/shadow-yarn-bin.js +2 -2
- package/dist/shadow-yarn-bin.js.map +1 -1
- package/dist/tsconfig.dts.tsbuildinfo +1 -1
- package/dist/types/commands/fix/cmd-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/coana-fix.d.mts.map +1 -1
- package/dist/types/commands/fix/env-helpers.d.mts +13 -0
- package/dist/types/commands/fix/env-helpers.d.mts.map +1 -1
- package/dist/types/commands/fix/handle-fix.d.mts.map +1 -1
- package/dist/types/commands/manifest/cmd-manifest-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/manifest/run-cdxgen.d.mts.map +1 -1
- package/dist/types/commands/optimize/apply-optimization.d.mts.map +1 -1
- package/dist/types/commands/optimize/update-lockfile.d.mts.map +1 -1
- package/dist/types/commands/package/fetch-purls-shallow-score.d.mts.map +1 -1
- package/dist/types/commands/patch/cmd-patch.d.mts.map +1 -1
- package/dist/types/commands/patch/handle-patch.d.mts.map +1 -1
- package/dist/types/commands/threat-feed/cmd-threat-feed.d.mts.map +1 -1
- package/dist/types/commands/yarn/cmd-yarn.d.mts +1 -1
- package/dist/types/commands/yarn/cmd-yarn.d.mts.map +1 -1
- package/dist/types/constants.d.mts +15 -19
- package/dist/types/constants.d.mts.map +1 -1
- package/dist/types/shadow/pnpm/bin.d.mts.map +1 -1
- package/dist/types/utils/agent.d.mts.map +1 -1
- package/dist/types/utils/api.d.mts.map +1 -1
- package/dist/types/utils/dlx.d.mts.map +1 -1
- package/dist/types/utils/package-environment.d.mts.map +1 -1
- package/dist/types/utils/path-resolve.d.mts.map +1 -1
- package/dist/utils.js +70 -29
- package/dist/utils.js.map +1 -1
- package/dist/vendor.js +514 -517
- package/external/@socketsecurity/registry/external/@inquirer/confirm.js +45 -205
- package/external/@socketsecurity/registry/external/@inquirer/input.js +45 -205
- package/external/@socketsecurity/registry/external/@inquirer/password.js +181 -205
- package/external/@socketsecurity/registry/external/@inquirer/search.js +47 -207
- package/external/@socketsecurity/registry/external/@inquirer/select.js +183 -207
- package/external/@socketsecurity/registry/external/@npmcli/package-json/index.js +388 -2280
- package/external/@socketsecurity/registry/external/browserslist.js +11534 -567
- package/external/@socketsecurity/registry/external/cacache.js +2575 -4914
- package/external/@socketsecurity/registry/external/libnpmpack.js +64667 -166061
- package/external/@socketsecurity/registry/external/make-fetch-happen.js +384 -4044
- package/external/@socketsecurity/registry/external/normalize-package-data.js +30 -278
- package/external/@socketsecurity/registry/external/npm-package-arg.js +28 -9
- package/external/@socketsecurity/registry/external/pacote.js +46680 -66482
- package/external/@socketsecurity/registry/external/spdx-correct.js +19 -0
- package/external/@socketsecurity/registry/external/spdx-expression-parse.js +19 -0
- package/external/@socketsecurity/registry/lib/agent.js +390 -0
- package/external/@socketsecurity/registry/lib/arrays.js +31 -0
- package/external/@socketsecurity/registry/lib/bin.js +650 -0
- package/external/@socketsecurity/registry/lib/constants/bun-lock.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/bun-lockb.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/bun.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/dot-git-dir.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/dot-socket-dir.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/empty-value.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/env.js +17 -3
- package/external/@socketsecurity/registry/lib/constants/ext-yaml.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/ext-yml.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/index.js +20 -11
- package/external/@socketsecurity/registry/lib/constants/npm-exec-path.js +2 -2
- package/external/@socketsecurity/registry/lib/constants/npm-real-exec-path.js +1 -1
- package/external/@socketsecurity/registry/lib/constants/npm-shrinkwrap-json.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/pnpm-exec-path.js +5 -0
- package/external/@socketsecurity/registry/lib/constants/pnpm-lock-yaml.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/unknown-error.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/unknown-value.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/vlt-lock-json.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/vlt.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/yarn-berry.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/yarn-classic.js +3 -0
- package/external/@socketsecurity/registry/lib/constants/yarn-exec-path.js +5 -0
- package/external/@socketsecurity/registry/lib/constants/yarn.js +3 -0
- package/external/@socketsecurity/registry/lib/debug.js +53 -0
- package/external/@socketsecurity/registry/lib/env.js +18 -0
- package/external/@socketsecurity/registry/lib/fs.js +218 -2
- package/external/@socketsecurity/registry/lib/functions.js +5 -0
- package/external/@socketsecurity/registry/lib/globs.js +22 -1
- package/external/@socketsecurity/registry/lib/json.js +16 -0
- package/external/@socketsecurity/registry/lib/logger.js +157 -0
- package/external/@socketsecurity/registry/lib/objects.js +103 -0
- package/external/@socketsecurity/registry/lib/packages.js +88 -0
- package/external/@socketsecurity/registry/lib/path.js +51 -1
- package/external/@socketsecurity/registry/lib/promises.js +55 -0
- package/external/@socketsecurity/registry/lib/regexps.js +5 -0
- package/external/@socketsecurity/registry/lib/sorts.js +17 -0
- package/external/@socketsecurity/registry/lib/spawn.js +105 -7
- package/external/@socketsecurity/registry/lib/streams.js +26 -0
- package/external/@socketsecurity/registry/lib/strings.js +123 -9
- package/external/@socketsecurity/registry/lib/url.js +21 -0
- package/external/@socketsecurity/registry/lib/words.js +16 -0
- package/external/@socketsecurity/registry/manifest.json +5 -4
- package/package.json +5 -4
- package/external/@socketsecurity/registry/external/ansi-regex.js +0 -13
- package/external/@socketsecurity/registry/lib/constants/node-workspaces.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/parse-args-config.js +0 -14
- package/external/@socketsecurity/registry/lib/constants/skip-tests-by-ecosystem.js +0 -43
- package/external/@socketsecurity/registry/lib/constants/template-cjs-browser.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/template-cjs-esm.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/template-cjs.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/template-es-shim-constructor.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/template-es-shim-prototype-method.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/template-es-shim-static-method.js +0 -3
- package/external/@socketsecurity/registry/lib/constants/win32-ensure-tests-by-ecosystem.js +0 -3
- package/external/@socketsecurity/registry/lib/npm.js +0 -404
- /package/external/@socketsecurity/registry/lib/constants/{hidden-package-lock-json.js → dot-package-lock-json.js} +0 -0
|
@@ -1794,13 +1794,13 @@ function requireCommonjs$4() {
|
|
|
1794
1794
|
return commonjs$5
|
|
1795
1795
|
}
|
|
1796
1796
|
|
|
1797
|
-
let minipass
|
|
1798
|
-
let hasRequiredMinipass
|
|
1799
|
-
function requireMinipass
|
|
1800
|
-
if (hasRequiredMinipass
|
|
1801
|
-
return minipass
|
|
1797
|
+
let minipass
|
|
1798
|
+
let hasRequiredMinipass
|
|
1799
|
+
function requireMinipass() {
|
|
1800
|
+
if (hasRequiredMinipass) {
|
|
1801
|
+
return minipass
|
|
1802
1802
|
}
|
|
1803
|
-
hasRequiredMinipass
|
|
1803
|
+
hasRequiredMinipass = 1
|
|
1804
1804
|
const proc =
|
|
1805
1805
|
typeof process === 'object' && process
|
|
1806
1806
|
? process
|
|
@@ -1885,7 +1885,7 @@ function requireMinipass$2() {
|
|
|
1885
1885
|
src.on('error', this.proxyErrors)
|
|
1886
1886
|
}
|
|
1887
1887
|
}
|
|
1888
|
-
minipass
|
|
1888
|
+
minipass = class Minipass extends Stream {
|
|
1889
1889
|
constructor(options) {
|
|
1890
1890
|
super()
|
|
1891
1891
|
this[FLOWING] = false
|
|
@@ -2489,7 +2489,7 @@ function requireMinipass$2() {
|
|
|
2489
2489
|
)
|
|
2490
2490
|
}
|
|
2491
2491
|
}
|
|
2492
|
-
return minipass
|
|
2492
|
+
return minipass
|
|
2493
2493
|
}
|
|
2494
2494
|
|
|
2495
2495
|
let minipassSized
|
|
@@ -2499,7 +2499,7 @@ function requireMinipassSized() {
|
|
|
2499
2499
|
return minipassSized
|
|
2500
2500
|
}
|
|
2501
2501
|
hasRequiredMinipassSized = 1
|
|
2502
|
-
const Minipass = requireMinipass
|
|
2502
|
+
const Minipass = requireMinipass()
|
|
2503
2503
|
class SizeError extends Error {
|
|
2504
2504
|
constructor(found, expect) {
|
|
2505
2505
|
super(`Bad data size: expected ${expect} bytes, but got ${found}`)
|
|
@@ -15695,1673 +15695,277 @@ function requirePolicy() {
|
|
|
15695
15695
|
}
|
|
15696
15696
|
}
|
|
15697
15697
|
|
|
15698
|
-
// static method to quickly determine if a request alone is storable
|
|
15699
|
-
static storable(request, options) {
|
|
15700
|
-
// no cachePath means no caching
|
|
15701
|
-
if (!options.cachePath) {
|
|
15702
|
-
return false
|
|
15703
|
-
}
|
|
15704
|
-
|
|
15705
|
-
// user explicitly asked not to cache
|
|
15706
|
-
if (options.cache === 'no-store') {
|
|
15707
|
-
return false
|
|
15708
|
-
}
|
|
15709
|
-
|
|
15710
|
-
// we only cache GET and HEAD requests
|
|
15711
|
-
if (!['GET', 'HEAD'].includes(request.method)) {
|
|
15712
|
-
return false
|
|
15713
|
-
}
|
|
15714
|
-
|
|
15715
|
-
// otherwise, let http-cache-semantics make the decision
|
|
15716
|
-
// based on the request's headers
|
|
15717
|
-
const policy = new CacheSemantics(
|
|
15718
|
-
requestObject(request),
|
|
15719
|
-
emptyResponse,
|
|
15720
|
-
policyOptions
|
|
15721
|
-
)
|
|
15722
|
-
return policy.storable()
|
|
15723
|
-
}
|
|
15724
|
-
|
|
15725
|
-
// returns true if the policy satisfies the request
|
|
15726
|
-
satisfies(request) {
|
|
15727
|
-
const _req = requestObject(request)
|
|
15728
|
-
if (this.request.headers.host !== _req.headers.host) {
|
|
15729
|
-
return false
|
|
15730
|
-
}
|
|
15731
|
-
if (this.request.compress !== _req.compress) {
|
|
15732
|
-
return false
|
|
15733
|
-
}
|
|
15734
|
-
const negotiatorA = new Negotiator(this.request)
|
|
15735
|
-
const negotiatorB = new Negotiator(_req)
|
|
15736
|
-
if (
|
|
15737
|
-
JSON.stringify(negotiatorA.mediaTypes()) !==
|
|
15738
|
-
JSON.stringify(negotiatorB.mediaTypes())
|
|
15739
|
-
) {
|
|
15740
|
-
return false
|
|
15741
|
-
}
|
|
15742
|
-
if (
|
|
15743
|
-
JSON.stringify(negotiatorA.languages()) !==
|
|
15744
|
-
JSON.stringify(negotiatorB.languages())
|
|
15745
|
-
) {
|
|
15746
|
-
return false
|
|
15747
|
-
}
|
|
15748
|
-
if (
|
|
15749
|
-
JSON.stringify(negotiatorA.encodings()) !==
|
|
15750
|
-
JSON.stringify(negotiatorB.encodings())
|
|
15751
|
-
) {
|
|
15752
|
-
return false
|
|
15753
|
-
}
|
|
15754
|
-
if (this.options.integrity) {
|
|
15755
|
-
return ssri.parse(this.options.integrity).match(this.entry.integrity)
|
|
15756
|
-
}
|
|
15757
|
-
return true
|
|
15758
|
-
}
|
|
15759
|
-
|
|
15760
|
-
// returns true if the request and response allow caching
|
|
15761
|
-
storable() {
|
|
15762
|
-
return this.policy.storable()
|
|
15763
|
-
}
|
|
15764
|
-
|
|
15765
|
-
// NOTE: this is a hack to avoid parsing the cache-control
|
|
15766
|
-
// header ourselves, it returns true if the response's
|
|
15767
|
-
// cache-control contains must-revalidate
|
|
15768
|
-
get mustRevalidate() {
|
|
15769
|
-
return !!this.policy._rescc['must-revalidate']
|
|
15770
|
-
}
|
|
15771
|
-
|
|
15772
|
-
// returns true if the cached response requires revalidation
|
|
15773
|
-
// for the given request
|
|
15774
|
-
needsRevalidation(request) {
|
|
15775
|
-
const _req = requestObject(request)
|
|
15776
|
-
// force method to GET because we only cache GETs
|
|
15777
|
-
// but can serve a HEAD from a cached GET
|
|
15778
|
-
_req.method = 'GET'
|
|
15779
|
-
return !this.policy.satisfiesWithoutRevalidation(_req)
|
|
15780
|
-
}
|
|
15781
|
-
responseHeaders() {
|
|
15782
|
-
return this.policy.responseHeaders()
|
|
15783
|
-
}
|
|
15784
|
-
|
|
15785
|
-
// returns a new object containing the appropriate headers
|
|
15786
|
-
// to send a revalidation request
|
|
15787
|
-
revalidationHeaders(request) {
|
|
15788
|
-
const _req = requestObject(request)
|
|
15789
|
-
return this.policy.revalidationHeaders(_req)
|
|
15790
|
-
}
|
|
15791
|
-
|
|
15792
|
-
// returns true if the request/response was revalidated
|
|
15793
|
-
// successfully. returns false if a new response was received
|
|
15794
|
-
revalidated(request, response) {
|
|
15795
|
-
const _req = requestObject(request)
|
|
15796
|
-
const _res = responseObject(response)
|
|
15797
|
-
const policy = this.policy.revalidatedPolicy(_req, _res)
|
|
15798
|
-
return !policy.modified
|
|
15799
|
-
}
|
|
15800
|
-
}
|
|
15801
|
-
policy = CachePolicy
|
|
15802
|
-
return policy
|
|
15803
|
-
}
|
|
15804
|
-
|
|
15805
|
-
let errors$2
|
|
15806
|
-
let hasRequiredErrors$2
|
|
15807
|
-
function requireErrors$2() {
|
|
15808
|
-
if (hasRequiredErrors$2) {
|
|
15809
|
-
return errors$2
|
|
15810
|
-
}
|
|
15811
|
-
hasRequiredErrors$2 = 1
|
|
15812
|
-
class NotCachedError extends Error {
|
|
15813
|
-
constructor(url) {
|
|
15814
|
-
/* eslint-disable-next-line max-len */
|
|
15815
|
-
super(
|
|
15816
|
-
`request to ${url} failed: cache mode is 'only-if-cached' but no cached response is available.`
|
|
15817
|
-
)
|
|
15818
|
-
this.code = 'ENOTCACHED'
|
|
15819
|
-
}
|
|
15820
|
-
}
|
|
15821
|
-
errors$2 = {
|
|
15822
|
-
NotCachedError
|
|
15823
|
-
}
|
|
15824
|
-
return errors$2
|
|
15825
|
-
}
|
|
15826
|
-
|
|
15827
|
-
let minipass$1
|
|
15828
|
-
let hasRequiredMinipass$1
|
|
15829
|
-
function requireMinipass$1() {
|
|
15830
|
-
if (hasRequiredMinipass$1) {
|
|
15831
|
-
return minipass$1
|
|
15832
|
-
}
|
|
15833
|
-
hasRequiredMinipass$1 = 1
|
|
15834
|
-
const proc =
|
|
15835
|
-
typeof process === 'object' && process
|
|
15836
|
-
? process
|
|
15837
|
-
: {
|
|
15838
|
-
stdout: null,
|
|
15839
|
-
stderr: null
|
|
15840
|
-
}
|
|
15841
|
-
const EE = require$$0$5
|
|
15842
|
-
const Stream = require$$1$2
|
|
15843
|
-
const SD = require$$2$2.StringDecoder
|
|
15844
|
-
const EOF = Symbol('EOF')
|
|
15845
|
-
const MAYBE_EMIT_END = Symbol('maybeEmitEnd')
|
|
15846
|
-
const EMITTED_END = Symbol('emittedEnd')
|
|
15847
|
-
const EMITTING_END = Symbol('emittingEnd')
|
|
15848
|
-
const EMITTED_ERROR = Symbol('emittedError')
|
|
15849
|
-
const CLOSED = Symbol('closed')
|
|
15850
|
-
const READ = Symbol('read')
|
|
15851
|
-
const FLUSH = Symbol('flush')
|
|
15852
|
-
const FLUSHCHUNK = Symbol('flushChunk')
|
|
15853
|
-
const ENCODING = Symbol('encoding')
|
|
15854
|
-
const DECODER = Symbol('decoder')
|
|
15855
|
-
const FLOWING = Symbol('flowing')
|
|
15856
|
-
const PAUSED = Symbol('paused')
|
|
15857
|
-
const RESUME = Symbol('resume')
|
|
15858
|
-
const BUFFERLENGTH = Symbol('bufferLength')
|
|
15859
|
-
const BUFFERPUSH = Symbol('bufferPush')
|
|
15860
|
-
const BUFFERSHIFT = Symbol('bufferShift')
|
|
15861
|
-
const OBJECTMODE = Symbol('objectMode')
|
|
15862
|
-
const DESTROYED = Symbol('destroyed')
|
|
15863
|
-
const EMITDATA = Symbol('emitData')
|
|
15864
|
-
const EMITEND = Symbol('emitEnd')
|
|
15865
|
-
const EMITEND2 = Symbol('emitEnd2')
|
|
15866
|
-
const ASYNC = Symbol('async')
|
|
15867
|
-
const defer = fn => Promise.resolve().then(fn)
|
|
15868
|
-
|
|
15869
|
-
// TODO remove when Node v8 support drops
|
|
15870
|
-
const doIter = global._MP_NO_ITERATOR_SYMBOLS_ !== '1'
|
|
15871
|
-
const ASYNCITERATOR =
|
|
15872
|
-
(doIter && Symbol.asyncIterator) || Symbol('asyncIterator not implemented')
|
|
15873
|
-
const ITERATOR =
|
|
15874
|
-
(doIter && Symbol.iterator) || Symbol('iterator not implemented')
|
|
15875
|
-
|
|
15876
|
-
// events that mean 'the stream is over'
|
|
15877
|
-
// these are treated specially, and re-emitted
|
|
15878
|
-
// if they are listened for after emitting.
|
|
15879
|
-
const isEndish = ev => ev === 'end' || ev === 'finish' || ev === 'prefinish'
|
|
15880
|
-
const isArrayBuffer = b =>
|
|
15881
|
-
b instanceof ArrayBuffer ||
|
|
15882
|
-
(typeof b === 'object' &&
|
|
15883
|
-
b.constructor &&
|
|
15884
|
-
b.constructor.name === 'ArrayBuffer' &&
|
|
15885
|
-
b.byteLength >= 0)
|
|
15886
|
-
const isArrayBufferView = b => !Buffer.isBuffer(b) && ArrayBuffer.isView(b)
|
|
15887
|
-
class Pipe {
|
|
15888
|
-
constructor(src, dest, opts) {
|
|
15889
|
-
this.src = src
|
|
15890
|
-
this.dest = dest
|
|
15891
|
-
this.opts = opts
|
|
15892
|
-
this.ondrain = () => src[RESUME]()
|
|
15893
|
-
dest.on('drain', this.ondrain)
|
|
15894
|
-
}
|
|
15895
|
-
unpipe() {
|
|
15896
|
-
this.dest.removeListener('drain', this.ondrain)
|
|
15897
|
-
}
|
|
15898
|
-
// istanbul ignore next - only here for the prototype
|
|
15899
|
-
proxyErrors() {}
|
|
15900
|
-
end() {
|
|
15901
|
-
this.unpipe()
|
|
15902
|
-
if (this.opts.end) {
|
|
15903
|
-
this.dest.end()
|
|
15904
|
-
}
|
|
15905
|
-
}
|
|
15906
|
-
}
|
|
15907
|
-
class PipeProxyErrors extends Pipe {
|
|
15908
|
-
unpipe() {
|
|
15909
|
-
this.src.removeListener('error', this.proxyErrors)
|
|
15910
|
-
super.unpipe()
|
|
15911
|
-
}
|
|
15912
|
-
constructor(src, dest, opts) {
|
|
15913
|
-
super(src, dest, opts)
|
|
15914
|
-
this.proxyErrors = er => dest.emit('error', er)
|
|
15915
|
-
src.on('error', this.proxyErrors)
|
|
15916
|
-
}
|
|
15917
|
-
}
|
|
15918
|
-
minipass$1 = class Minipass extends Stream {
|
|
15919
|
-
constructor(options) {
|
|
15920
|
-
super()
|
|
15921
|
-
this[FLOWING] = false
|
|
15922
|
-
// whether we're explicitly paused
|
|
15923
|
-
this[PAUSED] = false
|
|
15924
|
-
this.pipes = []
|
|
15925
|
-
this.buffer = []
|
|
15926
|
-
this[OBJECTMODE] = (options && options.objectMode) || false
|
|
15927
|
-
if (this[OBJECTMODE]) {
|
|
15928
|
-
this[ENCODING] = null
|
|
15929
|
-
} else {
|
|
15930
|
-
this[ENCODING] = (options && options.encoding) || null
|
|
15931
|
-
}
|
|
15932
|
-
if (this[ENCODING] === 'buffer') {
|
|
15933
|
-
this[ENCODING] = null
|
|
15934
|
-
}
|
|
15935
|
-
this[ASYNC] = (options && !!options.async) || false
|
|
15936
|
-
this[DECODER] = this[ENCODING] ? new SD(this[ENCODING]) : null
|
|
15937
|
-
this[EOF] = false
|
|
15938
|
-
this[EMITTED_END] = false
|
|
15939
|
-
this[EMITTING_END] = false
|
|
15940
|
-
this[CLOSED] = false
|
|
15941
|
-
this[EMITTED_ERROR] = null
|
|
15942
|
-
this.writable = true
|
|
15943
|
-
this.readable = true
|
|
15944
|
-
this[BUFFERLENGTH] = 0
|
|
15945
|
-
this[DESTROYED] = false
|
|
15946
|
-
}
|
|
15947
|
-
get bufferLength() {
|
|
15948
|
-
return this[BUFFERLENGTH]
|
|
15949
|
-
}
|
|
15950
|
-
get encoding() {
|
|
15951
|
-
return this[ENCODING]
|
|
15952
|
-
}
|
|
15953
|
-
set encoding(enc) {
|
|
15954
|
-
if (this[OBJECTMODE]) {
|
|
15955
|
-
throw new Error('cannot set encoding in objectMode')
|
|
15956
|
-
}
|
|
15957
|
-
if (
|
|
15958
|
-
this[ENCODING] &&
|
|
15959
|
-
enc !== this[ENCODING] &&
|
|
15960
|
-
((this[DECODER] && this[DECODER].lastNeed) || this[BUFFERLENGTH])
|
|
15961
|
-
) {
|
|
15962
|
-
throw new Error('cannot change encoding')
|
|
15963
|
-
}
|
|
15964
|
-
if (this[ENCODING] !== enc) {
|
|
15965
|
-
this[DECODER] = enc ? new SD(enc) : null
|
|
15966
|
-
if (this.buffer.length) {
|
|
15967
|
-
this.buffer = this.buffer.map(chunk => this[DECODER].write(chunk))
|
|
15968
|
-
}
|
|
15969
|
-
}
|
|
15970
|
-
this[ENCODING] = enc
|
|
15971
|
-
}
|
|
15972
|
-
setEncoding(enc) {
|
|
15973
|
-
this.encoding = enc
|
|
15974
|
-
}
|
|
15975
|
-
get objectMode() {
|
|
15976
|
-
return this[OBJECTMODE]
|
|
15977
|
-
}
|
|
15978
|
-
set objectMode(om) {
|
|
15979
|
-
this[OBJECTMODE] = this[OBJECTMODE] || !!om
|
|
15980
|
-
}
|
|
15981
|
-
get ['async']() {
|
|
15982
|
-
return this[ASYNC]
|
|
15983
|
-
}
|
|
15984
|
-
set ['async'](a) {
|
|
15985
|
-
this[ASYNC] = this[ASYNC] || !!a
|
|
15986
|
-
}
|
|
15987
|
-
write(chunk, encoding, cb) {
|
|
15988
|
-
if (this[EOF]) {
|
|
15989
|
-
throw new Error('write after end')
|
|
15990
|
-
}
|
|
15991
|
-
if (this[DESTROYED]) {
|
|
15992
|
-
this.emit(
|
|
15993
|
-
'error',
|
|
15994
|
-
Object.assign(
|
|
15995
|
-
new Error('Cannot call write after a stream was destroyed'),
|
|
15996
|
-
{
|
|
15997
|
-
code: 'ERR_STREAM_DESTROYED'
|
|
15998
|
-
}
|
|
15999
|
-
)
|
|
16000
|
-
)
|
|
16001
|
-
return true
|
|
16002
|
-
}
|
|
16003
|
-
if (typeof encoding === 'function') {
|
|
16004
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16005
|
-
}
|
|
16006
|
-
if (!encoding) {
|
|
16007
|
-
encoding = 'utf8'
|
|
16008
|
-
}
|
|
16009
|
-
const fn = this[ASYNC] ? defer : f => f()
|
|
16010
|
-
|
|
16011
|
-
// convert array buffers and typed array views into buffers
|
|
16012
|
-
// at some point in the future, we may want to do the opposite!
|
|
16013
|
-
// leave strings and buffers as-is
|
|
16014
|
-
// anything else switches us into object mode
|
|
16015
|
-
if (!this[OBJECTMODE] && !Buffer.isBuffer(chunk)) {
|
|
16016
|
-
if (isArrayBufferView(chunk)) {
|
|
16017
|
-
chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength)
|
|
16018
|
-
} else if (isArrayBuffer(chunk)) {
|
|
16019
|
-
chunk = Buffer.from(chunk)
|
|
16020
|
-
} else if (typeof chunk !== 'string') {
|
|
16021
|
-
// use the setter so we throw if we have encoding set
|
|
16022
|
-
this.objectMode = true
|
|
16023
|
-
}
|
|
16024
|
-
}
|
|
16025
|
-
|
|
16026
|
-
// handle object mode up front, since it's simpler
|
|
16027
|
-
// this yields better performance, fewer checks later.
|
|
16028
|
-
if (this[OBJECTMODE]) {
|
|
16029
|
-
/* istanbul ignore if - maybe impossible? */
|
|
16030
|
-
if (this.flowing && this[BUFFERLENGTH] !== 0) {
|
|
16031
|
-
this[FLUSH](true)
|
|
16032
|
-
}
|
|
16033
|
-
if (this.flowing) {
|
|
16034
|
-
this.emit('data', chunk)
|
|
16035
|
-
} else {
|
|
16036
|
-
this[BUFFERPUSH](chunk)
|
|
16037
|
-
}
|
|
16038
|
-
if (this[BUFFERLENGTH] !== 0) {
|
|
16039
|
-
this.emit('readable')
|
|
16040
|
-
}
|
|
16041
|
-
if (cb) {
|
|
16042
|
-
fn(cb)
|
|
16043
|
-
}
|
|
16044
|
-
return this.flowing
|
|
16045
|
-
}
|
|
16046
|
-
|
|
16047
|
-
// at this point the chunk is a buffer or string
|
|
16048
|
-
// don't buffer it up or send it to the decoder
|
|
16049
|
-
if (!chunk.length) {
|
|
16050
|
-
if (this[BUFFERLENGTH] !== 0) {
|
|
16051
|
-
this.emit('readable')
|
|
16052
|
-
}
|
|
16053
|
-
if (cb) {
|
|
16054
|
-
fn(cb)
|
|
16055
|
-
}
|
|
16056
|
-
return this.flowing
|
|
16057
|
-
}
|
|
16058
|
-
|
|
16059
|
-
// fast-path writing strings of same encoding to a stream with
|
|
16060
|
-
// an empty buffer, skipping the buffer/decoder dance
|
|
16061
|
-
if (
|
|
16062
|
-
typeof chunk === 'string' &&
|
|
16063
|
-
// unless it is a string already ready for us to use
|
|
16064
|
-
!(encoding === this[ENCODING] && !this[DECODER].lastNeed)
|
|
16065
|
-
) {
|
|
16066
|
-
chunk = Buffer.from(chunk, encoding)
|
|
16067
|
-
}
|
|
16068
|
-
if (Buffer.isBuffer(chunk) && this[ENCODING]) {
|
|
16069
|
-
chunk = this[DECODER].write(chunk)
|
|
16070
|
-
}
|
|
16071
|
-
|
|
16072
|
-
// Note: flushing CAN potentially switch us into not-flowing mode
|
|
16073
|
-
if (this.flowing && this[BUFFERLENGTH] !== 0) {
|
|
16074
|
-
this[FLUSH](true)
|
|
16075
|
-
}
|
|
16076
|
-
if (this.flowing) {
|
|
16077
|
-
this.emit('data', chunk)
|
|
16078
|
-
} else {
|
|
16079
|
-
this[BUFFERPUSH](chunk)
|
|
16080
|
-
}
|
|
16081
|
-
if (this[BUFFERLENGTH] !== 0) {
|
|
16082
|
-
this.emit('readable')
|
|
16083
|
-
}
|
|
16084
|
-
if (cb) {
|
|
16085
|
-
fn(cb)
|
|
16086
|
-
}
|
|
16087
|
-
return this.flowing
|
|
16088
|
-
}
|
|
16089
|
-
read(n) {
|
|
16090
|
-
if (this[DESTROYED]) {
|
|
16091
|
-
return null
|
|
16092
|
-
}
|
|
16093
|
-
if (this[BUFFERLENGTH] === 0 || n === 0 || n > this[BUFFERLENGTH]) {
|
|
16094
|
-
this[MAYBE_EMIT_END]()
|
|
16095
|
-
return null
|
|
16096
|
-
}
|
|
16097
|
-
if (this[OBJECTMODE]) {
|
|
16098
|
-
n = null
|
|
16099
|
-
}
|
|
16100
|
-
if (this.buffer.length > 1 && !this[OBJECTMODE]) {
|
|
16101
|
-
if (this.encoding) {
|
|
16102
|
-
this.buffer = [this.buffer.join('')]
|
|
16103
|
-
} else {
|
|
16104
|
-
this.buffer = [Buffer.concat(this.buffer, this[BUFFERLENGTH])]
|
|
16105
|
-
}
|
|
16106
|
-
}
|
|
16107
|
-
const ret = this[READ](n || null, this.buffer[0])
|
|
16108
|
-
this[MAYBE_EMIT_END]()
|
|
16109
|
-
return ret
|
|
16110
|
-
}
|
|
16111
|
-
[READ](n, chunk) {
|
|
16112
|
-
if (n === chunk.length || n === null) {
|
|
16113
|
-
this[BUFFERSHIFT]()
|
|
16114
|
-
} else {
|
|
16115
|
-
this.buffer[0] = chunk.slice(n)
|
|
16116
|
-
chunk = chunk.slice(0, n)
|
|
16117
|
-
this[BUFFERLENGTH] -= n
|
|
16118
|
-
}
|
|
16119
|
-
this.emit('data', chunk)
|
|
16120
|
-
if (!this.buffer.length && !this[EOF]) {
|
|
16121
|
-
this.emit('drain')
|
|
16122
|
-
}
|
|
16123
|
-
return chunk
|
|
16124
|
-
}
|
|
16125
|
-
end(chunk, encoding, cb) {
|
|
16126
|
-
if (typeof chunk === 'function') {
|
|
16127
|
-
;(cb = chunk), (chunk = null)
|
|
16128
|
-
}
|
|
16129
|
-
if (typeof encoding === 'function') {
|
|
16130
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16131
|
-
}
|
|
16132
|
-
if (chunk) {
|
|
16133
|
-
this.write(chunk, encoding)
|
|
16134
|
-
}
|
|
16135
|
-
if (cb) {
|
|
16136
|
-
this.once('end', cb)
|
|
16137
|
-
}
|
|
16138
|
-
this[EOF] = true
|
|
16139
|
-
this.writable = false
|
|
16140
|
-
|
|
16141
|
-
// if we haven't written anything, then go ahead and emit,
|
|
16142
|
-
// even if we're not reading.
|
|
16143
|
-
// we'll re-emit if a new 'end' listener is added anyway.
|
|
16144
|
-
// This makes MP more suitable to write-only use cases.
|
|
16145
|
-
if (this.flowing || !this[PAUSED]) {
|
|
16146
|
-
this[MAYBE_EMIT_END]()
|
|
16147
|
-
}
|
|
16148
|
-
return this
|
|
16149
|
-
}
|
|
16150
|
-
|
|
16151
|
-
// don't let the internal resume be overwritten
|
|
16152
|
-
[RESUME]() {
|
|
16153
|
-
if (this[DESTROYED]) {
|
|
16154
|
-
return
|
|
16155
|
-
}
|
|
16156
|
-
this[PAUSED] = false
|
|
16157
|
-
this[FLOWING] = true
|
|
16158
|
-
this.emit('resume')
|
|
16159
|
-
if (this.buffer.length) {
|
|
16160
|
-
this[FLUSH]()
|
|
16161
|
-
} else if (this[EOF]) {
|
|
16162
|
-
this[MAYBE_EMIT_END]()
|
|
16163
|
-
} else {
|
|
16164
|
-
this.emit('drain')
|
|
16165
|
-
}
|
|
16166
|
-
}
|
|
16167
|
-
resume() {
|
|
16168
|
-
return this[RESUME]()
|
|
16169
|
-
}
|
|
16170
|
-
pause() {
|
|
16171
|
-
this[FLOWING] = false
|
|
16172
|
-
this[PAUSED] = true
|
|
16173
|
-
}
|
|
16174
|
-
get destroyed() {
|
|
16175
|
-
return this[DESTROYED]
|
|
16176
|
-
}
|
|
16177
|
-
get flowing() {
|
|
16178
|
-
return this[FLOWING]
|
|
16179
|
-
}
|
|
16180
|
-
get paused() {
|
|
16181
|
-
return this[PAUSED]
|
|
16182
|
-
}
|
|
16183
|
-
[BUFFERPUSH](chunk) {
|
|
16184
|
-
if (this[OBJECTMODE]) {
|
|
16185
|
-
this[BUFFERLENGTH] += 1
|
|
16186
|
-
} else {
|
|
16187
|
-
this[BUFFERLENGTH] += chunk.length
|
|
16188
|
-
}
|
|
16189
|
-
this.buffer.push(chunk)
|
|
16190
|
-
}
|
|
16191
|
-
[BUFFERSHIFT]() {
|
|
16192
|
-
if (this.buffer.length) {
|
|
16193
|
-
if (this[OBJECTMODE]) {
|
|
16194
|
-
this[BUFFERLENGTH] -= 1
|
|
16195
|
-
} else {
|
|
16196
|
-
this[BUFFERLENGTH] -= this.buffer[0].length
|
|
16197
|
-
}
|
|
16198
|
-
}
|
|
16199
|
-
return this.buffer.shift()
|
|
16200
|
-
}
|
|
16201
|
-
[FLUSH](noDrain) {
|
|
16202
|
-
do {} while (this[FLUSHCHUNK](this[BUFFERSHIFT]()))
|
|
16203
|
-
if (!noDrain && !this.buffer.length && !this[EOF]) {
|
|
16204
|
-
this.emit('drain')
|
|
16205
|
-
}
|
|
16206
|
-
}
|
|
16207
|
-
[FLUSHCHUNK](chunk) {
|
|
16208
|
-
return chunk ? (this.emit('data', chunk), this.flowing) : false
|
|
16209
|
-
}
|
|
16210
|
-
pipe(dest, opts) {
|
|
16211
|
-
if (this[DESTROYED]) {
|
|
16212
|
-
return
|
|
16213
|
-
}
|
|
16214
|
-
const ended = this[EMITTED_END]
|
|
16215
|
-
opts = opts || {}
|
|
16216
|
-
if (dest === proc.stdout || dest === proc.stderr) {
|
|
16217
|
-
opts.end = false
|
|
16218
|
-
} else {
|
|
16219
|
-
opts.end = opts.end !== false
|
|
16220
|
-
}
|
|
16221
|
-
opts.proxyErrors = !!opts.proxyErrors
|
|
16222
|
-
|
|
16223
|
-
// piping an ended stream ends immediately
|
|
16224
|
-
if (ended) {
|
|
16225
|
-
if (opts.end) {
|
|
16226
|
-
dest.end()
|
|
16227
|
-
}
|
|
16228
|
-
} else {
|
|
16229
|
-
this.pipes.push(
|
|
16230
|
-
!opts.proxyErrors
|
|
16231
|
-
? new Pipe(this, dest, opts)
|
|
16232
|
-
: new PipeProxyErrors(this, dest, opts)
|
|
16233
|
-
)
|
|
16234
|
-
if (this[ASYNC]) {
|
|
16235
|
-
defer(() => this[RESUME]())
|
|
16236
|
-
} else {
|
|
16237
|
-
this[RESUME]()
|
|
16238
|
-
}
|
|
16239
|
-
}
|
|
16240
|
-
return dest
|
|
16241
|
-
}
|
|
16242
|
-
unpipe(dest) {
|
|
16243
|
-
const p = this.pipes.find(p => p.dest === dest)
|
|
16244
|
-
if (p) {
|
|
16245
|
-
this.pipes.splice(this.pipes.indexOf(p), 1)
|
|
16246
|
-
p.unpipe()
|
|
16247
|
-
}
|
|
16248
|
-
}
|
|
16249
|
-
addListener(ev, fn) {
|
|
16250
|
-
return this.on(ev, fn)
|
|
16251
|
-
}
|
|
16252
|
-
on(ev, fn) {
|
|
16253
|
-
const ret = super.on(ev, fn)
|
|
16254
|
-
if (ev === 'data' && !this.pipes.length && !this.flowing) {
|
|
16255
|
-
this[RESUME]()
|
|
16256
|
-
} else if (ev === 'readable' && this[BUFFERLENGTH] !== 0) {
|
|
16257
|
-
super.emit('readable')
|
|
16258
|
-
} else if (isEndish(ev) && this[EMITTED_END]) {
|
|
16259
|
-
super.emit(ev)
|
|
16260
|
-
this.removeAllListeners(ev)
|
|
16261
|
-
} else if (ev === 'error' && this[EMITTED_ERROR]) {
|
|
16262
|
-
if (this[ASYNC]) {
|
|
16263
|
-
defer(() => fn.call(this, this[EMITTED_ERROR]))
|
|
16264
|
-
} else {
|
|
16265
|
-
fn.call(this, this[EMITTED_ERROR])
|
|
16266
|
-
}
|
|
16267
|
-
}
|
|
16268
|
-
return ret
|
|
16269
|
-
}
|
|
16270
|
-
get emittedEnd() {
|
|
16271
|
-
return this[EMITTED_END]
|
|
16272
|
-
}
|
|
16273
|
-
[MAYBE_EMIT_END]() {
|
|
16274
|
-
if (
|
|
16275
|
-
!this[EMITTING_END] &&
|
|
16276
|
-
!this[EMITTED_END] &&
|
|
16277
|
-
!this[DESTROYED] &&
|
|
16278
|
-
this.buffer.length === 0 &&
|
|
16279
|
-
this[EOF]
|
|
16280
|
-
) {
|
|
16281
|
-
this[EMITTING_END] = true
|
|
16282
|
-
this.emit('end')
|
|
16283
|
-
this.emit('prefinish')
|
|
16284
|
-
this.emit('finish')
|
|
16285
|
-
if (this[CLOSED]) {
|
|
16286
|
-
this.emit('close')
|
|
16287
|
-
}
|
|
16288
|
-
this[EMITTING_END] = false
|
|
16289
|
-
}
|
|
16290
|
-
}
|
|
16291
|
-
emit(ev, data, ...extra) {
|
|
16292
|
-
// error and close are only events allowed after calling destroy()
|
|
16293
|
-
if (
|
|
16294
|
-
ev !== 'error' &&
|
|
16295
|
-
ev !== 'close' &&
|
|
16296
|
-
ev !== DESTROYED &&
|
|
16297
|
-
this[DESTROYED]
|
|
16298
|
-
) {
|
|
16299
|
-
return
|
|
16300
|
-
} else if (ev === 'data') {
|
|
16301
|
-
return !data
|
|
16302
|
-
? false
|
|
16303
|
-
: this[ASYNC]
|
|
16304
|
-
? defer(() => this[EMITDATA](data))
|
|
16305
|
-
: this[EMITDATA](data)
|
|
16306
|
-
} else if (ev === 'end') {
|
|
16307
|
-
return this[EMITEND]()
|
|
16308
|
-
} else if (ev === 'close') {
|
|
16309
|
-
this[CLOSED] = true
|
|
16310
|
-
// don't emit close before 'end' and 'finish'
|
|
16311
|
-
if (!this[EMITTED_END] && !this[DESTROYED]) {
|
|
16312
|
-
return
|
|
16313
|
-
}
|
|
16314
|
-
const ret = super.emit('close')
|
|
16315
|
-
this.removeAllListeners('close')
|
|
16316
|
-
return ret
|
|
16317
|
-
} else if (ev === 'error') {
|
|
16318
|
-
this[EMITTED_ERROR] = data
|
|
16319
|
-
const ret = super.emit('error', data)
|
|
16320
|
-
this[MAYBE_EMIT_END]()
|
|
16321
|
-
return ret
|
|
16322
|
-
} else if (ev === 'resume') {
|
|
16323
|
-
const ret = super.emit('resume')
|
|
16324
|
-
this[MAYBE_EMIT_END]()
|
|
16325
|
-
return ret
|
|
16326
|
-
} else if (ev === 'finish' || ev === 'prefinish') {
|
|
16327
|
-
const ret = super.emit(ev)
|
|
16328
|
-
this.removeAllListeners(ev)
|
|
16329
|
-
return ret
|
|
16330
|
-
}
|
|
16331
|
-
|
|
16332
|
-
// Some other unknown event
|
|
16333
|
-
const ret = super.emit(ev, data, ...extra)
|
|
16334
|
-
this[MAYBE_EMIT_END]()
|
|
16335
|
-
return ret
|
|
16336
|
-
}
|
|
16337
|
-
[EMITDATA](data) {
|
|
16338
|
-
for (const p of this.pipes) {
|
|
16339
|
-
if (p.dest.write(data) === false) {
|
|
16340
|
-
this.pause()
|
|
16341
|
-
}
|
|
16342
|
-
}
|
|
16343
|
-
const ret = super.emit('data', data)
|
|
16344
|
-
this[MAYBE_EMIT_END]()
|
|
16345
|
-
return ret
|
|
16346
|
-
}
|
|
16347
|
-
[EMITEND]() {
|
|
16348
|
-
if (this[EMITTED_END]) {
|
|
16349
|
-
return
|
|
16350
|
-
}
|
|
16351
|
-
this[EMITTED_END] = true
|
|
16352
|
-
this.readable = false
|
|
16353
|
-
if (this[ASYNC]) {
|
|
16354
|
-
defer(() => this[EMITEND2]())
|
|
16355
|
-
} else {
|
|
16356
|
-
this[EMITEND2]()
|
|
16357
|
-
}
|
|
16358
|
-
}
|
|
16359
|
-
[EMITEND2]() {
|
|
16360
|
-
if (this[DECODER]) {
|
|
16361
|
-
const data = this[DECODER].end()
|
|
16362
|
-
if (data) {
|
|
16363
|
-
for (const p of this.pipes) {
|
|
16364
|
-
p.dest.write(data)
|
|
16365
|
-
}
|
|
16366
|
-
super.emit('data', data)
|
|
16367
|
-
}
|
|
16368
|
-
}
|
|
16369
|
-
for (const p of this.pipes) {
|
|
16370
|
-
p.end()
|
|
16371
|
-
}
|
|
16372
|
-
const ret = super.emit('end')
|
|
16373
|
-
this.removeAllListeners('end')
|
|
16374
|
-
return ret
|
|
16375
|
-
}
|
|
16376
|
-
|
|
16377
|
-
// const all = await stream.collect()
|
|
16378
|
-
collect() {
|
|
16379
|
-
const buf = []
|
|
16380
|
-
if (!this[OBJECTMODE]) {
|
|
16381
|
-
buf.dataLength = 0
|
|
16382
|
-
}
|
|
16383
|
-
// set the promise first, in case an error is raised
|
|
16384
|
-
// by triggering the flow here.
|
|
16385
|
-
const p = this.promise()
|
|
16386
|
-
this.on('data', c => {
|
|
16387
|
-
buf.push(c)
|
|
16388
|
-
if (!this[OBJECTMODE]) {
|
|
16389
|
-
buf.dataLength += c.length
|
|
16390
|
-
}
|
|
16391
|
-
})
|
|
16392
|
-
return p.then(() => buf)
|
|
16393
|
-
}
|
|
16394
|
-
|
|
16395
|
-
// const data = await stream.concat()
|
|
16396
|
-
concat() {
|
|
16397
|
-
return this[OBJECTMODE]
|
|
16398
|
-
? Promise.reject(new Error('cannot concat in objectMode'))
|
|
16399
|
-
: this.collect().then(buf =>
|
|
16400
|
-
this[OBJECTMODE]
|
|
16401
|
-
? Promise.reject(new Error('cannot concat in objectMode'))
|
|
16402
|
-
: this[ENCODING]
|
|
16403
|
-
? buf.join('')
|
|
16404
|
-
: Buffer.concat(buf, buf.dataLength)
|
|
16405
|
-
)
|
|
16406
|
-
}
|
|
16407
|
-
|
|
16408
|
-
// stream.promise().then(() => done, er => emitted error)
|
|
16409
|
-
promise() {
|
|
16410
|
-
return new Promise((resolve, reject) => {
|
|
16411
|
-
this.on(DESTROYED, () => reject(new Error('stream destroyed')))
|
|
16412
|
-
this.on('error', er => reject(er))
|
|
16413
|
-
this.on('end', () => resolve())
|
|
16414
|
-
})
|
|
16415
|
-
}
|
|
16416
|
-
|
|
16417
|
-
// for await (let chunk of stream)
|
|
16418
|
-
[ASYNCITERATOR]() {
|
|
16419
|
-
const next = () => {
|
|
16420
|
-
const res = this.read()
|
|
16421
|
-
if (res !== null) {
|
|
16422
|
-
return Promise.resolve({
|
|
16423
|
-
done: false,
|
|
16424
|
-
value: res
|
|
16425
|
-
})
|
|
16426
|
-
}
|
|
16427
|
-
if (this[EOF]) {
|
|
16428
|
-
return Promise.resolve({
|
|
16429
|
-
done: true
|
|
16430
|
-
})
|
|
16431
|
-
}
|
|
16432
|
-
let resolve = null
|
|
16433
|
-
let reject = null
|
|
16434
|
-
const onerr = er => {
|
|
16435
|
-
this.removeListener('data', ondata)
|
|
16436
|
-
this.removeListener('end', onend)
|
|
16437
|
-
reject(er)
|
|
16438
|
-
}
|
|
16439
|
-
const ondata = value => {
|
|
16440
|
-
this.removeListener('error', onerr)
|
|
16441
|
-
this.removeListener('end', onend)
|
|
16442
|
-
this.pause()
|
|
16443
|
-
resolve({
|
|
16444
|
-
value: value,
|
|
16445
|
-
done: !!this[EOF]
|
|
16446
|
-
})
|
|
16447
|
-
}
|
|
16448
|
-
const onend = () => {
|
|
16449
|
-
this.removeListener('error', onerr)
|
|
16450
|
-
this.removeListener('data', ondata)
|
|
16451
|
-
resolve({
|
|
16452
|
-
done: true
|
|
16453
|
-
})
|
|
16454
|
-
}
|
|
16455
|
-
const ondestroy = () => onerr(new Error('stream destroyed'))
|
|
16456
|
-
return new Promise((res, rej) => {
|
|
16457
|
-
reject = rej
|
|
16458
|
-
resolve = res
|
|
16459
|
-
this.once(DESTROYED, ondestroy)
|
|
16460
|
-
this.once('error', onerr)
|
|
16461
|
-
this.once('end', onend)
|
|
16462
|
-
this.once('data', ondata)
|
|
16463
|
-
})
|
|
16464
|
-
}
|
|
16465
|
-
return {
|
|
16466
|
-
next
|
|
16467
|
-
}
|
|
16468
|
-
}
|
|
16469
|
-
|
|
16470
|
-
// for (let chunk of stream)
|
|
16471
|
-
[ITERATOR]() {
|
|
16472
|
-
const next = () => {
|
|
16473
|
-
const value = this.read()
|
|
16474
|
-
const done = value === null
|
|
16475
|
-
return {
|
|
16476
|
-
value,
|
|
16477
|
-
done
|
|
16478
|
-
}
|
|
16479
|
-
}
|
|
16480
|
-
return {
|
|
16481
|
-
next
|
|
16482
|
-
}
|
|
16483
|
-
}
|
|
16484
|
-
destroy(er) {
|
|
16485
|
-
if (this[DESTROYED]) {
|
|
16486
|
-
if (er) {
|
|
16487
|
-
this.emit('error', er)
|
|
16488
|
-
} else {
|
|
16489
|
-
this.emit(DESTROYED)
|
|
16490
|
-
}
|
|
16491
|
-
return this
|
|
16492
|
-
}
|
|
16493
|
-
this[DESTROYED] = true
|
|
16494
|
-
|
|
16495
|
-
// throw away all buffered data, it's never coming out
|
|
16496
|
-
this.buffer.length = 0
|
|
16497
|
-
this[BUFFERLENGTH] = 0
|
|
16498
|
-
if (typeof this.close === 'function' && !this[CLOSED]) {
|
|
16499
|
-
this.close()
|
|
16500
|
-
}
|
|
16501
|
-
if (er) {
|
|
16502
|
-
this.emit('error', er)
|
|
16503
|
-
}
|
|
16504
|
-
// if no error to emit, still reject pending promises
|
|
16505
|
-
else {
|
|
16506
|
-
this.emit(DESTROYED)
|
|
16507
|
-
}
|
|
16508
|
-
return this
|
|
16509
|
-
}
|
|
16510
|
-
static isStream(s) {
|
|
16511
|
-
return (
|
|
16512
|
-
!!s &&
|
|
16513
|
-
(s instanceof Minipass ||
|
|
16514
|
-
s instanceof Stream ||
|
|
16515
|
-
(s instanceof EE &&
|
|
16516
|
-
(typeof s.pipe === 'function' ||
|
|
16517
|
-
// readable
|
|
16518
|
-
(typeof s.write === 'function' && typeof s.end === 'function')))) // writable
|
|
16519
|
-
)
|
|
16520
|
-
}
|
|
16521
|
-
}
|
|
16522
|
-
return minipass$1
|
|
16523
|
-
}
|
|
16524
|
-
|
|
16525
|
-
let minipassFlush
|
|
16526
|
-
let hasRequiredMinipassFlush
|
|
16527
|
-
function requireMinipassFlush() {
|
|
16528
|
-
if (hasRequiredMinipassFlush) {
|
|
16529
|
-
return minipassFlush
|
|
16530
|
-
}
|
|
16531
|
-
hasRequiredMinipassFlush = 1
|
|
16532
|
-
const Minipass = requireMinipass$1()
|
|
16533
|
-
const _flush = Symbol('_flush')
|
|
16534
|
-
const _flushed = Symbol('_flushed')
|
|
16535
|
-
const _flushing = Symbol('_flushing')
|
|
16536
|
-
class Flush extends Minipass {
|
|
16537
|
-
constructor(opt = {}) {
|
|
16538
|
-
if (typeof opt === 'function') {
|
|
16539
|
-
opt = {
|
|
16540
|
-
flush: opt
|
|
16541
|
-
}
|
|
16542
|
-
}
|
|
16543
|
-
super(opt)
|
|
16544
|
-
|
|
16545
|
-
// or extend this class and provide a 'flush' method in your subclass
|
|
16546
|
-
if (typeof opt.flush !== 'function' && typeof this.flush !== 'function') {
|
|
16547
|
-
throw new TypeError('must provide flush function in options')
|
|
16548
|
-
}
|
|
16549
|
-
this[_flush] = opt.flush || this.flush
|
|
16550
|
-
}
|
|
16551
|
-
emit(ev, ...data) {
|
|
16552
|
-
if ((ev !== 'end' && ev !== 'finish') || this[_flushed]) {
|
|
16553
|
-
return super.emit(ev, ...data)
|
|
16554
|
-
}
|
|
16555
|
-
if (this[_flushing]) {
|
|
16556
|
-
return
|
|
16557
|
-
}
|
|
16558
|
-
this[_flushing] = true
|
|
16559
|
-
const afterFlush = er => {
|
|
16560
|
-
this[_flushed] = true
|
|
16561
|
-
er ? super.emit('error', er) : super.emit('end')
|
|
16562
|
-
}
|
|
16563
|
-
const ret = this[_flush](afterFlush)
|
|
16564
|
-
if (ret && ret.then) {
|
|
16565
|
-
ret.then(
|
|
16566
|
-
() => afterFlush(),
|
|
16567
|
-
er => afterFlush(er)
|
|
16568
|
-
)
|
|
16569
|
-
}
|
|
16570
|
-
}
|
|
16571
|
-
}
|
|
16572
|
-
minipassFlush = Flush
|
|
16573
|
-
return minipassFlush
|
|
16574
|
-
}
|
|
16575
|
-
|
|
16576
|
-
const lib$6 = { exports: {} }
|
|
16577
|
-
|
|
16578
|
-
const get = { exports: {} }
|
|
16579
|
-
|
|
16580
|
-
const minipassCollect = { exports: {} }
|
|
16581
|
-
|
|
16582
|
-
let hasRequiredMinipassCollect
|
|
16583
|
-
function requireMinipassCollect() {
|
|
16584
|
-
if (hasRequiredMinipassCollect) {
|
|
16585
|
-
return minipassCollect.exports
|
|
16586
|
-
}
|
|
16587
|
-
hasRequiredMinipassCollect = 1
|
|
16588
|
-
const { Minipass } = requireCommonjs$5()
|
|
16589
|
-
const _data = Symbol('_data')
|
|
16590
|
-
const _length = Symbol('_length')
|
|
16591
|
-
class Collect extends Minipass {
|
|
16592
|
-
constructor(options) {
|
|
16593
|
-
super(options)
|
|
16594
|
-
this[_data] = []
|
|
16595
|
-
this[_length] = 0
|
|
16596
|
-
}
|
|
16597
|
-
write(chunk, encoding, cb) {
|
|
16598
|
-
if (typeof encoding === 'function') {
|
|
16599
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16600
|
-
}
|
|
16601
|
-
if (!encoding) {
|
|
16602
|
-
encoding = 'utf8'
|
|
16603
|
-
}
|
|
16604
|
-
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding)
|
|
16605
|
-
this[_data].push(c)
|
|
16606
|
-
this[_length] += c.length
|
|
16607
|
-
if (cb) {
|
|
16608
|
-
cb()
|
|
16609
|
-
}
|
|
16610
|
-
return true
|
|
16611
|
-
}
|
|
16612
|
-
end(chunk, encoding, cb) {
|
|
16613
|
-
if (typeof chunk === 'function') {
|
|
16614
|
-
;(cb = chunk), (chunk = null)
|
|
16615
|
-
}
|
|
16616
|
-
if (typeof encoding === 'function') {
|
|
16617
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16618
|
-
}
|
|
16619
|
-
if (chunk) {
|
|
16620
|
-
this.write(chunk, encoding)
|
|
16621
|
-
}
|
|
16622
|
-
const result = Buffer.concat(this[_data], this[_length])
|
|
16623
|
-
super.write(result)
|
|
16624
|
-
return super.end(cb)
|
|
16625
|
-
}
|
|
16626
|
-
}
|
|
16627
|
-
minipassCollect.exports = Collect
|
|
16628
|
-
|
|
16629
|
-
// it would be possible to DRY this a bit by doing something like
|
|
16630
|
-
// this.collector = new Collect() and listening on its data event,
|
|
16631
|
-
// but it's not much code, and we may as well save the extra obj
|
|
16632
|
-
class CollectPassThrough extends Minipass {
|
|
16633
|
-
constructor(options) {
|
|
16634
|
-
super(options)
|
|
16635
|
-
this[_data] = []
|
|
16636
|
-
this[_length] = 0
|
|
16637
|
-
}
|
|
16638
|
-
write(chunk, encoding, cb) {
|
|
16639
|
-
if (typeof encoding === 'function') {
|
|
16640
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16641
|
-
}
|
|
16642
|
-
if (!encoding) {
|
|
16643
|
-
encoding = 'utf8'
|
|
16644
|
-
}
|
|
16645
|
-
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding)
|
|
16646
|
-
this[_data].push(c)
|
|
16647
|
-
this[_length] += c.length
|
|
16648
|
-
return super.write(chunk, encoding, cb)
|
|
16649
|
-
}
|
|
16650
|
-
end(chunk, encoding, cb) {
|
|
16651
|
-
if (typeof chunk === 'function') {
|
|
16652
|
-
;(cb = chunk), (chunk = null)
|
|
16653
|
-
}
|
|
16654
|
-
if (typeof encoding === 'function') {
|
|
16655
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16656
|
-
}
|
|
16657
|
-
if (chunk) {
|
|
16658
|
-
this.write(chunk, encoding)
|
|
16659
|
-
}
|
|
16660
|
-
const result = Buffer.concat(this[_data], this[_length])
|
|
16661
|
-
this.emit('collect', result)
|
|
16662
|
-
return super.end(cb)
|
|
16663
|
-
}
|
|
16664
|
-
}
|
|
16665
|
-
minipassCollect.exports.PassThrough = CollectPassThrough
|
|
16666
|
-
return minipassCollect.exports
|
|
16667
|
-
}
|
|
16668
|
-
|
|
16669
|
-
let minipass
|
|
16670
|
-
let hasRequiredMinipass
|
|
16671
|
-
function requireMinipass() {
|
|
16672
|
-
if (hasRequiredMinipass) {
|
|
16673
|
-
return minipass
|
|
16674
|
-
}
|
|
16675
|
-
hasRequiredMinipass = 1
|
|
16676
|
-
const proc =
|
|
16677
|
-
typeof process === 'object' && process
|
|
16678
|
-
? process
|
|
16679
|
-
: {
|
|
16680
|
-
stdout: null,
|
|
16681
|
-
stderr: null
|
|
16682
|
-
}
|
|
16683
|
-
const EE = require$$0$5
|
|
16684
|
-
const Stream = require$$1$2
|
|
16685
|
-
const SD = require$$2$2.StringDecoder
|
|
16686
|
-
const EOF = Symbol('EOF')
|
|
16687
|
-
const MAYBE_EMIT_END = Symbol('maybeEmitEnd')
|
|
16688
|
-
const EMITTED_END = Symbol('emittedEnd')
|
|
16689
|
-
const EMITTING_END = Symbol('emittingEnd')
|
|
16690
|
-
const EMITTED_ERROR = Symbol('emittedError')
|
|
16691
|
-
const CLOSED = Symbol('closed')
|
|
16692
|
-
const READ = Symbol('read')
|
|
16693
|
-
const FLUSH = Symbol('flush')
|
|
16694
|
-
const FLUSHCHUNK = Symbol('flushChunk')
|
|
16695
|
-
const ENCODING = Symbol('encoding')
|
|
16696
|
-
const DECODER = Symbol('decoder')
|
|
16697
|
-
const FLOWING = Symbol('flowing')
|
|
16698
|
-
const PAUSED = Symbol('paused')
|
|
16699
|
-
const RESUME = Symbol('resume')
|
|
16700
|
-
const BUFFERLENGTH = Symbol('bufferLength')
|
|
16701
|
-
const BUFFERPUSH = Symbol('bufferPush')
|
|
16702
|
-
const BUFFERSHIFT = Symbol('bufferShift')
|
|
16703
|
-
const OBJECTMODE = Symbol('objectMode')
|
|
16704
|
-
const DESTROYED = Symbol('destroyed')
|
|
16705
|
-
const EMITDATA = Symbol('emitData')
|
|
16706
|
-
const EMITEND = Symbol('emitEnd')
|
|
16707
|
-
const EMITEND2 = Symbol('emitEnd2')
|
|
16708
|
-
const ASYNC = Symbol('async')
|
|
16709
|
-
const defer = fn => Promise.resolve().then(fn)
|
|
16710
|
-
|
|
16711
|
-
// TODO remove when Node v8 support drops
|
|
16712
|
-
const doIter = global._MP_NO_ITERATOR_SYMBOLS_ !== '1'
|
|
16713
|
-
const ASYNCITERATOR =
|
|
16714
|
-
(doIter && Symbol.asyncIterator) || Symbol('asyncIterator not implemented')
|
|
16715
|
-
const ITERATOR =
|
|
16716
|
-
(doIter && Symbol.iterator) || Symbol('iterator not implemented')
|
|
16717
|
-
|
|
16718
|
-
// events that mean 'the stream is over'
|
|
16719
|
-
// these are treated specially, and re-emitted
|
|
16720
|
-
// if they are listened for after emitting.
|
|
16721
|
-
const isEndish = ev => ev === 'end' || ev === 'finish' || ev === 'prefinish'
|
|
16722
|
-
const isArrayBuffer = b =>
|
|
16723
|
-
b instanceof ArrayBuffer ||
|
|
16724
|
-
(typeof b === 'object' &&
|
|
16725
|
-
b.constructor &&
|
|
16726
|
-
b.constructor.name === 'ArrayBuffer' &&
|
|
16727
|
-
b.byteLength >= 0)
|
|
16728
|
-
const isArrayBufferView = b => !Buffer.isBuffer(b) && ArrayBuffer.isView(b)
|
|
16729
|
-
class Pipe {
|
|
16730
|
-
constructor(src, dest, opts) {
|
|
16731
|
-
this.src = src
|
|
16732
|
-
this.dest = dest
|
|
16733
|
-
this.opts = opts
|
|
16734
|
-
this.ondrain = () => src[RESUME]()
|
|
16735
|
-
dest.on('drain', this.ondrain)
|
|
16736
|
-
}
|
|
16737
|
-
unpipe() {
|
|
16738
|
-
this.dest.removeListener('drain', this.ondrain)
|
|
16739
|
-
}
|
|
16740
|
-
// istanbul ignore next - only here for the prototype
|
|
16741
|
-
proxyErrors() {}
|
|
16742
|
-
end() {
|
|
16743
|
-
this.unpipe()
|
|
16744
|
-
if (this.opts.end) {
|
|
16745
|
-
this.dest.end()
|
|
16746
|
-
}
|
|
16747
|
-
}
|
|
16748
|
-
}
|
|
16749
|
-
class PipeProxyErrors extends Pipe {
|
|
16750
|
-
unpipe() {
|
|
16751
|
-
this.src.removeListener('error', this.proxyErrors)
|
|
16752
|
-
super.unpipe()
|
|
16753
|
-
}
|
|
16754
|
-
constructor(src, dest, opts) {
|
|
16755
|
-
super(src, dest, opts)
|
|
16756
|
-
this.proxyErrors = er => dest.emit('error', er)
|
|
16757
|
-
src.on('error', this.proxyErrors)
|
|
16758
|
-
}
|
|
16759
|
-
}
|
|
16760
|
-
minipass = class Minipass extends Stream {
|
|
16761
|
-
constructor(options) {
|
|
16762
|
-
super()
|
|
16763
|
-
this[FLOWING] = false
|
|
16764
|
-
// whether we're explicitly paused
|
|
16765
|
-
this[PAUSED] = false
|
|
16766
|
-
this.pipes = []
|
|
16767
|
-
this.buffer = []
|
|
16768
|
-
this[OBJECTMODE] = (options && options.objectMode) || false
|
|
16769
|
-
if (this[OBJECTMODE]) {
|
|
16770
|
-
this[ENCODING] = null
|
|
16771
|
-
} else {
|
|
16772
|
-
this[ENCODING] = (options && options.encoding) || null
|
|
16773
|
-
}
|
|
16774
|
-
if (this[ENCODING] === 'buffer') {
|
|
16775
|
-
this[ENCODING] = null
|
|
16776
|
-
}
|
|
16777
|
-
this[ASYNC] = (options && !!options.async) || false
|
|
16778
|
-
this[DECODER] = this[ENCODING] ? new SD(this[ENCODING]) : null
|
|
16779
|
-
this[EOF] = false
|
|
16780
|
-
this[EMITTED_END] = false
|
|
16781
|
-
this[EMITTING_END] = false
|
|
16782
|
-
this[CLOSED] = false
|
|
16783
|
-
this[EMITTED_ERROR] = null
|
|
16784
|
-
this.writable = true
|
|
16785
|
-
this.readable = true
|
|
16786
|
-
this[BUFFERLENGTH] = 0
|
|
16787
|
-
this[DESTROYED] = false
|
|
16788
|
-
}
|
|
16789
|
-
get bufferLength() {
|
|
16790
|
-
return this[BUFFERLENGTH]
|
|
16791
|
-
}
|
|
16792
|
-
get encoding() {
|
|
16793
|
-
return this[ENCODING]
|
|
16794
|
-
}
|
|
16795
|
-
set encoding(enc) {
|
|
16796
|
-
if (this[OBJECTMODE]) {
|
|
16797
|
-
throw new Error('cannot set encoding in objectMode')
|
|
16798
|
-
}
|
|
16799
|
-
if (
|
|
16800
|
-
this[ENCODING] &&
|
|
16801
|
-
enc !== this[ENCODING] &&
|
|
16802
|
-
((this[DECODER] && this[DECODER].lastNeed) || this[BUFFERLENGTH])
|
|
16803
|
-
) {
|
|
16804
|
-
throw new Error('cannot change encoding')
|
|
16805
|
-
}
|
|
16806
|
-
if (this[ENCODING] !== enc) {
|
|
16807
|
-
this[DECODER] = enc ? new SD(enc) : null
|
|
16808
|
-
if (this.buffer.length) {
|
|
16809
|
-
this.buffer = this.buffer.map(chunk => this[DECODER].write(chunk))
|
|
16810
|
-
}
|
|
16811
|
-
}
|
|
16812
|
-
this[ENCODING] = enc
|
|
16813
|
-
}
|
|
16814
|
-
setEncoding(enc) {
|
|
16815
|
-
this.encoding = enc
|
|
16816
|
-
}
|
|
16817
|
-
get objectMode() {
|
|
16818
|
-
return this[OBJECTMODE]
|
|
16819
|
-
}
|
|
16820
|
-
set objectMode(om) {
|
|
16821
|
-
this[OBJECTMODE] = this[OBJECTMODE] || !!om
|
|
16822
|
-
}
|
|
16823
|
-
get ['async']() {
|
|
16824
|
-
return this[ASYNC]
|
|
16825
|
-
}
|
|
16826
|
-
set ['async'](a) {
|
|
16827
|
-
this[ASYNC] = this[ASYNC] || !!a
|
|
16828
|
-
}
|
|
16829
|
-
write(chunk, encoding, cb) {
|
|
16830
|
-
if (this[EOF]) {
|
|
16831
|
-
throw new Error('write after end')
|
|
16832
|
-
}
|
|
16833
|
-
if (this[DESTROYED]) {
|
|
16834
|
-
this.emit(
|
|
16835
|
-
'error',
|
|
16836
|
-
Object.assign(
|
|
16837
|
-
new Error('Cannot call write after a stream was destroyed'),
|
|
16838
|
-
{
|
|
16839
|
-
code: 'ERR_STREAM_DESTROYED'
|
|
16840
|
-
}
|
|
16841
|
-
)
|
|
16842
|
-
)
|
|
16843
|
-
return true
|
|
16844
|
-
}
|
|
16845
|
-
if (typeof encoding === 'function') {
|
|
16846
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16847
|
-
}
|
|
16848
|
-
if (!encoding) {
|
|
16849
|
-
encoding = 'utf8'
|
|
16850
|
-
}
|
|
16851
|
-
const fn = this[ASYNC] ? defer : f => f()
|
|
16852
|
-
|
|
16853
|
-
// convert array buffers and typed array views into buffers
|
|
16854
|
-
// at some point in the future, we may want to do the opposite!
|
|
16855
|
-
// leave strings and buffers as-is
|
|
16856
|
-
// anything else switches us into object mode
|
|
16857
|
-
if (!this[OBJECTMODE] && !Buffer.isBuffer(chunk)) {
|
|
16858
|
-
if (isArrayBufferView(chunk)) {
|
|
16859
|
-
chunk = Buffer.from(chunk.buffer, chunk.byteOffset, chunk.byteLength)
|
|
16860
|
-
} else if (isArrayBuffer(chunk)) {
|
|
16861
|
-
chunk = Buffer.from(chunk)
|
|
16862
|
-
} else if (typeof chunk !== 'string') {
|
|
16863
|
-
// use the setter so we throw if we have encoding set
|
|
16864
|
-
this.objectMode = true
|
|
16865
|
-
}
|
|
16866
|
-
}
|
|
16867
|
-
|
|
16868
|
-
// handle object mode up front, since it's simpler
|
|
16869
|
-
// this yields better performance, fewer checks later.
|
|
16870
|
-
if (this[OBJECTMODE]) {
|
|
16871
|
-
/* istanbul ignore if - maybe impossible? */
|
|
16872
|
-
if (this.flowing && this[BUFFERLENGTH] !== 0) {
|
|
16873
|
-
this[FLUSH](true)
|
|
16874
|
-
}
|
|
16875
|
-
if (this.flowing) {
|
|
16876
|
-
this.emit('data', chunk)
|
|
16877
|
-
} else {
|
|
16878
|
-
this[BUFFERPUSH](chunk)
|
|
16879
|
-
}
|
|
16880
|
-
if (this[BUFFERLENGTH] !== 0) {
|
|
16881
|
-
this.emit('readable')
|
|
16882
|
-
}
|
|
16883
|
-
if (cb) {
|
|
16884
|
-
fn(cb)
|
|
16885
|
-
}
|
|
16886
|
-
return this.flowing
|
|
16887
|
-
}
|
|
16888
|
-
|
|
16889
|
-
// at this point the chunk is a buffer or string
|
|
16890
|
-
// don't buffer it up or send it to the decoder
|
|
16891
|
-
if (!chunk.length) {
|
|
16892
|
-
if (this[BUFFERLENGTH] !== 0) {
|
|
16893
|
-
this.emit('readable')
|
|
16894
|
-
}
|
|
16895
|
-
if (cb) {
|
|
16896
|
-
fn(cb)
|
|
16897
|
-
}
|
|
16898
|
-
return this.flowing
|
|
16899
|
-
}
|
|
16900
|
-
|
|
16901
|
-
// fast-path writing strings of same encoding to a stream with
|
|
16902
|
-
// an empty buffer, skipping the buffer/decoder dance
|
|
16903
|
-
if (
|
|
16904
|
-
typeof chunk === 'string' &&
|
|
16905
|
-
// unless it is a string already ready for us to use
|
|
16906
|
-
!(encoding === this[ENCODING] && !this[DECODER].lastNeed)
|
|
16907
|
-
) {
|
|
16908
|
-
chunk = Buffer.from(chunk, encoding)
|
|
16909
|
-
}
|
|
16910
|
-
if (Buffer.isBuffer(chunk) && this[ENCODING]) {
|
|
16911
|
-
chunk = this[DECODER].write(chunk)
|
|
16912
|
-
}
|
|
16913
|
-
|
|
16914
|
-
// Note: flushing CAN potentially switch us into not-flowing mode
|
|
16915
|
-
if (this.flowing && this[BUFFERLENGTH] !== 0) {
|
|
16916
|
-
this[FLUSH](true)
|
|
16917
|
-
}
|
|
16918
|
-
if (this.flowing) {
|
|
16919
|
-
this.emit('data', chunk)
|
|
16920
|
-
} else {
|
|
16921
|
-
this[BUFFERPUSH](chunk)
|
|
16922
|
-
}
|
|
16923
|
-
if (this[BUFFERLENGTH] !== 0) {
|
|
16924
|
-
this.emit('readable')
|
|
16925
|
-
}
|
|
16926
|
-
if (cb) {
|
|
16927
|
-
fn(cb)
|
|
16928
|
-
}
|
|
16929
|
-
return this.flowing
|
|
16930
|
-
}
|
|
16931
|
-
read(n) {
|
|
16932
|
-
if (this[DESTROYED]) {
|
|
16933
|
-
return null
|
|
16934
|
-
}
|
|
16935
|
-
if (this[BUFFERLENGTH] === 0 || n === 0 || n > this[BUFFERLENGTH]) {
|
|
16936
|
-
this[MAYBE_EMIT_END]()
|
|
16937
|
-
return null
|
|
16938
|
-
}
|
|
16939
|
-
if (this[OBJECTMODE]) {
|
|
16940
|
-
n = null
|
|
16941
|
-
}
|
|
16942
|
-
if (this.buffer.length > 1 && !this[OBJECTMODE]) {
|
|
16943
|
-
if (this.encoding) {
|
|
16944
|
-
this.buffer = [this.buffer.join('')]
|
|
16945
|
-
} else {
|
|
16946
|
-
this.buffer = [Buffer.concat(this.buffer, this[BUFFERLENGTH])]
|
|
16947
|
-
}
|
|
16948
|
-
}
|
|
16949
|
-
const ret = this[READ](n || null, this.buffer[0])
|
|
16950
|
-
this[MAYBE_EMIT_END]()
|
|
16951
|
-
return ret
|
|
16952
|
-
}
|
|
16953
|
-
[READ](n, chunk) {
|
|
16954
|
-
if (n === chunk.length || n === null) {
|
|
16955
|
-
this[BUFFERSHIFT]()
|
|
16956
|
-
} else {
|
|
16957
|
-
this.buffer[0] = chunk.slice(n)
|
|
16958
|
-
chunk = chunk.slice(0, n)
|
|
16959
|
-
this[BUFFERLENGTH] -= n
|
|
16960
|
-
}
|
|
16961
|
-
this.emit('data', chunk)
|
|
16962
|
-
if (!this.buffer.length && !this[EOF]) {
|
|
16963
|
-
this.emit('drain')
|
|
16964
|
-
}
|
|
16965
|
-
return chunk
|
|
16966
|
-
}
|
|
16967
|
-
end(chunk, encoding, cb) {
|
|
16968
|
-
if (typeof chunk === 'function') {
|
|
16969
|
-
;(cb = chunk), (chunk = null)
|
|
16970
|
-
}
|
|
16971
|
-
if (typeof encoding === 'function') {
|
|
16972
|
-
;(cb = encoding), (encoding = 'utf8')
|
|
16973
|
-
}
|
|
16974
|
-
if (chunk) {
|
|
16975
|
-
this.write(chunk, encoding)
|
|
16976
|
-
}
|
|
16977
|
-
if (cb) {
|
|
16978
|
-
this.once('end', cb)
|
|
16979
|
-
}
|
|
16980
|
-
this[EOF] = true
|
|
16981
|
-
this.writable = false
|
|
16982
|
-
|
|
16983
|
-
// if we haven't written anything, then go ahead and emit,
|
|
16984
|
-
// even if we're not reading.
|
|
16985
|
-
// we'll re-emit if a new 'end' listener is added anyway.
|
|
16986
|
-
// This makes MP more suitable to write-only use cases.
|
|
16987
|
-
if (this.flowing || !this[PAUSED]) {
|
|
16988
|
-
this[MAYBE_EMIT_END]()
|
|
16989
|
-
}
|
|
16990
|
-
return this
|
|
16991
|
-
}
|
|
16992
|
-
|
|
16993
|
-
// don't let the internal resume be overwritten
|
|
16994
|
-
[RESUME]() {
|
|
16995
|
-
if (this[DESTROYED]) {
|
|
16996
|
-
return
|
|
16997
|
-
}
|
|
16998
|
-
this[PAUSED] = false
|
|
16999
|
-
this[FLOWING] = true
|
|
17000
|
-
this.emit('resume')
|
|
17001
|
-
if (this.buffer.length) {
|
|
17002
|
-
this[FLUSH]()
|
|
17003
|
-
} else if (this[EOF]) {
|
|
17004
|
-
this[MAYBE_EMIT_END]()
|
|
17005
|
-
} else {
|
|
17006
|
-
this.emit('drain')
|
|
17007
|
-
}
|
|
17008
|
-
}
|
|
17009
|
-
resume() {
|
|
17010
|
-
return this[RESUME]()
|
|
17011
|
-
}
|
|
17012
|
-
pause() {
|
|
17013
|
-
this[FLOWING] = false
|
|
17014
|
-
this[PAUSED] = true
|
|
17015
|
-
}
|
|
17016
|
-
get destroyed() {
|
|
17017
|
-
return this[DESTROYED]
|
|
17018
|
-
}
|
|
17019
|
-
get flowing() {
|
|
17020
|
-
return this[FLOWING]
|
|
17021
|
-
}
|
|
17022
|
-
get paused() {
|
|
17023
|
-
return this[PAUSED]
|
|
17024
|
-
}
|
|
17025
|
-
[BUFFERPUSH](chunk) {
|
|
17026
|
-
if (this[OBJECTMODE]) {
|
|
17027
|
-
this[BUFFERLENGTH] += 1
|
|
17028
|
-
} else {
|
|
17029
|
-
this[BUFFERLENGTH] += chunk.length
|
|
17030
|
-
}
|
|
17031
|
-
this.buffer.push(chunk)
|
|
17032
|
-
}
|
|
17033
|
-
[BUFFERSHIFT]() {
|
|
17034
|
-
if (this.buffer.length) {
|
|
17035
|
-
if (this[OBJECTMODE]) {
|
|
17036
|
-
this[BUFFERLENGTH] -= 1
|
|
17037
|
-
} else {
|
|
17038
|
-
this[BUFFERLENGTH] -= this.buffer[0].length
|
|
17039
|
-
}
|
|
17040
|
-
}
|
|
17041
|
-
return this.buffer.shift()
|
|
17042
|
-
}
|
|
17043
|
-
[FLUSH](noDrain) {
|
|
17044
|
-
do {} while (this[FLUSHCHUNK](this[BUFFERSHIFT]()))
|
|
17045
|
-
if (!noDrain && !this.buffer.length && !this[EOF]) {
|
|
17046
|
-
this.emit('drain')
|
|
17047
|
-
}
|
|
17048
|
-
}
|
|
17049
|
-
[FLUSHCHUNK](chunk) {
|
|
17050
|
-
return chunk ? (this.emit('data', chunk), this.flowing) : false
|
|
17051
|
-
}
|
|
17052
|
-
pipe(dest, opts) {
|
|
17053
|
-
if (this[DESTROYED]) {
|
|
17054
|
-
return
|
|
15698
|
+
// static method to quickly determine if a request alone is storable
|
|
15699
|
+
static storable(request, options) {
|
|
15700
|
+
// no cachePath means no caching
|
|
15701
|
+
if (!options.cachePath) {
|
|
15702
|
+
return false
|
|
17055
15703
|
}
|
|
17056
|
-
|
|
17057
|
-
|
|
17058
|
-
if (
|
|
17059
|
-
|
|
17060
|
-
} else {
|
|
17061
|
-
opts.end = opts.end !== false
|
|
15704
|
+
|
|
15705
|
+
// user explicitly asked not to cache
|
|
15706
|
+
if (options.cache === 'no-store') {
|
|
15707
|
+
return false
|
|
17062
15708
|
}
|
|
17063
|
-
opts.proxyErrors = !!opts.proxyErrors
|
|
17064
15709
|
|
|
17065
|
-
//
|
|
17066
|
-
if (
|
|
17067
|
-
|
|
17068
|
-
dest.end()
|
|
17069
|
-
}
|
|
17070
|
-
} else {
|
|
17071
|
-
this.pipes.push(
|
|
17072
|
-
!opts.proxyErrors
|
|
17073
|
-
? new Pipe(this, dest, opts)
|
|
17074
|
-
: new PipeProxyErrors(this, dest, opts)
|
|
17075
|
-
)
|
|
17076
|
-
if (this[ASYNC]) {
|
|
17077
|
-
defer(() => this[RESUME]())
|
|
17078
|
-
} else {
|
|
17079
|
-
this[RESUME]()
|
|
17080
|
-
}
|
|
15710
|
+
// we only cache GET and HEAD requests
|
|
15711
|
+
if (!['GET', 'HEAD'].includes(request.method)) {
|
|
15712
|
+
return false
|
|
17081
15713
|
}
|
|
17082
|
-
|
|
15714
|
+
|
|
15715
|
+
// otherwise, let http-cache-semantics make the decision
|
|
15716
|
+
// based on the request's headers
|
|
15717
|
+
const policy = new CacheSemantics(
|
|
15718
|
+
requestObject(request),
|
|
15719
|
+
emptyResponse,
|
|
15720
|
+
policyOptions
|
|
15721
|
+
)
|
|
15722
|
+
return policy.storable()
|
|
17083
15723
|
}
|
|
17084
|
-
|
|
17085
|
-
|
|
17086
|
-
|
|
17087
|
-
|
|
17088
|
-
|
|
15724
|
+
|
|
15725
|
+
// returns true if the policy satisfies the request
|
|
15726
|
+
satisfies(request) {
|
|
15727
|
+
const _req = requestObject(request)
|
|
15728
|
+
if (this.request.headers.host !== _req.headers.host) {
|
|
15729
|
+
return false
|
|
17089
15730
|
}
|
|
17090
|
-
|
|
17091
|
-
|
|
17092
|
-
return this.on(ev, fn)
|
|
17093
|
-
}
|
|
17094
|
-
on(ev, fn) {
|
|
17095
|
-
const ret = super.on(ev, fn)
|
|
17096
|
-
if (ev === 'data' && !this.pipes.length && !this.flowing) {
|
|
17097
|
-
this[RESUME]()
|
|
17098
|
-
} else if (ev === 'readable' && this[BUFFERLENGTH] !== 0) {
|
|
17099
|
-
super.emit('readable')
|
|
17100
|
-
} else if (isEndish(ev) && this[EMITTED_END]) {
|
|
17101
|
-
super.emit(ev)
|
|
17102
|
-
this.removeAllListeners(ev)
|
|
17103
|
-
} else if (ev === 'error' && this[EMITTED_ERROR]) {
|
|
17104
|
-
if (this[ASYNC]) {
|
|
17105
|
-
defer(() => fn.call(this, this[EMITTED_ERROR]))
|
|
17106
|
-
} else {
|
|
17107
|
-
fn.call(this, this[EMITTED_ERROR])
|
|
17108
|
-
}
|
|
15731
|
+
if (this.request.compress !== _req.compress) {
|
|
15732
|
+
return false
|
|
17109
15733
|
}
|
|
17110
|
-
|
|
17111
|
-
|
|
17112
|
-
get emittedEnd() {
|
|
17113
|
-
return this[EMITTED_END]
|
|
17114
|
-
}
|
|
17115
|
-
[MAYBE_EMIT_END]() {
|
|
15734
|
+
const negotiatorA = new Negotiator(this.request)
|
|
15735
|
+
const negotiatorB = new Negotiator(_req)
|
|
17116
15736
|
if (
|
|
17117
|
-
|
|
17118
|
-
|
|
17119
|
-
!this[DESTROYED] &&
|
|
17120
|
-
this.buffer.length === 0 &&
|
|
17121
|
-
this[EOF]
|
|
15737
|
+
JSON.stringify(negotiatorA.mediaTypes()) !==
|
|
15738
|
+
JSON.stringify(negotiatorB.mediaTypes())
|
|
17122
15739
|
) {
|
|
17123
|
-
|
|
17124
|
-
this.emit('end')
|
|
17125
|
-
this.emit('prefinish')
|
|
17126
|
-
this.emit('finish')
|
|
17127
|
-
if (this[CLOSED]) {
|
|
17128
|
-
this.emit('close')
|
|
17129
|
-
}
|
|
17130
|
-
this[EMITTING_END] = false
|
|
15740
|
+
return false
|
|
17131
15741
|
}
|
|
17132
|
-
}
|
|
17133
|
-
emit(ev, data, ...extra) {
|
|
17134
|
-
// error and close are only events allowed after calling destroy()
|
|
17135
15742
|
if (
|
|
17136
|
-
|
|
17137
|
-
|
|
17138
|
-
ev !== DESTROYED &&
|
|
17139
|
-
this[DESTROYED]
|
|
15743
|
+
JSON.stringify(negotiatorA.languages()) !==
|
|
15744
|
+
JSON.stringify(negotiatorB.languages())
|
|
17140
15745
|
) {
|
|
17141
|
-
return
|
|
17142
|
-
}
|
|
17143
|
-
|
|
17144
|
-
|
|
17145
|
-
|
|
17146
|
-
|
|
17147
|
-
|
|
17148
|
-
} else if (ev === 'end') {
|
|
17149
|
-
return this[EMITEND]()
|
|
17150
|
-
} else if (ev === 'close') {
|
|
17151
|
-
this[CLOSED] = true
|
|
17152
|
-
// don't emit close before 'end' and 'finish'
|
|
17153
|
-
if (!this[EMITTED_END] && !this[DESTROYED]) {
|
|
17154
|
-
return
|
|
17155
|
-
}
|
|
17156
|
-
const ret = super.emit('close')
|
|
17157
|
-
this.removeAllListeners('close')
|
|
17158
|
-
return ret
|
|
17159
|
-
} else if (ev === 'error') {
|
|
17160
|
-
this[EMITTED_ERROR] = data
|
|
17161
|
-
const ret = super.emit('error', data)
|
|
17162
|
-
this[MAYBE_EMIT_END]()
|
|
17163
|
-
return ret
|
|
17164
|
-
} else if (ev === 'resume') {
|
|
17165
|
-
const ret = super.emit('resume')
|
|
17166
|
-
this[MAYBE_EMIT_END]()
|
|
17167
|
-
return ret
|
|
17168
|
-
} else if (ev === 'finish' || ev === 'prefinish') {
|
|
17169
|
-
const ret = super.emit(ev)
|
|
17170
|
-
this.removeAllListeners(ev)
|
|
17171
|
-
return ret
|
|
15746
|
+
return false
|
|
15747
|
+
}
|
|
15748
|
+
if (
|
|
15749
|
+
JSON.stringify(negotiatorA.encodings()) !==
|
|
15750
|
+
JSON.stringify(negotiatorB.encodings())
|
|
15751
|
+
) {
|
|
15752
|
+
return false
|
|
17172
15753
|
}
|
|
15754
|
+
if (this.options.integrity) {
|
|
15755
|
+
return ssri.parse(this.options.integrity).match(this.entry.integrity)
|
|
15756
|
+
}
|
|
15757
|
+
return true
|
|
15758
|
+
}
|
|
17173
15759
|
|
|
17174
|
-
|
|
17175
|
-
|
|
17176
|
-
this
|
|
17177
|
-
return ret
|
|
15760
|
+
// returns true if the request and response allow caching
|
|
15761
|
+
storable() {
|
|
15762
|
+
return this.policy.storable()
|
|
17178
15763
|
}
|
|
17179
|
-
|
|
17180
|
-
|
|
17181
|
-
|
|
17182
|
-
|
|
17183
|
-
|
|
17184
|
-
|
|
17185
|
-
const ret = super.emit('data', data)
|
|
17186
|
-
this[MAYBE_EMIT_END]()
|
|
17187
|
-
return ret
|
|
15764
|
+
|
|
15765
|
+
// NOTE: this is a hack to avoid parsing the cache-control
|
|
15766
|
+
// header ourselves, it returns true if the response's
|
|
15767
|
+
// cache-control contains must-revalidate
|
|
15768
|
+
get mustRevalidate() {
|
|
15769
|
+
return !!this.policy._rescc['must-revalidate']
|
|
17188
15770
|
}
|
|
17189
|
-
|
|
17190
|
-
|
|
17191
|
-
|
|
17192
|
-
|
|
17193
|
-
|
|
17194
|
-
|
|
17195
|
-
|
|
17196
|
-
|
|
17197
|
-
|
|
17198
|
-
this[EMITEND2]()
|
|
17199
|
-
}
|
|
15771
|
+
|
|
15772
|
+
// returns true if the cached response requires revalidation
|
|
15773
|
+
// for the given request
|
|
15774
|
+
needsRevalidation(request) {
|
|
15775
|
+
const _req = requestObject(request)
|
|
15776
|
+
// force method to GET because we only cache GETs
|
|
15777
|
+
// but can serve a HEAD from a cached GET
|
|
15778
|
+
_req.method = 'GET'
|
|
15779
|
+
return !this.policy.satisfiesWithoutRevalidation(_req)
|
|
17200
15780
|
}
|
|
17201
|
-
|
|
17202
|
-
|
|
17203
|
-
const data = this[DECODER].end()
|
|
17204
|
-
if (data) {
|
|
17205
|
-
for (const p of this.pipes) {
|
|
17206
|
-
p.dest.write(data)
|
|
17207
|
-
}
|
|
17208
|
-
super.emit('data', data)
|
|
17209
|
-
}
|
|
17210
|
-
}
|
|
17211
|
-
for (const p of this.pipes) {
|
|
17212
|
-
p.end()
|
|
17213
|
-
}
|
|
17214
|
-
const ret = super.emit('end')
|
|
17215
|
-
this.removeAllListeners('end')
|
|
17216
|
-
return ret
|
|
15781
|
+
responseHeaders() {
|
|
15782
|
+
return this.policy.responseHeaders()
|
|
17217
15783
|
}
|
|
17218
15784
|
|
|
17219
|
-
//
|
|
17220
|
-
|
|
17221
|
-
|
|
17222
|
-
|
|
17223
|
-
|
|
17224
|
-
}
|
|
17225
|
-
// set the promise first, in case an error is raised
|
|
17226
|
-
// by triggering the flow here.
|
|
17227
|
-
const p = this.promise()
|
|
17228
|
-
this.on('data', c => {
|
|
17229
|
-
buf.push(c)
|
|
17230
|
-
if (!this[OBJECTMODE]) {
|
|
17231
|
-
buf.dataLength += c.length
|
|
17232
|
-
}
|
|
17233
|
-
})
|
|
17234
|
-
return p.then(() => buf)
|
|
15785
|
+
// returns a new object containing the appropriate headers
|
|
15786
|
+
// to send a revalidation request
|
|
15787
|
+
revalidationHeaders(request) {
|
|
15788
|
+
const _req = requestObject(request)
|
|
15789
|
+
return this.policy.revalidationHeaders(_req)
|
|
17235
15790
|
}
|
|
17236
15791
|
|
|
17237
|
-
//
|
|
17238
|
-
|
|
17239
|
-
|
|
17240
|
-
|
|
17241
|
-
|
|
17242
|
-
|
|
17243
|
-
|
|
17244
|
-
: this[ENCODING]
|
|
17245
|
-
? buf.join('')
|
|
17246
|
-
: Buffer.concat(buf, buf.dataLength)
|
|
17247
|
-
)
|
|
15792
|
+
// returns true if the request/response was revalidated
|
|
15793
|
+
// successfully. returns false if a new response was received
|
|
15794
|
+
revalidated(request, response) {
|
|
15795
|
+
const _req = requestObject(request)
|
|
15796
|
+
const _res = responseObject(response)
|
|
15797
|
+
const policy = this.policy.revalidatedPolicy(_req, _res)
|
|
15798
|
+
return !policy.modified
|
|
17248
15799
|
}
|
|
15800
|
+
}
|
|
15801
|
+
policy = CachePolicy
|
|
15802
|
+
return policy
|
|
15803
|
+
}
|
|
17249
15804
|
|
|
17250
|
-
|
|
17251
|
-
|
|
17252
|
-
|
|
17253
|
-
|
|
17254
|
-
|
|
17255
|
-
|
|
17256
|
-
|
|
15805
|
+
let errors$2
|
|
15806
|
+
let hasRequiredErrors$2
|
|
15807
|
+
function requireErrors$2() {
|
|
15808
|
+
if (hasRequiredErrors$2) {
|
|
15809
|
+
return errors$2
|
|
15810
|
+
}
|
|
15811
|
+
hasRequiredErrors$2 = 1
|
|
15812
|
+
class NotCachedError extends Error {
|
|
15813
|
+
constructor(url) {
|
|
15814
|
+
/* eslint-disable-next-line max-len */
|
|
15815
|
+
super(
|
|
15816
|
+
`request to ${url} failed: cache mode is 'only-if-cached' but no cached response is available.`
|
|
15817
|
+
)
|
|
15818
|
+
this.code = 'ENOTCACHED'
|
|
17257
15819
|
}
|
|
15820
|
+
}
|
|
15821
|
+
errors$2 = {
|
|
15822
|
+
NotCachedError
|
|
15823
|
+
}
|
|
15824
|
+
return errors$2
|
|
15825
|
+
}
|
|
17258
15826
|
|
|
17259
|
-
|
|
17260
|
-
|
|
17261
|
-
|
|
17262
|
-
|
|
17263
|
-
|
|
17264
|
-
|
|
17265
|
-
|
|
17266
|
-
|
|
17267
|
-
|
|
17268
|
-
|
|
17269
|
-
|
|
17270
|
-
|
|
17271
|
-
|
|
17272
|
-
|
|
17273
|
-
|
|
17274
|
-
|
|
17275
|
-
let reject = null
|
|
17276
|
-
const onerr = er => {
|
|
17277
|
-
this.removeListener('data', ondata)
|
|
17278
|
-
this.removeListener('end', onend)
|
|
17279
|
-
reject(er)
|
|
17280
|
-
}
|
|
17281
|
-
const ondata = value => {
|
|
17282
|
-
this.removeListener('error', onerr)
|
|
17283
|
-
this.removeListener('end', onend)
|
|
17284
|
-
this.pause()
|
|
17285
|
-
resolve({
|
|
17286
|
-
value: value,
|
|
17287
|
-
done: !!this[EOF]
|
|
17288
|
-
})
|
|
17289
|
-
}
|
|
17290
|
-
const onend = () => {
|
|
17291
|
-
this.removeListener('error', onerr)
|
|
17292
|
-
this.removeListener('data', ondata)
|
|
17293
|
-
resolve({
|
|
17294
|
-
done: true
|
|
17295
|
-
})
|
|
15827
|
+
let minipassFlush
|
|
15828
|
+
let hasRequiredMinipassFlush
|
|
15829
|
+
function requireMinipassFlush() {
|
|
15830
|
+
if (hasRequiredMinipassFlush) {
|
|
15831
|
+
return minipassFlush
|
|
15832
|
+
}
|
|
15833
|
+
hasRequiredMinipassFlush = 1
|
|
15834
|
+
const Minipass = requireMinipass()
|
|
15835
|
+
const _flush = Symbol('_flush')
|
|
15836
|
+
const _flushed = Symbol('_flushed')
|
|
15837
|
+
const _flushing = Symbol('_flushing')
|
|
15838
|
+
class Flush extends Minipass {
|
|
15839
|
+
constructor(opt = {}) {
|
|
15840
|
+
if (typeof opt === 'function') {
|
|
15841
|
+
opt = {
|
|
15842
|
+
flush: opt
|
|
17296
15843
|
}
|
|
17297
|
-
const ondestroy = () => onerr(new Error('stream destroyed'))
|
|
17298
|
-
return new Promise((res, rej) => {
|
|
17299
|
-
reject = rej
|
|
17300
|
-
resolve = res
|
|
17301
|
-
this.once(DESTROYED, ondestroy)
|
|
17302
|
-
this.once('error', onerr)
|
|
17303
|
-
this.once('end', onend)
|
|
17304
|
-
this.once('data', ondata)
|
|
17305
|
-
})
|
|
17306
15844
|
}
|
|
17307
|
-
|
|
17308
|
-
|
|
15845
|
+
super(opt)
|
|
15846
|
+
|
|
15847
|
+
// or extend this class and provide a 'flush' method in your subclass
|
|
15848
|
+
if (typeof opt.flush !== 'function' && typeof this.flush !== 'function') {
|
|
15849
|
+
throw new TypeError('must provide flush function in options')
|
|
15850
|
+
}
|
|
15851
|
+
this[_flush] = opt.flush || this.flush
|
|
15852
|
+
}
|
|
15853
|
+
emit(ev, ...data) {
|
|
15854
|
+
if ((ev !== 'end' && ev !== 'finish') || this[_flushed]) {
|
|
15855
|
+
return super.emit(ev, ...data)
|
|
15856
|
+
}
|
|
15857
|
+
if (this[_flushing]) {
|
|
15858
|
+
return
|
|
15859
|
+
}
|
|
15860
|
+
this[_flushing] = true
|
|
15861
|
+
const afterFlush = er => {
|
|
15862
|
+
this[_flushed] = true
|
|
15863
|
+
er ? super.emit('error', er) : super.emit('end')
|
|
15864
|
+
}
|
|
15865
|
+
const ret = this[_flush](afterFlush)
|
|
15866
|
+
if (ret && ret.then) {
|
|
15867
|
+
ret.then(
|
|
15868
|
+
() => afterFlush(),
|
|
15869
|
+
er => afterFlush(er)
|
|
15870
|
+
)
|
|
17309
15871
|
}
|
|
17310
15872
|
}
|
|
15873
|
+
}
|
|
15874
|
+
minipassFlush = Flush
|
|
15875
|
+
return minipassFlush
|
|
15876
|
+
}
|
|
17311
15877
|
|
|
17312
|
-
|
|
17313
|
-
|
|
17314
|
-
|
|
17315
|
-
|
|
17316
|
-
|
|
17317
|
-
|
|
17318
|
-
|
|
17319
|
-
|
|
17320
|
-
|
|
15878
|
+
const lib$6 = { exports: {} }
|
|
15879
|
+
|
|
15880
|
+
const get = { exports: {} }
|
|
15881
|
+
|
|
15882
|
+
const minipassCollect = { exports: {} }
|
|
15883
|
+
|
|
15884
|
+
let hasRequiredMinipassCollect
|
|
15885
|
+
function requireMinipassCollect() {
|
|
15886
|
+
if (hasRequiredMinipassCollect) {
|
|
15887
|
+
return minipassCollect.exports
|
|
15888
|
+
}
|
|
15889
|
+
hasRequiredMinipassCollect = 1
|
|
15890
|
+
const { Minipass } = requireCommonjs$5()
|
|
15891
|
+
const _data = Symbol('_data')
|
|
15892
|
+
const _length = Symbol('_length')
|
|
15893
|
+
class Collect extends Minipass {
|
|
15894
|
+
constructor(options) {
|
|
15895
|
+
super(options)
|
|
15896
|
+
this[_data] = []
|
|
15897
|
+
this[_length] = 0
|
|
15898
|
+
}
|
|
15899
|
+
write(chunk, encoding, cb) {
|
|
15900
|
+
if (typeof encoding === 'function') {
|
|
15901
|
+
;(cb = encoding), (encoding = 'utf8')
|
|
17321
15902
|
}
|
|
17322
|
-
|
|
17323
|
-
|
|
15903
|
+
if (!encoding) {
|
|
15904
|
+
encoding = 'utf8'
|
|
15905
|
+
}
|
|
15906
|
+
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding)
|
|
15907
|
+
this[_data].push(c)
|
|
15908
|
+
this[_length] += c.length
|
|
15909
|
+
if (cb) {
|
|
15910
|
+
cb()
|
|
17324
15911
|
}
|
|
15912
|
+
return true
|
|
17325
15913
|
}
|
|
17326
|
-
|
|
17327
|
-
if (
|
|
17328
|
-
|
|
17329
|
-
this.emit('error', er)
|
|
17330
|
-
} else {
|
|
17331
|
-
this.emit(DESTROYED)
|
|
17332
|
-
}
|
|
17333
|
-
return this
|
|
15914
|
+
end(chunk, encoding, cb) {
|
|
15915
|
+
if (typeof chunk === 'function') {
|
|
15916
|
+
;(cb = chunk), (chunk = null)
|
|
17334
15917
|
}
|
|
17335
|
-
|
|
17336
|
-
|
|
17337
|
-
// throw away all buffered data, it's never coming out
|
|
17338
|
-
this.buffer.length = 0
|
|
17339
|
-
this[BUFFERLENGTH] = 0
|
|
17340
|
-
if (typeof this.close === 'function' && !this[CLOSED]) {
|
|
17341
|
-
this.close()
|
|
15918
|
+
if (typeof encoding === 'function') {
|
|
15919
|
+
;(cb = encoding), (encoding = 'utf8')
|
|
17342
15920
|
}
|
|
17343
|
-
if (
|
|
17344
|
-
this.
|
|
15921
|
+
if (chunk) {
|
|
15922
|
+
this.write(chunk, encoding)
|
|
17345
15923
|
}
|
|
17346
|
-
|
|
17347
|
-
|
|
17348
|
-
|
|
15924
|
+
const result = Buffer.concat(this[_data], this[_length])
|
|
15925
|
+
super.write(result)
|
|
15926
|
+
return super.end(cb)
|
|
15927
|
+
}
|
|
15928
|
+
}
|
|
15929
|
+
minipassCollect.exports = Collect
|
|
15930
|
+
|
|
15931
|
+
// it would be possible to DRY this a bit by doing something like
|
|
15932
|
+
// this.collector = new Collect() and listening on its data event,
|
|
15933
|
+
// but it's not much code, and we may as well save the extra obj
|
|
15934
|
+
class CollectPassThrough extends Minipass {
|
|
15935
|
+
constructor(options) {
|
|
15936
|
+
super(options)
|
|
15937
|
+
this[_data] = []
|
|
15938
|
+
this[_length] = 0
|
|
15939
|
+
}
|
|
15940
|
+
write(chunk, encoding, cb) {
|
|
15941
|
+
if (typeof encoding === 'function') {
|
|
15942
|
+
;(cb = encoding), (encoding = 'utf8')
|
|
17349
15943
|
}
|
|
17350
|
-
|
|
15944
|
+
if (!encoding) {
|
|
15945
|
+
encoding = 'utf8'
|
|
15946
|
+
}
|
|
15947
|
+
const c = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk, encoding)
|
|
15948
|
+
this[_data].push(c)
|
|
15949
|
+
this[_length] += c.length
|
|
15950
|
+
return super.write(chunk, encoding, cb)
|
|
17351
15951
|
}
|
|
17352
|
-
|
|
17353
|
-
|
|
17354
|
-
|
|
17355
|
-
|
|
17356
|
-
|
|
17357
|
-
|
|
17358
|
-
|
|
17359
|
-
|
|
17360
|
-
|
|
17361
|
-
|
|
15952
|
+
end(chunk, encoding, cb) {
|
|
15953
|
+
if (typeof chunk === 'function') {
|
|
15954
|
+
;(cb = chunk), (chunk = null)
|
|
15955
|
+
}
|
|
15956
|
+
if (typeof encoding === 'function') {
|
|
15957
|
+
;(cb = encoding), (encoding = 'utf8')
|
|
15958
|
+
}
|
|
15959
|
+
if (chunk) {
|
|
15960
|
+
this.write(chunk, encoding)
|
|
15961
|
+
}
|
|
15962
|
+
const result = Buffer.concat(this[_data], this[_length])
|
|
15963
|
+
this.emit('collect', result)
|
|
15964
|
+
return super.end(cb)
|
|
17362
15965
|
}
|
|
17363
15966
|
}
|
|
17364
|
-
|
|
15967
|
+
minipassCollect.exports.PassThrough = CollectPassThrough
|
|
15968
|
+
return minipassCollect.exports
|
|
17365
15969
|
}
|
|
17366
15970
|
|
|
17367
15971
|
let minipassPipeline
|
|
@@ -35368,7 +33972,11 @@ function requireCommon() {
|
|
|
35368
33972
|
Object.defineProperty(common, '__esModule', {
|
|
35369
33973
|
value: true
|
|
35370
33974
|
})
|
|
35371
|
-
common.
|
|
33975
|
+
common.isInSubnet = isInSubnet
|
|
33976
|
+
common.isCorrect = isCorrect
|
|
33977
|
+
common.numberToPaddedHex = numberToPaddedHex
|
|
33978
|
+
common.stringToPaddedHex = stringToPaddedHex
|
|
33979
|
+
common.testBit = testBit
|
|
35372
33980
|
function isInSubnet(address) {
|
|
35373
33981
|
if (this.subnetMask < address.subnetMask) {
|
|
35374
33982
|
return false
|
|
@@ -35378,7 +33986,6 @@ function requireCommon() {
|
|
|
35378
33986
|
}
|
|
35379
33987
|
return false
|
|
35380
33988
|
}
|
|
35381
|
-
common.isInSubnet = isInSubnet
|
|
35382
33989
|
function isCorrect(defaultBits) {
|
|
35383
33990
|
return function () {
|
|
35384
33991
|
if (this.addressMinusSuffix !== this.correctForm()) {
|
|
@@ -35390,7 +33997,24 @@ function requireCommon() {
|
|
|
35390
33997
|
return this.parsedSubnet === String(this.subnetMask)
|
|
35391
33998
|
}
|
|
35392
33999
|
}
|
|
35393
|
-
|
|
34000
|
+
function numberToPaddedHex(number) {
|
|
34001
|
+
return number.toString(16).padStart(2, '0')
|
|
34002
|
+
}
|
|
34003
|
+
function stringToPaddedHex(numberString) {
|
|
34004
|
+
return numberToPaddedHex(parseInt(numberString, 10))
|
|
34005
|
+
}
|
|
34006
|
+
/**
|
|
34007
|
+
* @param binaryValue Binary representation of a value (e.g. `10`)
|
|
34008
|
+
* @param position Byte position, where 0 is the least significant bit
|
|
34009
|
+
*/
|
|
34010
|
+
function testBit(binaryValue, position) {
|
|
34011
|
+
const { length } = binaryValue
|
|
34012
|
+
if (position > length) {
|
|
34013
|
+
return false
|
|
34014
|
+
}
|
|
34015
|
+
const positionInString = length - position
|
|
34016
|
+
return binaryValue.substring(positionInString, positionInString + 1) === '1'
|
|
34017
|
+
}
|
|
35394
34018
|
return common
|
|
35395
34019
|
}
|
|
35396
34020
|
|
|
@@ -35434,2213 +34058,13 @@ function requireAddressError() {
|
|
|
35434
34058
|
constructor(message, parseMessage) {
|
|
35435
34059
|
super(message)
|
|
35436
34060
|
this.name = 'AddressError'
|
|
35437
|
-
|
|
35438
|
-
this.parseMessage = parseMessage
|
|
35439
|
-
}
|
|
34061
|
+
this.parseMessage = parseMessage
|
|
35440
34062
|
}
|
|
35441
34063
|
}
|
|
35442
34064
|
addressError.AddressError = AddressError
|
|
35443
34065
|
return addressError
|
|
35444
34066
|
}
|
|
35445
34067
|
|
|
35446
|
-
const jsbn = { exports: {} }
|
|
35447
|
-
|
|
35448
|
-
let hasRequiredJsbn
|
|
35449
|
-
function requireJsbn() {
|
|
35450
|
-
if (hasRequiredJsbn) {
|
|
35451
|
-
return jsbn.exports
|
|
35452
|
-
}
|
|
35453
|
-
hasRequiredJsbn = 1
|
|
35454
|
-
;(function (module, exports) {
|
|
35455
|
-
;(function () {
|
|
35456
|
-
// Copyright (c) 2005 Tom Wu
|
|
35457
|
-
// All Rights Reserved.
|
|
35458
|
-
// See "LICENSE" for details.
|
|
35459
|
-
|
|
35460
|
-
// Basic JavaScript BN library - subset useful for RSA encryption.
|
|
35461
|
-
|
|
35462
|
-
// Bits per digit
|
|
35463
|
-
let dbits
|
|
35464
|
-
|
|
35465
|
-
// JavaScript engine analysis
|
|
35466
|
-
const canary = 0xdeadbeefcafe
|
|
35467
|
-
const j_lm = (canary & 0xffffff) == 0xefcafe
|
|
35468
|
-
|
|
35469
|
-
// (public) Constructor
|
|
35470
|
-
function BigInteger(a, b, c) {
|
|
35471
|
-
if (a != null) {
|
|
35472
|
-
if ('number' == typeof a) this.fromNumber(a, b, c)
|
|
35473
|
-
else if (b == null && 'string' != typeof a) this.fromString(a, 256)
|
|
35474
|
-
else this.fromString(a, b)
|
|
35475
|
-
}
|
|
35476
|
-
}
|
|
35477
|
-
|
|
35478
|
-
// return new, unset BigInteger
|
|
35479
|
-
function nbi() {
|
|
35480
|
-
return new BigInteger(null)
|
|
35481
|
-
}
|
|
35482
|
-
|
|
35483
|
-
// am: Compute w_j += (x*this_i), propagate carries,
|
|
35484
|
-
// c is initial carry, returns final carry.
|
|
35485
|
-
// c < 3*dvalue, x < 2*dvalue, this_i < dvalue
|
|
35486
|
-
// We need to select the fastest one that works in this environment.
|
|
35487
|
-
|
|
35488
|
-
// am1: use a single mult and divide to get the high bits,
|
|
35489
|
-
// max digit bits should be 26 because
|
|
35490
|
-
// max internal value = 2*dvalue^2-2*dvalue (< 2^53)
|
|
35491
|
-
function am1(i, x, w, j, c, n) {
|
|
35492
|
-
while (--n >= 0) {
|
|
35493
|
-
const v = x * this[i++] + w[j] + c
|
|
35494
|
-
c = Math.floor(v / 0x4000000)
|
|
35495
|
-
w[j++] = v & 0x3ffffff
|
|
35496
|
-
}
|
|
35497
|
-
return c
|
|
35498
|
-
}
|
|
35499
|
-
// am2 avoids a big mult-and-extract completely.
|
|
35500
|
-
// Max digit bits should be <= 30 because we do bitwise ops
|
|
35501
|
-
// on values up to 2*hdvalue^2-hdvalue-1 (< 2^31)
|
|
35502
|
-
function am2(i, x, w, j, c, n) {
|
|
35503
|
-
const xl = x & 0x7fff,
|
|
35504
|
-
xh = x >> 15
|
|
35505
|
-
while (--n >= 0) {
|
|
35506
|
-
let l = this[i] & 0x7fff
|
|
35507
|
-
const h = this[i++] >> 15
|
|
35508
|
-
const m = xh * l + h * xl
|
|
35509
|
-
l = xl * l + ((m & 0x7fff) << 15) + w[j] + (c & 0x3fffffff)
|
|
35510
|
-
c = (l >>> 30) + (m >>> 15) + xh * h + (c >>> 30)
|
|
35511
|
-
w[j++] = l & 0x3fffffff
|
|
35512
|
-
}
|
|
35513
|
-
return c
|
|
35514
|
-
}
|
|
35515
|
-
// Alternately, set max digit bits to 28 since some
|
|
35516
|
-
// browsers slow down when dealing with 32-bit numbers.
|
|
35517
|
-
function am3(i, x, w, j, c, n) {
|
|
35518
|
-
const xl = x & 0x3fff,
|
|
35519
|
-
xh = x >> 14
|
|
35520
|
-
while (--n >= 0) {
|
|
35521
|
-
let l = this[i] & 0x3fff
|
|
35522
|
-
const h = this[i++] >> 14
|
|
35523
|
-
const m = xh * l + h * xl
|
|
35524
|
-
l = xl * l + ((m & 0x3fff) << 14) + w[j] + c
|
|
35525
|
-
c = (l >> 28) + (m >> 14) + xh * h
|
|
35526
|
-
w[j++] = l & 0xfffffff
|
|
35527
|
-
}
|
|
35528
|
-
return c
|
|
35529
|
-
}
|
|
35530
|
-
const inBrowser = typeof navigator !== 'undefined'
|
|
35531
|
-
if (
|
|
35532
|
-
inBrowser &&
|
|
35533
|
-
j_lm &&
|
|
35534
|
-
navigator.appName == 'Microsoft Internet Explorer'
|
|
35535
|
-
) {
|
|
35536
|
-
BigInteger.prototype.am = am2
|
|
35537
|
-
dbits = 30
|
|
35538
|
-
} else if (inBrowser && j_lm && navigator.appName != 'Netscape') {
|
|
35539
|
-
BigInteger.prototype.am = am1
|
|
35540
|
-
dbits = 26
|
|
35541
|
-
} else {
|
|
35542
|
-
// Mozilla/Netscape seems to prefer am3
|
|
35543
|
-
BigInteger.prototype.am = am3
|
|
35544
|
-
dbits = 28
|
|
35545
|
-
}
|
|
35546
|
-
BigInteger.prototype.DB = dbits
|
|
35547
|
-
BigInteger.prototype.DM = (1 << dbits) - 1
|
|
35548
|
-
BigInteger.prototype.DV = 1 << dbits
|
|
35549
|
-
const BI_FP = 52
|
|
35550
|
-
BigInteger.prototype.FV = Math.pow(2, BI_FP)
|
|
35551
|
-
BigInteger.prototype.F1 = BI_FP - dbits
|
|
35552
|
-
BigInteger.prototype.F2 = 2 * dbits - BI_FP
|
|
35553
|
-
|
|
35554
|
-
// Digit conversions
|
|
35555
|
-
const BI_RM = '0123456789abcdefghijklmnopqrstuvwxyz'
|
|
35556
|
-
const BI_RC = new Array()
|
|
35557
|
-
let rr, vv
|
|
35558
|
-
rr = '0'.charCodeAt(0)
|
|
35559
|
-
for (vv = 0; vv <= 9; ++vv) {
|
|
35560
|
-
BI_RC[rr++] = vv
|
|
35561
|
-
}
|
|
35562
|
-
rr = 'a'.charCodeAt(0)
|
|
35563
|
-
for (vv = 10; vv < 36; ++vv) {
|
|
35564
|
-
BI_RC[rr++] = vv
|
|
35565
|
-
}
|
|
35566
|
-
rr = 'A'.charCodeAt(0)
|
|
35567
|
-
for (vv = 10; vv < 36; ++vv) {
|
|
35568
|
-
BI_RC[rr++] = vv
|
|
35569
|
-
}
|
|
35570
|
-
function int2char(n) {
|
|
35571
|
-
return BI_RM.charAt(n)
|
|
35572
|
-
}
|
|
35573
|
-
function intAt(s, i) {
|
|
35574
|
-
const c = BI_RC[s.charCodeAt(i)]
|
|
35575
|
-
return c == null ? -1 : c
|
|
35576
|
-
}
|
|
35577
|
-
|
|
35578
|
-
// (protected) copy this to r
|
|
35579
|
-
function bnpCopyTo(r) {
|
|
35580
|
-
for (let i = this.t - 1; i >= 0; --i) {
|
|
35581
|
-
r[i] = this[i]
|
|
35582
|
-
}
|
|
35583
|
-
r.t = this.t
|
|
35584
|
-
r.s = this.s
|
|
35585
|
-
}
|
|
35586
|
-
|
|
35587
|
-
// (protected) set from integer value x, -DV <= x < DV
|
|
35588
|
-
function bnpFromInt(x) {
|
|
35589
|
-
this.t = 1
|
|
35590
|
-
this.s = x < 0 ? -1 : 0
|
|
35591
|
-
if (x > 0) {
|
|
35592
|
-
this[0] = x
|
|
35593
|
-
} else if (x < -1) {
|
|
35594
|
-
this[0] = x + this.DV
|
|
35595
|
-
} else {
|
|
35596
|
-
this.t = 0
|
|
35597
|
-
}
|
|
35598
|
-
}
|
|
35599
|
-
|
|
35600
|
-
// return bigint initialized to value
|
|
35601
|
-
function nbv(i) {
|
|
35602
|
-
const r = nbi()
|
|
35603
|
-
r.fromInt(i)
|
|
35604
|
-
return r
|
|
35605
|
-
}
|
|
35606
|
-
|
|
35607
|
-
// (protected) set from string and radix
|
|
35608
|
-
function bnpFromString(s, b) {
|
|
35609
|
-
let k
|
|
35610
|
-
if (b == 16) {
|
|
35611
|
-
k = 4
|
|
35612
|
-
} else if (b == 8) {
|
|
35613
|
-
k = 3
|
|
35614
|
-
} else if (b == 256) {
|
|
35615
|
-
k = 8
|
|
35616
|
-
} // byte array
|
|
35617
|
-
else if (b == 2) {
|
|
35618
|
-
k = 1
|
|
35619
|
-
} else if (b == 32) {
|
|
35620
|
-
k = 5
|
|
35621
|
-
} else if (b == 4) {
|
|
35622
|
-
k = 2
|
|
35623
|
-
} else {
|
|
35624
|
-
this.fromRadix(s, b)
|
|
35625
|
-
return
|
|
35626
|
-
}
|
|
35627
|
-
this.t = 0
|
|
35628
|
-
this.s = 0
|
|
35629
|
-
let i = s.length,
|
|
35630
|
-
mi = false,
|
|
35631
|
-
sh = 0
|
|
35632
|
-
while (--i >= 0) {
|
|
35633
|
-
const x = k == 8 ? s[i] & 0xff : intAt(s, i)
|
|
35634
|
-
if (x < 0) {
|
|
35635
|
-
if (s.charAt(i) == '-') {
|
|
35636
|
-
mi = true
|
|
35637
|
-
}
|
|
35638
|
-
continue
|
|
35639
|
-
}
|
|
35640
|
-
mi = false
|
|
35641
|
-
if (sh == 0) {
|
|
35642
|
-
this[this.t++] = x
|
|
35643
|
-
} else if (sh + k > this.DB) {
|
|
35644
|
-
this[this.t - 1] |= (x & ((1 << (this.DB - sh)) - 1)) << sh
|
|
35645
|
-
this[this.t++] = x >> (this.DB - sh)
|
|
35646
|
-
} else {
|
|
35647
|
-
this[this.t - 1] |= x << sh
|
|
35648
|
-
}
|
|
35649
|
-
sh += k
|
|
35650
|
-
if (sh >= this.DB) {
|
|
35651
|
-
sh -= this.DB
|
|
35652
|
-
}
|
|
35653
|
-
}
|
|
35654
|
-
if (k == 8 && (s[0] & 0x80) != 0) {
|
|
35655
|
-
this.s = -1
|
|
35656
|
-
if (sh > 0) {
|
|
35657
|
-
this[this.t - 1] |= ((1 << (this.DB - sh)) - 1) << sh
|
|
35658
|
-
}
|
|
35659
|
-
}
|
|
35660
|
-
this.clamp()
|
|
35661
|
-
if (mi) {
|
|
35662
|
-
BigInteger.ZERO.subTo(this, this)
|
|
35663
|
-
}
|
|
35664
|
-
}
|
|
35665
|
-
|
|
35666
|
-
// (protected) clamp off excess high words
|
|
35667
|
-
function bnpClamp() {
|
|
35668
|
-
const c = this.s & this.DM
|
|
35669
|
-
while (this.t > 0 && this[this.t - 1] == c) {
|
|
35670
|
-
--this.t
|
|
35671
|
-
}
|
|
35672
|
-
}
|
|
35673
|
-
|
|
35674
|
-
// (public) return string representation in given radix
|
|
35675
|
-
function bnToString(b) {
|
|
35676
|
-
if (this.s < 0) {
|
|
35677
|
-
return '-' + this.negate().toString(b)
|
|
35678
|
-
}
|
|
35679
|
-
let k
|
|
35680
|
-
if (b == 16) {
|
|
35681
|
-
k = 4
|
|
35682
|
-
} else if (b == 8) {
|
|
35683
|
-
k = 3
|
|
35684
|
-
} else if (b == 2) {
|
|
35685
|
-
k = 1
|
|
35686
|
-
} else if (b == 32) {
|
|
35687
|
-
k = 5
|
|
35688
|
-
} else if (b == 4) {
|
|
35689
|
-
k = 2
|
|
35690
|
-
} else {
|
|
35691
|
-
return this.toRadix(b)
|
|
35692
|
-
}
|
|
35693
|
-
let km = (1 << k) - 1,
|
|
35694
|
-
d,
|
|
35695
|
-
m = false,
|
|
35696
|
-
r = '',
|
|
35697
|
-
i = this.t
|
|
35698
|
-
let p = this.DB - ((i * this.DB) % k)
|
|
35699
|
-
if (i-- > 0) {
|
|
35700
|
-
if (p < this.DB && (d = this[i] >> p) > 0) {
|
|
35701
|
-
m = true
|
|
35702
|
-
r = int2char(d)
|
|
35703
|
-
}
|
|
35704
|
-
while (i >= 0) {
|
|
35705
|
-
if (p < k) {
|
|
35706
|
-
d = (this[i] & ((1 << p) - 1)) << (k - p)
|
|
35707
|
-
d |= this[--i] >> (p += this.DB - k)
|
|
35708
|
-
} else {
|
|
35709
|
-
d = (this[i] >> (p -= k)) & km
|
|
35710
|
-
if (p <= 0) {
|
|
35711
|
-
p += this.DB
|
|
35712
|
-
--i
|
|
35713
|
-
}
|
|
35714
|
-
}
|
|
35715
|
-
if (d > 0) {
|
|
35716
|
-
m = true
|
|
35717
|
-
}
|
|
35718
|
-
if (m) {
|
|
35719
|
-
r += int2char(d)
|
|
35720
|
-
}
|
|
35721
|
-
}
|
|
35722
|
-
}
|
|
35723
|
-
return m ? r : '0'
|
|
35724
|
-
}
|
|
35725
|
-
|
|
35726
|
-
// (public) -this
|
|
35727
|
-
function bnNegate() {
|
|
35728
|
-
const r = nbi()
|
|
35729
|
-
BigInteger.ZERO.subTo(this, r)
|
|
35730
|
-
return r
|
|
35731
|
-
}
|
|
35732
|
-
|
|
35733
|
-
// (public) |this|
|
|
35734
|
-
function bnAbs() {
|
|
35735
|
-
return this.s < 0 ? this.negate() : this
|
|
35736
|
-
}
|
|
35737
|
-
|
|
35738
|
-
// (public) return + if this > a, - if this < a, 0 if equal
|
|
35739
|
-
function bnCompareTo(a) {
|
|
35740
|
-
let r = this.s - a.s
|
|
35741
|
-
if (r != 0) {
|
|
35742
|
-
return r
|
|
35743
|
-
}
|
|
35744
|
-
let i = this.t
|
|
35745
|
-
r = i - a.t
|
|
35746
|
-
if (r != 0) {
|
|
35747
|
-
return this.s < 0 ? -r : r
|
|
35748
|
-
}
|
|
35749
|
-
while (--i >= 0) {
|
|
35750
|
-
if ((r = this[i] - a[i]) != 0) return r
|
|
35751
|
-
}
|
|
35752
|
-
return 0
|
|
35753
|
-
}
|
|
35754
|
-
|
|
35755
|
-
// returns bit length of the integer x
|
|
35756
|
-
function nbits(x) {
|
|
35757
|
-
let r = 1,
|
|
35758
|
-
t
|
|
35759
|
-
if ((t = x >>> 16) != 0) {
|
|
35760
|
-
x = t
|
|
35761
|
-
r += 16
|
|
35762
|
-
}
|
|
35763
|
-
if ((t = x >> 8) != 0) {
|
|
35764
|
-
x = t
|
|
35765
|
-
r += 8
|
|
35766
|
-
}
|
|
35767
|
-
if ((t = x >> 4) != 0) {
|
|
35768
|
-
x = t
|
|
35769
|
-
r += 4
|
|
35770
|
-
}
|
|
35771
|
-
if ((t = x >> 2) != 0) {
|
|
35772
|
-
x = t
|
|
35773
|
-
r += 2
|
|
35774
|
-
}
|
|
35775
|
-
if ((t = x >> 1) != 0) {
|
|
35776
|
-
x = t
|
|
35777
|
-
r += 1
|
|
35778
|
-
}
|
|
35779
|
-
return r
|
|
35780
|
-
}
|
|
35781
|
-
|
|
35782
|
-
// (public) return the number of bits in "this"
|
|
35783
|
-
function bnBitLength() {
|
|
35784
|
-
if (this.t <= 0) {
|
|
35785
|
-
return 0
|
|
35786
|
-
}
|
|
35787
|
-
return (
|
|
35788
|
-
this.DB * (this.t - 1) + nbits(this[this.t - 1] ^ (this.s & this.DM))
|
|
35789
|
-
)
|
|
35790
|
-
}
|
|
35791
|
-
|
|
35792
|
-
// (protected) r = this << n*DB
|
|
35793
|
-
function bnpDLShiftTo(n, r) {
|
|
35794
|
-
let i
|
|
35795
|
-
for (i = this.t - 1; i >= 0; --i) {
|
|
35796
|
-
r[i + n] = this[i]
|
|
35797
|
-
}
|
|
35798
|
-
for (i = n - 1; i >= 0; --i) {
|
|
35799
|
-
r[i] = 0
|
|
35800
|
-
}
|
|
35801
|
-
r.t = this.t + n
|
|
35802
|
-
r.s = this.s
|
|
35803
|
-
}
|
|
35804
|
-
|
|
35805
|
-
// (protected) r = this >> n*DB
|
|
35806
|
-
function bnpDRShiftTo(n, r) {
|
|
35807
|
-
for (let i = n; i < this.t; ++i) {
|
|
35808
|
-
r[i - n] = this[i]
|
|
35809
|
-
}
|
|
35810
|
-
r.t = Math.max(this.t - n, 0)
|
|
35811
|
-
r.s = this.s
|
|
35812
|
-
}
|
|
35813
|
-
|
|
35814
|
-
// (protected) r = this << n
|
|
35815
|
-
function bnpLShiftTo(n, r) {
|
|
35816
|
-
const bs = n % this.DB
|
|
35817
|
-
const cbs = this.DB - bs
|
|
35818
|
-
const bm = (1 << cbs) - 1
|
|
35819
|
-
let ds = Math.floor(n / this.DB),
|
|
35820
|
-
c = (this.s << bs) & this.DM,
|
|
35821
|
-
i
|
|
35822
|
-
for (i = this.t - 1; i >= 0; --i) {
|
|
35823
|
-
r[i + ds + 1] = (this[i] >> cbs) | c
|
|
35824
|
-
c = (this[i] & bm) << bs
|
|
35825
|
-
}
|
|
35826
|
-
for (i = ds - 1; i >= 0; --i) {
|
|
35827
|
-
r[i] = 0
|
|
35828
|
-
}
|
|
35829
|
-
r[ds] = c
|
|
35830
|
-
r.t = this.t + ds + 1
|
|
35831
|
-
r.s = this.s
|
|
35832
|
-
r.clamp()
|
|
35833
|
-
}
|
|
35834
|
-
|
|
35835
|
-
// (protected) r = this >> n
|
|
35836
|
-
function bnpRShiftTo(n, r) {
|
|
35837
|
-
r.s = this.s
|
|
35838
|
-
const ds = Math.floor(n / this.DB)
|
|
35839
|
-
if (ds >= this.t) {
|
|
35840
|
-
r.t = 0
|
|
35841
|
-
return
|
|
35842
|
-
}
|
|
35843
|
-
const bs = n % this.DB
|
|
35844
|
-
const cbs = this.DB - bs
|
|
35845
|
-
const bm = (1 << bs) - 1
|
|
35846
|
-
r[0] = this[ds] >> bs
|
|
35847
|
-
for (let i = ds + 1; i < this.t; ++i) {
|
|
35848
|
-
r[i - ds - 1] |= (this[i] & bm) << cbs
|
|
35849
|
-
r[i - ds] = this[i] >> bs
|
|
35850
|
-
}
|
|
35851
|
-
if (bs > 0) {
|
|
35852
|
-
r[this.t - ds - 1] |= (this.s & bm) << cbs
|
|
35853
|
-
}
|
|
35854
|
-
r.t = this.t - ds
|
|
35855
|
-
r.clamp()
|
|
35856
|
-
}
|
|
35857
|
-
|
|
35858
|
-
// (protected) r = this - a
|
|
35859
|
-
function bnpSubTo(a, r) {
|
|
35860
|
-
let i = 0,
|
|
35861
|
-
c = 0,
|
|
35862
|
-
m = Math.min(a.t, this.t)
|
|
35863
|
-
while (i < m) {
|
|
35864
|
-
c += this[i] - a[i]
|
|
35865
|
-
r[i++] = c & this.DM
|
|
35866
|
-
c >>= this.DB
|
|
35867
|
-
}
|
|
35868
|
-
if (a.t < this.t) {
|
|
35869
|
-
c -= a.s
|
|
35870
|
-
while (i < this.t) {
|
|
35871
|
-
c += this[i]
|
|
35872
|
-
r[i++] = c & this.DM
|
|
35873
|
-
c >>= this.DB
|
|
35874
|
-
}
|
|
35875
|
-
c += this.s
|
|
35876
|
-
} else {
|
|
35877
|
-
c += this.s
|
|
35878
|
-
while (i < a.t) {
|
|
35879
|
-
c -= a[i]
|
|
35880
|
-
r[i++] = c & this.DM
|
|
35881
|
-
c >>= this.DB
|
|
35882
|
-
}
|
|
35883
|
-
c -= a.s
|
|
35884
|
-
}
|
|
35885
|
-
r.s = c < 0 ? -1 : 0
|
|
35886
|
-
if (c < -1) {
|
|
35887
|
-
r[i++] = this.DV + c
|
|
35888
|
-
} else if (c > 0) {
|
|
35889
|
-
r[i++] = c
|
|
35890
|
-
}
|
|
35891
|
-
r.t = i
|
|
35892
|
-
r.clamp()
|
|
35893
|
-
}
|
|
35894
|
-
|
|
35895
|
-
// (protected) r = this * a, r != this,a (HAC 14.12)
|
|
35896
|
-
// "this" should be the larger one if appropriate.
|
|
35897
|
-
function bnpMultiplyTo(a, r) {
|
|
35898
|
-
const x = this.abs(),
|
|
35899
|
-
y = a.abs()
|
|
35900
|
-
let i = x.t
|
|
35901
|
-
r.t = i + y.t
|
|
35902
|
-
while (--i >= 0) {
|
|
35903
|
-
r[i] = 0
|
|
35904
|
-
}
|
|
35905
|
-
for (i = 0; i < y.t; ++i) {
|
|
35906
|
-
r[i + x.t] = x.am(0, y[i], r, i, 0, x.t)
|
|
35907
|
-
}
|
|
35908
|
-
r.s = 0
|
|
35909
|
-
r.clamp()
|
|
35910
|
-
if (this.s != a.s) {
|
|
35911
|
-
BigInteger.ZERO.subTo(r, r)
|
|
35912
|
-
}
|
|
35913
|
-
}
|
|
35914
|
-
|
|
35915
|
-
// (protected) r = this^2, r != this (HAC 14.16)
|
|
35916
|
-
function bnpSquareTo(r) {
|
|
35917
|
-
const x = this.abs()
|
|
35918
|
-
let i = (r.t = 2 * x.t)
|
|
35919
|
-
while (--i >= 0) {
|
|
35920
|
-
r[i] = 0
|
|
35921
|
-
}
|
|
35922
|
-
for (i = 0; i < x.t - 1; ++i) {
|
|
35923
|
-
const c = x.am(i, x[i], r, 2 * i, 0, 1)
|
|
35924
|
-
if (
|
|
35925
|
-
(r[i + x.t] += x.am(
|
|
35926
|
-
i + 1,
|
|
35927
|
-
2 * x[i],
|
|
35928
|
-
r,
|
|
35929
|
-
2 * i + 1,
|
|
35930
|
-
c,
|
|
35931
|
-
x.t - i - 1
|
|
35932
|
-
)) >= x.DV
|
|
35933
|
-
) {
|
|
35934
|
-
r[i + x.t] -= x.DV
|
|
35935
|
-
r[i + x.t + 1] = 1
|
|
35936
|
-
}
|
|
35937
|
-
}
|
|
35938
|
-
if (r.t > 0) {
|
|
35939
|
-
r[r.t - 1] += x.am(i, x[i], r, 2 * i, 0, 1)
|
|
35940
|
-
}
|
|
35941
|
-
r.s = 0
|
|
35942
|
-
r.clamp()
|
|
35943
|
-
}
|
|
35944
|
-
|
|
35945
|
-
// (protected) divide this by m, quotient and remainder to q, r (HAC 14.20)
|
|
35946
|
-
// r != q, this != m. q or r may be null.
|
|
35947
|
-
function bnpDivRemTo(m, q, r) {
|
|
35948
|
-
const pm = m.abs()
|
|
35949
|
-
if (pm.t <= 0) {
|
|
35950
|
-
return
|
|
35951
|
-
}
|
|
35952
|
-
const pt = this.abs()
|
|
35953
|
-
if (pt.t < pm.t) {
|
|
35954
|
-
if (q != null) {
|
|
35955
|
-
q.fromInt(0)
|
|
35956
|
-
}
|
|
35957
|
-
if (r != null) {
|
|
35958
|
-
this.copyTo(r)
|
|
35959
|
-
}
|
|
35960
|
-
return
|
|
35961
|
-
}
|
|
35962
|
-
if (r == null) {
|
|
35963
|
-
r = nbi()
|
|
35964
|
-
}
|
|
35965
|
-
const y = nbi(),
|
|
35966
|
-
ts = this.s,
|
|
35967
|
-
ms = m.s
|
|
35968
|
-
const nsh = this.DB - nbits(pm[pm.t - 1]) // normalize modulus
|
|
35969
|
-
if (nsh > 0) {
|
|
35970
|
-
pm.lShiftTo(nsh, y)
|
|
35971
|
-
pt.lShiftTo(nsh, r)
|
|
35972
|
-
} else {
|
|
35973
|
-
pm.copyTo(y)
|
|
35974
|
-
pt.copyTo(r)
|
|
35975
|
-
}
|
|
35976
|
-
const ys = y.t
|
|
35977
|
-
const y0 = y[ys - 1]
|
|
35978
|
-
if (y0 == 0) {
|
|
35979
|
-
return
|
|
35980
|
-
}
|
|
35981
|
-
const yt = y0 * (1 << this.F1) + (ys > 1 ? y[ys - 2] >> this.F2 : 0)
|
|
35982
|
-
const d1 = this.FV / yt,
|
|
35983
|
-
d2 = (1 << this.F1) / yt,
|
|
35984
|
-
e = 1 << this.F2
|
|
35985
|
-
let i = r.t,
|
|
35986
|
-
j = i - ys,
|
|
35987
|
-
t = q == null ? nbi() : q
|
|
35988
|
-
y.dlShiftTo(j, t)
|
|
35989
|
-
if (r.compareTo(t) >= 0) {
|
|
35990
|
-
r[r.t++] = 1
|
|
35991
|
-
r.subTo(t, r)
|
|
35992
|
-
}
|
|
35993
|
-
BigInteger.ONE.dlShiftTo(ys, t)
|
|
35994
|
-
t.subTo(y, y) // "negative" y so we can replace sub with am later
|
|
35995
|
-
while (y.t < ys) {
|
|
35996
|
-
y[y.t++] = 0
|
|
35997
|
-
}
|
|
35998
|
-
while (--j >= 0) {
|
|
35999
|
-
// Estimate quotient digit
|
|
36000
|
-
let qd =
|
|
36001
|
-
r[--i] == y0 ? this.DM : Math.floor(r[i] * d1 + (r[i - 1] + e) * d2)
|
|
36002
|
-
if ((r[i] += y.am(0, qd, r, j, 0, ys)) < qd) {
|
|
36003
|
-
// Try it out
|
|
36004
|
-
y.dlShiftTo(j, t)
|
|
36005
|
-
r.subTo(t, r)
|
|
36006
|
-
while (r[i] < --qd) {
|
|
36007
|
-
r.subTo(t, r)
|
|
36008
|
-
}
|
|
36009
|
-
}
|
|
36010
|
-
}
|
|
36011
|
-
if (q != null) {
|
|
36012
|
-
r.drShiftTo(ys, q)
|
|
36013
|
-
if (ts != ms) {
|
|
36014
|
-
BigInteger.ZERO.subTo(q, q)
|
|
36015
|
-
}
|
|
36016
|
-
}
|
|
36017
|
-
r.t = ys
|
|
36018
|
-
r.clamp()
|
|
36019
|
-
if (nsh > 0) {
|
|
36020
|
-
r.rShiftTo(nsh, r)
|
|
36021
|
-
} // Denormalize remainder
|
|
36022
|
-
if (ts < 0) {
|
|
36023
|
-
BigInteger.ZERO.subTo(r, r)
|
|
36024
|
-
}
|
|
36025
|
-
}
|
|
36026
|
-
|
|
36027
|
-
// (public) this mod a
|
|
36028
|
-
function bnMod(a) {
|
|
36029
|
-
const r = nbi()
|
|
36030
|
-
this.abs().divRemTo(a, null, r)
|
|
36031
|
-
if (this.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
|
|
36032
|
-
a.subTo(r, r)
|
|
36033
|
-
}
|
|
36034
|
-
return r
|
|
36035
|
-
}
|
|
36036
|
-
|
|
36037
|
-
// Modular reduction using "classic" algorithm
|
|
36038
|
-
function Classic(m) {
|
|
36039
|
-
this.m = m
|
|
36040
|
-
}
|
|
36041
|
-
function cConvert(x) {
|
|
36042
|
-
if (x.s < 0 || x.compareTo(this.m) >= 0) {
|
|
36043
|
-
return x.mod(this.m)
|
|
36044
|
-
} else {
|
|
36045
|
-
return x
|
|
36046
|
-
}
|
|
36047
|
-
}
|
|
36048
|
-
function cRevert(x) {
|
|
36049
|
-
return x
|
|
36050
|
-
}
|
|
36051
|
-
function cReduce(x) {
|
|
36052
|
-
x.divRemTo(this.m, null, x)
|
|
36053
|
-
}
|
|
36054
|
-
function cMulTo(x, y, r) {
|
|
36055
|
-
x.multiplyTo(y, r)
|
|
36056
|
-
this.reduce(r)
|
|
36057
|
-
}
|
|
36058
|
-
function cSqrTo(x, r) {
|
|
36059
|
-
x.squareTo(r)
|
|
36060
|
-
this.reduce(r)
|
|
36061
|
-
}
|
|
36062
|
-
Classic.prototype.convert = cConvert
|
|
36063
|
-
Classic.prototype.revert = cRevert
|
|
36064
|
-
Classic.prototype.reduce = cReduce
|
|
36065
|
-
Classic.prototype.mulTo = cMulTo
|
|
36066
|
-
Classic.prototype.sqrTo = cSqrTo
|
|
36067
|
-
|
|
36068
|
-
// (protected) return "-1/this % 2^DB"; useful for Mont. reduction
|
|
36069
|
-
// justification:
|
|
36070
|
-
// xy == 1 (mod m)
|
|
36071
|
-
// xy = 1+km
|
|
36072
|
-
// xy(2-xy) = (1+km)(1-km)
|
|
36073
|
-
// x[y(2-xy)] = 1-k^2m^2
|
|
36074
|
-
// x[y(2-xy)] == 1 (mod m^2)
|
|
36075
|
-
// if y is 1/x mod m, then y(2-xy) is 1/x mod m^2
|
|
36076
|
-
// should reduce x and y(2-xy) by m^2 at each step to keep size bounded.
|
|
36077
|
-
// JS multiply "overflows" differently from C/C++, so care is needed here.
|
|
36078
|
-
function bnpInvDigit() {
|
|
36079
|
-
if (this.t < 1) {
|
|
36080
|
-
return 0
|
|
36081
|
-
}
|
|
36082
|
-
const x = this[0]
|
|
36083
|
-
if ((x & 1) == 0) {
|
|
36084
|
-
return 0
|
|
36085
|
-
}
|
|
36086
|
-
let y = x & 3 // y == 1/x mod 2^2
|
|
36087
|
-
y = (y * (2 - (x & 0xf) * y)) & 0xf // y == 1/x mod 2^4
|
|
36088
|
-
y = (y * (2 - (x & 0xff) * y)) & 0xff // y == 1/x mod 2^8
|
|
36089
|
-
y = (y * (2 - (((x & 0xffff) * y) & 0xffff))) & 0xffff // y == 1/x mod 2^16
|
|
36090
|
-
// last step - calculate inverse mod DV directly;
|
|
36091
|
-
// assumes 16 < DB <= 32 and assumes ability to handle 48-bit ints
|
|
36092
|
-
y = (y * (2 - ((x * y) % this.DV))) % this.DV // y == 1/x mod 2^dbits
|
|
36093
|
-
// we really want the negative inverse, and -DV < y < DV
|
|
36094
|
-
return y > 0 ? this.DV - y : -y
|
|
36095
|
-
}
|
|
36096
|
-
|
|
36097
|
-
// Montgomery reduction
|
|
36098
|
-
function Montgomery(m) {
|
|
36099
|
-
this.m = m
|
|
36100
|
-
this.mp = m.invDigit()
|
|
36101
|
-
this.mpl = this.mp & 0x7fff
|
|
36102
|
-
this.mph = this.mp >> 15
|
|
36103
|
-
this.um = (1 << (m.DB - 15)) - 1
|
|
36104
|
-
this.mt2 = 2 * m.t
|
|
36105
|
-
}
|
|
36106
|
-
|
|
36107
|
-
// xR mod m
|
|
36108
|
-
function montConvert(x) {
|
|
36109
|
-
const r = nbi()
|
|
36110
|
-
x.abs().dlShiftTo(this.m.t, r)
|
|
36111
|
-
r.divRemTo(this.m, null, r)
|
|
36112
|
-
if (x.s < 0 && r.compareTo(BigInteger.ZERO) > 0) {
|
|
36113
|
-
this.m.subTo(r, r)
|
|
36114
|
-
}
|
|
36115
|
-
return r
|
|
36116
|
-
}
|
|
36117
|
-
|
|
36118
|
-
// x/R mod m
|
|
36119
|
-
function montRevert(x) {
|
|
36120
|
-
const r = nbi()
|
|
36121
|
-
x.copyTo(r)
|
|
36122
|
-
this.reduce(r)
|
|
36123
|
-
return r
|
|
36124
|
-
}
|
|
36125
|
-
|
|
36126
|
-
// x = x/R mod m (HAC 14.32)
|
|
36127
|
-
function montReduce(x) {
|
|
36128
|
-
while (x.t <= this.mt2) {
|
|
36129
|
-
// pad x so am has enough room later
|
|
36130
|
-
x[x.t++] = 0
|
|
36131
|
-
}
|
|
36132
|
-
for (let i = 0; i < this.m.t; ++i) {
|
|
36133
|
-
// faster way of calculating u0 = x[i]*mp mod DV
|
|
36134
|
-
let j = x[i] & 0x7fff
|
|
36135
|
-
const u0 =
|
|
36136
|
-
(j * this.mpl +
|
|
36137
|
-
(((j * this.mph + (x[i] >> 15) * this.mpl) & this.um) << 15)) &
|
|
36138
|
-
x.DM
|
|
36139
|
-
// use am to combine the multiply-shift-add into one call
|
|
36140
|
-
j = i + this.m.t
|
|
36141
|
-
x[j] += this.m.am(0, u0, x, i, 0, this.m.t)
|
|
36142
|
-
// propagate carry
|
|
36143
|
-
while (x[j] >= x.DV) {
|
|
36144
|
-
x[j] -= x.DV
|
|
36145
|
-
x[++j]++
|
|
36146
|
-
}
|
|
36147
|
-
}
|
|
36148
|
-
x.clamp()
|
|
36149
|
-
x.drShiftTo(this.m.t, x)
|
|
36150
|
-
if (x.compareTo(this.m) >= 0) {
|
|
36151
|
-
x.subTo(this.m, x)
|
|
36152
|
-
}
|
|
36153
|
-
}
|
|
36154
|
-
|
|
36155
|
-
// r = "x^2/R mod m"; x != r
|
|
36156
|
-
function montSqrTo(x, r) {
|
|
36157
|
-
x.squareTo(r)
|
|
36158
|
-
this.reduce(r)
|
|
36159
|
-
}
|
|
36160
|
-
|
|
36161
|
-
// r = "xy/R mod m"; x,y != r
|
|
36162
|
-
function montMulTo(x, y, r) {
|
|
36163
|
-
x.multiplyTo(y, r)
|
|
36164
|
-
this.reduce(r)
|
|
36165
|
-
}
|
|
36166
|
-
Montgomery.prototype.convert = montConvert
|
|
36167
|
-
Montgomery.prototype.revert = montRevert
|
|
36168
|
-
Montgomery.prototype.reduce = montReduce
|
|
36169
|
-
Montgomery.prototype.mulTo = montMulTo
|
|
36170
|
-
Montgomery.prototype.sqrTo = montSqrTo
|
|
36171
|
-
|
|
36172
|
-
// (protected) true iff this is even
|
|
36173
|
-
function bnpIsEven() {
|
|
36174
|
-
return (this.t > 0 ? this[0] & 1 : this.s) == 0
|
|
36175
|
-
}
|
|
36176
|
-
|
|
36177
|
-
// (protected) this^e, e < 2^32, doing sqr and mul with "r" (HAC 14.79)
|
|
36178
|
-
function bnpExp(e, z) {
|
|
36179
|
-
if (e > 0xffffffff || e < 1) {
|
|
36180
|
-
return BigInteger.ONE
|
|
36181
|
-
}
|
|
36182
|
-
let r = nbi(),
|
|
36183
|
-
r2 = nbi(),
|
|
36184
|
-
g = z.convert(this),
|
|
36185
|
-
i = nbits(e) - 1
|
|
36186
|
-
g.copyTo(r)
|
|
36187
|
-
while (--i >= 0) {
|
|
36188
|
-
z.sqrTo(r, r2)
|
|
36189
|
-
if ((e & (1 << i)) > 0) {
|
|
36190
|
-
z.mulTo(r2, g, r)
|
|
36191
|
-
} else {
|
|
36192
|
-
const t = r
|
|
36193
|
-
r = r2
|
|
36194
|
-
r2 = t
|
|
36195
|
-
}
|
|
36196
|
-
}
|
|
36197
|
-
return z.revert(r)
|
|
36198
|
-
}
|
|
36199
|
-
|
|
36200
|
-
// (public) this^e % m, 0 <= e < 2^32
|
|
36201
|
-
function bnModPowInt(e, m) {
|
|
36202
|
-
let z
|
|
36203
|
-
if (e < 256 || m.isEven()) {
|
|
36204
|
-
z = new Classic(m)
|
|
36205
|
-
} else {
|
|
36206
|
-
z = new Montgomery(m)
|
|
36207
|
-
}
|
|
36208
|
-
return this.exp(e, z)
|
|
36209
|
-
}
|
|
36210
|
-
|
|
36211
|
-
// protected
|
|
36212
|
-
BigInteger.prototype.copyTo = bnpCopyTo
|
|
36213
|
-
BigInteger.prototype.fromInt = bnpFromInt
|
|
36214
|
-
BigInteger.prototype.fromString = bnpFromString
|
|
36215
|
-
BigInteger.prototype.clamp = bnpClamp
|
|
36216
|
-
BigInteger.prototype.dlShiftTo = bnpDLShiftTo
|
|
36217
|
-
BigInteger.prototype.drShiftTo = bnpDRShiftTo
|
|
36218
|
-
BigInteger.prototype.lShiftTo = bnpLShiftTo
|
|
36219
|
-
BigInteger.prototype.rShiftTo = bnpRShiftTo
|
|
36220
|
-
BigInteger.prototype.subTo = bnpSubTo
|
|
36221
|
-
BigInteger.prototype.multiplyTo = bnpMultiplyTo
|
|
36222
|
-
BigInteger.prototype.squareTo = bnpSquareTo
|
|
36223
|
-
BigInteger.prototype.divRemTo = bnpDivRemTo
|
|
36224
|
-
BigInteger.prototype.invDigit = bnpInvDigit
|
|
36225
|
-
BigInteger.prototype.isEven = bnpIsEven
|
|
36226
|
-
BigInteger.prototype.exp = bnpExp
|
|
36227
|
-
|
|
36228
|
-
// public
|
|
36229
|
-
BigInteger.prototype.toString = bnToString
|
|
36230
|
-
BigInteger.prototype.negate = bnNegate
|
|
36231
|
-
BigInteger.prototype.abs = bnAbs
|
|
36232
|
-
BigInteger.prototype.compareTo = bnCompareTo
|
|
36233
|
-
BigInteger.prototype.bitLength = bnBitLength
|
|
36234
|
-
BigInteger.prototype.mod = bnMod
|
|
36235
|
-
BigInteger.prototype.modPowInt = bnModPowInt
|
|
36236
|
-
|
|
36237
|
-
// "constants"
|
|
36238
|
-
BigInteger.ZERO = nbv(0)
|
|
36239
|
-
BigInteger.ONE = nbv(1)
|
|
36240
|
-
|
|
36241
|
-
// Copyright (c) 2005-2009 Tom Wu
|
|
36242
|
-
// All Rights Reserved.
|
|
36243
|
-
// See "LICENSE" for details.
|
|
36244
|
-
|
|
36245
|
-
// Extended JavaScript BN functions, required for RSA private ops.
|
|
36246
|
-
|
|
36247
|
-
// Version 1.1: new BigInteger("0", 10) returns "proper" zero
|
|
36248
|
-
// Version 1.2: square() API, isProbablePrime fix
|
|
36249
|
-
|
|
36250
|
-
// (public)
|
|
36251
|
-
function bnClone() {
|
|
36252
|
-
const r = nbi()
|
|
36253
|
-
this.copyTo(r)
|
|
36254
|
-
return r
|
|
36255
|
-
}
|
|
36256
|
-
|
|
36257
|
-
// (public) return value as integer
|
|
36258
|
-
function bnIntValue() {
|
|
36259
|
-
if (this.s < 0) {
|
|
36260
|
-
if (this.t == 1) {
|
|
36261
|
-
return this[0] - this.DV
|
|
36262
|
-
} else if (this.t == 0) {
|
|
36263
|
-
return -1
|
|
36264
|
-
}
|
|
36265
|
-
} else if (this.t == 1) {
|
|
36266
|
-
return this[0]
|
|
36267
|
-
} else if (this.t == 0) {
|
|
36268
|
-
return 0
|
|
36269
|
-
}
|
|
36270
|
-
// assumes 16 < DB < 32
|
|
36271
|
-
return ((this[1] & ((1 << (32 - this.DB)) - 1)) << this.DB) | this[0]
|
|
36272
|
-
}
|
|
36273
|
-
|
|
36274
|
-
// (public) return value as byte
|
|
36275
|
-
function bnByteValue() {
|
|
36276
|
-
return this.t == 0 ? this.s : (this[0] << 24) >> 24
|
|
36277
|
-
}
|
|
36278
|
-
|
|
36279
|
-
// (public) return value as short (assumes DB>=16)
|
|
36280
|
-
function bnShortValue() {
|
|
36281
|
-
return this.t == 0 ? this.s : (this[0] << 16) >> 16
|
|
36282
|
-
}
|
|
36283
|
-
|
|
36284
|
-
// (protected) return x s.t. r^x < DV
|
|
36285
|
-
function bnpChunkSize(r) {
|
|
36286
|
-
return Math.floor((Math.LN2 * this.DB) / Math.log(r))
|
|
36287
|
-
}
|
|
36288
|
-
|
|
36289
|
-
// (public) 0 if this == 0, 1 if this > 0
|
|
36290
|
-
function bnSigNum() {
|
|
36291
|
-
if (this.s < 0) {
|
|
36292
|
-
return -1
|
|
36293
|
-
} else if (this.t <= 0 || (this.t == 1 && this[0] <= 0)) {
|
|
36294
|
-
return 0
|
|
36295
|
-
} else {
|
|
36296
|
-
return 1
|
|
36297
|
-
}
|
|
36298
|
-
}
|
|
36299
|
-
|
|
36300
|
-
// (protected) convert to radix string
|
|
36301
|
-
function bnpToRadix(b) {
|
|
36302
|
-
if (b == null) {
|
|
36303
|
-
b = 10
|
|
36304
|
-
}
|
|
36305
|
-
if (this.signum() == 0 || b < 2 || b > 36) {
|
|
36306
|
-
return '0'
|
|
36307
|
-
}
|
|
36308
|
-
const cs = this.chunkSize(b)
|
|
36309
|
-
const a = Math.pow(b, cs)
|
|
36310
|
-
let d = nbv(a),
|
|
36311
|
-
y = nbi(),
|
|
36312
|
-
z = nbi(),
|
|
36313
|
-
r = ''
|
|
36314
|
-
this.divRemTo(d, y, z)
|
|
36315
|
-
while (y.signum() > 0) {
|
|
36316
|
-
r = (a + z.intValue()).toString(b).substr(1) + r
|
|
36317
|
-
y.divRemTo(d, y, z)
|
|
36318
|
-
}
|
|
36319
|
-
return z.intValue().toString(b) + r
|
|
36320
|
-
}
|
|
36321
|
-
|
|
36322
|
-
// (protected) convert from radix string
|
|
36323
|
-
function bnpFromRadix(s, b) {
|
|
36324
|
-
this.fromInt(0)
|
|
36325
|
-
if (b == null) {
|
|
36326
|
-
b = 10
|
|
36327
|
-
}
|
|
36328
|
-
const cs = this.chunkSize(b)
|
|
36329
|
-
let d = Math.pow(b, cs),
|
|
36330
|
-
mi = false,
|
|
36331
|
-
j = 0,
|
|
36332
|
-
w = 0
|
|
36333
|
-
for (let i = 0; i < s.length; ++i) {
|
|
36334
|
-
const x = intAt(s, i)
|
|
36335
|
-
if (x < 0) {
|
|
36336
|
-
if (s.charAt(i) == '-' && this.signum() == 0) {
|
|
36337
|
-
mi = true
|
|
36338
|
-
}
|
|
36339
|
-
continue
|
|
36340
|
-
}
|
|
36341
|
-
w = b * w + x
|
|
36342
|
-
if (++j >= cs) {
|
|
36343
|
-
this.dMultiply(d)
|
|
36344
|
-
this.dAddOffset(w, 0)
|
|
36345
|
-
j = 0
|
|
36346
|
-
w = 0
|
|
36347
|
-
}
|
|
36348
|
-
}
|
|
36349
|
-
if (j > 0) {
|
|
36350
|
-
this.dMultiply(Math.pow(b, j))
|
|
36351
|
-
this.dAddOffset(w, 0)
|
|
36352
|
-
}
|
|
36353
|
-
if (mi) {
|
|
36354
|
-
BigInteger.ZERO.subTo(this, this)
|
|
36355
|
-
}
|
|
36356
|
-
}
|
|
36357
|
-
|
|
36358
|
-
// (protected) alternate constructor
|
|
36359
|
-
function bnpFromNumber(a, b, c) {
|
|
36360
|
-
if ('number' == typeof b) {
|
|
36361
|
-
// new BigInteger(int,int,RNG)
|
|
36362
|
-
if (a < 2) {
|
|
36363
|
-
this.fromInt(1)
|
|
36364
|
-
} else {
|
|
36365
|
-
this.fromNumber(a, c)
|
|
36366
|
-
if (!this.testBit(a - 1)) {
|
|
36367
|
-
// force MSB set
|
|
36368
|
-
this.bitwiseTo(BigInteger.ONE.shiftLeft(a - 1), op_or, this)
|
|
36369
|
-
}
|
|
36370
|
-
if (this.isEven()) {
|
|
36371
|
-
this.dAddOffset(1, 0)
|
|
36372
|
-
} // force odd
|
|
36373
|
-
while (!this.isProbablePrime(b)) {
|
|
36374
|
-
this.dAddOffset(2, 0)
|
|
36375
|
-
if (this.bitLength() > a) {
|
|
36376
|
-
this.subTo(BigInteger.ONE.shiftLeft(a - 1), this)
|
|
36377
|
-
}
|
|
36378
|
-
}
|
|
36379
|
-
}
|
|
36380
|
-
} else {
|
|
36381
|
-
// new BigInteger(int,RNG)
|
|
36382
|
-
const x = new Array(),
|
|
36383
|
-
t = a & 7
|
|
36384
|
-
x.length = (a >> 3) + 1
|
|
36385
|
-
b.nextBytes(x)
|
|
36386
|
-
if (t > 0) {
|
|
36387
|
-
x[0] &= (1 << t) - 1
|
|
36388
|
-
} else {
|
|
36389
|
-
x[0] = 0
|
|
36390
|
-
}
|
|
36391
|
-
this.fromString(x, 256)
|
|
36392
|
-
}
|
|
36393
|
-
}
|
|
36394
|
-
|
|
36395
|
-
// (public) convert to bigendian byte array
|
|
36396
|
-
function bnToByteArray() {
|
|
36397
|
-
let i = this.t,
|
|
36398
|
-
r = new Array()
|
|
36399
|
-
r[0] = this.s
|
|
36400
|
-
let p = this.DB - ((i * this.DB) % 8),
|
|
36401
|
-
d,
|
|
36402
|
-
k = 0
|
|
36403
|
-
if (i-- > 0) {
|
|
36404
|
-
if (p < this.DB && (d = this[i] >> p) != (this.s & this.DM) >> p) {
|
|
36405
|
-
r[k++] = d | (this.s << (this.DB - p))
|
|
36406
|
-
}
|
|
36407
|
-
while (i >= 0) {
|
|
36408
|
-
if (p < 8) {
|
|
36409
|
-
d = (this[i] & ((1 << p) - 1)) << (8 - p)
|
|
36410
|
-
d |= this[--i] >> (p += this.DB - 8)
|
|
36411
|
-
} else {
|
|
36412
|
-
d = (this[i] >> (p -= 8)) & 0xff
|
|
36413
|
-
if (p <= 0) {
|
|
36414
|
-
p += this.DB
|
|
36415
|
-
--i
|
|
36416
|
-
}
|
|
36417
|
-
}
|
|
36418
|
-
if ((d & 0x80) != 0) {
|
|
36419
|
-
d |= -256
|
|
36420
|
-
}
|
|
36421
|
-
if (k == 0 && (this.s & 0x80) != (d & 0x80)) {
|
|
36422
|
-
++k
|
|
36423
|
-
}
|
|
36424
|
-
if (k > 0 || d != this.s) {
|
|
36425
|
-
r[k++] = d
|
|
36426
|
-
}
|
|
36427
|
-
}
|
|
36428
|
-
}
|
|
36429
|
-
return r
|
|
36430
|
-
}
|
|
36431
|
-
function bnEquals(a) {
|
|
36432
|
-
return this.compareTo(a) == 0
|
|
36433
|
-
}
|
|
36434
|
-
function bnMin(a) {
|
|
36435
|
-
return this.compareTo(a) < 0 ? this : a
|
|
36436
|
-
}
|
|
36437
|
-
function bnMax(a) {
|
|
36438
|
-
return this.compareTo(a) > 0 ? this : a
|
|
36439
|
-
}
|
|
36440
|
-
|
|
36441
|
-
// (protected) r = this op a (bitwise)
|
|
36442
|
-
function bnpBitwiseTo(a, op, r) {
|
|
36443
|
-
let i,
|
|
36444
|
-
f,
|
|
36445
|
-
m = Math.min(a.t, this.t)
|
|
36446
|
-
for (i = 0; i < m; ++i) {
|
|
36447
|
-
r[i] = op(this[i], a[i])
|
|
36448
|
-
}
|
|
36449
|
-
if (a.t < this.t) {
|
|
36450
|
-
f = a.s & this.DM
|
|
36451
|
-
for (i = m; i < this.t; ++i) {
|
|
36452
|
-
r[i] = op(this[i], f)
|
|
36453
|
-
}
|
|
36454
|
-
r.t = this.t
|
|
36455
|
-
} else {
|
|
36456
|
-
f = this.s & this.DM
|
|
36457
|
-
for (i = m; i < a.t; ++i) {
|
|
36458
|
-
r[i] = op(f, a[i])
|
|
36459
|
-
}
|
|
36460
|
-
r.t = a.t
|
|
36461
|
-
}
|
|
36462
|
-
r.s = op(this.s, a.s)
|
|
36463
|
-
r.clamp()
|
|
36464
|
-
}
|
|
36465
|
-
|
|
36466
|
-
// (public) this & a
|
|
36467
|
-
function op_and(x, y) {
|
|
36468
|
-
return x & y
|
|
36469
|
-
}
|
|
36470
|
-
function bnAnd(a) {
|
|
36471
|
-
const r = nbi()
|
|
36472
|
-
this.bitwiseTo(a, op_and, r)
|
|
36473
|
-
return r
|
|
36474
|
-
}
|
|
36475
|
-
|
|
36476
|
-
// (public) this | a
|
|
36477
|
-
function op_or(x, y) {
|
|
36478
|
-
return x | y
|
|
36479
|
-
}
|
|
36480
|
-
function bnOr(a) {
|
|
36481
|
-
const r = nbi()
|
|
36482
|
-
this.bitwiseTo(a, op_or, r)
|
|
36483
|
-
return r
|
|
36484
|
-
}
|
|
36485
|
-
|
|
36486
|
-
// (public) this ^ a
|
|
36487
|
-
function op_xor(x, y) {
|
|
36488
|
-
return x ^ y
|
|
36489
|
-
}
|
|
36490
|
-
function bnXor(a) {
|
|
36491
|
-
const r = nbi()
|
|
36492
|
-
this.bitwiseTo(a, op_xor, r)
|
|
36493
|
-
return r
|
|
36494
|
-
}
|
|
36495
|
-
|
|
36496
|
-
// (public) this & ~a
|
|
36497
|
-
function op_andnot(x, y) {
|
|
36498
|
-
return x & ~y
|
|
36499
|
-
}
|
|
36500
|
-
function bnAndNot(a) {
|
|
36501
|
-
const r = nbi()
|
|
36502
|
-
this.bitwiseTo(a, op_andnot, r)
|
|
36503
|
-
return r
|
|
36504
|
-
}
|
|
36505
|
-
|
|
36506
|
-
// (public) ~this
|
|
36507
|
-
function bnNot() {
|
|
36508
|
-
const r = nbi()
|
|
36509
|
-
for (let i = 0; i < this.t; ++i) {
|
|
36510
|
-
r[i] = this.DM & ~this[i]
|
|
36511
|
-
}
|
|
36512
|
-
r.t = this.t
|
|
36513
|
-
r.s = ~this.s
|
|
36514
|
-
return r
|
|
36515
|
-
}
|
|
36516
|
-
|
|
36517
|
-
// (public) this << n
|
|
36518
|
-
function bnShiftLeft(n) {
|
|
36519
|
-
const r = nbi()
|
|
36520
|
-
if (n < 0) {
|
|
36521
|
-
this.rShiftTo(-n, r)
|
|
36522
|
-
} else {
|
|
36523
|
-
this.lShiftTo(n, r)
|
|
36524
|
-
}
|
|
36525
|
-
return r
|
|
36526
|
-
}
|
|
36527
|
-
|
|
36528
|
-
// (public) this >> n
|
|
36529
|
-
function bnShiftRight(n) {
|
|
36530
|
-
const r = nbi()
|
|
36531
|
-
if (n < 0) {
|
|
36532
|
-
this.lShiftTo(-n, r)
|
|
36533
|
-
} else {
|
|
36534
|
-
this.rShiftTo(n, r)
|
|
36535
|
-
}
|
|
36536
|
-
return r
|
|
36537
|
-
}
|
|
36538
|
-
|
|
36539
|
-
// return index of lowest 1-bit in x, x < 2^31
|
|
36540
|
-
function lbit(x) {
|
|
36541
|
-
if (x == 0) {
|
|
36542
|
-
return -1
|
|
36543
|
-
}
|
|
36544
|
-
let r = 0
|
|
36545
|
-
if ((x & 0xffff) == 0) {
|
|
36546
|
-
x >>= 16
|
|
36547
|
-
r += 16
|
|
36548
|
-
}
|
|
36549
|
-
if ((x & 0xff) == 0) {
|
|
36550
|
-
x >>= 8
|
|
36551
|
-
r += 8
|
|
36552
|
-
}
|
|
36553
|
-
if ((x & 0xf) == 0) {
|
|
36554
|
-
x >>= 4
|
|
36555
|
-
r += 4
|
|
36556
|
-
}
|
|
36557
|
-
if ((x & 3) == 0) {
|
|
36558
|
-
x >>= 2
|
|
36559
|
-
r += 2
|
|
36560
|
-
}
|
|
36561
|
-
if ((x & 1) == 0) {
|
|
36562
|
-
++r
|
|
36563
|
-
}
|
|
36564
|
-
return r
|
|
36565
|
-
}
|
|
36566
|
-
|
|
36567
|
-
// (public) returns index of lowest 1-bit (or -1 if none)
|
|
36568
|
-
function bnGetLowestSetBit() {
|
|
36569
|
-
for (let i = 0; i < this.t; ++i) {
|
|
36570
|
-
if (this[i] != 0) return i * this.DB + lbit(this[i])
|
|
36571
|
-
}
|
|
36572
|
-
if (this.s < 0) {
|
|
36573
|
-
return this.t * this.DB
|
|
36574
|
-
}
|
|
36575
|
-
return -1
|
|
36576
|
-
}
|
|
36577
|
-
|
|
36578
|
-
// return number of 1 bits in x
|
|
36579
|
-
function cbit(x) {
|
|
36580
|
-
let r = 0
|
|
36581
|
-
while (x != 0) {
|
|
36582
|
-
x &= x - 1
|
|
36583
|
-
++r
|
|
36584
|
-
}
|
|
36585
|
-
return r
|
|
36586
|
-
}
|
|
36587
|
-
|
|
36588
|
-
// (public) return number of set bits
|
|
36589
|
-
function bnBitCount() {
|
|
36590
|
-
let r = 0,
|
|
36591
|
-
x = this.s & this.DM
|
|
36592
|
-
for (let i = 0; i < this.t; ++i) {
|
|
36593
|
-
r += cbit(this[i] ^ x)
|
|
36594
|
-
}
|
|
36595
|
-
return r
|
|
36596
|
-
}
|
|
36597
|
-
|
|
36598
|
-
// (public) true iff nth bit is set
|
|
36599
|
-
function bnTestBit(n) {
|
|
36600
|
-
const j = Math.floor(n / this.DB)
|
|
36601
|
-
if (j >= this.t) {
|
|
36602
|
-
return this.s != 0
|
|
36603
|
-
}
|
|
36604
|
-
return (this[j] & (1 << (n % this.DB))) != 0
|
|
36605
|
-
}
|
|
36606
|
-
|
|
36607
|
-
// (protected) this op (1<<n)
|
|
36608
|
-
function bnpChangeBit(n, op) {
|
|
36609
|
-
const r = BigInteger.ONE.shiftLeft(n)
|
|
36610
|
-
this.bitwiseTo(r, op, r)
|
|
36611
|
-
return r
|
|
36612
|
-
}
|
|
36613
|
-
|
|
36614
|
-
// (public) this | (1<<n)
|
|
36615
|
-
function bnSetBit(n) {
|
|
36616
|
-
return this.changeBit(n, op_or)
|
|
36617
|
-
}
|
|
36618
|
-
|
|
36619
|
-
// (public) this & ~(1<<n)
|
|
36620
|
-
function bnClearBit(n) {
|
|
36621
|
-
return this.changeBit(n, op_andnot)
|
|
36622
|
-
}
|
|
36623
|
-
|
|
36624
|
-
// (public) this ^ (1<<n)
|
|
36625
|
-
function bnFlipBit(n) {
|
|
36626
|
-
return this.changeBit(n, op_xor)
|
|
36627
|
-
}
|
|
36628
|
-
|
|
36629
|
-
// (protected) r = this + a
|
|
36630
|
-
function bnpAddTo(a, r) {
|
|
36631
|
-
let i = 0,
|
|
36632
|
-
c = 0,
|
|
36633
|
-
m = Math.min(a.t, this.t)
|
|
36634
|
-
while (i < m) {
|
|
36635
|
-
c += this[i] + a[i]
|
|
36636
|
-
r[i++] = c & this.DM
|
|
36637
|
-
c >>= this.DB
|
|
36638
|
-
}
|
|
36639
|
-
if (a.t < this.t) {
|
|
36640
|
-
c += a.s
|
|
36641
|
-
while (i < this.t) {
|
|
36642
|
-
c += this[i]
|
|
36643
|
-
r[i++] = c & this.DM
|
|
36644
|
-
c >>= this.DB
|
|
36645
|
-
}
|
|
36646
|
-
c += this.s
|
|
36647
|
-
} else {
|
|
36648
|
-
c += this.s
|
|
36649
|
-
while (i < a.t) {
|
|
36650
|
-
c += a[i]
|
|
36651
|
-
r[i++] = c & this.DM
|
|
36652
|
-
c >>= this.DB
|
|
36653
|
-
}
|
|
36654
|
-
c += a.s
|
|
36655
|
-
}
|
|
36656
|
-
r.s = c < 0 ? -1 : 0
|
|
36657
|
-
if (c > 0) {
|
|
36658
|
-
r[i++] = c
|
|
36659
|
-
} else if (c < -1) {
|
|
36660
|
-
r[i++] = this.DV + c
|
|
36661
|
-
}
|
|
36662
|
-
r.t = i
|
|
36663
|
-
r.clamp()
|
|
36664
|
-
}
|
|
36665
|
-
|
|
36666
|
-
// (public) this + a
|
|
36667
|
-
function bnAdd(a) {
|
|
36668
|
-
const r = nbi()
|
|
36669
|
-
this.addTo(a, r)
|
|
36670
|
-
return r
|
|
36671
|
-
}
|
|
36672
|
-
|
|
36673
|
-
// (public) this - a
|
|
36674
|
-
function bnSubtract(a) {
|
|
36675
|
-
const r = nbi()
|
|
36676
|
-
this.subTo(a, r)
|
|
36677
|
-
return r
|
|
36678
|
-
}
|
|
36679
|
-
|
|
36680
|
-
// (public) this * a
|
|
36681
|
-
function bnMultiply(a) {
|
|
36682
|
-
const r = nbi()
|
|
36683
|
-
this.multiplyTo(a, r)
|
|
36684
|
-
return r
|
|
36685
|
-
}
|
|
36686
|
-
|
|
36687
|
-
// (public) this^2
|
|
36688
|
-
function bnSquare() {
|
|
36689
|
-
const r = nbi()
|
|
36690
|
-
this.squareTo(r)
|
|
36691
|
-
return r
|
|
36692
|
-
}
|
|
36693
|
-
|
|
36694
|
-
// (public) this / a
|
|
36695
|
-
function bnDivide(a) {
|
|
36696
|
-
const r = nbi()
|
|
36697
|
-
this.divRemTo(a, r, null)
|
|
36698
|
-
return r
|
|
36699
|
-
}
|
|
36700
|
-
|
|
36701
|
-
// (public) this % a
|
|
36702
|
-
function bnRemainder(a) {
|
|
36703
|
-
const r = nbi()
|
|
36704
|
-
this.divRemTo(a, null, r)
|
|
36705
|
-
return r
|
|
36706
|
-
}
|
|
36707
|
-
|
|
36708
|
-
// (public) [this/a,this%a]
|
|
36709
|
-
function bnDivideAndRemainder(a) {
|
|
36710
|
-
const q = nbi(),
|
|
36711
|
-
r = nbi()
|
|
36712
|
-
this.divRemTo(a, q, r)
|
|
36713
|
-
return new Array(q, r)
|
|
36714
|
-
}
|
|
36715
|
-
|
|
36716
|
-
// (protected) this *= n, this >= 0, 1 < n < DV
|
|
36717
|
-
function bnpDMultiply(n) {
|
|
36718
|
-
this[this.t] = this.am(0, n - 1, this, 0, 0, this.t)
|
|
36719
|
-
++this.t
|
|
36720
|
-
this.clamp()
|
|
36721
|
-
}
|
|
36722
|
-
|
|
36723
|
-
// (protected) this += n << w words, this >= 0
|
|
36724
|
-
function bnpDAddOffset(n, w) {
|
|
36725
|
-
if (n == 0) {
|
|
36726
|
-
return
|
|
36727
|
-
}
|
|
36728
|
-
while (this.t <= w) {
|
|
36729
|
-
this[this.t++] = 0
|
|
36730
|
-
}
|
|
36731
|
-
this[w] += n
|
|
36732
|
-
while (this[w] >= this.DV) {
|
|
36733
|
-
this[w] -= this.DV
|
|
36734
|
-
if (++w >= this.t) {
|
|
36735
|
-
this[this.t++] = 0
|
|
36736
|
-
}
|
|
36737
|
-
++this[w]
|
|
36738
|
-
}
|
|
36739
|
-
}
|
|
36740
|
-
|
|
36741
|
-
// A "null" reducer
|
|
36742
|
-
function NullExp() {}
|
|
36743
|
-
function nNop(x) {
|
|
36744
|
-
return x
|
|
36745
|
-
}
|
|
36746
|
-
function nMulTo(x, y, r) {
|
|
36747
|
-
x.multiplyTo(y, r)
|
|
36748
|
-
}
|
|
36749
|
-
function nSqrTo(x, r) {
|
|
36750
|
-
x.squareTo(r)
|
|
36751
|
-
}
|
|
36752
|
-
NullExp.prototype.convert = nNop
|
|
36753
|
-
NullExp.prototype.revert = nNop
|
|
36754
|
-
NullExp.prototype.mulTo = nMulTo
|
|
36755
|
-
NullExp.prototype.sqrTo = nSqrTo
|
|
36756
|
-
|
|
36757
|
-
// (public) this^e
|
|
36758
|
-
function bnPow(e) {
|
|
36759
|
-
return this.exp(e, new NullExp())
|
|
36760
|
-
}
|
|
36761
|
-
|
|
36762
|
-
// (protected) r = lower n words of "this * a", a.t <= n
|
|
36763
|
-
// "this" should be the larger one if appropriate.
|
|
36764
|
-
function bnpMultiplyLowerTo(a, n, r) {
|
|
36765
|
-
let i = Math.min(this.t + a.t, n)
|
|
36766
|
-
r.s = 0 // assumes a,this >= 0
|
|
36767
|
-
r.t = i
|
|
36768
|
-
while (i > 0) {
|
|
36769
|
-
r[--i] = 0
|
|
36770
|
-
}
|
|
36771
|
-
let j
|
|
36772
|
-
for (j = r.t - this.t; i < j; ++i) {
|
|
36773
|
-
r[i + this.t] = this.am(0, a[i], r, i, 0, this.t)
|
|
36774
|
-
}
|
|
36775
|
-
for (j = Math.min(a.t, n); i < j; ++i) {
|
|
36776
|
-
this.am(0, a[i], r, i, 0, n - i)
|
|
36777
|
-
}
|
|
36778
|
-
r.clamp()
|
|
36779
|
-
}
|
|
36780
|
-
|
|
36781
|
-
// (protected) r = "this * a" without lower n words, n > 0
|
|
36782
|
-
// "this" should be the larger one if appropriate.
|
|
36783
|
-
function bnpMultiplyUpperTo(a, n, r) {
|
|
36784
|
-
--n
|
|
36785
|
-
let i = (r.t = this.t + a.t - n)
|
|
36786
|
-
r.s = 0 // assumes a,this >= 0
|
|
36787
|
-
while (--i >= 0) {
|
|
36788
|
-
r[i] = 0
|
|
36789
|
-
}
|
|
36790
|
-
for (i = Math.max(n - this.t, 0); i < a.t; ++i) {
|
|
36791
|
-
r[this.t + i - n] = this.am(n - i, a[i], r, 0, 0, this.t + i - n)
|
|
36792
|
-
}
|
|
36793
|
-
r.clamp()
|
|
36794
|
-
r.drShiftTo(1, r)
|
|
36795
|
-
}
|
|
36796
|
-
|
|
36797
|
-
// Barrett modular reduction
|
|
36798
|
-
function Barrett(m) {
|
|
36799
|
-
// setup Barrett
|
|
36800
|
-
this.r2 = nbi()
|
|
36801
|
-
this.q3 = nbi()
|
|
36802
|
-
BigInteger.ONE.dlShiftTo(2 * m.t, this.r2)
|
|
36803
|
-
this.mu = this.r2.divide(m)
|
|
36804
|
-
this.m = m
|
|
36805
|
-
}
|
|
36806
|
-
function barrettConvert(x) {
|
|
36807
|
-
if (x.s < 0 || x.t > 2 * this.m.t) {
|
|
36808
|
-
return x.mod(this.m)
|
|
36809
|
-
} else if (x.compareTo(this.m) < 0) {
|
|
36810
|
-
return x
|
|
36811
|
-
} else {
|
|
36812
|
-
const r = nbi()
|
|
36813
|
-
x.copyTo(r)
|
|
36814
|
-
this.reduce(r)
|
|
36815
|
-
return r
|
|
36816
|
-
}
|
|
36817
|
-
}
|
|
36818
|
-
function barrettRevert(x) {
|
|
36819
|
-
return x
|
|
36820
|
-
}
|
|
36821
|
-
|
|
36822
|
-
// x = x mod m (HAC 14.42)
|
|
36823
|
-
function barrettReduce(x) {
|
|
36824
|
-
x.drShiftTo(this.m.t - 1, this.r2)
|
|
36825
|
-
if (x.t > this.m.t + 1) {
|
|
36826
|
-
x.t = this.m.t + 1
|
|
36827
|
-
x.clamp()
|
|
36828
|
-
}
|
|
36829
|
-
this.mu.multiplyUpperTo(this.r2, this.m.t + 1, this.q3)
|
|
36830
|
-
this.m.multiplyLowerTo(this.q3, this.m.t + 1, this.r2)
|
|
36831
|
-
while (x.compareTo(this.r2) < 0) {
|
|
36832
|
-
x.dAddOffset(1, this.m.t + 1)
|
|
36833
|
-
}
|
|
36834
|
-
x.subTo(this.r2, x)
|
|
36835
|
-
while (x.compareTo(this.m) >= 0) {
|
|
36836
|
-
x.subTo(this.m, x)
|
|
36837
|
-
}
|
|
36838
|
-
}
|
|
36839
|
-
|
|
36840
|
-
// r = x^2 mod m; x != r
|
|
36841
|
-
function barrettSqrTo(x, r) {
|
|
36842
|
-
x.squareTo(r)
|
|
36843
|
-
this.reduce(r)
|
|
36844
|
-
}
|
|
36845
|
-
|
|
36846
|
-
// r = x*y mod m; x,y != r
|
|
36847
|
-
function barrettMulTo(x, y, r) {
|
|
36848
|
-
x.multiplyTo(y, r)
|
|
36849
|
-
this.reduce(r)
|
|
36850
|
-
}
|
|
36851
|
-
Barrett.prototype.convert = barrettConvert
|
|
36852
|
-
Barrett.prototype.revert = barrettRevert
|
|
36853
|
-
Barrett.prototype.reduce = barrettReduce
|
|
36854
|
-
Barrett.prototype.mulTo = barrettMulTo
|
|
36855
|
-
Barrett.prototype.sqrTo = barrettSqrTo
|
|
36856
|
-
|
|
36857
|
-
// (public) this^e % m (HAC 14.85)
|
|
36858
|
-
function bnModPow(e, m) {
|
|
36859
|
-
let i = e.bitLength(),
|
|
36860
|
-
k,
|
|
36861
|
-
r = nbv(1),
|
|
36862
|
-
z
|
|
36863
|
-
if (i <= 0) {
|
|
36864
|
-
return r
|
|
36865
|
-
} else if (i < 18) {
|
|
36866
|
-
k = 1
|
|
36867
|
-
} else if (i < 48) {
|
|
36868
|
-
k = 3
|
|
36869
|
-
} else if (i < 144) {
|
|
36870
|
-
k = 4
|
|
36871
|
-
} else if (i < 768) {
|
|
36872
|
-
k = 5
|
|
36873
|
-
} else {
|
|
36874
|
-
k = 6
|
|
36875
|
-
}
|
|
36876
|
-
if (i < 8) {
|
|
36877
|
-
z = new Classic(m)
|
|
36878
|
-
} else if (m.isEven()) {
|
|
36879
|
-
z = new Barrett(m)
|
|
36880
|
-
} else {
|
|
36881
|
-
z = new Montgomery(m)
|
|
36882
|
-
}
|
|
36883
|
-
|
|
36884
|
-
// precomputation
|
|
36885
|
-
let g = new Array(),
|
|
36886
|
-
n = 3,
|
|
36887
|
-
k1 = k - 1,
|
|
36888
|
-
km = (1 << k) - 1
|
|
36889
|
-
g[1] = z.convert(this)
|
|
36890
|
-
if (k > 1) {
|
|
36891
|
-
const g2 = nbi()
|
|
36892
|
-
z.sqrTo(g[1], g2)
|
|
36893
|
-
while (n <= km) {
|
|
36894
|
-
g[n] = nbi()
|
|
36895
|
-
z.mulTo(g2, g[n - 2], g[n])
|
|
36896
|
-
n += 2
|
|
36897
|
-
}
|
|
36898
|
-
}
|
|
36899
|
-
let j = e.t - 1,
|
|
36900
|
-
w,
|
|
36901
|
-
is1 = true,
|
|
36902
|
-
r2 = nbi(),
|
|
36903
|
-
t
|
|
36904
|
-
i = nbits(e[j]) - 1
|
|
36905
|
-
while (j >= 0) {
|
|
36906
|
-
if (i >= k1) {
|
|
36907
|
-
w = (e[j] >> (i - k1)) & km
|
|
36908
|
-
} else {
|
|
36909
|
-
w = (e[j] & ((1 << (i + 1)) - 1)) << (k1 - i)
|
|
36910
|
-
if (j > 0) {
|
|
36911
|
-
w |= e[j - 1] >> (this.DB + i - k1)
|
|
36912
|
-
}
|
|
36913
|
-
}
|
|
36914
|
-
n = k
|
|
36915
|
-
while ((w & 1) == 0) {
|
|
36916
|
-
w >>= 1
|
|
36917
|
-
--n
|
|
36918
|
-
}
|
|
36919
|
-
if ((i -= n) < 0) {
|
|
36920
|
-
i += this.DB
|
|
36921
|
-
--j
|
|
36922
|
-
}
|
|
36923
|
-
if (is1) {
|
|
36924
|
-
// ret == 1, don't bother squaring or multiplying it
|
|
36925
|
-
g[w].copyTo(r)
|
|
36926
|
-
is1 = false
|
|
36927
|
-
} else {
|
|
36928
|
-
while (n > 1) {
|
|
36929
|
-
z.sqrTo(r, r2)
|
|
36930
|
-
z.sqrTo(r2, r)
|
|
36931
|
-
n -= 2
|
|
36932
|
-
}
|
|
36933
|
-
if (n > 0) {
|
|
36934
|
-
z.sqrTo(r, r2)
|
|
36935
|
-
} else {
|
|
36936
|
-
t = r
|
|
36937
|
-
r = r2
|
|
36938
|
-
r2 = t
|
|
36939
|
-
}
|
|
36940
|
-
z.mulTo(r2, g[w], r)
|
|
36941
|
-
}
|
|
36942
|
-
while (j >= 0 && (e[j] & (1 << i)) == 0) {
|
|
36943
|
-
z.sqrTo(r, r2)
|
|
36944
|
-
t = r
|
|
36945
|
-
r = r2
|
|
36946
|
-
r2 = t
|
|
36947
|
-
if (--i < 0) {
|
|
36948
|
-
i = this.DB - 1
|
|
36949
|
-
--j
|
|
36950
|
-
}
|
|
36951
|
-
}
|
|
36952
|
-
}
|
|
36953
|
-
return z.revert(r)
|
|
36954
|
-
}
|
|
36955
|
-
|
|
36956
|
-
// (public) gcd(this,a) (HAC 14.54)
|
|
36957
|
-
function bnGCD(a) {
|
|
36958
|
-
let x = this.s < 0 ? this.negate() : this.clone()
|
|
36959
|
-
let y = a.s < 0 ? a.negate() : a.clone()
|
|
36960
|
-
if (x.compareTo(y) < 0) {
|
|
36961
|
-
const t = x
|
|
36962
|
-
x = y
|
|
36963
|
-
y = t
|
|
36964
|
-
}
|
|
36965
|
-
let i = x.getLowestSetBit(),
|
|
36966
|
-
g = y.getLowestSetBit()
|
|
36967
|
-
if (g < 0) {
|
|
36968
|
-
return x
|
|
36969
|
-
}
|
|
36970
|
-
if (i < g) {
|
|
36971
|
-
g = i
|
|
36972
|
-
}
|
|
36973
|
-
if (g > 0) {
|
|
36974
|
-
x.rShiftTo(g, x)
|
|
36975
|
-
y.rShiftTo(g, y)
|
|
36976
|
-
}
|
|
36977
|
-
while (x.signum() > 0) {
|
|
36978
|
-
if ((i = x.getLowestSetBit()) > 0) {
|
|
36979
|
-
x.rShiftTo(i, x)
|
|
36980
|
-
}
|
|
36981
|
-
if ((i = y.getLowestSetBit()) > 0) {
|
|
36982
|
-
y.rShiftTo(i, y)
|
|
36983
|
-
}
|
|
36984
|
-
if (x.compareTo(y) >= 0) {
|
|
36985
|
-
x.subTo(y, x)
|
|
36986
|
-
x.rShiftTo(1, x)
|
|
36987
|
-
} else {
|
|
36988
|
-
y.subTo(x, y)
|
|
36989
|
-
y.rShiftTo(1, y)
|
|
36990
|
-
}
|
|
36991
|
-
}
|
|
36992
|
-
if (g > 0) {
|
|
36993
|
-
y.lShiftTo(g, y)
|
|
36994
|
-
}
|
|
36995
|
-
return y
|
|
36996
|
-
}
|
|
36997
|
-
|
|
36998
|
-
// (protected) this % n, n < 2^26
|
|
36999
|
-
function bnpModInt(n) {
|
|
37000
|
-
if (n <= 0) {
|
|
37001
|
-
return 0
|
|
37002
|
-
}
|
|
37003
|
-
let d = this.DV % n,
|
|
37004
|
-
r = this.s < 0 ? n - 1 : 0
|
|
37005
|
-
if (this.t > 0) {
|
|
37006
|
-
if (d == 0) r = this[0] % n
|
|
37007
|
-
else for (var i = this.t - 1; i >= 0; --i) r = (d * r + this[i]) % n
|
|
37008
|
-
}
|
|
37009
|
-
return r
|
|
37010
|
-
}
|
|
37011
|
-
|
|
37012
|
-
// (public) 1/this % m (HAC 14.61)
|
|
37013
|
-
function bnModInverse(m) {
|
|
37014
|
-
const ac = m.isEven()
|
|
37015
|
-
if ((this.isEven() && ac) || m.signum() == 0) {
|
|
37016
|
-
return BigInteger.ZERO
|
|
37017
|
-
}
|
|
37018
|
-
const u = m.clone(),
|
|
37019
|
-
v = this.clone()
|
|
37020
|
-
const a = nbv(1),
|
|
37021
|
-
b = nbv(0),
|
|
37022
|
-
c = nbv(0),
|
|
37023
|
-
d = nbv(1)
|
|
37024
|
-
while (u.signum() != 0) {
|
|
37025
|
-
while (u.isEven()) {
|
|
37026
|
-
u.rShiftTo(1, u)
|
|
37027
|
-
if (ac) {
|
|
37028
|
-
if (!a.isEven() || !b.isEven()) {
|
|
37029
|
-
a.addTo(this, a)
|
|
37030
|
-
b.subTo(m, b)
|
|
37031
|
-
}
|
|
37032
|
-
a.rShiftTo(1, a)
|
|
37033
|
-
} else if (!b.isEven()) {
|
|
37034
|
-
b.subTo(m, b)
|
|
37035
|
-
}
|
|
37036
|
-
b.rShiftTo(1, b)
|
|
37037
|
-
}
|
|
37038
|
-
while (v.isEven()) {
|
|
37039
|
-
v.rShiftTo(1, v)
|
|
37040
|
-
if (ac) {
|
|
37041
|
-
if (!c.isEven() || !d.isEven()) {
|
|
37042
|
-
c.addTo(this, c)
|
|
37043
|
-
d.subTo(m, d)
|
|
37044
|
-
}
|
|
37045
|
-
c.rShiftTo(1, c)
|
|
37046
|
-
} else if (!d.isEven()) {
|
|
37047
|
-
d.subTo(m, d)
|
|
37048
|
-
}
|
|
37049
|
-
d.rShiftTo(1, d)
|
|
37050
|
-
}
|
|
37051
|
-
if (u.compareTo(v) >= 0) {
|
|
37052
|
-
u.subTo(v, u)
|
|
37053
|
-
if (ac) {
|
|
37054
|
-
a.subTo(c, a)
|
|
37055
|
-
}
|
|
37056
|
-
b.subTo(d, b)
|
|
37057
|
-
} else {
|
|
37058
|
-
v.subTo(u, v)
|
|
37059
|
-
if (ac) {
|
|
37060
|
-
c.subTo(a, c)
|
|
37061
|
-
}
|
|
37062
|
-
d.subTo(b, d)
|
|
37063
|
-
}
|
|
37064
|
-
}
|
|
37065
|
-
if (v.compareTo(BigInteger.ONE) != 0) {
|
|
37066
|
-
return BigInteger.ZERO
|
|
37067
|
-
}
|
|
37068
|
-
if (d.compareTo(m) >= 0) {
|
|
37069
|
-
return d.subtract(m)
|
|
37070
|
-
}
|
|
37071
|
-
if (d.signum() < 0) {
|
|
37072
|
-
d.addTo(m, d)
|
|
37073
|
-
} else {
|
|
37074
|
-
return d
|
|
37075
|
-
}
|
|
37076
|
-
if (d.signum() < 0) {
|
|
37077
|
-
return d.add(m)
|
|
37078
|
-
} else {
|
|
37079
|
-
return d
|
|
37080
|
-
}
|
|
37081
|
-
}
|
|
37082
|
-
const lowprimes = [
|
|
37083
|
-
2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
|
|
37084
|
-
71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139,
|
|
37085
|
-
149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
|
|
37086
|
-
227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293,
|
|
37087
|
-
307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383,
|
|
37088
|
-
389, 397, 401, 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463,
|
|
37089
|
-
467, 479, 487, 491, 499, 503, 509, 521, 523, 541, 547, 557, 563, 569,
|
|
37090
|
-
571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, 641, 643, 647,
|
|
37091
|
-
653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743,
|
|
37092
|
-
751, 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839,
|
|
37093
|
-
853, 857, 859, 863, 877, 881, 883, 887, 907, 911, 919, 929, 937, 941,
|
|
37094
|
-
947, 953, 967, 971, 977, 983, 991, 997
|
|
37095
|
-
]
|
|
37096
|
-
const lplim = (1 << 26) / lowprimes[lowprimes.length - 1]
|
|
37097
|
-
|
|
37098
|
-
// (public) test primality with certainty >= 1-.5^t
|
|
37099
|
-
function bnIsProbablePrime(t) {
|
|
37100
|
-
let i,
|
|
37101
|
-
x = this.abs()
|
|
37102
|
-
if (x.t == 1 && x[0] <= lowprimes[lowprimes.length - 1]) {
|
|
37103
|
-
for (i = 0; i < lowprimes.length; ++i) {
|
|
37104
|
-
if (x[0] == lowprimes[i]) return true
|
|
37105
|
-
}
|
|
37106
|
-
return false
|
|
37107
|
-
}
|
|
37108
|
-
if (x.isEven()) {
|
|
37109
|
-
return false
|
|
37110
|
-
}
|
|
37111
|
-
i = 1
|
|
37112
|
-
while (i < lowprimes.length) {
|
|
37113
|
-
let m = lowprimes[i],
|
|
37114
|
-
j = i + 1
|
|
37115
|
-
while (j < lowprimes.length && m < lplim) {
|
|
37116
|
-
m *= lowprimes[j++]
|
|
37117
|
-
}
|
|
37118
|
-
m = x.modInt(m)
|
|
37119
|
-
while (i < j) {
|
|
37120
|
-
if (m % lowprimes[i++] == 0) return false
|
|
37121
|
-
}
|
|
37122
|
-
}
|
|
37123
|
-
return x.millerRabin(t)
|
|
37124
|
-
}
|
|
37125
|
-
|
|
37126
|
-
// (protected) true if probably prime (HAC 4.24, Miller-Rabin)
|
|
37127
|
-
function bnpMillerRabin(t) {
|
|
37128
|
-
const n1 = this.subtract(BigInteger.ONE)
|
|
37129
|
-
const k = n1.getLowestSetBit()
|
|
37130
|
-
if (k <= 0) {
|
|
37131
|
-
return false
|
|
37132
|
-
}
|
|
37133
|
-
const r = n1.shiftRight(k)
|
|
37134
|
-
t = (t + 1) >> 1
|
|
37135
|
-
if (t > lowprimes.length) {
|
|
37136
|
-
t = lowprimes.length
|
|
37137
|
-
}
|
|
37138
|
-
const a = nbi()
|
|
37139
|
-
for (let i = 0; i < t; ++i) {
|
|
37140
|
-
//Pick bases at random, instead of starting at 2
|
|
37141
|
-
a.fromInt(lowprimes[Math.floor(Math.random() * lowprimes.length)])
|
|
37142
|
-
let y = a.modPow(r, this)
|
|
37143
|
-
if (y.compareTo(BigInteger.ONE) != 0 && y.compareTo(n1) != 0) {
|
|
37144
|
-
let j = 1
|
|
37145
|
-
while (j++ < k && y.compareTo(n1) != 0) {
|
|
37146
|
-
y = y.modPowInt(2, this)
|
|
37147
|
-
if (y.compareTo(BigInteger.ONE) == 0) {
|
|
37148
|
-
return false
|
|
37149
|
-
}
|
|
37150
|
-
}
|
|
37151
|
-
if (y.compareTo(n1) != 0) {
|
|
37152
|
-
return false
|
|
37153
|
-
}
|
|
37154
|
-
}
|
|
37155
|
-
}
|
|
37156
|
-
return true
|
|
37157
|
-
}
|
|
37158
|
-
|
|
37159
|
-
// protected
|
|
37160
|
-
BigInteger.prototype.chunkSize = bnpChunkSize
|
|
37161
|
-
BigInteger.prototype.toRadix = bnpToRadix
|
|
37162
|
-
BigInteger.prototype.fromRadix = bnpFromRadix
|
|
37163
|
-
BigInteger.prototype.fromNumber = bnpFromNumber
|
|
37164
|
-
BigInteger.prototype.bitwiseTo = bnpBitwiseTo
|
|
37165
|
-
BigInteger.prototype.changeBit = bnpChangeBit
|
|
37166
|
-
BigInteger.prototype.addTo = bnpAddTo
|
|
37167
|
-
BigInteger.prototype.dMultiply = bnpDMultiply
|
|
37168
|
-
BigInteger.prototype.dAddOffset = bnpDAddOffset
|
|
37169
|
-
BigInteger.prototype.multiplyLowerTo = bnpMultiplyLowerTo
|
|
37170
|
-
BigInteger.prototype.multiplyUpperTo = bnpMultiplyUpperTo
|
|
37171
|
-
BigInteger.prototype.modInt = bnpModInt
|
|
37172
|
-
BigInteger.prototype.millerRabin = bnpMillerRabin
|
|
37173
|
-
|
|
37174
|
-
// public
|
|
37175
|
-
BigInteger.prototype.clone = bnClone
|
|
37176
|
-
BigInteger.prototype.intValue = bnIntValue
|
|
37177
|
-
BigInteger.prototype.byteValue = bnByteValue
|
|
37178
|
-
BigInteger.prototype.shortValue = bnShortValue
|
|
37179
|
-
BigInteger.prototype.signum = bnSigNum
|
|
37180
|
-
BigInteger.prototype.toByteArray = bnToByteArray
|
|
37181
|
-
BigInteger.prototype.equals = bnEquals
|
|
37182
|
-
BigInteger.prototype.min = bnMin
|
|
37183
|
-
BigInteger.prototype.max = bnMax
|
|
37184
|
-
BigInteger.prototype.and = bnAnd
|
|
37185
|
-
BigInteger.prototype.or = bnOr
|
|
37186
|
-
BigInteger.prototype.xor = bnXor
|
|
37187
|
-
BigInteger.prototype.andNot = bnAndNot
|
|
37188
|
-
BigInteger.prototype.not = bnNot
|
|
37189
|
-
BigInteger.prototype.shiftLeft = bnShiftLeft
|
|
37190
|
-
BigInteger.prototype.shiftRight = bnShiftRight
|
|
37191
|
-
BigInteger.prototype.getLowestSetBit = bnGetLowestSetBit
|
|
37192
|
-
BigInteger.prototype.bitCount = bnBitCount
|
|
37193
|
-
BigInteger.prototype.testBit = bnTestBit
|
|
37194
|
-
BigInteger.prototype.setBit = bnSetBit
|
|
37195
|
-
BigInteger.prototype.clearBit = bnClearBit
|
|
37196
|
-
BigInteger.prototype.flipBit = bnFlipBit
|
|
37197
|
-
BigInteger.prototype.add = bnAdd
|
|
37198
|
-
BigInteger.prototype.subtract = bnSubtract
|
|
37199
|
-
BigInteger.prototype.multiply = bnMultiply
|
|
37200
|
-
BigInteger.prototype.divide = bnDivide
|
|
37201
|
-
BigInteger.prototype.remainder = bnRemainder
|
|
37202
|
-
BigInteger.prototype.divideAndRemainder = bnDivideAndRemainder
|
|
37203
|
-
BigInteger.prototype.modPow = bnModPow
|
|
37204
|
-
BigInteger.prototype.modInverse = bnModInverse
|
|
37205
|
-
BigInteger.prototype.pow = bnPow
|
|
37206
|
-
BigInteger.prototype.gcd = bnGCD
|
|
37207
|
-
BigInteger.prototype.isProbablePrime = bnIsProbablePrime
|
|
37208
|
-
|
|
37209
|
-
// JSBN-specific extension
|
|
37210
|
-
BigInteger.prototype.square = bnSquare
|
|
37211
|
-
|
|
37212
|
-
// Expose the Barrett function
|
|
37213
|
-
BigInteger.prototype.Barrett = Barrett
|
|
37214
|
-
|
|
37215
|
-
// BigInteger interfaces not implemented in jsbn:
|
|
37216
|
-
|
|
37217
|
-
// BigInteger(int signum, byte[] magnitude)
|
|
37218
|
-
// double doubleValue()
|
|
37219
|
-
// float floatValue()
|
|
37220
|
-
// int hashCode()
|
|
37221
|
-
// long longValue()
|
|
37222
|
-
// static BigInteger valueOf(long val)
|
|
37223
|
-
|
|
37224
|
-
// Random number generator - requires a PRNG backend, e.g. prng4.js
|
|
37225
|
-
|
|
37226
|
-
// For best results, put code like
|
|
37227
|
-
// <body onClick='rng_seed_time();' onKeyPress='rng_seed_time();'>
|
|
37228
|
-
// in your main HTML document.
|
|
37229
|
-
|
|
37230
|
-
let rng_state
|
|
37231
|
-
let rng_pool
|
|
37232
|
-
let rng_pptr
|
|
37233
|
-
// Pool size must be a multiple of 4 and greater than 32.
|
|
37234
|
-
// An array of bytes the size of the pool will be passed to init()
|
|
37235
|
-
const rng_psize = 256
|
|
37236
|
-
|
|
37237
|
-
// Mix in a 32-bit integer into the pool
|
|
37238
|
-
function rng_seed_int(x) {
|
|
37239
|
-
rng_pool[rng_pptr++] ^= x & 255
|
|
37240
|
-
rng_pool[rng_pptr++] ^= (x >> 8) & 255
|
|
37241
|
-
rng_pool[rng_pptr++] ^= (x >> 16) & 255
|
|
37242
|
-
rng_pool[rng_pptr++] ^= (x >> 24) & 255
|
|
37243
|
-
if (rng_pptr >= rng_psize) {
|
|
37244
|
-
rng_pptr -= rng_psize
|
|
37245
|
-
}
|
|
37246
|
-
}
|
|
37247
|
-
|
|
37248
|
-
// Mix in the current time (w/milliseconds) into the pool
|
|
37249
|
-
function rng_seed_time() {
|
|
37250
|
-
rng_seed_int(new Date().getTime())
|
|
37251
|
-
}
|
|
37252
|
-
|
|
37253
|
-
// Initialize the pool with junk if needed.
|
|
37254
|
-
if (rng_pool == null) {
|
|
37255
|
-
rng_pool = new Array()
|
|
37256
|
-
rng_pptr = 0
|
|
37257
|
-
let t
|
|
37258
|
-
if (typeof window !== 'undefined' && window.crypto) {
|
|
37259
|
-
if (window.crypto.getRandomValues) {
|
|
37260
|
-
// Use webcrypto if available
|
|
37261
|
-
const ua = new Uint8Array(32)
|
|
37262
|
-
window.crypto.getRandomValues(ua)
|
|
37263
|
-
for (t = 0; t < 32; ++t) {
|
|
37264
|
-
rng_pool[rng_pptr++] = ua[t]
|
|
37265
|
-
}
|
|
37266
|
-
} else if (
|
|
37267
|
-
navigator.appName == 'Netscape' &&
|
|
37268
|
-
navigator.appVersion < '5'
|
|
37269
|
-
) {
|
|
37270
|
-
// Extract entropy (256 bits) from NS4 RNG if available
|
|
37271
|
-
const z = window.crypto.random(32)
|
|
37272
|
-
for (t = 0; t < z.length; ++t) {
|
|
37273
|
-
rng_pool[rng_pptr++] = z.charCodeAt(t) & 255
|
|
37274
|
-
}
|
|
37275
|
-
}
|
|
37276
|
-
}
|
|
37277
|
-
while (rng_pptr < rng_psize) {
|
|
37278
|
-
// extract some randomness from Math.random()
|
|
37279
|
-
t = Math.floor(65536 * Math.random())
|
|
37280
|
-
rng_pool[rng_pptr++] = t >>> 8
|
|
37281
|
-
rng_pool[rng_pptr++] = t & 255
|
|
37282
|
-
}
|
|
37283
|
-
rng_pptr = 0
|
|
37284
|
-
rng_seed_time()
|
|
37285
|
-
//rng_seed_int(window.screenX);
|
|
37286
|
-
//rng_seed_int(window.screenY);
|
|
37287
|
-
}
|
|
37288
|
-
function rng_get_byte() {
|
|
37289
|
-
if (rng_state == null) {
|
|
37290
|
-
rng_seed_time()
|
|
37291
|
-
rng_state = prng_newstate()
|
|
37292
|
-
rng_state.init(rng_pool)
|
|
37293
|
-
for (rng_pptr = 0; rng_pptr < rng_pool.length; ++rng_pptr) {
|
|
37294
|
-
rng_pool[rng_pptr] = 0
|
|
37295
|
-
}
|
|
37296
|
-
rng_pptr = 0
|
|
37297
|
-
//rng_pool = null;
|
|
37298
|
-
}
|
|
37299
|
-
// TODO: allow reseeding after first request
|
|
37300
|
-
return rng_state.next()
|
|
37301
|
-
}
|
|
37302
|
-
function rng_get_bytes(ba) {
|
|
37303
|
-
let i
|
|
37304
|
-
for (i = 0; i < ba.length; ++i) {
|
|
37305
|
-
ba[i] = rng_get_byte()
|
|
37306
|
-
}
|
|
37307
|
-
}
|
|
37308
|
-
function SecureRandom() {}
|
|
37309
|
-
SecureRandom.prototype.nextBytes = rng_get_bytes
|
|
37310
|
-
|
|
37311
|
-
// prng4.js - uses Arcfour as a PRNG
|
|
37312
|
-
|
|
37313
|
-
function Arcfour() {
|
|
37314
|
-
this.i = 0
|
|
37315
|
-
this.j = 0
|
|
37316
|
-
this.S = new Array()
|
|
37317
|
-
}
|
|
37318
|
-
|
|
37319
|
-
// Initialize arcfour context from key, an array of ints, each from [0..255]
|
|
37320
|
-
function ARC4init(key) {
|
|
37321
|
-
let i, j, t
|
|
37322
|
-
for (i = 0; i < 256; ++i) {
|
|
37323
|
-
this.S[i] = i
|
|
37324
|
-
}
|
|
37325
|
-
j = 0
|
|
37326
|
-
for (i = 0; i < 256; ++i) {
|
|
37327
|
-
j = (j + this.S[i] + key[i % key.length]) & 255
|
|
37328
|
-
t = this.S[i]
|
|
37329
|
-
this.S[i] = this.S[j]
|
|
37330
|
-
this.S[j] = t
|
|
37331
|
-
}
|
|
37332
|
-
this.i = 0
|
|
37333
|
-
this.j = 0
|
|
37334
|
-
}
|
|
37335
|
-
function ARC4next() {
|
|
37336
|
-
let t
|
|
37337
|
-
this.i = (this.i + 1) & 255
|
|
37338
|
-
this.j = (this.j + this.S[this.i]) & 255
|
|
37339
|
-
t = this.S[this.i]
|
|
37340
|
-
this.S[this.i] = this.S[this.j]
|
|
37341
|
-
this.S[this.j] = t
|
|
37342
|
-
return this.S[(t + this.S[this.i]) & 255]
|
|
37343
|
-
}
|
|
37344
|
-
Arcfour.prototype.init = ARC4init
|
|
37345
|
-
Arcfour.prototype.next = ARC4next
|
|
37346
|
-
|
|
37347
|
-
// Plug in your RNG constructor here
|
|
37348
|
-
function prng_newstate() {
|
|
37349
|
-
return new Arcfour()
|
|
37350
|
-
}
|
|
37351
|
-
{
|
|
37352
|
-
module.exports = {
|
|
37353
|
-
default: BigInteger,
|
|
37354
|
-
BigInteger: BigInteger,
|
|
37355
|
-
SecureRandom: SecureRandom
|
|
37356
|
-
}
|
|
37357
|
-
}
|
|
37358
|
-
}).call(this)
|
|
37359
|
-
})(jsbn)
|
|
37360
|
-
return jsbn.exports
|
|
37361
|
-
}
|
|
37362
|
-
|
|
37363
|
-
const sprintf = {}
|
|
37364
|
-
|
|
37365
|
-
/* global window, exports, define */
|
|
37366
|
-
let hasRequiredSprintf
|
|
37367
|
-
function requireSprintf() {
|
|
37368
|
-
if (hasRequiredSprintf) {
|
|
37369
|
-
return sprintf
|
|
37370
|
-
}
|
|
37371
|
-
hasRequiredSprintf = 1
|
|
37372
|
-
;(function (exports) {
|
|
37373
|
-
!(function () {
|
|
37374
|
-
const re = {
|
|
37375
|
-
not_type: /[^T]/,
|
|
37376
|
-
not_primitive: /[^v]/,
|
|
37377
|
-
number: /[diefg]/,
|
|
37378
|
-
numeric_arg: /[bcdiefguxX]/,
|
|
37379
|
-
json: /[j]/,
|
|
37380
|
-
text: /^[^\x25]+/,
|
|
37381
|
-
modulo: /^\x25{2}/,
|
|
37382
|
-
placeholder:
|
|
37383
|
-
/^\x25(?:([1-9]\d*)\$|\(([^)]+)\))?(\+)?(0|'[^$])?(-)?(\d+)?(?:\.(\d+))?([b-gijostTuvxX])/,
|
|
37384
|
-
key: /^([a-z_][a-z_\d]*)/i,
|
|
37385
|
-
key_access: /^\.([a-z_][a-z_\d]*)/i,
|
|
37386
|
-
index_access: /^\[(\d+)\]/,
|
|
37387
|
-
sign: /^[+-]/
|
|
37388
|
-
}
|
|
37389
|
-
function sprintf(key) {
|
|
37390
|
-
// `arguments` is not an array, but should be fine for this call
|
|
37391
|
-
return sprintf_format(sprintf_parse(key), arguments)
|
|
37392
|
-
}
|
|
37393
|
-
function vsprintf(fmt, argv) {
|
|
37394
|
-
return sprintf.apply(null, [fmt].concat(argv || []))
|
|
37395
|
-
}
|
|
37396
|
-
function sprintf_format(parse_tree, argv) {
|
|
37397
|
-
let cursor = 1,
|
|
37398
|
-
tree_length = parse_tree.length,
|
|
37399
|
-
arg,
|
|
37400
|
-
output = '',
|
|
37401
|
-
i,
|
|
37402
|
-
k,
|
|
37403
|
-
ph,
|
|
37404
|
-
pad,
|
|
37405
|
-
pad_character,
|
|
37406
|
-
pad_length,
|
|
37407
|
-
is_positive,
|
|
37408
|
-
sign
|
|
37409
|
-
for (i = 0; i < tree_length; i++) {
|
|
37410
|
-
if (typeof parse_tree[i] === 'string') {
|
|
37411
|
-
output += parse_tree[i]
|
|
37412
|
-
} else if (typeof parse_tree[i] === 'object') {
|
|
37413
|
-
ph = parse_tree[i] // convenience purposes only
|
|
37414
|
-
if (ph.keys) {
|
|
37415
|
-
// keyword argument
|
|
37416
|
-
arg = argv[cursor]
|
|
37417
|
-
for (k = 0; k < ph.keys.length; k++) {
|
|
37418
|
-
if (arg == undefined) {
|
|
37419
|
-
throw new Error(
|
|
37420
|
-
sprintf(
|
|
37421
|
-
'[sprintf] Cannot access property "%s" of undefined value "%s"',
|
|
37422
|
-
ph.keys[k],
|
|
37423
|
-
ph.keys[k - 1]
|
|
37424
|
-
)
|
|
37425
|
-
)
|
|
37426
|
-
}
|
|
37427
|
-
arg = arg[ph.keys[k]]
|
|
37428
|
-
}
|
|
37429
|
-
} else if (ph.param_no) {
|
|
37430
|
-
// positional argument (explicit)
|
|
37431
|
-
arg = argv[ph.param_no]
|
|
37432
|
-
} else {
|
|
37433
|
-
// positional argument (implicit)
|
|
37434
|
-
arg = argv[cursor++]
|
|
37435
|
-
}
|
|
37436
|
-
if (
|
|
37437
|
-
re.not_type.test(ph.type) &&
|
|
37438
|
-
re.not_primitive.test(ph.type) &&
|
|
37439
|
-
arg instanceof Function
|
|
37440
|
-
) {
|
|
37441
|
-
arg = arg()
|
|
37442
|
-
}
|
|
37443
|
-
if (
|
|
37444
|
-
re.numeric_arg.test(ph.type) &&
|
|
37445
|
-
typeof arg !== 'number' &&
|
|
37446
|
-
isNaN(arg)
|
|
37447
|
-
) {
|
|
37448
|
-
throw new TypeError(
|
|
37449
|
-
sprintf('[sprintf] expecting number but found %T', arg)
|
|
37450
|
-
)
|
|
37451
|
-
}
|
|
37452
|
-
if (re.number.test(ph.type)) {
|
|
37453
|
-
is_positive = arg >= 0
|
|
37454
|
-
}
|
|
37455
|
-
switch (ph.type) {
|
|
37456
|
-
case 'b':
|
|
37457
|
-
arg = parseInt(arg, 10).toString(2)
|
|
37458
|
-
break
|
|
37459
|
-
case 'c':
|
|
37460
|
-
arg = String.fromCharCode(parseInt(arg, 10))
|
|
37461
|
-
break
|
|
37462
|
-
case 'd':
|
|
37463
|
-
case 'i':
|
|
37464
|
-
arg = parseInt(arg, 10)
|
|
37465
|
-
break
|
|
37466
|
-
case 'j':
|
|
37467
|
-
arg = JSON.stringify(
|
|
37468
|
-
arg,
|
|
37469
|
-
null,
|
|
37470
|
-
ph.width ? parseInt(ph.width) : 0
|
|
37471
|
-
)
|
|
37472
|
-
break
|
|
37473
|
-
case 'e':
|
|
37474
|
-
arg = ph.precision
|
|
37475
|
-
? parseFloat(arg).toExponential(ph.precision)
|
|
37476
|
-
: parseFloat(arg).toExponential()
|
|
37477
|
-
break
|
|
37478
|
-
case 'f':
|
|
37479
|
-
arg = ph.precision
|
|
37480
|
-
? parseFloat(arg).toFixed(ph.precision)
|
|
37481
|
-
: parseFloat(arg)
|
|
37482
|
-
break
|
|
37483
|
-
case 'g':
|
|
37484
|
-
arg = ph.precision
|
|
37485
|
-
? String(Number(arg.toPrecision(ph.precision)))
|
|
37486
|
-
: parseFloat(arg)
|
|
37487
|
-
break
|
|
37488
|
-
case 'o':
|
|
37489
|
-
arg = (parseInt(arg, 10) >>> 0).toString(8)
|
|
37490
|
-
break
|
|
37491
|
-
case 's':
|
|
37492
|
-
arg = String(arg)
|
|
37493
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg
|
|
37494
|
-
break
|
|
37495
|
-
case 't':
|
|
37496
|
-
arg = String(!!arg)
|
|
37497
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg
|
|
37498
|
-
break
|
|
37499
|
-
case 'T':
|
|
37500
|
-
arg = Object.prototype.toString
|
|
37501
|
-
.call(arg)
|
|
37502
|
-
.slice(8, -1)
|
|
37503
|
-
.toLowerCase()
|
|
37504
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg
|
|
37505
|
-
break
|
|
37506
|
-
case 'u':
|
|
37507
|
-
arg = parseInt(arg, 10) >>> 0
|
|
37508
|
-
break
|
|
37509
|
-
case 'v':
|
|
37510
|
-
arg = arg.valueOf()
|
|
37511
|
-
arg = ph.precision ? arg.substring(0, ph.precision) : arg
|
|
37512
|
-
break
|
|
37513
|
-
case 'x':
|
|
37514
|
-
arg = (parseInt(arg, 10) >>> 0).toString(16)
|
|
37515
|
-
break
|
|
37516
|
-
case 'X':
|
|
37517
|
-
arg = (parseInt(arg, 10) >>> 0).toString(16).toUpperCase()
|
|
37518
|
-
break
|
|
37519
|
-
}
|
|
37520
|
-
if (re.json.test(ph.type)) {
|
|
37521
|
-
output += arg
|
|
37522
|
-
} else {
|
|
37523
|
-
if (re.number.test(ph.type) && (!is_positive || ph.sign)) {
|
|
37524
|
-
sign = is_positive ? '+' : '-'
|
|
37525
|
-
arg = arg.toString().replace(re.sign, '')
|
|
37526
|
-
} else {
|
|
37527
|
-
sign = ''
|
|
37528
|
-
}
|
|
37529
|
-
pad_character = ph.pad_char
|
|
37530
|
-
? ph.pad_char === '0'
|
|
37531
|
-
? '0'
|
|
37532
|
-
: ph.pad_char.charAt(1)
|
|
37533
|
-
: ' '
|
|
37534
|
-
pad_length = ph.width - (sign + arg).length
|
|
37535
|
-
pad = ph.width
|
|
37536
|
-
? pad_length > 0
|
|
37537
|
-
? pad_character.repeat(pad_length)
|
|
37538
|
-
: ''
|
|
37539
|
-
: ''
|
|
37540
|
-
output += ph.align
|
|
37541
|
-
? sign + arg + pad
|
|
37542
|
-
: pad_character === '0'
|
|
37543
|
-
? sign + pad + arg
|
|
37544
|
-
: pad + sign + arg
|
|
37545
|
-
}
|
|
37546
|
-
}
|
|
37547
|
-
}
|
|
37548
|
-
return output
|
|
37549
|
-
}
|
|
37550
|
-
const sprintf_cache = Object.create(null)
|
|
37551
|
-
function sprintf_parse(fmt) {
|
|
37552
|
-
if (sprintf_cache[fmt]) {
|
|
37553
|
-
return sprintf_cache[fmt]
|
|
37554
|
-
}
|
|
37555
|
-
let _fmt = fmt,
|
|
37556
|
-
match,
|
|
37557
|
-
parse_tree = [],
|
|
37558
|
-
arg_names = 0
|
|
37559
|
-
while (_fmt) {
|
|
37560
|
-
if ((match = re.text.exec(_fmt)) !== null) {
|
|
37561
|
-
parse_tree.push(match[0])
|
|
37562
|
-
} else if ((match = re.modulo.exec(_fmt)) !== null) {
|
|
37563
|
-
parse_tree.push('%')
|
|
37564
|
-
} else if ((match = re.placeholder.exec(_fmt)) !== null) {
|
|
37565
|
-
if (match[2]) {
|
|
37566
|
-
arg_names |= 1
|
|
37567
|
-
let field_list = [],
|
|
37568
|
-
replacement_field = match[2],
|
|
37569
|
-
field_match = []
|
|
37570
|
-
if ((field_match = re.key.exec(replacement_field)) !== null) {
|
|
37571
|
-
field_list.push(field_match[1])
|
|
37572
|
-
while (
|
|
37573
|
-
(replacement_field = replacement_field.substring(
|
|
37574
|
-
field_match[0].length
|
|
37575
|
-
)) !== ''
|
|
37576
|
-
) {
|
|
37577
|
-
if (
|
|
37578
|
-
(field_match = re.key_access.exec(replacement_field)) !==
|
|
37579
|
-
null
|
|
37580
|
-
) {
|
|
37581
|
-
field_list.push(field_match[1])
|
|
37582
|
-
} else if (
|
|
37583
|
-
(field_match = re.index_access.exec(replacement_field)) !==
|
|
37584
|
-
null
|
|
37585
|
-
) {
|
|
37586
|
-
field_list.push(field_match[1])
|
|
37587
|
-
} else {
|
|
37588
|
-
throw new SyntaxError(
|
|
37589
|
-
'[sprintf] failed to parse named argument key'
|
|
37590
|
-
)
|
|
37591
|
-
}
|
|
37592
|
-
}
|
|
37593
|
-
} else {
|
|
37594
|
-
throw new SyntaxError(
|
|
37595
|
-
'[sprintf] failed to parse named argument key'
|
|
37596
|
-
)
|
|
37597
|
-
}
|
|
37598
|
-
match[2] = field_list
|
|
37599
|
-
} else {
|
|
37600
|
-
arg_names |= 2
|
|
37601
|
-
}
|
|
37602
|
-
if (arg_names === 3) {
|
|
37603
|
-
throw new Error(
|
|
37604
|
-
'[sprintf] mixing positional and named placeholders is not (yet) supported'
|
|
37605
|
-
)
|
|
37606
|
-
}
|
|
37607
|
-
parse_tree.push({
|
|
37608
|
-
placeholder: match[0],
|
|
37609
|
-
param_no: match[1],
|
|
37610
|
-
keys: match[2],
|
|
37611
|
-
sign: match[3],
|
|
37612
|
-
pad_char: match[4],
|
|
37613
|
-
align: match[5],
|
|
37614
|
-
width: match[6],
|
|
37615
|
-
precision: match[7],
|
|
37616
|
-
type: match[8]
|
|
37617
|
-
})
|
|
37618
|
-
} else {
|
|
37619
|
-
throw new SyntaxError('[sprintf] unexpected placeholder')
|
|
37620
|
-
}
|
|
37621
|
-
_fmt = _fmt.substring(match[0].length)
|
|
37622
|
-
}
|
|
37623
|
-
return (sprintf_cache[fmt] = parse_tree)
|
|
37624
|
-
}
|
|
37625
|
-
|
|
37626
|
-
/**
|
|
37627
|
-
* export to either browser or node.js
|
|
37628
|
-
*/
|
|
37629
|
-
/* eslint-disable quote-props */
|
|
37630
|
-
{
|
|
37631
|
-
exports['sprintf'] = sprintf
|
|
37632
|
-
exports['vsprintf'] = vsprintf
|
|
37633
|
-
}
|
|
37634
|
-
if (typeof window !== 'undefined') {
|
|
37635
|
-
window['sprintf'] = sprintf
|
|
37636
|
-
window['vsprintf'] = vsprintf
|
|
37637
|
-
}
|
|
37638
|
-
/* eslint-enable quote-props */
|
|
37639
|
-
})() // eslint-disable-line
|
|
37640
|
-
})(sprintf)
|
|
37641
|
-
return sprintf
|
|
37642
|
-
}
|
|
37643
|
-
|
|
37644
34068
|
let hasRequiredIpv4
|
|
37645
34069
|
function requireIpv4() {
|
|
37646
34070
|
if (hasRequiredIpv4) {
|
|
@@ -37709,8 +34133,6 @@ function requireIpv4() {
|
|
|
37709
34133
|
const common = __importStar(requireCommon())
|
|
37710
34134
|
const constants = __importStar(requireConstants$1())
|
|
37711
34135
|
const address_error_1 = requireAddressError()
|
|
37712
|
-
const jsbn_1 = requireJsbn()
|
|
37713
|
-
const sprintf_js_1 = requireSprintf()
|
|
37714
34136
|
/**
|
|
37715
34137
|
* Represents an IPv4 address
|
|
37716
34138
|
* @class Address4
|
|
@@ -37831,7 +34253,7 @@ function requireIpv4() {
|
|
|
37831
34253
|
*/
|
|
37832
34254
|
toHex() {
|
|
37833
34255
|
return this.parsedAddress
|
|
37834
|
-
.map(part =>
|
|
34256
|
+
.map(part => common.stringToPaddedHex(part))
|
|
37835
34257
|
.join(':')
|
|
37836
34258
|
}
|
|
37837
34259
|
/**
|
|
@@ -37853,39 +34275,32 @@ function requireIpv4() {
|
|
|
37853
34275
|
const output = []
|
|
37854
34276
|
let i
|
|
37855
34277
|
for (i = 0; i < constants.GROUPS; i += 2) {
|
|
37856
|
-
|
|
37857
|
-
|
|
37858
|
-
parseInt(this.parsedAddress[i], 10),
|
|
37859
|
-
parseInt(this.parsedAddress[i + 1], 10)
|
|
34278
|
+
output.push(
|
|
34279
|
+
`${common.stringToPaddedHex(this.parsedAddress[i])}${common.stringToPaddedHex(this.parsedAddress[i + 1])}`
|
|
37860
34280
|
)
|
|
37861
|
-
output.push((0, sprintf_js_1.sprintf)('%x', parseInt(hex, 16)))
|
|
37862
34281
|
}
|
|
37863
34282
|
return output.join(':')
|
|
37864
34283
|
}
|
|
37865
34284
|
/**
|
|
37866
|
-
* Returns the address as a
|
|
34285
|
+
* Returns the address as a `bigint`
|
|
37867
34286
|
* @memberof Address4
|
|
37868
34287
|
* @instance
|
|
37869
|
-
* @returns {
|
|
34288
|
+
* @returns {bigint}
|
|
37870
34289
|
*/
|
|
37871
|
-
|
|
37872
|
-
return
|
|
37873
|
-
this.parsedAddress
|
|
37874
|
-
.map(n => (0, sprintf_js_1.sprintf)('%02x', parseInt(n, 10)))
|
|
37875
|
-
.join(''),
|
|
37876
|
-
16
|
|
34290
|
+
bigInt() {
|
|
34291
|
+
return BigInt(
|
|
34292
|
+
`0x${this.parsedAddress.map(n => common.stringToPaddedHex(n)).join('')}`
|
|
37877
34293
|
)
|
|
37878
34294
|
}
|
|
37879
34295
|
/**
|
|
37880
34296
|
* Helper function getting start address.
|
|
37881
34297
|
* @memberof Address4
|
|
37882
34298
|
* @instance
|
|
37883
|
-
* @returns {
|
|
34299
|
+
* @returns {bigint}
|
|
37884
34300
|
*/
|
|
37885
34301
|
_startAddress() {
|
|
37886
|
-
return
|
|
37887
|
-
this.mask() + '0'.repeat(constants.BITS - this.subnetMask)
|
|
37888
|
-
2
|
|
34302
|
+
return BigInt(
|
|
34303
|
+
`0b${this.mask() + '0'.repeat(constants.BITS - this.subnetMask)}`
|
|
37889
34304
|
)
|
|
37890
34305
|
}
|
|
37891
34306
|
/**
|
|
@@ -37896,7 +34311,7 @@ function requireIpv4() {
|
|
|
37896
34311
|
* @returns {Address4}
|
|
37897
34312
|
*/
|
|
37898
34313
|
startAddress() {
|
|
37899
|
-
return Address4.
|
|
34314
|
+
return Address4.fromBigInt(this._startAddress())
|
|
37900
34315
|
}
|
|
37901
34316
|
/**
|
|
37902
34317
|
* The first host address in the range given by this address's subnet ie
|
|
@@ -37906,19 +34321,18 @@ function requireIpv4() {
|
|
|
37906
34321
|
* @returns {Address4}
|
|
37907
34322
|
*/
|
|
37908
34323
|
startAddressExclusive() {
|
|
37909
|
-
const adjust =
|
|
37910
|
-
return Address4.
|
|
34324
|
+
const adjust = BigInt('1')
|
|
34325
|
+
return Address4.fromBigInt(this._startAddress() + adjust)
|
|
37911
34326
|
}
|
|
37912
34327
|
/**
|
|
37913
34328
|
* Helper function getting end address.
|
|
37914
34329
|
* @memberof Address4
|
|
37915
34330
|
* @instance
|
|
37916
|
-
* @returns {
|
|
34331
|
+
* @returns {bigint}
|
|
37917
34332
|
*/
|
|
37918
34333
|
_endAddress() {
|
|
37919
|
-
return
|
|
37920
|
-
this.mask() + '1'.repeat(constants.BITS - this.subnetMask)
|
|
37921
|
-
2
|
|
34334
|
+
return BigInt(
|
|
34335
|
+
`0b${this.mask() + '1'.repeat(constants.BITS - this.subnetMask)}`
|
|
37922
34336
|
)
|
|
37923
34337
|
}
|
|
37924
34338
|
/**
|
|
@@ -37929,7 +34343,7 @@ function requireIpv4() {
|
|
|
37929
34343
|
* @returns {Address4}
|
|
37930
34344
|
*/
|
|
37931
34345
|
endAddress() {
|
|
37932
|
-
return Address4.
|
|
34346
|
+
return Address4.fromBigInt(this._endAddress())
|
|
37933
34347
|
}
|
|
37934
34348
|
/**
|
|
37935
34349
|
* The last host address in the range given by this address's subnet ie
|
|
@@ -37939,18 +34353,18 @@ function requireIpv4() {
|
|
|
37939
34353
|
* @returns {Address4}
|
|
37940
34354
|
*/
|
|
37941
34355
|
endAddressExclusive() {
|
|
37942
|
-
const adjust =
|
|
37943
|
-
return Address4.
|
|
34356
|
+
const adjust = BigInt('1')
|
|
34357
|
+
return Address4.fromBigInt(this._endAddress() - adjust)
|
|
37944
34358
|
}
|
|
37945
34359
|
/**
|
|
37946
|
-
* Converts a
|
|
34360
|
+
* Converts a BigInt to a v4 address object
|
|
37947
34361
|
* @memberof Address4
|
|
37948
34362
|
* @static
|
|
37949
|
-
* @param {
|
|
34363
|
+
* @param {bigint} bigInt - a BigInt to convert
|
|
37950
34364
|
* @returns {Address4}
|
|
37951
34365
|
*/
|
|
37952
|
-
static
|
|
37953
|
-
return Address4.
|
|
34366
|
+
static fromBigInt(bigInt) {
|
|
34367
|
+
return Address4.fromHex(bigInt.toString(16))
|
|
37954
34368
|
}
|
|
37955
34369
|
/**
|
|
37956
34370
|
* Returns the first n bits of the address, defaulting to the
|
|
@@ -37990,7 +34404,7 @@ function requireIpv4() {
|
|
|
37990
34404
|
if (options.omitSuffix) {
|
|
37991
34405
|
return reversed
|
|
37992
34406
|
}
|
|
37993
|
-
return
|
|
34407
|
+
return `${reversed}.in-addr.arpa.`
|
|
37994
34408
|
}
|
|
37995
34409
|
/**
|
|
37996
34410
|
* Returns true if the given address is a multicast address
|
|
@@ -38008,7 +34422,7 @@ function requireIpv4() {
|
|
|
38008
34422
|
* @returns {string}
|
|
38009
34423
|
*/
|
|
38010
34424
|
binaryZeroPad() {
|
|
38011
|
-
return this.
|
|
34425
|
+
return this.bigInt().toString(2).padStart(constants.BITS, '0')
|
|
38012
34426
|
}
|
|
38013
34427
|
/**
|
|
38014
34428
|
* Groups an IPv4 address for inclusion at the end of an IPv6 address
|
|
@@ -38018,11 +34432,7 @@ function requireIpv4() {
|
|
|
38018
34432
|
const segments = this.parsedAddress
|
|
38019
34433
|
return this.address.replace(
|
|
38020
34434
|
constants.RE_ADDRESS,
|
|
38021
|
-
(0,
|
|
38022
|
-
'<span class="hover-group group-v4 group-6">%s</span>.<span class="hover-group group-v4 group-7">%s</span>',
|
|
38023
|
-
segments.slice(0, 2).join('.'),
|
|
38024
|
-
segments.slice(2, 4).join('.')
|
|
38025
|
-
)
|
|
34435
|
+
`<span class="hover-group group-v4 group-6">${segments.slice(0, 2).join('.')}</span>.<span class="hover-group group-v4 group-7">${segments.slice(2, 4).join('.')}</span>`
|
|
38026
34436
|
)
|
|
38027
34437
|
}
|
|
38028
34438
|
}
|
|
@@ -38126,8 +34536,8 @@ function requireConstants() {
|
|
|
38126
34536
|
* @static
|
|
38127
34537
|
*/
|
|
38128
34538
|
constants.RE_ZONE_STRING = /%.*$/
|
|
38129
|
-
constants.RE_URL =
|
|
38130
|
-
constants.RE_URL_WITH_PORT =
|
|
34539
|
+
constants.RE_URL = /^\[{0,1}([0-9a-f:]+)\]{0,1}/
|
|
34540
|
+
constants.RE_URL_WITH_PORT = /\[([0-9a-f:]+)\]:([0-9]{1,5})/
|
|
38131
34541
|
return constants
|
|
38132
34542
|
}
|
|
38133
34543
|
|
|
@@ -38142,19 +34552,16 @@ function requireHelpers$1() {
|
|
|
38142
34552
|
Object.defineProperty(helpers, '__esModule', {
|
|
38143
34553
|
value: true
|
|
38144
34554
|
})
|
|
38145
|
-
helpers.
|
|
38146
|
-
|
|
38147
|
-
|
|
38148
|
-
|
|
38149
|
-
void 0
|
|
38150
|
-
const sprintf_js_1 = requireSprintf()
|
|
34555
|
+
helpers.spanAllZeroes = spanAllZeroes
|
|
34556
|
+
helpers.spanAll = spanAll
|
|
34557
|
+
helpers.spanLeadingZeroes = spanLeadingZeroes
|
|
34558
|
+
helpers.simpleGroup = simpleGroup
|
|
38151
34559
|
/**
|
|
38152
34560
|
* @returns {String} the string with all zeroes contained in a <span>
|
|
38153
34561
|
*/
|
|
38154
34562
|
function spanAllZeroes(s) {
|
|
38155
34563
|
return s.replace(/(0+)/g, '<span class="zero">$1</span>')
|
|
38156
34564
|
}
|
|
38157
|
-
helpers.spanAllZeroes = spanAllZeroes
|
|
38158
34565
|
/**
|
|
38159
34566
|
* @returns {String} the string with each character contained in a <span>
|
|
38160
34567
|
*/
|
|
@@ -38163,16 +34570,10 @@ function requireHelpers$1() {
|
|
|
38163
34570
|
return letters
|
|
38164
34571
|
.map(
|
|
38165
34572
|
(n, i) =>
|
|
38166
|
-
(
|
|
38167
|
-
'<span class="digit value-%s position-%d">%s</span>',
|
|
38168
|
-
n,
|
|
38169
|
-
i + offset,
|
|
38170
|
-
spanAllZeroes(n)
|
|
38171
|
-
) // XXX Use #base-2 .value-0 instead?
|
|
34573
|
+
`<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`
|
|
38172
34574
|
)
|
|
38173
34575
|
.join('')
|
|
38174
34576
|
}
|
|
38175
|
-
helpers.spanAll = spanAll
|
|
38176
34577
|
function spanLeadingZeroesSimple(group) {
|
|
38177
34578
|
return group.replace(/^(0+)/, '<span class="zero">$1</span>')
|
|
38178
34579
|
}
|
|
@@ -38183,7 +34584,6 @@ function requireHelpers$1() {
|
|
|
38183
34584
|
const groups = address.split(':')
|
|
38184
34585
|
return groups.map(g => spanLeadingZeroesSimple(g)).join(':')
|
|
38185
34586
|
}
|
|
38186
|
-
helpers.spanLeadingZeroes = spanLeadingZeroes
|
|
38187
34587
|
/**
|
|
38188
34588
|
* Groups an address
|
|
38189
34589
|
* @returns {String} a grouped address
|
|
@@ -38194,14 +34594,9 @@ function requireHelpers$1() {
|
|
|
38194
34594
|
if (/group-v4/.test(g)) {
|
|
38195
34595
|
return g
|
|
38196
34596
|
}
|
|
38197
|
-
return (
|
|
38198
|
-
'<span class="hover-group group-%d">%s</span>',
|
|
38199
|
-
i + offset,
|
|
38200
|
-
spanLeadingZeroesSimple(g)
|
|
38201
|
-
)
|
|
34597
|
+
return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`
|
|
38202
34598
|
})
|
|
38203
34599
|
}
|
|
38204
|
-
helpers.simpleGroup = simpleGroup
|
|
38205
34600
|
return helpers
|
|
38206
34601
|
}
|
|
38207
34602
|
|
|
@@ -38270,25 +34665,21 @@ function requireRegularExpressions() {
|
|
|
38270
34665
|
Object.defineProperty(regularExpressions, '__esModule', {
|
|
38271
34666
|
value: true
|
|
38272
34667
|
})
|
|
38273
|
-
regularExpressions.
|
|
38274
|
-
|
|
38275
|
-
|
|
38276
|
-
|
|
38277
|
-
|
|
38278
|
-
void 0
|
|
34668
|
+
regularExpressions.ADDRESS_BOUNDARY = void 0
|
|
34669
|
+
regularExpressions.groupPossibilities = groupPossibilities
|
|
34670
|
+
regularExpressions.padGroup = padGroup
|
|
34671
|
+
regularExpressions.simpleRegularExpression = simpleRegularExpression
|
|
34672
|
+
regularExpressions.possibleElisions = possibleElisions
|
|
38279
34673
|
const v6 = __importStar(requireConstants())
|
|
38280
|
-
const sprintf_js_1 = requireSprintf()
|
|
38281
34674
|
function groupPossibilities(possibilities) {
|
|
38282
|
-
return (
|
|
34675
|
+
return `(${possibilities.join('|')})`
|
|
38283
34676
|
}
|
|
38284
|
-
regularExpressions.groupPossibilities = groupPossibilities
|
|
38285
34677
|
function padGroup(group) {
|
|
38286
34678
|
if (group.length < 4) {
|
|
38287
|
-
return
|
|
34679
|
+
return `0{0,${4 - group.length}}${group}`
|
|
38288
34680
|
}
|
|
38289
34681
|
return group
|
|
38290
34682
|
}
|
|
38291
|
-
regularExpressions.padGroup = padGroup
|
|
38292
34683
|
regularExpressions.ADDRESS_BOUNDARY = '[^A-Fa-f0-9:]'
|
|
38293
34684
|
function simpleRegularExpression(groups) {
|
|
38294
34685
|
const zeroIndexes = []
|
|
@@ -38315,7 +34706,6 @@ function requireRegularExpressions() {
|
|
|
38315
34706
|
possibilities.push(groups.map(padGroup).join(':'))
|
|
38316
34707
|
return groupPossibilities(possibilities)
|
|
38317
34708
|
}
|
|
38318
|
-
regularExpressions.simpleRegularExpression = simpleRegularExpression
|
|
38319
34709
|
function possibleElisions(elidedGroups, moreLeft, moreRight) {
|
|
38320
34710
|
const left = moreLeft ? '' : ':'
|
|
38321
34711
|
const right = moreRight ? '' : ':'
|
|
@@ -38333,32 +34723,21 @@ function requireRegularExpressions() {
|
|
|
38333
34723
|
possibilities.push(':')
|
|
38334
34724
|
}
|
|
38335
34725
|
// 4. elision from the left side
|
|
38336
|
-
possibilities.push(
|
|
38337
|
-
(0, sprintf_js_1.sprintf)('%s(:0{1,4}){1,%d}', left, elidedGroups - 1)
|
|
38338
|
-
)
|
|
34726
|
+
possibilities.push(`${left}(:0{1,4}){1,${elidedGroups - 1}}`)
|
|
38339
34727
|
// 5. elision from the right side
|
|
38340
|
-
possibilities.push(
|
|
38341
|
-
(0, sprintf_js_1.sprintf)('(0{1,4}:){1,%d}%s', elidedGroups - 1, right)
|
|
38342
|
-
)
|
|
34728
|
+
possibilities.push(`(0{1,4}:){1,${elidedGroups - 1}}${right}`)
|
|
38343
34729
|
// 6. no elision
|
|
38344
|
-
possibilities.push(
|
|
38345
|
-
(0, sprintf_js_1.sprintf)('(0{1,4}:){%d}0{1,4}', elidedGroups - 1)
|
|
38346
|
-
)
|
|
34730
|
+
possibilities.push(`(0{1,4}:){${elidedGroups - 1}}0{1,4}`)
|
|
38347
34731
|
// 7. elision (including sloppy elision) from the middle
|
|
38348
34732
|
for (let groups = 1; groups < elidedGroups - 1; groups++) {
|
|
38349
34733
|
for (let position = 1; position < elidedGroups - groups; position++) {
|
|
38350
34734
|
possibilities.push(
|
|
38351
|
-
(0,
|
|
38352
|
-
'(0{1,4}:){%d}:(0{1,4}:){%d}0{1,4}',
|
|
38353
|
-
position,
|
|
38354
|
-
elidedGroups - position - groups - 1
|
|
38355
|
-
)
|
|
34735
|
+
`(0{1,4}:){${position}}:(0{1,4}:){${elidedGroups - position - groups - 1}}0{1,4}`
|
|
38356
34736
|
)
|
|
38357
34737
|
}
|
|
38358
34738
|
}
|
|
38359
34739
|
return groupPossibilities(possibilities)
|
|
38360
34740
|
}
|
|
38361
|
-
regularExpressions.possibleElisions = possibleElisions
|
|
38362
34741
|
return regularExpressions
|
|
38363
34742
|
}
|
|
38364
34743
|
|
|
@@ -38435,8 +34814,7 @@ function requireIpv6() {
|
|
|
38435
34814
|
const ipv4_1 = requireIpv4()
|
|
38436
34815
|
const regular_expressions_1 = requireRegularExpressions()
|
|
38437
34816
|
const address_error_1 = requireAddressError()
|
|
38438
|
-
const
|
|
38439
|
-
const sprintf_js_1 = requireSprintf()
|
|
34817
|
+
const common_1 = requireCommon()
|
|
38440
34818
|
function assert(condition) {
|
|
38441
34819
|
if (!condition) {
|
|
38442
34820
|
throw new Error('Assertion failed.')
|
|
@@ -38471,7 +34849,7 @@ function requireIpv6() {
|
|
|
38471
34849
|
return s1.concat(['compact']).concat(s2)
|
|
38472
34850
|
}
|
|
38473
34851
|
function paddedHex(octet) {
|
|
38474
|
-
return (
|
|
34852
|
+
return parseInt(octet, 16).toString(16).padStart(4, '0')
|
|
38475
34853
|
}
|
|
38476
34854
|
function unsignByte(b) {
|
|
38477
34855
|
// eslint-disable-next-line no-bitwise
|
|
@@ -38548,18 +34926,18 @@ function requireIpv6() {
|
|
|
38548
34926
|
}
|
|
38549
34927
|
}
|
|
38550
34928
|
/**
|
|
38551
|
-
* Convert a
|
|
34929
|
+
* Convert a BigInt to a v6 address object
|
|
38552
34930
|
* @memberof Address6
|
|
38553
34931
|
* @static
|
|
38554
|
-
* @param {
|
|
34932
|
+
* @param {bigint} bigInt - a BigInt to convert
|
|
38555
34933
|
* @returns {Address6}
|
|
38556
34934
|
* @example
|
|
38557
|
-
* var
|
|
38558
|
-
* var address = Address6.
|
|
34935
|
+
* var bigInt = BigInt('1000000000000');
|
|
34936
|
+
* var address = Address6.fromBigInt(bigInt);
|
|
38559
34937
|
* address.correctForm(); // '::e8:d4a5:1000'
|
|
38560
34938
|
*/
|
|
38561
|
-
static
|
|
38562
|
-
const hex =
|
|
34939
|
+
static fromBigInt(bigInt) {
|
|
34940
|
+
const hex = bigInt.toString(16).padStart(32, '0')
|
|
38563
34941
|
const groups = []
|
|
38564
34942
|
let i
|
|
38565
34943
|
for (i = 0; i < constants6.GROUPS; i++) {
|
|
@@ -38676,10 +35054,7 @@ function requireIpv6() {
|
|
|
38676
35054
|
* @returns {String} the Microsoft UNC transcription of the address
|
|
38677
35055
|
*/
|
|
38678
35056
|
microsoftTranscription() {
|
|
38679
|
-
return (
|
|
38680
|
-
'%s.ipv6-literal.net',
|
|
38681
|
-
this.correctForm().replace(/:/g, '-')
|
|
38682
|
-
)
|
|
35057
|
+
return `${this.correctForm().replace(/:/g, '-')}.ipv6-literal.net`
|
|
38683
35058
|
}
|
|
38684
35059
|
/**
|
|
38685
35060
|
* Return the first n bits of the address, defaulting to the subnet mask
|
|
@@ -38695,7 +35070,7 @@ function requireIpv6() {
|
|
|
38695
35070
|
* Return the number of possible subnets of a given size in the address
|
|
38696
35071
|
* @memberof Address6
|
|
38697
35072
|
* @instance
|
|
38698
|
-
* @param {number} [
|
|
35073
|
+
* @param {number} [subnetSize=128] - the subnet size
|
|
38699
35074
|
* @returns {String}
|
|
38700
35075
|
*/
|
|
38701
35076
|
// TODO: probably useful to have a numeric version of this too
|
|
@@ -38706,20 +35081,17 @@ function requireIpv6() {
|
|
|
38706
35081
|
if (subnetPowers < 0) {
|
|
38707
35082
|
return '0'
|
|
38708
35083
|
}
|
|
38709
|
-
return addCommas(
|
|
38710
|
-
new jsbn_1.BigInteger('2', 10).pow(subnetPowers).toString(10)
|
|
38711
|
-
)
|
|
35084
|
+
return addCommas((BigInt('2') ** BigInt(subnetPowers)).toString(10))
|
|
38712
35085
|
}
|
|
38713
35086
|
/**
|
|
38714
35087
|
* Helper function getting start address.
|
|
38715
35088
|
* @memberof Address6
|
|
38716
35089
|
* @instance
|
|
38717
|
-
* @returns {
|
|
35090
|
+
* @returns {bigint}
|
|
38718
35091
|
*/
|
|
38719
35092
|
_startAddress() {
|
|
38720
|
-
return
|
|
38721
|
-
this.mask() + '0'.repeat(constants6.BITS - this.subnetMask)
|
|
38722
|
-
2
|
|
35093
|
+
return BigInt(
|
|
35094
|
+
`0b${this.mask() + '0'.repeat(constants6.BITS - this.subnetMask)}`
|
|
38723
35095
|
)
|
|
38724
35096
|
}
|
|
38725
35097
|
/**
|
|
@@ -38730,7 +35102,7 @@ function requireIpv6() {
|
|
|
38730
35102
|
* @returns {Address6}
|
|
38731
35103
|
*/
|
|
38732
35104
|
startAddress() {
|
|
38733
|
-
return Address6.
|
|
35105
|
+
return Address6.fromBigInt(this._startAddress())
|
|
38734
35106
|
}
|
|
38735
35107
|
/**
|
|
38736
35108
|
* The first host address in the range given by this address's subnet ie
|
|
@@ -38740,19 +35112,18 @@ function requireIpv6() {
|
|
|
38740
35112
|
* @returns {Address6}
|
|
38741
35113
|
*/
|
|
38742
35114
|
startAddressExclusive() {
|
|
38743
|
-
const adjust =
|
|
38744
|
-
return Address6.
|
|
35115
|
+
const adjust = BigInt('1')
|
|
35116
|
+
return Address6.fromBigInt(this._startAddress() + adjust)
|
|
38745
35117
|
}
|
|
38746
35118
|
/**
|
|
38747
35119
|
* Helper function getting end address.
|
|
38748
35120
|
* @memberof Address6
|
|
38749
35121
|
* @instance
|
|
38750
|
-
* @returns {
|
|
35122
|
+
* @returns {bigint}
|
|
38751
35123
|
*/
|
|
38752
35124
|
_endAddress() {
|
|
38753
|
-
return
|
|
38754
|
-
this.mask() + '1'.repeat(constants6.BITS - this.subnetMask)
|
|
38755
|
-
2
|
|
35125
|
+
return BigInt(
|
|
35126
|
+
`0b${this.mask() + '1'.repeat(constants6.BITS - this.subnetMask)}`
|
|
38756
35127
|
)
|
|
38757
35128
|
}
|
|
38758
35129
|
/**
|
|
@@ -38763,7 +35134,7 @@ function requireIpv6() {
|
|
|
38763
35134
|
* @returns {Address6}
|
|
38764
35135
|
*/
|
|
38765
35136
|
endAddress() {
|
|
38766
|
-
return Address6.
|
|
35137
|
+
return Address6.fromBigInt(this._endAddress())
|
|
38767
35138
|
}
|
|
38768
35139
|
/**
|
|
38769
35140
|
* The last host address in the range given by this address's subnet ie
|
|
@@ -38773,8 +35144,8 @@ function requireIpv6() {
|
|
|
38773
35144
|
* @returns {Address6}
|
|
38774
35145
|
*/
|
|
38775
35146
|
endAddressExclusive() {
|
|
38776
|
-
const adjust =
|
|
38777
|
-
return Address6.
|
|
35147
|
+
const adjust = BigInt('1')
|
|
35148
|
+
return Address6.fromBigInt(this._endAddress() - adjust)
|
|
38778
35149
|
}
|
|
38779
35150
|
/**
|
|
38780
35151
|
* Return the scope of the address
|
|
@@ -38783,7 +35154,8 @@ function requireIpv6() {
|
|
|
38783
35154
|
* @returns {String}
|
|
38784
35155
|
*/
|
|
38785
35156
|
getScope() {
|
|
38786
|
-
let scope =
|
|
35157
|
+
let scope =
|
|
35158
|
+
constants6.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)]
|
|
38787
35159
|
if (this.getType() === 'Global unicast' && scope !== 'Link local') {
|
|
38788
35160
|
scope = 'Global'
|
|
38789
35161
|
}
|
|
@@ -38804,13 +35176,13 @@ function requireIpv6() {
|
|
|
38804
35176
|
return 'Global unicast'
|
|
38805
35177
|
}
|
|
38806
35178
|
/**
|
|
38807
|
-
* Return the bits in the given range as a
|
|
35179
|
+
* Return the bits in the given range as a BigInt
|
|
38808
35180
|
* @memberof Address6
|
|
38809
35181
|
* @instance
|
|
38810
|
-
* @returns {
|
|
35182
|
+
* @returns {bigint}
|
|
38811
35183
|
*/
|
|
38812
35184
|
getBits(start, end) {
|
|
38813
|
-
return
|
|
35185
|
+
return BigInt(`0b${this.getBitsBase2(start, end)}`)
|
|
38814
35186
|
}
|
|
38815
35187
|
/**
|
|
38816
35188
|
* Return the bits in the given range as a base-2 string
|
|
@@ -38868,7 +35240,7 @@ function requireIpv6() {
|
|
|
38868
35240
|
if (options.omitSuffix) {
|
|
38869
35241
|
return reversed
|
|
38870
35242
|
}
|
|
38871
|
-
return
|
|
35243
|
+
return `${reversed}.ip6.arpa.`
|
|
38872
35244
|
}
|
|
38873
35245
|
if (options.omitSuffix) {
|
|
38874
35246
|
return ''
|
|
@@ -38919,7 +35291,7 @@ function requireIpv6() {
|
|
|
38919
35291
|
}
|
|
38920
35292
|
let correct = groups.join(':')
|
|
38921
35293
|
correct = correct.replace(/^compact$/, '::')
|
|
38922
|
-
correct = correct.replace(
|
|
35294
|
+
correct = correct.replace(/(^compact)|(compact$)/, ':')
|
|
38923
35295
|
correct = correct.replace(/compact/, '')
|
|
38924
35296
|
return correct
|
|
38925
35297
|
}
|
|
@@ -38935,7 +35307,7 @@ function requireIpv6() {
|
|
|
38935
35307
|
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
|
38936
35308
|
*/
|
|
38937
35309
|
binaryZeroPad() {
|
|
38938
|
-
return this.
|
|
35310
|
+
return this.bigInt().toString(2).padStart(constants6.BITS, '0')
|
|
38939
35311
|
}
|
|
38940
35312
|
// TODO: Improve the semantics of this helper function
|
|
38941
35313
|
parse4in6(address) {
|
|
@@ -38968,11 +35340,7 @@ function requireIpv6() {
|
|
|
38968
35340
|
const badCharacters = address.match(constants6.RE_BAD_CHARACTERS)
|
|
38969
35341
|
if (badCharacters) {
|
|
38970
35342
|
throw new address_error_1.AddressError(
|
|
38971
|
-
|
|
38972
|
-
'Bad character%s detected in address: %s',
|
|
38973
|
-
badCharacters.length > 1 ? 's' : '',
|
|
38974
|
-
badCharacters.join('')
|
|
38975
|
-
),
|
|
35343
|
+
`Bad character${badCharacters.length > 1 ? 's' : ''} detected in address: ${badCharacters.join('')}`,
|
|
38976
35344
|
address.replace(
|
|
38977
35345
|
constants6.RE_BAD_CHARACTERS,
|
|
38978
35346
|
'<span class="parse-error">$1</span>'
|
|
@@ -38982,10 +35350,7 @@ function requireIpv6() {
|
|
|
38982
35350
|
const badAddress = address.match(constants6.RE_BAD_ADDRESS)
|
|
38983
35351
|
if (badAddress) {
|
|
38984
35352
|
throw new address_error_1.AddressError(
|
|
38985
|
-
|
|
38986
|
-
'Address failed regex: %s',
|
|
38987
|
-
badAddress.join('')
|
|
38988
|
-
),
|
|
35353
|
+
`Address failed regex: ${badAddress.join('')}`,
|
|
38989
35354
|
address.replace(
|
|
38990
35355
|
constants6.RE_BAD_ADDRESS,
|
|
38991
35356
|
'<span class="parse-error">$1</span>'
|
|
@@ -39021,9 +35386,7 @@ function requireIpv6() {
|
|
|
39021
35386
|
} else {
|
|
39022
35387
|
throw new address_error_1.AddressError('Too many :: groups found')
|
|
39023
35388
|
}
|
|
39024
|
-
groups = groups.map(group =>
|
|
39025
|
-
(0, sprintf_js_1.sprintf)('%x', parseInt(group, 16))
|
|
39026
|
-
)
|
|
35389
|
+
groups = groups.map(group => parseInt(group, 16).toString(16))
|
|
39027
35390
|
if (groups.length !== this.groups) {
|
|
39028
35391
|
throw new address_error_1.AddressError(
|
|
39029
35392
|
'Incorrect number of groups found'
|
|
@@ -39048,20 +35411,17 @@ function requireIpv6() {
|
|
|
39048
35411
|
*/
|
|
39049
35412
|
decimal() {
|
|
39050
35413
|
return this.parsedAddress
|
|
39051
|
-
.map(n => (
|
|
35414
|
+
.map(n => parseInt(n, 16).toString(10).padStart(5, '0'))
|
|
39052
35415
|
.join(':')
|
|
39053
35416
|
}
|
|
39054
35417
|
/**
|
|
39055
|
-
* Return the address as a
|
|
35418
|
+
* Return the address as a BigInt
|
|
39056
35419
|
* @memberof Address6
|
|
39057
35420
|
* @instance
|
|
39058
|
-
* @returns {
|
|
35421
|
+
* @returns {bigint}
|
|
39059
35422
|
*/
|
|
39060
|
-
|
|
39061
|
-
return
|
|
39062
|
-
this.parsedAddress.map(paddedHex).join(''),
|
|
39063
|
-
16
|
|
39064
|
-
)
|
|
35423
|
+
bigInt() {
|
|
35424
|
+
return BigInt(`0x${this.parsedAddress.map(paddedHex).join('')}`)
|
|
39065
35425
|
}
|
|
39066
35426
|
/**
|
|
39067
35427
|
* Return the last two groups of this address as an IPv4 address string
|
|
@@ -39075,7 +35435,7 @@ function requireIpv6() {
|
|
|
39075
35435
|
to4() {
|
|
39076
35436
|
const binary = this.binaryZeroPad().split('')
|
|
39077
35437
|
return ipv4_1.Address4.fromHex(
|
|
39078
|
-
|
|
35438
|
+
BigInt(`0b${binary.slice(96, 128).join('')}`).toString(16)
|
|
39079
35439
|
)
|
|
39080
35440
|
}
|
|
39081
35441
|
/**
|
|
@@ -39123,31 +35483,25 @@ function requireIpv6() {
|
|
|
39123
35483
|
public IPv4 address of the NAT with all bits inverted.
|
|
39124
35484
|
*/
|
|
39125
35485
|
const prefix = this.getBitsBase16(0, 32)
|
|
39126
|
-
const
|
|
39127
|
-
|
|
39128
|
-
|
|
35486
|
+
const bitsForUdpPort = this.getBits(80, 96)
|
|
35487
|
+
// eslint-disable-next-line no-bitwise
|
|
35488
|
+
const udpPort = (bitsForUdpPort ^ BigInt('0xffff')).toString()
|
|
39129
35489
|
const server4 = ipv4_1.Address4.fromHex(this.getBitsBase16(32, 64))
|
|
35490
|
+
const bitsForClient4 = this.getBits(96, 128)
|
|
35491
|
+
// eslint-disable-next-line no-bitwise
|
|
39130
35492
|
const client4 = ipv4_1.Address4.fromHex(
|
|
39131
|
-
|
|
39132
|
-
.xor(new jsbn_1.BigInteger('ffffffff', 16))
|
|
39133
|
-
.toString(16)
|
|
35493
|
+
(bitsForClient4 ^ BigInt('0xffffffff')).toString(16)
|
|
39134
35494
|
)
|
|
39135
|
-
const flags = this.getBits(64, 80)
|
|
39136
35495
|
const flagsBase2 = this.getBitsBase2(64, 80)
|
|
39137
|
-
const coneNat =
|
|
39138
|
-
const reserved =
|
|
39139
|
-
const groupIndividual =
|
|
39140
|
-
const universalLocal =
|
|
39141
|
-
const nonce =
|
|
39142
|
-
flagsBase2.slice(2, 6) + flagsBase2.slice(8, 16)
|
|
39143
|
-
2
|
|
35496
|
+
const coneNat = (0, common_1.testBit)(flagsBase2, 15)
|
|
35497
|
+
const reserved = (0, common_1.testBit)(flagsBase2, 14)
|
|
35498
|
+
const groupIndividual = (0, common_1.testBit)(flagsBase2, 8)
|
|
35499
|
+
const universalLocal = (0, common_1.testBit)(flagsBase2, 9)
|
|
35500
|
+
const nonce = BigInt(
|
|
35501
|
+
`0b${flagsBase2.slice(2, 6) + flagsBase2.slice(8, 16)}`
|
|
39144
35502
|
).toString(10)
|
|
39145
35503
|
return {
|
|
39146
|
-
prefix: (0,
|
|
39147
|
-
'%s:%s',
|
|
39148
|
-
prefix.slice(0, 4),
|
|
39149
|
-
prefix.slice(4, 8)
|
|
39150
|
-
),
|
|
35504
|
+
prefix: `${prefix.slice(0, 4)}:${prefix.slice(4, 8)}`,
|
|
39151
35505
|
server4: server4.address,
|
|
39152
35506
|
client4: client4.address,
|
|
39153
35507
|
flags: flagsBase2,
|
|
@@ -39175,7 +35529,7 @@ function requireIpv6() {
|
|
|
39175
35529
|
const prefix = this.getBitsBase16(0, 16)
|
|
39176
35530
|
const gateway = ipv4_1.Address4.fromHex(this.getBitsBase16(16, 48))
|
|
39177
35531
|
return {
|
|
39178
|
-
prefix:
|
|
35532
|
+
prefix: prefix.slice(0, 4),
|
|
39179
35533
|
gateway: gateway.address
|
|
39180
35534
|
}
|
|
39181
35535
|
}
|
|
@@ -39205,12 +35559,14 @@ function requireIpv6() {
|
|
|
39205
35559
|
* @returns {Array}
|
|
39206
35560
|
*/
|
|
39207
35561
|
toByteArray() {
|
|
39208
|
-
const
|
|
39209
|
-
|
|
39210
|
-
|
|
39211
|
-
|
|
35562
|
+
const valueWithoutPadding = this.bigInt().toString(16)
|
|
35563
|
+
const leadingPad = '0'.repeat(valueWithoutPadding.length % 2)
|
|
35564
|
+
const value = `${leadingPad}${valueWithoutPadding}`
|
|
35565
|
+
const bytes = []
|
|
35566
|
+
for (let i = 0, length = value.length; i < length; i += 2) {
|
|
35567
|
+
bytes.push(parseInt(value.substring(i, i + 2), 16))
|
|
39212
35568
|
}
|
|
39213
|
-
return
|
|
35569
|
+
return bytes
|
|
39214
35570
|
}
|
|
39215
35571
|
/**
|
|
39216
35572
|
* Return an unsigned byte array
|
|
@@ -39237,16 +35593,14 @@ function requireIpv6() {
|
|
|
39237
35593
|
* @returns {Address6}
|
|
39238
35594
|
*/
|
|
39239
35595
|
static fromUnsignedByteArray(bytes) {
|
|
39240
|
-
const BYTE_MAX =
|
|
39241
|
-
let result =
|
|
39242
|
-
let multiplier =
|
|
35596
|
+
const BYTE_MAX = BigInt('256')
|
|
35597
|
+
let result = BigInt('0')
|
|
35598
|
+
let multiplier = BigInt('1')
|
|
39243
35599
|
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
39244
|
-
result
|
|
39245
|
-
|
|
39246
|
-
)
|
|
39247
|
-
multiplier = multiplier.multiply(BYTE_MAX)
|
|
35600
|
+
result += multiplier * BigInt(bytes[i].toString(10))
|
|
35601
|
+
multiplier *= BYTE_MAX
|
|
39248
35602
|
}
|
|
39249
|
-
return Address6.
|
|
35603
|
+
return Address6.fromBigInt(result)
|
|
39250
35604
|
}
|
|
39251
35605
|
/**
|
|
39252
35606
|
* Returns true if the address is in the canonical form, false otherwise
|
|
@@ -39327,13 +35681,9 @@ function requireIpv6() {
|
|
|
39327
35681
|
if (optionalPort === undefined) {
|
|
39328
35682
|
optionalPort = ''
|
|
39329
35683
|
} else {
|
|
39330
|
-
optionalPort =
|
|
35684
|
+
optionalPort = `:${optionalPort}`
|
|
39331
35685
|
}
|
|
39332
|
-
return (
|
|
39333
|
-
'http://[%s]%s/',
|
|
39334
|
-
this.correctForm(),
|
|
39335
|
-
optionalPort
|
|
39336
|
-
)
|
|
35686
|
+
return `http://[${this.correctForm()}]${optionalPort}/`
|
|
39337
35687
|
}
|
|
39338
35688
|
/**
|
|
39339
35689
|
* @returns {String} a link suitable for conveying the address via a URL hash
|
|
@@ -39355,19 +35705,11 @@ function requireIpv6() {
|
|
|
39355
35705
|
if (options.v4) {
|
|
39356
35706
|
formFunction = this.to4in6
|
|
39357
35707
|
}
|
|
35708
|
+
const form = formFunction.call(this)
|
|
39358
35709
|
if (options.className) {
|
|
39359
|
-
return
|
|
39360
|
-
'<a href="%1$s%2$s" class="%3$s">%2$s</a>',
|
|
39361
|
-
options.prefix,
|
|
39362
|
-
formFunction.call(this),
|
|
39363
|
-
options.className
|
|
39364
|
-
)
|
|
35710
|
+
return `<a href="${options.prefix}${form}" class="${options.className}">${form}</a>`
|
|
39365
35711
|
}
|
|
39366
|
-
return
|
|
39367
|
-
'<a href="%1$s%2$s">%2$s</a>',
|
|
39368
|
-
options.prefix,
|
|
39369
|
-
formFunction.call(this)
|
|
39370
|
-
)
|
|
35712
|
+
return `<a href="${options.prefix}${form}">${form}</a>`
|
|
39371
35713
|
}
|
|
39372
35714
|
/**
|
|
39373
35715
|
* Groups an address
|
|
@@ -39394,11 +35736,9 @@ function requireIpv6() {
|
|
|
39394
35736
|
i < this.elisionBegin + this.elidedGroups;
|
|
39395
35737
|
i++
|
|
39396
35738
|
) {
|
|
39397
|
-
classes.push(
|
|
35739
|
+
classes.push(`group-${i}`)
|
|
39398
35740
|
}
|
|
39399
|
-
output.push(
|
|
39400
|
-
(0, sprintf_js_1.sprintf)('<span class="%s"></span>', classes.join(' '))
|
|
39401
|
-
)
|
|
35741
|
+
output.push(`<span class="${classes.join(' ')}"></span>`)
|
|
39402
35742
|
if (right.length) {
|
|
39403
35743
|
output.push(...helpers.simpleGroup(right, this.elisionEnd))
|
|
39404
35744
|
} else {
|