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