@fedify/vocab-runtime 2.4.0-pr.934.40 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (140) hide show
  1. package/deno.json +4 -2
  2. package/dist/{tests/docloader-Xi61Le8w.mjs → contexts-BK1CqBR5.cjs} +164 -269
  3. package/dist/{tests/docloader-BFedvemb.cjs → contexts-DPuJ4UYL.js} +160 -288
  4. package/dist/{docloader-DnUMWHaJ.d.cts → docloader-CYwqh5Df.d.cts} +68 -2
  5. package/dist/{docloader-xRGn1azD.d.ts → docloader-CYwqh5Df.d.ts} +68 -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 +715 -4523
  20. package/dist/mod.d.cts +406 -6
  21. package/dist/mod.d.ts +406 -7
  22. package/dist/mod.js +694 -4518
  23. package/dist/portable-DqtfLy_1.d.cts +160 -0
  24. package/dist/portable-DtWsu2yU.d.ts +160 -0
  25. package/dist/tests/body-CYiu9CO-.mjs +130 -0
  26. package/dist/tests/body-CkEwROsn.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-C3YFl6y4.cjs +396 -0
  42. package/dist/tests/docloader-CvmS4sVq.mjs +373 -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-BLKllU56.cjs +153 -0
  70. package/dist/tests/portable-media-DRSGBORB.mjs +148 -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-cCPgOxYG.cjs → request-8vPWtV1-.cjs} +10 -4
  80. package/dist/tests/{request-BOS-hNaf.mjs → request-DRaOaTqD.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 +503 -3
  92. package/dist/tests/url.test.mjs +503 -2
  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/fep-ef61.json +10 -0
  102. package/src/contexts/miscellany.json +17 -0
  103. package/src/contexts/security-data-integrity-v1.json +0 -4
  104. package/src/contexts.ts +40 -0
  105. package/src/digest.test.ts +220 -0
  106. package/src/digest.ts +229 -0
  107. package/src/docloader.test.ts +918 -27
  108. package/src/docloader.ts +322 -105
  109. package/src/internal/jsonld-cache.ts +97 -1
  110. package/src/internal/portable-dereference.test.ts +254 -0
  111. package/src/internal/portable-dereference.ts +1000 -0
  112. package/src/internal/signed-representation.ts +565 -0
  113. package/src/jsonld-cache.test.ts +89 -0
  114. package/src/key.test.ts +9 -0
  115. package/src/key.ts +11 -1
  116. package/src/mod.ts +30 -0
  117. package/src/multibase/multibase.test.ts +5 -5
  118. package/src/portable-media.test.ts +293 -0
  119. package/src/portable-media.ts +264 -0
  120. package/src/portable-workers.test.ts +81 -0
  121. package/src/portable.ts +180 -0
  122. package/src/preprocessor.ts +7 -0
  123. package/src/request.test.ts +10 -1
  124. package/src/request.ts +9 -1
  125. package/src/signed-representation.test.ts +338 -0
  126. package/src/url.test.ts +844 -1
  127. package/src/url.ts +717 -17
  128. package/tsdown.config.ts +2 -0
  129. package/dist/tests/url-BvjYQdxL.cjs +0 -456
  130. package/dist/tests/url-a2D8NAgh.mjs +0 -378
  131. package/dist/url-Ck3dGEwH.cjs +0 -457
  132. package/dist/url-m1YxGNZ0.js +0 -379
  133. /package/dist/{chunk-M78iaK0I.cjs → rolldown-runtime-B7lfambq.cjs} +0 -0
  134. /package/dist/tests/{langstr-CbAxaeEZ.cjs → langstr-C4Fl80ae.cjs} +0 -0
  135. /package/dist/tests/{langstr-Di5AvKpB.mjs → langstr-CQ26J_L7.mjs} +0 -0
  136. /package/dist/tests/{link-NUUWCdnK.mjs → link-Cevmc87v.mjs} +0 -0
  137. /package/dist/tests/{link-FguCydMA.cjs → link-DlKm8bEr.cjs} +0 -0
  138. /package/dist/tests/{multicodec-CxGVGa91.cjs → multicodec-CLRPeW4N.cjs} +0 -0
  139. /package/dist/tests/{multicodec-CyFp54fI.mjs → multicodec-CRIj_05H.mjs} +0 -0
  140. /package/dist/tests/{chunk-C2EiDwsr.cjs → rolldown-runtime-emK7D4bc.cjs} +0 -0
@@ -1,6 +1,6 @@
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
- import { deepStrictEqual, ok, rejects, throws } from "node:assert";
1
+ import { C as withoutGatewayHints, S as withGatewayHints, _ as parseIri, a as expandIPv6Address, b as validateLookupAddresses, c as getFe34Origin, d as haveSameIriOrigin, f as isGatewayUrl, g as parseGatewayUrl, i as canonicalizePortableUri, l as getGatewayHints, m as isValidPublicIPv6Address, n as UrlError, o as formatIri, p as isValidPublicIPv4Address, r as arePortableUrisEqual, s as fromCompatibleEf61Id, u as haveSameFe34Origin, v as parseJsonLdId, x as validatePublicUrl, y as toCompatibleEf61Id } from "./url-DMxmp7ZG.mjs";
3
2
  import { test } from "node:test";
3
+ import { deepStrictEqual, ok, rejects, strictEqual, throws } from "node:assert";
4
4
  //#region src/url.test.ts
5
5
  test("parseIri() accepts portable ActivityPub URI schemes", () => {
6
6
  for (const iri of [
@@ -11,6 +11,39 @@ 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("portable URI parsing refuses dot segments before URL normalization", () => {
15
+ const base = "ap://did:key:z6Mkabc";
16
+ for (const segment of [
17
+ ".",
18
+ "..",
19
+ "%2e",
20
+ ".%2E",
21
+ "%2e.",
22
+ "%2E%2e"
23
+ ]) for (const path of [
24
+ `/${segment}`,
25
+ `/a/${segment}/b`,
26
+ `/a/${segment}`
27
+ ]) {
28
+ const iri = base + path;
29
+ throws(() => parseIri(iri), TypeError, iri);
30
+ throws(() => parseJsonLdId(iri), TypeError, iri);
31
+ throws(() => formatIri(iri), TypeError, iri);
32
+ }
33
+ for (const iri of [
34
+ `${base}/a/.\t./b`,
35
+ `${base}/a/..\n/b`,
36
+ ` ${base}/a/../b`,
37
+ `${base}/a/.. `
38
+ ]) throws(() => parseIri(iri), TypeError, iri);
39
+ for (const path of [
40
+ "/a/.../b",
41
+ "/a/.x/b",
42
+ "/a/x.y/b",
43
+ "/a/%252e/b"
44
+ ]) deepStrictEqual(formatIri(parseIri(base + path)), `ap+ef61://did:key:z6Mkabc${path}`);
45
+ throws(() => parseIri("child", `${base}/a/../b`), TypeError);
46
+ });
14
47
  test("parseIri() normalizes DID scheme and method casing", () => {
15
48
  for (const iri of [
16
49
  "ap://DID:key:z6Mkabc/actor",
@@ -44,6 +77,20 @@ test("parseIri() resolves relative IRIs against portable string bases", () => {
44
77
  deepStrictEqual(parseIri("attachments/1", "ap://did:key:z6Mkabc/objects/1"), new URL("ap+ef61://did%3Akey%3Az6Mkabc/objects/attachments/1"));
45
78
  throws(() => parseIri("//example.com/outbox", "ap://did:key:z6Mkabc/objects/1"), TypeError);
46
79
  });
80
+ test("parseIri() rejects lossy compatible ID string bases", () => {
81
+ const base = "https://server.example/.well-known/apgateway/did:key:z6MkAlice";
82
+ for (const segment of [
83
+ ".",
84
+ "..",
85
+ "%2e",
86
+ "%2e%2e"
87
+ ]) {
88
+ const rawBase = `${base}/a/${segment}/b`;
89
+ throws(() => parseIri("child", rawBase), TypeError, rawBase);
90
+ throws(() => parseJsonLdId("child", rawBase), TypeError, rawBase);
91
+ }
92
+ deepStrictEqual(parseIri("child", "https://server.example/a/../b"), new URL("https://server.example/child"));
93
+ });
47
94
  test("parseIri() resolves relative IRIs against at:// string bases", () => {
48
95
  deepStrictEqual(parseIri("/record", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/record"));
49
96
  deepStrictEqual(parseIri("reply", "at://did:plc:example/collection/item"), new URL("at://did%3Aplc%3Aexample/collection/reply"));
@@ -227,6 +274,303 @@ test("parseIri() preserves encoded percent signs while decoding delimiters", ()
227
274
  deepStrictEqual(parsed, new URL("ap+ef61://did%3Aweb%3Aexample.com%2500/u/1"));
228
275
  deepStrictEqual(formatIri(parsed), "ap+ef61://did:web:example.com%00/u/1");
229
276
  });
277
+ test("parseGatewayUrl() accepts only HTTP(S) base URIs", () => {
278
+ for (const url of [
279
+ "https://server.example",
280
+ "https://server.example/",
281
+ "http://server.example/"
282
+ ]) {
283
+ deepStrictEqual(parseGatewayUrl(url), new URL(url));
284
+ ok(isGatewayUrl(new URL(url)));
285
+ }
286
+ for (const url of [
287
+ "ftp://server.example/",
288
+ "https://user:pass@server.example/",
289
+ "https://user@server.example/",
290
+ "https://server.example/path",
291
+ "https://server.example/?x=1",
292
+ "https://server.example/?",
293
+ "https://server.example/#fragment",
294
+ "https://server.example/#"
295
+ ]) {
296
+ throws(() => parseGatewayUrl(url), (error) => error instanceof TypeError && error.message.startsWith("Invalid FEP-ef61 gateway: "));
297
+ ok(!isGatewayUrl(new URL(url)));
298
+ }
299
+ const mutated = new URL("https://server.example/");
300
+ mutated.search = "?";
301
+ ok(!isGatewayUrl(mutated));
302
+ mutated.search = "";
303
+ mutated.hash = "#";
304
+ ok(!isGatewayUrl(mutated));
305
+ });
306
+ test("fromCompatibleEf61Id() converts compatible identifiers", () => {
307
+ for (const [input, expected] of [
308
+ ["https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1", "ap+ef61://did%3Akey%3Az6MkAlice/objects/1"],
309
+ ["http://server.example:8080/.well-known/apgateway/did:key:z6MkAlice/actor", "ap+ef61://did%3Akey%3Az6MkAlice/actor"],
310
+ ["https://server.example/.well-known/apgateway/did%3Akey%3Az6MkAlice/actor", "ap+ef61://did%3Akey%3Az6MkAlice/actor"],
311
+ ["https://server.example/.well-known/apgateway/DID:key:z6MkAlice/actor", "ap+ef61://did%3Akey%3Az6MkAlice/actor"],
312
+ ["https://server.example/.well-known/apgateway/did:key:z6MkAlice/a/b/c", "ap+ef61://did%3Akey%3Az6MkAlice/a/b/c"],
313
+ ["https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#main-key", "ap+ef61://did%3Akey%3Az6MkAlice/actor#main-key"],
314
+ ["https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#", "ap+ef61://did%3Akey%3Az6MkAlice/actor#"],
315
+ ["https://server.example/.well-known/apgateway/did:key:z6MkAlice/outbox?page=2", "ap+ef61://did%3Akey%3Az6MkAlice/outbox?page=2"],
316
+ ["https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%2Fb", "ap+ef61://did%3Akey%3Az6MkAlice/a%2Fb"],
317
+ ["https://server.example/.well-known/apgateway/did:web:example.com%3A8080/actor", "ap+ef61://did%3Aweb%3Aexample.com%253A8080/actor"],
318
+ ["https://server.example/.well-known/apgateway/did:example:a%2525/x", "ap+ef61://did%3Aexample%3Aa%2525/x"]
319
+ ]) {
320
+ deepStrictEqual(fromCompatibleEf61Id(input)?.href, expected, input);
321
+ deepStrictEqual(fromCompatibleEf61Id(new URL(input))?.href, expected, input);
322
+ }
323
+ const converted = fromCompatibleEf61Id("https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1");
324
+ deepStrictEqual(formatIri(converted), "ap+ef61://did:key:z6MkAlice/objects/1");
325
+ deepStrictEqual(canonicalizePortableUri(converted.href), "ap+ef61://did:key:z6MkAlice/objects/1");
326
+ ok(arePortableUrisEqual(fromCompatibleEf61Id("https://a.example/.well-known/apgateway/did:key:z6MkAlice/actor").href, fromCompatibleEf61Id("https://b.example/.well-known/apgateway/did:key:z6MkAlice/actor").href));
327
+ });
328
+ test("fromCompatibleEf61Id() returns null for other URLs", () => {
329
+ for (const input of [
330
+ "https://server.example/users/alice",
331
+ "https://server.example/.well-known/webfinger?resource=acct:a@b",
332
+ "https://server.example/.well-known/apgateway",
333
+ "https://server.example/.well-known/apgateway/",
334
+ "https://server.example/.well-known/apgateway/hl:zQmdfTbBqBPQ7VNxZEYEj14VmRuZBkqFbiwReogJgS1zR1n",
335
+ "https://server.example/.well-known/apgateway/objects/did:key:z6MkAlice/x",
336
+ "https://server.example/.well-known/apgatewayx/did:key:z6MkAlice/x",
337
+ "https://server.example/ap/did:key:z6MkAlice/actor",
338
+ "https://server.example/?id=/.well-known/apgateway/did:key:z6MkAlice/x",
339
+ "ap://did:key:z6MkAlice/actor",
340
+ "ap+ef61://did:key:z6MkAlice/actor",
341
+ "ftp://server.example/.well-known/apgateway/did:key:z6MkAlice/actor",
342
+ "not a URL",
343
+ "/.well-known/apgateway/did:key:z6MkAlice/actor"
344
+ ]) deepStrictEqual(fromCompatibleEf61Id(input), null, input);
345
+ deepStrictEqual(fromCompatibleEf61Id(new URL("ap+ef61://did%3Akey%3Az6MkAlice/actor")), null);
346
+ deepStrictEqual(fromCompatibleEf61Id(123), null);
347
+ });
348
+ test("fromCompatibleEf61Id() rejects malformed compatible identifiers", () => {
349
+ for (const input of [
350
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice",
351
+ "https://server.example/.well-known/apgateway/did:",
352
+ "https://server.example/.well-known/apgateway/did:key/actor",
353
+ "https://server.example/.well-known/apgateway/did:ke%y:z6MkAlice/actor",
354
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%zz",
355
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a#%zz",
356
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?x=%zz",
357
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?@gateway=https%3A%2F%2Fevil.example",
358
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?page=2&%40gateway=x",
359
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?@%67ateway=x",
360
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a?gateways=x",
361
+ "https://server.example/.well-known/apgateway/did:example:a%25/x",
362
+ "https://user:pass@server.example/.well-known/apgateway/did:key:z6MkAlice/a",
363
+ "https://user@server.example/.well-known/apgateway/did:key:z6MkAlice/a"
364
+ ]) throws(() => fromCompatibleEf61Id(input), TypeError, input);
365
+ });
366
+ test("fromCompatibleEf61Id() refuses raw paths changed by URL parsing", () => {
367
+ const base = "https://server.example/.well-known/apgateway/did:key:z6MkAlice";
368
+ for (const path of [
369
+ "/a/../b",
370
+ "/a/%2e%2E/b",
371
+ "/a/. ./b",
372
+ "/a/.. "
373
+ ]) {
374
+ throws(() => fromCompatibleEf61Id(base + path), TypeError, path);
375
+ throws(() => parseIri(base + path), TypeError, path);
376
+ throws(() => formatIri(base + path), TypeError, path);
377
+ }
378
+ for (const input of [
379
+ "https:/server.example/.well-known/apgateway/did:key:z6MkAlice/a/../b",
380
+ "https:server.example/.well-known/apgateway/did:key:z6MkAlice/a/../b",
381
+ "https:\\\\server.example\\.well-known\\apgateway\\did:key:z6MkAlice\\a\\..\\b",
382
+ ` ${base}/../../other`
383
+ ]) {
384
+ throws(() => parseIri(input), TypeError, input);
385
+ throws(() => formatIri(input), TypeError, input);
386
+ }
387
+ throws(() => fromCompatibleEf61Id(` ${base}/actor`), TypeError);
388
+ throws(() => fromCompatibleEf61Id(`https://server.example/foo/../.well-known/apgateway/did:key:z6MkAlice/actor`), TypeError);
389
+ deepStrictEqual(fromCompatibleEf61Id(`${base}/a/%252e/b`)?.pathname, "/a/%252e/b");
390
+ deepStrictEqual(fromCompatibleEf61Id("https://server.example/.WELL-KNOWN/apgateway/did:key:z6MkAlice/actor"), null);
391
+ });
392
+ test("toCompatibleEf61Id() converts portable URIs", () => {
393
+ const cases = [
394
+ [
395
+ "ap+ef61://did:key:z6MkAlice/objects/1",
396
+ "https://server.example",
397
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1"
398
+ ],
399
+ [
400
+ "ap://did:key:z6MkAlice/objects/1",
401
+ "https://server.example/",
402
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/objects/1"
403
+ ],
404
+ [
405
+ "ap://did%3Akey%3Az6MkAlice/actor",
406
+ new URL("http://server.example:8080"),
407
+ "http://server.example:8080/.well-known/apgateway/did:key:z6MkAlice/actor"
408
+ ],
409
+ [
410
+ new URL("ap+ef61://did%3Akey%3Az6MkAlice/actor"),
411
+ "https://server.example",
412
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor"
413
+ ],
414
+ [
415
+ new URL("ap://did%3Akey%3Az6MkAlice/actor"),
416
+ "https://SERVER.example",
417
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor"
418
+ ],
419
+ [
420
+ "ap://did:key:z6MkAlice/a/b/c",
421
+ "https://server.example",
422
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a/b/c"
423
+ ],
424
+ [
425
+ "ap://did:key:z6MkAlice/actor#main-key",
426
+ "https://server.example",
427
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#main-key"
428
+ ],
429
+ [
430
+ "ap://did:key:z6MkAlice/actor#",
431
+ "https://server.example",
432
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor#"
433
+ ],
434
+ [
435
+ "ap://DID:key:z6MkAlice/actor",
436
+ "https://server.example",
437
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor"
438
+ ],
439
+ [
440
+ "ap://did:example:a%2525/x",
441
+ "https://server.example",
442
+ "https://server.example/.well-known/apgateway/did:example:a%2525/x"
443
+ ],
444
+ [
445
+ "ap://did:web:example.com%3A8080/actor",
446
+ "https://server.example",
447
+ "https://server.example/.well-known/apgateway/did:web:example.com%3A8080/actor"
448
+ ],
449
+ [
450
+ "ap://did:key:z6MkAlice/a%2Fb/%252e",
451
+ "https://server.example",
452
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%2Fb/%252e"
453
+ ],
454
+ [
455
+ "ap://did:key:z6MkAlice/a\\b c é/%7euser",
456
+ "https://server.example",
457
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/a%5Cb%20c%09%C3%A9/~user"
458
+ ]
459
+ ];
460
+ for (const [portableId, gateway, expected] of cases) deepStrictEqual(toCompatibleEf61Id(portableId, gateway).href, expected, String(portableId));
461
+ });
462
+ test("toCompatibleEf61Id() removes location hints from queries", () => {
463
+ const base = "https://server.example/.well-known/apgateway/did:key:z6MkAlice";
464
+ const cases = [
465
+ ["ap://did:key:z6MkAlice/actor?@gateway=https%3A%2F%2Fa.example&@gateway=https%3A%2F%2Fb.example", `${base}/actor`],
466
+ ["ap://did:key:z6MkAlice/actor?gateways=https%3A%2F%2Fa.example", `${base}/actor`],
467
+ ["ap://did:key:z6MkAlice/actor?%40gateway=https%3A%2F%2Fa.example", `${base}/actor`],
468
+ ["ap://did:key:z6MkAlice/actor?@%67ateway=https%3A%2F%2Fa.example", `${base}/actor`],
469
+ ["ap://did:key:z6MkAlice/actor?@gateway", `${base}/actor`],
470
+ ["ap://did:key:z6MkAlice/c?page=3&@gateway=https%3A%2F%2Fa.example&maxItems=20&page=4", `${base}/c?page=3&maxItems=20&page=4`],
471
+ ["ap://did:key:z6MkAlice/c?a=1&&b=2#frag", `${base}/c?a=1&&b=2#frag`],
472
+ ["ap://did:key:z6MkAlice/c?", `${base}/c?`],
473
+ ["ap://did:key:z6MkAlice/c?x='y'", `${base}/c?x=%27y%27`],
474
+ ["ap://did:key:z6MkAlice/c?@gate way=https%3A%2F%2Fa.example", `${base}/c?@gate%09way=https%3A%2F%2Fa.example`],
475
+ ["ap://did:key:z6MkAlice/c?@gate\nway=1&x=\r2", `${base}/c?@gate%0Away=1&x=%0D2`],
476
+ ["ap://did:key:z6MkAlice/c?%ff=1", `${base}/c?%FF=1`]
477
+ ];
478
+ for (const [portableId, expected] of cases) {
479
+ const result = toCompatibleEf61Id(portableId, "https://server.example");
480
+ deepStrictEqual(result.href, expected, portableId);
481
+ ok(!/[?&](%40|@)gateway(=|&|$)/i.test(result.search), portableId);
482
+ }
483
+ });
484
+ test("toCompatibleEf61Id() rejects invalid portable IDs", () => {
485
+ const cases = [
486
+ "https://server.example/actor",
487
+ "https://server.example/.well-known/apgateway/did:key:z6MkAlice/actor",
488
+ "at://did:plc:example/record",
489
+ "ap://not-a-did/actor",
490
+ "ap://did:key:z6MkAlice",
491
+ "ap://did:key:z6MkAlice/a%zz",
492
+ "ap://did:key:z6MkAlice/a#%zz",
493
+ "ap://did:key:z6MkAlice/a?x=%zz",
494
+ "ap://did:key:z6MkAlice/.",
495
+ "ap://did:key:z6MkAlice/..",
496
+ "ap://did:key:z6MkAlice/a/./b",
497
+ "ap://did:key:z6MkAlice/a/../b",
498
+ "ap://did:key:z6MkAlice/a/%2e/b",
499
+ "ap://did:key:z6MkAlice/a/%2E%2e/b",
500
+ "ap://did:key:z6MkAlice/a/.%2e/b",
501
+ "ap://did:key:z6MkAlice/a/%2e./b",
502
+ new URL("https://server.example/actor"),
503
+ new URL("ap+ef61://user:pass@did%3Akey%3Az6MkAlice/actor"),
504
+ new URL("ap+ef61://did%3Akey%3Az6MkAlice:8080/actor"),
505
+ 123
506
+ ];
507
+ for (const portableId of cases) throws(() => toCompatibleEf61Id(portableId, "https://server.example"), TypeError, String(portableId));
508
+ });
509
+ test("toCompatibleEf61Id() rejects gateways that are not HTTP(S) origins", () => {
510
+ const cases = [
511
+ "ftp://server.example",
512
+ "ap+ef61://did:key:z6MkAlice/actor",
513
+ "https://user:pass@server.example",
514
+ "https://user@server.example",
515
+ "https://server.example/ap",
516
+ "https://server.example/ap/",
517
+ "https://server.example/.well-known/apgateway",
518
+ "https://server.example/?x=1",
519
+ "https://server.example/?",
520
+ "https://server.example/#fragment",
521
+ "https://server.example/#",
522
+ "server.example",
523
+ "",
524
+ new URL("https://server.example/?"),
525
+ new URL("https://server.example/#"),
526
+ new URL("https://server.example/ap"),
527
+ new URL("ftp://server.example/"),
528
+ 123
529
+ ];
530
+ for (const gateway of cases) throws(() => toCompatibleEf61Id("ap://did:key:z6MkAlice/actor", gateway), TypeError, String(gateway));
531
+ });
532
+ test("compatible identifier conversion round-trips", () => {
533
+ for (const portableId of [
534
+ "ap+ef61://did:key:z6MkAlice/objects/1",
535
+ "ap://did:key:z6MkAlice/actor",
536
+ "ap://did%3Akey%3Az6MkAlice/actor/inbox",
537
+ "ap://did:key:z6MkAlice/actor#",
538
+ "ap://did:key:z6MkAlice/actor#main-key",
539
+ "ap://did:key:z6MkAlice/a%2Fb/%252e",
540
+ "ap://did:key:z6MkAlice/a\\b c é",
541
+ "ap://did:example:a%2525/x",
542
+ "ap://did:web:example.com%3A8080/actor",
543
+ "ap://did:key:z6MkAlice/c?page=3&@gateway=https%3A%2F%2Fa.example"
544
+ ]) {
545
+ const converted = fromCompatibleEf61Id(toCompatibleEf61Id(portableId, "https://server.example"));
546
+ ok(converted != null, portableId);
547
+ deepStrictEqual(canonicalizePortableUri(converted.href), canonicalizePortableUri(portableId), portableId);
548
+ }
549
+ ok(!arePortableUrisEqual(fromCompatibleEf61Id(toCompatibleEf61Id("ap://did:key:z6MkAlice/actor", "https://server.example")).href, fromCompatibleEf61Id(toCompatibleEf61Id("ap://did:key:z6MkAlice/actor#", "https://server.example")).href));
550
+ });
551
+ test("UrlError reason is independent of its cause", () => {
552
+ const cause = /* @__PURE__ */ new Error("Underlying failure");
553
+ strictEqual(new UrlError("Rejected URL").reason, "disallowed");
554
+ const disallowedError = new UrlError("Rejected URL", { cause });
555
+ strictEqual(disallowedError.reason, "disallowed");
556
+ strictEqual(disallowedError.cause, cause);
557
+ const dnsError = new UrlError("Lookup failed", {
558
+ reason: "dns",
559
+ cause
560
+ });
561
+ strictEqual(dnsError.reason, "dns");
562
+ strictEqual(dnsError.cause, cause);
563
+ });
564
+ test("validatePublicUrl() classifies disallowed URLs", async () => {
565
+ for (const url of [
566
+ "ftp://example.com",
567
+ "https://localhost",
568
+ "https://127.0.0.1"
569
+ ]) await rejects(() => validatePublicUrl(url), {
570
+ name: "UrlError",
571
+ reason: "disallowed"
572
+ });
573
+ });
230
574
  test("validatePublicUrl()", async () => {
231
575
  await rejects(() => validatePublicUrl("ftp://localhost"), UrlError);
232
576
  await rejects(() => validatePublicUrl("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="), UrlError);
@@ -253,6 +597,45 @@ test("validatePublicUrl()", async () => {
253
597
  await validatePublicUrl("https://[2001:db8::1]");
254
598
  await validatePublicUrl("https://[64:ff9b::8.8.8.8]");
255
599
  });
600
+ test("validateLookupAddresses() tolerates Cloudflare Workers CNAME entries", () => {
601
+ validateLookupAddresses([
602
+ {
603
+ address: "app-host.example.net.",
604
+ family: 4
605
+ },
606
+ {
607
+ address: "93.184.216.34",
608
+ family: 4
609
+ },
610
+ {
611
+ address: "2606:2800:220:1:248:1893:25c8:1946",
612
+ family: 6
613
+ }
614
+ ]);
615
+ });
616
+ test("validateLookupAddresses() rejects unsafe or CNAME-only Cloudflare Workers results", () => {
617
+ throws(() => validateLookupAddresses([{
618
+ address: "private-host.example.net.",
619
+ family: 4
620
+ }, {
621
+ address: "127.0.0.1",
622
+ family: 4
623
+ }]), {
624
+ name: "UrlError",
625
+ reason: "disallowed"
626
+ });
627
+ throws(() => validateLookupAddresses([{
628
+ address: "app-host.example.net.",
629
+ family: 4
630
+ }]), {
631
+ name: "UrlError",
632
+ reason: "dns"
633
+ });
634
+ throws(() => validateLookupAddresses([]), {
635
+ name: "UrlError",
636
+ reason: "dns"
637
+ });
638
+ });
256
639
  test("isValidPublicIPv4Address()", () => {
257
640
  ok(isValidPublicIPv4Address("8.8.8.8"));
258
641
  ok(!isValidPublicIPv4Address("192.168.1.1"));
@@ -310,5 +693,123 @@ test("expandIPv6Address()", () => {
310
693
  deepStrictEqual(expandIPv6Address("2001:db8::1"), "2001:0db8:0000:0000:0000:0000:0000:0001");
311
694
  deepStrictEqual(expandIPv6Address("64:ff9b::8.8.8.8"), "0064:ff9b:0000:0000:0000:0000:0808:0808");
312
695
  });
696
+ test("withGatewayHints() adds @gateway location hints", () => {
697
+ const expected = "ap+ef61://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fserver1.example&@gateway=https%3A%2F%2Fserver2.example";
698
+ for (const id of [
699
+ "ap://did:key:z6Mkabc/actor",
700
+ "ap+ef61://did:key:z6Mkabc/actor",
701
+ "ap://did%3Akey%3Az6Mkabc/actor",
702
+ parseIri("ap://did:key:z6Mkabc/actor"),
703
+ new URL("ap://did%3Akey%3Az6Mkabc/actor")
704
+ ]) {
705
+ const hinted = withGatewayHints(id, ["https://server1.example", new URL("https://server2.example/")]);
706
+ ok(hinted instanceof URL);
707
+ strictEqual(hinted.href, "ap+ef61://did%3Akey%3Az6Mkabc/actor?@gateway=https%3A%2F%2Fserver1.example&@gateway=https%3A%2F%2Fserver2.example");
708
+ strictEqual(formatIri(hinted), expected);
709
+ deepStrictEqual(parseIri(formatIri(hinted)), hinted);
710
+ }
711
+ });
712
+ test("withGatewayHints() encodes and deduplicates gateway origins", () => {
713
+ function* gateways() {
714
+ yield "https://A.example:443";
715
+ yield "https://a.example/";
716
+ yield new URL("https://a.example");
717
+ yield "https://b.example:8443";
718
+ yield "http://c.example:80/";
719
+ yield "https://例え.jp";
720
+ }
721
+ strictEqual(formatIri(withGatewayHints("ap://did:key:z6Mkabc/actor", gateways())), "ap+ef61://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example&@gateway=https%3A%2F%2Fb.example%3A8443&@gateway=http%3A%2F%2Fc.example&@gateway=https%3A%2F%2Fxn--r8jz45g.jp");
722
+ strictEqual(formatIri(withGatewayHints("ap://did:key:z6Mkabc/actor", /* @__PURE__ */ new Set(["https://b.example", "https://a.example"]))), "ap+ef61://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fb.example&@gateway=https%3A%2F%2Fa.example");
723
+ const many = Array.from({ length: 7 }, (_, i) => `https://server${i}.example`);
724
+ deepStrictEqual(getGatewayHints(withGatewayHints("ap://did:key:z6Mkabc/actor", many)).map((url) => url.origin), many);
725
+ });
726
+ test("withGatewayHints() keeps other query parameters and fragments", () => {
727
+ strictEqual(formatIri(withGatewayHints("ap://did:key:z6Mkabc/collection?page=3&maxItems=20&q=a+b%20c%2b", ["https://server.example"])), "ap+ef61://did:key:z6Mkabc/collection?page=3&maxItems=20&q=a+b%20c%2B&@gateway=https%3A%2F%2Fserver.example");
728
+ strictEqual(formatIri(withGatewayHints("ap://did:key:z6Mkabc/actor?x=%26%3D#main-key", ["https://server.example"])), "ap+ef61://did:key:z6Mkabc/actor?x=%26%3D&@gateway=https%3A%2F%2Fserver.example#main-key");
729
+ strictEqual(withGatewayHints("ap://did:key:z6Mkabc/actor#", ["https://s.example"]).href, "ap+ef61://did%3Akey%3Az6Mkabc/actor?@gateway=https%3A%2F%2Fs.example#");
730
+ });
731
+ test("withGatewayHints() replaces existing location hints", () => {
732
+ strictEqual(formatIri(withGatewayHints("ap://did:key:z6Mkabc/collection?@gateway=https%3A%2F%2Fold.example&page=2&%40gateway=https%3A%2F%2Fold2.example&@gateway&gateways=https%3A%2F%2Flegacy.example&%2540gateway=kept", ["https://new.example"])), "ap+ef61://did:key:z6Mkabc/collection?page=2&%2540gateway=kept&@gateway=https%3A%2F%2Fnew.example");
733
+ for (const char of [
734
+ " ",
735
+ "\n",
736
+ "\r"
737
+ ]) deepStrictEqual(getGatewayHints(withGatewayHints(`ap://did:key:z6Mkabc/actor?@gate${char}way=https%3A%2F%2Fevil.example`, ["https://new.example"])).map((url) => url.href), ["https://new.example/"]);
738
+ });
739
+ test("withGatewayHints() with no gateways removes location hints", () => {
740
+ for (const [input, expected] of [
741
+ ["ap://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example", "ap+ef61://did%3Akey%3Az6Mkabc/actor"],
742
+ ["ap://did:key:z6Mkabc/actor?&@gateway=https%3A%2F%2Fa.example&&p=1&", "ap+ef61://did%3Akey%3Az6Mkabc/actor?p=1"],
743
+ ["ap://did:key:z6Mkabc/actor?", "ap+ef61://did%3Akey%3Az6Mkabc/actor"],
744
+ ["ap://did:key:z6Mkabc/actor?gateways=https%3A%2F%2Fa.example#k", "ap+ef61://did%3Akey%3Az6Mkabc/actor#k"]
745
+ ]) {
746
+ strictEqual(withGatewayHints(input, []).href, expected, input);
747
+ strictEqual(withoutGatewayHints(input).href, expected, input);
748
+ }
749
+ const input = parseIri("ap://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example");
750
+ const href = input.href;
751
+ withoutGatewayHints(input);
752
+ strictEqual(input.href, href);
753
+ });
754
+ test("withGatewayHints() rejects non-portable IDs", () => {
755
+ for (const id of [
756
+ "https://server.example/.well-known/apgateway/did:key:z6Mkabc/actor",
757
+ "https://example.com/actor",
758
+ "did:key:z6Mkabc#z6Mkabc",
759
+ "ap://did:key:z6Mkabc",
760
+ "ap://example.com/actor",
761
+ "ap://did:key:z6Mkabc/actor%zz",
762
+ new URL("https://example.com/actor"),
763
+ new URL("ap://did%3Akey%3Az6Mkabc:8080/actor"),
764
+ new URL("ap://user@did%3Akey%3Az6Mkabc/actor")
765
+ ]) {
766
+ throws(() => withGatewayHints(id, ["https://server.example"]), TypeError, String(id));
767
+ throws(() => withoutGatewayHints(id), TypeError, String(id));
768
+ throws(() => getGatewayHints(id), TypeError, String(id));
769
+ }
770
+ });
771
+ test("withGatewayHints() rejects paths that URLs cannot represent", () => {
772
+ for (const id of [
773
+ "ap://did:key:z6Mkabc/a/../actor",
774
+ "ap://did:key:z6Mkabc/a/./actor",
775
+ "ap://did:key:z6Mkabc/a/%2e%2e/actor",
776
+ "ap://did:key:z6Mkabc/a/%2E/actor"
777
+ ]) {
778
+ throws(() => withGatewayHints(id, ["https://server.example"]), TypeError, id);
779
+ throws(() => withoutGatewayHints(id), TypeError, id);
780
+ }
781
+ strictEqual(withoutGatewayHints("ap://did:key:z6Mkabc/a b").href, "ap+ef61://did%3Akey%3Az6Mkabc/a%09b");
782
+ });
783
+ test("withGatewayHints() rejects invalid gateways", () => {
784
+ for (const gateway of [
785
+ "https://server.example/path",
786
+ "https://server.example/?",
787
+ "https://server.example/#",
788
+ "https://server.example/?q=1",
789
+ "https://user:pass@server.example",
790
+ "ftp://server.example",
791
+ "ap://did:key:z6Mkabc/actor",
792
+ "server.example",
793
+ new URL("https://server.example/path")
794
+ ]) throws(() => withGatewayHints("ap://did:key:z6Mkabc/actor", [gateway]), TypeError, String(gateway));
795
+ throws(() => withGatewayHints("ap://did:key:z6Mkabc/actor", "https://server.example"), TypeError);
796
+ });
797
+ test("getGatewayHints() reads @gateway location hints", () => {
798
+ deepStrictEqual(getGatewayHints("ap://did:key:z6Mkabc/actor?@gateway=https%3A%2F%2Fa.example&@gateway=invalid&%40gateway=https%3A%2F%2Fb.example%2F&@gateway=https%3A%2F%2Fa.example%2F&@gateway=https%3A%2F%2Fc.example%2Fpath&gateways=https%3A%2F%2Flegacy.example&page=1#k").map((url) => url.href), ["https://a.example/", "https://b.example/"]);
799
+ deepStrictEqual(getGatewayHints("ap://did:key:z6Mkabc/actor"), []);
800
+ const questioned = "ap://did:key:z6Mkabc/actor??@gateway=https%3A%2F%2Fa.example";
801
+ deepStrictEqual(getGatewayHints(questioned), []);
802
+ strictEqual(withoutGatewayHints(questioned).href, "ap+ef61://did%3Akey%3Az6Mkabc/actor??@gateway=https%3A%2F%2Fa.example");
803
+ deepStrictEqual(getGatewayHints(withGatewayHints(questioned, ["https://b.example"])).map((url) => url.href), ["https://b.example/"]);
804
+ deepStrictEqual(getGatewayHints("ap://did:key:z6Mkabc/actor?@gate%09way=https%3A%2F%2Fa.example"), []);
805
+ deepStrictEqual(getGatewayHints("ap://did:key:z6Mkabc/actor?@gate way=https%3A%2F%2Fa.example"), []);
806
+ });
807
+ test("withGatewayHints() round-trips with other portable ID helpers", () => {
808
+ const hinted = withGatewayHints("ap://did:key:z6Mkabc/objects/1#frag", ["https://server1.example", "https://server2.example"]);
809
+ strictEqual(canonicalizePortableUri(formatIri(hinted)), "ap+ef61://did:key:z6Mkabc/objects/1#frag");
810
+ ok(arePortableUrisEqual(formatIri(hinted), "ap://did:key:z6Mkabc/objects/1#frag"));
811
+ strictEqual(toCompatibleEf61Id(hinted, "https://server1.example").href, "https://server1.example/.well-known/apgateway/did:key:z6Mkabc/objects/1#frag");
812
+ strictEqual(formatIri(withoutGatewayHints(hinted)), "ap+ef61://did:key:z6Mkabc/objects/1#frag");
813
+ });
313
814
  //#endregion
314
815
  export {};