@fedify/fedify 2.2.19 → 2.2.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (109) hide show
  1. package/dist/attachment-arrays-CalAATqD.mjs +16 -0
  2. package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
  3. package/dist/callback-0KrwzutD.d.mts +2607 -0
  4. package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
  15. package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
  16. package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
  17. package/dist/docloader-Bogpjg4d.mjs +125 -0
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/collection.test.mjs +1 -1
  22. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  23. package/dist/federation/delivery-attachments.test.mjs +288 -0
  24. package/dist/federation/handler.test.mjs +208 -16
  25. package/dist/federation/idempotency.test.mjs +2 -2
  26. package/dist/federation/inbox.test.mjs +2 -2
  27. package/dist/federation/middleware.test.mjs +1567 -30
  28. package/dist/federation/mod.cjs +1 -1
  29. package/dist/federation/mod.d.cts +2 -2
  30. package/dist/federation/mod.d.ts +2 -2
  31. package/dist/federation/mod.js +1 -1
  32. package/dist/federation/negotiation.test.mjs +1 -1
  33. package/dist/federation/retry.test.mjs +1 -1
  34. package/dist/federation/send.test.mjs +723 -68
  35. package/dist/federation/temporal.test.mjs +25 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
  38. package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
  39. package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
  40. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  41. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  42. package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
  43. package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
  44. package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
  45. package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
  46. package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
  47. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  48. package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
  49. package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
  50. package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
  51. package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
  52. package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
  53. package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
  54. package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
  55. package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
  56. package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
  57. package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
  58. package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
  59. package/dist/mod.cjs +5 -5
  60. package/dist/mod.d.cts +8 -8
  61. package/dist/mod.d.ts +8 -8
  62. package/dist/mod.js +5 -5
  63. package/dist/nodeinfo/client.test.mjs +764 -18
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/nodeinfo/mod.cjs +1 -1
  66. package/dist/nodeinfo/mod.d.cts +1 -1
  67. package/dist/nodeinfo/mod.d.ts +1 -1
  68. package/dist/nodeinfo/mod.js +1 -1
  69. package/dist/nodeinfo/types.test.mjs +1 -1
  70. package/dist/otel/exporter.test.mjs +292 -30
  71. package/dist/otel/mod.cjs +36 -30
  72. package/dist/otel/mod.d.cts +13 -0
  73. package/dist/otel/mod.d.ts +13 -0
  74. package/dist/otel/mod.js +36 -30
  75. package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
  76. package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
  77. package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
  78. package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
  79. package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
  80. package/dist/send-CAdpwbFX.mjs +416 -0
  81. package/dist/sig/http.test.mjs +528 -2
  82. package/dist/sig/key-types.test.d.mts +218 -0
  83. package/dist/sig/key-types.test.mjs +8 -0
  84. package/dist/sig/key.test.mjs +2 -2
  85. package/dist/sig/ld.test.mjs +573 -8
  86. package/dist/sig/mod.cjs +2 -2
  87. package/dist/sig/mod.d.cts +3 -3
  88. package/dist/sig/mod.d.ts +3 -3
  89. package/dist/sig/mod.js +2 -2
  90. package/dist/sig/owner.test.mjs +1 -1
  91. package/dist/sig/proof.test.mjs +96 -4
  92. package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
  93. package/dist/testing/mod.d.mts +1 -2396
  94. package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
  95. package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
  96. package/dist/utils/docloader.test.mjs +318 -34
  97. package/dist/utils/mod.cjs +1 -1
  98. package/dist/utils/mod.d.cts +1 -1
  99. package/dist/utils/mod.d.ts +1 -1
  100. package/dist/utils/mod.js +1 -1
  101. package/package.json +6 -6
  102. package/dist/docloader-D1ghurDJ.mjs +0 -83
  103. package/dist/send-D35Va72B.mjs +0 -260
  104. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  105. /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
  106. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
  107. /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
  108. /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
  109. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -5,12 +5,15 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
