@fedify/vocab-runtime 2.4.0-dev.1583 → 2.4.0-dev.1618
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 +1 -1
- package/dist/internal/jsonld-cache.cjs +2 -2
- package/dist/internal/jsonld-cache.js +2 -2
- package/dist/mod.cjs +6 -2
- package/dist/mod.d.cts +46 -1
- package/dist/mod.d.ts +46 -1
- package/dist/mod.js +3 -3
- package/dist/tests/decimal.test.cjs +2 -2
- package/dist/tests/decimal.test.mjs +2 -2
- package/dist/tests/{docloader-z8KkbO2O.mjs → docloader-CBVde8Va.mjs} +2 -2
- package/dist/tests/{docloader-CSsDIyQU.cjs → docloader-QmR6VOqT.cjs} +2 -2
- package/dist/tests/docloader.test.cjs +3 -3
- package/dist/tests/docloader.test.mjs +3 -3
- package/dist/tests/jsonld-cache.test.cjs +2 -2
- package/dist/tests/jsonld-cache.test.mjs +2 -2
- package/dist/tests/{request-CLZQgTNJ.mjs → request-BHx0fCb5.mjs} +1 -1
- package/dist/tests/{request-DpegHvk6.cjs → request-DxSceLvB.cjs} +1 -1
- package/dist/tests/request.test.cjs +1 -1
- package/dist/tests/request.test.mjs +1 -1
- package/dist/tests/{url-2XwVbUS_.cjs → url-BvjYQdxL.cjs} +144 -2
- package/dist/tests/{url-YWJbnRlf.mjs → url-a2D8NAgh.mjs} +121 -3
- package/dist/tests/url.test.cjs +125 -3
- package/dist/tests/url.test.mjs +125 -3
- package/dist/{url-BAdyyqAa.cjs → url-Ck3dGEwH.cjs} +144 -2
- package/dist/{url-BuxPHxK2.js → url-m1YxGNZ0.js} +121 -3
- package/package.json +1 -1
- package/src/internal/jsonld-cache.ts +3 -2
- package/src/mod.ts +4 -0
- package/src/url.test.ts +381 -2
- package/src/url.ts +175 -2
|
@@ -9,6 +9,7 @@ var UrlError = class extends Error {
|
|
|
9
9
|
};
|
|
10
10
|
const PORTABLE_IRI_PATTERN = /^(ap|ap\+ef61):\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i;
|
|
11
11
|
const INVALID_PERCENT_ENCODING_PATTERN = /%(?![0-9A-Fa-f]{2})/;
|
|
12
|
+
const PERCENT_ENCODING_PATTERN = /%[0-9A-Fa-f]{2}/g;
|
|
12
13
|
const DID_SCHEME_PATTERN = /^did:/i;
|
|
13
14
|
const DID_PATTERN = /^did:[a-z0-9]+:[-A-Za-z0-9._%]+(?::[-A-Za-z0-9._%]+)*$/i;
|
|
14
15
|
/**
|
|
@@ -43,6 +44,88 @@ function formatIri(iri) {
|
|
|
43
44
|
return `ap+ef61://${decodePortableAuthority(parsed.host)}${parsed.pathname}${parsed.search}${parsed.hash}`;
|
|
44
45
|
}
|
|
45
46
|
/**
|
|
47
|
+
* Canonicalizes a FEP-ef61 portable ActivityPub URI for comparison.
|
|
48
|
+
*
|
|
49
|
+
* This accepts both `ap:` and `ap+ef61:` URI strings with decoded or
|
|
50
|
+
* percent-encoded DID authorities. The returned value uses the `ap+ef61:`
|
|
51
|
+
* scheme, a decoded DID authority, and no query component. Pass the raw URI
|
|
52
|
+
* string, not a `URL` object, because JavaScript `URL` normalizes opaque path
|
|
53
|
+
* segments before Fedify can compare them.
|
|
54
|
+
*
|
|
55
|
+
* @param input The raw portable ActivityPub URI string to canonicalize.
|
|
56
|
+
* @returns The canonical portable ActivityPub URI string.
|
|
57
|
+
* @throws {TypeError} If the input is not a valid portable ActivityPub IRI.
|
|
58
|
+
* @since 2.4.0
|
|
59
|
+
*/
|
|
60
|
+
function canonicalizePortableUri(input) {
|
|
61
|
+
if (typeof input !== "string") throw new TypeError("Invalid portable ActivityPub IRI.");
|
|
62
|
+
const parsed = parsePortableIri(input);
|
|
63
|
+
if (parsed == null) throw new TypeError("Invalid portable ActivityPub IRI.");
|
|
64
|
+
const match = input.match(PORTABLE_IRI_PATTERN);
|
|
65
|
+
return `ap+ef61://${normalizePortableAuthority(getDidUrlOrigin(decodePortableAuthority(parsed.host)))}${normalizePortableComponent(match[3])}${match[5] == null ? "" : normalizePortableComponent(match[5])}`;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Checks whether two FEP-ef61 portable ActivityPub URIs identify the same
|
|
69
|
+
* portable object.
|
|
70
|
+
*
|
|
71
|
+
* Non-string inputs return `false`. Non-portable URI strings use strict string
|
|
72
|
+
* equality. Portable URI strings are compared through
|
|
73
|
+
* {@link canonicalizePortableUri}; malformed portable URI strings return
|
|
74
|
+
* `false` unless they are exactly equal.
|
|
75
|
+
*
|
|
76
|
+
* @since 2.4.0
|
|
77
|
+
*/
|
|
78
|
+
function arePortableUrisEqual(left, right) {
|
|
79
|
+
if (typeof left !== "string" || typeof right !== "string") return false;
|
|
80
|
+
if (left === right) return true;
|
|
81
|
+
if (!PORTABLE_IRI_PATTERN.test(left) || !PORTABLE_IRI_PATTERN.test(right)) return false;
|
|
82
|
+
try {
|
|
83
|
+
return canonicalizePortableUri(left) === canonicalizePortableUri(right);
|
|
84
|
+
} catch (error) {
|
|
85
|
+
if (error instanceof TypeError) return false;
|
|
86
|
+
throw error;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Computes an IRI's FEP-fe34 origin.
|
|
91
|
+
*
|
|
92
|
+
* HTTP(S) IRIs use their web origin. FEP-ef61 portable ActivityPub IRIs and
|
|
93
|
+
* DID URLs use their DID as a cryptographic origin.
|
|
94
|
+
*
|
|
95
|
+
* @throws {TypeError} If the IRI does not have a supported FEP-fe34 origin.
|
|
96
|
+
* @since 2.4.0
|
|
97
|
+
*/
|
|
98
|
+
function getFe34Origin(input) {
|
|
99
|
+
if (input instanceof URL) {
|
|
100
|
+
const portable = normalizePortableUrl(input);
|
|
101
|
+
if (portable != null) return getPortableCryptographicOrigin(portable);
|
|
102
|
+
if (input.protocol === "did:") return getDidUrlOrigin(input.href);
|
|
103
|
+
if (input.protocol === "http:" || input.protocol === "https:") return input.origin;
|
|
104
|
+
throw new TypeError("Unsupported FEP-fe34 origin IRI.");
|
|
105
|
+
}
|
|
106
|
+
const portable = parsePortableIri(input);
|
|
107
|
+
if (portable != null) return getPortableCryptographicOrigin(portable);
|
|
108
|
+
if (DID_SCHEME_PATTERN.test(input)) return getDidUrlOrigin(input);
|
|
109
|
+
const parsed = new URL(input);
|
|
110
|
+
if (parsed.protocol === "http:" || parsed.protocol === "https:") return parsed.origin;
|
|
111
|
+
throw new TypeError("Unsupported FEP-fe34 origin IRI.");
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Checks whether two IRIs have the same FEP-fe34 origin.
|
|
115
|
+
*
|
|
116
|
+
* Malformed or unsupported IRIs are treated as non-matching.
|
|
117
|
+
*
|
|
118
|
+
* @since 2.4.0
|
|
119
|
+
*/
|
|
120
|
+
function haveSameFe34Origin(left, right) {
|
|
121
|
+
try {
|
|
122
|
+
return getFe34Origin(left) === getFe34Origin(right);
|
|
123
|
+
} catch (error) {
|
|
124
|
+
if (error instanceof TypeError) return false;
|
|
125
|
+
throw error;
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
46
129
|
* Checks whether two IRIs have the same origin.
|
|
47
130
|
*/
|
|
48
131
|
function haveSameIriOrigin(left, right) {
|
|
@@ -52,15 +135,25 @@ function getComparableIriOrigin(iri) {
|
|
|
52
135
|
iri = normalizePortableUrl(iri) ?? iri;
|
|
53
136
|
if (iri.origin !== "null") return iri.origin;
|
|
54
137
|
if (iri.host !== "") {
|
|
55
|
-
const host = iri.protocol === "ap+ef61:" ? encodeURIComponent(decodePortableAuthority(iri.host)
|
|
138
|
+
const host = iri.protocol === "ap+ef61:" ? encodeURIComponent(getDidUrlOrigin(decodePortableAuthority(iri.host))) : iri.host;
|
|
56
139
|
return `${iri.protocol}//${host}`;
|
|
57
140
|
}
|
|
58
141
|
return iri.href;
|
|
59
142
|
}
|
|
143
|
+
function getPortableCryptographicOrigin(iri) {
|
|
144
|
+
return getDidUrlOrigin(decodePortableAuthority(iri.host));
|
|
145
|
+
}
|
|
146
|
+
function getDidUrlOrigin(iri) {
|
|
147
|
+
const did = iri.split(/[/?#]/, 1)[0].replace(DID_SCHEME_PATTERN, "did:");
|
|
148
|
+
if (!DID_PATTERN.test(did)) throw new TypeError("Invalid DID URL.");
|
|
149
|
+
const parts = did.split(":");
|
|
150
|
+
parts[1] = parts[1].toLowerCase();
|
|
151
|
+
return normalizePortableAuthority(parts.join(":"));
|
|
152
|
+
}
|
|
60
153
|
function parsePortableIri(iri) {
|
|
61
154
|
const match = iri.match(PORTABLE_IRI_PATTERN);
|
|
62
155
|
if (match == null) return null;
|
|
63
|
-
const authority = decodePortableAuthority(match[2]);
|
|
156
|
+
const authority = getDidUrlOrigin(decodePortableAuthority(match[2]));
|
|
64
157
|
if (!DID_PATTERN.test(authority)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
|
|
65
158
|
if (match[3] === "") throw new TypeError("Invalid portable ActivityPub IRI path.");
|
|
66
159
|
return new URL(`ap+ef61://${encodeURIComponent(authority)}${match[3]}${match[4] ?? ""}${match[5] ?? ""}`);
|
|
@@ -85,6 +178,31 @@ function decodePortableAuthority(authority) {
|
|
|
85
178
|
if (INVALID_PERCENT_ENCODING_PATTERN.test(decoded)) throw new TypeError("Invalid portable ActivityPub IRI authority.");
|
|
86
179
|
return decoded;
|
|
87
180
|
}
|
|
181
|
+
function normalizePercentEncoding(value) {
|
|
182
|
+
return value.replace(PERCENT_ENCODING_PATTERN, (match) => match.toUpperCase());
|
|
183
|
+
}
|
|
184
|
+
function normalizePortableAuthority(authority) {
|
|
185
|
+
return normalizePercentEncoding(authority).replace(PERCENT_ENCODING_PATTERN, (match) => {
|
|
186
|
+
const decoded = String.fromCharCode(Number.parseInt(match.slice(1), 16));
|
|
187
|
+
return /[A-Za-z0-9._~-]/.test(decoded) ? decoded : match;
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
function normalizePortableComponent(value) {
|
|
191
|
+
if (INVALID_PERCENT_ENCODING_PATTERN.test(value)) throw new TypeError("Invalid portable ActivityPub IRI component.");
|
|
192
|
+
return value.replace(/%[0-9A-Fa-f]{2}|[^%]+/g, (match) => {
|
|
193
|
+
if (match.startsWith("%")) {
|
|
194
|
+
const upper = match.toUpperCase();
|
|
195
|
+
const decoded = String.fromCharCode(Number.parseInt(upper.slice(1), 16));
|
|
196
|
+
return /[A-Za-z0-9._~-]/.test(decoded) ? decoded : upper;
|
|
197
|
+
}
|
|
198
|
+
try {
|
|
199
|
+
return encodeURI(match);
|
|
200
|
+
} catch (error) {
|
|
201
|
+
if (error instanceof URIError) throw new TypeError("Invalid portable ActivityPub IRI component.");
|
|
202
|
+
throw error;
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
88
206
|
function parseAtUri(uri) {
|
|
89
207
|
const index = uri.indexOf("/", 5);
|
|
90
208
|
const authority = index >= 0 ? uri.slice(5, index) : uri.slice(5);
|
|
@@ -257,4 +375,4 @@ function matchesIPv6Prefix(address, prefixWords, prefixLength) {
|
|
|
257
375
|
return true;
|
|
258
376
|
}
|
|
259
377
|
//#endregion
|
|
260
|
-
export {
|
|
378
|
+
export { formatIri as a, haveSameIriOrigin as c, parseIri as d, parseJsonLdId as f, expandIPv6Address as i, isValidPublicIPv4Address as l, arePortableUrisEqual as n, getFe34Origin as o, validatePublicUrl as p, canonicalizePortableUri as r, haveSameFe34Origin as s, UrlError as t, isValidPublicIPv6Address as u };
|
package/dist/tests/url.test.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
require("./chunk-C2EiDwsr.cjs");
|
|
2
|
-
const require_url = require("./url-
|
|
2
|
+
const require_url = require("./url-BvjYQdxL.cjs");
|
|
3
3
|
let node_assert = require("node:assert");
|
|
4
4
|
let node_test = require("node:test");
|
|
5
5
|
//#region src/url.test.ts
|
|
@@ -12,8 +12,12 @@ let node_test = require("node:test");
|
|
|
12
12
|
"AP+EF61://did:key:z6Mkabc/actor"
|
|
13
13
|
]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
|
|
14
14
|
});
|
|
15
|
-
(0, node_test.test)("parseIri()
|
|
16
|
-
for (const iri of [
|
|
15
|
+
(0, node_test.test)("parseIri() normalizes DID scheme and method casing", () => {
|
|
16
|
+
for (const iri of [
|
|
17
|
+
"ap://DID:key:z6Mkabc/actor",
|
|
18
|
+
"ap://DID%3Akey%3Az6Mkabc/actor",
|
|
19
|
+
"ap://did:KEY:z6Mkabc/actor"
|
|
20
|
+
]) (0, node_assert.deepStrictEqual)(require_url.parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
|
|
17
21
|
});
|
|
18
22
|
(0, node_test.test)("parseIri() accepts DID method names that start with digits", () => {
|
|
19
23
|
(0, node_assert.deepStrictEqual)(require_url.parseIri("ap://did:3:abc/actor"), new URL("ap+ef61://did%3A3%3Aabc/actor"));
|
|
@@ -60,12 +64,50 @@ let node_test = require("node:test");
|
|
|
60
64
|
]) (0, node_assert.throws)(() => require_url.parseIri(iri), TypeError);
|
|
61
65
|
});
|
|
62
66
|
(0, node_test.test)("haveSameIriOrigin() compares portable IRI authorities", () => {
|
|
67
|
+
(0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ftp://example.com/pub/1"), new URL("ftp://example.com/pub/2")));
|
|
68
|
+
(0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("mailto:alice@example.com"), new URL("mailto:alice@example.com")));
|
|
63
69
|
(0, node_assert.ok)(require_url.haveSameIriOrigin(require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkabc/outbox")));
|
|
64
70
|
(0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
|
|
65
71
|
(0, node_assert.ok)(require_url.haveSameIriOrigin(require_url.parseIri("ap://DID:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkabc/outbox")));
|
|
66
72
|
(0, node_assert.ok)(require_url.haveSameIriOrigin(new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
|
|
67
73
|
(0, node_assert.ok)(!require_url.haveSameIriOrigin(require_url.parseIri("ap://did:key:z6Mkabc/actor"), require_url.parseIri("ap://did:key:z6Mkdef/actor")));
|
|
68
74
|
});
|
|
75
|
+
(0, node_test.test)("getFe34Origin() computes web and cryptographic origins", () => {
|
|
76
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("https://Example.COM:443/users/alice"), "https://example.com");
|
|
77
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin(new URL("http://example.com:8080/notes/1")), "http://example.com:8080");
|
|
78
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("ap://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fa.example"), "did:key:z6Mkabc");
|
|
79
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("ap+ef61://did%3Akey%3Az6Mkabc/objects/1#fragment"), "did:key:z6Mkabc");
|
|
80
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin(new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")), "did:key:z6Mkabc");
|
|
81
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("did:key:z6Mkabc#z6Mkabc"), "did:key:z6Mkabc");
|
|
82
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin(new URL("did:key:z6Mkabc?service=activitypub#key")), "did:key:z6Mkabc");
|
|
83
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("did:key:z6Mkabc/path/to/resource?service=activitypub#key"), "did:key:z6Mkabc");
|
|
84
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("did:KEY:z6Mkabc#z6Mkabc"), "did:key:z6Mkabc");
|
|
85
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("ap://did%3Aweb%3Afoo%2Dbar.example/actor"), "did:web:foo-bar.example");
|
|
86
|
+
(0, node_assert.deepStrictEqual)(require_url.getFe34Origin("did:web:foo%2dbar.example#key"), "did:web:foo-bar.example");
|
|
87
|
+
});
|
|
88
|
+
(0, node_test.test)("getFe34Origin() rejects unsupported or malformed identifiers", () => {
|
|
89
|
+
for (const iri of [
|
|
90
|
+
"mailto:alice@example.com",
|
|
91
|
+
"ap://not-a-did/actor",
|
|
92
|
+
"ap://did:key/actor",
|
|
93
|
+
"did:key",
|
|
94
|
+
"did:key:",
|
|
95
|
+
"did:"
|
|
96
|
+
]) (0, node_assert.throws)(() => require_url.getFe34Origin(iri), TypeError);
|
|
97
|
+
});
|
|
98
|
+
(0, node_test.test)("haveSameFe34Origin() compares web and cryptographic origins", () => {
|
|
99
|
+
(0, node_assert.ok)(require_url.haveSameFe34Origin("https://example.com/users/alice", "https://example.com/notes/1"));
|
|
100
|
+
(0, node_assert.ok)(!require_url.haveSameFe34Origin("https://example.com/users/alice", "http://example.com/users/alice"));
|
|
101
|
+
(0, node_assert.ok)(!require_url.haveSameFe34Origin("https://example.com/users/alice", "https://example.com:8443/users/alice"));
|
|
102
|
+
(0, node_assert.ok)(require_url.haveSameFe34Origin("ap://did:key:z6Mkabc/actor", "ap+ef61://did%3Akey%3Az6Mkabc/objects/1"));
|
|
103
|
+
(0, node_assert.ok)(require_url.haveSameFe34Origin("ap+ef61://did:key:z6Mkabc/actor", "did:key:z6Mkabc#z6Mkabc"));
|
|
104
|
+
(0, node_assert.ok)(require_url.haveSameFe34Origin("ap://did:KEY:z6Mkabc/actor", "did:key:z6Mkabc#z6Mkabc"));
|
|
105
|
+
(0, node_assert.ok)(require_url.haveSameFe34Origin("ap://did%3Aweb%3Afoo%2Dbar.example/actor", "ap://did:web:foo-bar.example/note"));
|
|
106
|
+
(0, node_assert.ok)(require_url.haveSameFe34Origin("ap://did%3Aexample%3Aabc%252fdef/actor", "did:example:abc%2Fdef#key"));
|
|
107
|
+
(0, node_assert.ok)(!require_url.haveSameFe34Origin("ap+ef61://did:key:z6Mkabc/actor", "did:key:z6Mkdef#z6Mkdef"));
|
|
108
|
+
(0, node_assert.ok)(!require_url.haveSameFe34Origin("ap+ef61://did:key:z6Mkabc/actor", "https://example.com/actor"));
|
|
109
|
+
(0, node_assert.ok)(!require_url.haveSameFe34Origin("ap://not-a-did/actor", "ap://not-a-did/actor"));
|
|
110
|
+
});
|
|
69
111
|
(0, node_test.test)("parseIri() normalizes portable URL instances", () => {
|
|
70
112
|
(0, node_assert.deepStrictEqual)(require_url.parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
|
|
71
113
|
(0, node_assert.throws)(() => require_url.parseIri("ap+ef61://not-a-did/actor"), TypeError);
|
|
@@ -76,6 +118,86 @@ let node_test = require("node:test");
|
|
|
76
118
|
(0, node_assert.deepStrictEqual)(require_url.formatIri(new URL("https://example.com/actor")), "https://example.com/actor");
|
|
77
119
|
(0, node_assert.deepStrictEqual)(require_url.formatIri("/actor"), "/actor");
|
|
78
120
|
});
|
|
121
|
+
(0, node_test.test)("canonicalizePortableUri() emits comparison forms", () => {
|
|
122
|
+
for (const iri of [
|
|
123
|
+
"ap://did:key:z6Mkabc/actor",
|
|
124
|
+
"ap://did%3Akey%3Az6Mkabc/actor",
|
|
125
|
+
"ap://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fa.example",
|
|
126
|
+
"ap+ef61://did:key:z6Mkabc/actor",
|
|
127
|
+
"ap+ef61://did%3Akey%3Az6Mkabc/actor?gateways=https%3A%2F%2Fa.example"
|
|
128
|
+
]) (0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri(iri), "ap+ef61://did:key:z6Mkabc/actor");
|
|
129
|
+
});
|
|
130
|
+
(0, node_test.test)("canonicalizePortableUri() preserves paths and fragments", () => {
|
|
131
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/objects/1/attachments/2?gateways=https%3A%2F%2Fa.example#image"), "ap+ef61://did:key:z6Mkabc/objects/1/attachments/2#image");
|
|
132
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/objects/1#reply"), "ap+ef61://did:key:z6Mkabc/objects/1#reply");
|
|
133
|
+
});
|
|
134
|
+
(0, node_test.test)("canonicalizePortableUri() preserves DID-internal pct-encoded characters", () => {
|
|
135
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:example:abc%2Fdef/actor?x=1"), "ap+ef61://did:example:abc%2Fdef/actor");
|
|
136
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did%3Aweb%3Aexample.com%253A3000/u/1"), "ap+ef61://did:web:example.com%3A3000/u/1");
|
|
137
|
+
});
|
|
138
|
+
(0, node_test.test)("canonicalizePortableUri() normalizes authority pct-encoding casing", () => {
|
|
139
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:example:abc%2fdef/actor"), "ap+ef61://did:example:abc%2Fdef/actor");
|
|
140
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:example:abc%2fdef%3abar/actor"), "ap+ef61://did:example:abc%2Fdef%3Abar/actor");
|
|
141
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did%3Aexample%3Aabc%252fdef/actor"), "ap+ef61://did:example:abc%2Fdef/actor");
|
|
142
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did%3Akey%3Az6Mk%2Dabc/actor"), "ap+ef61://did:key:z6Mk-abc/actor");
|
|
143
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://did:example:abc%2fdef/actor", "ap://did:example:abc%2Fdef/actor"));
|
|
144
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://did%3Akey%3Az6Mk%2Dabc/actor", "ap://did:key:z6Mk-abc/actor"));
|
|
145
|
+
});
|
|
146
|
+
(0, node_test.test)("canonicalizePortableUri() normalizes path and fragment pct-encoding casing", () => {
|
|
147
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/actor%2fprofile#part%2ftwo"), "ap+ef61://did:key:z6Mkabc/actor%2Fprofile#part%2Ftwo");
|
|
148
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/actor%2fprofile%3aimage"), "ap+ef61://did:key:z6Mkabc/actor%2Fprofile%3Aimage");
|
|
149
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/actor%2Dprofile#part%7Etwo"), "ap+ef61://did:key:z6Mkabc/actor-profile#part~two");
|
|
150
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor%2fprofile#part%2ftwo", "ap://did:key:z6Mkabc/actor%2Fprofile#part%2Ftwo"));
|
|
151
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor%2Dprofile#part%7Etwo", "ap://did:key:z6Mkabc/actor-profile#part~two"));
|
|
152
|
+
});
|
|
153
|
+
(0, node_test.test)("canonicalizePortableUri() encodes raw path and fragment characters", () => {
|
|
154
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/é#é"), "ap+ef61://did:key:z6Mkabc/%C3%A9#%C3%A9");
|
|
155
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/é#é", "ap://did:key:z6Mkabc/%C3%A9#%C3%A9"));
|
|
156
|
+
});
|
|
157
|
+
(0, node_test.test)("canonicalizePortableUri() normalizes DID scheme casing", () => {
|
|
158
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://DID:key:z6Mkabc/actor"), "ap+ef61://did:key:z6Mkabc/actor");
|
|
159
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://DID%3Akey%3Az6Mkabc/actor"), "ap+ef61://did:key:z6Mkabc/actor");
|
|
160
|
+
});
|
|
161
|
+
(0, node_test.test)("canonicalizePortableUri() preserves opaque path segments", () => {
|
|
162
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/a/../b?gateways=x"), "ap+ef61://did:key:z6Mkabc/a/../b");
|
|
163
|
+
(0, node_assert.deepStrictEqual)(require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/a/%2e%2e/b"), "ap+ef61://did:key:z6Mkabc/a/../b");
|
|
164
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/a/../b", "ap://did:key:z6Mkabc/b"));
|
|
165
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/a/%2e%2e/b", "ap://did:key:z6Mkabc/b"));
|
|
166
|
+
});
|
|
167
|
+
(0, node_test.test)("canonicalizePortableUri() rejects non-portable URIs", () => {
|
|
168
|
+
for (const iri of [
|
|
169
|
+
"https://example.com/actor",
|
|
170
|
+
"at://did:plc:example/record",
|
|
171
|
+
"/actor",
|
|
172
|
+
"ap://not-a-did/actor",
|
|
173
|
+
"ap://did:key:z6Mkabc"
|
|
174
|
+
]) (0, node_assert.throws)(() => require_url.canonicalizePortableUri(iri), TypeError);
|
|
175
|
+
(0, node_assert.throws)(() => require_url.canonicalizePortableUri(new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")), TypeError);
|
|
176
|
+
});
|
|
177
|
+
(0, node_test.test)("canonicalizePortableUri() rejects invalid path and fragment pct-encoding", () => {
|
|
178
|
+
(0, node_assert.throws)(() => require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/a%zz"), TypeError);
|
|
179
|
+
(0, node_assert.throws)(() => require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/actor#part%zz"), TypeError);
|
|
180
|
+
(0, node_assert.throws)(() => require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/\ud800"), TypeError);
|
|
181
|
+
(0, node_assert.throws)(() => require_url.canonicalizePortableUri("ap://did:key:z6Mkabc/actor#\ud800"), TypeError);
|
|
182
|
+
});
|
|
183
|
+
(0, node_test.test)("arePortableUrisEqual() compares canonical portable URI forms", () => {
|
|
184
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "ap+ef61://did%3Akey%3Az6Mkabc/actor?gateways=https%3A%2F%2Fa.example"));
|
|
185
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://DID:key:z6Mkabc/actor", "ap://did:key:z6Mkabc/actor"));
|
|
186
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "ap://did:key:z6Mkdef/actor"));
|
|
187
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "ap://did:key:z6Mkabc/outbox"));
|
|
188
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor#one", "ap://did:key:z6Mkabc/actor#two"));
|
|
189
|
+
});
|
|
190
|
+
(0, node_test.test)("arePortableUrisEqual() handles non-portable URI strings", () => {
|
|
191
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("https://example.com/actor", "https://example.com/actor"));
|
|
192
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("https://example.com/actor", "https://example.com/outbox"));
|
|
193
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "https://example.com/actor"));
|
|
194
|
+
(0, node_assert.ok)(require_url.arePortableUrisEqual("ap://not-a-did/actor", "ap://not-a-did/actor"));
|
|
195
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://not-a-did/actor", "ap://not-a-did/outbox"));
|
|
196
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://not-a-did/actor", "ap://did:key:z6Mkabc/actor"));
|
|
197
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/a%zz", "ap://did:key:z6Mkabc/a%25zz"));
|
|
198
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/\ud800", "ap://did:key:z6Mkabc/%EF%BF%BD"));
|
|
199
|
+
(0, node_assert.ok)(!require_url.arePortableUrisEqual("ap://did:key:z6Mkabc/actor#\ud800", "ap://did:key:z6Mkabc/actor#%EF%BF%BD"));
|
|
200
|
+
});
|
|
79
201
|
(0, node_test.test)("formatIri() preserves DID authority pct-encoded delimiters", () => {
|
|
80
202
|
const parsed = require_url.parseIri("ap://did:example:abc%2Fdef/actor");
|
|
81
203
|
(0, node_assert.deepStrictEqual)(parsed, new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
|
package/dist/tests/url.test.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as
|
|
1
|
+
import { a as formatIri, c as haveSameIriOrigin, d as parseIri, f as parseJsonLdId, i as expandIPv6Address, l as isValidPublicIPv4Address, n as arePortableUrisEqual, o as getFe34Origin, p as validatePublicUrl, r as canonicalizePortableUri, s as haveSameFe34Origin, t as UrlError, u as isValidPublicIPv6Address } from "./url-a2D8NAgh.mjs";
|
|
2
2
|
import { deepStrictEqual, ok, rejects, throws } from "node:assert";
|
|
3
3
|
import { test } from "node:test";
|
|
4
4
|
//#region src/url.test.ts
|
|
@@ -11,8 +11,12 @@ test("parseIri() accepts portable ActivityPub URI schemes", () => {
|
|
|
11
11
|
"AP+EF61://did:key:z6Mkabc/actor"
|
|
12
12
|
]) deepStrictEqual(parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
|
|
13
13
|
});
|
|
14
|
-
test("parseIri()
|
|
15
|
-
for (const iri of [
|
|
14
|
+
test("parseIri() normalizes DID scheme and method casing", () => {
|
|
15
|
+
for (const iri of [
|
|
16
|
+
"ap://DID:key:z6Mkabc/actor",
|
|
17
|
+
"ap://DID%3Akey%3Az6Mkabc/actor",
|
|
18
|
+
"ap://did:KEY:z6Mkabc/actor"
|
|
19
|
+
]) deepStrictEqual(parseIri(iri), new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor"));
|
|
16
20
|
});
|
|
17
21
|
test("parseIri() accepts DID method names that start with digits", () => {
|
|
18
22
|
deepStrictEqual(parseIri("ap://did:3:abc/actor"), new URL("ap+ef61://did%3A3%3Aabc/actor"));
|
|
@@ -59,12 +63,50 @@ test("parseIri() rejects malformed portable DID authorities", () => {
|
|
|
59
63
|
]) throws(() => parseIri(iri), TypeError);
|
|
60
64
|
});
|
|
61
65
|
test("haveSameIriOrigin() compares portable IRI authorities", () => {
|
|
66
|
+
ok(haveSameIriOrigin(new URL("ftp://example.com/pub/1"), new URL("ftp://example.com/pub/2")));
|
|
67
|
+
ok(haveSameIriOrigin(new URL("mailto:alice@example.com"), new URL("mailto:alice@example.com")));
|
|
62
68
|
ok(haveSameIriOrigin(parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkabc/outbox")));
|
|
63
69
|
ok(haveSameIriOrigin(new URL("ap://did%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
|
|
64
70
|
ok(haveSameIriOrigin(parseIri("ap://DID:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkabc/outbox")));
|
|
65
71
|
ok(haveSameIriOrigin(new URL("ap+ef61://DID%3Akey%3Az6Mkabc/actor"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/outbox")));
|
|
66
72
|
ok(!haveSameIriOrigin(parseIri("ap://did:key:z6Mkabc/actor"), parseIri("ap://did:key:z6Mkdef/actor")));
|
|
67
73
|
});
|
|
74
|
+
test("getFe34Origin() computes web and cryptographic origins", () => {
|
|
75
|
+
deepStrictEqual(getFe34Origin("https://Example.COM:443/users/alice"), "https://example.com");
|
|
76
|
+
deepStrictEqual(getFe34Origin(new URL("http://example.com:8080/notes/1")), "http://example.com:8080");
|
|
77
|
+
deepStrictEqual(getFe34Origin("ap://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fa.example"), "did:key:z6Mkabc");
|
|
78
|
+
deepStrictEqual(getFe34Origin("ap+ef61://did%3Akey%3Az6Mkabc/objects/1#fragment"), "did:key:z6Mkabc");
|
|
79
|
+
deepStrictEqual(getFe34Origin(new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")), "did:key:z6Mkabc");
|
|
80
|
+
deepStrictEqual(getFe34Origin("did:key:z6Mkabc#z6Mkabc"), "did:key:z6Mkabc");
|
|
81
|
+
deepStrictEqual(getFe34Origin(new URL("did:key:z6Mkabc?service=activitypub#key")), "did:key:z6Mkabc");
|
|
82
|
+
deepStrictEqual(getFe34Origin("did:key:z6Mkabc/path/to/resource?service=activitypub#key"), "did:key:z6Mkabc");
|
|
83
|
+
deepStrictEqual(getFe34Origin("did:KEY:z6Mkabc#z6Mkabc"), "did:key:z6Mkabc");
|
|
84
|
+
deepStrictEqual(getFe34Origin("ap://did%3Aweb%3Afoo%2Dbar.example/actor"), "did:web:foo-bar.example");
|
|
85
|
+
deepStrictEqual(getFe34Origin("did:web:foo%2dbar.example#key"), "did:web:foo-bar.example");
|
|
86
|
+
});
|
|
87
|
+
test("getFe34Origin() rejects unsupported or malformed identifiers", () => {
|
|
88
|
+
for (const iri of [
|
|
89
|
+
"mailto:alice@example.com",
|
|
90
|
+
"ap://not-a-did/actor",
|
|
91
|
+
"ap://did:key/actor",
|
|
92
|
+
"did:key",
|
|
93
|
+
"did:key:",
|
|
94
|
+
"did:"
|
|
95
|
+
]) throws(() => getFe34Origin(iri), TypeError);
|
|
96
|
+
});
|
|
97
|
+
test("haveSameFe34Origin() compares web and cryptographic origins", () => {
|
|
98
|
+
ok(haveSameFe34Origin("https://example.com/users/alice", "https://example.com/notes/1"));
|
|
99
|
+
ok(!haveSameFe34Origin("https://example.com/users/alice", "http://example.com/users/alice"));
|
|
100
|
+
ok(!haveSameFe34Origin("https://example.com/users/alice", "https://example.com:8443/users/alice"));
|
|
101
|
+
ok(haveSameFe34Origin("ap://did:key:z6Mkabc/actor", "ap+ef61://did%3Akey%3Az6Mkabc/objects/1"));
|
|
102
|
+
ok(haveSameFe34Origin("ap+ef61://did:key:z6Mkabc/actor", "did:key:z6Mkabc#z6Mkabc"));
|
|
103
|
+
ok(haveSameFe34Origin("ap://did:KEY:z6Mkabc/actor", "did:key:z6Mkabc#z6Mkabc"));
|
|
104
|
+
ok(haveSameFe34Origin("ap://did%3Aweb%3Afoo%2Dbar.example/actor", "ap://did:web:foo-bar.example/note"));
|
|
105
|
+
ok(haveSameFe34Origin("ap://did%3Aexample%3Aabc%252fdef/actor", "did:example:abc%2Fdef#key"));
|
|
106
|
+
ok(!haveSameFe34Origin("ap+ef61://did:key:z6Mkabc/actor", "did:key:z6Mkdef#z6Mkdef"));
|
|
107
|
+
ok(!haveSameFe34Origin("ap+ef61://did:key:z6Mkabc/actor", "https://example.com/actor"));
|
|
108
|
+
ok(!haveSameFe34Origin("ap://not-a-did/actor", "ap://not-a-did/actor"));
|
|
109
|
+
});
|
|
68
110
|
test("parseIri() normalizes portable URL instances", () => {
|
|
69
111
|
deepStrictEqual(parseIri(new URL("ap+ef61://did%3Aexample%3Aabc%2Fdef/actor")), new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
|
|
70
112
|
throws(() => parseIri("ap+ef61://not-a-did/actor"), TypeError);
|
|
@@ -75,6 +117,86 @@ test("formatIri() emits canonical portable ActivityPub URI syntax", () => {
|
|
|
75
117
|
deepStrictEqual(formatIri(new URL("https://example.com/actor")), "https://example.com/actor");
|
|
76
118
|
deepStrictEqual(formatIri("/actor"), "/actor");
|
|
77
119
|
});
|
|
120
|
+
test("canonicalizePortableUri() emits comparison forms", () => {
|
|
121
|
+
for (const iri of [
|
|
122
|
+
"ap://did:key:z6Mkabc/actor",
|
|
123
|
+
"ap://did%3Akey%3Az6Mkabc/actor",
|
|
124
|
+
"ap://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fa.example",
|
|
125
|
+
"ap+ef61://did:key:z6Mkabc/actor",
|
|
126
|
+
"ap+ef61://did%3Akey%3Az6Mkabc/actor?gateways=https%3A%2F%2Fa.example"
|
|
127
|
+
]) deepStrictEqual(canonicalizePortableUri(iri), "ap+ef61://did:key:z6Mkabc/actor");
|
|
128
|
+
});
|
|
129
|
+
test("canonicalizePortableUri() preserves paths and fragments", () => {
|
|
130
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/objects/1/attachments/2?gateways=https%3A%2F%2Fa.example#image"), "ap+ef61://did:key:z6Mkabc/objects/1/attachments/2#image");
|
|
131
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/objects/1#reply"), "ap+ef61://did:key:z6Mkabc/objects/1#reply");
|
|
132
|
+
});
|
|
133
|
+
test("canonicalizePortableUri() preserves DID-internal pct-encoded characters", () => {
|
|
134
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:example:abc%2Fdef/actor?x=1"), "ap+ef61://did:example:abc%2Fdef/actor");
|
|
135
|
+
deepStrictEqual(canonicalizePortableUri("ap://did%3Aweb%3Aexample.com%253A3000/u/1"), "ap+ef61://did:web:example.com%3A3000/u/1");
|
|
136
|
+
});
|
|
137
|
+
test("canonicalizePortableUri() normalizes authority pct-encoding casing", () => {
|
|
138
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:example:abc%2fdef/actor"), "ap+ef61://did:example:abc%2Fdef/actor");
|
|
139
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:example:abc%2fdef%3abar/actor"), "ap+ef61://did:example:abc%2Fdef%3Abar/actor");
|
|
140
|
+
deepStrictEqual(canonicalizePortableUri("ap://did%3Aexample%3Aabc%252fdef/actor"), "ap+ef61://did:example:abc%2Fdef/actor");
|
|
141
|
+
deepStrictEqual(canonicalizePortableUri("ap://did%3Akey%3Az6Mk%2Dabc/actor"), "ap+ef61://did:key:z6Mk-abc/actor");
|
|
142
|
+
ok(arePortableUrisEqual("ap://did:example:abc%2fdef/actor", "ap://did:example:abc%2Fdef/actor"));
|
|
143
|
+
ok(arePortableUrisEqual("ap://did%3Akey%3Az6Mk%2Dabc/actor", "ap://did:key:z6Mk-abc/actor"));
|
|
144
|
+
});
|
|
145
|
+
test("canonicalizePortableUri() normalizes path and fragment pct-encoding casing", () => {
|
|
146
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/actor%2fprofile#part%2ftwo"), "ap+ef61://did:key:z6Mkabc/actor%2Fprofile#part%2Ftwo");
|
|
147
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/actor%2fprofile%3aimage"), "ap+ef61://did:key:z6Mkabc/actor%2Fprofile%3Aimage");
|
|
148
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/actor%2Dprofile#part%7Etwo"), "ap+ef61://did:key:z6Mkabc/actor-profile#part~two");
|
|
149
|
+
ok(arePortableUrisEqual("ap://did:key:z6Mkabc/actor%2fprofile#part%2ftwo", "ap://did:key:z6Mkabc/actor%2Fprofile#part%2Ftwo"));
|
|
150
|
+
ok(arePortableUrisEqual("ap://did:key:z6Mkabc/actor%2Dprofile#part%7Etwo", "ap://did:key:z6Mkabc/actor-profile#part~two"));
|
|
151
|
+
});
|
|
152
|
+
test("canonicalizePortableUri() encodes raw path and fragment characters", () => {
|
|
153
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/é#é"), "ap+ef61://did:key:z6Mkabc/%C3%A9#%C3%A9");
|
|
154
|
+
ok(arePortableUrisEqual("ap://did:key:z6Mkabc/é#é", "ap://did:key:z6Mkabc/%C3%A9#%C3%A9"));
|
|
155
|
+
});
|
|
156
|
+
test("canonicalizePortableUri() normalizes DID scheme casing", () => {
|
|
157
|
+
deepStrictEqual(canonicalizePortableUri("ap://DID:key:z6Mkabc/actor"), "ap+ef61://did:key:z6Mkabc/actor");
|
|
158
|
+
deepStrictEqual(canonicalizePortableUri("ap://DID%3Akey%3Az6Mkabc/actor"), "ap+ef61://did:key:z6Mkabc/actor");
|
|
159
|
+
});
|
|
160
|
+
test("canonicalizePortableUri() preserves opaque path segments", () => {
|
|
161
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/a/../b?gateways=x"), "ap+ef61://did:key:z6Mkabc/a/../b");
|
|
162
|
+
deepStrictEqual(canonicalizePortableUri("ap://did:key:z6Mkabc/a/%2e%2e/b"), "ap+ef61://did:key:z6Mkabc/a/../b");
|
|
163
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/a/../b", "ap://did:key:z6Mkabc/b"));
|
|
164
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/a/%2e%2e/b", "ap://did:key:z6Mkabc/b"));
|
|
165
|
+
});
|
|
166
|
+
test("canonicalizePortableUri() rejects non-portable URIs", () => {
|
|
167
|
+
for (const iri of [
|
|
168
|
+
"https://example.com/actor",
|
|
169
|
+
"at://did:plc:example/record",
|
|
170
|
+
"/actor",
|
|
171
|
+
"ap://not-a-did/actor",
|
|
172
|
+
"ap://did:key:z6Mkabc"
|
|
173
|
+
]) throws(() => canonicalizePortableUri(iri), TypeError);
|
|
174
|
+
throws(() => canonicalizePortableUri(new URL("ap+ef61://did%3Akey%3Az6Mkabc/actor")), TypeError);
|
|
175
|
+
});
|
|
176
|
+
test("canonicalizePortableUri() rejects invalid path and fragment pct-encoding", () => {
|
|
177
|
+
throws(() => canonicalizePortableUri("ap://did:key:z6Mkabc/a%zz"), TypeError);
|
|
178
|
+
throws(() => canonicalizePortableUri("ap://did:key:z6Mkabc/actor#part%zz"), TypeError);
|
|
179
|
+
throws(() => canonicalizePortableUri("ap://did:key:z6Mkabc/\ud800"), TypeError);
|
|
180
|
+
throws(() => canonicalizePortableUri("ap://did:key:z6Mkabc/actor#\ud800"), TypeError);
|
|
181
|
+
});
|
|
182
|
+
test("arePortableUrisEqual() compares canonical portable URI forms", () => {
|
|
183
|
+
ok(arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "ap+ef61://did%3Akey%3Az6Mkabc/actor?gateways=https%3A%2F%2Fa.example"));
|
|
184
|
+
ok(arePortableUrisEqual("ap://DID:key:z6Mkabc/actor", "ap://did:key:z6Mkabc/actor"));
|
|
185
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "ap://did:key:z6Mkdef/actor"));
|
|
186
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "ap://did:key:z6Mkabc/outbox"));
|
|
187
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/actor#one", "ap://did:key:z6Mkabc/actor#two"));
|
|
188
|
+
});
|
|
189
|
+
test("arePortableUrisEqual() handles non-portable URI strings", () => {
|
|
190
|
+
ok(arePortableUrisEqual("https://example.com/actor", "https://example.com/actor"));
|
|
191
|
+
ok(!arePortableUrisEqual("https://example.com/actor", "https://example.com/outbox"));
|
|
192
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/actor", "https://example.com/actor"));
|
|
193
|
+
ok(arePortableUrisEqual("ap://not-a-did/actor", "ap://not-a-did/actor"));
|
|
194
|
+
ok(!arePortableUrisEqual("ap://not-a-did/actor", "ap://not-a-did/outbox"));
|
|
195
|
+
ok(!arePortableUrisEqual("ap://not-a-did/actor", "ap://did:key:z6Mkabc/actor"));
|
|
196
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/a%zz", "ap://did:key:z6Mkabc/a%25zz"));
|
|
197
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/\ud800", "ap://did:key:z6Mkabc/%EF%BF%BD"));
|
|
198
|
+
ok(!arePortableUrisEqual("ap://did:key:z6Mkabc/actor#\ud800", "ap://did:key:z6Mkabc/actor#%EF%BF%BD"));
|
|
199
|
+
});
|
|
78
200
|
test("formatIri() preserves DID authority pct-encoded delimiters", () => {
|
|
79
201
|
const parsed = parseIri("ap://did:example:abc%2Fdef/actor");
|
|
80
202
|
deepStrictEqual(parsed, new URL("ap+ef61://did%3Aexample%3Aabc%252Fdef/actor"));
|