@fedify/fedify 2.1.30 → 2.1.32

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 (104) hide show
  1. package/dist/attachment-arrays-DZ4JHJD8.mjs +111 -0
  2. package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
  3. package/dist/callback-BARPujV7.d.mts +2388 -0
  4. package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
  5. package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
  6. package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +254 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/transformers.test.mjs +1 -1
  12. package/dist/{context-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
  13. package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
  14. package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
  15. package/dist/docloader-DUXr9k_O.mjs +124 -0
  16. package/dist/federation/attachment-responses.test.d.mts +2 -0
  17. package/dist/federation/attachment-responses.test.mjs +182 -0
  18. package/dist/federation/builder.test.mjs +1 -1
  19. package/dist/federation/collection.test.mjs +1 -1
  20. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  21. package/dist/federation/delivery-attachments.test.mjs +280 -0
  22. package/dist/federation/handler.test.mjs +208 -16
  23. package/dist/federation/idempotency.test.mjs +2 -2
  24. package/dist/federation/inbox.test.mjs +1 -1
  25. package/dist/federation/middleware.test.mjs +1559 -26
  26. package/dist/federation/mod.cjs +1 -1
  27. package/dist/federation/mod.d.cts +2 -2
  28. package/dist/federation/mod.d.ts +2 -2
  29. package/dist/federation/mod.js +1 -1
  30. package/dist/federation/negotiation.test.mjs +1 -1
  31. package/dist/federation/retry.test.mjs +1 -1
  32. package/dist/federation/send.test.mjs +723 -68
  33. package/dist/federation/temporal.test.mjs +25 -1
  34. package/dist/federation/webfinger.test.mjs +1 -1
  35. package/dist/{http-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
  36. package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
  37. package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
  38. package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
  39. package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
  40. package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
  41. package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
  42. package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
  43. package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
  44. package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
  45. package/dist/ld-signature-DoZcbsZR.mjs +23 -0
  46. package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
  47. package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
  48. package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
  49. package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
  50. package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
  51. package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
  52. package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
  53. package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
  54. package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
  55. package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
  56. package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.d.cts} +1 -1
  57. package/dist/mod.cjs +5 -5
  58. package/dist/mod.d.cts +8 -8
  59. package/dist/mod.d.ts +8 -8
  60. package/dist/mod.js +5 -5
  61. package/dist/nodeinfo/client.test.mjs +764 -19
  62. package/dist/nodeinfo/handler.test.mjs +1 -1
  63. package/dist/nodeinfo/mod.cjs +1 -1
  64. package/dist/nodeinfo/mod.d.cts +1 -1
  65. package/dist/nodeinfo/mod.d.ts +1 -1
  66. package/dist/nodeinfo/mod.js +1 -1
  67. package/dist/nodeinfo/types.test.mjs +1 -1
  68. package/dist/otel/exporter.test.mjs +292 -30
  69. package/dist/otel/mod.cjs +36 -30
  70. package/dist/otel/mod.d.cts +13 -0
  71. package/dist/otel/mod.d.ts +13 -0
  72. package/dist/otel/mod.js +36 -30
  73. package/dist/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
  74. package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
  75. package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
  76. package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
  77. package/dist/send-BGSfQkIK.mjs +416 -0
  78. package/dist/sig/http.test.mjs +506 -2
  79. package/dist/sig/key-types.test.d.mts +218 -0
  80. package/dist/sig/key-types.test.mjs +8 -0
  81. package/dist/sig/key.test.mjs +2 -2
  82. package/dist/sig/ld.test.mjs +573 -8
  83. package/dist/sig/mod.cjs +2 -2
  84. package/dist/sig/mod.d.cts +3 -3
  85. package/dist/sig/mod.d.ts +3 -3
  86. package/dist/sig/mod.js +2 -2
  87. package/dist/sig/owner.test.mjs +1 -1
  88. package/dist/sig/proof.test.mjs +95 -3
  89. package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
  90. package/dist/testing/mod.d.mts +1 -2177
  91. package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
  92. package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
  93. package/dist/utils/docloader.test.mjs +316 -32
  94. package/dist/utils/mod.cjs +1 -1
  95. package/dist/utils/mod.d.cts +1 -1
  96. package/dist/utils/mod.d.ts +1 -1
  97. package/dist/utils/mod.js +1 -1
  98. package/package.json +7 -7
  99. package/dist/docloader-OLWc7P2D.mjs +0 -82
  100. package/dist/send-BHIt_8ia.mjs +0 -260
  101. /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
  102. /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
  103. /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
  104. /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.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-ClQh9Qqh.mjs";
8
+ import { a as generateCryptoKeyPair } from "../key-Dai3f5yI.mjs";
9
9
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CtZLJq76.mjs";
10
- import { a as compactJsonLd, d as isInvalidUrlTypeError, f as signJsonLd, h as verifySignature, i as attachSignature, m as verifyJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature } from "../ld-Crg0Xmwr.mjs";
10
+ import { _ as verifySignature, a as compactJsonLd, c as detachSignature, d as hasVerifiableSignature, g as verifyJsonLd, i as attachSignature, m as signJsonLd, n as UnsafeJsonLdError, o as createSignature, p as isInvalidUrlTypeError, s as describeSignatureShape, u as hasSignature } from "../ld-DN6x1iZ8.mjs";
11
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-DoZcbsZR.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,16 +125,148 @@ 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
  }));