6
6
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
8
- import { a as generateCryptoKeyPair } from "../key-DolXUaLH.mjs";
8
+ import { a as generateCryptoKeyPair } from "../key-Bhc8cQC7.mjs";
9
9
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
10
- import { a as compactJsonLd, f as isInvalidUrlTypeError, g as verifySignature, h as verifyJsonLd, i as attachSignature, n as UnsafeJsonLdError, o as createSignature, p as signJsonLd, s as detachSignature, u as hasSignatureLike } from "../ld-rTdIfZ63.mjs";
10
+ import { _ as verifyJsonLd, a as compactJsonLd, c as detachSignature, d as hasSignatureLike, f as hasVerifiableSignature, h as signJsonLd, i as attachSignature, m as isInvalidUrlTypeError, n as UnsafeJsonLdError, o as createSignature, s as describeSignatureShape, u as hasSignature, v as verifySignature } from "../ld-DTeykI0e.mjs";
11
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-Dgz_b89j.mjs";
11
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
- import { CryptographicKey } from "@fedify/vocab";
13
+ import { Create, CryptographicKey, Note } from "@fedify/vocab";
14
+ import { configure, reset } from "@logtape/logtape";
13
15
  import { encodeBase64 } from "byte-encodings/base64";
16
+ import jsonld from "@fedify/vocab-runtime/jsonld";
14
17
  //#region src/sig/ld.test.ts
