@fedify/vocab-runtime 2.4.0-pr.936.41 → 2.5.0-dev.2271

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.
Files changed (138) hide show
  1. package/deno.json +4 -2
  2. package/dist/{tests/docloader-Ck8bcBir.mjs → contexts-BK1CqBR5.cjs} +164 -275
  3. package/dist/{tests/docloader-S_gQZ2tt.cjs → contexts-DPuJ4UYL.js} +160 -294
  4. package/dist/{docloader-C_dir7Xb.d.ts → docloader-CYwqh5Df.d.cts} +66 -2
  5. package/dist/{docloader-D2DTRiyA.d.cts → docloader-CYwqh5Df.d.ts} +66 -2
  6. package/dist/internal/jsonld-cache.cjs +70 -1
  7. package/dist/internal/jsonld-cache.d.cts +35 -2
  8. package/dist/internal/jsonld-cache.d.ts +35 -2
  9. package/dist/internal/jsonld-cache.js +67 -2
  10. package/dist/internal/portable-dereference.cjs +721 -0
  11. package/dist/internal/portable-dereference.d.cts +349 -0
  12. package/dist/internal/portable-dereference.d.ts +349 -0
  13. package/dist/internal/portable-dereference.js +702 -0
  14. package/dist/internal/signed-representation.cjs +378 -0
  15. package/dist/internal/signed-representation.d.cts +144 -0
  16. package/dist/internal/signed-representation.d.ts +144 -0
  17. package/dist/internal/signed-representation.js +371 -0
  18. package/dist/jsonld.cjs +2 -2
  19. package/dist/mod.cjs +711 -4527
  20. package/dist/mod.d.cts +400 -8
  21. package/dist/mod.d.ts +400 -9
  22. package/dist/mod.js +692 -4522
  23. package/dist/portable-DqtfLy_1.d.cts +160 -0
  24. package/dist/portable-DtWsu2yU.d.ts +160 -0
  25. package/dist/tests/body-CVR1bABr.mjs +130 -0
  26. package/dist/tests/body-T_yQWql3.cjs +153 -0
  27. package/dist/tests/body.test.cjs +89 -0
  28. package/dist/tests/body.test.d.cts +1 -0
  29. package/dist/tests/body.test.d.mts +1 -0
  30. package/dist/tests/body.test.mjs +90 -0
  31. package/dist/tests/contexts-CIKsin4e.mjs +4512 -0
  32. package/dist/tests/contexts-DizzBjz4.cjs +4523 -0
  33. package/dist/tests/decimal.test.cjs +8 -7
  34. package/dist/tests/decimal.test.mjs +8 -6
  35. package/dist/tests/digest-3FeH2Y-Q.cjs +176 -0
  36. package/dist/tests/digest-COC7xDiQ.mjs +141 -0
  37. package/dist/tests/digest.test.cjs +102 -0
  38. package/dist/tests/digest.test.d.cts +1 -0
  39. package/dist/tests/digest.test.d.mts +1 -0
  40. package/dist/tests/digest.test.mjs +103 -0
  41. package/dist/tests/docloader-C6yApEts.mjs +373 -0
  42. package/dist/tests/docloader-CJK2w3l-.cjs +396 -0
  43. package/dist/tests/docloader.test.cjs +692 -39
  44. package/dist/tests/docloader.test.mjs +686 -34
  45. package/dist/tests/internal/multicodec.test.cjs +2 -3
  46. package/dist/tests/internal/multicodec.test.mjs +2 -2
  47. package/dist/tests/internal/portable-dereference.test.cjs +172 -0
  48. package/dist/tests/internal/portable-dereference.test.d.cts +1 -0
  49. package/dist/tests/internal/portable-dereference.test.d.mts +1 -0
  50. package/dist/tests/internal/portable-dereference.test.mjs +173 -0
  51. package/dist/tests/jsonld-cache-BPQmOZWD.mjs +342 -0
  52. package/dist/tests/jsonld-cache-C07AyNOY.cjs +397 -0
  53. package/dist/tests/jsonld-cache.test.cjs +101 -298
  54. package/dist/tests/jsonld-cache.test.mjs +94 -289
  55. package/dist/tests/{key-_wXwomh_.cjs → key-C-AYkdJJ.cjs} +11 -4
  56. package/dist/tests/{key-CDGDH_vC.mjs → key-C2Db_TAJ.mjs} +11 -3
  57. package/dist/tests/key.test.cjs +6 -5
  58. package/dist/tests/key.test.mjs +6 -4
  59. package/dist/tests/langstr.test.cjs +4 -4
  60. package/dist/tests/langstr.test.mjs +2 -2
  61. package/dist/tests/link.test.cjs +2 -3
  62. package/dist/tests/link.test.mjs +2 -2
  63. package/dist/tests/multibase/multibase.test.cjs +8 -9
  64. package/dist/tests/multibase/multibase.test.mjs +6 -6
  65. package/dist/tests/{multibase-Bz_UUDtL.cjs → multibase-B5Mea7Ip.cjs} +19 -2
  66. package/dist/tests/{multibase-B4bvakyA.mjs → multibase-BPnF_L4e.mjs} +12 -1
  67. package/dist/tests/portable-dereference-BNXtgg5U.cjs +278 -0
  68. package/dist/tests/portable-dereference-DRE5bz-l.mjs +249 -0
  69. package/dist/tests/portable-media-C4LEXJk4.mjs +148 -0
  70. package/dist/tests/portable-media-D05JJIJg.cjs +153 -0
  71. package/dist/tests/portable-media.test.cjs +222 -0
  72. package/dist/tests/portable-media.test.d.cts +1 -0
  73. package/dist/tests/portable-media.test.d.mts +1 -0
  74. package/dist/tests/portable-media.test.mjs +223 -0
  75. package/dist/tests/portable-workers.test.cjs +36 -0
  76. package/dist/tests/portable-workers.test.d.cts +2 -0
  77. package/dist/tests/portable-workers.test.d.mts +2 -0
  78. package/dist/tests/portable-workers.test.mjs +35 -0
  79. package/dist/tests/{request-uk51rkhO.cjs → request-C-VZ9TLj.cjs} +10 -4
  80. package/dist/tests/{request-C8CaGwtt.mjs → request-Cf-A3DU-.mjs} +8 -2
  81. package/dist/tests/request.test.cjs +7 -4
  82. package/dist/tests/request.test.mjs +5 -2
  83. package/dist/tests/signed-representation.test.cjs +588 -0
  84. package/dist/tests/signed-representation.test.d.cts +1 -0
  85. package/dist/tests/signed-representation.test.d.mts +1 -0
  86. package/dist/tests/signed-representation.test.mjs +589 -0
  87. package/dist/tests/temporal.test.cjs +1 -2
  88. package/dist/tests/temporal.test.mjs +1 -1
  89. package/dist/tests/url-BNakuZ8k.cjs +998 -0
  90. package/dist/tests/url-DMxmp7ZG.mjs +859 -0
  91. package/dist/tests/url.test.cjs +489 -6
  92. package/dist/tests/url.test.mjs +489 -5
  93. package/dist/url-DrGTR8yv.cjs +993 -0
  94. package/dist/url-Dzyp-NsC.js +860 -0
  95. package/package.json +27 -4
  96. package/scripts/test-bun.mjs +17 -0
  97. package/src/body.test.ts +125 -0
  98. package/src/body.ts +152 -0
  99. package/src/contexts/cid-v1.json +114 -0
  100. package/src/contexts/fep-22cd.json +21 -0
  101. package/src/contexts/miscellany.json +17 -0
  102. package/src/contexts.ts +39 -1
  103. package/src/digest.test.ts +220 -0
  104. package/src/digest.ts +229 -0
  105. package/src/docloader.test.ts +918 -27
  106. package/src/docloader.ts +320 -105
  107. package/src/internal/jsonld-cache.ts +97 -1
  108. package/src/internal/portable-dereference.test.ts +254 -0
  109. package/src/internal/portable-dereference.ts +1000 -0
  110. package/src/internal/signed-representation.ts +565 -0
  111. package/src/jsonld-cache.test.ts +89 -0
  112. package/src/key.test.ts +9 -0
  113. package/src/key.ts +11 -1
  114. package/src/mod.ts +28 -0
  115. package/src/multibase/multibase.test.ts +5 -5
  116. package/src/portable-media.test.ts +293 -0
  117. package/src/portable-media.ts +264 -0
  118. package/src/portable-workers.test.ts +81 -0
  119. package/src/portable.ts +180 -0
  120. package/src/preprocessor.ts +7 -0
  121. package/src/request.test.ts +10 -1
  122. package/src/request.ts +9 -1
  123. package/src/signed-representation.test.ts +338 -0
  124. package/src/url.test.ts +823 -3
  125. package/src/url.ts +700 -23
  126. package/tsdown.config.ts +2 -0
  127. package/dist/tests/url-CsOV_B_P.cjs +0 -482
  128. package/dist/tests/url-Du7RQQgP.mjs +0 -392
  129. package/dist/url-DD4F0ULf.cjs +0 -483
  130. package/dist/url-DGVbSVVi.js +0 -393
  131. /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
  132. /package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-C4Fl80ae.cjs} +0 -0
  133. /package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-CQ26J_L7.mjs} +0 -0
  134. /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
  135. /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
  136. /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
  137. /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
  138. /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