68
140
  });
141
+ test("signJsonLd() defines the signature term when the context lacks it", async () => {
142
+ const signed = await signJsonLd({
143
+ "@context": "https://www.w3.org/ns/activitystreams",
144
+ id: "https://example.com/notes/1",
145
+ type: "Note",
146
+ content: "Hello"
147
+ }, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
148
+ assert(Array.isArray(signed["@context"]));
149
+ assertEquals(signed["@context"][1], { "signature": "https://w3id.org/security#signature" });
150
+ assert((await jsonld.canonize(signed, {
151
+ format: "application/n-quads",
152
+ documentLoader: mockDocumentLoader
153
+ })).includes("<https://w3id.org/security#signature>"));
154
+ assertEquals(await verifySignature(signed, {
155
+ documentLoader: mockDocumentLoader,
156
+ contextLoader: mockDocumentLoader
157
+ }), rsaPublicKey2);
158
+ });
159
+ test("signJsonLd() signs documents that use the signature term", async () => {
160
+ const signatureTerm = { "signature": "https://w3id.org/security#signature" };
161
+ for (const object of [{
162
+ type: "Note",
163
+ signature: "nested value"
164
+ }, { type: "signature" }]) {
165
+ const doc = {
166
+ "@context": ["https://www.w3.org/ns/activitystreams", { "@vocab": "https://example.com/" }],
167
+ id: "https://example.com/1",
168
+ type: "Create",
169
+ object
170
+ };
171
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
172
+ assertEquals(signed["@context"], [...doc["@context"], signatureTerm]);
173
+ assertEquals(signed["object"], object);
174
+ assertEquals(await verifySignature(signed, {
175
+ documentLoader: mockDocumentLoader,
176
+ contextLoader: mockDocumentLoader
177
+ }), rsaPublicKey2);
178
+ }
179
+ });
180
+ test("signJsonLd() does not share the inline signature definition", async () => {
181
+ const doc = {
182
+ "@context": "https://www.w3.org/ns/activitystreams",
183
+ id: "https://example.com/notes/1",
184
+ type: "Note"
185
+ };
186
+ const firstContext = (await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }))["@context"];
187
+ firstContext[1]["signature"] = "https://example.com/signature";
188
+ assertEquals((await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }))["@context"][1], { "signature": "https://w3id.org/security#signature" });
189
+ });
190
+ test("signJsonLd() respects a protected null signature definition", async () => {
191
+ for (const context of [{
192
+ "@protected": true,
193
+ "signature": { "@id": null }
194
+ }, { "signature": {
195
+ "@id": null,
196
+ "@protected": true
197
+ } }]) {
198
+ const doc = {
199
+ "@context": ["https://www.w3.org/ns/activitystreams", context],
200
+ id: "https://example.com/1",
201
+ type: "Note"
202
+ };
203
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
204
+ assertEquals(signed["@context"], doc["@context"]);
205
+ assertEquals(await verifySignature(signed, {
206
+ documentLoader: mockDocumentLoader,
207
+ contextLoader: mockDocumentLoader
208
+ }), rsaPublicKey2);
209
+ }
210
+ });
211
+ test("signJsonLd() respects protection from imported contexts", async () => {
212
+ const importUrl = "https://example.com/contexts/imported-protected";
213
+ const contextLoader = async (url) => {
214
+ if (new URL(url).href === importUrl) return {
215
+ contextUrl: null,
216
+ documentUrl: url,
217
+ document: { "@context": {
218
+ "@protected": true,
219
+ "name": "https://example.com/name"
220
+ } }
221
+ };
222
+ return await mockDocumentLoader(url);
223
+ };
224
+ for (const signature of [null, { "@id": null }]) {
225
+ const doc = {
226
+ "@context": ["https://www.w3.org/ns/activitystreams", {
227
+ "@import": importUrl,
228
+ signature
229
+ }],
230
+ id: "https://example.com/1",
231
+ type: "Note",
232
+ name: "Alice"
233
+ };
234
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader });
235
+ assertEquals(signed["@context"], doc["@context"]);
236
+ assertEquals(await verifySignature(signed, {
237
+ documentLoader: mockDocumentLoader,
238
+ contextLoader
239
+ }), rsaPublicKey2);
240
+ }
241
+ });
242
+ test("signJsonLd() leaves unrecognized remote contexts unchanged", async () => {
243
+ const contextUrl = "https://example.com/contexts/custom";
244
+ const contextLoader = async (url) => {
245
+ if (new URL(url).href === contextUrl) return {
246
+ contextUrl: null,
247
+ documentUrl: url,
248
+ document: { "@context": {
249
+ "@protected": true,
250
+ "signature": {
251
+ "@id": "https://w3id.org/security#signature",
252
+ "@type": "@id"
253
+ }
254
+ } }
255
+ };
256
+ return await mockDocumentLoader(url);
257
+ };
258
+ const doc = {
259
+ "@context": ["https://www.w3.org/ns/activitystreams", contextUrl],
260
+ id: "https://example.com/1",
261
+ type: "Note"
262
+ };
263
+ const signed = await signJsonLd(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader });
264
+ assertEquals(signed["@context"], doc["@context"]);
265
+ assertEquals(await verifySignature(signed, {
266
+ documentLoader: mockDocumentLoader,
267
+ contextLoader
268
+ }), rsaPublicKey2);
269
+ });
69
270
  const document = {
70
271
  "@context": ["https://www.w3.org/ns/activitystreams", {
71
272
  "ostatus": "http://ostatus.org#",
@@ -218,6 +419,367 @@ test("verifyJsonLd()", async () => {
218
419
  contextLoader: mockDocumentLoader
219
420
  }));
220
421
  });
