@suveren/gateway 0.7.6 → 0.8.0
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/content/integrations/mollie.json +103 -28
- package/dist/mcp-server/http.mjs +228 -118
- package/dist/ui/assets/{index-CsrM6RQr.js → index-BFnSVa9N.js} +22 -22
- package/dist/ui/index.html +1 -1
- package/node_modules/@hap/core/dist/index.d.mts +29 -6
- package/node_modules/@hap/core/dist/index.d.ts +29 -6
- package/node_modules/@hap/core/dist/index.js +54 -8
- package/node_modules/@hap/core/dist/index.mjs +53 -8
- package/node_modules/@hap/core/package.json +2 -1
- package/node_modules/@hap/core/src/frame.ts +115 -14
- package/node_modules/@hap/core/src/gatekeeper.ts +26 -0
- package/node_modules/@hap/core/src/types.ts +7 -1
- package/node_modules/@types/node/README.md +1 -1
- package/node_modules/@types/node/buffer.buffer.d.ts +5 -0
- package/node_modules/@types/node/crypto.d.ts +0 -2
- package/node_modules/@types/node/dgram.d.ts +119 -4
- package/node_modules/@types/node/ffi.d.ts +1 -1
- package/node_modules/@types/node/fs/promises.d.ts +61 -65
- package/node_modules/@types/node/fs.d.ts +86 -76
- package/node_modules/@types/node/http.d.ts +1 -1
- package/node_modules/@types/node/http2.d.ts +2 -2
- package/node_modules/@types/node/index.d.ts +1 -0
- package/node_modules/@types/node/inspector.d.ts +2 -1
- package/node_modules/@types/node/net.d.ts +108 -16
- package/node_modules/@types/node/package.json +2 -2
- package/node_modules/@types/node/quic.d.ts +37 -11
- package/node_modules/@types/node/stream/iter.d.ts +4 -4
- package/node_modules/@types/node/tls.d.ts +24 -0
- package/node_modules/@types/node/ts5.6/buffer.buffer.d.ts +5 -0
- package/node_modules/@types/node/ts5.6/index.d.ts +1 -0
- package/node_modules/@types/node/ts5.7/index.d.ts +1 -0
- package/node_modules/@types/node/tty.d.ts +4 -3
- package/node_modules/@types/node/vfs.d.ts +210 -0
- package/node_modules/@types/node/vm.d.ts +1 -1
- package/node_modules/express-rate-limit/dist/index.cjs +6 -3
- package/node_modules/express-rate-limit/dist/index.d.cts +11 -0
- package/node_modules/express-rate-limit/dist/index.d.mts +11 -0
- package/node_modules/express-rate-limit/dist/index.d.ts +11 -0
- package/node_modules/express-rate-limit/dist/index.mjs +6 -3
- package/node_modules/express-rate-limit/{license.md → license} +7 -6
- package/node_modules/express-rate-limit/package.json +5 -5
- package/node_modules/express-rate-limit/readme.md +1 -0
- package/node_modules/fast-uri/index.js +20 -5
- package/node_modules/fast-uri/lib/utils.js +8 -1
- package/node_modules/fast-uri/package.json +1 -1
- package/node_modules/fast-uri/test/component-safe-serialization.test.js +58 -0
- package/node_modules/fast-uri/test/ipv6-validation.test.js +34 -0
- package/node_modules/ip-address/README.md +92 -82
- package/node_modules/ip-address/dist/common.d.ts +20 -0
- package/node_modules/ip-address/dist/common.js +36 -0
- package/node_modules/ip-address/dist/common.js.map +1 -1
- package/node_modules/ip-address/dist/ipv4.d.ts +50 -0
- package/node_modules/ip-address/dist/ipv4.js +75 -0
- package/node_modules/ip-address/dist/ipv4.js.map +1 -1
- package/node_modules/ip-address/dist/ipv6.d.ts +79 -10
- package/node_modules/ip-address/dist/ipv6.js +120 -30
- package/node_modules/ip-address/dist/ipv6.js.map +1 -1
- package/node_modules/ip-address/dist/v4/constants.d.ts +12 -0
- package/node_modules/ip-address/dist/v4/constants.js +40 -1
- package/node_modules/ip-address/dist/v4/constants.js.map +1 -1
- package/node_modules/ip-address/dist/v6/constants.d.ts +14 -0
- package/node_modules/ip-address/dist/v6/constants.js +47 -1
- package/node_modules/ip-address/dist/v6/constants.js.map +1 -1
- package/node_modules/ip-address/package.json +1 -1
- package/node_modules/jose/dist/types/jwe/compact/decrypt.d.ts +7 -16
- package/node_modules/jose/dist/types/jwe/compact/encrypt.d.ts +6 -17
- package/node_modules/jose/dist/types/jwe/flattened/decrypt.d.ts +7 -16
- package/node_modules/jose/dist/types/jwe/flattened/encrypt.d.ts +11 -34
- package/node_modules/jose/dist/types/jwe/general/decrypt.d.ts +7 -16
- package/node_modules/jose/dist/types/jwe/general/encrypt.d.ts +15 -35
- package/node_modules/jose/dist/types/jwk/embedded.d.ts +3 -8
- package/node_modules/jose/dist/types/jwk/thumbprint.d.ts +5 -5
- package/node_modules/jose/dist/types/jwks/local.d.ts +6 -10
- package/node_modules/jose/dist/types/jwks/remote.d.ts +13 -24
- package/node_modules/jose/dist/types/jws/compact/sign.d.ts +5 -10
- package/node_modules/jose/dist/types/jws/compact/verify.d.ts +9 -18
- package/node_modules/jose/dist/types/jws/flattened/sign.d.ts +7 -16
- package/node_modules/jose/dist/types/jws/flattened/verify.d.ts +9 -18
- package/node_modules/jose/dist/types/jws/general/sign.d.ts +11 -21
- package/node_modules/jose/dist/types/jws/general/verify.d.ts +9 -18
- package/node_modules/jose/dist/types/jwt/decrypt.d.ts +10 -20
- package/node_modules/jose/dist/types/jwt/encrypt.d.ts +6 -13
- package/node_modules/jose/dist/types/jwt/sign.d.ts +5 -6
- package/node_modules/jose/dist/types/jwt/unsecured.d.ts +9 -14
- package/node_modules/jose/dist/types/jwt/verify.d.ts +9 -19
- package/node_modules/jose/dist/types/key/export.d.ts +4 -4
- package/node_modules/jose/dist/types/key/generate_key_pair.d.ts +6 -8
- package/node_modules/jose/dist/types/key/generate_secret.d.ts +4 -11
- package/node_modules/jose/dist/types/key/import.d.ts +10 -17
- package/node_modules/jose/dist/types/types.d.ts +44 -84
- package/node_modules/jose/dist/types/util/base64url.d.ts +2 -2
- package/node_modules/jose/dist/types/util/decode_jwt.d.ts +3 -10
- package/node_modules/jose/dist/types/util/decode_protected_header.d.ts +4 -4
- package/node_modules/jose/dist/types/util/errors.d.ts +26 -53
- package/node_modules/jose/dist/webapi/index.js +70 -32
- package/node_modules/jose/dist/webapi/jwe/compact/decrypt.js +7 -8
- package/node_modules/jose/dist/webapi/jwe/compact/encrypt.js +42 -48
- package/node_modules/jose/dist/webapi/jwe/flattened/decrypt.js +14 -14
- package/node_modules/jose/dist/webapi/jwe/flattened/encrypt.js +53 -64
- package/node_modules/jose/dist/webapi/jwe/general/decrypt.js +38 -49
- package/node_modules/jose/dist/webapi/jwe/general/encrypt.js +121 -169
- package/node_modules/jose/dist/webapi/jwk/embedded.js +30 -32
- package/node_modules/jose/dist/webapi/jwk/thumbprint.js +54 -70
- package/node_modules/jose/dist/webapi/jwks/local.js +47 -64
- package/node_modules/jose/dist/webapi/jwks/remote.js +88 -136
- package/node_modules/jose/dist/webapi/jws/compact/sign.js +21 -21
- package/node_modules/jose/dist/webapi/jws/compact/verify.js +7 -8
- package/node_modules/jose/dist/webapi/jws/flattened/sign.js +29 -31
- package/node_modules/jose/dist/webapi/jws/flattened/verify.js +21 -24
- package/node_modules/jose/dist/webapi/jws/general/sign.js +61 -72
- package/node_modules/jose/dist/webapi/jws/general/verify.js +45 -69
- package/node_modules/jose/dist/webapi/jwt/decrypt.js +13 -20
- package/node_modules/jose/dist/webapi/jwt/encrypt.js +57 -70
- package/node_modules/jose/dist/webapi/jwt/sign.js +17 -16
- package/node_modules/jose/dist/webapi/jwt/unsecured.js +32 -40
- package/node_modules/jose/dist/webapi/jwt/verify.js +12 -14
- package/node_modules/jose/dist/webapi/key/export.js +32 -37
- package/node_modules/jose/dist/webapi/key/generate_key_pair.js +40 -48
- package/node_modules/jose/dist/webapi/key/generate_secret.js +35 -40
- package/node_modules/jose/dist/webapi/key/import.js +52 -56
- package/node_modules/jose/dist/webapi/lib/asn1.js +130 -169
- package/node_modules/jose/dist/webapi/lib/base64.js +18 -20
- package/node_modules/jose/dist/webapi/lib/buffer_utils.js +34 -38
- package/node_modules/jose/dist/webapi/lib/content_encryption.js +79 -115
- package/node_modules/jose/dist/webapi/lib/crypto_key.js +24 -25
- package/node_modules/jose/dist/webapi/lib/deflate.js +45 -47
- package/node_modules/jose/dist/webapi/lib/helpers.js +40 -37
- package/node_modules/jose/dist/webapi/lib/invalid_key_input.js +10 -24
- package/node_modules/jose/dist/webapi/lib/is_key_like.js +17 -15
- package/node_modules/jose/dist/webapi/lib/jwe_algorithms.js +106 -93
- package/node_modules/jose/dist/webapi/lib/jwe_decrypt.js +207 -230
- package/node_modules/jose/dist/webapi/lib/jwe_encrypt.js +104 -138
- package/node_modules/jose/dist/webapi/lib/jwk_metadata.js +17 -18
- package/node_modules/jose/dist/webapi/lib/jwk_to_key.js +9 -16
- package/node_modules/jose/dist/webapi/lib/jws_algorithms.js +62 -61
- package/node_modules/jose/dist/webapi/lib/jws_sign.js +50 -75
- package/node_modules/jose/dist/webapi/lib/jws_verify.js +80 -125
- package/node_modules/jose/dist/webapi/lib/jwt_claims_set.js +123 -209
- package/node_modules/jose/dist/webapi/lib/key.js +84 -136
- package/node_modules/jose/dist/webapi/lib/key_algorithm.js +13 -8
- package/node_modules/jose/dist/webapi/lib/key_descriptor.js +8 -6
- package/node_modules/jose/dist/webapi/lib/key_management.js +200 -231
- package/node_modules/jose/dist/webapi/lib/key_options.js +7 -5
- package/node_modules/jose/dist/webapi/lib/options.js +55 -68
- package/node_modules/jose/dist/webapi/lib/signing.js +18 -22
- package/node_modules/jose/dist/webapi/lib/type_checks.js +26 -29
- package/node_modules/jose/dist/webapi/util/base64url.js +26 -35
- package/node_modules/jose/dist/webapi/util/decode_jwt.js +32 -31
- package/node_modules/jose/dist/webapi/util/decode_protected_header.js +18 -23
- package/node_modules/jose/dist/webapi/util/errors.js +94 -84
- package/node_modules/jose/package.json +17 -81
- package/package.json +2 -2
- package/profiles/calendar/0.5.profile.json +190 -0
- package/profiles/charge/0.5.profile.json +210 -0
- package/profiles/customers/0.7.profile.json +157 -0
- package/profiles/deploy/0.9.profile.json +176 -0
- package/profiles/email/0.6.profile.json +208 -0
- package/profiles/index.json +9 -1
- package/profiles/publish/0.5.profile.json +186 -0
- package/profiles/purchase/0.5.profile.json +231 -0
- package/profiles/records/0.5.profile.json +117 -0
|
@@ -285,6 +285,33 @@ class Address4 {
|
|
|
285
285
|
const adjust = BigInt('1');
|
|
286
286
|
return Address4.fromBigInt(this._startAddress() + adjust);
|
|
287
287
|
}
|
|
288
|
+
/**
|
|
289
|
+
* Returns the address `n` addresses after this one (or before, when `n` is
|
|
290
|
+
* negative), keeping this address's subnet mask. Throws `AddressError` when
|
|
291
|
+
* the result would fall outside the IPv4 address space or `n` is not an
|
|
292
|
+
* integer.
|
|
293
|
+
* @param {number | bigint} n
|
|
294
|
+
* @returns {Address4}
|
|
295
|
+
* @example
|
|
296
|
+
* new Address4('10.0.0.0/24').offset(1).correctForm(); // '10.0.0.1'
|
|
297
|
+
*/
|
|
298
|
+
offset(n) {
|
|
299
|
+
return Address4.fromBigInt(common.offsetBigInt(this.bigInt(), n, constants.BITS, 'IPv4')).withSubnetMask(this.subnetMask);
|
|
300
|
+
}
|
|
301
|
+
/**
|
|
302
|
+
* Returns the network that follows this address's network: the address after
|
|
303
|
+
* {@link endAddress}, with the same subnet mask. Throws `AddressError` when
|
|
304
|
+
* this network is the last one in the address space.
|
|
305
|
+
* @returns {Address4}
|
|
306
|
+
* @example
|
|
307
|
+
* new Address4('10.0.0.0/24').nextNetwork().networkForm(); // '10.0.1.0/24'
|
|
308
|
+
*/
|
|
309
|
+
nextNetwork() {
|
|
310
|
+
return Address4.fromBigInt(common.offsetBigInt(this._endAddress(), 1, constants.BITS, 'IPv4')).withSubnetMask(this.subnetMask);
|
|
311
|
+
}
|
|
312
|
+
withSubnetMask(subnetMask) {
|
|
313
|
+
return new Address4(`${this.correctForm()}/${subnetMask}`);
|
|
314
|
+
}
|
|
288
315
|
/**
|
|
289
316
|
* Helper function getting end address.
|
|
290
317
|
* @returns {bigint}
|
|
@@ -462,6 +489,43 @@ class Address4 {
|
|
|
462
489
|
isCGNAT() {
|
|
463
490
|
return this.isHostInSubnet(CGNAT_V4);
|
|
464
491
|
}
|
|
492
|
+
/**
|
|
493
|
+
* Returns true if the address is in one of the documentation ranges
|
|
494
|
+
* `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24` ([RFC 5737](https://datatracker.ietf.org/doc/html/rfc5737)).
|
|
495
|
+
* @returns {boolean}
|
|
496
|
+
*/
|
|
497
|
+
isDocumentation() {
|
|
498
|
+
return DOCUMENTATION_V4.some((subnet) => this.isHostInSubnet(subnet));
|
|
499
|
+
}
|
|
500
|
+
/**
|
|
501
|
+
* Returns true if the address is in the benchmarking range `198.18.0.0/15` ([RFC 2544](https://datatracker.ietf.org/doc/html/rfc2544)).
|
|
502
|
+
* @returns {boolean}
|
|
503
|
+
*/
|
|
504
|
+
isBenchmarking() {
|
|
505
|
+
return this.isHostInSubnet(BENCHMARKING_V4);
|
|
506
|
+
}
|
|
507
|
+
/**
|
|
508
|
+
* Returns true if the address is in the reserved range `240.0.0.0/4` ([RFC 1112](https://datatracker.ietf.org/doc/html/rfc1112)),
|
|
509
|
+
* which includes the limited broadcast address.
|
|
510
|
+
* @returns {boolean}
|
|
511
|
+
*/
|
|
512
|
+
isReserved() {
|
|
513
|
+
return this.isHostInSubnet(RESERVED_V4);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* Returns true if the address is globally reachable: not multicast, and not
|
|
517
|
+
* in any block the [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/)
|
|
518
|
+
* marks as not globally reachable. That covers everything the individual
|
|
519
|
+
* classifiers name (private, loopback, link-local, CGNAT, unspecified,
|
|
520
|
+
* broadcast, documentation, benchmarking, reserved) and the blocks they do
|
|
521
|
+
* not, such as `0.0.0.0/8` and the IETF protocol assignments in
|
|
522
|
+
* `192.0.0.0/24`. This is the single predicate to use where a request must
|
|
523
|
+
* not reach an internal or special-purpose destination; see SECURITY.md.
|
|
524
|
+
* @returns {boolean}
|
|
525
|
+
*/
|
|
526
|
+
isGlobal() {
|
|
527
|
+
return !this.isMulticast() && common.isGloballyReachable.call(this, SPECIAL_PURPOSE_V4);
|
|
528
|
+
}
|
|
465
529
|
/**
|
|
466
530
|
* Returns a zero-padded base-2 string representation of the address
|
|
467
531
|
* @returns {string}
|
|
@@ -502,4 +566,15 @@ const LINK_LOCAL_V4 = new Address4('169.254.0.0/16');
|
|
|
502
566
|
const UNSPECIFIED_V4 = new Address4('0.0.0.0/32');
|
|
503
567
|
const BROADCAST_V4 = new Address4('255.255.255.255/32');
|
|
504
568
|
const CGNAT_V4 = new Address4('100.64.0.0/10');
|
|
569
|
+
const DOCUMENTATION_V4 = [
|
|
570
|
+
new Address4('192.0.2.0/24'),
|
|
571
|
+
new Address4('198.51.100.0/24'),
|
|
572
|
+
new Address4('203.0.113.0/24'),
|
|
573
|
+
];
|
|
574
|
+
const BENCHMARKING_V4 = new Address4('198.18.0.0/15');
|
|
575
|
+
const RESERVED_V4 = new Address4('240.0.0.0/4');
|
|
576
|
+
const SPECIAL_PURPOSE_V4 = constants.SPECIAL_PURPOSE.map(([cidr, , reachable]) => ({
|
|
577
|
+
subnet: new Address4(cidr),
|
|
578
|
+
reachable,
|
|
579
|
+
}));
|
|
505
580
|
//# sourceMappingURL=ipv4.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ipv4.js","sourceRoot":"","sources":["../src/ipv4.ts"],"names":[],"mappings":";AAAA,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtC,iDAAmC;AACnC,0DAA4C;AAC5C,mDAA+C;AAE/C,MAAM,UAAU,GAAG,MAAM,CAAC,SAAS,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAEpD;;;GAGG;AACH,MAAa,QAAQ;IAWnB,YAAY,OAAe;QAT3B,uBAAkB,GAAW,EAAE,CAAC;QAChC,WAAM,GAAW,SAAS,CAAC,MAAM,CAAC;QAClC,kBAAa,GAAa,EAAE,CAAC;QAC7B,iBAAY,GAAW,EAAE,CAAC;QAC1B,WAAM,GAAW,KAAK,CAAC;QACvB,eAAU,GAAW,EAAE,CAAC;QACxB,OAAE,GAAY,IAAI,CAAC;QA0EnB;;;WAGG;QACH,cAAS,GAAG,UAAU,CAAC;QAgWvB;;;WAGG;QACH,eAAU,GAAG,MAAM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rD,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AACxD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,eAAe,CAAC,CAAC","sourcesContent":["/* eslint-disable no-param-reassign */\n\nimport * as common from './common';\nimport * as constants from './v4/constants';\nimport { AddressError } from './address-error';\n\nconst isCorrect4 = common.isCorrect(constants.BITS);\n\n/**\n * Represents an IPv4 address\n * @param {string} address - An IPv4 address string\n */\nexport class Address4 {\n address: string;\n addressMinusSuffix: string = '';\n groups: number = constants.GROUPS;\n parsedAddress: string[] = [];\n parsedSubnet: string = '';\n subnet: string = '/32';\n subnetMask: number = 32;\n v4: boolean = true;\n private _binaryZeroPad?: string;\n\n constructor(address: string) {\n this.address = address;\n\n const subnet = constants.RE_SUBNET_STRING.exec(address);\n\n if (subnet) {\n this.parsedSubnet = subnet[0].replace('/', '');\n this.subnetMask = parseInt(this.parsedSubnet, 10);\n this.subnet = `/${this.subnetMask}`;\n\n if (this.subnetMask < 0 || this.subnetMask > constants.BITS) {\n throw new AddressError('Invalid subnet mask.');\n }\n\n address = address.replace(constants.RE_SUBNET_STRING, '');\n }\n\n this.addressMinusSuffix = address;\n\n this.parsedAddress = this.parse(address);\n }\n\n /**\n * Returns true if the given string is a valid IPv4 address (with optional\n * CIDR subnet), false otherwise. Host bits in the subnet portion are\n * allowed (e.g. `192.168.1.5/24` is valid); for strict network-address\n * validation compare `correctForm()` to `startAddress().correctForm()`,\n * or use `networkForm()`.\n */\n static isValid(address: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new Address4(address);\n\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Parses an IPv4 address string into its four octet groups and stores the\n * result on `this.parsedAddress`. Called automatically by the constructor;\n * you typically don't need to call it directly. Throws `AddressError` if\n * the input is not a valid IPv4 address.\n */\n parse(address: string) {\n const groups = address.split('.');\n\n // Checked before the general match so the error names the actual problem.\n // Address6 rejects the same notation on its v4-in-v6 path.\n if (groups.some((group) => /^0\\d/.test(group))) {\n throw new AddressError(\"IPv4 addresses can't have leading zeroes.\");\n }\n\n if (!address.match(constants.RE_ADDRESS)) {\n throw new AddressError('Invalid IPv4 address.');\n }\n\n return groups;\n }\n\n /**\n * Returns the address in correct form: octets joined with `.` and any\n * leading zeros stripped (e.g. `192.168.1.1`). For IPv4 this matches the\n * canonical dotted-decimal representation.\n */\n correctForm(): string {\n return this.parsedAddress.map((part) => parseInt(part, 10)).join('.');\n }\n\n /**\n * Returns true if the address is correct, false otherwise\n * @returns {Boolean}\n */\n isCorrect = isCorrect4;\n\n /**\n * Construct an `Address4` from an address and a dotted-decimal subnet\n * mask given as separate strings (e.g. as returned by Node's\n * `os.networkInterfaces()`). Throws `AddressError` if the mask is\n * non-contiguous (e.g. `255.0.255.0`).\n * @example\n * var address = Address4.fromAddressAndMask('192.168.1.1', '255.255.255.0');\n * address.subnetMask; // 24\n */\n static fromAddressAndMask(address: string, mask: string): Address4 {\n const bits = common.prefixLengthFromMask(new Address4(mask).bigInt(), constants.BITS);\n return new Address4(`${address}/${bits}`);\n }\n\n /**\n * Construct an `Address4` from an address and a Cisco-style wildcard mask\n * given as separate strings (e.g. `0.0.0.255` for a `/24`). The wildcard\n * mask is the bitwise inverse of the subnet mask. Throws `AddressError`\n * if the mask is non-contiguous (e.g. `0.255.0.255`).\n * @example\n * var address = Address4.fromAddressAndWildcardMask('10.0.0.1', '0.0.0.255');\n * address.subnetMask; // 24\n */\n static fromAddressAndWildcardMask(address: string, wildcardMask: string): Address4 {\n const wildcard = new Address4(wildcardMask).bigInt();\n const allOnes = (BigInt(1) << BigInt(constants.BITS)) - BigInt(1);\n const mask = wildcard ^ allOnes;\n const bits = common.prefixLengthFromMask(mask, constants.BITS);\n return new Address4(`${address}/${bits}`);\n }\n\n /**\n * Construct an `Address4` from a wildcard pattern with trailing `*`\n * octets. The number of trailing wildcards determines the prefix\n * length: each `*` represents 8 bits.\n *\n * Only trailing whole-octet wildcards are supported. Partial-octet\n * wildcards (e.g. `192.168.0.1*`) and interior wildcards (e.g.\n * `192.*.0.1`) throw `AddressError`.\n * @example\n * Address4.fromWildcard('192.168.0.*').subnet; // '/24'\n * Address4.fromWildcard('192.168.*.*').subnet; // '/16'\n * Address4.fromWildcard('*.*.*.*').subnet; // '/0'\n */\n static fromWildcard(input: string): Address4 {\n const groups = input.split('.');\n\n if (groups.length !== constants.GROUPS) {\n throw new AddressError('Wildcard pattern must have 4 octets');\n }\n\n let firstWildcard = -1;\n\n for (let i = 0; i < groups.length; i++) {\n if (groups[i] === '*') {\n if (firstWildcard === -1) {\n firstWildcard = i;\n }\n } else if (firstWildcard !== -1) {\n throw new AddressError(\n 'Wildcard `*` must only appear in trailing octets (e.g. `192.168.0.*`)',\n );\n }\n }\n\n const trailing = firstWildcard === -1 ? 0 : groups.length - firstWildcard;\n const replaced = groups.map((g) => (g === '*' ? '0' : g));\n const subnetBits = constants.BITS - trailing * 8;\n\n return new Address4(`${replaced.join('.')}/${subnetBits}`);\n }\n\n /**\n * Converts a hex string to an IPv4 address object. Accepts 8 hex digits\n * with optional `:` separators (e.g. `'7f000001'` or `'7f:00:00:01'`).\n * Throws `AddressError` for any other length or for non-hex characters.\n * @param {string} hex - a hex string to convert\n * @returns {Address4}\n */\n static fromHex(hex: string): Address4 {\n const stripped = hex.replace(/:/g, '');\n\n if (!/^[0-9a-fA-F]{8}$/.test(stripped)) {\n throw new AddressError('IPv4 hex must be exactly 8 hex digits');\n }\n\n const groups = [];\n\n for (let i = 0; i < 8; i += 2) {\n groups.push(parseInt(stripped.slice(i, i + 2), 16));\n }\n\n return new Address4(groups.join('.'));\n }\n\n /**\n * Converts an integer into a IPv4 address object. The integer must be a\n * non-negative safe integer in the range `[0, 2**32 - 1]`; otherwise\n * `AddressError` is thrown.\n * @param {integer} integer - a number to convert\n * @returns {Address4}\n */\n static fromInteger(integer: number): Address4 {\n if (!Number.isInteger(integer) || integer < 0 || integer > 0xffffffff) {\n throw new AddressError('IPv4 integer must be in the range 0 to 2**32 - 1');\n }\n\n return Address4.fromHex(integer.toString(16).padStart(8, '0'));\n }\n\n /**\n * Return an address from in-addr.arpa form\n * @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address\n * @returns {Adress4}\n * @example\n * var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.)\n * address.correctForm(); // '192.0.2.42'\n */\n static fromArpa(arpaFormAddress: string): Address4 {\n // remove ending \".in-addr.arpa.\" or just \".\"\n const leader = arpaFormAddress.replace(/(\\.in-addr\\.arpa)?\\.$/, '');\n\n const address = leader.split('.').reverse().join('.');\n\n return new Address4(address);\n }\n\n /**\n * Converts an IPv4 address object to a hex string\n * @returns {String}\n */\n toHex(): string {\n return this.parsedAddress.map((part) => common.stringToPaddedHex(part)).join(':');\n }\n\n /**\n * Converts an IPv4 address object to an array of bytes.\n *\n * To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toArray())`.\n * @returns {Array}\n */\n toArray(): number[] {\n return this.parsedAddress.map((part) => parseInt(part, 10));\n }\n\n /**\n * Converts an IPv4 address object to an IPv6 address group\n * @returns {String}\n */\n toGroup6(): string {\n const output = [];\n let i;\n\n for (i = 0; i < constants.GROUPS; i += 2) {\n output.push(\n `${common.stringToPaddedHex(this.parsedAddress[i])}${common.stringToPaddedHex(\n this.parsedAddress[i + 1],\n )}`,\n );\n }\n\n return output.join(':');\n }\n\n /**\n * Returns the address as a `bigint`\n * @returns {bigint}\n */\n bigInt(): bigint {\n return BigInt(`0x${this.parsedAddress.map((n) => common.stringToPaddedHex(n)).join('')}`);\n }\n\n /**\n * Helper function getting start address.\n * @returns {bigint}\n */\n _startAddress(): bigint {\n return BigInt(`0b${this.mask() + '0'.repeat(constants.BITS - this.subnetMask)}`);\n }\n\n /**\n * The first address in the range given by this address' subnet.\n * Often referred to as the Network Address.\n * @returns {Address4}\n */\n startAddress(): Address4 {\n return Address4.fromBigInt(this._startAddress());\n }\n\n /**\n * The first host address in the range given by this address's subnet ie\n * the first address after the Network Address\n * @returns {Address4}\n */\n startAddressExclusive(): Address4 {\n const adjust = BigInt('1');\n return Address4.fromBigInt(this._startAddress() + adjust);\n }\n\n /**\n * Helper function getting end address.\n * @returns {bigint}\n */\n _endAddress(): bigint {\n return BigInt(`0b${this.mask() + '1'.repeat(constants.BITS - this.subnetMask)}`);\n }\n\n /**\n * The last address in the range given by this address' subnet\n * Often referred to as the Broadcast\n * @returns {Address4}\n */\n endAddress(): Address4 {\n return Address4.fromBigInt(this._endAddress());\n }\n\n /**\n * The last host address in the range given by this address's subnet ie\n * the last address prior to the Broadcast Address\n * @returns {Address4}\n */\n endAddressExclusive(): Address4 {\n const adjust = BigInt('1');\n return Address4.fromBigInt(this._endAddress() - adjust);\n }\n\n /**\n * The dotted-decimal form of the subnet mask, e.g. `255.255.240.0` for\n * a `/20`. Returns an `Address4`; call `.correctForm()` for the string.\n * @returns {Address4}\n */\n subnetMaskAddress(): Address4 {\n return Address4.fromBigInt(\n BigInt(`0b${'1'.repeat(this.subnetMask)}${'0'.repeat(constants.BITS - this.subnetMask)}`),\n );\n }\n\n /**\n * The Cisco-style wildcard mask, e.g. `0.0.0.255` for a `/24`. This is\n * the bitwise inverse of `subnetMaskAddress()`. Returns an `Address4`;\n * call `.correctForm()` for the string.\n * @returns {Address4}\n */\n wildcardMask(): Address4 {\n return Address4.fromBigInt(\n BigInt(`0b${'0'.repeat(this.subnetMask)}${'1'.repeat(constants.BITS - this.subnetMask)}`),\n );\n }\n\n /**\n * The network address in CIDR string form, e.g. `192.168.1.0/24` for\n * `192.168.1.5/24`. For an address with no explicit subnet the prefix is\n * `/32`, e.g. `networkForm()` on `192.168.1.5` returns `192.168.1.5/32`.\n * @returns {string}\n */\n networkForm(): string {\n return `${this.startAddress().correctForm()}/${this.subnetMask}`;\n }\n\n /**\n * Converts a BigInt to a v4 address object. The value must be in the\n * range `[0, 2**32 - 1]`; otherwise `AddressError` is thrown.\n * @param {bigint} bigInt - a BigInt to convert\n * @returns {Address4}\n */\n static fromBigInt(bigInt: bigint): Address4 {\n if (bigInt < BigInt(0) || bigInt > BigInt(0xffffffff)) {\n throw new AddressError('IPv4 BigInt must be in the range 0 to 2**32 - 1');\n }\n\n return Address4.fromHex(bigInt.toString(16).padStart(8, '0'));\n }\n\n /**\n * Convert a byte array to an Address4 object. Throws `AddressError` unless\n * given exactly 4 integers from 0 to 255. Signed bytes are rejected, so\n * this differs from `Address6.fromByteArray`, which folds them; the two\n * contracts converge on this stricter form in the next major version.\n *\n * To convert from a Node.js `Buffer`, spread it: `Address4.fromByteArray([...buf])`.\n * @param {Array<number>} bytes - an array of 4 bytes (0-255)\n * @returns {Address4}\n */\n static fromByteArray(bytes: Array<number>): Address4 {\n common.assertByteArray(bytes, 4, 'IPv4', 0);\n\n return this.fromUnsignedByteArray(bytes);\n }\n\n /**\n * Convert an unsigned byte array to an Address4 object. Throws\n * `AddressError` unless given exactly 4 bytes, and rejects values outside\n * 0 to 255 when parsing the resulting address.\n *\n * To convert from a Node.js `Buffer`, spread it:\n * `Address4.fromUnsignedByteArray([...buf])`.\n * @param {Array<number>} bytes - an array of 4 unsigned bytes (0-255)\n * @returns {Address4}\n */\n static fromUnsignedByteArray(bytes: Array<number>): Address4 {\n if (bytes.length !== 4) {\n throw new AddressError('IPv4 addresses require exactly 4 bytes');\n }\n\n const address = bytes.join('.');\n return new Address4(address);\n }\n\n /**\n * Returns the first n bits of the address, defaulting to the\n * subnet mask\n * @returns {String}\n */\n mask(mask?: number): string {\n if (mask === undefined) {\n mask = this.subnetMask;\n }\n\n return this.getBitsBase2(0, mask);\n }\n\n /**\n * Returns the bits in the given range as a base-2 string\n * @returns {string}\n */\n getBitsBase2(start: number, end: number): string {\n return this.binaryZeroPad().slice(start, end);\n }\n\n /**\n * Return the reversed in-addr.arpa form of the address, e.g.\n * `42.2.0.192.in-addr.arpa.` for `192.0.2.42`.\n * @param {Object} options\n * @param {boolean} options.omitSuffix - omit the \"in-addr.arpa\" suffix\n * @returns {String}\n */\n reverseForm(options?: common.ReverseFormOptions): string {\n if (!options) {\n options = {};\n }\n\n const reversed = this.correctForm().split('.').reverse().join('.');\n\n if (options.omitSuffix) {\n return reversed;\n }\n\n return `${reversed}.in-addr.arpa.`;\n }\n\n /**\n * Returns true if the given address is in the subnet of the current address\n * @returns {boolean}\n */\n isInSubnet = common.isInSubnet;\n\n /**\n * Returns true if this address's host bits fall inside the given subnet,\n * ignoring this address's own subnet mask. Prefer this over `isInSubnet`\n * when classifying a single address, so the answer doesn't change with the\n * CIDR suffix the caller happened to write — notably when the address came\n * from untrusted input and the result backs a trust-boundary decision.\n * @returns {boolean}\n */\n isHostInSubnet = common.isHostInSubnet;\n\n /**\n * Returns true if the given address is a multicast address\n * @returns {boolean}\n */\n isMulticast(): boolean {\n return this.isHostInSubnet(MULTICAST_V4);\n }\n\n /**\n * Returns true if the address is in one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private address ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`).\n * @returns {boolean}\n */\n isPrivate(): boolean {\n return PRIVATE_V4.some((subnet) => this.isHostInSubnet(subnet));\n }\n\n /**\n * Returns true if the address is in the loopback range `127.0.0.0/8` ([RFC 1122](https://datatracker.ietf.org/doc/html/rfc1122)).\n * @returns {boolean}\n */\n isLoopback(): boolean {\n return this.isHostInSubnet(LOOPBACK_V4);\n }\n\n /**\n * Returns true if the address is in the link-local range `169.254.0.0/16` ([RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927)).\n * @returns {boolean}\n */\n isLinkLocal(): boolean {\n return this.isHostInSubnet(LINK_LOCAL_V4);\n }\n\n /**\n * Returns true if the address is the unspecified address `0.0.0.0`.\n * @returns {boolean}\n */\n isUnspecified(): boolean {\n return this.isHostInSubnet(UNSPECIFIED_V4);\n }\n\n /**\n * Returns true if the address is the limited broadcast address `255.255.255.255` ([RFC 919](https://datatracker.ietf.org/doc/html/rfc919)).\n * @returns {boolean}\n */\n isBroadcast(): boolean {\n return this.isHostInSubnet(BROADCAST_V4);\n }\n\n /**\n * Returns true if the address is in the carrier-grade NAT range `100.64.0.0/10` ([RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598)).\n * @returns {boolean}\n */\n isCGNAT(): boolean {\n return this.isHostInSubnet(CGNAT_V4);\n }\n\n /**\n * Returns a zero-padded base-2 string representation of the address\n * @returns {string}\n */\n binaryZeroPad(): string {\n if (this._binaryZeroPad === undefined) {\n this._binaryZeroPad = this.bigInt().toString(2).padStart(constants.BITS, '0');\n }\n return this._binaryZeroPad;\n }\n\n /**\n * Groups an IPv4 address for inclusion at the end of an IPv6 address.\n *\n * Returns an HTML fragment: each half of the address is wrapped in a\n * `<span>` carrying the group classes an address-inspector UI hovers on.\n * The address content is HTML-escaped; anything you concatenate around it\n * is your responsibility.\n * @returns {String}\n */\n groupForV6(): string {\n const segments = this.parsedAddress;\n\n return this.correctForm().replace(\n constants.RE_ADDRESS,\n `<span class=\"hover-group group-v4 group-6\">${segments\n .slice(0, 2)\n .join('.')}</span>.<span class=\"hover-group group-v4 group-7\">${segments\n .slice(2, 4)\n .join('.')}</span>`,\n );\n }\n}\n\nconst MULTICAST_V4 = new Address4('224.0.0.0/4');\nconst PRIVATE_V4 = [\n new Address4('10.0.0.0/8'),\n new Address4('172.16.0.0/12'),\n new Address4('192.168.0.0/16'),\n];\nconst LOOPBACK_V4 = new Address4('127.0.0.0/8');\nconst LINK_LOCAL_V4 = new Address4('169.254.0.0/16');\nconst UNSPECIFIED_V4 = new Address4('0.0.0.0/32');\nconst BROADCAST_V4 = new Address4('255.255.255.255/32');\nconst CGNAT_V4 = new Address4('100.64.0.0/10');\n"]}
|
|
1
|
+
{"version":3,"file":"ipv4.js","sourceRoot":"","sources":["../src/ipv4.ts"],"names":[],"mappings":";AAAA,sCAAsC;;;;;;;;;;;;;;;;;;;;;;;;;;AAEtC,iDAAmC;AACnC,0DAA4C;AAC5C,mDAA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,YAAY,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC;AACjD,MAAM,UAAU,GAAG;IACjB,IAAI,QAAQ,CAAC,YAAY,CAAC;IAC1B,IAAI,QAAQ,CAAC,eAAe,CAAC;IAC7B,IAAI,QAAQ,CAAC,gBAAgB,CAAC;CAC/B,CAAC;AACF,MAAM,WAAW,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC;AAChD,MAAM,aAAa,GAAG,IAAI,QAAQ,CAAC,gBAAgB,CAAC,CAAC;AACrD,MAAM,cAAc,GAAG,IAAI,QAAQ,CAAC,YAAY,CAAC,CAAC;AAClD,MAAM,YAAY,GAAG,IAAI,QAAQ,CAAC,oBAAoB,CAAC,CAAC;AACxD,MAAM,QAAQ,GAAG,IAAI,QAAQ,CAAC,eAAe,CAAC,CAAC;AAC/C,MAAM,gBAAgB,GAAG;IACvB,IAAI,QAAQ,CAAC,cAAc,CAAC;IAC5B,IAAI,QAAQ,CAAC,iBAAiB,CAAC;IAC/B,IAAI,QAAQ,CAAC,gBAAgB,CAAC;CAC/B,CAAC;AACF,MAAM,eAAe,GAAG,IAAI,QAAQ,CAAC,eAAe,CAAC,CAAC;AACtD,MAAM,WAAW,GAAG,IAAI,QAAQ,CAAC,aAAa,CAAC,CAAC;AAChD,MAAM,kBAAkB,GAAG,SAAS,CAAC,eAAe,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,AAAD,EAAG,SAAS,CAAC,EAAE,EAAE,CAAC,CAAC;IACjF,MAAM,EAAE,IAAI,QAAQ,CAAC,IAAI,CAAC;IAC1B,SAAS;CACV,CAAC,CAAC,CAAC","sourcesContent":["/* eslint-disable no-param-reassign */\n\nimport * as common from './common';\nimport * as constants from './v4/constants';\nimport { AddressError } from './address-error';\n\nconst isCorrect4 = common.isCorrect(constants.BITS);\n\n/**\n * Represents an IPv4 address\n * @param {string} address - An IPv4 address string\n */\nexport class Address4 {\n address: string;\n addressMinusSuffix: string = '';\n groups: number = constants.GROUPS;\n parsedAddress: string[] = [];\n parsedSubnet: string = '';\n subnet: string = '/32';\n subnetMask: number = 32;\n v4: boolean = true;\n private _binaryZeroPad?: string;\n\n constructor(address: string) {\n this.address = address;\n\n const subnet = constants.RE_SUBNET_STRING.exec(address);\n\n if (subnet) {\n this.parsedSubnet = subnet[0].replace('/', '');\n this.subnetMask = parseInt(this.parsedSubnet, 10);\n this.subnet = `/${this.subnetMask}`;\n\n if (this.subnetMask < 0 || this.subnetMask > constants.BITS) {\n throw new AddressError('Invalid subnet mask.');\n }\n\n address = address.replace(constants.RE_SUBNET_STRING, '');\n }\n\n this.addressMinusSuffix = address;\n\n this.parsedAddress = this.parse(address);\n }\n\n /**\n * Returns true if the given string is a valid IPv4 address (with optional\n * CIDR subnet), false otherwise. Host bits in the subnet portion are\n * allowed (e.g. `192.168.1.5/24` is valid); for strict network-address\n * validation compare `correctForm()` to `startAddress().correctForm()`,\n * or use `networkForm()`.\n */\n static isValid(address: string): boolean {\n try {\n // eslint-disable-next-line no-new\n new Address4(address);\n\n return true;\n } catch {\n return false;\n }\n }\n\n /**\n * Parses an IPv4 address string into its four octet groups and stores the\n * result on `this.parsedAddress`. Called automatically by the constructor;\n * you typically don't need to call it directly. Throws `AddressError` if\n * the input is not a valid IPv4 address.\n */\n parse(address: string) {\n const groups = address.split('.');\n\n // Checked before the general match so the error names the actual problem.\n // Address6 rejects the same notation on its v4-in-v6 path.\n if (groups.some((group) => /^0\\d/.test(group))) {\n throw new AddressError(\"IPv4 addresses can't have leading zeroes.\");\n }\n\n if (!address.match(constants.RE_ADDRESS)) {\n throw new AddressError('Invalid IPv4 address.');\n }\n\n return groups;\n }\n\n /**\n * Returns the address in correct form: octets joined with `.` and any\n * leading zeros stripped (e.g. `192.168.1.1`). For IPv4 this matches the\n * canonical dotted-decimal representation.\n */\n correctForm(): string {\n return this.parsedAddress.map((part) => parseInt(part, 10)).join('.');\n }\n\n /**\n * Returns true if the address is correct, false otherwise\n * @returns {Boolean}\n */\n isCorrect = isCorrect4;\n\n /**\n * Construct an `Address4` from an address and a dotted-decimal subnet\n * mask given as separate strings (e.g. as returned by Node's\n * `os.networkInterfaces()`). Throws `AddressError` if the mask is\n * non-contiguous (e.g. `255.0.255.0`).\n * @example\n * var address = Address4.fromAddressAndMask('192.168.1.1', '255.255.255.0');\n * address.subnetMask; // 24\n */\n static fromAddressAndMask(address: string, mask: string): Address4 {\n const bits = common.prefixLengthFromMask(new Address4(mask).bigInt(), constants.BITS);\n return new Address4(`${address}/${bits}`);\n }\n\n /**\n * Construct an `Address4` from an address and a Cisco-style wildcard mask\n * given as separate strings (e.g. `0.0.0.255` for a `/24`). The wildcard\n * mask is the bitwise inverse of the subnet mask. Throws `AddressError`\n * if the mask is non-contiguous (e.g. `0.255.0.255`).\n * @example\n * var address = Address4.fromAddressAndWildcardMask('10.0.0.1', '0.0.0.255');\n * address.subnetMask; // 24\n */\n static fromAddressAndWildcardMask(address: string, wildcardMask: string): Address4 {\n const wildcard = new Address4(wildcardMask).bigInt();\n const allOnes = (BigInt(1) << BigInt(constants.BITS)) - BigInt(1);\n const mask = wildcard ^ allOnes;\n const bits = common.prefixLengthFromMask(mask, constants.BITS);\n return new Address4(`${address}/${bits}`);\n }\n\n /**\n * Construct an `Address4` from a wildcard pattern with trailing `*`\n * octets. The number of trailing wildcards determines the prefix\n * length: each `*` represents 8 bits.\n *\n * Only trailing whole-octet wildcards are supported. Partial-octet\n * wildcards (e.g. `192.168.0.1*`) and interior wildcards (e.g.\n * `192.*.0.1`) throw `AddressError`.\n * @example\n * Address4.fromWildcard('192.168.0.*').subnet; // '/24'\n * Address4.fromWildcard('192.168.*.*').subnet; // '/16'\n * Address4.fromWildcard('*.*.*.*').subnet; // '/0'\n */\n static fromWildcard(input: string): Address4 {\n const groups = input.split('.');\n\n if (groups.length !== constants.GROUPS) {\n throw new AddressError('Wildcard pattern must have 4 octets');\n }\n\n let firstWildcard = -1;\n\n for (let i = 0; i < groups.length; i++) {\n if (groups[i] === '*') {\n if (firstWildcard === -1) {\n firstWildcard = i;\n }\n } else if (firstWildcard !== -1) {\n throw new AddressError(\n 'Wildcard `*` must only appear in trailing octets (e.g. `192.168.0.*`)',\n );\n }\n }\n\n const trailing = firstWildcard === -1 ? 0 : groups.length - firstWildcard;\n const replaced = groups.map((g) => (g === '*' ? '0' : g));\n const subnetBits = constants.BITS - trailing * 8;\n\n return new Address4(`${replaced.join('.')}/${subnetBits}`);\n }\n\n /**\n * Converts a hex string to an IPv4 address object. Accepts 8 hex digits\n * with optional `:` separators (e.g. `'7f000001'` or `'7f:00:00:01'`).\n * Throws `AddressError` for any other length or for non-hex characters.\n * @param {string} hex - a hex string to convert\n * @returns {Address4}\n */\n static fromHex(hex: string): Address4 {\n const stripped = hex.replace(/:/g, '');\n\n if (!/^[0-9a-fA-F]{8}$/.test(stripped)) {\n throw new AddressError('IPv4 hex must be exactly 8 hex digits');\n }\n\n const groups = [];\n\n for (let i = 0; i < 8; i += 2) {\n groups.push(parseInt(stripped.slice(i, i + 2), 16));\n }\n\n return new Address4(groups.join('.'));\n }\n\n /**\n * Converts an integer into a IPv4 address object. The integer must be a\n * non-negative safe integer in the range `[0, 2**32 - 1]`; otherwise\n * `AddressError` is thrown.\n * @param {integer} integer - a number to convert\n * @returns {Address4}\n */\n static fromInteger(integer: number): Address4 {\n if (!Number.isInteger(integer) || integer < 0 || integer > 0xffffffff) {\n throw new AddressError('IPv4 integer must be in the range 0 to 2**32 - 1');\n }\n\n return Address4.fromHex(integer.toString(16).padStart(8, '0'));\n }\n\n /**\n * Return an address from in-addr.arpa form\n * @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address\n * @returns {Adress4}\n * @example\n * var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.)\n * address.correctForm(); // '192.0.2.42'\n */\n static fromArpa(arpaFormAddress: string): Address4 {\n // remove ending \".in-addr.arpa.\" or just \".\"\n const leader = arpaFormAddress.replace(/(\\.in-addr\\.arpa)?\\.$/, '');\n\n const address = leader.split('.').reverse().join('.');\n\n return new Address4(address);\n }\n\n /**\n * Converts an IPv4 address object to a hex string\n * @returns {String}\n */\n toHex(): string {\n return this.parsedAddress.map((part) => common.stringToPaddedHex(part)).join(':');\n }\n\n /**\n * Converts an IPv4 address object to an array of bytes.\n *\n * To get a Node.js `Buffer`, wrap the result: `Buffer.from(address.toArray())`.\n * @returns {Array}\n */\n toArray(): number[] {\n return this.parsedAddress.map((part) => parseInt(part, 10));\n }\n\n /**\n * Converts an IPv4 address object to an IPv6 address group\n * @returns {String}\n */\n toGroup6(): string {\n const output = [];\n let i;\n\n for (i = 0; i < constants.GROUPS; i += 2) {\n output.push(\n `${common.stringToPaddedHex(this.parsedAddress[i])}${common.stringToPaddedHex(\n this.parsedAddress[i + 1],\n )}`,\n );\n }\n\n return output.join(':');\n }\n\n /**\n * Returns the address as a `bigint`\n * @returns {bigint}\n */\n bigInt(): bigint {\n return BigInt(`0x${this.parsedAddress.map((n) => common.stringToPaddedHex(n)).join('')}`);\n }\n\n /**\n * Helper function getting start address.\n * @returns {bigint}\n */\n _startAddress(): bigint {\n return BigInt(`0b${this.mask() + '0'.repeat(constants.BITS - this.subnetMask)}`);\n }\n\n /**\n * The first address in the range given by this address' subnet.\n * Often referred to as the Network Address.\n * @returns {Address4}\n */\n startAddress(): Address4 {\n return Address4.fromBigInt(this._startAddress());\n }\n\n /**\n * The first host address in the range given by this address's subnet ie\n * the first address after the Network Address\n * @returns {Address4}\n */\n startAddressExclusive(): Address4 {\n const adjust = BigInt('1');\n return Address4.fromBigInt(this._startAddress() + adjust);\n }\n\n /**\n * Returns the address `n` addresses after this one (or before, when `n` is\n * negative), keeping this address's subnet mask. Throws `AddressError` when\n * the result would fall outside the IPv4 address space or `n` is not an\n * integer.\n * @param {number | bigint} n\n * @returns {Address4}\n * @example\n * new Address4('10.0.0.0/24').offset(1).correctForm(); // '10.0.0.1'\n */\n offset(n: number | bigint): Address4 {\n return Address4.fromBigInt(\n common.offsetBigInt(this.bigInt(), n, constants.BITS, 'IPv4'),\n ).withSubnetMask(this.subnetMask);\n }\n\n /**\n * Returns the network that follows this address's network: the address after\n * {@link endAddress}, with the same subnet mask. Throws `AddressError` when\n * this network is the last one in the address space.\n * @returns {Address4}\n * @example\n * new Address4('10.0.0.0/24').nextNetwork().networkForm(); // '10.0.1.0/24'\n */\n nextNetwork(): Address4 {\n return Address4.fromBigInt(\n common.offsetBigInt(this._endAddress(), 1, constants.BITS, 'IPv4'),\n ).withSubnetMask(this.subnetMask);\n }\n\n private withSubnetMask(subnetMask: number): Address4 {\n return new Address4(`${this.correctForm()}/${subnetMask}`);\n }\n\n /**\n * Helper function getting end address.\n * @returns {bigint}\n */\n _endAddress(): bigint {\n return BigInt(`0b${this.mask() + '1'.repeat(constants.BITS - this.subnetMask)}`);\n }\n\n /**\n * The last address in the range given by this address' subnet\n * Often referred to as the Broadcast\n * @returns {Address4}\n */\n endAddress(): Address4 {\n return Address4.fromBigInt(this._endAddress());\n }\n\n /**\n * The last host address in the range given by this address's subnet ie\n * the last address prior to the Broadcast Address\n * @returns {Address4}\n */\n endAddressExclusive(): Address4 {\n const adjust = BigInt('1');\n return Address4.fromBigInt(this._endAddress() - adjust);\n }\n\n /**\n * The dotted-decimal form of the subnet mask, e.g. `255.255.240.0` for\n * a `/20`. Returns an `Address4`; call `.correctForm()` for the string.\n * @returns {Address4}\n */\n subnetMaskAddress(): Address4 {\n return Address4.fromBigInt(\n BigInt(`0b${'1'.repeat(this.subnetMask)}${'0'.repeat(constants.BITS - this.subnetMask)}`),\n );\n }\n\n /**\n * The Cisco-style wildcard mask, e.g. `0.0.0.255` for a `/24`. This is\n * the bitwise inverse of `subnetMaskAddress()`. Returns an `Address4`;\n * call `.correctForm()` for the string.\n * @returns {Address4}\n */\n wildcardMask(): Address4 {\n return Address4.fromBigInt(\n BigInt(`0b${'0'.repeat(this.subnetMask)}${'1'.repeat(constants.BITS - this.subnetMask)}`),\n );\n }\n\n /**\n * The network address in CIDR string form, e.g. `192.168.1.0/24` for\n * `192.168.1.5/24`. For an address with no explicit subnet the prefix is\n * `/32`, e.g. `networkForm()` on `192.168.1.5` returns `192.168.1.5/32`.\n * @returns {string}\n */\n networkForm(): string {\n return `${this.startAddress().correctForm()}/${this.subnetMask}`;\n }\n\n /**\n * Converts a BigInt to a v4 address object. The value must be in the\n * range `[0, 2**32 - 1]`; otherwise `AddressError` is thrown.\n * @param {bigint} bigInt - a BigInt to convert\n * @returns {Address4}\n */\n static fromBigInt(bigInt: bigint): Address4 {\n if (bigInt < BigInt(0) || bigInt > BigInt(0xffffffff)) {\n throw new AddressError('IPv4 BigInt must be in the range 0 to 2**32 - 1');\n }\n\n return Address4.fromHex(bigInt.toString(16).padStart(8, '0'));\n }\n\n /**\n * Convert a byte array to an Address4 object. Throws `AddressError` unless\n * given exactly 4 integers from 0 to 255. Signed bytes are rejected, so\n * this differs from `Address6.fromByteArray`, which folds them; the two\n * contracts converge on this stricter form in the next major version.\n *\n * To convert from a Node.js `Buffer`, spread it: `Address4.fromByteArray([...buf])`.\n * @param {Array<number>} bytes - an array of 4 bytes (0-255)\n * @returns {Address4}\n */\n static fromByteArray(bytes: Array<number>): Address4 {\n common.assertByteArray(bytes, 4, 'IPv4', 0);\n\n return this.fromUnsignedByteArray(bytes);\n }\n\n /**\n * Convert an unsigned byte array to an Address4 object. Throws\n * `AddressError` unless given exactly 4 bytes, and rejects values outside\n * 0 to 255 when parsing the resulting address.\n *\n * To convert from a Node.js `Buffer`, spread it:\n * `Address4.fromUnsignedByteArray([...buf])`.\n * @param {Array<number>} bytes - an array of 4 unsigned bytes (0-255)\n * @returns {Address4}\n */\n static fromUnsignedByteArray(bytes: Array<number>): Address4 {\n if (bytes.length !== 4) {\n throw new AddressError('IPv4 addresses require exactly 4 bytes');\n }\n\n const address = bytes.join('.');\n return new Address4(address);\n }\n\n /**\n * Returns the first n bits of the address, defaulting to the\n * subnet mask\n * @returns {String}\n */\n mask(mask?: number): string {\n if (mask === undefined) {\n mask = this.subnetMask;\n }\n\n return this.getBitsBase2(0, mask);\n }\n\n /**\n * Returns the bits in the given range as a base-2 string\n * @returns {string}\n */\n getBitsBase2(start: number, end: number): string {\n return this.binaryZeroPad().slice(start, end);\n }\n\n /**\n * Return the reversed in-addr.arpa form of the address, e.g.\n * `42.2.0.192.in-addr.arpa.` for `192.0.2.42`.\n * @param {Object} options\n * @param {boolean} options.omitSuffix - omit the \"in-addr.arpa\" suffix\n * @returns {String}\n */\n reverseForm(options?: common.ReverseFormOptions): string {\n if (!options) {\n options = {};\n }\n\n const reversed = this.correctForm().split('.').reverse().join('.');\n\n if (options.omitSuffix) {\n return reversed;\n }\n\n return `${reversed}.in-addr.arpa.`;\n }\n\n /**\n * Returns true if the given address is in the subnet of the current address\n * @returns {boolean}\n */\n isInSubnet = common.isInSubnet;\n\n /**\n * Returns true if this address's host bits fall inside the given subnet,\n * ignoring this address's own subnet mask. Prefer this over `isInSubnet`\n * when classifying a single address, so the answer doesn't change with the\n * CIDR suffix the caller happened to write — notably when the address came\n * from untrusted input and the result backs a trust-boundary decision.\n * @returns {boolean}\n */\n isHostInSubnet = common.isHostInSubnet;\n\n /**\n * Returns true if the given address is a multicast address\n * @returns {boolean}\n */\n isMulticast(): boolean {\n return this.isHostInSubnet(MULTICAST_V4);\n }\n\n /**\n * Returns true if the address is in one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918) private address ranges (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`).\n * @returns {boolean}\n */\n isPrivate(): boolean {\n return PRIVATE_V4.some((subnet) => this.isHostInSubnet(subnet));\n }\n\n /**\n * Returns true if the address is in the loopback range `127.0.0.0/8` ([RFC 1122](https://datatracker.ietf.org/doc/html/rfc1122)).\n * @returns {boolean}\n */\n isLoopback(): boolean {\n return this.isHostInSubnet(LOOPBACK_V4);\n }\n\n /**\n * Returns true if the address is in the link-local range `169.254.0.0/16` ([RFC 3927](https://datatracker.ietf.org/doc/html/rfc3927)).\n * @returns {boolean}\n */\n isLinkLocal(): boolean {\n return this.isHostInSubnet(LINK_LOCAL_V4);\n }\n\n /**\n * Returns true if the address is the unspecified address `0.0.0.0`.\n * @returns {boolean}\n */\n isUnspecified(): boolean {\n return this.isHostInSubnet(UNSPECIFIED_V4);\n }\n\n /**\n * Returns true if the address is the limited broadcast address `255.255.255.255` ([RFC 919](https://datatracker.ietf.org/doc/html/rfc919)).\n * @returns {boolean}\n */\n isBroadcast(): boolean {\n return this.isHostInSubnet(BROADCAST_V4);\n }\n\n /**\n * Returns true if the address is in the carrier-grade NAT range `100.64.0.0/10` ([RFC 6598](https://datatracker.ietf.org/doc/html/rfc6598)).\n * @returns {boolean}\n */\n isCGNAT(): boolean {\n return this.isHostInSubnet(CGNAT_V4);\n }\n\n /**\n * Returns true if the address is in one of the documentation ranges\n * `192.0.2.0/24`, `198.51.100.0/24`, or `203.0.113.0/24` ([RFC 5737](https://datatracker.ietf.org/doc/html/rfc5737)).\n * @returns {boolean}\n */\n isDocumentation(): boolean {\n return DOCUMENTATION_V4.some((subnet) => this.isHostInSubnet(subnet));\n }\n\n /**\n * Returns true if the address is in the benchmarking range `198.18.0.0/15` ([RFC 2544](https://datatracker.ietf.org/doc/html/rfc2544)).\n * @returns {boolean}\n */\n isBenchmarking(): boolean {\n return this.isHostInSubnet(BENCHMARKING_V4);\n }\n\n /**\n * Returns true if the address is in the reserved range `240.0.0.0/4` ([RFC 1112](https://datatracker.ietf.org/doc/html/rfc1112)),\n * which includes the limited broadcast address.\n * @returns {boolean}\n */\n isReserved(): boolean {\n return this.isHostInSubnet(RESERVED_V4);\n }\n\n /**\n * Returns true if the address is globally reachable: not multicast, and not\n * in any block the [IANA IPv4 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv4-special-registry/)\n * marks as not globally reachable. That covers everything the individual\n * classifiers name (private, loopback, link-local, CGNAT, unspecified,\n * broadcast, documentation, benchmarking, reserved) and the blocks they do\n * not, such as `0.0.0.0/8` and the IETF protocol assignments in\n * `192.0.0.0/24`. This is the single predicate to use where a request must\n * not reach an internal or special-purpose destination; see SECURITY.md.\n * @returns {boolean}\n */\n isGlobal(): boolean {\n return !this.isMulticast() && common.isGloballyReachable.call(this, SPECIAL_PURPOSE_V4);\n }\n\n /**\n * Returns a zero-padded base-2 string representation of the address\n * @returns {string}\n */\n binaryZeroPad(): string {\n if (this._binaryZeroPad === undefined) {\n this._binaryZeroPad = this.bigInt().toString(2).padStart(constants.BITS, '0');\n }\n return this._binaryZeroPad;\n }\n\n /**\n * Groups an IPv4 address for inclusion at the end of an IPv6 address.\n *\n * Returns an HTML fragment: each half of the address is wrapped in a\n * `<span>` carrying the group classes an address-inspector UI hovers on.\n * The address content is HTML-escaped; anything you concatenate around it\n * is your responsibility.\n * @returns {String}\n */\n groupForV6(): string {\n const segments = this.parsedAddress;\n\n return this.correctForm().replace(\n constants.RE_ADDRESS,\n `<span class=\"hover-group group-v4 group-6\">${segments\n .slice(0, 2)\n .join('.')}</span>.<span class=\"hover-group group-v4 group-7\">${segments\n .slice(2, 4)\n .join('.')}</span>`,\n );\n }\n}\n\nconst MULTICAST_V4 = new Address4('224.0.0.0/4');\nconst PRIVATE_V4 = [\n new Address4('10.0.0.0/8'),\n new Address4('172.16.0.0/12'),\n new Address4('192.168.0.0/16'),\n];\nconst LOOPBACK_V4 = new Address4('127.0.0.0/8');\nconst LINK_LOCAL_V4 = new Address4('169.254.0.0/16');\nconst UNSPECIFIED_V4 = new Address4('0.0.0.0/32');\nconst BROADCAST_V4 = new Address4('255.255.255.255/32');\nconst CGNAT_V4 = new Address4('100.64.0.0/10');\nconst DOCUMENTATION_V4 = [\n new Address4('192.0.2.0/24'),\n new Address4('198.51.100.0/24'),\n new Address4('203.0.113.0/24'),\n];\nconst BENCHMARKING_V4 = new Address4('198.18.0.0/15');\nconst RESERVED_V4 = new Address4('240.0.0.0/4');\nconst SPECIAL_PURPOSE_V4 = constants.SPECIAL_PURPOSE.map(([cidr, , reachable]) => ({\n subnet: new Address4(cidr),\n reachable,\n}));\n"]}
|
|
@@ -126,12 +126,16 @@ export declare class Address6 {
|
|
|
126
126
|
*/
|
|
127
127
|
static fromAddress4(address: string): Address6;
|
|
128
128
|
/**
|
|
129
|
-
* Return an address from ip6.arpa form
|
|
129
|
+
* Return an address from ip6.arpa form. A full 32-nibble name gives a /128
|
|
130
|
+
* address; a shorter name, as used for a delegated reverse zone, gives the
|
|
131
|
+
* network it covers, with a subnet mask of four bits per nibble, so
|
|
132
|
+
* `fromArpa(x.reverseForm())` round-trips {@link reverseForm} for any prefix.
|
|
130
133
|
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
|
131
134
|
* @returns {Adress6}
|
|
132
135
|
* @example
|
|
133
136
|
* var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
|
|
134
137
|
* address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
|
|
138
|
+
* Address6.fromArpa('8.b.d.0.1.0.0.2.ip6.arpa.').networkForm(); // '2001:db8::/32'
|
|
135
139
|
*/
|
|
136
140
|
static fromArpa(arpaFormAddress: string): Address6;
|
|
137
141
|
/**
|
|
@@ -174,17 +178,42 @@ export declare class Address6 {
|
|
|
174
178
|
*/
|
|
175
179
|
_endAddress(): bigint;
|
|
176
180
|
/**
|
|
177
|
-
* The last address in the range given by this address' subnet
|
|
178
|
-
*
|
|
181
|
+
* The last address in the range given by this address's subnet. IPv6 has
|
|
182
|
+
* no broadcast address, so this is an ordinary assignable address (in a
|
|
183
|
+
* 64-bit-interface-identifier subnet it falls inside the reserved
|
|
184
|
+
* subnet-anycast block of [RFC 2526](https://datatracker.ietf.org/doc/html/rfc2526)).
|
|
179
185
|
* @returns {Address6}
|
|
180
186
|
*/
|
|
181
187
|
endAddress(): Address6;
|
|
182
188
|
/**
|
|
183
|
-
* The
|
|
184
|
-
* the
|
|
189
|
+
* The address one before {@link endAddress}. This is the IPv6 counterpart
|
|
190
|
+
* of the IPv4 method that skips the broadcast address; IPv6 has no broadcast,
|
|
191
|
+
* so it drops exactly one address and does not model the 128 reserved
|
|
192
|
+
* subnet-anycast identifiers of [RFC 2526](https://datatracker.ietf.org/doc/html/rfc2526).
|
|
185
193
|
* @returns {Address6}
|
|
186
194
|
*/
|
|
187
195
|
endAddressExclusive(): Address6;
|
|
196
|
+
/**
|
|
197
|
+
* Returns the address `n` addresses after this one (or before, when `n` is
|
|
198
|
+
* negative), keeping this address's subnet mask. Throws `AddressError` when
|
|
199
|
+
* the result would fall outside the IPv6 address space or `n` is not an
|
|
200
|
+
* integer.
|
|
201
|
+
* @param {number | bigint} n
|
|
202
|
+
* @returns {Address6}
|
|
203
|
+
* @example
|
|
204
|
+
* new Address6('2001:db8::/64').offset(1).correctForm(); // '2001:db8::1'
|
|
205
|
+
*/
|
|
206
|
+
offset(n: number | bigint): Address6;
|
|
207
|
+
/**
|
|
208
|
+
* Returns the network that follows this address's network: the address after
|
|
209
|
+
* {@link endAddress}, with the same subnet mask. Throws `AddressError` when
|
|
210
|
+
* this network is the last one in the address space.
|
|
211
|
+
* @returns {Address6}
|
|
212
|
+
* @example
|
|
213
|
+
* new Address6('2001:db8::/64').nextNetwork().networkForm(); // '2001:db8:0:1::/64'
|
|
214
|
+
*/
|
|
215
|
+
nextNetwork(): Address6;
|
|
216
|
+
private withSubnetMask;
|
|
188
217
|
/**
|
|
189
218
|
* The hex form of the subnet mask, e.g. `ffff:ffff:ffff:ffff::` for a
|
|
190
219
|
* `/64`. Returns an `Address6`; call `.correctForm()` for the string.
|
|
@@ -411,7 +440,10 @@ export declare class Address6 {
|
|
|
411
440
|
*/
|
|
412
441
|
isCanonical(): boolean;
|
|
413
442
|
/**
|
|
414
|
-
* Returns true if the address is a link
|
|
443
|
+
* Returns true if the address is a link-local unicast address in `fe80::/10`
|
|
444
|
+
* ([RFC 4291 §2.4](https://datatracker.ietf.org/doc/html/rfc4291#section-2.4))
|
|
445
|
+
* or an IPv4-mapped / NAT64 address whose embedded IPv4 address is link-local
|
|
446
|
+
* (`169.254.0.0/16`, e.g. `::ffff:169.254.169.254`), false otherwise.
|
|
415
447
|
* @returns {boolean}
|
|
416
448
|
*/
|
|
417
449
|
isLinkLocal(): boolean;
|
|
@@ -477,12 +509,20 @@ export declare class Address6 {
|
|
|
477
509
|
isULA(): boolean;
|
|
478
510
|
/**
|
|
479
511
|
* Returns true if the address is private, i.e. a Unique Local Address in
|
|
480
|
-
* `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193))
|
|
481
|
-
*
|
|
482
|
-
* [RFC
|
|
483
|
-
*
|
|
512
|
+
* `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)), an
|
|
513
|
+
* address in the NAT64 local-use range `64:ff9b:1::/48`
|
|
514
|
+
* ([RFC 8215](https://datatracker.ietf.org/doc/html/rfc8215)), or an
|
|
515
|
+
* IPv4-mapped / NAT64 well-known address whose embedded IPv4 address is in
|
|
516
|
+
* one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918)
|
|
517
|
+
* private ranges (e.g. `::ffff:10.0.0.1`). This is the IPv6 counterpart to
|
|
484
518
|
* {@link Address4.isPrivate}; use it instead of {@link isULA} when you need to
|
|
485
519
|
* catch mapped RFC 1918 addresses as well as native ULAs.
|
|
520
|
+
*
|
|
521
|
+
* The local-use NAT64 range is reported private as a whole rather than by
|
|
522
|
+
* its embedded IPv4 address: an operator may carve a prefix of any RFC 6052
|
|
523
|
+
* length out of `64:ff9b:1::/48`, so the same bits decode to different IPv4
|
|
524
|
+
* addresses under different deployments and no single decoding is correct.
|
|
525
|
+
* Use {@link toAddress4Nat64} with the deployment's prefix to decode one.
|
|
486
526
|
* @returns {boolean}
|
|
487
527
|
*/
|
|
488
528
|
isPrivate(): boolean;
|
|
@@ -514,6 +554,35 @@ export declare class Address6 {
|
|
|
514
554
|
* @returns {boolean}
|
|
515
555
|
*/
|
|
516
556
|
isDocumentation(): boolean;
|
|
557
|
+
/**
|
|
558
|
+
* Returns true if the address is in the benchmarking range `2001:2::/48`
|
|
559
|
+
* ([RFC 5180](https://datatracker.ietf.org/doc/html/rfc5180)) or is an
|
|
560
|
+
* IPv4-mapped / NAT64 address whose embedded IPv4 address is in
|
|
561
|
+
* `198.18.0.0/15`, false otherwise.
|
|
562
|
+
* @returns {boolean}
|
|
563
|
+
*/
|
|
564
|
+
isBenchmarking(): boolean;
|
|
565
|
+
/**
|
|
566
|
+
* Returns true if the address is globally reachable: inside the global
|
|
567
|
+
* unicast allocation `2000::/3` (the only range the [IANA IPv6 Address Space
|
|
568
|
+
* Registry](https://www.iana.org/assignments/ipv6-address-space/) assigns
|
|
569
|
+
* for global unicast; everything else is reserved, ULA, link-local, or
|
|
570
|
+
* multicast) and not in any block the [IANA IPv6 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/)
|
|
571
|
+
* marks as not globally reachable. An IPv4-mapped or NAT64 well-known
|
|
572
|
+
* address answers for its embedded IPv4 address, so `::ffff:10.0.0.1` and
|
|
573
|
+
* `64:ff9b::7f00:1` are not global. Teredo (`2001::/32`) and 6to4
|
|
574
|
+
* (`2002::/16`) are not global either: the registry lists them as N/A and a
|
|
575
|
+
* packet to one needs a relay.
|
|
576
|
+
*
|
|
577
|
+
* This covers everything the individual classifiers name and the blocks they
|
|
578
|
+
* do not: the discard-only prefix `100::/64`, the IETF protocol assignments
|
|
579
|
+
* in `2001::/23`, the deprecated site-local `fec0::/10` and IPv4-compatible
|
|
580
|
+
* `::/96` ranges, and unallocated space such as `4000::/3`. It is the single
|
|
581
|
+
* predicate to use where a request must not reach an internal or
|
|
582
|
+
* special-purpose destination; see SECURITY.md.
|
|
583
|
+
* @returns {boolean}
|
|
584
|
+
*/
|
|
585
|
+
isGlobal(): boolean;
|
|
517
586
|
/**
|
|
518
587
|
* Returns the address as an HTTP URL with the host bracketed, e.g.
|
|
519
588
|
* `http://[2001:db8::1]/`. If `optionalPort` is provided it is appended,
|
|
@@ -339,28 +339,31 @@ class Address6 {
|
|
|
339
339
|
return new Address6(`::ffff:${address4.correctForm()}/${mask6}`);
|
|
340
340
|
}
|
|
341
341
|
/**
|
|
342
|
-
* Return an address from ip6.arpa form
|
|
342
|
+
* Return an address from ip6.arpa form. A full 32-nibble name gives a /128
|
|
343
|
+
* address; a shorter name, as used for a delegated reverse zone, gives the
|
|
344
|
+
* network it covers, with a subnet mask of four bits per nibble, so
|
|
345
|
+
* `fromArpa(x.reverseForm())` round-trips {@link reverseForm} for any prefix.
|
|
343
346
|
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
|
344
347
|
* @returns {Adress6}
|
|
345
348
|
* @example
|
|
346
349
|
* var address = Address6.fromArpa(e.f.f.f.3.c.2.6.f.f.f.e.6.6.8.e.1.0.6.7.9.4.e.c.0.0.0.0.1.0.0.2.ip6.arpa.)
|
|
347
350
|
* address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
|
|
351
|
+
* Address6.fromArpa('8.b.d.0.1.0.0.2.ip6.arpa.').networkForm(); // '2001:db8::/32'
|
|
348
352
|
*/
|
|
349
353
|
static fromArpa(arpaFormAddress) {
|
|
350
|
-
// remove ending ".ip6.arpa
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
// correct ip6.arpa form with ending removed will be 63 characters
|
|
354
|
-
if (address.length !== 63) {
|
|
354
|
+
// remove an ending ".ip6.arpa", with or without the root dot
|
|
355
|
+
const nibbles = arpaFormAddress.replace(/(\.ip6\.arpa)?\.?$/, '');
|
|
356
|
+
if (!/^[0-9a-f](\.[0-9a-f]){0,31}$/i.test(nibbles)) {
|
|
355
357
|
throw new address_error_1.AddressError("Invalid 'ip6.arpa' form.");
|
|
356
358
|
}
|
|
357
|
-
const
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
359
|
+
const reversed = nibbles.split('.').reverse();
|
|
360
|
+
const subnetMask = reversed.length * 4;
|
|
361
|
+
const hex = reversed.join('').padEnd(32, '0');
|
|
362
|
+
const groups = [];
|
|
363
|
+
for (let i = 0; i < constants6.GROUPS; i++) {
|
|
364
|
+
groups.push(hex.slice(i * 4, (i + 1) * 4));
|
|
361
365
|
}
|
|
362
|
-
|
|
363
|
-
return new Address6(address);
|
|
366
|
+
return new Address6(`${groups.join(':')}/${subnetMask}`);
|
|
364
367
|
}
|
|
365
368
|
/**
|
|
366
369
|
* Return the Microsoft UNC transcription of the address
|
|
@@ -424,22 +427,53 @@ class Address6 {
|
|
|
424
427
|
return BigInt(`0b${this.mask() + '1'.repeat(constants6.BITS - this.subnetMask)}`);
|
|
425
428
|
}
|
|
426
429
|
/**
|
|
427
|
-
* The last address in the range given by this address' subnet
|
|
428
|
-
*
|
|
430
|
+
* The last address in the range given by this address's subnet. IPv6 has
|
|
431
|
+
* no broadcast address, so this is an ordinary assignable address (in a
|
|
432
|
+
* 64-bit-interface-identifier subnet it falls inside the reserved
|
|
433
|
+
* subnet-anycast block of [RFC 2526](https://datatracker.ietf.org/doc/html/rfc2526)).
|
|
429
434
|
* @returns {Address6}
|
|
430
435
|
*/
|
|
431
436
|
endAddress() {
|
|
432
437
|
return Address6.fromBigInt(this._endAddress());
|
|
433
438
|
}
|
|
434
439
|
/**
|
|
435
|
-
* The
|
|
436
|
-
* the
|
|
440
|
+
* The address one before {@link endAddress}. This is the IPv6 counterpart
|
|
441
|
+
* of the IPv4 method that skips the broadcast address; IPv6 has no broadcast,
|
|
442
|
+
* so it drops exactly one address and does not model the 128 reserved
|
|
443
|
+
* subnet-anycast identifiers of [RFC 2526](https://datatracker.ietf.org/doc/html/rfc2526).
|
|
437
444
|
* @returns {Address6}
|
|
438
445
|
*/
|
|
439
446
|
endAddressExclusive() {
|
|
440
447
|
const adjust = BigInt('1');
|
|
441
448
|
return Address6.fromBigInt(this._endAddress() - adjust);
|
|
442
449
|
}
|
|
450
|
+
/**
|
|
451
|
+
* Returns the address `n` addresses after this one (or before, when `n` is
|
|
452
|
+
* negative), keeping this address's subnet mask. Throws `AddressError` when
|
|
453
|
+
* the result would fall outside the IPv6 address space or `n` is not an
|
|
454
|
+
* integer.
|
|
455
|
+
* @param {number | bigint} n
|
|
456
|
+
* @returns {Address6}
|
|
457
|
+
* @example
|
|
458
|
+
* new Address6('2001:db8::/64').offset(1).correctForm(); // '2001:db8::1'
|
|
459
|
+
*/
|
|
460
|
+
offset(n) {
|
|
461
|
+
return Address6.fromBigInt(common.offsetBigInt(this.bigInt(), n, constants6.BITS, 'IPv6')).withSubnetMask(this.subnetMask);
|
|
462
|
+
}
|
|
463
|
+
/**
|
|
464
|
+
* Returns the network that follows this address's network: the address after
|
|
465
|
+
* {@link endAddress}, with the same subnet mask. Throws `AddressError` when
|
|
466
|
+
* this network is the last one in the address space.
|
|
467
|
+
* @returns {Address6}
|
|
468
|
+
* @example
|
|
469
|
+
* new Address6('2001:db8::/64').nextNetwork().networkForm(); // '2001:db8:0:1::/64'
|
|
470
|
+
*/
|
|
471
|
+
nextNetwork() {
|
|
472
|
+
return Address6.fromBigInt(common.offsetBigInt(this._endAddress(), 1, constants6.BITS, 'IPv6')).withSubnetMask(this.subnetMask);
|
|
473
|
+
}
|
|
474
|
+
withSubnetMask(subnetMask) {
|
|
475
|
+
return new Address6(`${this.correctForm()}/${subnetMask}`);
|
|
476
|
+
}
|
|
443
477
|
/**
|
|
444
478
|
* The hex form of the subnet mask, e.g. `ffff:ffff:ffff:ffff::` for a
|
|
445
479
|
* `/64`. Returns an `Address6`; call `.correctForm()` for the string.
|
|
@@ -1022,7 +1056,10 @@ class Address6 {
|
|
|
1022
1056
|
return this.addressMinusSuffix === this.canonicalForm();
|
|
1023
1057
|
}
|
|
1024
1058
|
/**
|
|
1025
|
-
* Returns true if the address is a link
|
|
1059
|
+
* Returns true if the address is a link-local unicast address in `fe80::/10`
|
|
1060
|
+
* ([RFC 4291 §2.4](https://datatracker.ietf.org/doc/html/rfc4291#section-2.4))
|
|
1061
|
+
* or an IPv4-mapped / NAT64 address whose embedded IPv4 address is link-local
|
|
1062
|
+
* (`169.254.0.0/16`, e.g. `::ffff:169.254.169.254`), false otherwise.
|
|
1026
1063
|
* @returns {boolean}
|
|
1027
1064
|
*/
|
|
1028
1065
|
isLinkLocal() {
|
|
@@ -1030,12 +1067,7 @@ class Address6 {
|
|
|
1030
1067
|
if (embedded) {
|
|
1031
1068
|
return embedded.isLinkLocal();
|
|
1032
1069
|
}
|
|
1033
|
-
|
|
1034
|
-
if (this.getBitsBase2(0, 64) ===
|
|
1035
|
-
'1111111010000000000000000000000000000000000000000000000000000000') {
|
|
1036
|
-
return true;
|
|
1037
|
-
}
|
|
1038
|
-
return false;
|
|
1070
|
+
return this.isHostInSubnet(LINK_LOCAL_SUBNET);
|
|
1039
1071
|
}
|
|
1040
1072
|
/**
|
|
1041
1073
|
* Returns true if the address is a multicast address, false otherwise
|
|
@@ -1127,12 +1159,20 @@ class Address6 {
|
|
|
1127
1159
|
}
|
|
1128
1160
|
/**
|
|
1129
1161
|
* Returns true if the address is private, i.e. a Unique Local Address in
|
|
1130
|
-
* `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193))
|
|
1131
|
-
*
|
|
1132
|
-
* [RFC
|
|
1133
|
-
*
|
|
1162
|
+
* `fc00::/7` ([RFC 4193](https://datatracker.ietf.org/doc/html/rfc4193)), an
|
|
1163
|
+
* address in the NAT64 local-use range `64:ff9b:1::/48`
|
|
1164
|
+
* ([RFC 8215](https://datatracker.ietf.org/doc/html/rfc8215)), or an
|
|
1165
|
+
* IPv4-mapped / NAT64 well-known address whose embedded IPv4 address is in
|
|
1166
|
+
* one of the [RFC 1918](https://datatracker.ietf.org/doc/html/rfc1918)
|
|
1167
|
+
* private ranges (e.g. `::ffff:10.0.0.1`). This is the IPv6 counterpart to
|
|
1134
1168
|
* {@link Address4.isPrivate}; use it instead of {@link isULA} when you need to
|
|
1135
1169
|
* catch mapped RFC 1918 addresses as well as native ULAs.
|
|
1170
|
+
*
|
|
1171
|
+
* The local-use NAT64 range is reported private as a whole rather than by
|
|
1172
|
+
* its embedded IPv4 address: an operator may carve a prefix of any RFC 6052
|
|
1173
|
+
* length out of `64:ff9b:1::/48`, so the same bits decode to different IPv4
|
|
1174
|
+
* addresses under different deployments and no single decoding is correct.
|
|
1175
|
+
* Use {@link toAddress4Nat64} with the deployment's prefix to decode one.
|
|
1136
1176
|
* @returns {boolean}
|
|
1137
1177
|
*/
|
|
1138
1178
|
isPrivate() {
|
|
@@ -1140,7 +1180,7 @@ class Address6 {
|
|
|
1140
1180
|
if (embedded) {
|
|
1141
1181
|
return embedded.isPrivate();
|
|
1142
1182
|
}
|
|
1143
|
-
return this.isULA();
|
|
1183
|
+
return this.isULA() || this.isHostInSubnet(NAT64_LOCAL_USE_SUBNET);
|
|
1144
1184
|
}
|
|
1145
1185
|
/**
|
|
1146
1186
|
* Returns true if the address is an IPv4-mapped / NAT64 address whose embedded
|
|
@@ -1188,7 +1228,49 @@ class Address6 {
|
|
|
1188
1228
|
* @returns {boolean}
|
|
1189
1229
|
*/
|
|
1190
1230
|
isDocumentation() {
|
|
1191
|
-
return this.isHostInSubnet(
|
|
1231
|
+
return DOCUMENTATION_SUBNETS.some((subnet) => this.isHostInSubnet(subnet));
|
|
1232
|
+
}
|
|
1233
|
+
/**
|
|
1234
|
+
* Returns true if the address is in the benchmarking range `2001:2::/48`
|
|
1235
|
+
* ([RFC 5180](https://datatracker.ietf.org/doc/html/rfc5180)) or is an
|
|
1236
|
+
* IPv4-mapped / NAT64 address whose embedded IPv4 address is in
|
|
1237
|
+
* `198.18.0.0/15`, false otherwise.
|
|
1238
|
+
* @returns {boolean}
|
|
1239
|
+
*/
|
|
1240
|
+
isBenchmarking() {
|
|
1241
|
+
const embedded = this.embeddedIPv4();
|
|
1242
|
+
if (embedded) {
|
|
1243
|
+
return embedded.isBenchmarking();
|
|
1244
|
+
}
|
|
1245
|
+
return this.isHostInSubnet(BENCHMARKING_SUBNET);
|
|
1246
|
+
}
|
|
1247
|
+
/**
|
|
1248
|
+
* Returns true if the address is globally reachable: inside the global
|
|
1249
|
+
* unicast allocation `2000::/3` (the only range the [IANA IPv6 Address Space
|
|
1250
|
+
* Registry](https://www.iana.org/assignments/ipv6-address-space/) assigns
|
|
1251
|
+
* for global unicast; everything else is reserved, ULA, link-local, or
|
|
1252
|
+
* multicast) and not in any block the [IANA IPv6 Special-Purpose Address Registry](https://www.iana.org/assignments/iana-ipv6-special-registry/)
|
|
1253
|
+
* marks as not globally reachable. An IPv4-mapped or NAT64 well-known
|
|
1254
|
+
* address answers for its embedded IPv4 address, so `::ffff:10.0.0.1` and
|
|
1255
|
+
* `64:ff9b::7f00:1` are not global. Teredo (`2001::/32`) and 6to4
|
|
1256
|
+
* (`2002::/16`) are not global either: the registry lists them as N/A and a
|
|
1257
|
+
* packet to one needs a relay.
|
|
1258
|
+
*
|
|
1259
|
+
* This covers everything the individual classifiers name and the blocks they
|
|
1260
|
+
* do not: the discard-only prefix `100::/64`, the IETF protocol assignments
|
|
1261
|
+
* in `2001::/23`, the deprecated site-local `fec0::/10` and IPv4-compatible
|
|
1262
|
+
* `::/96` ranges, and unallocated space such as `4000::/3`. It is the single
|
|
1263
|
+
* predicate to use where a request must not reach an internal or
|
|
1264
|
+
* special-purpose destination; see SECURITY.md.
|
|
1265
|
+
* @returns {boolean}
|
|
1266
|
+
*/
|
|
1267
|
+
isGlobal() {
|
|
1268
|
+
const embedded = this.embeddedIPv4();
|
|
1269
|
+
if (embedded) {
|
|
1270
|
+
return embedded.isGlobal();
|
|
1271
|
+
}
|
|
1272
|
+
return (this.isHostInSubnet(GLOBAL_UNICAST_SUBNET) &&
|
|
1273
|
+
common.isGloballyReachable.call(this, SPECIAL_PURPOSE_V6));
|
|
1192
1274
|
}
|
|
1193
1275
|
// #endregion
|
|
1194
1276
|
// #region HTML
|
|
@@ -1347,7 +1429,15 @@ const TYPE_SUBNETS = Object.keys(constants6.TYPES).map((subnet) => [
|
|
|
1347
1429
|
const TEREDO_SUBNET = new Address6('2001::/32');
|
|
1348
1430
|
const SIX_TO_FOUR_SUBNET = new Address6('2002::/16');
|
|
1349
1431
|
const ULA_SUBNET = new Address6('fc00::/7');
|
|
1350
|
-
const
|
|
1432
|
+
const LINK_LOCAL_SUBNET = new Address6('fe80::/10');
|
|
1433
|
+
const DOCUMENTATION_SUBNETS = [new Address6('2001:db8::/32'), new Address6('3fff::/20')];
|
|
1434
|
+
const BENCHMARKING_SUBNET = new Address6('2001:2::/48');
|
|
1435
|
+
const GLOBAL_UNICAST_SUBNET = new Address6('2000::/3');
|
|
1436
|
+
const SPECIAL_PURPOSE_V6 = constants6.SPECIAL_PURPOSE.map(([cidr, , reachable]) => ({
|
|
1437
|
+
subnet: new Address6(cidr),
|
|
1438
|
+
reachable,
|
|
1439
|
+
}));
|
|
1351
1440
|
const IPV4_MAPPED_SUBNET = new Address6('::ffff:0:0/96');
|
|
1352
1441
|
const NAT64_WELL_KNOWN_SUBNET = new Address6('64:ff9b::/96');
|
|
1442
|
+
const NAT64_LOCAL_USE_SUBNET = new Address6('64:ff9b:1::/48');
|
|
1353
1443
|
//# sourceMappingURL=ipv6.js.map
|