@@ -1,483 +0,0 @@
1
-
2
- require("./chunk-M78iaK0I.cjs");
3
- let node_dns_promises = require("node:dns/promises");
4
- let node_net = require("node:net");
5
- //#region src/url.ts
6
- var UrlError = class extends Error {
7
- constructor(message) {
8
- super(message);
9
- this.name = "UrlError";
10
- }
11
- };
12
- const PORTABLE_IRI_PATTERN = /^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
13
- const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/;
14
- const PERCENT_ENCODING_PATTERN = /%[0-9A-Fa-f]{2}/g;
15
- const DID_SCHEME_PATTERN = /^did:/i;
16
- const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i;
17
- /**
18
- * Parses a JSON-LD `@id` value as an IRI.
19
- */
20
- function parseJsonLdId(id, base) {
21
- if (id == null || id.startsWith("_:")) return void 0;
22
- try {
23
- return parseIri(id, base);
24
- } catch {
25
- throw new TypeError("Invalid @id: " + id);
26
- }
27
- }
28
- /**
29
- * Parses an IRI as a URL, including FEP-ef61 portable ActivityPub IRIs.
30
- */
31
- function parseIri(iri, base) {
32
- if (iri instanceof URL) return normalizePortableUrl(iri) ?? new URL(iri.href);
33
- const portable = parsePortableIri(iri);
34
- if (portable != null) return portable;
35
- base = normalizeBaseIri(base);
36
- if (!URL.canParse(iri, base) && iri.startsWith("at://")) return parseAtUri(iri);
37
- const parsed = new URL(iri, base);
38
- return normalizePortableUrl(parsed) ?? parsed;
39
- }
40
- /**
41
- * Formats a URL as an IRI, including FEP-ef61 portable ActivityPub IRIs.
42
- */
43
- function formatIri(iri) {
44
- const parsed = parsePortableIri(iri instanceof URL ? iri.href : iri);
45
- if (parsed == null) return iri instanceof URL ? iri.href : URL.canParse(iri) ? new URL(iri).href : iri;
46
- return `ap+ef61://${decodePortableAuthority(parsed.host)}${parsed.pathname}${parsed.search}${parsed.hash}`;
47
- }
48
- /**
49
- * Canonicalizes a FEP-ef61 portable ActivityPub URI for comparison.
50
- *
51
- * This accepts both `ap:` and `ap+ef61:` URI strings with decoded or
52
- * percent-encoded DID authorities. The returned value uses the `ap+ef61:`
53
- * scheme, a decoded DID authority, and no query component. Pass the raw URI
54
- * string, not a `URL` object, because JavaScript `URL` normalizes opaque path
55
- * segments before Fedify can compare them.
56
- *
57
- * @param input The raw portable ActivityPub URI string to canonicalize.
58
- * @returns The canonical portable ActivityPub URI string.
59
- * @throws {TypeError} If the input is not a valid portable ActivityPub IRI.
60
- * @since 2.4.0
61
- */
62
- function canonicalizePortableUri(input) {
63
- if (typeof input !== "string") throw new TypeError("Invalid portable ActivityPub IRI.");
64
- const parsed = parsePortableIri(input);
65
- if (parsed == null) throw new TypeError("Invalid portable ActivityPub IRI.");
66
- const match = input.match(PORTABLE_IRI_PATTERN);
67
- return `ap+ef61://${normalizePortableAuthority(getDidUrlOrigin(decodePortableAuthority(parsed.host)))}${normalizePortableComponent(match[3])}${match[5] == null ? "" : normalizePortableComponent(match[5])}`;
68
- }
69
- /**
70
- * Checks whether two FEP-ef61 portable ActivityPub URIs identify the same
71
- * portable object.
72
- *
73
- * Non-string inputs return `false`. Non-portable URI strings use strict string
74
- * equality. Portable URI strings are compared through
75
- * {@link canonicalizePortableUri}; malformed portable URI strings return
76
- * `false` unless they are exactly equal.
77
- *
78
- * @since 2.4.0
79
- */
80
- function arePortableUrisEqual(left, right) {
81
- if (typeof left !== "string" || typeof right !== "string") return false;
82
- if (left === right) return true;
83
- if (!PORTABLE_IRI_PATTERN.test(left) || !PORTABLE_IRI_PATTERN.test(right)) return false;
84
- try {
85
- return canonicalizePortableUri(left) === canonicalizePortableUri(right);
86
- } catch (error) {
87
- if (error instanceof TypeError) return false;
88
- throw error;
89
- }
90
- }
91
- /**
92
- * Computes an IRI's FEP-fe34 origin.
93
- *
94
- * HTTP(S) IRIs use their web origin. FEP-ef61 portable ActivityPub IRIs and
95
- * DID URLs use their DID as a cryptographic origin.
96
- *
97
- * @throws {TypeError} If the IRI does not have a supported FEP-fe34 origin.
98
- * @since 2.4.0
99
- */
100
- function getFe34Origin(input) {
101
- if (input instanceof URL) {
102
- const portable = normalizePortableUrl(input);
103
- if (portable != null) return getPortableCryptographicOrigin(portable);
104
- if (input.protocol === "did:") return getDidUrlOrigin(input.href);
105
- if (input.protocol === "http:" || input.protocol === "https:") return input.origin;
106
- throw new TypeError("Unsupported FEP-fe34 origin IRI.");
107
- }
108
- const portable = parsePortableIri(input);
109
- if (portable != null) return getPortableCryptographicOrigin(portable);
110
- if (DID_SCHEME_PATTERN.test(input)) return getDidUrlOrigin(input);
111
- const parsed = new URL(input);
112
- if (parsed.protocol === "http:" || parsed.protocol === "https:") return parsed.origin;
113
- throw new TypeError("Unsupported FEP-fe34 origin IRI.");
114
- }
115
- /**
116
- * Checks whether two IRIs have the same FEP-fe34 origin.
117
- *
118
- * Malformed or unsupported IRIs are treated as non-matching.
119
- *
120
- * @since 2.4.0
121
- */
122
- function haveSameFe34Origin(left, right) {
123
- try {
124
- return getFe34Origin(left) === getFe34Origin(right);
125
- } catch (error) {
126
- if (error instanceof TypeError) return false;
127
- throw error;
128
- }
129
- }
130
- /**
131
- * Checks whether two IRIs have the same origin.
132
- */
133
- function haveSameIriOrigin(left, right) {
134
- return getComparableIriOrigin(left) === getComparableIriOrigin(right);
135
- }
136
- function getComparableIriOrigin(iri) {
137
- iri = normalizePortableUrl(iri) ?? iri;
138
- if (iri.origin !== "null") return iri.origin;
139
- if (iri.host !== "") {
140
- const host = iri.protocol === "ap+ef61:" ? encodeURIComponent(getDidUrlOrigin(decodePortableAuthority(iri.host))) : iri.host;
141
- return `${iri.protocol}//${host}`;
142
- }
143
- return iri.href;
144
- }
145
- function getPortableCryptographicOrigin(iri) {
146
- return getDidUrlOrigin(decodePortableAuthority(iri.host));
147
- }
148
- function getDidUrlOrigin(iri) {
149
- const did = iri.split(/[/?#]/, 1)[0].replace(DID_SCHEME_PATTERN, "did:");
150
- if (!DID_PATTERN.test(did)) throw new TypeError("Invalid DID URL.");
151
- const parts = did.split(":");
152
- parts[1] = parts[1].toLowerCase();
153
- return normalizePortableAuthority(parts.join(":"));
154
- }
155
- function parsePortableIri(iri) {
156
- const match = iri.match(PORTABLE_IRI_PATTERN);
157
- if (match == null) return null;
158
- const authority = getDidUrlOrigin(decodePortableAuthority(match[2]));
159
- if (!DID_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
160
- if (match[3] === "") throw new TypeError("Invalid portable ActivityPub IRI path.");
161
- return new URL(`ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${match[5] ?? ""}`);
162
- }
163
- function normalizePortableUrl(iri) {
164
- if (iri.protocol !== "ap:" && iri.protocol !== "ap+ef61:") return null;
165
- return parsePortableIri(`ap+ef61://${iri.host}${iri.pathname}${iri.search}${iri.hash}`);
166
- }
167
- function normalizeBaseIri(base) {
168
- if (base == null) return void 0;
169
- if (base instanceof URL) return normalizePortableUrl(base) ?? base;
170
- return parsePortableIri(base) ?? (base.startsWith("at://") && !URL.canParse(".", base) ? parseAtUri(base) : base);
171
- }
172
- function decodePortableAuthority(authority) {
173
- if (INVALID_PERCENT_ENCODING_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
174
- if (DID_SCHEME_PATTERN.test(authority)) {
175
- const decoded = authority.replace(/%25/gi, "%");
176
- if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
177
- return decoded;
178
- }
179
- const decoded = authority.replace(/%(25|3A)/gi, (match) => match.toLowerCase() === "%3a" ? ":" : "%");
180
- if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
181
- return decoded;
182
- }
183
- function normalizePercentEncoding(value) {
184
- return value.replace(PERCENT_ENCODING_PATTERN, (match) => match.toUpperCase());
185
- }
186
- function normalizePortableAuthority(authority) {
187
- return normalizePercentEncoding(authority).replace(PERCENT_ENCODING_PATTERN, (match) => {
188
- const decoded = String.fromCharCode(Number.parseInt(match.slice(1), 16));
189
- return /[A-Za-z0-9._~-]/.test(decoded) ? decoded : match;
190
- });
191
- }
192
- function normalizePortableComponent(value) {
193
- if (INVALID_PERCENT_ENCODING_PATTERN.test(value)) throw new TypeError("Invalid portable ActivityPub IRI component.");
194
- return value.replace(/%[0-9A-Fa-f]{2}|[^%]+/g, (match) => {
195
- if (match.startsWith("%")) {
196
- const upper = match.toUpperCase();
197
- const decoded = String.fromCharCode(Number.parseInt(upper.slice(1), 16));
198
- return /[A-Za-z0-9._~-]/.test(decoded) ? decoded : upper;
199
- }
200
- try {
201
- return encodeURI(match);
202
- } catch (error) {
203
- if (error instanceof URIError) throw new TypeError("Invalid portable ActivityPub IRI component.");
204
- throw error;
205
- }
206
- });
207
- }
208
- function parseAtUri(uri) {
209
- const index = uri.indexOf("/", 5);
210
- const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5);
211
- const path = index >= 0 ? uri.slice(index) : "";
212
- return new URL("at://" + encodeURIComponent(authority) + path);
213
- }
214
- /**
215
- * Checks whether the URL is an FEP-ef61 gateway base URI.
216
- */
217
- function isGatewayUrl(url) {
218
- return (url.protocol === "http:" || url.protocol === "https:") && url.username === "" && url.password === "" && url.pathname === "/" && url.search === "" && url.hash === "";
219
- }
220
- /**
221
- * Parses and validates an FEP-ef61 gateway base URI.
222
- */
223
- function parseGatewayUrl(url) {
224
- const parsed = parseIri(url);
225
- if (!isGatewayUrl(parsed)) throw new TypeError("FEP-ef61 gateways must be HTTP(S) base URIs with no credentials, path, query, or fragment.");
226
- return parsed;
227
- }
228
- /**
229
- * Validates a URL to prevent SSRF attacks.
230
- */
231
- async function validatePublicUrl(url) {
232
- const parsed = new URL(url);
233
- if (parsed.protocol !== "http:" && parsed.protocol !== "https:") throw new UrlError(`Unsupported protocol: ${parsed.protocol}`);
234
- let hostname = parsed.hostname;
235
- if (hostname.startsWith("[") && hostname.endsWith("]")) hostname = hostname.slice(1, -1);
236
- if (hostname === "localhost") throw new UrlError("Localhost is not allowed");
237
- const hostnameFamily = (0, node_net.isIP)(hostname);
238
- if (hostnameFamily !== 0) {
239
- validatePublicIpAddress(hostname, hostnameFamily);
240
- return;
241
- }
242
- if ("Deno" in globalThis && !(0, node_net.isIP)(hostname)) {
243
- if ((await Deno.permissions.query({ name: "net" })).state !== "granted") return;
244
- }
245
- if ("Bun" in globalThis) {
246
- if (hostname === "example.com" || hostname.endsWith(".example.com")) return;
247
- else if (hostname === "fedify-test.internal") throw new UrlError("Invalid or private address: fedify-test.internal");
248
- }
249
- let addresses;
250
- try {
251
- addresses = await (0, node_dns_promises.lookup)(hostname, { all: true });
252
- } catch {
253
- addresses = [];
254
- }
255
- for (const { address, family } of addresses) validatePublicIpAddress(address, family);
256
- }
257
- function validatePublicIpAddress(address, family) {
258
- if (family === 4 && isValidPublicIPv4Address(address) || family === 6 && isValidPublicIPv6Address(address)) return;
259
- throw new UrlError(`Invalid or private address: ${address}`);
260
- }
261
- function isValidPublicIPv4Address(address) {
262
- const parts = parseIPv4Address(address);
263
- if (parts == null) return false;
264
- const value = ipv4PartsToNumber(parts);
265
- return !nonPublicIPv4Prefixes.some(({ base, prefix }) => matchesIPv4Prefix(value, base, prefix));
266
- }
267
- function isValidPublicIPv6Address(address) {
268
- const words = parseIPv6Address(address);
269
- if (words == null) return false;
270
- if (nonPublicIPv6Prefixes.some(({ words: prefixWords, prefix }) => matchesIPv6Prefix(words, prefixWords, prefix))) return false;
271
- for (const { extractIPv4, prefix, words: prefixWords } of ipv6WithIPv4Prefixes) {
272
- if (!matchesIPv6Prefix(words, prefixWords, prefix)) continue;
273
- const ipv4Address = extractIPv4(words);
274
- if (ipv4Address != null && !isValidPublicIPv4Address(ipv4Address)) return false;
275
- }
276
- return true;
277
- }
278
- function expandIPv6Address(address) {
279
- address = address.toLowerCase();
280
- const ipv4Delimiter = address.lastIndexOf(":");
281
- if (address.includes(".") && ipv4Delimiter >= 0) {
282
- const ipv4Parts = parseIPv4Address(address.substring(ipv4Delimiter + 1));
283
- if (ipv4Parts == null) return address;
284
- const high = (ipv4Parts[0] << 8) + ipv4Parts[1];
285
- const low = (ipv4Parts[2] << 8) + ipv4Parts[3];
286
- address = address.substring(0, ipv4Delimiter + 1) + high.toString(16) + ":" + low.toString(16);
287
- }
288
- if (address === "::") return "0000:0000:0000:0000:0000:0000:0000:0000";
289
- if (address.startsWith("::")) address = "0000" + address;
290
- if (address.endsWith("::")) address = address + "0000";
291
- address = address.replace("::", ":0000".repeat(8 - (address.match(/:/g) || []).length) + ":");
292
- return address.split(":").map((part) => part.padStart(4, "0")).join(":");
293
- }
294
- const nonPublicIPv4Prefixes = [
295
- ipv4Prefix("0.0.0.0/8", "RFC 6890"),
296
- ipv4Prefix("10.0.0.0/8", "RFC 1918"),
297
- ipv4Prefix("100.64.0.0/10", "RFC 6598"),
298
- ipv4Prefix("127.0.0.0/8", "RFC 1122"),
299
- ipv4Prefix("169.254.0.0/16", "RFC 3927"),
300
- ipv4Prefix("172.16.0.0/12", "RFC 1918"),
301
- ipv4Prefix("192.0.0.0/24", "RFC 6890"),
302
- ipv4Prefix("192.0.2.0/24", "RFC 5737"),
303
- ipv4Prefix("192.88.99.0/24", "RFC 7526"),
304
- ipv4Prefix("192.168.0.0/16", "RFC 1918"),
305
- ipv4Prefix("198.18.0.0/15", "RFC 2544"),
306
- ipv4Prefix("198.51.100.0/24", "RFC 5737"),
307
- ipv4Prefix("203.0.113.0/24", "RFC 5737"),
308
- ipv4Prefix("224.0.0.0/4", "RFC 5771"),
309
- ipv4Prefix("240.0.0.0/4", "RFC 1112")
310
- ];
311
- const nonPublicIPv6Prefixes = [
312
- ipv6Prefix("::/16", "RFC 4291"),
313
- ipv6Prefix("2001::/32", "RFC 4380"),
314
- ipv6Prefix("2002::/16", "RFC 3056"),
315
- ipv6Prefix("64:ff9b:1::/48", "RFC 8215"),
316
- ipv6Prefix("fc00::/7", "RFC 4193"),
317
- ipv6Prefix("fe80::/10", "RFC 4291"),
318
- ipv6Prefix("ff00::/8", "RFC 4291")
319
- ];
320
- const ipv6WithIPv4Prefixes = [{
321
- ...ipv6Prefix("64:ff9b::/96", "RFC 6052"),
322
- extractIPv4: (words) => ipv4FromWords(words[6], words[7])
323
- }];
324
- function ipv4Prefix(cidr, rfc) {
325
- const [address, prefixText] = cidr.split("/");
326
- const prefix = parseInt(prefixText, 10);
327
- const parts = parseIPv4Address(address);
328
- if (parts == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 32) throw new Error(`Invalid IPv4 prefix: ${cidr}`);
329
- return {
330
- cidr,
331
- base: ipv4PartsToNumber(parts),
332
- prefix,
333
- rfc
334
- };
335
- }
336
- function ipv6Prefix(cidr, rfc) {
337
- const [address, prefixText] = cidr.split("/");
338
- const prefix = parseInt(prefixText, 10);
339
- const words = parseIPv6Address(address);
340
- if (words == null || !Number.isInteger(prefix) || prefix < 0 || prefix > 128) throw new Error(`Invalid IPv6 prefix: ${cidr}`);
341
- return {
342
- cidr,
343
- words,
344
- prefix,
345
- rfc
346
- };
347
- }
348
- function parseIPv4Address(address) {
349
- const parts = address.split(".").map((part) => {
350
- if (!/^\d+$/.test(part)) return NaN;
351
- return parseInt(part, 10);
352
- });
353
- if (parts.length !== 4 || parts.some((part) => !Number.isInteger(part) || part < 0 || part > 255)) return null;
354
- return parts;
355
- }
356
- function parseIPv6Address(address) {
357
- const parts = expandIPv6Address(address).split(":");
358
- if (parts.length !== 8) return null;
359
- const words = parts.map((part) => {
360
- if (!/^[0-9a-f]{1,4}$/i.test(part)) return NaN;
361
- return parseInt(part, 16);
362
- });
363
- if (words.some((word) => !Number.isInteger(word) || word < 0 || word > 65535)) return null;
364
- return words;
365
- }
366
- function ipv4PartsToNumber(parts) {
367
- return parts[0] * 2 ** 24 + parts[1] * 2 ** 16 + parts[2] * 2 ** 8 + parts[3];
368
- }
369
- function ipv4FromWords(highWord, lowWord) {
370
- return [
371
- highWord >> 8,
372
- highWord & 255,
373
- lowWord >> 8,
374
- lowWord & 255
375
- ].join(".");
376
- }
377
- function matchesIPv4Prefix(address, prefixBase, prefixLength) {
378
- const blockSize = 2 ** (32 - prefixLength);
379
- return Math.floor(address / blockSize) === Math.floor(prefixBase / blockSize);
380
- }
381
- function matchesIPv6Prefix(address, prefixWords, prefixLength) {
382
- let remaining = prefixLength;
383
- for (let i = 0; i < 8 && remaining > 0; i++) if (remaining >= 16) {
384
- if (address[i] !== prefixWords[i]) return false;
385
- remaining -= 16;
386
- } else {
387
- const mask = 65535 << 16 - remaining & 65535;
388
- if ((address[i] & mask) !== (prefixWords[i] & mask)) return false;
389
- remaining = 0;
390
- }
391
- return true;
392
- }
393
- //#endregion
394
- Object.defineProperty(exports, "UrlError", {
395
- enumerable: true,
396
- get: function() {
397
- return UrlError;
398
- }
399
- });
400
- Object.defineProperty(exports, "arePortableUrisEqual", {
401
- enumerable: true,
402
- get: function() {
403
- return arePortableUrisEqual;
404
- }
405
- });
406
- Object.defineProperty(exports, "canonicalizePortableUri", {
407
- enumerable: true,
408
- get: function() {
409
- return canonicalizePortableUri;
410
- }
411
- });
412
- Object.defineProperty(exports, "expandIPv6Address", {
413
- enumerable: true,
414
- get: function() {
415
- return expandIPv6Address;
416
- }
417
- });
418
- Object.defineProperty(exports, "formatIri", {
419
- enumerable: true,
420
- get: function() {
421
- return formatIri;
422
- }
423
- });
424
- Object.defineProperty(exports, "getFe34Origin", {
425
- enumerable: true,
426
- get: function() {
427
- return getFe34Origin;
428
- }
429
- });
430
- Object.defineProperty(exports, "haveSameFe34Origin", {
431
- enumerable: true,
432
- get: function() {
433
- return haveSameFe34Origin;
434
- }
435
- });
436
- Object.defineProperty(exports, "haveSameIriOrigin", {
437
- enumerable: true,
438
- get: function() {
439
- return haveSameIriOrigin;
440
- }
441
- });
442
- Object.defineProperty(exports, "isGatewayUrl", {
443
- enumerable: true,
444
- get: function() {
445
- return isGatewayUrl;
446
- }
447
- });
448
- Object.defineProperty(exports, "isValidPublicIPv4Address", {
449
- enumerable: true,
450
- get: function() {
451
- return isValidPublicIPv4Address;
452
- }
453
- });
454
- Object.defineProperty(exports, "isValidPublicIPv6Address", {
455
- enumerable: true,
456
- get: function() {
457
- return isValidPublicIPv6Address;
458
- }
459
- });
460
- Object.defineProperty(exports, "parseGatewayUrl", {
461
- enumerable: true,
462
- get: function() {
463
- return parseGatewayUrl;
464
- }
465
- });
466
- Object.defineProperty(exports, "parseIri", {
467
- enumerable: true,
468
- get: function() {
469
- return parseIri;
470
- }
471
- });
472
- Object.defineProperty(exports, "parseJsonLdId", {
473
- enumerable: true,
474
- get: function() {
475
- return parseJsonLdId;
476
- }
477
- });
478
- Object.defineProperty(exports, "validatePublicUrl", {
479
- enumerable: true,
480
- get: function() {
481
- return validatePublicUrl;
482
- }
483
- });