422
+ test("verifyJsonLd() tolerates unmapped document and signature properties", async () => {
423
+ const options = {
424
+ documentLoader: mockDocumentLoader,
425
+ contextLoader: mockDocumentLoader
426
+ };
427
+ const canonize = (input) => jsonld.canonize(input, {
428
+ format: "application/n-quads",
429
+ documentLoader: mockDocumentLoader,
430
+ safe: false
431
+ });
432
+ const withQuote = {
433
+ ...document,
434
+ object: {
435
+ ...document.object,
436
+ quoteUri: "https://example.com/quoted"
437
+ }
438
+ };
439
+ const sigOptions = {
440
+ "@context": "https://w3id.org/identity/v1",
441
+ creator: signature.creator,
442
+ created: signature.created
443
+ };
444
+ const extraOption = { quoteUri: "https://example.com/quoted" };
445
+ assertEquals(await canonize(withQuote), await canonize(document));
446
+ assertEquals(await canonize({
447
+ ...sigOptions,
448
+ ...extraOption
449
+ }), await canonize(sigOptions));
450
+ for (const input of [withQuote, {
451
+ ...sigOptions,
452
+ ...extraOption
453
+ }]) await assertRejects(() => jsonld.canonize(input, {
454
+ format: "application/n-quads",
455
+ documentLoader: mockDocumentLoader,
456
+ safe: true
457
+ }), Error, "Safe mode validation error.");
458
+ const expectedKey = await verifySignature(testVector, options);
459
+ assertInstanceOf(expectedKey, CryptographicKey);
460
+ for (const signed of [
461
+ {
462
+ ...withQuote,
463
+ signature
464
+ },
465
+ {
466
+ ...document,
467
+ signature: {
468
+ ...signature,
469
+ ...extraOption
470
+ }
471
+ },
472
+ {
473
+ ...withQuote,
474
+ signature: {
475
+ ...signature,
476
+ ...extraOption
477
+ }
478
+ }
479
+ ]) {
480
+ assertEquals(await verifySignature(signed, options), expectedKey);
481
+ assert(await verifyJsonLd(signed, options));
482
+ }
483
+ const tampered = {
484
+ ...withQuote,
485
+ object: {
486
+ ...withQuote.object,
487
+ content: "<p>Forged</p>"
488
+ },
489
+ signature
490
+ };
491
+ assertEquals(await verifySignature(tampered, options), null);
492
+ assertFalse(await verifyJsonLd(tampered, options));
493
+ });
494
+ test("verifyJsonLd() rejects relative IRIs despite unmapped properties", async () => {
495
+ const options = {
496
+ documentLoader: mockDocumentLoader,
497
+ contextLoader: mockDocumentLoader
498
+ };
499
+ const canonize = (input) => jsonld.canonize(input, {
500
+ format: "application/n-quads",
501
+ documentLoader: mockDocumentLoader,
502
+ safe: false
503
+ });
504
+ const withRelativeUrl = {
505
+ ...document,
506
+ object: {
507
+ ...document.object,
508
+ url: [document.object.url, "/evil"]
509
+ }
510
+ };
511
+ const note = await (await Create.fromJsonLd(withRelativeUrl, options)).getObject(options);
512
+ assertInstanceOf(note, Note);
513
+ assertEquals(note.urls.map((url) => url instanceof URL ? url.href : null), [document.object.url, "https://activitypub.academy/evil"]);
514
+ for (const input of [withRelativeUrl, {
515
+ ...document,
516
+ "https://example.com/extension": { "@id": "relative" }
517
+ }]) {
518
+ assertEquals(await canonize(input), await canonize(document));
519
+ for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) {
520
+ const signed = {
521
+ ...input,
522
+ ...extra,
523
+ signature
524
+ };
525
+ assertEquals(await verifySignature(signed, options), null);
526
+ assertFalse(await verifyJsonLd(signed, options));
527
+ }
528
+ }
529
+ const relativeOptions = {
530
+ ...testVector,
531
+ signature: {
532
+ ...signature,
533
+ nonce: { "@id": "relative" },
534
+ quoteUri: "https://example.com/quoted"
535
+ }
536
+ };
537
+ const sigOptions = {
538
+ "@context": "https://w3id.org/identity/v1",
539
+ creator: signature.creator,
540
+ created: signature.created
541
+ };
542
+ assertEquals(await canonize({
543
+ ...sigOptions,
544
+ nonce: relativeOptions.signature.nonce,
545
+ quoteUri: relativeOptions.signature.quoteUri
546
+ }), await canonize(sigOptions));
547
+ assertEquals(await verifySignature(relativeOptions, options), null);
548
+ assertFalse(await verifyJsonLd(relativeOptions, options));
549
+ });
550
+ test("signing still rejects unmapped properties", async () => {
551
+ const input = {
552
+ ...document,
553
+ quoteUri: "https://example.com/quoted"
554
+ };
555
+ const options = { contextLoader: mockDocumentLoader };
556
+ await assertRejects(() => createSignature(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
557
+ await assertRejects(() => signJsonLd(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
558
+ });
559
+ test("verification still rejects malformed JSON-LD", async () => {
560
+ const malformed = {
561
+ ...testVector,
562
+ "@context": 42
563
+ };
564
+ const options = {
565
+ documentLoader: mockDocumentLoader,
566
+ contextLoader: mockDocumentLoader
567
+ };
568
+ assertEquals(await verifySignature(malformed, options), null);
569
+ assertEquals((await assertRejects(() => verifyJsonLd(malformed, options), Error)).name, "jsonld.SyntaxError");
570
+ });
571
+ test("Linked Data verification without created", async (t) => {
572
+ const options = {
573
+ documentLoader: mockDocumentLoader,
574
+ contextLoader: mockDocumentLoader
575
+ };
576
+ await t.step("verifies the independently signed options", async () => {
577
+ assertFalse(hasSignature(ldSignatureWithoutCreated));
578
+ assertEquals(await verifySignature(ldSignatureWithoutCreated, options), rsaPublicKey3);
579
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, options));
580
+ });
581
+ await t.step("uses normalization contexts with a restrictive loader", async () => {
582
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, {
583
+ ...options,
584
+ contextLoader: async (url) => {
585
+ if (url !== "https://w3id.org/security/v1" && url !== "https://w3id.org/security/data-integrity/v1") return await mockDocumentLoader(url);
586
+ throw new Error(`Unexpected context: ${url}`);
587
+ }
588
+ }));
589
+ });
590
+ await t.step("rejects tampering with the signed timestamp or content", async () => {
591
+ const inserted = {
592
+ ...ldSignatureWithoutCreated,
593
+ signature: {
594
+ ...ldSignatureWithoutCreated.signature,
595
+ created: "2024-09-12T16:50:46Z"
596
+ }
597
+ };
598
+ const removed = structuredClone(testVector);
599
+ Reflect.deleteProperty(removed.signature, "created");
600
+ const changed = structuredClone(testVector);
601
+ changed.signature.created = "2024-09-13T16:50:46Z";
602
+ const changedContent = structuredClone(ldSignatureWithoutCreated);
603
+ changedContent.object.content = "tampered";
604
+ for (const doc of [
605
+ inserted,
606
+ removed,
607
+ changed,
608
+ changedContent
609
+ ]) {
610
+ assertEquals(await verifySignature(doc, options), null);
611
+ assertFalse(await verifyJsonLd(doc, options));
612
+ }
613
+ });
614
+ await t.step("still rejects graph restructuring", async () => {
615
+ const { signature, ...document } = ldSignatureWithoutCreated;
616
+ await assertRejects(() => verifyJsonLd({
617
+ "@context": document["@context"],
618
+ "@graph": [document],
619
+ signature
620
+ }, options), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
621
+ });
622
+ });
623
+ test("Linked Data verification rejects malformed creator URLs", async () => {
624
+ let keyLoads = 0;
625
+ const options = {
626
+ documentLoader: (url) => {
627
+ keyLoads++;
628
+ return mockDocumentLoader(url);
629
+ },
630
+ contextLoader: mockDocumentLoader
631
+ };
632
+ for (const creator of [
633
+ "not a URL",
634
+ "",
635
+ "/keys/main",
636
+ "https://["
637
+ ]) for (const withCreated of [false, true]) {
638
+ const input = {
639
+ ...ldSignatureWithoutCreated,
640
+ signature: {
641
+ ...ldSignatureWithoutCreated.signature,
642
+ creator,
643
+ ...withCreated ? { created: "2024-09-12T16:50:46Z" } : {}
644
+ }
645
+ };
646
+ assert(hasVerifiableSignature(input));
647
+ assertEquals(await verifySignature(input, options), null);
648
+ assertFalse(await verifyJsonLd(input, options));
649
+ }
650
+ assertEquals(keyLoads, 0);
651
+ });
652
+ test("Linked Data verification distinguishes malformed and absent signatures", async () => {
653
+ const signature = {
654
+ type: "RsaSignature2017",
655
+ creator: "https://example.com/private-creator-sentinel#key",
656
+ signatureValue: "private-signature-sentinel"
657
+ };
658
+ assert(hasVerifiableSignature({ signature }));
659
+ assertFalse(hasSignature({ signature }));
660
+ for (const created of [
661
+ "2024-09-12T16:50:46Z",
662
+ "not a date",
663
+ ""
664
+ ]) {
665
+ const doc = { signature: {
666
+ ...signature,
667
+ created
668
+ } };
669
+ assert(hasVerifiableSignature(doc));
670
+ assert(hasSignature(doc));
671
+ }
672
+ const malformed = [
673
+ null,
674
+ [],
675
+ "signature",
676
+ {},
677
+ {
678
+ ...signature,
679
+ type: "OtherSignature"
680
+ },
681
+ {
682
+ ...signature,
683
+ type: ["RsaSignature2017"]
684
+ },
685
+ {
686
+ ...signature,
687
+ creator: {}
688
+ },
689
+ {
690
+ ...signature,
691
+ signatureValue: 1
692
+ },
693
+ ...[
694
+ void 0,
695
+ null,
696
+ 123,
697
+ {},
698
+ []
699
+ ].map((created) => ({
700
+ ...signature,
701
+ created
702
+ }))
703
+ ];
704
+ const records = [];
705
+ await configure({
706
+ sinks: { buffer: (record) => records.push(record) },
707
+ loggers: [{
708
+ category: [
709
+ "fedify",
710
+ "sig",
711
+ "ld"
712
+ ],
713
+ sinks: ["buffer"],
714
+ lowestLevel: "debug"
715
+ }, {
716
+ category: ["logtape", "meta"],
717
+ sinks: []
718
+ }],
719
+ reset: true
720
+ });
721
+ let keyLoads = 0;
722
+ const options = {
723
+ documentLoader: (url) => {
724
+ keyLoads++;
725
+ return mockDocumentLoader(url);
726
+ },
727
+ contextLoader: mockDocumentLoader
728
+ };
729
+ try {
730
+ for (const value of malformed) {
731
+ const doc = { signature: value };
732
+ assertFalse(hasVerifiableSignature(doc));
733
+ assertEquals(await verifySignature(doc, options), null);
734
+ }
735
+ assertEquals(keyLoads, 0);
736
+ assertEquals(records.length, malformed.length);
737
+ for (const record of records) {
738
+ assertEquals(record.level, "debug");
739
+ assertFalse(JSON.stringify(record).includes(signature.creator));
740
+ assertFalse(JSON.stringify(record).includes(signature.signatureValue));
741
+ }
742
+ assertEquals(records.at(-1)?.properties, {
743
+ signatureKind: "object",
744
+ signatureProperties: [
745
+ "created",
746
+ "creator",
747
+ "signatureValue",
748
+ "type"
749
+ ],
750
+ signaturePropertyCount: 4
751
+ });
752
+ for (const absent of [
753
+ null,
754
+ [],
755
+ 1,
756
+ {},
757
+ { type: "Create" }
758
+ ]) {
759
+ assertEquals(await verifySignature(absent, options), null);
760
+ assertFalse(hasVerifiableSignature(absent));
761
+ assertEquals(describeSignatureShape(absent), null);
762
+ }
763
+ assertEquals(records.length, malformed.length);
764
+ assertFalse(await verifyJsonLd({
765
+ ...ldSignatureWithoutCreated,
766
+ signature: {
767
+ ...signature,
768
+ created: 123
769
+ }
770
+ }, options));
771
+ assertEquals(records.length, malformed.length + 1);
772
+ assertEquals(keyLoads, 0);
773
+ } finally {
774
+ await reset();
775
+ }
776
+ const shape = describeSignatureShape({ signature: globalThis.Object.fromEntries(Array.from({ length: 30 }, (_, i) => [`field${i}`.padEnd(200, "x"), "secret"])) });
777
+ assertEquals(shape?.signaturePropertyCount, 30);
778
+ assertEquals(shape?.signatureProperties.length, 20);
779
+ assert(shape?.signatureProperties.every((name) => name.length === 80));
780
+ assertEquals(describeSignatureShape({ signature: null })?.signatureKind, "null");
781
+ assertEquals(describeSignatureShape({ signature: [] })?.signatureKind, "array");
782
+ });
221
783
  test("compactJsonLd() with restrictive context loader", async () => {
222
784
  const restrictiveContextLoader = async (resource) => {
223
785
  const url = new URL(resource).href;
@@ -722,7 +1284,10 @@ test("verifyJsonLd() rejects unsafe JSON-LD keywords", async () => {
722
1284
  signature: signed.signature
723
1285
  }]
724
1286
  ];
725
- for (const [keyword, jsonLd] of cases) await assertRejects(() => verifyJsonLd(jsonLd, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
1287
+ for (const [keyword, jsonLd] of cases) for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) await assertRejects(() => verifyJsonLd({
1288
+ ...jsonLd,
1289
+ ...extra
1290
+ }, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
726
1291
  });
727
1292
  test("compactJsonLd() rejects unsafe JSON-LD keywords inside signature objects", async () => {
728
1293
  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-BoR1M3W7.cjs");
5
- const require_proof = require("../proof-CHXVlsH_.cjs");
4
+ const require_http = require("../http-D5woFKA_.cjs");
5
+ const require_proof = require("../proof-Be-4K4jn.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 verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "../mod-DiuFTYUt.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, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };
4
+ import { _ as detachSignature, a as VerifyObjectOptions, b as verifySignature, c as signObject, d as CreateSignatureOptions, f as SignJsonLdOptions, g as createSignature, h as attachSignature, i as SignObjectOptions, l as verifyObject, m as VerifySignatureOptions, n as CryptoKeyPairLike, o as VerifyProofOptions, p as VerifyJsonLdOptions, r as CreateProofOptions, s as createProof, t as CryptoKeyLike, u as verifyProof, v as signJsonLd, y as verifyJsonLd } from "../mod-CehHJOV4.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, importJwk, parseAcceptSignature, signJsonLd, signObject, signRequest, validateAcceptSignature, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifyRequestDetailed, verifySignature };