@fedify/fedify 2.4.6-dev.2628 → 2.4.6

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 (133) hide show
  1. package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
  2. package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
  3. package/dist/callback-DPDs_dxC.d.mts +5280 -0
  4. package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
  5. package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
  6. package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
  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.cjs +1 -1
  10. package/dist/compat/mod.d.cts +1 -1
  11. package/dist/compat/mod.d.ts +1 -1
  12. package/dist/compat/mod.js +1 -1
  13. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  14. package/dist/compat/transformers.test.mjs +1 -1
  15. package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
  16. package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
  17. package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
  18. package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
  19. package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
  20. package/dist/federation/attachment-responses.test.d.mts +2 -0
  21. package/dist/federation/attachment-responses.test.mjs +182 -0
  22. package/dist/federation/builder.test.mjs +1 -1
  23. package/dist/federation/compound-fanout.test.mjs +4 -4
  24. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  25. package/dist/federation/delivery-attachments.test.mjs +288 -0
  26. package/dist/federation/handler-compound-proof.test.mjs +3 -3
  27. package/dist/federation/handler.test.mjs +206 -14
  28. package/dist/federation/hashlink-media.test.mjs +2 -2
  29. package/dist/federation/idempotency.test.mjs +2 -2
  30. package/dist/federation/inbox-report.test.mjs +5 -5
  31. package/dist/federation/inbox.test.mjs +1 -1
  32. package/dist/federation/metrics.test.mjs +1 -1
  33. package/dist/federation/middleware.test.mjs +1188 -13
  34. package/dist/federation/mod.cjs +1 -1
  35. package/dist/federation/mod.d.cts +3 -3
  36. package/dist/federation/mod.d.ts +3 -3
  37. package/dist/federation/mod.js +1 -1
  38. package/dist/federation/outgoing-proof.test.mjs +4 -4
  39. package/dist/federation/portable-actor.test.mjs +3 -3
  40. package/dist/federation/portable-chain.test.mjs +3 -3
  41. package/dist/federation/portable-collection.test.mjs +4 -4
  42. package/dist/federation/portable-delivery.test.mjs +2 -2
  43. package/dist/federation/portable-gateway-keys.test.mjs +5 -5
  44. package/dist/federation/portable-inbox.test.mjs +4 -4
  45. package/dist/federation/portable-parse-uri.test.mjs +1 -1
  46. package/dist/federation/portable-route-activity.test.mjs +2 -2
  47. package/dist/federation/portable.test.mjs +3 -3
  48. package/dist/federation/send.test.mjs +293 -3
  49. package/dist/federation/tasks/enqueue.test.mjs +1 -1
  50. package/dist/federation/tasks/tasks.test.mjs +2 -2
  51. package/dist/federation/temporal.test.mjs +25 -1
  52. package/dist/federation/webfinger.test.mjs +1 -1
  53. package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
  54. package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
  55. package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
  56. package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
  57. package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
  58. package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
  59. package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
  60. package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
  61. package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
  62. package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
  63. package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
  64. package/dist/ld-signature-D1tFSFK8.mjs +23 -0
  65. package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
  66. package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
  67. package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
  68. package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
  69. package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
  70. package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
  71. package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
  72. package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
  73. package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
  74. package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
  75. package/dist/mod.cjs +6 -6
  76. package/dist/mod.d.cts +8 -8
  77. package/dist/mod.d.ts +8 -8
  78. package/dist/mod.js +6 -6
  79. package/dist/nodeinfo/client.test.mjs +432 -4
  80. package/dist/nodeinfo/handler.test.mjs +1 -1
  81. package/dist/nodeinfo/mod.cjs +1 -1
  82. package/dist/nodeinfo/mod.d.cts +1 -1
  83. package/dist/nodeinfo/mod.d.ts +1 -1
  84. package/dist/nodeinfo/mod.js +1 -1
  85. package/dist/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
  86. package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
  87. package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
  88. package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
  89. package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
  90. package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
  91. package/dist/portable-verifier-CPA86vIP.js +22 -0
  92. package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
  93. package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
  94. package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
  95. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  96. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  97. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  98. package/dist/sig/compound-proof.test.mjs +3 -3
  99. package/dist/sig/http.test.mjs +2 -2
  100. package/dist/sig/key-types.test.d.mts +162 -0
  101. package/dist/sig/key-types.test.mjs +8 -0
  102. package/dist/sig/key.test.mjs +1 -1
  103. package/dist/sig/ld.test.mjs +572 -7
  104. package/dist/sig/mitra-receive-interop.test.mjs +4 -4
  105. package/dist/sig/mitra-send-interop.test.mjs +3 -3
  106. package/dist/sig/mod.cjs +2 -2
  107. package/dist/sig/mod.d.cts +3 -3
  108. package/dist/sig/mod.d.ts +3 -3
  109. package/dist/sig/mod.js +2 -2
  110. package/dist/sig/owner.test.mjs +1 -1
  111. package/dist/sig/portable-collection.test.mjs +1 -1
  112. package/dist/sig/portable-interop.test.mjs +3 -3
  113. package/dist/sig/portable-key.test.mjs +5 -5
  114. package/dist/sig/proof.test.mjs +100 -6
  115. package/dist/sig/tootik-request-interop.test.mjs +4 -4
  116. package/dist/sig/tootik-send-interop.test.mjs +3 -3
  117. package/dist/sig/verification.test.mjs +3 -3
  118. package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
  119. package/dist/testing/kv.test.mjs +1 -1
  120. package/dist/testing/mod.d.mts +3 -5045
  121. package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
  122. package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
  123. package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
  124. package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
  125. package/dist/utils/docloader.test.mjs +2 -2
  126. package/dist/utils/kv-cache.test.mjs +1 -1
  127. package/dist/utils/mod.cjs +1 -1
  128. package/dist/utils/mod.d.cts +1 -1
  129. package/dist/utils/mod.d.ts +1 -1
  130. package/dist/utils/mod.js +1 -1
  131. package/dist/utils/portable-verifier.test.d.mts +2 -0
  132. package/dist/utils/portable-verifier.test.mjs +126 -0
  133. package/package.json +6 -6
