piclaw 0.0.20 → 0.0.21
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/.output/nitro.json +1 -1
- package/.output/public/assets/defult-D5RLDUrI.js +1 -0
- package/.output/public/assets/{dist-D-Hc5HbQ.js → dist-BH_oa-kv.js} +1 -1
- package/.output/public/assets/index-7JvURuHy.js +204 -0
- package/.output/public/assets/index-K43slwjJ.css +1 -0
- package/.output/public/index.html +11 -2
- package/.output/server/_chunks/app.mjs +138 -104
- package/.output/server/_chunks/config.mjs +4 -0
- package/.output/server/_chunks/dummy.mjs +1 -1
- package/.output/server/_chunks/logger.mjs +1 -1
- package/.output/server/_chunks/notes.mjs +1 -3
- package/.output/server/_chunks/renderer-template.mjs +1 -1
- package/.output/server/_chunks/sandbox.mjs +217 -0
- package/.output/server/_chunks/server.mjs +411 -291
- package/.output/server/_chunks/terminal.mjs +47 -8
- package/.output/server/_chunks/virtual.mjs +192 -54
- package/.output/server/_id_.delete.mjs +5 -2
- package/.output/server/_id_2.delete.mjs +8 -0
- package/.output/server/_jid_.delete.mjs +0 -1
- package/.output/server/_jid_.patch.mjs +21 -3
- package/.output/server/_jid_2.delete.mjs +0 -1
- package/.output/server/_libs/@acemir/cssom+[...].mjs +2269 -1137
- package/.output/server/_libs/@google/genai.mjs +348 -284
- package/.output/server/_libs/@mariozechner/pi-agent-core+[...].mjs +381 -2073
- package/.output/server/_libs/@mariozechner/pi-coding-agent+[...].mjs +236 -136
- package/.output/server/_libs/_.mjs +3 -2
- package/.output/server/_libs/_10.mjs +2 -4
- package/.output/server/_libs/_11.mjs +2 -4
- package/.output/server/_libs/_12.mjs +2 -3
- package/.output/server/_libs/_13.mjs +2 -3
- package/.output/server/_libs/_14.mjs +2 -4
- package/.output/server/_libs/_15.mjs +2 -4
- package/.output/server/_libs/_16.mjs +2 -3
- package/.output/server/_libs/_17.mjs +2 -4
- package/.output/server/_libs/_18.mjs +2 -2
- package/.output/server/_libs/_19.mjs +2 -2
- package/.output/server/_libs/_2.mjs +3 -3
- package/.output/server/_libs/_20.mjs +2 -2
- package/.output/server/_libs/_21.mjs +2 -2
- package/.output/server/_libs/_22.mjs +2 -2
- package/.output/server/_libs/_23.mjs +2 -2
- package/.output/server/_libs/_24.mjs +2 -2
- package/.output/server/_libs/_25.mjs +2 -2
- package/.output/server/_libs/_26.mjs +2 -2
- package/.output/server/_libs/_27.mjs +2 -2
- package/.output/server/_libs/_28.mjs +2 -2
- package/.output/server/_libs/_29.mjs +2 -2
- package/.output/server/_libs/_3.mjs +3 -3
- package/.output/server/_libs/_30.mjs +2 -2
- package/.output/server/_libs/_31.mjs +2 -2
- package/.output/server/_libs/_32.mjs +2 -2
- package/.output/server/_libs/_33.mjs +2 -2
- package/.output/server/_libs/_34.mjs +2 -2
- package/.output/server/_libs/_35.mjs +2 -2
- package/.output/server/_libs/_36.mjs +2 -2
- package/.output/server/_libs/_37.mjs +2 -2
- package/.output/server/_libs/_38.mjs +2 -2
- package/.output/server/_libs/_39.mjs +2 -2
- package/.output/server/_libs/_4.mjs +4 -3
- package/.output/server/_libs/_40.mjs +2 -2
- package/.output/server/_libs/_41.mjs +2 -2
- package/.output/server/_libs/_42.mjs +2 -2
- package/.output/server/_libs/_43.mjs +2 -2
- package/.output/server/_libs/_44.mjs +2 -2
- package/.output/server/_libs/_45.mjs +2 -2
- package/.output/server/_libs/_46.mjs +2 -2
- package/.output/server/_libs/_47.mjs +2 -2
- package/.output/server/_libs/_48.mjs +2 -2
- package/.output/server/_libs/_49.mjs +2 -2
- package/.output/server/_libs/_5.mjs +2 -3
- package/.output/server/_libs/_50.mjs +2 -2
- package/.output/server/_libs/_51.mjs +2 -2
- package/.output/server/_libs/_52.mjs +2 -2
- package/.output/server/_libs/_53.mjs +2 -2
- package/.output/server/_libs/_54.mjs +2 -2
- package/.output/server/_libs/_55.mjs +2 -2
- package/.output/server/_libs/_56.mjs +2 -2
- package/.output/server/_libs/_57.mjs +2 -2
- package/.output/server/_libs/_58.mjs +2 -2
- package/.output/server/_libs/_59.mjs +2 -2
- package/.output/server/_libs/_6.mjs +2 -3
- package/.output/server/_libs/_60.mjs +2 -2
- package/.output/server/_libs/_61.mjs +2 -2
- package/.output/server/_libs/_62.mjs +2 -2
- package/.output/server/_libs/_63.mjs +2 -2
- package/.output/server/_libs/_64.mjs +2 -2
- package/.output/server/_libs/_65.mjs +2 -2
- package/.output/server/_libs/_66.mjs +2 -2
- package/.output/server/_libs/_67.mjs +2 -2
- package/.output/server/_libs/_68.mjs +2 -2
- package/.output/server/_libs/_69.mjs +2 -2
- package/.output/server/_libs/_7.mjs +2 -5
- package/.output/server/_libs/_70.mjs +2 -2
- package/.output/server/_libs/_71.mjs +2 -2
- package/.output/server/_libs/_72.mjs +2 -2
- package/.output/server/_libs/_73.mjs +2 -2
- package/.output/server/_libs/_74.mjs +2 -2
- package/.output/server/_libs/_75.mjs +2 -2
- package/.output/server/_libs/_76.mjs +2 -2
- package/.output/server/_libs/_77.mjs +2 -2
- package/.output/server/_libs/_78.mjs +2 -2
- package/.output/server/_libs/_79.mjs +2 -2
- package/.output/server/_libs/_8.mjs +2 -3
- package/.output/server/_libs/_80.mjs +2 -2
- package/.output/server/_libs/_81.mjs +2 -2
- package/.output/server/_libs/_82.mjs +2 -2
- package/.output/server/_libs/_83.mjs +2 -2
- package/.output/server/_libs/_84.mjs +2 -2
- package/.output/server/_libs/_85.mjs +2 -2
- package/.output/server/_libs/_86.mjs +2 -2
- package/.output/server/_libs/_87.mjs +2 -2
- package/.output/server/_libs/_88.mjs +2 -2
- package/.output/server/_libs/_89.mjs +2 -2
- package/.output/server/_libs/_9.mjs +2 -4
- package/.output/server/_libs/_90.mjs +5 -2
- package/.output/server/_libs/_91.mjs +3 -2
- package/.output/server/_libs/_92.mjs +2 -2
- package/.output/server/_libs/_93.mjs +2 -2
- package/.output/server/_libs/_94.mjs +2 -2
- package/.output/server/_libs/agent-base.mjs +1 -1
- package/.output/server/_libs/cheerio+[...].mjs +1 -1
- package/.output/server/_libs/data-uri-to-buffer.mjs +2 -67
- package/.output/server/_libs/data-urls+[...].mjs +1 -1
- package/.output/server/_libs/diff.mjs +1 -1
- package/.output/server/_libs/exodus__bytes.mjs +99 -81
- package/.output/server/_libs/fetch-blob+node-domexception.mjs +1 -1
- package/.output/server/_libs/h3+rou3+srvx.mjs +34 -4
- package/.output/server/_libs/html-encoding-sniffer.mjs +1 -1
- package/.output/server/_libs/https-proxy-agent.mjs +2 -2
- package/.output/server/_libs/jsdom.mjs +1 -1
- package/.output/server/_libs/just-bash+[...].mjs +4676 -3916
- package/.output/server/_libs/mariozechner__jiti.mjs +1 -1
- package/.output/server/_libs/mariozechner__pi-ai.mjs +1472 -0
- package/.output/server/_libs/md4x.mjs +1 -1
- package/.output/server/_libs/node-fetch.mjs +14 -14
- package/.output/server/_libs/node-liblzma.mjs +1 -1
- package/.output/server/_libs/silvia-odwyer__photon-node.mjs +1 -1
- package/.output/server/_routes/api/auth/status.mjs +25 -6
- package/.output/server/_routes/api/config2.mjs +2 -0
- package/.output/server/_routes/api/files/groups.mjs +0 -1
- package/.output/server/_routes/api/groups.mjs +4 -2
- package/.output/server/_routes/api/groups2.mjs +14 -5
- package/.output/server/_routes/api/health.mjs +0 -1
- package/.output/server/_routes/api/pi/apikey.mjs +0 -1
- package/.output/server/_routes/api/pi/apikey_providers.mjs +0 -1
- package/.output/server/_routes/api/pi/commands.mjs +1 -2
- package/.output/server/_routes/api/pi/login/events.mjs +0 -1
- package/.output/server/_routes/api/pi/login/respond.mjs +0 -1
- package/.output/server/_routes/api/pi/login.mjs +0 -1
- package/.output/server/_routes/api/pi/logout.mjs +0 -1
- package/.output/server/_routes/api/pi/models.mjs +0 -1
- package/.output/server/_routes/api/pi/status.mjs +0 -1
- package/.output/server/_routes/api/sandbox.mjs +26 -0
- package/.output/server/_routes/api/sandbox2.mjs +17 -0
- package/.output/server/_routes/api/send.mjs +12 -12
- package/.output/server/_routes/api/status.mjs +0 -1
- package/.output/server/_routes/api/stop.mjs +0 -1
- package/.output/server/_routes/api/tasks2.mjs +0 -1
- package/.output/server/_routes/api/telegram/setup.mjs +0 -1
- package/.output/server/_routes/api/telegram/status.mjs +0 -1
- package/.output/server/_routes/api/terminal2.mjs +2 -1
- package/.output/server/_routes/api/tunnel/setup.mjs +0 -1
- package/.output/server/_runtime.mjs +1 -2
- package/.output/server/index.mjs +1 -1
- package/.output/server/node_modules/amdefine/amdefine.js +301 -0
- package/.output/server/node_modules/amdefine/package.json +16 -0
- package/.output/server/node_modules/compressjs/lib/BWT.js +420 -0
- package/.output/server/node_modules/compressjs/lib/BWTC.js +234 -0
- package/.output/server/node_modules/compressjs/lib/BitStream.js +108 -0
- package/.output/server/node_modules/compressjs/lib/Bzip2.js +936 -0
- package/.output/server/node_modules/compressjs/lib/CRC32.js +105 -0
- package/.output/server/node_modules/compressjs/lib/Context1Model.js +56 -0
- package/.output/server/node_modules/compressjs/lib/DefSumModel.js +152 -0
- package/.output/server/node_modules/compressjs/lib/DeflateDistanceModel.js +55 -0
- package/.output/server/node_modules/compressjs/lib/Dmc.js +197 -0
- package/.output/server/node_modules/compressjs/lib/DummyRangeCoder.js +81 -0
- package/.output/server/node_modules/compressjs/lib/FenwickModel.js +194 -0
- package/.output/server/node_modules/compressjs/lib/Huffman.js +514 -0
- package/.output/server/node_modules/compressjs/lib/HuffmanAllocator.js +227 -0
- package/.output/server/node_modules/compressjs/lib/LogDistanceModel.js +46 -0
- package/.output/server/node_modules/compressjs/lib/Lzjb.js +300 -0
- package/.output/server/node_modules/compressjs/lib/LzjbR.js +241 -0
- package/.output/server/node_modules/compressjs/lib/Lzp3.js +273 -0
- package/.output/server/node_modules/compressjs/lib/MTFModel.js +208 -0
- package/.output/server/node_modules/compressjs/lib/NoModel.js +46 -0
- package/.output/server/node_modules/compressjs/lib/PPM.js +343 -0
- package/.output/server/node_modules/compressjs/lib/RangeCoder.js +238 -0
- package/.output/server/node_modules/compressjs/lib/Simple.js +111 -0
- package/.output/server/node_modules/compressjs/lib/Stream.js +53 -0
- package/.output/server/node_modules/compressjs/lib/Util.js +324 -0
- package/.output/server/node_modules/compressjs/lib/freeze.js +14 -0
- package/.output/server/node_modules/compressjs/main.js +29 -0
- package/.output/server/node_modules/compressjs/package.json +35 -0
- package/.output/server/package.json +2 -1
- package/README.md +10 -1
- package/lib/index.d.mts +1 -0
- package/lib/index.mjs +1 -0
- package/lib/piclaw.mjs +100 -0
- package/lib/utils.mjs +96 -0
- package/package.json +16 -11
- package/.output/public/assets/defult-DtwgaiMA.js +0 -1
- package/.output/public/assets/index-B5n0eraW.css +0 -1
- package/.output/public/assets/index-DUbn6fuj.js +0 -205
- package/.output/server/_libs/@aws-crypto/crc32+[...].mjs +0 -299
- package/.output/server/_libs/@aws-sdk/client-bedrock-runtime+[...].mjs +0 -17828
- package/.output/server/_libs/@aws-sdk/credential-provider-http+[...].mjs +0 -122
- package/.output/server/_libs/@aws-sdk/credential-provider-ini+[...].mjs +0 -417
- package/.output/server/_libs/@aws-sdk/credential-provider-process+[...].mjs +0 -54
- package/.output/server/_libs/@aws-sdk/credential-provider-sso+[...].mjs +0 -1151
- package/.output/server/_libs/@aws-sdk/credential-provider-web-identity+[...].mjs +0 -50
- package/.output/server/_libs/@smithy/credential-provider-imds+[...].mjs +0 -369
- package/.output/server/_libs/@tootallnate/quickjs-emscripten+[...].mjs +0 -3011
- package/.output/server/_libs/_100.mjs +0 -2
- package/.output/server/_libs/_101.mjs +0 -2
- package/.output/server/_libs/_102.mjs +0 -2
- package/.output/server/_libs/_103.mjs +0 -5
- package/.output/server/_libs/_104.mjs +0 -3
- package/.output/server/_libs/_105.mjs +0 -2
- package/.output/server/_libs/_106.mjs +0 -3
- package/.output/server/_libs/_107.mjs +0 -2
- package/.output/server/_libs/_108.mjs +0 -2
- package/.output/server/_libs/_95.mjs +0 -2
- package/.output/server/_libs/_96.mjs +0 -2
- package/.output/server/_libs/_97.mjs +0 -2
- package/.output/server/_libs/_98.mjs +0 -2
- package/.output/server/_libs/_99.mjs +0 -2
- package/.output/server/_libs/amdefine.mjs +0 -188
- package/.output/server/_libs/ast-types.mjs +0 -2270
- package/.output/server/_libs/aws-sdk__nested-clients.mjs +0 -3141
- package/.output/server/_libs/basic-ftp.mjs +0 -1906
- package/.output/server/_libs/compressjs.mjs +0 -50
- package/.output/server/_libs/degenerator+[...].mjs +0 -9964
- package/.output/server/_libs/get-uri.mjs +0 -413
- package/.output/server/_libs/http-proxy-agent.mjs +0 -123
- package/.output/server/_libs/ip-address.mjs +0 -1423
- package/.output/server/_libs/lru-cache.mjs +0 -732
- package/.output/server/_libs/netmask.mjs +0 -139
- package/.output/server/_libs/pac-proxy-agent+[...].mjs +0 -3104
- package/.output/server/_libs/proxy-agent+proxy-from-env.mjs +0 -204
- package/.output/server/_libs/smithy__core.mjs +0 -192
- package/.output/server/node_modules/tslib/modules/index.js +0 -70
- package/.output/server/node_modules/tslib/modules/package.json +0 -3
- package/.output/server/node_modules/tslib/package.json +0 -47
- package/.output/server/node_modules/tslib/tslib.js +0 -484
- package/bin/piclaw.mjs +0 -195
|
@@ -1,1423 +0,0 @@
|
|
|
1
|
-
import { t as __commonJSMin } from "../_runtime.mjs";
|
|
2
|
-
var require_common = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
3
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
|
-
exports.isInSubnet = isInSubnet;
|
|
5
|
-
exports.isCorrect = isCorrect;
|
|
6
|
-
exports.numberToPaddedHex = numberToPaddedHex;
|
|
7
|
-
exports.stringToPaddedHex = stringToPaddedHex;
|
|
8
|
-
exports.testBit = testBit;
|
|
9
|
-
function isInSubnet(address) {
|
|
10
|
-
if (this.subnetMask < address.subnetMask) return false;
|
|
11
|
-
if (this.mask(address.subnetMask) === address.mask()) return true;
|
|
12
|
-
return false;
|
|
13
|
-
}
|
|
14
|
-
function isCorrect(defaultBits) {
|
|
15
|
-
return function() {
|
|
16
|
-
if (this.addressMinusSuffix !== this.correctForm()) return false;
|
|
17
|
-
if (this.subnetMask === defaultBits && !this.parsedSubnet) return true;
|
|
18
|
-
return this.parsedSubnet === String(this.subnetMask);
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
function numberToPaddedHex(number) {
|
|
22
|
-
return number.toString(16).padStart(2, "0");
|
|
23
|
-
}
|
|
24
|
-
function stringToPaddedHex(numberString) {
|
|
25
|
-
return numberToPaddedHex(parseInt(numberString, 10));
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* @param binaryValue Binary representation of a value (e.g. `10`)
|
|
29
|
-
* @param position Byte position, where 0 is the least significant bit
|
|
30
|
-
*/
|
|
31
|
-
function testBit(binaryValue, position) {
|
|
32
|
-
const { length } = binaryValue;
|
|
33
|
-
if (position > length) return false;
|
|
34
|
-
const positionInString = length - position;
|
|
35
|
-
return binaryValue.substring(positionInString, positionInString + 1) === "1";
|
|
36
|
-
}
|
|
37
|
-
}));
|
|
38
|
-
var require_constants$1 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
39
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
-
exports.RE_SUBNET_STRING = exports.RE_ADDRESS = exports.GROUPS = exports.BITS = void 0;
|
|
41
|
-
exports.BITS = 32;
|
|
42
|
-
exports.GROUPS = 4;
|
|
43
|
-
exports.RE_ADDRESS = /^(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$/g;
|
|
44
|
-
exports.RE_SUBNET_STRING = /\/\d{1,2}$/;
|
|
45
|
-
}));
|
|
46
|
-
var require_address_error = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
47
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
|
-
exports.AddressError = void 0;
|
|
49
|
-
var AddressError = class extends Error {
|
|
50
|
-
constructor(message, parseMessage) {
|
|
51
|
-
super(message);
|
|
52
|
-
this.name = "AddressError";
|
|
53
|
-
this.parseMessage = parseMessage;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
exports.AddressError = AddressError;
|
|
57
|
-
}));
|
|
58
|
-
var require_ipv4 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
59
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
60
|
-
if (k2 === void 0) k2 = k;
|
|
61
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
62
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
63
|
-
enumerable: true,
|
|
64
|
-
get: function() {
|
|
65
|
-
return m[k];
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
Object.defineProperty(o, k2, desc);
|
|
69
|
-
}) : (function(o, m, k, k2) {
|
|
70
|
-
if (k2 === void 0) k2 = k;
|
|
71
|
-
o[k2] = m[k];
|
|
72
|
-
}));
|
|
73
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
74
|
-
Object.defineProperty(o, "default", {
|
|
75
|
-
enumerable: true,
|
|
76
|
-
value: v
|
|
77
|
-
});
|
|
78
|
-
}) : function(o, v) {
|
|
79
|
-
o["default"] = v;
|
|
80
|
-
});
|
|
81
|
-
var __importStar = exports && exports.__importStar || function(mod) {
|
|
82
|
-
if (mod && mod.__esModule) return mod;
|
|
83
|
-
var result = {};
|
|
84
|
-
if (mod != null) {
|
|
85
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
86
|
-
}
|
|
87
|
-
__setModuleDefault(result, mod);
|
|
88
|
-
return result;
|
|
89
|
-
};
|
|
90
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
91
|
-
exports.Address4 = void 0;
|
|
92
|
-
var common = __importStar(require_common());
|
|
93
|
-
var constants = __importStar(require_constants$1());
|
|
94
|
-
var address_error_1 = require_address_error();
|
|
95
|
-
exports.Address4 = class Address4 {
|
|
96
|
-
constructor(address) {
|
|
97
|
-
this.groups = constants.GROUPS;
|
|
98
|
-
this.parsedAddress = [];
|
|
99
|
-
this.parsedSubnet = "";
|
|
100
|
-
this.subnet = "/32";
|
|
101
|
-
this.subnetMask = 32;
|
|
102
|
-
this.v4 = true;
|
|
103
|
-
/**
|
|
104
|
-
* Returns true if the address is correct, false otherwise
|
|
105
|
-
* @memberof Address4
|
|
106
|
-
* @instance
|
|
107
|
-
* @returns {Boolean}
|
|
108
|
-
*/
|
|
109
|
-
this.isCorrect = common.isCorrect(constants.BITS);
|
|
110
|
-
/**
|
|
111
|
-
* Returns true if the given address is in the subnet of the current address
|
|
112
|
-
* @memberof Address4
|
|
113
|
-
* @instance
|
|
114
|
-
* @returns {boolean}
|
|
115
|
-
*/
|
|
116
|
-
this.isInSubnet = common.isInSubnet;
|
|
117
|
-
this.address = address;
|
|
118
|
-
const subnet = constants.RE_SUBNET_STRING.exec(address);
|
|
119
|
-
if (subnet) {
|
|
120
|
-
this.parsedSubnet = subnet[0].replace("/", "");
|
|
121
|
-
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
|
122
|
-
this.subnet = `/${this.subnetMask}`;
|
|
123
|
-
if (this.subnetMask < 0 || this.subnetMask > constants.BITS) throw new address_error_1.AddressError("Invalid subnet mask.");
|
|
124
|
-
address = address.replace(constants.RE_SUBNET_STRING, "");
|
|
125
|
-
}
|
|
126
|
-
this.addressMinusSuffix = address;
|
|
127
|
-
this.parsedAddress = this.parse(address);
|
|
128
|
-
}
|
|
129
|
-
static isValid(address) {
|
|
130
|
-
try {
|
|
131
|
-
new Address4(address);
|
|
132
|
-
return true;
|
|
133
|
-
} catch (e) {
|
|
134
|
-
return false;
|
|
135
|
-
}
|
|
136
|
-
}
|
|
137
|
-
parse(address) {
|
|
138
|
-
const groups = address.split(".");
|
|
139
|
-
if (!address.match(constants.RE_ADDRESS)) throw new address_error_1.AddressError("Invalid IPv4 address.");
|
|
140
|
-
return groups;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* Returns the correct form of an address
|
|
144
|
-
* @memberof Address4
|
|
145
|
-
* @instance
|
|
146
|
-
* @returns {String}
|
|
147
|
-
*/
|
|
148
|
-
correctForm() {
|
|
149
|
-
return this.parsedAddress.map((part) => parseInt(part, 10)).join(".");
|
|
150
|
-
}
|
|
151
|
-
/**
|
|
152
|
-
* Converts a hex string to an IPv4 address object
|
|
153
|
-
* @memberof Address4
|
|
154
|
-
* @static
|
|
155
|
-
* @param {string} hex - a hex string to convert
|
|
156
|
-
* @returns {Address4}
|
|
157
|
-
*/
|
|
158
|
-
static fromHex(hex) {
|
|
159
|
-
const padded = hex.replace(/:/g, "").padStart(8, "0");
|
|
160
|
-
const groups = [];
|
|
161
|
-
let i;
|
|
162
|
-
for (i = 0; i < 8; i += 2) {
|
|
163
|
-
const h = padded.slice(i, i + 2);
|
|
164
|
-
groups.push(parseInt(h, 16));
|
|
165
|
-
}
|
|
166
|
-
return new Address4(groups.join("."));
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Converts an integer into a IPv4 address object
|
|
170
|
-
* @memberof Address4
|
|
171
|
-
* @static
|
|
172
|
-
* @param {integer} integer - a number to convert
|
|
173
|
-
* @returns {Address4}
|
|
174
|
-
*/
|
|
175
|
-
static fromInteger(integer) {
|
|
176
|
-
return Address4.fromHex(integer.toString(16));
|
|
177
|
-
}
|
|
178
|
-
/**
|
|
179
|
-
* Return an address from in-addr.arpa form
|
|
180
|
-
* @memberof Address4
|
|
181
|
-
* @static
|
|
182
|
-
* @param {string} arpaFormAddress - an 'in-addr.arpa' form ipv4 address
|
|
183
|
-
* @returns {Adress4}
|
|
184
|
-
* @example
|
|
185
|
-
* var address = Address4.fromArpa(42.2.0.192.in-addr.arpa.)
|
|
186
|
-
* address.correctForm(); // '192.0.2.42'
|
|
187
|
-
*/
|
|
188
|
-
static fromArpa(arpaFormAddress) {
|
|
189
|
-
return new Address4(arpaFormAddress.replace(/(\.in-addr\.arpa)?\.$/, "").split(".").reverse().join("."));
|
|
190
|
-
}
|
|
191
|
-
/**
|
|
192
|
-
* Converts an IPv4 address object to a hex string
|
|
193
|
-
* @memberof Address4
|
|
194
|
-
* @instance
|
|
195
|
-
* @returns {String}
|
|
196
|
-
*/
|
|
197
|
-
toHex() {
|
|
198
|
-
return this.parsedAddress.map((part) => common.stringToPaddedHex(part)).join(":");
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Converts an IPv4 address object to an array of bytes
|
|
202
|
-
* @memberof Address4
|
|
203
|
-
* @instance
|
|
204
|
-
* @returns {Array}
|
|
205
|
-
*/
|
|
206
|
-
toArray() {
|
|
207
|
-
return this.parsedAddress.map((part) => parseInt(part, 10));
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Converts an IPv4 address object to an IPv6 address group
|
|
211
|
-
* @memberof Address4
|
|
212
|
-
* @instance
|
|
213
|
-
* @returns {String}
|
|
214
|
-
*/
|
|
215
|
-
toGroup6() {
|
|
216
|
-
const output = [];
|
|
217
|
-
let i;
|
|
218
|
-
for (i = 0; i < constants.GROUPS; i += 2) output.push(`${common.stringToPaddedHex(this.parsedAddress[i])}${common.stringToPaddedHex(this.parsedAddress[i + 1])}`);
|
|
219
|
-
return output.join(":");
|
|
220
|
-
}
|
|
221
|
-
/**
|
|
222
|
-
* Returns the address as a `bigint`
|
|
223
|
-
* @memberof Address4
|
|
224
|
-
* @instance
|
|
225
|
-
* @returns {bigint}
|
|
226
|
-
*/
|
|
227
|
-
bigInt() {
|
|
228
|
-
return BigInt(`0x${this.parsedAddress.map((n) => common.stringToPaddedHex(n)).join("")}`);
|
|
229
|
-
}
|
|
230
|
-
/**
|
|
231
|
-
* Helper function getting start address.
|
|
232
|
-
* @memberof Address4
|
|
233
|
-
* @instance
|
|
234
|
-
* @returns {bigint}
|
|
235
|
-
*/
|
|
236
|
-
_startAddress() {
|
|
237
|
-
return BigInt(`0b${this.mask() + "0".repeat(constants.BITS - this.subnetMask)}`);
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* The first address in the range given by this address' subnet.
|
|
241
|
-
* Often referred to as the Network Address.
|
|
242
|
-
* @memberof Address4
|
|
243
|
-
* @instance
|
|
244
|
-
* @returns {Address4}
|
|
245
|
-
*/
|
|
246
|
-
startAddress() {
|
|
247
|
-
return Address4.fromBigInt(this._startAddress());
|
|
248
|
-
}
|
|
249
|
-
/**
|
|
250
|
-
* The first host address in the range given by this address's subnet ie
|
|
251
|
-
* the first address after the Network Address
|
|
252
|
-
* @memberof Address4
|
|
253
|
-
* @instance
|
|
254
|
-
* @returns {Address4}
|
|
255
|
-
*/
|
|
256
|
-
startAddressExclusive() {
|
|
257
|
-
const adjust = BigInt("1");
|
|
258
|
-
return Address4.fromBigInt(this._startAddress() + adjust);
|
|
259
|
-
}
|
|
260
|
-
/**
|
|
261
|
-
* Helper function getting end address.
|
|
262
|
-
* @memberof Address4
|
|
263
|
-
* @instance
|
|
264
|
-
* @returns {bigint}
|
|
265
|
-
*/
|
|
266
|
-
_endAddress() {
|
|
267
|
-
return BigInt(`0b${this.mask() + "1".repeat(constants.BITS - this.subnetMask)}`);
|
|
268
|
-
}
|
|
269
|
-
/**
|
|
270
|
-
* The last address in the range given by this address' subnet
|
|
271
|
-
* Often referred to as the Broadcast
|
|
272
|
-
* @memberof Address4
|
|
273
|
-
* @instance
|
|
274
|
-
* @returns {Address4}
|
|
275
|
-
*/
|
|
276
|
-
endAddress() {
|
|
277
|
-
return Address4.fromBigInt(this._endAddress());
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* The last host address in the range given by this address's subnet ie
|
|
281
|
-
* the last address prior to the Broadcast Address
|
|
282
|
-
* @memberof Address4
|
|
283
|
-
* @instance
|
|
284
|
-
* @returns {Address4}
|
|
285
|
-
*/
|
|
286
|
-
endAddressExclusive() {
|
|
287
|
-
const adjust = BigInt("1");
|
|
288
|
-
return Address4.fromBigInt(this._endAddress() - adjust);
|
|
289
|
-
}
|
|
290
|
-
/**
|
|
291
|
-
* Converts a BigInt to a v4 address object
|
|
292
|
-
* @memberof Address4
|
|
293
|
-
* @static
|
|
294
|
-
* @param {bigint} bigInt - a BigInt to convert
|
|
295
|
-
* @returns {Address4}
|
|
296
|
-
*/
|
|
297
|
-
static fromBigInt(bigInt) {
|
|
298
|
-
return Address4.fromHex(bigInt.toString(16));
|
|
299
|
-
}
|
|
300
|
-
/**
|
|
301
|
-
* Convert a byte array to an Address4 object
|
|
302
|
-
* @memberof Address4
|
|
303
|
-
* @static
|
|
304
|
-
* @param {Array<number>} bytes - an array of 4 bytes (0-255)
|
|
305
|
-
* @returns {Address4}
|
|
306
|
-
*/
|
|
307
|
-
static fromByteArray(bytes) {
|
|
308
|
-
if (bytes.length !== 4) throw new address_error_1.AddressError("IPv4 addresses require exactly 4 bytes");
|
|
309
|
-
for (let i = 0; i < bytes.length; i++) if (!Number.isInteger(bytes[i]) || bytes[i] < 0 || bytes[i] > 255) throw new address_error_1.AddressError("All bytes must be integers between 0 and 255");
|
|
310
|
-
return this.fromUnsignedByteArray(bytes);
|
|
311
|
-
}
|
|
312
|
-
/**
|
|
313
|
-
* Convert an unsigned byte array to an Address4 object
|
|
314
|
-
* @memberof Address4
|
|
315
|
-
* @static
|
|
316
|
-
* @param {Array<number>} bytes - an array of 4 unsigned bytes (0-255)
|
|
317
|
-
* @returns {Address4}
|
|
318
|
-
*/
|
|
319
|
-
static fromUnsignedByteArray(bytes) {
|
|
320
|
-
if (bytes.length !== 4) throw new address_error_1.AddressError("IPv4 addresses require exactly 4 bytes");
|
|
321
|
-
return new Address4(bytes.join("."));
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* Returns the first n bits of the address, defaulting to the
|
|
325
|
-
* subnet mask
|
|
326
|
-
* @memberof Address4
|
|
327
|
-
* @instance
|
|
328
|
-
* @returns {String}
|
|
329
|
-
*/
|
|
330
|
-
mask(mask) {
|
|
331
|
-
if (mask === void 0) mask = this.subnetMask;
|
|
332
|
-
return this.getBitsBase2(0, mask);
|
|
333
|
-
}
|
|
334
|
-
/**
|
|
335
|
-
* Returns the bits in the given range as a base-2 string
|
|
336
|
-
* @memberof Address4
|
|
337
|
-
* @instance
|
|
338
|
-
* @returns {string}
|
|
339
|
-
*/
|
|
340
|
-
getBitsBase2(start, end) {
|
|
341
|
-
return this.binaryZeroPad().slice(start, end);
|
|
342
|
-
}
|
|
343
|
-
/**
|
|
344
|
-
* Return the reversed ip6.arpa form of the address
|
|
345
|
-
* @memberof Address4
|
|
346
|
-
* @param {Object} options
|
|
347
|
-
* @param {boolean} options.omitSuffix - omit the "in-addr.arpa" suffix
|
|
348
|
-
* @instance
|
|
349
|
-
* @returns {String}
|
|
350
|
-
*/
|
|
351
|
-
reverseForm(options) {
|
|
352
|
-
if (!options) options = {};
|
|
353
|
-
const reversed = this.correctForm().split(".").reverse().join(".");
|
|
354
|
-
if (options.omitSuffix) return reversed;
|
|
355
|
-
return `${reversed}.in-addr.arpa.`;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* Returns true if the given address is a multicast address
|
|
359
|
-
* @memberof Address4
|
|
360
|
-
* @instance
|
|
361
|
-
* @returns {boolean}
|
|
362
|
-
*/
|
|
363
|
-
isMulticast() {
|
|
364
|
-
return this.isInSubnet(new Address4("224.0.0.0/4"));
|
|
365
|
-
}
|
|
366
|
-
/**
|
|
367
|
-
* Returns a zero-padded base-2 string representation of the address
|
|
368
|
-
* @memberof Address4
|
|
369
|
-
* @instance
|
|
370
|
-
* @returns {string}
|
|
371
|
-
*/
|
|
372
|
-
binaryZeroPad() {
|
|
373
|
-
return this.bigInt().toString(2).padStart(constants.BITS, "0");
|
|
374
|
-
}
|
|
375
|
-
/**
|
|
376
|
-
* Groups an IPv4 address for inclusion at the end of an IPv6 address
|
|
377
|
-
* @returns {String}
|
|
378
|
-
*/
|
|
379
|
-
groupForV6() {
|
|
380
|
-
const segments = this.parsedAddress;
|
|
381
|
-
return this.address.replace(constants.RE_ADDRESS, `<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>`);
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
}));
|
|
385
|
-
var require_constants = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
386
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
387
|
-
exports.RE_URL_WITH_PORT = exports.RE_URL = exports.RE_ZONE_STRING = exports.RE_SUBNET_STRING = exports.RE_BAD_ADDRESS = exports.RE_BAD_CHARACTERS = exports.TYPES = exports.SCOPES = exports.GROUPS = exports.BITS = void 0;
|
|
388
|
-
exports.BITS = 128;
|
|
389
|
-
exports.GROUPS = 8;
|
|
390
|
-
/**
|
|
391
|
-
* Represents IPv6 address scopes
|
|
392
|
-
* @memberof Address6
|
|
393
|
-
* @static
|
|
394
|
-
*/
|
|
395
|
-
exports.SCOPES = {
|
|
396
|
-
0: "Reserved",
|
|
397
|
-
1: "Interface local",
|
|
398
|
-
2: "Link local",
|
|
399
|
-
4: "Admin local",
|
|
400
|
-
5: "Site local",
|
|
401
|
-
8: "Organization local",
|
|
402
|
-
14: "Global",
|
|
403
|
-
15: "Reserved"
|
|
404
|
-
};
|
|
405
|
-
/**
|
|
406
|
-
* Represents IPv6 address types
|
|
407
|
-
* @memberof Address6
|
|
408
|
-
* @static
|
|
409
|
-
*/
|
|
410
|
-
exports.TYPES = {
|
|
411
|
-
"ff01::1/128": "Multicast (All nodes on this interface)",
|
|
412
|
-
"ff01::2/128": "Multicast (All routers on this interface)",
|
|
413
|
-
"ff02::1/128": "Multicast (All nodes on this link)",
|
|
414
|
-
"ff02::2/128": "Multicast (All routers on this link)",
|
|
415
|
-
"ff05::2/128": "Multicast (All routers in this site)",
|
|
416
|
-
"ff02::5/128": "Multicast (OSPFv3 AllSPF routers)",
|
|
417
|
-
"ff02::6/128": "Multicast (OSPFv3 AllDR routers)",
|
|
418
|
-
"ff02::9/128": "Multicast (RIP routers)",
|
|
419
|
-
"ff02::a/128": "Multicast (EIGRP routers)",
|
|
420
|
-
"ff02::d/128": "Multicast (PIM routers)",
|
|
421
|
-
"ff02::16/128": "Multicast (MLDv2 reports)",
|
|
422
|
-
"ff01::fb/128": "Multicast (mDNSv6)",
|
|
423
|
-
"ff02::fb/128": "Multicast (mDNSv6)",
|
|
424
|
-
"ff05::fb/128": "Multicast (mDNSv6)",
|
|
425
|
-
"ff02::1:2/128": "Multicast (All DHCP servers and relay agents on this link)",
|
|
426
|
-
"ff05::1:2/128": "Multicast (All DHCP servers and relay agents in this site)",
|
|
427
|
-
"ff02::1:3/128": "Multicast (All DHCP servers on this link)",
|
|
428
|
-
"ff05::1:3/128": "Multicast (All DHCP servers in this site)",
|
|
429
|
-
"::/128": "Unspecified",
|
|
430
|
-
"::1/128": "Loopback",
|
|
431
|
-
"ff00::/8": "Multicast",
|
|
432
|
-
"fe80::/10": "Link-local unicast"
|
|
433
|
-
};
|
|
434
|
-
/**
|
|
435
|
-
* A regular expression that matches bad characters in an IPv6 address
|
|
436
|
-
* @memberof Address6
|
|
437
|
-
* @static
|
|
438
|
-
*/
|
|
439
|
-
exports.RE_BAD_CHARACTERS = /([^0-9a-f:/%])/gi;
|
|
440
|
-
/**
|
|
441
|
-
* A regular expression that matches an incorrect IPv6 address
|
|
442
|
-
* @memberof Address6
|
|
443
|
-
* @static
|
|
444
|
-
*/
|
|
445
|
-
exports.RE_BAD_ADDRESS = /([0-9a-f]{5,}|:{3,}|[^:]:$|^:[^:]|\/$)/gi;
|
|
446
|
-
/**
|
|
447
|
-
* A regular expression that matches an IPv6 subnet
|
|
448
|
-
* @memberof Address6
|
|
449
|
-
* @static
|
|
450
|
-
*/
|
|
451
|
-
exports.RE_SUBNET_STRING = /\/\d{1,3}(?=%|$)/;
|
|
452
|
-
/**
|
|
453
|
-
* A regular expression that matches an IPv6 zone
|
|
454
|
-
* @memberof Address6
|
|
455
|
-
* @static
|
|
456
|
-
*/
|
|
457
|
-
exports.RE_ZONE_STRING = /%.*$/;
|
|
458
|
-
exports.RE_URL = /^\[{0,1}([0-9a-f:]+)\]{0,1}/;
|
|
459
|
-
exports.RE_URL_WITH_PORT = /\[([0-9a-f:]+)\]:([0-9]{1,5})/;
|
|
460
|
-
}));
|
|
461
|
-
var require_helpers = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
462
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
463
|
-
exports.spanAllZeroes = spanAllZeroes;
|
|
464
|
-
exports.spanAll = spanAll;
|
|
465
|
-
exports.spanLeadingZeroes = spanLeadingZeroes;
|
|
466
|
-
exports.simpleGroup = simpleGroup;
|
|
467
|
-
/**
|
|
468
|
-
* @returns {String} the string with all zeroes contained in a <span>
|
|
469
|
-
*/
|
|
470
|
-
function spanAllZeroes(s) {
|
|
471
|
-
return s.replace(/(0+)/g, "<span class=\"zero\">$1</span>");
|
|
472
|
-
}
|
|
473
|
-
/**
|
|
474
|
-
* @returns {String} the string with each character contained in a <span>
|
|
475
|
-
*/
|
|
476
|
-
function spanAll(s, offset = 0) {
|
|
477
|
-
return s.split("").map((n, i) => `<span class="digit value-${n} position-${i + offset}">${spanAllZeroes(n)}</span>`).join("");
|
|
478
|
-
}
|
|
479
|
-
function spanLeadingZeroesSimple(group) {
|
|
480
|
-
return group.replace(/^(0+)/, "<span class=\"zero\">$1</span>");
|
|
481
|
-
}
|
|
482
|
-
/**
|
|
483
|
-
* @returns {String} the string with leading zeroes contained in a <span>
|
|
484
|
-
*/
|
|
485
|
-
function spanLeadingZeroes(address) {
|
|
486
|
-
return address.split(":").map((g) => spanLeadingZeroesSimple(g)).join(":");
|
|
487
|
-
}
|
|
488
|
-
/**
|
|
489
|
-
* Groups an address
|
|
490
|
-
* @returns {String} a grouped address
|
|
491
|
-
*/
|
|
492
|
-
function simpleGroup(addressString, offset = 0) {
|
|
493
|
-
return addressString.split(":").map((g, i) => {
|
|
494
|
-
if (/group-v4/.test(g)) return g;
|
|
495
|
-
return `<span class="hover-group group-${i + offset}">${spanLeadingZeroesSimple(g)}</span>`;
|
|
496
|
-
});
|
|
497
|
-
}
|
|
498
|
-
}));
|
|
499
|
-
var require_regular_expressions = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
500
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
501
|
-
if (k2 === void 0) k2 = k;
|
|
502
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
503
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
504
|
-
enumerable: true,
|
|
505
|
-
get: function() {
|
|
506
|
-
return m[k];
|
|
507
|
-
}
|
|
508
|
-
};
|
|
509
|
-
Object.defineProperty(o, k2, desc);
|
|
510
|
-
}) : (function(o, m, k, k2) {
|
|
511
|
-
if (k2 === void 0) k2 = k;
|
|
512
|
-
o[k2] = m[k];
|
|
513
|
-
}));
|
|
514
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
515
|
-
Object.defineProperty(o, "default", {
|
|
516
|
-
enumerable: true,
|
|
517
|
-
value: v
|
|
518
|
-
});
|
|
519
|
-
}) : function(o, v) {
|
|
520
|
-
o["default"] = v;
|
|
521
|
-
});
|
|
522
|
-
var __importStar = exports && exports.__importStar || function(mod) {
|
|
523
|
-
if (mod && mod.__esModule) return mod;
|
|
524
|
-
var result = {};
|
|
525
|
-
if (mod != null) {
|
|
526
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
527
|
-
}
|
|
528
|
-
__setModuleDefault(result, mod);
|
|
529
|
-
return result;
|
|
530
|
-
};
|
|
531
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
532
|
-
exports.ADDRESS_BOUNDARY = void 0;
|
|
533
|
-
exports.groupPossibilities = groupPossibilities;
|
|
534
|
-
exports.padGroup = padGroup;
|
|
535
|
-
exports.simpleRegularExpression = simpleRegularExpression;
|
|
536
|
-
exports.possibleElisions = possibleElisions;
|
|
537
|
-
var v6 = __importStar(require_constants());
|
|
538
|
-
function groupPossibilities(possibilities) {
|
|
539
|
-
return `(${possibilities.join("|")})`;
|
|
540
|
-
}
|
|
541
|
-
function padGroup(group) {
|
|
542
|
-
if (group.length < 4) return `0{0,${4 - group.length}}${group}`;
|
|
543
|
-
return group;
|
|
544
|
-
}
|
|
545
|
-
exports.ADDRESS_BOUNDARY = "[^A-Fa-f0-9:]";
|
|
546
|
-
function simpleRegularExpression(groups) {
|
|
547
|
-
const zeroIndexes = [];
|
|
548
|
-
groups.forEach((group, i) => {
|
|
549
|
-
if (parseInt(group, 16) === 0) zeroIndexes.push(i);
|
|
550
|
-
});
|
|
551
|
-
const possibilities = zeroIndexes.map((zeroIndex) => groups.map((group, i) => {
|
|
552
|
-
if (i === zeroIndex) {
|
|
553
|
-
const elision = i === 0 || i === v6.GROUPS - 1 ? ":" : "";
|
|
554
|
-
return groupPossibilities([padGroup(group), elision]);
|
|
555
|
-
}
|
|
556
|
-
return padGroup(group);
|
|
557
|
-
}).join(":"));
|
|
558
|
-
possibilities.push(groups.map(padGroup).join(":"));
|
|
559
|
-
return groupPossibilities(possibilities);
|
|
560
|
-
}
|
|
561
|
-
function possibleElisions(elidedGroups, moreLeft, moreRight) {
|
|
562
|
-
const left = moreLeft ? "" : ":";
|
|
563
|
-
const right = moreRight ? "" : ":";
|
|
564
|
-
const possibilities = [];
|
|
565
|
-
if (!moreLeft && !moreRight) possibilities.push("::");
|
|
566
|
-
if (moreLeft && moreRight) possibilities.push("");
|
|
567
|
-
if (moreRight && !moreLeft || !moreRight && moreLeft) possibilities.push(":");
|
|
568
|
-
possibilities.push(`${left}(:0{1,4}){1,${elidedGroups - 1}}`);
|
|
569
|
-
possibilities.push(`(0{1,4}:){1,${elidedGroups - 1}}${right}`);
|
|
570
|
-
possibilities.push(`(0{1,4}:){${elidedGroups - 1}}0{1,4}`);
|
|
571
|
-
for (let groups = 1; groups < elidedGroups - 1; groups++) for (let position = 1; position < elidedGroups - groups; position++) possibilities.push(`(0{1,4}:){${position}}:(0{1,4}:){${elidedGroups - position - groups - 1}}0{1,4}`);
|
|
572
|
-
return groupPossibilities(possibilities);
|
|
573
|
-
}
|
|
574
|
-
}));
|
|
575
|
-
var require_ipv6 = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
576
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
577
|
-
if (k2 === void 0) k2 = k;
|
|
578
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
579
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
580
|
-
enumerable: true,
|
|
581
|
-
get: function() {
|
|
582
|
-
return m[k];
|
|
583
|
-
}
|
|
584
|
-
};
|
|
585
|
-
Object.defineProperty(o, k2, desc);
|
|
586
|
-
}) : (function(o, m, k, k2) {
|
|
587
|
-
if (k2 === void 0) k2 = k;
|
|
588
|
-
o[k2] = m[k];
|
|
589
|
-
}));
|
|
590
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
591
|
-
Object.defineProperty(o, "default", {
|
|
592
|
-
enumerable: true,
|
|
593
|
-
value: v
|
|
594
|
-
});
|
|
595
|
-
}) : function(o, v) {
|
|
596
|
-
o["default"] = v;
|
|
597
|
-
});
|
|
598
|
-
var __importStar = exports && exports.__importStar || function(mod) {
|
|
599
|
-
if (mod && mod.__esModule) return mod;
|
|
600
|
-
var result = {};
|
|
601
|
-
if (mod != null) {
|
|
602
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
603
|
-
}
|
|
604
|
-
__setModuleDefault(result, mod);
|
|
605
|
-
return result;
|
|
606
|
-
};
|
|
607
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
608
|
-
exports.Address6 = void 0;
|
|
609
|
-
var common = __importStar(require_common());
|
|
610
|
-
var constants4 = __importStar(require_constants$1());
|
|
611
|
-
var constants6 = __importStar(require_constants());
|
|
612
|
-
var helpers = __importStar(require_helpers());
|
|
613
|
-
var ipv4_1 = require_ipv4();
|
|
614
|
-
var regular_expressions_1 = require_regular_expressions();
|
|
615
|
-
var address_error_1 = require_address_error();
|
|
616
|
-
var common_1 = require_common();
|
|
617
|
-
function assert(condition) {
|
|
618
|
-
if (!condition) throw new Error("Assertion failed.");
|
|
619
|
-
}
|
|
620
|
-
function addCommas(number) {
|
|
621
|
-
const r = /(\d+)(\d{3})/;
|
|
622
|
-
while (r.test(number)) number = number.replace(r, "$1,$2");
|
|
623
|
-
return number;
|
|
624
|
-
}
|
|
625
|
-
function spanLeadingZeroes4(n) {
|
|
626
|
-
n = n.replace(/^(0{1,})([1-9]+)$/, "<span class=\"parse-error\">$1</span>$2");
|
|
627
|
-
n = n.replace(/^(0{1,})(0)$/, "<span class=\"parse-error\">$1</span>$2");
|
|
628
|
-
return n;
|
|
629
|
-
}
|
|
630
|
-
function compact(address, slice) {
|
|
631
|
-
const s1 = [];
|
|
632
|
-
const s2 = [];
|
|
633
|
-
let i;
|
|
634
|
-
for (i = 0; i < address.length; i++) if (i < slice[0]) s1.push(address[i]);
|
|
635
|
-
else if (i > slice[1]) s2.push(address[i]);
|
|
636
|
-
return s1.concat(["compact"]).concat(s2);
|
|
637
|
-
}
|
|
638
|
-
function paddedHex(octet) {
|
|
639
|
-
return parseInt(octet, 16).toString(16).padStart(4, "0");
|
|
640
|
-
}
|
|
641
|
-
function unsignByte(b) {
|
|
642
|
-
return b & 255;
|
|
643
|
-
}
|
|
644
|
-
exports.Address6 = class Address6 {
|
|
645
|
-
constructor(address, optionalGroups) {
|
|
646
|
-
this.addressMinusSuffix = "";
|
|
647
|
-
this.parsedSubnet = "";
|
|
648
|
-
this.subnet = "/128";
|
|
649
|
-
this.subnetMask = 128;
|
|
650
|
-
this.v4 = false;
|
|
651
|
-
this.zone = "";
|
|
652
|
-
/**
|
|
653
|
-
* Returns true if the given address is in the subnet of the current address
|
|
654
|
-
* @memberof Address6
|
|
655
|
-
* @instance
|
|
656
|
-
* @returns {boolean}
|
|
657
|
-
*/
|
|
658
|
-
this.isInSubnet = common.isInSubnet;
|
|
659
|
-
/**
|
|
660
|
-
* Returns true if the address is correct, false otherwise
|
|
661
|
-
* @memberof Address6
|
|
662
|
-
* @instance
|
|
663
|
-
* @returns {boolean}
|
|
664
|
-
*/
|
|
665
|
-
this.isCorrect = common.isCorrect(constants6.BITS);
|
|
666
|
-
if (optionalGroups === void 0) this.groups = constants6.GROUPS;
|
|
667
|
-
else this.groups = optionalGroups;
|
|
668
|
-
this.address = address;
|
|
669
|
-
const subnet = constants6.RE_SUBNET_STRING.exec(address);
|
|
670
|
-
if (subnet) {
|
|
671
|
-
this.parsedSubnet = subnet[0].replace("/", "");
|
|
672
|
-
this.subnetMask = parseInt(this.parsedSubnet, 10);
|
|
673
|
-
this.subnet = `/${this.subnetMask}`;
|
|
674
|
-
if (Number.isNaN(this.subnetMask) || this.subnetMask < 0 || this.subnetMask > constants6.BITS) throw new address_error_1.AddressError("Invalid subnet mask.");
|
|
675
|
-
address = address.replace(constants6.RE_SUBNET_STRING, "");
|
|
676
|
-
} else if (/\//.test(address)) throw new address_error_1.AddressError("Invalid subnet mask.");
|
|
677
|
-
const zone = constants6.RE_ZONE_STRING.exec(address);
|
|
678
|
-
if (zone) {
|
|
679
|
-
this.zone = zone[0];
|
|
680
|
-
address = address.replace(constants6.RE_ZONE_STRING, "");
|
|
681
|
-
}
|
|
682
|
-
this.addressMinusSuffix = address;
|
|
683
|
-
this.parsedAddress = this.parse(this.addressMinusSuffix);
|
|
684
|
-
}
|
|
685
|
-
static isValid(address) {
|
|
686
|
-
try {
|
|
687
|
-
new Address6(address);
|
|
688
|
-
return true;
|
|
689
|
-
} catch (e) {
|
|
690
|
-
return false;
|
|
691
|
-
}
|
|
692
|
-
}
|
|
693
|
-
/**
|
|
694
|
-
* Convert a BigInt to a v6 address object
|
|
695
|
-
* @memberof Address6
|
|
696
|
-
* @static
|
|
697
|
-
* @param {bigint} bigInt - a BigInt to convert
|
|
698
|
-
* @returns {Address6}
|
|
699
|
-
* @example
|
|
700
|
-
* var bigInt = BigInt('1000000000000');
|
|
701
|
-
* var address = Address6.fromBigInt(bigInt);
|
|
702
|
-
* address.correctForm(); // '::e8:d4a5:1000'
|
|
703
|
-
*/
|
|
704
|
-
static fromBigInt(bigInt) {
|
|
705
|
-
const hex = bigInt.toString(16).padStart(32, "0");
|
|
706
|
-
const groups = [];
|
|
707
|
-
let i;
|
|
708
|
-
for (i = 0; i < constants6.GROUPS; i++) groups.push(hex.slice(i * 4, (i + 1) * 4));
|
|
709
|
-
return new Address6(groups.join(":"));
|
|
710
|
-
}
|
|
711
|
-
/**
|
|
712
|
-
* Convert a URL (with optional port number) to an address object
|
|
713
|
-
* @memberof Address6
|
|
714
|
-
* @static
|
|
715
|
-
* @param {string} url - a URL with optional port number
|
|
716
|
-
* @example
|
|
717
|
-
* var addressAndPort = Address6.fromURL('http://[ffff::]:8080/foo/');
|
|
718
|
-
* addressAndPort.address.correctForm(); // 'ffff::'
|
|
719
|
-
* addressAndPort.port; // 8080
|
|
720
|
-
*/
|
|
721
|
-
static fromURL(url) {
|
|
722
|
-
let host;
|
|
723
|
-
let port = null;
|
|
724
|
-
let result;
|
|
725
|
-
if (url.indexOf("[") !== -1 && url.indexOf("]:") !== -1) {
|
|
726
|
-
result = constants6.RE_URL_WITH_PORT.exec(url);
|
|
727
|
-
if (result === null) return {
|
|
728
|
-
error: "failed to parse address with port",
|
|
729
|
-
address: null,
|
|
730
|
-
port: null
|
|
731
|
-
};
|
|
732
|
-
host = result[1];
|
|
733
|
-
port = result[2];
|
|
734
|
-
} else if (url.indexOf("/") !== -1) {
|
|
735
|
-
url = url.replace(/^[a-z0-9]+:\/\//, "");
|
|
736
|
-
result = constants6.RE_URL.exec(url);
|
|
737
|
-
if (result === null) return {
|
|
738
|
-
error: "failed to parse address from URL",
|
|
739
|
-
address: null,
|
|
740
|
-
port: null
|
|
741
|
-
};
|
|
742
|
-
host = result[1];
|
|
743
|
-
} else host = url;
|
|
744
|
-
if (port) {
|
|
745
|
-
port = parseInt(port, 10);
|
|
746
|
-
if (port < 0 || port > 65536) port = null;
|
|
747
|
-
} else port = null;
|
|
748
|
-
return {
|
|
749
|
-
address: new Address6(host),
|
|
750
|
-
port
|
|
751
|
-
};
|
|
752
|
-
}
|
|
753
|
-
/**
|
|
754
|
-
* Create an IPv6-mapped address given an IPv4 address
|
|
755
|
-
* @memberof Address6
|
|
756
|
-
* @static
|
|
757
|
-
* @param {string} address - An IPv4 address string
|
|
758
|
-
* @returns {Address6}
|
|
759
|
-
* @example
|
|
760
|
-
* var address = Address6.fromAddress4('192.168.0.1');
|
|
761
|
-
* address.correctForm(); // '::ffff:c0a8:1'
|
|
762
|
-
* address.to4in6(); // '::ffff:192.168.0.1'
|
|
763
|
-
*/
|
|
764
|
-
static fromAddress4(address) {
|
|
765
|
-
const address4 = new ipv4_1.Address4(address);
|
|
766
|
-
const mask6 = constants6.BITS - (constants4.BITS - address4.subnetMask);
|
|
767
|
-
return new Address6(`::ffff:${address4.correctForm()}/${mask6}`);
|
|
768
|
-
}
|
|
769
|
-
/**
|
|
770
|
-
* Return an address from ip6.arpa form
|
|
771
|
-
* @memberof Address6
|
|
772
|
-
* @static
|
|
773
|
-
* @param {string} arpaFormAddress - an 'ip6.arpa' form address
|
|
774
|
-
* @returns {Adress6}
|
|
775
|
-
* @example
|
|
776
|
-
* 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.)
|
|
777
|
-
* address.correctForm(); // '2001:0:ce49:7601:e866:efff:62c3:fffe'
|
|
778
|
-
*/
|
|
779
|
-
static fromArpa(arpaFormAddress) {
|
|
780
|
-
let address = arpaFormAddress.replace(/(\.ip6\.arpa)?\.$/, "");
|
|
781
|
-
const semicolonAmount = 7;
|
|
782
|
-
if (address.length !== 63) throw new address_error_1.AddressError("Invalid 'ip6.arpa' form.");
|
|
783
|
-
const parts = address.split(".").reverse();
|
|
784
|
-
for (let i = semicolonAmount; i > 0; i--) {
|
|
785
|
-
const insertIndex = i * 4;
|
|
786
|
-
parts.splice(insertIndex, 0, ":");
|
|
787
|
-
}
|
|
788
|
-
address = parts.join("");
|
|
789
|
-
return new Address6(address);
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* Return the Microsoft UNC transcription of the address
|
|
793
|
-
* @memberof Address6
|
|
794
|
-
* @instance
|
|
795
|
-
* @returns {String} the Microsoft UNC transcription of the address
|
|
796
|
-
*/
|
|
797
|
-
microsoftTranscription() {
|
|
798
|
-
return `${this.correctForm().replace(/:/g, "-")}.ipv6-literal.net`;
|
|
799
|
-
}
|
|
800
|
-
/**
|
|
801
|
-
* Return the first n bits of the address, defaulting to the subnet mask
|
|
802
|
-
* @memberof Address6
|
|
803
|
-
* @instance
|
|
804
|
-
* @param {number} [mask=subnet] - the number of bits to mask
|
|
805
|
-
* @returns {String} the first n bits of the address as a string
|
|
806
|
-
*/
|
|
807
|
-
mask(mask = this.subnetMask) {
|
|
808
|
-
return this.getBitsBase2(0, mask);
|
|
809
|
-
}
|
|
810
|
-
/**
|
|
811
|
-
* Return the number of possible subnets of a given size in the address
|
|
812
|
-
* @memberof Address6
|
|
813
|
-
* @instance
|
|
814
|
-
* @param {number} [subnetSize=128] - the subnet size
|
|
815
|
-
* @returns {String}
|
|
816
|
-
*/
|
|
817
|
-
possibleSubnets(subnetSize = 128) {
|
|
818
|
-
const subnetPowers = constants6.BITS - this.subnetMask - Math.abs(subnetSize - constants6.BITS);
|
|
819
|
-
if (subnetPowers < 0) return "0";
|
|
820
|
-
return addCommas((BigInt("2") ** BigInt(subnetPowers)).toString(10));
|
|
821
|
-
}
|
|
822
|
-
/**
|
|
823
|
-
* Helper function getting start address.
|
|
824
|
-
* @memberof Address6
|
|
825
|
-
* @instance
|
|
826
|
-
* @returns {bigint}
|
|
827
|
-
*/
|
|
828
|
-
_startAddress() {
|
|
829
|
-
return BigInt(`0b${this.mask() + "0".repeat(constants6.BITS - this.subnetMask)}`);
|
|
830
|
-
}
|
|
831
|
-
/**
|
|
832
|
-
* The first address in the range given by this address' subnet
|
|
833
|
-
* Often referred to as the Network Address.
|
|
834
|
-
* @memberof Address6
|
|
835
|
-
* @instance
|
|
836
|
-
* @returns {Address6}
|
|
837
|
-
*/
|
|
838
|
-
startAddress() {
|
|
839
|
-
return Address6.fromBigInt(this._startAddress());
|
|
840
|
-
}
|
|
841
|
-
/**
|
|
842
|
-
* The first host address in the range given by this address's subnet ie
|
|
843
|
-
* the first address after the Network Address
|
|
844
|
-
* @memberof Address6
|
|
845
|
-
* @instance
|
|
846
|
-
* @returns {Address6}
|
|
847
|
-
*/
|
|
848
|
-
startAddressExclusive() {
|
|
849
|
-
const adjust = BigInt("1");
|
|
850
|
-
return Address6.fromBigInt(this._startAddress() + adjust);
|
|
851
|
-
}
|
|
852
|
-
/**
|
|
853
|
-
* Helper function getting end address.
|
|
854
|
-
* @memberof Address6
|
|
855
|
-
* @instance
|
|
856
|
-
* @returns {bigint}
|
|
857
|
-
*/
|
|
858
|
-
_endAddress() {
|
|
859
|
-
return BigInt(`0b${this.mask() + "1".repeat(constants6.BITS - this.subnetMask)}`);
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* The last address in the range given by this address' subnet
|
|
863
|
-
* Often referred to as the Broadcast
|
|
864
|
-
* @memberof Address6
|
|
865
|
-
* @instance
|
|
866
|
-
* @returns {Address6}
|
|
867
|
-
*/
|
|
868
|
-
endAddress() {
|
|
869
|
-
return Address6.fromBigInt(this._endAddress());
|
|
870
|
-
}
|
|
871
|
-
/**
|
|
872
|
-
* The last host address in the range given by this address's subnet ie
|
|
873
|
-
* the last address prior to the Broadcast Address
|
|
874
|
-
* @memberof Address6
|
|
875
|
-
* @instance
|
|
876
|
-
* @returns {Address6}
|
|
877
|
-
*/
|
|
878
|
-
endAddressExclusive() {
|
|
879
|
-
const adjust = BigInt("1");
|
|
880
|
-
return Address6.fromBigInt(this._endAddress() - adjust);
|
|
881
|
-
}
|
|
882
|
-
/**
|
|
883
|
-
* Return the scope of the address
|
|
884
|
-
* @memberof Address6
|
|
885
|
-
* @instance
|
|
886
|
-
* @returns {String}
|
|
887
|
-
*/
|
|
888
|
-
getScope() {
|
|
889
|
-
let scope = constants6.SCOPES[parseInt(this.getBits(12, 16).toString(10), 10)];
|
|
890
|
-
if (this.getType() === "Global unicast" && scope !== "Link local") scope = "Global";
|
|
891
|
-
return scope || "Unknown";
|
|
892
|
-
}
|
|
893
|
-
/**
|
|
894
|
-
* Return the type of the address
|
|
895
|
-
* @memberof Address6
|
|
896
|
-
* @instance
|
|
897
|
-
* @returns {String}
|
|
898
|
-
*/
|
|
899
|
-
getType() {
|
|
900
|
-
for (const subnet of Object.keys(constants6.TYPES)) if (this.isInSubnet(new Address6(subnet))) return constants6.TYPES[subnet];
|
|
901
|
-
return "Global unicast";
|
|
902
|
-
}
|
|
903
|
-
/**
|
|
904
|
-
* Return the bits in the given range as a BigInt
|
|
905
|
-
* @memberof Address6
|
|
906
|
-
* @instance
|
|
907
|
-
* @returns {bigint}
|
|
908
|
-
*/
|
|
909
|
-
getBits(start, end) {
|
|
910
|
-
return BigInt(`0b${this.getBitsBase2(start, end)}`);
|
|
911
|
-
}
|
|
912
|
-
/**
|
|
913
|
-
* Return the bits in the given range as a base-2 string
|
|
914
|
-
* @memberof Address6
|
|
915
|
-
* @instance
|
|
916
|
-
* @returns {String}
|
|
917
|
-
*/
|
|
918
|
-
getBitsBase2(start, end) {
|
|
919
|
-
return this.binaryZeroPad().slice(start, end);
|
|
920
|
-
}
|
|
921
|
-
/**
|
|
922
|
-
* Return the bits in the given range as a base-16 string
|
|
923
|
-
* @memberof Address6
|
|
924
|
-
* @instance
|
|
925
|
-
* @returns {String}
|
|
926
|
-
*/
|
|
927
|
-
getBitsBase16(start, end) {
|
|
928
|
-
const length = end - start;
|
|
929
|
-
if (length % 4 !== 0) throw new Error("Length of bits to retrieve must be divisible by four");
|
|
930
|
-
return this.getBits(start, end).toString(16).padStart(length / 4, "0");
|
|
931
|
-
}
|
|
932
|
-
/**
|
|
933
|
-
* Return the bits that are set past the subnet mask length
|
|
934
|
-
* @memberof Address6
|
|
935
|
-
* @instance
|
|
936
|
-
* @returns {String}
|
|
937
|
-
*/
|
|
938
|
-
getBitsPastSubnet() {
|
|
939
|
-
return this.getBitsBase2(this.subnetMask, constants6.BITS);
|
|
940
|
-
}
|
|
941
|
-
/**
|
|
942
|
-
* Return the reversed ip6.arpa form of the address
|
|
943
|
-
* @memberof Address6
|
|
944
|
-
* @param {Object} options
|
|
945
|
-
* @param {boolean} options.omitSuffix - omit the "ip6.arpa" suffix
|
|
946
|
-
* @instance
|
|
947
|
-
* @returns {String}
|
|
948
|
-
*/
|
|
949
|
-
reverseForm(options) {
|
|
950
|
-
if (!options) options = {};
|
|
951
|
-
const characters = Math.floor(this.subnetMask / 4);
|
|
952
|
-
const reversed = this.canonicalForm().replace(/:/g, "").split("").slice(0, characters).reverse().join(".");
|
|
953
|
-
if (characters > 0) {
|
|
954
|
-
if (options.omitSuffix) return reversed;
|
|
955
|
-
return `${reversed}.ip6.arpa.`;
|
|
956
|
-
}
|
|
957
|
-
if (options.omitSuffix) return "";
|
|
958
|
-
return "ip6.arpa.";
|
|
959
|
-
}
|
|
960
|
-
/**
|
|
961
|
-
* Return the correct form of the address
|
|
962
|
-
* @memberof Address6
|
|
963
|
-
* @instance
|
|
964
|
-
* @returns {String}
|
|
965
|
-
*/
|
|
966
|
-
correctForm() {
|
|
967
|
-
let i;
|
|
968
|
-
let groups = [];
|
|
969
|
-
let zeroCounter = 0;
|
|
970
|
-
const zeroes = [];
|
|
971
|
-
for (i = 0; i < this.parsedAddress.length; i++) {
|
|
972
|
-
const value = parseInt(this.parsedAddress[i], 16);
|
|
973
|
-
if (value === 0) zeroCounter++;
|
|
974
|
-
if (value !== 0 && zeroCounter > 0) {
|
|
975
|
-
if (zeroCounter > 1) zeroes.push([i - zeroCounter, i - 1]);
|
|
976
|
-
zeroCounter = 0;
|
|
977
|
-
}
|
|
978
|
-
}
|
|
979
|
-
if (zeroCounter > 1) zeroes.push([this.parsedAddress.length - zeroCounter, this.parsedAddress.length - 1]);
|
|
980
|
-
const zeroLengths = zeroes.map((n) => n[1] - n[0] + 1);
|
|
981
|
-
if (zeroes.length > 0) {
|
|
982
|
-
const index = zeroLengths.indexOf(Math.max(...zeroLengths));
|
|
983
|
-
groups = compact(this.parsedAddress, zeroes[index]);
|
|
984
|
-
} else groups = this.parsedAddress;
|
|
985
|
-
for (i = 0; i < groups.length; i++) if (groups[i] !== "compact") groups[i] = parseInt(groups[i], 16).toString(16);
|
|
986
|
-
let correct = groups.join(":");
|
|
987
|
-
correct = correct.replace(/^compact$/, "::");
|
|
988
|
-
correct = correct.replace(/(^compact)|(compact$)/, ":");
|
|
989
|
-
correct = correct.replace(/compact/, "");
|
|
990
|
-
return correct;
|
|
991
|
-
}
|
|
992
|
-
/**
|
|
993
|
-
* Return a zero-padded base-2 string representation of the address
|
|
994
|
-
* @memberof Address6
|
|
995
|
-
* @instance
|
|
996
|
-
* @returns {String}
|
|
997
|
-
* @example
|
|
998
|
-
* var address = new Address6('2001:4860:4001:803::1011');
|
|
999
|
-
* address.binaryZeroPad();
|
|
1000
|
-
* // '0010000000000001010010000110000001000000000000010000100000000011
|
|
1001
|
-
* // 0000000000000000000000000000000000000000000000000001000000010001'
|
|
1002
|
-
*/
|
|
1003
|
-
binaryZeroPad() {
|
|
1004
|
-
return this.bigInt().toString(2).padStart(constants6.BITS, "0");
|
|
1005
|
-
}
|
|
1006
|
-
parse4in6(address) {
|
|
1007
|
-
const groups = address.split(":");
|
|
1008
|
-
const address4 = groups.slice(-1)[0].match(constants4.RE_ADDRESS);
|
|
1009
|
-
if (address4) {
|
|
1010
|
-
this.parsedAddress4 = address4[0];
|
|
1011
|
-
this.address4 = new ipv4_1.Address4(this.parsedAddress4);
|
|
1012
|
-
for (let i = 0; i < this.address4.groups; i++) if (/^0[0-9]+/.test(this.address4.parsedAddress[i])) throw new address_error_1.AddressError("IPv4 addresses can't have leading zeroes.", address.replace(constants4.RE_ADDRESS, this.address4.parsedAddress.map(spanLeadingZeroes4).join(".")));
|
|
1013
|
-
this.v4 = true;
|
|
1014
|
-
groups[groups.length - 1] = this.address4.toGroup6();
|
|
1015
|
-
address = groups.join(":");
|
|
1016
|
-
}
|
|
1017
|
-
return address;
|
|
1018
|
-
}
|
|
1019
|
-
parse(address) {
|
|
1020
|
-
address = this.parse4in6(address);
|
|
1021
|
-
const badCharacters = address.match(constants6.RE_BAD_CHARACTERS);
|
|
1022
|
-
if (badCharacters) throw new address_error_1.AddressError(`Bad character${badCharacters.length > 1 ? "s" : ""} detected in address: ${badCharacters.join("")}`, address.replace(constants6.RE_BAD_CHARACTERS, "<span class=\"parse-error\">$1</span>"));
|
|
1023
|
-
const badAddress = address.match(constants6.RE_BAD_ADDRESS);
|
|
1024
|
-
if (badAddress) throw new address_error_1.AddressError(`Address failed regex: ${badAddress.join("")}`, address.replace(constants6.RE_BAD_ADDRESS, "<span class=\"parse-error\">$1</span>"));
|
|
1025
|
-
let groups = [];
|
|
1026
|
-
const halves = address.split("::");
|
|
1027
|
-
if (halves.length === 2) {
|
|
1028
|
-
let first = halves[0].split(":");
|
|
1029
|
-
let last = halves[1].split(":");
|
|
1030
|
-
if (first.length === 1 && first[0] === "") first = [];
|
|
1031
|
-
if (last.length === 1 && last[0] === "") last = [];
|
|
1032
|
-
const remaining = this.groups - (first.length + last.length);
|
|
1033
|
-
if (!remaining) throw new address_error_1.AddressError("Error parsing groups");
|
|
1034
|
-
this.elidedGroups = remaining;
|
|
1035
|
-
this.elisionBegin = first.length;
|
|
1036
|
-
this.elisionEnd = first.length + this.elidedGroups;
|
|
1037
|
-
groups = groups.concat(first);
|
|
1038
|
-
for (let i = 0; i < remaining; i++) groups.push("0");
|
|
1039
|
-
groups = groups.concat(last);
|
|
1040
|
-
} else if (halves.length === 1) {
|
|
1041
|
-
groups = address.split(":");
|
|
1042
|
-
this.elidedGroups = 0;
|
|
1043
|
-
} else throw new address_error_1.AddressError("Too many :: groups found");
|
|
1044
|
-
groups = groups.map((group) => parseInt(group, 16).toString(16));
|
|
1045
|
-
if (groups.length !== this.groups) throw new address_error_1.AddressError("Incorrect number of groups found");
|
|
1046
|
-
return groups;
|
|
1047
|
-
}
|
|
1048
|
-
/**
|
|
1049
|
-
* Return the canonical form of the address
|
|
1050
|
-
* @memberof Address6
|
|
1051
|
-
* @instance
|
|
1052
|
-
* @returns {String}
|
|
1053
|
-
*/
|
|
1054
|
-
canonicalForm() {
|
|
1055
|
-
return this.parsedAddress.map(paddedHex).join(":");
|
|
1056
|
-
}
|
|
1057
|
-
/**
|
|
1058
|
-
* Return the decimal form of the address
|
|
1059
|
-
* @memberof Address6
|
|
1060
|
-
* @instance
|
|
1061
|
-
* @returns {String}
|
|
1062
|
-
*/
|
|
1063
|
-
decimal() {
|
|
1064
|
-
return this.parsedAddress.map((n) => parseInt(n, 16).toString(10).padStart(5, "0")).join(":");
|
|
1065
|
-
}
|
|
1066
|
-
/**
|
|
1067
|
-
* Return the address as a BigInt
|
|
1068
|
-
* @memberof Address6
|
|
1069
|
-
* @instance
|
|
1070
|
-
* @returns {bigint}
|
|
1071
|
-
*/
|
|
1072
|
-
bigInt() {
|
|
1073
|
-
return BigInt(`0x${this.parsedAddress.map(paddedHex).join("")}`);
|
|
1074
|
-
}
|
|
1075
|
-
/**
|
|
1076
|
-
* Return the last two groups of this address as an IPv4 address string
|
|
1077
|
-
* @memberof Address6
|
|
1078
|
-
* @instance
|
|
1079
|
-
* @returns {Address4}
|
|
1080
|
-
* @example
|
|
1081
|
-
* var address = new Address6('2001:4860:4001::1825:bf11');
|
|
1082
|
-
* address.to4().correctForm(); // '24.37.191.17'
|
|
1083
|
-
*/
|
|
1084
|
-
to4() {
|
|
1085
|
-
const binary = this.binaryZeroPad().split("");
|
|
1086
|
-
return ipv4_1.Address4.fromHex(BigInt(`0b${binary.slice(96, 128).join("")}`).toString(16));
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Return the v4-in-v6 form of the address
|
|
1090
|
-
* @memberof Address6
|
|
1091
|
-
* @instance
|
|
1092
|
-
* @returns {String}
|
|
1093
|
-
*/
|
|
1094
|
-
to4in6() {
|
|
1095
|
-
const address4 = this.to4();
|
|
1096
|
-
const correct = new Address6(this.parsedAddress.slice(0, 6).join(":"), 6).correctForm();
|
|
1097
|
-
let infix = "";
|
|
1098
|
-
if (!/:$/.test(correct)) infix = ":";
|
|
1099
|
-
return correct + infix + address4.address;
|
|
1100
|
-
}
|
|
1101
|
-
/**
|
|
1102
|
-
* Return an object containing the Teredo properties of the address
|
|
1103
|
-
* @memberof Address6
|
|
1104
|
-
* @instance
|
|
1105
|
-
* @returns {Object}
|
|
1106
|
-
*/
|
|
1107
|
-
inspectTeredo() {
|
|
1108
|
-
const prefix = this.getBitsBase16(0, 32);
|
|
1109
|
-
const udpPort = (this.getBits(80, 96) ^ BigInt("0xffff")).toString();
|
|
1110
|
-
const server4 = ipv4_1.Address4.fromHex(this.getBitsBase16(32, 64));
|
|
1111
|
-
const bitsForClient4 = this.getBits(96, 128);
|
|
1112
|
-
const client4 = ipv4_1.Address4.fromHex((bitsForClient4 ^ BigInt("0xffffffff")).toString(16));
|
|
1113
|
-
const flagsBase2 = this.getBitsBase2(64, 80);
|
|
1114
|
-
const coneNat = (0, common_1.testBit)(flagsBase2, 15);
|
|
1115
|
-
const reserved = (0, common_1.testBit)(flagsBase2, 14);
|
|
1116
|
-
const groupIndividual = (0, common_1.testBit)(flagsBase2, 8);
|
|
1117
|
-
const universalLocal = (0, common_1.testBit)(flagsBase2, 9);
|
|
1118
|
-
const nonce = BigInt(`0b${flagsBase2.slice(2, 6) + flagsBase2.slice(8, 16)}`).toString(10);
|
|
1119
|
-
return {
|
|
1120
|
-
prefix: `${prefix.slice(0, 4)}:${prefix.slice(4, 8)}`,
|
|
1121
|
-
server4: server4.address,
|
|
1122
|
-
client4: client4.address,
|
|
1123
|
-
flags: flagsBase2,
|
|
1124
|
-
coneNat,
|
|
1125
|
-
microsoft: {
|
|
1126
|
-
reserved,
|
|
1127
|
-
universalLocal,
|
|
1128
|
-
groupIndividual,
|
|
1129
|
-
nonce
|
|
1130
|
-
},
|
|
1131
|
-
udpPort
|
|
1132
|
-
};
|
|
1133
|
-
}
|
|
1134
|
-
/**
|
|
1135
|
-
* Return an object containing the 6to4 properties of the address
|
|
1136
|
-
* @memberof Address6
|
|
1137
|
-
* @instance
|
|
1138
|
-
* @returns {Object}
|
|
1139
|
-
*/
|
|
1140
|
-
inspect6to4() {
|
|
1141
|
-
const prefix = this.getBitsBase16(0, 16);
|
|
1142
|
-
const gateway = ipv4_1.Address4.fromHex(this.getBitsBase16(16, 48));
|
|
1143
|
-
return {
|
|
1144
|
-
prefix: prefix.slice(0, 4),
|
|
1145
|
-
gateway: gateway.address
|
|
1146
|
-
};
|
|
1147
|
-
}
|
|
1148
|
-
/**
|
|
1149
|
-
* Return a v6 6to4 address from a v6 v4inv6 address
|
|
1150
|
-
* @memberof Address6
|
|
1151
|
-
* @instance
|
|
1152
|
-
* @returns {Address6}
|
|
1153
|
-
*/
|
|
1154
|
-
to6to4() {
|
|
1155
|
-
if (!this.is4()) return null;
|
|
1156
|
-
return new Address6([
|
|
1157
|
-
"2002",
|
|
1158
|
-
this.getBitsBase16(96, 112),
|
|
1159
|
-
this.getBitsBase16(112, 128),
|
|
1160
|
-
"",
|
|
1161
|
-
"/16"
|
|
1162
|
-
].join(":"));
|
|
1163
|
-
}
|
|
1164
|
-
/**
|
|
1165
|
-
* Return a byte array
|
|
1166
|
-
* @memberof Address6
|
|
1167
|
-
* @instance
|
|
1168
|
-
* @returns {Array}
|
|
1169
|
-
*/
|
|
1170
|
-
toByteArray() {
|
|
1171
|
-
const valueWithoutPadding = this.bigInt().toString(16);
|
|
1172
|
-
const value = `${"0".repeat(valueWithoutPadding.length % 2)}${valueWithoutPadding}`;
|
|
1173
|
-
const bytes = [];
|
|
1174
|
-
for (let i = 0, length = value.length; i < length; i += 2) bytes.push(parseInt(value.substring(i, i + 2), 16));
|
|
1175
|
-
return bytes;
|
|
1176
|
-
}
|
|
1177
|
-
/**
|
|
1178
|
-
* Return an unsigned byte array
|
|
1179
|
-
* @memberof Address6
|
|
1180
|
-
* @instance
|
|
1181
|
-
* @returns {Array}
|
|
1182
|
-
*/
|
|
1183
|
-
toUnsignedByteArray() {
|
|
1184
|
-
return this.toByteArray().map(unsignByte);
|
|
1185
|
-
}
|
|
1186
|
-
/**
|
|
1187
|
-
* Convert a byte array to an Address6 object
|
|
1188
|
-
* @memberof Address6
|
|
1189
|
-
* @static
|
|
1190
|
-
* @returns {Address6}
|
|
1191
|
-
*/
|
|
1192
|
-
static fromByteArray(bytes) {
|
|
1193
|
-
return this.fromUnsignedByteArray(bytes.map(unsignByte));
|
|
1194
|
-
}
|
|
1195
|
-
/**
|
|
1196
|
-
* Convert an unsigned byte array to an Address6 object
|
|
1197
|
-
* @memberof Address6
|
|
1198
|
-
* @static
|
|
1199
|
-
* @returns {Address6}
|
|
1200
|
-
*/
|
|
1201
|
-
static fromUnsignedByteArray(bytes) {
|
|
1202
|
-
const BYTE_MAX = BigInt("256");
|
|
1203
|
-
let result = BigInt("0");
|
|
1204
|
-
let multiplier = BigInt("1");
|
|
1205
|
-
for (let i = bytes.length - 1; i >= 0; i--) {
|
|
1206
|
-
result += multiplier * BigInt(bytes[i].toString(10));
|
|
1207
|
-
multiplier *= BYTE_MAX;
|
|
1208
|
-
}
|
|
1209
|
-
return Address6.fromBigInt(result);
|
|
1210
|
-
}
|
|
1211
|
-
/**
|
|
1212
|
-
* Returns true if the address is in the canonical form, false otherwise
|
|
1213
|
-
* @memberof Address6
|
|
1214
|
-
* @instance
|
|
1215
|
-
* @returns {boolean}
|
|
1216
|
-
*/
|
|
1217
|
-
isCanonical() {
|
|
1218
|
-
return this.addressMinusSuffix === this.canonicalForm();
|
|
1219
|
-
}
|
|
1220
|
-
/**
|
|
1221
|
-
* Returns true if the address is a link local address, false otherwise
|
|
1222
|
-
* @memberof Address6
|
|
1223
|
-
* @instance
|
|
1224
|
-
* @returns {boolean}
|
|
1225
|
-
*/
|
|
1226
|
-
isLinkLocal() {
|
|
1227
|
-
if (this.getBitsBase2(0, 64) === "1111111010000000000000000000000000000000000000000000000000000000") return true;
|
|
1228
|
-
return false;
|
|
1229
|
-
}
|
|
1230
|
-
/**
|
|
1231
|
-
* Returns true if the address is a multicast address, false otherwise
|
|
1232
|
-
* @memberof Address6
|
|
1233
|
-
* @instance
|
|
1234
|
-
* @returns {boolean}
|
|
1235
|
-
*/
|
|
1236
|
-
isMulticast() {
|
|
1237
|
-
return this.getType() === "Multicast";
|
|
1238
|
-
}
|
|
1239
|
-
/**
|
|
1240
|
-
* Returns true if the address is a v4-in-v6 address, false otherwise
|
|
1241
|
-
* @memberof Address6
|
|
1242
|
-
* @instance
|
|
1243
|
-
* @returns {boolean}
|
|
1244
|
-
*/
|
|
1245
|
-
is4() {
|
|
1246
|
-
return this.v4;
|
|
1247
|
-
}
|
|
1248
|
-
/**
|
|
1249
|
-
* Returns true if the address is a Teredo address, false otherwise
|
|
1250
|
-
* @memberof Address6
|
|
1251
|
-
* @instance
|
|
1252
|
-
* @returns {boolean}
|
|
1253
|
-
*/
|
|
1254
|
-
isTeredo() {
|
|
1255
|
-
return this.isInSubnet(new Address6("2001::/32"));
|
|
1256
|
-
}
|
|
1257
|
-
/**
|
|
1258
|
-
* Returns true if the address is a 6to4 address, false otherwise
|
|
1259
|
-
* @memberof Address6
|
|
1260
|
-
* @instance
|
|
1261
|
-
* @returns {boolean}
|
|
1262
|
-
*/
|
|
1263
|
-
is6to4() {
|
|
1264
|
-
return this.isInSubnet(new Address6("2002::/16"));
|
|
1265
|
-
}
|
|
1266
|
-
/**
|
|
1267
|
-
* Returns true if the address is a loopback address, false otherwise
|
|
1268
|
-
* @memberof Address6
|
|
1269
|
-
* @instance
|
|
1270
|
-
* @returns {boolean}
|
|
1271
|
-
*/
|
|
1272
|
-
isLoopback() {
|
|
1273
|
-
return this.getType() === "Loopback";
|
|
1274
|
-
}
|
|
1275
|
-
/**
|
|
1276
|
-
* @returns {String} the address in link form with a default port of 80
|
|
1277
|
-
*/
|
|
1278
|
-
href(optionalPort) {
|
|
1279
|
-
if (optionalPort === void 0) optionalPort = "";
|
|
1280
|
-
else optionalPort = `:${optionalPort}`;
|
|
1281
|
-
return `http://[${this.correctForm()}]${optionalPort}/`;
|
|
1282
|
-
}
|
|
1283
|
-
/**
|
|
1284
|
-
* @returns {String} a link suitable for conveying the address via a URL hash
|
|
1285
|
-
*/
|
|
1286
|
-
link(options) {
|
|
1287
|
-
if (!options) options = {};
|
|
1288
|
-
if (options.className === void 0) options.className = "";
|
|
1289
|
-
if (options.prefix === void 0) options.prefix = "/#address=";
|
|
1290
|
-
if (options.v4 === void 0) options.v4 = false;
|
|
1291
|
-
let formFunction = this.correctForm;
|
|
1292
|
-
if (options.v4) formFunction = this.to4in6;
|
|
1293
|
-
const form = formFunction.call(this);
|
|
1294
|
-
if (options.className) return `<a href="${options.prefix}${form}" class="${options.className}">${form}</a>`;
|
|
1295
|
-
return `<a href="${options.prefix}${form}">${form}</a>`;
|
|
1296
|
-
}
|
|
1297
|
-
/**
|
|
1298
|
-
* Groups an address
|
|
1299
|
-
* @returns {String}
|
|
1300
|
-
*/
|
|
1301
|
-
group() {
|
|
1302
|
-
if (this.elidedGroups === 0) return helpers.simpleGroup(this.address).join(":");
|
|
1303
|
-
assert(typeof this.elidedGroups === "number");
|
|
1304
|
-
assert(typeof this.elisionBegin === "number");
|
|
1305
|
-
const output = [];
|
|
1306
|
-
const [left, right] = this.address.split("::");
|
|
1307
|
-
if (left.length) output.push(...helpers.simpleGroup(left));
|
|
1308
|
-
else output.push("");
|
|
1309
|
-
const classes = ["hover-group"];
|
|
1310
|
-
for (let i = this.elisionBegin; i < this.elisionBegin + this.elidedGroups; i++) classes.push(`group-${i}`);
|
|
1311
|
-
output.push(`<span class="${classes.join(" ")}"></span>`);
|
|
1312
|
-
if (right.length) output.push(...helpers.simpleGroup(right, this.elisionEnd));
|
|
1313
|
-
else output.push("");
|
|
1314
|
-
if (this.is4()) {
|
|
1315
|
-
assert(this.address4 instanceof ipv4_1.Address4);
|
|
1316
|
-
output.pop();
|
|
1317
|
-
output.push(this.address4.groupForV6());
|
|
1318
|
-
}
|
|
1319
|
-
return output.join(":");
|
|
1320
|
-
}
|
|
1321
|
-
/**
|
|
1322
|
-
* Generate a regular expression string that can be used to find or validate
|
|
1323
|
-
* all variations of this address
|
|
1324
|
-
* @memberof Address6
|
|
1325
|
-
* @instance
|
|
1326
|
-
* @param {boolean} substringSearch
|
|
1327
|
-
* @returns {string}
|
|
1328
|
-
*/
|
|
1329
|
-
regularExpressionString(substringSearch = false) {
|
|
1330
|
-
let output = [];
|
|
1331
|
-
const address6 = new Address6(this.correctForm());
|
|
1332
|
-
if (address6.elidedGroups === 0) output.push((0, regular_expressions_1.simpleRegularExpression)(address6.parsedAddress));
|
|
1333
|
-
else if (address6.elidedGroups === constants6.GROUPS) output.push((0, regular_expressions_1.possibleElisions)(constants6.GROUPS));
|
|
1334
|
-
else {
|
|
1335
|
-
const halves = address6.address.split("::");
|
|
1336
|
-
if (halves[0].length) output.push((0, regular_expressions_1.simpleRegularExpression)(halves[0].split(":")));
|
|
1337
|
-
assert(typeof address6.elidedGroups === "number");
|
|
1338
|
-
output.push((0, regular_expressions_1.possibleElisions)(address6.elidedGroups, halves[0].length !== 0, halves[1].length !== 0));
|
|
1339
|
-
if (halves[1].length) output.push((0, regular_expressions_1.simpleRegularExpression)(halves[1].split(":")));
|
|
1340
|
-
output = [output.join(":")];
|
|
1341
|
-
}
|
|
1342
|
-
if (!substringSearch) output = [
|
|
1343
|
-
"(?=^|",
|
|
1344
|
-
regular_expressions_1.ADDRESS_BOUNDARY,
|
|
1345
|
-
"|[^\\w\\:])(",
|
|
1346
|
-
...output,
|
|
1347
|
-
")(?=[^\\w\\:]|",
|
|
1348
|
-
regular_expressions_1.ADDRESS_BOUNDARY,
|
|
1349
|
-
"|$)"
|
|
1350
|
-
];
|
|
1351
|
-
return output.join("");
|
|
1352
|
-
}
|
|
1353
|
-
/**
|
|
1354
|
-
* Generate a regular expression that can be used to find or validate all
|
|
1355
|
-
* variations of this address.
|
|
1356
|
-
* @memberof Address6
|
|
1357
|
-
* @instance
|
|
1358
|
-
* @param {boolean} substringSearch
|
|
1359
|
-
* @returns {RegExp}
|
|
1360
|
-
*/
|
|
1361
|
-
regularExpression(substringSearch = false) {
|
|
1362
|
-
return new RegExp(this.regularExpressionString(substringSearch), "i");
|
|
1363
|
-
}
|
|
1364
|
-
};
|
|
1365
|
-
}));
|
|
1366
|
-
var require_ip_address = /* @__PURE__ */ __commonJSMin(((exports) => {
|
|
1367
|
-
var __createBinding = exports && exports.__createBinding || (Object.create ? (function(o, m, k, k2) {
|
|
1368
|
-
if (k2 === void 0) k2 = k;
|
|
1369
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
1370
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) desc = {
|
|
1371
|
-
enumerable: true,
|
|
1372
|
-
get: function() {
|
|
1373
|
-
return m[k];
|
|
1374
|
-
}
|
|
1375
|
-
};
|
|
1376
|
-
Object.defineProperty(o, k2, desc);
|
|
1377
|
-
}) : (function(o, m, k, k2) {
|
|
1378
|
-
if (k2 === void 0) k2 = k;
|
|
1379
|
-
o[k2] = m[k];
|
|
1380
|
-
}));
|
|
1381
|
-
var __setModuleDefault = exports && exports.__setModuleDefault || (Object.create ? (function(o, v) {
|
|
1382
|
-
Object.defineProperty(o, "default", {
|
|
1383
|
-
enumerable: true,
|
|
1384
|
-
value: v
|
|
1385
|
-
});
|
|
1386
|
-
}) : function(o, v) {
|
|
1387
|
-
o["default"] = v;
|
|
1388
|
-
});
|
|
1389
|
-
var __importStar = exports && exports.__importStar || function(mod) {
|
|
1390
|
-
if (mod && mod.__esModule) return mod;
|
|
1391
|
-
var result = {};
|
|
1392
|
-
if (mod != null) {
|
|
1393
|
-
for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
1394
|
-
}
|
|
1395
|
-
__setModuleDefault(result, mod);
|
|
1396
|
-
return result;
|
|
1397
|
-
};
|
|
1398
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
1399
|
-
exports.v6 = exports.AddressError = exports.Address6 = exports.Address4 = void 0;
|
|
1400
|
-
var ipv4_1 = require_ipv4();
|
|
1401
|
-
Object.defineProperty(exports, "Address4", {
|
|
1402
|
-
enumerable: true,
|
|
1403
|
-
get: function() {
|
|
1404
|
-
return ipv4_1.Address4;
|
|
1405
|
-
}
|
|
1406
|
-
});
|
|
1407
|
-
var ipv6_1 = require_ipv6();
|
|
1408
|
-
Object.defineProperty(exports, "Address6", {
|
|
1409
|
-
enumerable: true,
|
|
1410
|
-
get: function() {
|
|
1411
|
-
return ipv6_1.Address6;
|
|
1412
|
-
}
|
|
1413
|
-
});
|
|
1414
|
-
var address_error_1 = require_address_error();
|
|
1415
|
-
Object.defineProperty(exports, "AddressError", {
|
|
1416
|
-
enumerable: true,
|
|
1417
|
-
get: function() {
|
|
1418
|
-
return address_error_1.AddressError;
|
|
1419
|
-
}
|
|
1420
|
-
});
|
|
1421
|
-
exports.v6 = { helpers: __importStar(require_helpers()) };
|
|
1422
|
-
}));
|
|
1423
|
-
export { require_ip_address as t };
|