15
18
  test("isInvalidUrlTypeError()", () => {
16
19
  assert(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("Invalid URL string.")));
@@ -25,22 +28,84 @@ test("isInvalidUrlTypeError()", () => {
25
28
  });
26
29
  test("attachSignature()", () => {
27
30
  const sig = {
28
- "@context": "https://w3id.org/identity/v1",
31
+ "@context": "https://w3id.org/security/v1",
29
32
  type: "RsaSignature2017",
30
33
  creator: "https://activitypub.academy/users/brauca_darradiul#main-key",
31
34
  created: "2024-09-12T16:50:46Z",
32
35
  signatureValue: "asdf"
33
36
  };
37
+ const signatureTerm = { "signature": "https://w3id.org/security#signature" };
34
38
  const doc = {
35
39
  "@context": "https://www.w3.org/ns/activitystreams",
36
40
  id: "https://example.com/1"
37
41
  };
38
42
  assertEquals(attachSignature(doc, sig), {
39
43
  ...doc,
44
+ "@context": ["https://www.w3.org/ns/activitystreams", signatureTerm],
45
+ signature: sig
46
+ });
47
+ const arrayDoc = {
48
+ "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
49
+ id: "https://example.com/1"
50
+ };
51
+ assertEquals(attachSignature(arrayDoc, sig), {
52
+ ...arrayDoc,
53
+ "@context": [...arrayDoc["@context"], signatureTerm],
54
+ signature: sig
55
+ });
56
+ for (const context of [
57
+ ["https://w3id.org/identity/v1", "https://www.w3.org/ns/activitystreams"],
58
+ ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
59
+ ["https://www.w3.org/ns/activitystreams", signatureTerm],
60
+ { "signature": "https://w3id.org/security#signature" }
61
+ ]) {
62
+ const contextDoc = {
63
+ "@context": context,
64
+ id: "https://example.com/1"
65
+ };
66
+ assertEquals(attachSignature(contextDoc, sig), {
67
+ ...contextDoc,
68
+ signature: sig
69
+ });
70
+ }
71
+ assertEquals(attachSignature({
72
+ "@context": null,
73
+ id: "https://example.com/1"
74
+ }, sig), {
75
+ "@context": [signatureTerm],
76
+ id: "https://example.com/1",
77
+ signature: sig
78
+ });
79
+ const resetDoc = {
80
+ "@context": [
81
+ "https://w3id.org/security/v1",
82
+ null,
83
+ "https://www.w3.org/ns/activitystreams"
84
+ ],
85
+ id: "https://example.com/1"
86
+ };
87
+ assertEquals(attachSignature(resetDoc, sig), {
88
+ ...resetDoc,
89
+ "@context": [...resetDoc["@context"], signatureTerm],
90
+ signature: sig
91
+ });
92
+ const disabledTermDoc = {
93
+ "@context": [{ "signature": { "@id": null } }, "https://www.w3.org/ns/activitystreams"],
94
+ id: "https://example.com/1"
95
+ };
96
+ assertEquals(attachSignature(disabledTermDoc, sig), {
97
+ ...disabledTermDoc,
98
+ "@context": [...disabledTermDoc["@context"], signatureTerm],
99
+ signature: sig
100
+ });
101
+ assertEquals(attachSignature({ id: "https://example.com/1" }, sig), {
102
+ id: "https://example.com/1",
103
+ "@context": [signatureTerm],
40
104
  signature: sig
41
105
  });
42
106
  assertThrows(() => attachSignature(null, sig), TypeError);
43
107
  assertThrows(() => attachSignature(1234, sig), TypeError);
108
+ assertThrows(() => attachSignature([], sig), TypeError);
44
109
  });
45
110
  test("createSignature()", async () => {
46
111
  const doc = {
@@ -48,7 +113,11 @@ test("createSignature()", async () => {
48
113
  id: "https://example.com/1",
49
114
  type: "Create"
50
115
  };
51
- assertEquals(await verifySignature(attachSignature(doc, await createSignature(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader })), {
116
+ const sig = await createSignature(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
117
+ assertEquals(typeof sig.created, "string");
118
+ assert(hasSignature(attachSignature(doc, sig)));
119
+ assertEquals(sig["@context"], "https://w3id.org/security/v1");
120
+ assertEquals(await verifySignature(attachSignature(doc, sig), {
52
121
  documentLoader: mockDocumentLoader,
53
122
  contextLoader: mockDocumentLoader
54
123
  }), rsaPublicKey2);
@@ -56,12 +125,15 @@ test("createSignature()", async () => {
56
125
  assertRejects(() => createSignature(doc, ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader }), TypeError);
57
126
  });
58
127
  test("signJsonLd()", async () => {
59
- assert(await verifyJsonLd(await signJsonLd({
128
+ const signed = await signJsonLd({
60
129
  "@context": "https://www.w3.org/ns/activitystreams",
61
130
  id: "https://example.com/1",
62
131
  type: "Create",
63
132
  actor: "https://example.com/person2"
64
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }), {
133
+ }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader });
134
+ assert(hasSignature(signed));
135
+ assertEquals(typeof signed.signature.created, "string");
136
+ assert(await verifyJsonLd(signed, {
65
137
  documentLoader: mockDocumentLoader,
66
138
  contextLoader: mockDocumentLoader
67
139
  }));
@@ -108,6 +180,135 @@ test("hasSignatureLike()", () => {
108
180
  } }));
109
181
  assertFalse(hasSignatureLike(null));
110
182
  });
183
+ test("signJsonLd() defines the signature term when the context lacks it", async () => {
184
+ const signed = await signJsonLd({
185
+ "@context": "https://www.w3.org/ns/activitystreams",
186
+ id: "https://example.com/notes/1",
187
+ type: "Note",
188
+ content: "Hello"
189
+ }, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
190
+ assert(Array.isArray(signed["@context"]));
191
+ assertEquals(signed["@context"][1], { "signature": "https://w3id.org/security#signature" });
192
+ assert((await jsonld.canonize(signed, {
193
+ format: "application/n-quads",
194
+ documentLoader: mockDocumentLoader
195
+ })).includes("<https://w3id.org/security#signature>"));
196
+ assertEquals(await verifySignature(signed, {
197
+ documentLoader: mockDocumentLoader,
198
+ contextLoader: mockDocumentLoader
199
+ }), rsaPublicKey2);
200
+ });
201
+ test("signJsonLd() signs documents that use the signature term", async () => {
202
+ const signatureTerm = { "signature": "https://w3id.org/security#signature" };
203
+ for (const object of [{
204
+ type: "Note",
205
+ signature: "nested value"
206
+ }, { type: "signature" }]) {
207
+ const doc = {
208
+ "@context": ["https://www.w3.org/ns/activitystreams", { "@vocab": "https://example.com/" }],
209
+ id: "https://example.com/1",
210
+ type: "Create",
211
+ object
212
+ };
213
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
214
+ assertEquals(signed["@context"], [...doc["@context"], signatureTerm]);
215
+ assertEquals(signed["object"], object);
216
+ assertEquals(await verifySignature(signed, {
217
+ documentLoader: mockDocumentLoader,
218
+ contextLoader: mockDocumentLoader
219
+ }), rsaPublicKey2);
220
+ }
221
+ });
222
+ test("signJsonLd() does not share the inline signature definition", async () => {
223
+ const doc = {
224
+ "@context": "https://www.w3.org/ns/activitystreams",
225
+ id: "https://example.com/notes/1",
226
+ type: "Note"
227
+ };
228
+ const firstContext = (await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }))["@context"];
229
+ firstContext[1]["signature"] = "https://example.com/signature";
230
+ assertEquals((await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }))["@context"][1], { "signature": "https://w3id.org/security#signature" });
231
+ });
232
+ test("signJsonLd() respects a protected null signature definition", async () => {
233
+ for (const context of [{
234
+ "@protected": true,
235
+ "signature": { "@id": null }
236
+ }, { "signature": {
237
+ "@id": null,
238
+ "@protected": true
239
+ } }]) {
240
+ const doc = {
241
+ "@context": ["https://www.w3.org/ns/activitystreams", context],
242
+ id: "https://example.com/1",
243
+ type: "Note"
244
+ };
245
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
246
+ assertEquals(signed["@context"], doc["@context"]);
247
+ assertEquals(await verifySignature(signed, {
248
+ documentLoader: mockDocumentLoader,
249
+ contextLoader: mockDocumentLoader
250
+ }), rsaPublicKey2);
251
+ }
252
+ });
253
+ test("signJsonLd() respects protection from imported contexts", async () => {
254
+ const importUrl = "https://example.com/contexts/imported-protected";
255
+ const contextLoader = async (url) => {
256
+ if (new URL(url).href === importUrl) return {
257
+ contextUrl: null,
258
+ documentUrl: url,
259
+ document: { "@context": {
260
+ "@protected": true,
261
+ "name": "https://example.com/name"
262
+ } }
263
+ };
264
+ return await mockDocumentLoader(url);
265
+ };
266
+ for (const signature of [null, { "@id": null }]) {
267
+ const doc = {
268
+ "@context": ["https://www.w3.org/ns/activitystreams", {
269
+ "@import": importUrl,
270
+ signature
271
+ }],
272
+ id: "https://example.com/1",
273
+ type: "Note",
274
+ name: "Alice"
275
+ };
276
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader });
277
+ assertEquals(signed["@context"], doc["@context"]);
278
+ assertEquals(await verifySignature(signed, {
279
+ documentLoader: mockDocumentLoader,
280
+ contextLoader
281
+ }), rsaPublicKey2);
282
+ }
283
+ });
284
+ test("signJsonLd() leaves unrecognized remote contexts unchanged", async () => {
285
+ const contextUrl = "https://example.com/contexts/custom";
286
+ const contextLoader = async (url) => {
287
+ if (new URL(url).href === contextUrl) return {
288
+ contextUrl: null,
289
+ documentUrl: url,
290
+ document: { "@context": {
291
+ "@protected": true,
292
+ "signature": {
293
+ "@id": "https://w3id.org/security#signature",
294
+ "@type": "@id"
295
+ }
296
+ } }
297
+ };
298
+ return await mockDocumentLoader(url);
299
+ };
300
+ const doc = {
301
+ "@context": ["https://www.w3.org/ns/activitystreams", contextUrl],
302
+ id: "https://example.com/1",
303
+ type: "Note"
304
+ };
305
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader });
306
+ assertEquals(signed["@context"], doc["@context"]);
307
+ assertEquals(await verifySignature(signed, {
308
+ documentLoader: mockDocumentLoader,
309
+ contextLoader
310
+ }), rsaPublicKey2);
311
+ });
111
312
  const document = {
112
313
  "@context": ["https://www.w3.org/ns/activitystreams", {
113
314
  "ostatus": "http://ostatus.org#",
@@ -260,6 +461,367 @@ test("verifyJsonLd()", async () => {
260
461
  contextLoader: mockDocumentLoader
261
462
  }));
262
463
  });