@@ -8,11 +8,14 @@ import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
8
8
  import { t as assertThrows } from "../assert_throws-BYITOvPO.mjs";
9
9
  import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
10
10
  import { t as assert } from "../assert-D1Eafmd_.mjs";
11
- import { C as generateCryptoKeyPair, 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-DJZrjNuN.mjs";
11
+ import { T as generateCryptoKeyPair, _ 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-BGnZDnia.mjs";
12
12
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
13
- import { CryptographicKey } from "@fedify/vocab";
13
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-D1tFSFK8.mjs";
14
+ import { configure, reset } from "@logtape/logtape";
15
+ import { Create, CryptographicKey, Note } from "@fedify/vocab";
14
16
  import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
15
17
  import { encodeBase64 } from "byte-encodings/base64";
18
+ import jsonld from "@fedify/vocab-runtime/jsonld";
16
19
  //#region src/sig/ld.test.ts
17
20
  test("isInvalidUrlTypeError()", () => {
18
21
  assert(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("Invalid URL string.")));
@@ -27,22 +30,84 @@ test("isInvalidUrlTypeError()", () => {
27
30
  });
28
31
  test("attachSignature()", () => {
29
32
  const sig = {
30
- "@context": "https://w3id.org/identity/v1",
33
+ "@context": "https://w3id.org/security/v1",
31
34
  type: "RsaSignature2017",
32
35
  creator: "https://activitypub.academy/users/brauca_darradiul#main-key",
33
36
  created: "2024-09-12T16:50:46Z",
34
37
  signatureValue: "asdf"
35
38
  };
39
+ const signatureTerm = { "signature": "https://w3id.org/security#signature" };
36
40
  const doc = {
37
41
  "@context": "https://www.w3.org/ns/activitystreams",
38
42
  id: "https://example.com/1"
39
43
  };
40
44
  assertEquals(attachSignature(doc, sig), {
41
45
  ...doc,
46
+ "@context": ["https://www.w3.org/ns/activitystreams", signatureTerm],
47
+ signature: sig
48
+ });
49
+ const arrayDoc = {
50
+ "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
51
+ id: "https://example.com/1"
52
+ };
53
+ assertEquals(attachSignature(arrayDoc, sig), {
54
+ ...arrayDoc,
55
+ "@context": [...arrayDoc["@context"], signatureTerm],
56
+ signature: sig
57
+ });
58
+ for (const context of [
59
+ ["https://w3id.org/identity/v1", "https://www.w3.org/ns/activitystreams"],
60
+ ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
61
+ ["https://www.w3.org/ns/activitystreams", signatureTerm],
62
+ { "signature": "https://w3id.org/security#signature" }
63
+ ]) {
64
+ const contextDoc = {
65
+ "@context": context,
66
+ id: "https://example.com/1"
67
+ };
68
+ assertEquals(attachSignature(contextDoc, sig), {
69
+ ...contextDoc,
70
+ signature: sig
71
+ });
72
+ }
73
+ assertEquals(attachSignature({
74
+ "@context": null,
75
+ id: "https://example.com/1"
76
+ }, sig), {
77
+ "@context": [signatureTerm],
78
+ id: "https://example.com/1",
79
+ signature: sig
80
+ });
81
+ const resetDoc = {
82
+ "@context": [
83
+ "https://w3id.org/security/v1",
84
+ null,
85
+ "https://www.w3.org/ns/activitystreams"
86
+ ],
87
+ id: "https://example.com/1"
88
+ };
89
+ assertEquals(attachSignature(resetDoc, sig), {
90
+ ...resetDoc,
91
+ "@context": [...resetDoc["@context"], signatureTerm],
92
+ signature: sig
93
+ });
94
+ const disabledTermDoc = {
95
+ "@context": [{ "signature": { "@id": null } }, "https://www.w3.org/ns/activitystreams"],
96
+ id: "https://example.com/1"
97
+ };
98
+ assertEquals(attachSignature(disabledTermDoc, sig), {
99
+ ...disabledTermDoc,
100
+ "@context": [...disabledTermDoc["@context"], signatureTerm],
101
+ signature: sig
102
+ });
103
+ assertEquals(attachSignature({ id: "https://example.com/1" }, sig), {
104
+ id: "https://example.com/1",
105
+ "@context": [signatureTerm],
42
106
  signature: sig
43
107
  });
44
108
  assertThrows(() => attachSignature(null, sig), TypeError);
45
109
  assertThrows(() => attachSignature(1234, sig), TypeError);
110
+ assertThrows(() => attachSignature([], sig), TypeError);
46
111
  });
47
112
  test("createSignature()", async () => {
48
113
  const doc = {
@@ -50,7 +115,11 @@ test("createSignature()", async () => {
50
115
  id: "https://example.com/1",
51
116
  type: "Create"
52
117
  };
53
- assertEquals(await verifySignature(attachSignature(doc, await createSignature(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader })), {
118
+ const sig = await createSignature(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
119
+ assertEquals(typeof sig.created, "string");
120
+ assert(hasSignature(attachSignature(doc, sig)));
121
+ assertEquals(sig["@context"], "https://w3id.org/security/v1");
122
+ assertEquals(await verifySignature(attachSignature(doc, sig), {
54
123
  documentLoader: mockDocumentLoader,
55
124
  contextLoader: mockDocumentLoader
56
125
  }), rsaPublicKey2);
@@ -58,12 +127,15 @@ test("createSignature()", async () => {
58
127
  assertRejects(() => createSignature(doc, ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader }), TypeError);
59
128
  });
60
129
  test("signJsonLd()", async () => {
61
- assert(await verifyJsonLd(await signJsonLd({
130
+ const signed = await signJsonLd({
62
131
  "@context": "https://www.w3.org/ns/activitystreams",
63
132
  id: "https://example.com/1",
64
133
  type: "Create",
65
134
  actor: "https://example.com/person2"
66
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }), {
135
+ }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader });
136
+ assert(hasSignature(signed));
137
+ assertEquals(typeof signed.signature.created, "string");
138
+ assert(await verifyJsonLd(signed, {
67
139
  documentLoader: mockDocumentLoader,
68
140
  contextLoader: mockDocumentLoader
69
141
  }));
@@ -110,6 +182,135 @@ test("hasSignatureLike()", () => {
110
182
  } }));
111
183
  assertFalse(hasSignatureLike(null));
112
184
  });
185
+ test("signJsonLd() defines the signature term when the context lacks it", async () => {
186
+ const signed = await signJsonLd({
187
+ "@context": "https://www.w3.org/ns/activitystreams",
188
+ id: "https://example.com/notes/1",
189
+ type: "Note",
190
+ content: "Hello"
191
+ }, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
192
+ assert(Array.isArray(signed["@context"]));
193
+ assertEquals(signed["@context"][1], { "signature": "https://w3id.org/security#signature" });
194
+ assert((await jsonld.canonize(signed, {
195
+ format: "application/n-quads",
196
+ documentLoader: mockDocumentLoader
197
+ })).includes("<https://w3id.org/security#signature>"));
198
+ assertEquals(await verifySignature(signed, {
199
+ documentLoader: mockDocumentLoader,
200
+ contextLoader: mockDocumentLoader
201
+ }), rsaPublicKey2);
202
+ });
203
+ test("signJsonLd() signs documents that use the signature term", async () => {
204
+ const signatureTerm = { "signature": "https://w3id.org/security#signature" };
205
+ for (const object of [{
206
+ type: "Note",
207
+ signature: "nested value"
208
+ }, { type: "signature" }]) {
209
+ const doc = {
210
+ "@context": ["https://www.w3.org/ns/activitystreams", { "@vocab": "https://example.com/" }],
211
+ id: "https://example.com/1",
212
+ type: "Create",
213
+ object
214
+ };
215
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
216
+ assertEquals(signed["@context"], [...doc["@context"], signatureTerm]);
217
+ assertEquals(signed["object"], object);
218
+ assertEquals(await verifySignature(signed, {
219
+ documentLoader: mockDocumentLoader,
220
+ contextLoader: mockDocumentLoader
221
+ }), rsaPublicKey2);
222
+ }
223
+ });
224
+ test("signJsonLd() does not share the inline signature definition", async () => {
225
+ const doc = {
226
+ "@context": "https://www.w3.org/ns/activitystreams",
227
+ id: "https://example.com/notes/1",
228
+ type: "Note"
229
+ };
230
+ const firstContext = (await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }))["@context"];
231
+ firstContext[1]["signature"] = "https://example.com/signature";
232
+ assertEquals((await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }))["@context"][1], { "signature": "https://w3id.org/security#signature" });
233
+ });
234
+ test("signJsonLd() respects a protected null signature definition", async () => {
235
+ for (const context of [{
236
+ "@protected": true,
237
+ "signature": { "@id": null }
238
+ }, { "signature": {
239
+ "@id": null,
240
+ "@protected": true
241
+ } }]) {
242
+ const doc = {
243
+ "@context": ["https://www.w3.org/ns/activitystreams", context],
244
+ id: "https://example.com/1",
245
+ type: "Note"
246
+ };
247
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
248
+ assertEquals(signed["@context"], doc["@context"]);
249
+ assertEquals(await verifySignature(signed, {
250
+ documentLoader: mockDocumentLoader,
251
+ contextLoader: mockDocumentLoader
252
+ }), rsaPublicKey2);
253
+ }
254
+ });
255
+ test("signJsonLd() respects protection from imported contexts", async () => {
256
+ const importUrl = "https://example.com/contexts/imported-protected";
257
+ const contextLoader = async (url) => {
258
+ if (new URL(url).href === importUrl) return {
259
+ contextUrl: null,
260
+ documentUrl: url,
261
+ document: { "@context": {
262
+ "@protected": true,
263
+ "name": "https://example.com/name"
264
+ } }
265
+ };
266
+ return await mockDocumentLoader(url);
267
+ };
268
+ for (const signature of [null, { "@id": null }]) {
269
+ const doc = {
270
+ "@context": ["https://www.w3.org/ns/activitystreams", {
271
+ "@import": importUrl,
272
+ signature
273
+ }],
274
+ id: "https://example.com/1",
275
+ type: "Note",
276
+ name: "Alice"
277
+ };
278
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader });
279
+ assertEquals(signed["@context"], doc["@context"]);
280
+ assertEquals(await verifySignature(signed, {
281
+ documentLoader: mockDocumentLoader,
282
+ contextLoader
283
+ }), rsaPublicKey2);
284
+ }
285
+ });
286
+ test("signJsonLd() leaves unrecognized remote contexts unchanged", async () => {
287
+ const contextUrl = "https://example.com/contexts/custom";
288
+ const contextLoader = async (url) => {
289
+ if (new URL(url).href === contextUrl) return {
290
+ contextUrl: null,
291
+ documentUrl: url,
292
+ document: { "@context": {
293
+ "@protected": true,
294
+ "signature": {
295
+ "@id": "https://w3id.org/security#signature",
296
+ "@type": "@id"
297
+ }
298
+ } }
299
+ };
300
+ return await mockDocumentLoader(url);
301
+ };
302
+ const doc = {
303
+ "@context": ["https://www.w3.org/ns/activitystreams", contextUrl],
304
+ id: "https://example.com/1",
305
+ type: "Note"
306
+ };
307
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader });
308
+ assertEquals(signed["@context"], doc["@context"]);
309
+ assertEquals(await verifySignature(signed, {
310
+ documentLoader: mockDocumentLoader,
311
+ contextLoader
312
+ }), rsaPublicKey2);
313
+ });
113
314
  const document = {
114
315
  "@context": ["https://www.w3.org/ns/activitystreams", {
115
316
  "ostatus": "http://ostatus.org#",
@@ -395,6 +596,367 @@ test("verifyJsonLd() records verification duration metric", async (t) => {
395
596
  assertFalse("ld_signatures.type" in measurements[0].attributes);
396
597
  });
397
598
  });
599
+ test("verifyJsonLd() tolerates unmapped document and signature properties", async () => {
600
+ const options = {
601
+ documentLoader: mockDocumentLoader,
602
+ contextLoader: mockDocumentLoader
603
+ };
604
+ const canonize = (input) => jsonld.canonize(input, {
605
+ format: "application/n-quads",
606
+ documentLoader: mockDocumentLoader,
607
+ safe: false
608
+ });
609
+ const withQuote = {
610
+ ...document,
611
+ object: {
612
+ ...document.object,
613
+ quoteUri: "https://example.com/quoted"
614
+ }
615
+ };
616
+ const sigOptions = {
617
+ "@context": "https://w3id.org/identity/v1",
618
+ creator: signature.creator,
619
+ created: signature.created
620
+ };
621
+ const extraOption = { quoteUri: "https://example.com/quoted" };
622
+ assertEquals(await canonize(withQuote), await canonize(document));
623
+ assertEquals(await canonize({
624
+ ...sigOptions,
625
+ ...extraOption
626
+ }), await canonize(sigOptions));
627
+ for (const input of [withQuote, {
628
+ ...sigOptions,
629
+ ...extraOption
630
+ }]) await assertRejects(() => jsonld.canonize(input, {
631
+ format: "application/n-quads",
632
+ documentLoader: mockDocumentLoader,
633
+ safe: true
634
+ }), Error, "Safe mode validation error.");
635
+ const expectedKey = await verifySignature(testVector, options);
636
+ assertInstanceOf(expectedKey, CryptographicKey);
637
+ for (const signed of [
638
+ {
639
+ ...withQuote,
640
+ signature
641
+ },
642
+ {
643
+ ...document,
644
+ signature: {
645
+ ...signature,
646
+ ...extraOption
647
+ }
648
+ },
649
+ {
650
+ ...withQuote,
651
+ signature: {
652
+ ...signature,
653
+ ...extraOption
654
+ }
655
+ }
656
+ ]) {
657
+ assertEquals(await verifySignature(signed, options), expectedKey);
658
+ assert(await verifyJsonLd(signed, options));
659
+ }
660
+ const tampered = {
661
+ ...withQuote,
662
+ object: {
663
+ ...withQuote.object,
664
+ content: "<p>Forged</p>"
665
+ },
666
+ signature
667
+ };
668
+ assertEquals(await verifySignature(tampered, options), null);
669
+ assertFalse(await verifyJsonLd(tampered, options));
670
+ });
671
+ test("verifyJsonLd() rejects relative IRIs despite unmapped properties", async () => {
672
+ const options = {
673
+ documentLoader: mockDocumentLoader,
674
+ contextLoader: mockDocumentLoader
675
+ };
676
+ const canonize = (input) => jsonld.canonize(input, {
677
+ format: "application/n-quads",
678
+ documentLoader: mockDocumentLoader,
679
+ safe: false
680
+ });
681
+ const withRelativeUrl = {
682
+ ...document,
683
+ object: {
684
+ ...document.object,
685
+ url: [document.object.url, "/evil"]
686
+ }
687
+ };
688
+ const note = await (await Create.fromJsonLd(withRelativeUrl, options)).getObject(options);
689
+ assertInstanceOf(note, Note);
690
+ assertEquals(note.urls.map((url) => url instanceof URL ? url.href : null), [document.object.url, "https://activitypub.academy/evil"]);
691
+ for (const input of [withRelativeUrl, {
692
+ ...document,
693
+ "https://example.com/extension": { "@id": "relative" }
694
+ }]) {
695
+ assertEquals(await canonize(input), await canonize(document));
696
+ for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) {
697
+ const signed = {
698
+ ...input,
699
+ ...extra,
700
+ signature
701
+ };
702
+ assertEquals(await verifySignature(signed, options), null);
703
+ assertFalse(await verifyJsonLd(signed, options));
704
+ }
705
+ }
706
+ const relativeOptions = {
707
+ ...testVector,
708
+ signature: {
709
+ ...signature,
710
+ nonce: { "@id": "relative" },
711
+ quoteUri: "https://example.com/quoted"
712
+ }
713
+ };
714
+ const sigOptions = {
715
+ "@context": "https://w3id.org/identity/v1",
716
+ creator: signature.creator,
717
+ created: signature.created
718
+ };
719
+ assertEquals(await canonize({
720
+ ...sigOptions,
721
+ nonce: relativeOptions.signature.nonce,
722
+ quoteUri: relativeOptions.signature.quoteUri
723
+ }), await canonize(sigOptions));
724
+ assertEquals(await verifySignature(relativeOptions, options), null);
725
+ assertFalse(await verifyJsonLd(relativeOptions, options));
726
+ });
727
+ test("signing still rejects unmapped properties", async () => {
728
+ const input = {
729
+ ...document,
730
+ quoteUri: "https://example.com/quoted"
731
+ };
732
+ const options = { contextLoader: mockDocumentLoader };
733
+ await assertRejects(() => createSignature(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
734
+ await assertRejects(() => signJsonLd(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
735
+ });
736
+ test("verification still rejects malformed JSON-LD", async () => {
737
+ const malformed = {
738
+ ...testVector,
739
+ "@context": 42
740
+ };
741
+ const options = {
742
+ documentLoader: mockDocumentLoader,
743
+ contextLoader: mockDocumentLoader
744
+ };
745
+ assertEquals(await verifySignature(malformed, options), null);
746
+ assertEquals((await assertRejects(() => verifyJsonLd(malformed, options), Error)).name, "jsonld.SyntaxError");
747
+ });
748
+ test("Linked Data verification without created", async (t) => {
749
+ const options = {
750
+ documentLoader: mockDocumentLoader,
751
+ contextLoader: mockDocumentLoader
752
+ };
753
+ await t.step("verifies the independently signed options", async () => {
754
+ assertFalse(hasSignature(ldSignatureWithoutCreated));
755
+ assertEquals(await verifySignature(ldSignatureWithoutCreated, options), rsaPublicKey3);
756
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, options));
757
+ });
758
+ await t.step("uses normalization contexts with a restrictive loader", async () => {
759
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, {
760
+ ...options,
761
+ contextLoader: async (url) => {
762
+ if (url !== "https://w3id.org/security/v1" && url !== "https://w3id.org/security/data-integrity/v1") return await mockDocumentLoader(url);
763
+ throw new Error(`Unexpected context: ${url}`);
764
+ }
765
+ }));
766
+ });
767
+ await t.step("rejects tampering with the signed timestamp or content", async () => {
768
+ const inserted = {
769
+ ...ldSignatureWithoutCreated,
770
+ signature: {
771
+ ...ldSignatureWithoutCreated.signature,
772
+ created: "2024-09-12T16:50:46Z"
773
+ }
774
+ };
775
+ const removed = structuredClone(testVector);
776
+ Reflect.deleteProperty(removed.signature, "created");
777
+ const changed = structuredClone(testVector);
778
+ changed.signature.created = "2024-09-13T16:50:46Z";
779
+ const changedContent = structuredClone(ldSignatureWithoutCreated);
780
+ changedContent.object.content = "tampered";
781
+ for (const doc of [
782
+ inserted,
783
+ removed,
784
+ changed,
785
+ changedContent
786
+ ]) {
787
+ assertEquals(await verifySignature(doc, options), null);
788
+ assertFalse(await verifyJsonLd(doc, options));
789
+ }
790
+ });
791
+ await t.step("still rejects graph restructuring", async () => {
792
+ const { signature, ...document } = ldSignatureWithoutCreated;
793
+ await assertRejects(() => verifyJsonLd({
794
+ "@context": document["@context"],
795
+ "@graph": [document],
796
+ signature
797
+ }, options), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
798
+ });
799
+ });
800
+ test("Linked Data verification rejects malformed creator URLs", async () => {
801
+ let keyLoads = 0;
802
+ const options = {
803
+ documentLoader: (url) => {
804
+ keyLoads++;
805
+ return mockDocumentLoader(url);
806
+ },
807
+ contextLoader: mockDocumentLoader
808
+ };
809
+ for (const creator of [
810
+ "not a URL",
811
+ "",
812
+ "/keys/main",
813
+ "https://["
814
+ ]) for (const withCreated of [false, true]) {
815
+ const input = {
816
+ ...ldSignatureWithoutCreated,
817
+ signature: {
818
+ ...ldSignatureWithoutCreated.signature,
819
+ creator,
820
+ ...withCreated ? { created: "2024-09-12T16:50:46Z" } : {}
821
+ }
822
+ };
823
+ assert(hasVerifiableSignature(input));
824
+ assertEquals(await verifySignature(input, options), null);
825
+ assertFalse(await verifyJsonLd(input, options));
826
+ }
827
+ assertEquals(keyLoads, 0);
828
+ });
829
+ test("Linked Data verification distinguishes malformed and absent signatures", async () => {
830
+ const signature = {
831
+ type: "RsaSignature2017",
832
+ creator: "https://example.com/private-creator-sentinel#key",
833
+ signatureValue: "private-signature-sentinel"
834
+ };
835
+ assert(hasVerifiableSignature({ signature }));
836
+ assertFalse(hasSignature({ signature }));
837
+ for (const created of [
838
+ "2024-09-12T16:50:46Z",
839
+ "not a date",
840
+ ""
841
+ ]) {
842
+ const doc = { signature: {
843
+ ...signature,
844
+ created
845
+ } };
846
+ assert(hasVerifiableSignature(doc));
847
+ assert(hasSignature(doc));
848
+ }
849
+ const malformed = [
850
+ null,
851
+ [],
852
+ "signature",
853
+ {},
854
+ {
855
+ ...signature,
856
+ type: "OtherSignature"
857
+ },
858
+ {
859
+ ...signature,
860
+ type: ["RsaSignature2017"]
861
+ },
862
+ {
863
+ ...signature,
864
+ creator: {}
865
+ },
866
+ {
867
+ ...signature,
868
+ signatureValue: 1
869
+ },
870
+ ...[
871
+ void 0,
872
+ null,
873
+ 123,
874
+ {},
875
+ []
876
+ ].map((created) => ({
877
+ ...signature,
878
+ created
879
+ }))
880
+ ];
881
+ const records = [];
882
+ await configure({
883
+ sinks: { buffer: (record) => records.push(record) },
884
+ loggers: [{
885
+ category: [
886
+ "fedify",
887
+ "sig",
888
+ "ld"
889
+ ],
890
+ sinks: ["buffer"],
891
+ lowestLevel: "debug"
892
+ }, {
893
+ category: ["logtape", "meta"],
894
+ sinks: []
895
+ }],
896
+ reset: true
897
+ });
898
+ let keyLoads = 0;
899
+ const options = {
900
+ documentLoader: (url) => {
901
+ keyLoads++;
902
+ return mockDocumentLoader(url);
903
+ },
904
+ contextLoader: mockDocumentLoader
905
+ };
906
+ try {
907
+ for (const value of malformed) {
908
+ const doc = { signature: value };
909
+ assertFalse(hasVerifiableSignature(doc));
910
+ assertEquals(await verifySignature(doc, options), null);
911
+ }
912
+ assertEquals(keyLoads, 0);
913
+ assertEquals(records.length, malformed.length);
914
+ for (const record of records) {
915
+ assertEquals(record.level, "debug");
916
+ assertFalse(JSON.stringify(record).includes(signature.creator));
917
+ assertFalse(JSON.stringify(record).includes(signature.signatureValue));
918
+ }
919
+ assertEquals(records.at(-1)?.properties, {
920
+ signatureKind: "object",
921
+ signatureProperties: [
922
+ "created",
923
+ "creator",
924
+ "signatureValue",
925
+ "type"
926
+ ],
927
+ signaturePropertyCount: 4
928
+ });
929
+ for (const absent of [
930
+ null,
931
+ [],
932
+ 1,
933
+ {},
934
+ { type: "Create" }
935
+ ]) {
936
+ assertEquals(await verifySignature(absent, options), null);
937
+ assertFalse(hasVerifiableSignature(absent));
938
+ assertEquals(describeSignatureShape(absent), null);
939
+ }
940
+ assertEquals(records.length, malformed.length);
941
+ assertFalse(await verifyJsonLd({
942
+ ...ldSignatureWithoutCreated,
943
+ signature: {
944
+ ...signature,
945
+ created: 123
946
+ }
947
+ }, options));
948
+ assertEquals(records.length, malformed.length + 1);
949
+ assertEquals(keyLoads, 0);
950
+ } finally {
951
+ await reset();
952
+ }
953
+ const shape = describeSignatureShape({ signature: globalThis.Object.fromEntries(Array.from({ length: 30 }, (_, i) => [`field${i}`.padEnd(200, "x"), "secret"])) });
954
+ assertEquals(shape?.signaturePropertyCount, 30);
955
+ assertEquals(shape?.signatureProperties.length, 20);
956
+ assert(shape?.signatureProperties.every((name) => name.length === 80));
957
+ assertEquals(describeSignatureShape({ signature: null })?.signatureKind, "null");
958
+ assertEquals(describeSignatureShape({ signature: [] })?.signatureKind, "array");
959
+ });
398
960
  test("compactJsonLd() with restrictive context loader", async () => {
399
961
  const restrictiveContextLoader = async (resource) => {
400
962
  const url = new URL(resource).href;
@@ -899,7 +1461,10 @@ test("verifyJsonLd() rejects unsafe JSON-LD keywords", async () => {
899
1461
  signature: signed.signature
900
1462
  }]
901
1463
  ];
902
- for (const [keyword, jsonLd] of cases) await assertRejects(() => verifyJsonLd(jsonLd, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
1464
+ for (const [keyword, jsonLd] of cases) for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) await assertRejects(() => verifyJsonLd({
1465
+ ...jsonLd,
1466
+ ...extra
1467
+ }, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
903
1468
  });
904
1469
  test("compactJsonLd() rejects unsafe JSON-LD keywords inside signature objects", async () => {
905
1470
  const signed = await signJsonLd({
@@ -5,10 +5,10 @@ import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
6
6
  import "../std__assert-DvMDRPes.mjs";
7
7
  import { t as assert } from "../assert-D1Eafmd_.mjs";
8
- import { c as verifyPortableObjectProof } from "../proof-DW0FK6Cp.mjs";
9
- import { m as verifyRequestDetailed } from "../http-BSARoDPh.mjs";
10
- import { o as createFederation } from "../middleware-DblGj642.mjs";
11
- import { t as doesActorOwnKey } from "../owner-2vfqhUJw.mjs";
8
+ import { c as verifyPortableObjectProof } from "../proof-C4pwAF2k.mjs";
9
+ import { m as verifyRequestDetailed } from "../http-B6sfb5xN.mjs";
10
+ import { o as createFederation } from "../middleware-mRXKHq68.mjs";
11
+ import { t as doesActorOwnKey } from "../owner-DEiBiiqR.mjs";
12
12
  import { Create, Person } from "@fedify/vocab";
13
13
  import { canonicalizePortableUri, decodeMultibase, importDidKey } from "@fedify/vocab-runtime";
14
14
  import { mockDocumentLoader, test } from "@fedify/fixture";
@@ -4,9 +4,9 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
5
5
  import "../std__assert-DvMDRPes.mjs";
6
6
  import { t as assert } from "../assert-D1Eafmd_.mjs";
7
- import { c as verifyPortableObjectProof } from "../proof-DW0FK6Cp.mjs";
8
- import { m as verifyRequestDetailed } from "../http-BSARoDPh.mjs";
9
- import { t as doesActorOwnKey } from "../owner-2vfqhUJw.mjs";
7
+ import { c as verifyPortableObjectProof } from "../proof-C4pwAF2k.mjs";
8
+ import { m as verifyRequestDetailed } from "../http-B6sfb5xN.mjs";
9
+ import { t as doesActorOwnKey } from "../owner-DEiBiiqR.mjs";
10
10
  import { Create } from "@fedify/vocab";
11
11
  import { canonicalizePortableUri, decodeMultibase, fromCompatibleEf61Id, importDidKey } from "@fedify/vocab-runtime";
12
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
package/dist/sig/mod.cjs CHANGED
@@ -1,7 +1,7 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const require_http = require("../http-CeVcKQMZ.cjs");
4
- const require_portable_collection = require("../portable-collection-Cs--KD5A.cjs");
3
+ const require_http = require("../http-Tj9eQ_rd.cjs");
4
+ const require_portable_collection = require("../portable-collection--h11WDIi.cjs");
5
5
  exports.attachSignature = require_http.attachSignature;
6
6
  exports.createProof = require_http.createProof;
7
7
  exports.createSignature = require_http.createSignature;