464
+ test("verifyJsonLd() tolerates unmapped document and signature properties", async () => {
465
+ const options = {
466
+ documentLoader: mockDocumentLoader,
467
+ contextLoader: mockDocumentLoader
468
+ };
469
+ const canonize = (input) => jsonld.canonize(input, {
470
+ format: "application/n-quads",
471
+ documentLoader: mockDocumentLoader,
472
+ safe: false
473
+ });
474
+ const withQuote = {
475
+ ...document,
476
+ object: {
477
+ ...document.object,
478
+ quoteUri: "https://example.com/quoted"
479
+ }
480
+ };
481
+ const sigOptions = {
482
+ "@context": "https://w3id.org/identity/v1",
483
+ creator: signature.creator,
484
+ created: signature.created
485
+ };
486
+ const extraOption = { quoteUri: "https://example.com/quoted" };
487
+ assertEquals(await canonize(withQuote), await canonize(document));
488
+ assertEquals(await canonize({
489
+ ...sigOptions,
490
+ ...extraOption
491
+ }), await canonize(sigOptions));
492
+ for (const input of [withQuote, {
493
+ ...sigOptions,
494
+ ...extraOption
495
+ }]) await assertRejects(() => jsonld.canonize(input, {
496
+ format: "application/n-quads",
497
+ documentLoader: mockDocumentLoader,
498
+ safe: true
499
+ }), Error, "Safe mode validation error.");
500
+ const expectedKey = await verifySignature(testVector, options);
501
+ assertInstanceOf(expectedKey, CryptographicKey);
502
+ for (const signed of [
503
+ {
504
+ ...withQuote,
505
+ signature
506
+ },
507
+ {
508
+ ...document,
509
+ signature: {
510
+ ...signature,
511
+ ...extraOption
512
+ }
513
+ },
514
+ {
515
+ ...withQuote,
516
+ signature: {
517
+ ...signature,
518
+ ...extraOption
519
+ }
520
+ }
521
+ ]) {
522
+ assertEquals(await verifySignature(signed, options), expectedKey);
523
+ assert(await verifyJsonLd(signed, options));
524
+ }
525
+ const tampered = {
526
+ ...withQuote,
527
+ object: {
528
+ ...withQuote.object,
529
+ content: "<p>Forged</p>"
530
+ },
531
+ signature
532
+ };
533
+ assertEquals(await verifySignature(tampered, options), null);
534
+ assertFalse(await verifyJsonLd(tampered, options));
535
+ });
536
+ test("verifyJsonLd() rejects relative IRIs despite unmapped properties", async () => {
537
+ const options = {
538
+ documentLoader: mockDocumentLoader,
539
+ contextLoader: mockDocumentLoader
540
+ };
541
+ const canonize = (input) => jsonld.canonize(input, {
542
+ format: "application/n-quads",
543
+ documentLoader: mockDocumentLoader,
544
+ safe: false
545
+ });
546
+ const withRelativeUrl = {
547
+ ...document,
548
+ object: {
549
+ ...document.object,
550
+ url: [document.object.url, "/evil"]
551
+ }
552
+ };
553
+ const note = await (await Create.fromJsonLd(withRelativeUrl, options)).getObject(options);
554
+ assertInstanceOf(note, Note);
555
+ assertEquals(note.urls.map((url) => url instanceof URL ? url.href : null), [document.object.url, "https://activitypub.academy/evil"]);
556
+ for (const input of [withRelativeUrl, {
557
+ ...document,
558
+ "https://example.com/extension": { "@id": "relative" }
559
+ }]) {
560
+ assertEquals(await canonize(input), await canonize(document));
561
+ for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) {
562
+ const signed = {
563
+ ...input,
564
+ ...extra,
565
+ signature
566
+ };
567
+ assertEquals(await verifySignature(signed, options), null);
568
+ assertFalse(await verifyJsonLd(signed, options));
569
+ }
570
+ }
571
+ const relativeOptions = {
572
+ ...testVector,
573
+ signature: {
574
+ ...signature,
575
+ nonce: { "@id": "relative" },
576
+ quoteUri: "https://example.com/quoted"
577
+ }
578
+ };
579
+ const sigOptions = {
580
+ "@context": "https://w3id.org/identity/v1",
581
+ creator: signature.creator,
582
+ created: signature.created
583
+ };
584
+ assertEquals(await canonize({
585
+ ...sigOptions,
586
+ nonce: relativeOptions.signature.nonce,
587
+ quoteUri: relativeOptions.signature.quoteUri
588
+ }), await canonize(sigOptions));
589
+ assertEquals(await verifySignature(relativeOptions, options), null);
590
+ assertFalse(await verifyJsonLd(relativeOptions, options));
591
+ });
592
+ test("signing still rejects unmapped properties", async () => {
593
+ const input = {
594
+ ...document,
595
+ quoteUri: "https://example.com/quoted"
596
+ };
597
+ const options = { contextLoader: mockDocumentLoader };
598
+ await assertRejects(() => createSignature(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
599
+ await assertRejects(() => signJsonLd(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
600
+ });
601
+ test("verification still rejects malformed JSON-LD", async () => {
602
+ const malformed = {
603
+ ...testVector,
604
+ "@context": 42
605
+ };
606
+ const options = {
607
+ documentLoader: mockDocumentLoader,
608
+ contextLoader: mockDocumentLoader
609
+ };
610
+ assertEquals(await verifySignature(malformed, options), null);
611
+ assertEquals((await assertRejects(() => verifyJsonLd(malformed, options), Error)).name, "jsonld.SyntaxError");
612
+ });
613
+ test("Linked Data verification without created", async (t) => {
614
+ const options = {
615
+ documentLoader: mockDocumentLoader,
616
+ contextLoader: mockDocumentLoader
617
+ };
618
+ await t.step("verifies the independently signed options", async () => {
619
+ assertFalse(hasSignature(ldSignatureWithoutCreated));
620
+ assertEquals(await verifySignature(ldSignatureWithoutCreated, options), rsaPublicKey3);
621
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, options));
622
+ });
623
+ await t.step("uses normalization contexts with a restrictive loader", async () => {
624
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, {
625
+ ...options,
626
+ contextLoader: async (url) => {
627
+ if (url !== "https://w3id.org/security/v1" && url !== "https://w3id.org/security/data-integrity/v1") return await mockDocumentLoader(url);
628
+ throw new Error(`Unexpected context: ${url}`);
629
+ }
630
+ }));
631
+ });
632
+ await t.step("rejects tampering with the signed timestamp or content", async () => {
633
+ const inserted = {
634
+ ...ldSignatureWithoutCreated,
635
+ signature: {
636
+ ...ldSignatureWithoutCreated.signature,
637
+ created: "2024-09-12T16:50:46Z"
638
+ }
639
+ };
640
+ const removed = structuredClone(testVector);
641
+ Reflect.deleteProperty(removed.signature, "created");
642
+ const changed = structuredClone(testVector);
643
+ changed.signature.created = "2024-09-13T16:50:46Z";
644
+ const changedContent = structuredClone(ldSignatureWithoutCreated);
645
+ changedContent.object.content = "tampered";
646
+ for (const doc of [
647
+ inserted,
648
+ removed,
649
+ changed,
650
+ changedContent
651
+ ]) {
652
+ assertEquals(await verifySignature(doc, options), null);
653
+ assertFalse(await verifyJsonLd(doc, options));
654
+ }
655
+ });
656
+ await t.step("still rejects graph restructuring", async () => {
657
+ const { signature, ...document } = ldSignatureWithoutCreated;
658
+ await assertRejects(() => verifyJsonLd({
659
+ "@context": document["@context"],
660
+ "@graph": [document],
661
+ signature
662
+ }, options), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
663
+ });
664
+ });
665
+ test("Linked Data verification rejects malformed creator URLs", async () => {
666
+ let keyLoads = 0;
667
+ const options = {
668
+ documentLoader: (url) => {
669
+ keyLoads++;
670
+ return mockDocumentLoader(url);
671
+ },
672
+ contextLoader: mockDocumentLoader
673
+ };
674
+ for (const creator of [
675
+ "not a URL",
676
+ "",
677
+ "/keys/main",
678
+ "https://["
679
+ ]) for (const withCreated of [false, true]) {
680
+ const input = {
681
+ ...ldSignatureWithoutCreated,
682
+ signature: {
683
+ ...ldSignatureWithoutCreated.signature,
684
+ creator,
685
+ ...withCreated ? { created: "2024-09-12T16:50:46Z" } : {}
686
+ }
687
+ };
688
+ assert(hasVerifiableSignature(input));
689
+ assertEquals(await verifySignature(input, options), null);
690
+ assertFalse(await verifyJsonLd(input, options));
691
+ }
692
+ assertEquals(keyLoads, 0);
693
+ });
694
+ test("Linked Data verification distinguishes malformed and absent signatures", async () => {
695
+ const signature = {
696
+ type: "RsaSignature2017",
697
+ creator: "https://example.com/private-creator-sentinel#key",
698
+ signatureValue: "private-signature-sentinel"
699
+ };
700
+ assert(hasVerifiableSignature({ signature }));
701
+ assertFalse(hasSignature({ signature }));
702
+ for (const created of [
703
+ "2024-09-12T16:50:46Z",
704
+ "not a date",
705
+ ""
706
+ ]) {
707
+ const doc = { signature: {
708
+ ...signature,
709
+ created
710
+ } };
711
+ assert(hasVerifiableSignature(doc));
712
+ assert(hasSignature(doc));
713
+ }
714
+ const malformed = [
715
+ null,
716
+ [],
717
+ "signature",
718
+ {},
719
+ {
720
+ ...signature,
721
+ type: "OtherSignature"
722
+ },
723
+ {
724
+ ...signature,
725
+ type: ["RsaSignature2017"]
726
+ },
727
+ {
728
+ ...signature,
729
+ creator: {}
730
+ },
731
+ {
732
+ ...signature,
733
+ signatureValue: 1
734
+ },
735
+ ...[
736
+ void 0,
737
+ null,
738
+ 123,
739
+ {},
740
+ []
741
+ ].map((created) => ({
742
+ ...signature,
743
+ created
744
+ }))
745
+ ];
746
+ const records = [];
747
+ await configure({
748
+ sinks: { buffer: (record) => records.push(record) },
749
+ loggers: [{
750
+ category: [
751
+ "fedify",
752
+ "sig",
753
+ "ld"
754
+ ],
755
+ sinks: ["buffer"],
756
+ lowestLevel: "debug"
757
+ }, {
758
+ category: ["logtape", "meta"],
759
+ sinks: []
760
+ }],
761
+ reset: true
762
+ });
763
+ let keyLoads = 0;
764
+ const options = {
765
+ documentLoader: (url) => {
766
+ keyLoads++;
767
+ return mockDocumentLoader(url);
768
+ },
769
+ contextLoader: mockDocumentLoader
770
+ };
771
+ try {
772
+ for (const value of malformed) {
773
+ const doc = { signature: value };
774
+ assertFalse(hasVerifiableSignature(doc));
775
+ assertEquals(await verifySignature(doc, options), null);
776
+ }
777
+ assertEquals(keyLoads, 0);
778
+ assertEquals(records.length, malformed.length);
779
+ for (const record of records) {
780
+ assertEquals(record.level, "debug");
781
+ assertFalse(JSON.stringify(record).includes(signature.creator));
782
+ assertFalse(JSON.stringify(record).includes(signature.signatureValue));
783
+ }
784
+ assertEquals(records.at(-1)?.properties, {
785
+ signatureKind: "object",
786
+ signatureProperties: [
787
+ "created",
788
+ "creator",
789
+ "signatureValue",
790
+ "type"
791
+ ],
792
+ signaturePropertyCount: 4
793
+ });
794
+ for (const absent of [
795
+ null,
796
+ [],
797
+ 1,
798
+ {},
799
+ { type: "Create" }
800
+ ]) {
801
+ assertEquals(await verifySignature(absent, options), null);
802
+ assertFalse(hasVerifiableSignature(absent));
803
+ assertEquals(describeSignatureShape(absent), null);
804
+ }
805
+ assertEquals(records.length, malformed.length);
806
+ assertFalse(await verifyJsonLd({
807
+ ...ldSignatureWithoutCreated,
808
+ signature: {
809
+ ...signature,
810
+ created: 123
811
+ }
812
+ }, options));
813
+ assertEquals(records.length, malformed.length + 1);
814
+ assertEquals(keyLoads, 0);
815
+ } finally {
816
+ await reset();
817
+ }
818
+ const shape = describeSignatureShape({ signature: globalThis.Object.fromEntries(Array.from({ length: 30 }, (_, i) => [`field${i}`.padEnd(200, "x"), "secret"])) });
819
+ assertEquals(shape?.signaturePropertyCount, 30);
820
+ assertEquals(shape?.signatureProperties.length, 20);
821
+ assert(shape?.signatureProperties.every((name) => name.length === 80));
822
+ assertEquals(describeSignatureShape({ signature: null })?.signatureKind, "null");
823
+ assertEquals(describeSignatureShape({ signature: [] })?.signatureKind, "array");
824
+ });
263
825
  test("compactJsonLd() with restrictive context loader", async () => {
264
826
  const restrictiveContextLoader = async (resource) => {
265
827
  const url = new URL(resource).href;
@@ -764,7 +1326,10 @@ test("verifyJsonLd() rejects unsafe JSON-LD keywords", async () => {
764
1326
  signature: signed.signature
765
1327
  }]
766
1328
  ];
767
- for (const [keyword, jsonLd] of cases) await assertRejects(() => verifyJsonLd(jsonLd, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
1329
+ for (const [keyword, jsonLd] of cases) for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) await assertRejects(() => verifyJsonLd({
1330
+ ...jsonLd,
1331
+ ...extra
1332
+ }, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
768
1333
  });
769
1334
  test("compactJsonLd() rejects unsafe JSON-LD keywords inside signature objects", async () => {
770
1335
  const signed = await signJsonLd({
package/dist/sig/mod.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_http = require("../http-DrUG4fPS.cjs");
5
- const require_proof = require("../proof-DhaTTn-P.cjs");
4
+ const require_http = require("../http-BNaPJVnF.cjs");
5
+ const require_proof = require("../proof-Dbz6ApNP.cjs");
6
6
  exports.attachSignature = require_proof.attachSignature;
7
7
  exports.createProof = require_proof.createProof;
8
8
  exports.createSignature = require_proof.createSignature;
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "../http-DqZhyEso.cjs";
2
+ import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "../http-C8qLHs_Z.cjs";
3
3
  import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-B3hNQCG8.cjs";
4
- import { _ as hasSignatureLike, a as createProof, b as verifySignature, c as verifyObject, d as SignJsonLdOptions, f as VerifyJsonLdOptions, g as detachSignature, h as createSignature, i as VerifyProofOptions, l as verifyProof, m as attachSignature, n as SignObjectOptions, o as hasProofLike, p as VerifySignatureOptions, r as VerifyObjectOptions, s as signObject, t as CreateProofOptions, u as CreateSignatureOptions, v as signJsonLd, y as verifyJsonLd } from "../mod-D2JyWtW3.cjs";
5
- export { AcceptSignatureMember, AcceptSignatureParameters, CreateProofOptions, CreateSignatureOptions, DoesActorOwnKeyOptions, FetchKeyDetailedResult, FetchKeyErrorResult, FetchKeyOptions, FetchKeyResult, FulfillAcceptSignatureResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, Rfc9421SignRequestOptions, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestDetailedResult, VerifyRequestFailureReason, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, fetchKeyDetailed, formatAcceptSignature, fulfillAcceptSignature, generateCryptoKeyPair, getKeyOwner, hasProofLike, hasSignatureLike, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };
4
+ import { S as verifySignature, _ as createSignature, a as VerifyObjectOptions, b as signJsonLd, c as hasProofLike, d as verifyProof, f as CreateSignatureOptions, g as attachSignature, h as VerifySignatureOptions, i as SignObjectOptions, l as signObject, m as VerifyJsonLdOptions, n as CryptoKeyPairLike, o as VerifyProofOptions, p as SignJsonLdOptions, r as CreateProofOptions, s as createProof, t as CryptoKeyLike, u as verifyObject, v as detachSignature, x as verifyJsonLd, y as hasSignatureLike } from "../mod-INjDw-m0.cjs";
5
+ export { AcceptSignatureMember, AcceptSignatureParameters, CreateProofOptions, CreateSignatureOptions, CryptoKeyLike, CryptoKeyPairLike, DoesActorOwnKeyOptions, FetchKeyDetailedResult, FetchKeyErrorResult, FetchKeyOptions, FetchKeyResult, FulfillAcceptSignatureResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, Rfc9421SignRequestOptions, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestDetailedResult, VerifyRequestFailureReason, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, fetchKeyDetailed, formatAcceptSignature, fulfillAcceptSignature, generateCryptoKeyPair, getKeyOwner, hasProofLike, hasSignatureLike, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };