@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710

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 (244) hide show
  1. package/dist/federation/mod.cjs +1 -1
  2. package/dist/federation/mod.js +1 -1
  3. package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
  4. package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
  5. package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
  6. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  7. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  13. package/dist/sig/mod.cjs +2 -2
  14. package/dist/sig/mod.js +2 -2
  15. package/dist/utils/mod.cjs +1 -1
  16. package/dist/utils/mod.js +1 -1
  17. package/package.json +22 -9
  18. package/skills/fedify/SKILL.md +10 -0
  19. package/dist/accept-CPVqki78.mjs +0 -145
  20. package/dist/activity-listener-CELFAodc.mjs +0 -44
  21. package/dist/assert-D1Eafmd_.mjs +0 -23
  22. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  23. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  24. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  25. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  26. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  27. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  28. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  29. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  30. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  31. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  32. package/dist/audience-CHQ-FlLD.mjs +0 -95
  33. package/dist/builder-D1FP_5nQ.mjs +0 -911
  34. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  35. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  36. package/dist/client-5SIFzW3q.mjs +0 -441
  37. package/dist/codec-C6rTrpIp.mjs +0 -147
  38. package/dist/collection-CnnP1UAv.mjs +0 -44
  39. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  40. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  41. package/dist/compat/public-audience.test.d.mts +0 -2
  42. package/dist/compat/public-audience.test.mjs +0 -187
  43. package/dist/compat/secured-document.test.d.mts +0 -2
  44. package/dist/compat/secured-document.test.mjs +0 -58
  45. package/dist/compat/transformers.test.d.mts +0 -2
  46. package/dist/compat/transformers.test.mjs +0 -62
  47. package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
  48. package/dist/context-LgGFFSz7.mjs +0 -146
  49. package/dist/deno-C50ikGBU.mjs +0 -8
  50. package/dist/dist-_geWsuaI.mjs +0 -189
  51. package/dist/docloader-BY-SEID0.mjs +0 -136
  52. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  53. package/dist/exporter-DVG68ozH.mjs +0 -263
  54. package/dist/federation/audience.test.d.mts +0 -2
  55. package/dist/federation/audience.test.mjs +0 -130
  56. package/dist/federation/builder.test.d.mts +0 -2
  57. package/dist/federation/builder.test.mjs +0 -396
  58. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  59. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  60. package/dist/federation/collection.test.d.mts +0 -2
  61. package/dist/federation/collection.test.mjs +0 -21
  62. package/dist/federation/compound-fanout.test.d.mts +0 -2
  63. package/dist/federation/compound-fanout.test.mjs +0 -231
  64. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  65. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  66. package/dist/federation/handler.test.d.mts +0 -2
  67. package/dist/federation/handler.test.mjs +0 -5445
  68. package/dist/federation/hashlink-media.test.d.mts +0 -2
  69. package/dist/federation/hashlink-media.test.mjs +0 -422
  70. package/dist/federation/idempotency.test.d.mts +0 -2
  71. package/dist/federation/idempotency.test.mjs +0 -207
  72. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  73. package/dist/federation/inbox-actorless.test.mjs +0 -522
  74. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  75. package/dist/federation/inbox-authentication.test.mjs +0 -220
  76. package/dist/federation/inbox-report.test.d.mts +0 -2
  77. package/dist/federation/inbox-report.test.mjs +0 -719
  78. package/dist/federation/inbox-view.test.d.mts +0 -2
  79. package/dist/federation/inbox-view.test.mjs +0 -369
  80. package/dist/federation/inbox.test.d.mts +0 -2
  81. package/dist/federation/inbox.test.mjs +0 -139
  82. package/dist/federation/keycache.test.d.mts +0 -2
  83. package/dist/federation/keycache.test.mjs +0 -337
  84. package/dist/federation/kv.test.d.mts +0 -2
  85. package/dist/federation/kv.test.mjs +0 -88
  86. package/dist/federation/metrics.test.d.mts +0 -2
  87. package/dist/federation/metrics.test.mjs +0 -634
  88. package/dist/federation/middleware.test.d.mts +0 -2
  89. package/dist/federation/middleware.test.mjs +0 -9314
  90. package/dist/federation/mq.test.d.mts +0 -2
  91. package/dist/federation/mq.test.mjs +0 -591
  92. package/dist/federation/negotiation.test.d.mts +0 -2
  93. package/dist/federation/negotiation.test.mjs +0 -18
  94. package/dist/federation/outbound-body.test.d.mts +0 -2
  95. package/dist/federation/outbound-body.test.mjs +0 -149
  96. package/dist/federation/outbound-capture.test.d.mts +0 -2
  97. package/dist/federation/outbound-capture.test.mjs +0 -394
  98. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  99. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  100. package/dist/federation/outbound-document.test.d.mts +0 -2
  101. package/dist/federation/outbound-document.test.mjs +0 -171
  102. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  103. package/dist/federation/outbound-provenance.test.mjs +0 -543
  104. package/dist/federation/outbound-report.test.d.mts +0 -2
  105. package/dist/federation/outbound-report.test.mjs +0 -5475
  106. package/dist/federation/outbound-workers.test.d.mts +0 -2
  107. package/dist/federation/outbound-workers.test.mjs +0 -64
  108. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  109. package/dist/federation/outbound-workflow.test.mjs +0 -154
  110. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  111. package/dist/federation/outgoing-proof.test.mjs +0 -933
  112. package/dist/federation/portable-actor.test.d.mts +0 -2
  113. package/dist/federation/portable-actor.test.mjs +0 -496
  114. package/dist/federation/portable-chain.test.d.mts +0 -2
  115. package/dist/federation/portable-chain.test.mjs +0 -370
  116. package/dist/federation/portable-collection.test.d.mts +0 -2
  117. package/dist/federation/portable-collection.test.mjs +0 -832
  118. package/dist/federation/portable-delivery.test.d.mts +0 -2
  119. package/dist/federation/portable-delivery.test.mjs +0 -845
  120. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  121. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  122. package/dist/federation/portable-inbox.test.d.mts +0 -2
  123. package/dist/federation/portable-inbox.test.mjs +0 -1960
  124. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  125. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  126. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  127. package/dist/federation/portable-route-activity.test.mjs +0 -259
  128. package/dist/federation/portable.test.d.mts +0 -2
  129. package/dist/federation/portable.test.mjs +0 -1072
  130. package/dist/federation/retry.test.d.mts +0 -2
  131. package/dist/federation/retry.test.mjs +0 -42
  132. package/dist/federation/router.test.d.mts +0 -2
  133. package/dist/federation/router.test.mjs +0 -123
  134. package/dist/federation/send.test.d.mts +0 -2
  135. package/dist/federation/send.test.mjs +0 -1421
  136. package/dist/federation/tasks/codec.test.d.mts +0 -2
  137. package/dist/federation/tasks/codec.test.mjs +0 -302
  138. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  139. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  140. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  141. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  142. package/dist/federation/temporal.test.d.mts +0 -2
  143. package/dist/federation/temporal.test.mjs +0 -71
  144. package/dist/federation/webfinger.test.d.mts +0 -2
  145. package/dist/federation/webfinger.test.mjs +0 -944
  146. package/dist/http-BXbQQZDM.mjs +0 -1449
  147. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  148. package/dist/inbox-cS97XzOD.mjs +0 -399
  149. package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
  150. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  151. package/dist/keycache-N2opu4-3.mjs +0 -221
  152. package/dist/keys-DIJNHW-Y.mjs +0 -120
  153. package/dist/kv-DBRWVx3Q.mjs +0 -104
  154. package/dist/kv-DCHkaJ9-.mjs +0 -92
  155. package/dist/kv-cache-fgbLHGVL.mjs +0 -121
  156. package/dist/ld-BpkhkDGj.mjs +0 -1752
  157. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  158. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  159. package/dist/metrics-Uqf8GomB.mjs +0 -818
  160. package/dist/middleware-DcXzz-YK.mjs +0 -9971
  161. package/dist/middleware-DgwZkvJR.mjs +0 -5
  162. package/dist/mq-eF96QxUT.mjs +0 -288
  163. package/dist/negotiation-BAKO9nih.mjs +0 -96
  164. package/dist/nodeinfo/client.test.d.mts +0 -2
  165. package/dist/nodeinfo/client.test.mjs +0 -1364
  166. package/dist/nodeinfo/handler.test.d.mts +0 -2
  167. package/dist/nodeinfo/handler.test.mjs +0 -94
  168. package/dist/nodeinfo/types.test.d.mts +0 -2
  169. package/dist/nodeinfo/types.test.mjs +0 -192
  170. package/dist/otel/exporter.test.d.mts +0 -2
  171. package/dist/otel/exporter.test.mjs +0 -887
  172. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  173. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  174. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  175. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  176. package/dist/owner-BVenIFg1.mjs +0 -267
  177. package/dist/portable-collection-DIk9gpjL.mjs +0 -418
  178. package/dist/portable-key-C7pVaHNR.mjs +0 -549
  179. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  180. package/dist/proof-BlfZ95--.mjs +0 -1420
  181. package/dist/public-audience--klBIOk1.mjs +0 -197
  182. package/dist/retry-zX5xw5e0.mjs +0 -34
  183. package/dist/router-u5O5KCQr.mjs +0 -156
  184. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  185. package/dist/send-DEGHPGFk.mjs +0 -710
  186. package/dist/sig/accept.test.d.mts +0 -2
  187. package/dist/sig/accept.test.mjs +0 -416
  188. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  189. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  190. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  191. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  192. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  193. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  194. package/dist/sig/compound-proof.test.d.mts +0 -2
  195. package/dist/sig/compound-proof.test.mjs +0 -411
  196. package/dist/sig/http.test.d.mts +0 -2
  197. package/dist/sig/http.test.mjs +0 -3328
  198. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  199. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  200. package/dist/sig/key.test.d.mts +0 -2
  201. package/dist/sig/key.test.mjs +0 -1250
  202. package/dist/sig/ld.test.d.mts +0 -2
  203. package/dist/sig/ld.test.mjs +0 -1044
  204. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  205. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  206. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  207. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  208. package/dist/sig/owner.test.d.mts +0 -2
  209. package/dist/sig/owner.test.mjs +0 -202
  210. package/dist/sig/portable-collection.test.d.mts +0 -2
  211. package/dist/sig/portable-collection.test.mjs +0 -697
  212. package/dist/sig/portable-interop.test.d.mts +0 -2
  213. package/dist/sig/portable-interop.test.mjs +0 -156
  214. package/dist/sig/portable-key-id.test.d.mts +0 -2
  215. package/dist/sig/portable-key-id.test.mjs +0 -67
  216. package/dist/sig/portable-key.test.d.mts +0 -2
  217. package/dist/sig/portable-key.test.mjs +0 -1438
  218. package/dist/sig/proof.test.d.mts +0 -2
  219. package/dist/sig/proof.test.mjs +0 -2638
  220. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  221. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  222. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  223. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  224. package/dist/sig/verification.test.d.mts +0 -2
  225. package/dist/sig/verification.test.mjs +0 -310
  226. package/dist/std__assert-DvMDRPes.mjs +0 -8
  227. package/dist/tasks-BCUmQbbz.mjs +0 -77
  228. package/dist/temporal-B4oQ8HpW.mjs +0 -95
  229. package/dist/testing/context.test.d.mts +0 -2
  230. package/dist/testing/context.test.mjs +0 -19
  231. package/dist/testing/kv.test.d.mts +0 -2
  232. package/dist/testing/kv.test.mjs +0 -101
  233. package/dist/testing/mod.d.mts +0 -6099
  234. package/dist/testing/mod.mjs +0 -9
  235. package/dist/testing-vrnD5Uaa.mjs +0 -8
  236. package/dist/types-DE_LV1JB.mjs +0 -46
  237. package/dist/utils/docloader.test.d.mts +0 -2
  238. package/dist/utils/docloader.test.mjs +0 -1076
  239. package/dist/utils/kv-cache.test.d.mts +0 -2
  240. package/dist/utils/kv-cache.test.mjs +0 -261
  241. package/dist/verification-C3954hQh.mjs +0 -5
  242. package/dist/verification-Dpfcw8ml.mjs +0 -105
  243. package/dist/vocab/cjs.test.d.mts +0 -2
  244. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,1044 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
5
- import { t as assertFalse } from "../assert_false-CPdRnc3E.mjs";
6
- import { t as assertGreaterOrEqual } from "../assert_greater_or_equal-BlafOF4-.mjs";
7
- import { t as assertInstanceOf } from "../assert_instance_of-mrXWWNY-.mjs";
8
- import { t as assertThrows } from "../assert_throws-BYITOvPO.mjs";
9
- import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
10
- import { t as assert } from "../assert-D1Eafmd_.mjs";
11
- import { T as generateCryptoKeyPair, _ as verifyJsonLd, a as compactJsonLd, f as isInvalidUrlTypeError, i as attachSignature, m as signJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature, u as hasSignatureLike, v as verifySignature } from "../ld-BpkhkDGj.mjs";
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";
14
- import { createTestMeterProvider, mockDocumentLoader, test } from "@fedify/fixture";
15
- import { encodeBase64 } from "byte-encodings/base64";
16
- //#region src/sig/ld.test.ts
17
- test("isInvalidUrlTypeError()", () => {
18
- assert(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("Invalid URL string.")));
19
- assertFalse(isInvalidUrlTypeError(/* @__PURE__ */ new Error("Invalid URL string.")));
20
- assertFalse(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("Invalid URL string. Other error")));
21
- assert(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("Invalid URL: http://[")));
22
- assert(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("\"http://[\" cannot be parsed as a URL.")));
23
- const error = /* @__PURE__ */ new TypeError("Failed to parse URL");
24
- error.code = "ERR_INVALID_URL";
25
- assert(isInvalidUrlTypeError(error));
26
- assertFalse(isInvalidUrlTypeError(/* @__PURE__ */ new TypeError("Failed to fetch")));
27
- });
28
- test("attachSignature()", () => {
29
- const sig = {
30
- "@context": "https://w3id.org/identity/v1",
31
- type: "RsaSignature2017",
32
- creator: "https://activitypub.academy/users/brauca_darradiul#main-key",
33
- created: "2024-09-12T16:50:46Z",
34
- signatureValue: "asdf"
35
- };
36
- const doc = {
37
- "@context": "https://www.w3.org/ns/activitystreams",
38
- id: "https://example.com/1"
39
- };
40
- assertEquals(attachSignature(doc, sig), {
41
- ...doc,
42
- signature: sig
43
- });
44
- assertThrows(() => attachSignature(null, sig), TypeError);
45
- assertThrows(() => attachSignature(1234, sig), TypeError);
46
- });
47
- test("createSignature()", async () => {
48
- const doc = {
49
- "@context": "https://www.w3.org/ns/activitystreams",
50
- id: "https://example.com/1",
51
- type: "Create"
52
- };
53
- assertEquals(await verifySignature(attachSignature(doc, await createSignature(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader })), {
54
- documentLoader: mockDocumentLoader,
55
- contextLoader: mockDocumentLoader
56
- }), rsaPublicKey2);
57
- assertRejects(() => createSignature(doc, rsaPublicKey2.publicKey, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }), TypeError);
58
- assertRejects(() => createSignature(doc, ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader }), TypeError);
59
- });
60
- test("signJsonLd()", async () => {
61
- assert(await verifyJsonLd(await signJsonLd({
62
- "@context": "https://www.w3.org/ns/activitystreams",
63
- id: "https://example.com/1",
64
- type: "Create",
65
- actor: "https://example.com/person2"
66
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }), {
67
- documentLoader: mockDocumentLoader,
68
- contextLoader: mockDocumentLoader
69
- }));
70
- });
71
- test("hasSignatureLike()", () => {
72
- assert(hasSignatureLike({ signature: {
73
- type: "RsaSignature2017",
74
- creator: "https://example.com/users/alice#main-key",
75
- signatureValue: "signature"
76
- } }));
77
- assert(hasSignatureLike({ signature: {
78
- type: "Ed25519Signature2020",
79
- verificationMethod: "https://example.com/users/alice#main-key",
80
- jws: "signature"
81
- } }));
82
- assert(hasSignatureLike({ signature: {
83
- type: "Ed25519Signature2020",
84
- verificationMethod: { id: "https://example.com/users/alice#main-key" },
85
- jws: "signature"
86
- } }));
87
- assert(hasSignatureLike({ signature: {
88
- type: "Ed25519Signature2020",
89
- verificationMethod: [{ id: "https://example.com/users/alice#main-key" }],
90
- jws: "signature"
91
- } }));
92
- assert(hasSignatureLike({ signature: {
93
- type: "Ed25519Signature2020",
94
- verificationMethod: { "@id": "https://example.com/users/alice#main-key" },
95
- jws: "signature"
96
- } }));
97
- assert(hasSignatureLike({ signature: [{
98
- type: "Ed25519Signature2020",
99
- verificationMethod: { "@id": "https://example.com/users/alice#main-key" },
100
- jws: "signature"
101
- }] }));
102
- assert(hasSignatureLike({ signature: {
103
- type: ["Ed25519Signature2020"],
104
- verificationMethod: "https://example.com/users/alice#main-key",
105
- jws: "signature"
106
- } }));
107
- assertFalse(hasSignatureLike({ signature: {
108
- type: "Ed25519Signature2020",
109
- verificationMethod: "https://example.com/users/alice#main-key"
110
- } }));
111
- assertFalse(hasSignatureLike(null));
112
- });
113
- const document = {
114
- "@context": ["https://www.w3.org/ns/activitystreams", {
115
- "ostatus": "http://ostatus.org#",
116
- "atomUri": "ostatus:atomUri",
117
- "inReplyToAtomUri": "ostatus:inReplyToAtomUri",
118
- "conversation": "ostatus:conversation",
119
- "sensitive": "as:sensitive",
120
- "toot": "http://joinmastodon.org/ns#",
121
- "votersCount": "toot:votersCount"
122
- }],
123
- "id": "https://activitypub.academy/users/brauca_darradiul/statuses/113125611605598678/activity",
124
- "type": "Create",
125
- "actor": "https://activitypub.academy/users/brauca_darradiul",
126
- "published": "2024-09-12T16:50:45Z",
127
- "to": ["https://www.w3.org/ns/activitystreams#Public"],
128
- "cc": ["https://activitypub.academy/users/brauca_darradiul/followers"],
129
- "object": {
130
- "id": "https://activitypub.academy/users/brauca_darradiul/statuses/113125611605598678",
131
- "type": "Note",
132
- "summary": null,
133
- "inReplyTo": null,
134
- "published": "2024-09-12T16:50:45Z",
135
- "url": "https://activitypub.academy/@brauca_darradiul/113125611605598678",
136
- "attributedTo": "https://activitypub.academy/users/brauca_darradiul",
137
- "to": ["https://www.w3.org/ns/activitystreams#Public"],
138
- "cc": ["https://activitypub.academy/users/brauca_darradiul/followers"],
139
- "sensitive": false,
140
- "atomUri": "https://activitypub.academy/users/brauca_darradiul/statuses/113125611605598678",
141
- "inReplyToAtomUri": null,
142
- "conversation": "tag:activitypub.academy,2024-09-12:objectId=187606:objectType=Conversation",
143
- "content": "<p>Test</p>",
144
- "contentMap": { "en": "<p>Test</p>" },
145
- "attachment": [],
146
- "tag": [],
147
- "replies": {
148
- "id": "https://activitypub.academy/users/brauca_darradiul/statuses/113125611605598678/replies",
149
- "type": "Collection",
150
- "first": {
151
- "type": "CollectionPage",
152
- "next": "https://activitypub.academy/users/brauca_darradiul/statuses/113125611605598678/replies?only_other_accounts=true&page=true",
153
- "partOf": "https://activitypub.academy/users/brauca_darradiul/statuses/113125611605598678/replies",
154
- "items": []
155
- }
156
- }
157
- }
158
- };
159
- const signature = {
160
- "type": "RsaSignature2017",
161
- "creator": "https://activitypub.academy/users/brauca_darradiul#main-key",
162
- "created": "2024-09-12T16:50:46Z",
163
- "signatureValue": "osp9n4Pubp8XFvBi0iwrpCjDkIpuuUr2klp+r8Jp289ISqRNlUPeHVvNrQSE2vqNm4j/cJGuQruIqZPTAmTjjB3HtqgawoAG11DA7OPpY6mJLruKnbqadV1cy5V0DJI9CRJXEBuEmMTJRO9gi1cyzlM4QxK30YrjmtQNLoU9th97da4lumsl+a5cAue38MDuJZvLWDOTZ1EGixwhLP8FevdnZ+jqwctGu9KrgDImBIpBkQaqHFTTGrbE7FlXsj1pneOUQTuRDa9zlk2DmgXeEBWN2OJZDjgJ4iBsF2JHtCn6PccKbuI9s2VLhnobPtLB8YdHYKqIPLmv0UOjAM8XrQ=="
164
- };
165
- const testVector = {
166
- ...document,
167
- signature
168
- };
169
- test("detachSignature()", () => {
170
- assertEquals(detachSignature(testVector), document);
171
- assertEquals(detachSignature(document), document);
172
- });
173
- test("verifySignature()", async () => {
174
- const doc = { ...testVector };
175
- const key = await verifySignature(doc, {
176
- documentLoader: mockDocumentLoader,
177
- contextLoader: mockDocumentLoader
178
- });
179
- assertEquals(doc, testVector);
180
- assertEquals(key, await CryptographicKey.fromJsonLd({
181
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
182
- id: "https://activitypub.academy/users/brauca_darradiul#main-key",
183
- owner: "https://activitypub.academy/users/brauca_darradiul",
184
- publicKeyPem: "-----BEGIN PUBLIC KEY----- MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA5W/9rYXddIjKo9Ury/LK XqQYbj0cOx/c+T1uRHJzced8JbvXdiBCNZXVVrIaygy3G/MOvxMW4kbA1bqeiSYY V9TXBMI6gVVDnl5VG64uGxswcvUWqQU5Q1mwuwyGCPhexAq3BKe/7uH64AZgx11e KLl3W3WcIMKmunYn8+z6hm0003hMensXMNpMVfqLoXaeuro7pYnwOSWoHFS3AxWK llMwAoa5waulgai8gD7/uA5Y9Hvguk/OBYBh9YnIX5N5jScsmY/EYuesNIH2Ct9s E3aVkTjZUt55JtXnk8Q9eTnrcB/98RtLWH4pJTKJhzxv19i3aZT3yDApPk0Q/biI JQIDAQAB -----END PUBLIC KEY----- "
185
- }));
186
- const doc2 = {
187
- ...testVector,
188
- signature: {
189
- ...testVector.signature,
190
- signatureValue: "!"
191
- }
192
- };
193
- const key2 = await verifySignature(doc2, {
194
- documentLoader: mockDocumentLoader,
195
- contextLoader: mockDocumentLoader
196
- });
197
- assertEquals(doc2, {
198
- ...testVector,
199
- signature: {
200
- ...testVector.signature,
201
- signatureValue: "!"
202
- }
203
- });
204
- assertEquals(key2, null);
205
- const incorrectSig = encodeBase64(new Uint8Array([
206
- 1,
207
- 2,
208
- 3,
209
- 4
210
- ]));
211
- const doc3 = {
212
- ...testVector,
213
- signature: {
214
- ...testVector.signature,
215
- signatureValue: incorrectSig
216
- }
217
- };
218
- const key3 = await verifySignature(doc3, {
219
- documentLoader: mockDocumentLoader,
220
- contextLoader: mockDocumentLoader
221
- });
222
- assertEquals(doc3, {
223
- ...testVector,
224
- signature: {
225
- ...testVector.signature,
226
- signatureValue: incorrectSig
227
- }
228
- });
229
- assertEquals(key3, null);
230
- const doc4 = { ...testVector };
231
- const key4 = await verifySignature(doc4, {
232
- documentLoader: mockDocumentLoader,
233
- contextLoader: mockDocumentLoader,
234
- keyCache: {
235
- async get(keyId) {
236
- return new CryptographicKey({
237
- id: keyId,
238
- owner: new URL("https://activitypub.academy/users/brauca_darradiul"),
239
- publicKey: (await generateCryptoKeyPair("RSASSA-PKCS1-v1_5")).publicKey
240
- });
241
- },
242
- set(_keyId, _key) {
243
- return Promise.resolve();
244
- }
245
- }
246
- });
247
- assertEquals(doc4, testVector);
248
- assertEquals(key4, key);
249
- });
250
- test("verifyJsonLd()", async () => {
251
- assert(await verifyJsonLd(testVector, {
252
- documentLoader: mockDocumentLoader,
253
- contextLoader: mockDocumentLoader
254
- }));
255
- assertFalse(await verifyJsonLd(await signJsonLd({
256
- "@context": "https://www.w3.org/ns/activitystreams",
257
- id: "https://example.com/1",
258
- type: "Create",
259
- actor: "https://example.com/person2"
260
- }, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader }), {
261
- documentLoader: mockDocumentLoader,
262
- contextLoader: mockDocumentLoader
263
- }));
264
- });
265
- test("verifyJsonLd() records verification duration metric", async (t) => {
266
- await t.step("verified path records result=verified with bounded type", async () => {
267
- const [meterProvider, recorder] = createTestMeterProvider();
268
- assert(await verifyJsonLd(testVector, {
269
- documentLoader: mockDocumentLoader,
270
- contextLoader: mockDocumentLoader,
271
- meterProvider
272
- }));
273
- const measurements = recorder.getMeasurements("activitypub.signature.verification.duration");
274
- assertEquals(measurements.length, 1);
275
- const m = measurements[0];
276
- assertEquals(m.type, "histogram");
277
- assertGreaterOrEqual(m.value, 0);
278
- assertEquals(m.attributes["activitypub.signature.kind"], "linked_data");
279
- assertEquals(m.attributes["activitypub.signature.result"], "verified");
280
- assertEquals(m.attributes["ld_signatures.type"], "RsaSignature2017");
281
- });
282
- await t.step("missing signature records result=missing without type", async () => {
283
- const [meterProvider, recorder] = createTestMeterProvider();
284
- assertFalse(await verifyJsonLd(document, {
285
- documentLoader: mockDocumentLoader,
286
- contextLoader: mockDocumentLoader,
287
- meterProvider
288
- }));
289
- const measurements = recorder.getMeasurements("activitypub.signature.verification.duration");
290
- assertEquals(measurements.length, 1);
291
- assertEquals(measurements[0].attributes["activitypub.signature.kind"], "linked_data");
292
- assertEquals(measurements[0].attributes["activitypub.signature.result"], "missing");
293
- assertFalse("ld_signatures.type" in measurements[0].attributes);
294
- });
295
- await t.step("invalid signature records result=rejected", async () => {
296
- const [meterProvider, recorder] = createTestMeterProvider();
297
- assertFalse(await verifyJsonLd({
298
- ...testVector,
299
- signature: {
300
- ...testVector.signature,
301
- signatureValue: encodeBase64(new Uint8Array([
302
- 1,
303
- 2,
304
- 3,
305
- 4
306
- ]))
307
- }
308
- }, {
309
- documentLoader: mockDocumentLoader,
310
- contextLoader: mockDocumentLoader,
311
- meterProvider
312
- }));
313
- const measurements = recorder.getMeasurements("activitypub.signature.verification.duration");
314
- assertEquals(measurements.length, 1);
315
- assertEquals(measurements[0].attributes["activitypub.signature.result"], "rejected");
316
- assertEquals(measurements[0].attributes["ld_signatures.type"], "RsaSignature2017");
317
- });
318
- await t.step("malformed (null) signature property records result=rejected, not missing", async () => {
319
- const [meterProvider, recorder] = createTestMeterProvider();
320
- assertFalse(await verifyJsonLd({
321
- ...document,
322
- signature: null
323
- }, {
324
- documentLoader: mockDocumentLoader,
325
- contextLoader: mockDocumentLoader,
326
- meterProvider
327
- }));
328
- const measurements = recorder.getMeasurements("activitypub.signature.verification.duration");
329
- assertEquals(measurements.length, 1);
330
- assertEquals(measurements[0].attributes["activitypub.signature.result"], "rejected");
331
- assertFalse("ld_signatures.type" in measurements[0].attributes);
332
- });
333
- await t.step("key fetch records result=fetched on a cold cache", async () => {
334
- const [meterProvider, recorder] = createTestMeterProvider();
335
- assert(await verifyJsonLd(testVector, {
336
- documentLoader: mockDocumentLoader,
337
- contextLoader: mockDocumentLoader,
338
- meterProvider
339
- }));
340
- const measurements = recorder.getMeasurements("activitypub.signature.key_fetch.duration");
341
- assertEquals(measurements.length, 1);
342
- assertGreaterOrEqual(measurements[0].value, 0);
343
- assertEquals(measurements[0].attributes["activitypub.signature.kind"], "linked_data");
344
- assertEquals(measurements[0].attributes["activitypub.signature.key_fetch.result"], "fetched");
345
- });
346
- await t.step("missing signature emits no key_fetch measurement", async () => {
347
- const [meterProvider, recorder] = createTestMeterProvider();
348
- assertFalse(await verifyJsonLd(document, {
349
- documentLoader: mockDocumentLoader,
350
- contextLoader: mockDocumentLoader,
351
- meterProvider
352
- }));
353
- assertEquals(recorder.getMeasurements("activitypub.signature.key_fetch.duration").length, 0);
354
- });
355
- await t.step("cached-key retry emits two key_fetch measurements: hit then fetched", async () => {
356
- const [meterProvider, recorder] = createTestMeterProvider();
357
- assert(await verifyJsonLd(testVector, {
358
- documentLoader: mockDocumentLoader,
359
- contextLoader: mockDocumentLoader,
360
- meterProvider,
361
- keyCache: {
362
- async get(keyId) {
363
- return new CryptographicKey({
364
- id: keyId,
365
- owner: new URL("https://activitypub.academy/users/brauca_darradiul"),
366
- publicKey: (await generateCryptoKeyPair("RSASSA-PKCS1-v1_5")).publicKey
367
- });
368
- },
369
- set(_keyId, _key) {
370
- return Promise.resolve();
371
- }
372
- }
373
- }));
374
- const measurements = recorder.getMeasurements("activitypub.signature.key_fetch.duration");
375
- assertEquals(measurements.length, 2);
376
- assertEquals(measurements[0].attributes["activitypub.signature.key_fetch.result"], "hit");
377
- assertEquals(measurements[1].attributes["activitypub.signature.key_fetch.result"], "fetched");
378
- });
379
- await t.step("unknown signature type omits the ld_signatures.type metric attribute", async () => {
380
- const [meterProvider, recorder] = createTestMeterProvider();
381
- assertFalse(await verifyJsonLd({
382
- ...testVector,
383
- signature: {
384
- ...testVector.signature,
385
- type: "MadeUpSignature9999"
386
- }
387
- }, {
388
- documentLoader: mockDocumentLoader,
389
- contextLoader: mockDocumentLoader,
390
- meterProvider
391
- }));
392
- const measurements = recorder.getMeasurements("activitypub.signature.verification.duration");
393
- assertEquals(measurements.length, 1);
394
- assertEquals(measurements[0].attributes["activitypub.signature.result"], "rejected");
395
- assertFalse("ld_signatures.type" in measurements[0].attributes);
396
- });
397
- });
398
- test("compactJsonLd() with restrictive context loader", async () => {
399
- const restrictiveContextLoader = async (resource) => {
400
- const url = new URL(resource).href;
401
- if (url === "https://www.w3.org/ns/activitystreams" || url === "https://w3id.org/identity/v1") return await mockDocumentLoader(url);
402
- throw new Error(`Unexpected context: ${url}`);
403
- };
404
- const signed = await signJsonLd({
405
- "@context": [
406
- "https://www.w3.org/ns/activitystreams",
407
- "https://w3id.org/identity/v1",
408
- "https://w3id.org/security/v1",
409
- "https://w3id.org/security/data-integrity/v1"
410
- ],
411
- id: "https://example.com/1",
412
- type: "Create",
413
- actor: "https://example.com/person2"
414
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader });
415
- assertEquals(await compactJsonLd(signed, restrictiveContextLoader), {
416
- "@context": [
417
- "https://w3id.org/identity/v1",
418
- "https://www.w3.org/ns/activitystreams",
419
- "https://w3id.org/security/v1",
420
- "https://w3id.org/security/data-integrity/v1"
421
- ],
422
- id: "https://example.com/1",
423
- type: "Create",
424
- actor: "https://example.com/person2",
425
- signature: signed.signature
426
- });
427
- });
428
- test("compactJsonLd() caches repeated remote contexts across graph scan and compaction", async () => {
429
- const remoteUrl = "https://example.com/context";
430
- let calls = 0;
431
- const countingLoader = async (resource) => {
432
- const url = new URL(resource).href;
433
- if (url === remoteUrl) {
434
- calls++;
435
- return {
436
- contextUrl: null,
437
- documentUrl: url,
438
- document: { "@context": { extra: "https://example.com/extra" } }
439
- };
440
- }
441
- return await mockDocumentLoader(url);
442
- };
443
- await compactJsonLd({
444
- "@context": "https://www.w3.org/ns/activitystreams",
445
- id: "https://example.com/activities/remote-contexts",
446
- type: "Create",
447
- actor: "https://example.com/person2",
448
- object: [
449
- {
450
- "@context": ["https://www.w3.org/ns/activitystreams", remoteUrl],
451
- type: "Note",
452
- content: "one"
453
- },
454
- {
455
- "@context": ["https://www.w3.org/ns/activitystreams", remoteUrl],
456
- type: "Note",
457
- content: "two"
458
- },
459
- {
460
- "@context": ["https://www.w3.org/ns/activitystreams", remoteUrl],
461
- type: "Note",
462
- content: "three"
463
- }
464
- ]
465
- }, countingLoader);
466
- assertEquals(calls, 1);
467
- });
468
- test("compactJsonLd() reuses the same remote context response for graph scan and compaction", async () => {
469
- const remoteUrl = "https://example.com/context";
470
- let calls = 0;
471
- const compacted = await compactJsonLd({
472
- "@context": [remoteUrl, "https://www.w3.org/ns/activitystreams"],
473
- id: "https://example.com/activities/memoized-remote-context",
474
- type: "Create",
475
- actor: "https://example.com/person2",
476
- graph: "https://example.com/custom-graph",
477
- object: "https://example.com/notes/1"
478
- }, async (resource) => {
479
- const url = new URL(resource).href;
480
- if (url === remoteUrl) {
481
- calls++;
482
- if (calls > 1) throw new Error(`Remote context should not be fetched twice: ${url}`);
483
- return {
484
- contextUrl: null,
485
- documentUrl: url,
486
- document: { "@context": { graph: "https://example.com/graph" } }
487
- };
488
- }
489
- return await mockDocumentLoader(url);
490
- });
491
- assertEquals(calls, 1);
492
- assertEquals(compacted, {
493
- "@context": [
494
- "https://w3id.org/identity/v1",
495
- "https://www.w3.org/ns/activitystreams",
496
- "https://w3id.org/security/v1",
497
- "https://w3id.org/security/data-integrity/v1"
498
- ],
499
- id: "https://example.com/activities/memoized-remote-context",
500
- type: "Create",
501
- actor: "https://example.com/person2",
502
- "https://example.com/graph": "https://example.com/custom-graph",
503
- object: "https://example.com/notes/1"
504
- });
505
- });
506
- test("compactJsonLd() preserves opaque top-level ids and resolves relative remote contexts against documentUrl during graph scan", async () => {
507
- const rootContextId = "opaque-root";
508
- const rootContextUrl = "https://example.com/contexts/root";
509
- const childContextUrl = "https://example.com/contexts/child";
510
- const calls = [];
511
- const customLoader = async (resource) => {
512
- calls.push(resource);
513
- if (resource === rootContextId) return {
514
- contextUrl: null,
515
- documentUrl: rootContextUrl,
516
- document: { "@context": {
517
- "@import": "./child",
518
- ext: "https://example.com/ext"
519
- } }
520
- };
521
- if (resource === childContextUrl || resource === "child") return {
522
- contextUrl: null,
523
- documentUrl: childContextUrl,
524
- document: { "@context": { child: "https://example.com/child" } }
525
- };
526
- return await mockDocumentLoader(resource);
527
- };
528
- assertEquals(await compactJsonLd({
529
- "@context": [rootContextId, "https://www.w3.org/ns/activitystreams"],
530
- id: "https://example.com/activities/custom-loader-contexts",
531
- type: "Create",
532
- actor: "https://example.com/person2",
533
- ext: "preserve-me",
534
- object: {
535
- type: "Note",
536
- content: "Hello"
537
- }
538
- }, customLoader), {
539
- "@context": [
540
- "https://w3id.org/identity/v1",
541
- "https://www.w3.org/ns/activitystreams",
542
- "https://w3id.org/security/v1",
543
- "https://w3id.org/security/data-integrity/v1"
544
- ],
545
- id: "https://example.com/activities/custom-loader-contexts",
546
- type: "Create",
547
- actor: "https://example.com/person2",
548
- "https://example.com/ext": "preserve-me",
549
- object: {
550
- type: "Note",
551
- content: "Hello"
552
- }
553
- });
554
- assert(calls.includes(rootContextId));
555
- assert(calls.includes(childContextUrl));
556
- assertFalse(calls.includes("./child"));
557
- });
558
- test("compactJsonLd() preserves base URLs for property-scoped remote contexts", async () => {
559
- const rootContextId = "opaque-root";
560
- const rootContextUrl = "https://example.com/contexts/root";
561
- const childContextUrl = "https://example.com/contexts/child";
562
- const calls = [];
563
- const customLoader = async (resource) => {
564
- calls.push(resource);
565
- if (resource === rootContextId) return {
566
- contextUrl: null,
567
- documentUrl: rootContextUrl,
568
- document: { "@context": { p: {
569
- "@id": "https://example.com/p",
570
- "@context": "./child"
571
- } } }
572
- };
573
- if (resource === childContextUrl) return {
574
- contextUrl: null,
575
- documentUrl: childContextUrl,
576
- document: { "@context": { nested: "https://example.com/nested" } }
577
- };
578
- return await mockDocumentLoader(resource);
579
- };
580
- assertEquals(await compactJsonLd({
581
- "@context": [rootContextId, "https://www.w3.org/ns/activitystreams"],
582
- id: "https://example.com/activities/property-scoped-contexts",
583
- type: "Create",
584
- actor: "https://example.com/person2",
585
- p: { nested: "value" },
586
- object: "https://example.com/notes/1"
587
- }, customLoader), {
588
- "@context": [
589
- "https://w3id.org/identity/v1",
590
- "https://www.w3.org/ns/activitystreams",
591
- "https://w3id.org/security/v1",
592
- "https://w3id.org/security/data-integrity/v1"
593
- ],
594
- id: "https://example.com/activities/property-scoped-contexts",
595
- type: "Create",
596
- actor: "https://example.com/person2",
597
- "https://example.com/p": { "https://example.com/nested": "value" },
598
- object: "https://example.com/notes/1"
599
- });
600
- assert(calls.includes(rootContextId));
601
- assert(calls.includes(childContextUrl));
602
- assertFalse(calls.includes("./child"));
603
- });
604
- test("compactJsonLd() ignores unsafe-looking keys inside @json values", async () => {
605
- const remoteContextUrl = "https://example.com/contexts/json";
606
- assertEquals(await compactJsonLd({
607
- "@context": [remoteContextUrl, "https://www.w3.org/ns/activitystreams"],
608
- id: "https://example.com/activities/json-blob",
609
- type: "Create",
610
- actor: "https://example.com/person2",
611
- blob: {
612
- graph: { nested: true },
613
- "@reverse": { nope: true },
614
- "@included": [{ still: "raw-json" }]
615
- },
616
- object: "https://example.com/notes/1"
617
- }, async (resource) => {
618
- const url = new URL(resource).href;
619
- if (url === remoteContextUrl) return {
620
- contextUrl: null,
621
- documentUrl: url,
622
- document: { "@context": {
623
- blob: {
624
- "@id": "https://example.com/blob",
625
- "@type": "@json"
626
- },
627
- graph: "@graph"
628
- } }
629
- };
630
- return await mockDocumentLoader(url);
631
- }), {
632
- "@context": [
633
- "https://w3id.org/identity/v1",
634
- "https://www.w3.org/ns/activitystreams",
635
- "https://w3id.org/security/v1",
636
- "https://w3id.org/security/data-integrity/v1"
637
- ],
638
- id: "https://example.com/activities/json-blob",
639
- type: "Create",
640
- "https://example.com/blob": {
641
- type: "@json",
642
- "@value": {
643
- graph: { nested: true },
644
- "@reverse": { nope: true },
645
- "@included": [{ still: "raw-json" }]
646
- }
647
- },
648
- actor: "https://example.com/person2",
649
- object: "https://example.com/notes/1"
650
- });
651
- });
652
- test("compactJsonLd() ignores unsafe-looking keys inside inline @json value wrappers", async () => {
653
- const remoteContextUrl = "https://example.com/contexts/inline-json";
654
- assertEquals(await compactJsonLd({
655
- "@context": [remoteContextUrl, "https://www.w3.org/ns/activitystreams"],
656
- id: "https://example.com/activities/inline-json-blob",
657
- type: "Create",
658
- actor: "https://example.com/person2",
659
- blob: {
660
- "@value": {
661
- graph: { nested: true },
662
- "@reverse": { nope: true },
663
- "@included": [{ still: "raw-json" }]
664
- },
665
- "@type": "@json"
666
- },
667
- object: "https://example.com/notes/1"
668
- }, async (resource) => {
669
- const url = new URL(resource).href;
670
- if (url === remoteContextUrl) return {
671
- contextUrl: null,
672
- documentUrl: url,
673
- document: { "@context": {
674
- blob: "https://example.com/blob",
675
- graph: "@graph"
676
- } }
677
- };
678
- return await mockDocumentLoader(url);
679
- }), {
680
- "@context": [
681
- "https://w3id.org/identity/v1",
682
- "https://www.w3.org/ns/activitystreams",
683
- "https://w3id.org/security/v1",
684
- "https://w3id.org/security/data-integrity/v1"
685
- ],
686
- id: "https://example.com/activities/inline-json-blob",
687
- type: "Create",
688
- "https://example.com/blob": {
689
- type: "@json",
690
- "@value": {
691
- graph: { nested: true },
692
- "@reverse": { nope: true },
693
- "@included": [{ still: "raw-json" }]
694
- }
695
- },
696
- actor: "https://example.com/person2",
697
- object: "https://example.com/notes/1"
698
- });
699
- });
700
- test("verifyJsonLd() respects @graph alias overrides", async () => {
701
- assert(await verifyJsonLd(await signJsonLd({
702
- "@context": [
703
- "https://www.w3.org/ns/activitystreams",
704
- { graph: "@graph" },
705
- { graph: "https://example.com/graph" }
706
- ],
707
- id: "https://example.com/activities/1",
708
- type: "Create",
709
- actor: "https://example.com/person2",
710
- object: "https://example.com/notes/1",
711
- graph: "https://example.com/custom-graph"
712
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }), {
713
- documentLoader: mockDocumentLoader,
714
- contextLoader: mockDocumentLoader
715
- }));
716
- });
717
- test("compactJsonLd() respects nested @context scope for @graph aliases", async () => {
718
- assertEquals(await compactJsonLd({
719
- "@context": ["https://www.w3.org/ns/activitystreams", {
720
- graph: "https://example.com/graph",
721
- meta: {
722
- "@id": "https://example.com/meta",
723
- "@context": { graph: "@graph" }
724
- }
725
- }],
726
- id: "https://example.com/activities/2",
727
- type: "Create",
728
- actor: "https://example.com/person2",
729
- object: "https://example.com/notes/2",
730
- graph: "https://example.com/custom-graph",
731
- meta: { value: "ok" }
732
- }, mockDocumentLoader), {
733
- "@context": [
734
- "https://w3id.org/identity/v1",
735
- "https://www.w3.org/ns/activitystreams",
736
- "https://w3id.org/security/v1",
737
- "https://w3id.org/security/data-integrity/v1"
738
- ],
739
- id: "https://example.com/activities/2",
740
- type: "Create",
741
- "https://example.com/graph": "https://example.com/custom-graph",
742
- actor: "https://example.com/person2",
743
- object: "https://example.com/notes/2",
744
- "https://example.com/meta": { value: "ok" }
745
- });
746
- });
747
- test("compactJsonLd() resets inherited @graph aliases on @context: null", async () => {
748
- assertEquals(await compactJsonLd({
749
- "@context": ["https://www.w3.org/ns/activitystreams", { g: "@graph" }],
750
- id: "https://example.com/activities/3",
751
- type: "Create",
752
- actor: "https://example.com/person2",
753
- object: {
754
- "@context": null,
755
- g: "literal"
756
- }
757
- }, mockDocumentLoader), {
758
- "@context": [
759
- "https://w3id.org/identity/v1",
760
- "https://www.w3.org/ns/activitystreams",
761
- "https://w3id.org/security/v1",
762
- "https://w3id.org/security/data-integrity/v1"
763
- ],
764
- id: "https://example.com/activities/3",
765
- type: "Create",
766
- actor: "https://example.com/person2",
767
- object: {}
768
- });
769
- });
770
- test("compactJsonLd() rejects same-object forward @graph alias chains", async () => {
771
- await assertRejects(() => compactJsonLd({
772
- "@context": ["https://www.w3.org/ns/activitystreams", {
773
- a: "b",
774
- b: "@graph"
775
- }],
776
- id: "https://example.com/activities/forward-graph-alias",
777
- type: "Create",
778
- actor: "https://example.com/person2",
779
- a: [{
780
- id: "https://example.com/notes/forward-graph-alias",
781
- type: "Note",
782
- content: "Hello"
783
- }]
784
- }, mockDocumentLoader), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
785
- });
786
- test("compactJsonLd() preserves captured @graph aliases across later overrides", async () => {
787
- await assertRejects(() => compactJsonLd({
788
- "@context": [
789
- "https://www.w3.org/ns/activitystreams",
790
- { b: "@graph" },
791
- { a: "b" },
792
- { b: "https://example.com/b" }
793
- ],
794
- id: "https://example.com/activities/captured-graph-alias",
795
- type: "Create",
796
- actor: "https://example.com/person2",
797
- a: [{
798
- id: "https://example.com/notes/captured-graph-alias",
799
- type: "Note",
800
- content: "Hello"
801
- }]
802
- }, mockDocumentLoader), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
803
- });
804
- test("compactJsonLd() does not retroactively apply later @graph aliases", async () => {
805
- assertEquals(await compactJsonLd({
806
- "@context": [
807
- "https://www.w3.org/ns/activitystreams",
808
- { a: "b" },
809
- { b: "@graph" }
810
- ],
811
- id: "https://example.com/activities/non-retroactive-graph-alias",
812
- type: "Create",
813
- actor: "https://example.com/person2",
814
- a: [{
815
- id: "https://example.com/notes/non-retroactive-graph-alias",
816
- type: "Note",
817
- content: "Hello"
818
- }]
819
- }, mockDocumentLoader), {
820
- "@context": [
821
- "https://w3id.org/identity/v1",
822
- "https://www.w3.org/ns/activitystreams",
823
- "https://w3id.org/security/v1",
824
- "https://w3id.org/security/data-integrity/v1"
825
- ],
826
- id: "https://example.com/activities/non-retroactive-graph-alias",
827
- type: "Create",
828
- b: {
829
- id: "https://example.com/notes/non-retroactive-graph-alias",
830
- type: "Note",
831
- content: "Hello"
832
- },
833
- actor: "https://example.com/person2"
834
- });
835
- });
836
- test("verifyJsonLd() rejects unsafe JSON-LD keywords", async () => {
837
- const original = {
838
- "@context": "https://www.w3.org/ns/activitystreams",
839
- id: "https://example.com/activities/undo",
840
- type: "Undo",
841
- actor: "https://example.com/person2",
842
- object: {
843
- id: "https://example.com/activities/announce",
844
- type: "Announce",
845
- actor: "https://example.com/person2",
846
- object: "https://example.com/status/1"
847
- }
848
- };
849
- const signed = await signJsonLd(original, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader });
850
- const options = {
851
- documentLoader: mockDocumentLoader,
852
- contextLoader: mockDocumentLoader
853
- };
854
- const cases = [
855
- ["@reverse", {
856
- "@context": ["https://www.w3.org/ns/activitystreams", { rev: "@reverse" }],
857
- id: "https://example.com/activities/announce",
858
- type: "Announce",
859
- actor: "https://example.com/person2",
860
- object: "https://example.com/status/1",
861
- rev: { object: {
862
- id: "https://example.com/activities/undo",
863
- type: "Undo",
864
- actor: "https://example.com/person2"
865
- } },
866
- signature: signed.signature
867
- }],
868
- ["@included", {
869
- "@context": ["https://www.w3.org/ns/activitystreams", { inc: "@included" }],
870
- id: "https://example.com/activities/announce",
871
- type: "Announce",
872
- actor: "https://example.com/person2",
873
- object: "https://example.com/status/1",
874
- inc: [{
875
- id: "https://example.com/activities/undo",
876
- type: "Undo",
877
- actor: "https://example.com/person2",
878
- object: "https://example.com/activities/announce"
879
- }],
880
- signature: signed.signature
881
- }],
882
- ["@graph", {
883
- "@context": ["https://www.w3.org/ns/activitystreams", { graph: "@graph" }],
884
- graph: [original],
885
- signature: signed.signature
886
- }],
887
- ["@graph", {
888
- "@context": ["https://www.w3.org/ns/activitystreams", { graph: "@graph" }],
889
- id: "https://example.com/activities/announce",
890
- type: "Announce",
891
- actor: "https://example.com/person2",
892
- object: "https://example.com/status/1",
893
- graph: [{
894
- id: "https://example.com/activities/undo",
895
- type: "Undo",
896
- actor: "https://example.com/person2",
897
- object: "https://example.com/activities/announce"
898
- }],
899
- signature: signed.signature
900
- }]
901
- ];
902
- for (const [keyword, jsonLd] of cases) await assertRejects(() => verifyJsonLd(jsonLd, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
903
- });
904
- test("compactJsonLd() rejects unsafe JSON-LD keywords inside signature objects", async () => {
905
- const signed = await signJsonLd({
906
- "@context": "https://www.w3.org/ns/activitystreams",
907
- id: "https://example.com/activities/signed-signature-keywords",
908
- type: "Create",
909
- actor: "https://example.com/person2",
910
- object: "https://example.com/notes/1"
911
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader });
912
- for (const [keyword, value] of [
913
- ["@reverse", { object: {
914
- id: "https://example.com/activities/reverse-inside-signature",
915
- type: "Undo"
916
- } }],
917
- ["@included", [{
918
- id: "https://example.com/activities/included-inside-signature",
919
- type: "Undo"
920
- }]],
921
- ["@graph", [{
922
- id: "https://example.com/activities/graph-inside-signature",
923
- type: "Undo"
924
- }]]
925
- ]) await assertRejects(() => compactJsonLd({
926
- ...signed,
927
- signature: {
928
- ...signed.signature,
929
- [keyword]: value
930
- }
931
- }, mockDocumentLoader), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
932
- });
933
- test("compactJsonLd() rejects inputs that compact into @graph wrappers", async () => {
934
- await assertRejects(() => compactJsonLd([{
935
- "@context": "https://www.w3.org/ns/activitystreams",
936
- id: "https://example.com/notes/graph-wrapper-1",
937
- type: "Note",
938
- content: "one"
939
- }, {
940
- "@context": "https://www.w3.org/ns/activitystreams",
941
- id: "https://example.com/notes/graph-wrapper-2",
942
- type: "Note",
943
- content: "two"
944
- }], mockDocumentLoader), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
945
- });
946
- test("verifyJsonLd() rejects a key that claims a forged owner", async () => {
947
- const keyId = new URL("https://attacker.example/key");
948
- const impersonated = "https://example.com/person";
949
- const { publicKeyPem } = await rsaPublicKey2.toJsonLd({ contextLoader: mockDocumentLoader });
950
- const signed = await signJsonLd({
951
- "@context": "https://www.w3.org/ns/activitystreams",
952
- id: "https://attacker.example/activities/1",
953
- type: "Create",
954
- actor: impersonated
955
- }, rsaPrivateKey2, keyId, { contextLoader: mockDocumentLoader });
956
- const serveKeyOwnedBy = (owner) => (resource) => {
957
- if (resource === keyId.href) return Promise.resolve({
958
- contextUrl: null,
959
- documentUrl: resource,
960
- document: {
961
- "@context": "https://w3id.org/security/v1",
962
- id: keyId.href,
963
- type: "CryptographicKey",
964
- owner,
965
- publicKeyPem
966
- }
967
- });
968
- if (resource === "https://attacker.example/actor") return Promise.resolve({
969
- contextUrl: null,
970
- documentUrl: resource,
971
- document: {
972
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
973
- id: resource,
974
- type: "Person",
975
- publicKey: [keyId.href]
976
- }
977
- });
978
- return mockDocumentLoader(resource);
979
- };
980
- assertEquals(await verifySignature(signed, {
981
- documentLoader: serveKeyOwnedBy(impersonated),
982
- contextLoader: mockDocumentLoader
983
- }), null);
984
- assertFalse(await verifyJsonLd(signed, {
985
- documentLoader: serveKeyOwnedBy(impersonated),
986
- contextLoader: mockDocumentLoader
987
- }));
988
- const honestLoader = serveKeyOwnedBy("https://attacker.example/actor");
989
- assertInstanceOf(await verifySignature(signed, {
990
- documentLoader: honestLoader,
991
- contextLoader: mockDocumentLoader
992
- }), CryptographicKey);
993
- assertFalse(await verifyJsonLd(signed, {
994
- documentLoader: honestLoader,
995
- contextLoader: mockDocumentLoader
996
- }));
997
- });
998
- test("verifyJsonLd() rejects a key whose owner redirects to another actor", async () => {
999
- const keyId = new URL("https://evil.example/keys/1");
1000
- const victim = "https://victim.example/users/alice";
1001
- const mallory = "https://evil.example/users/mallory";
1002
- const { publicKeyPem } = await rsaPublicKey3.toJsonLd({ contextLoader: mockDocumentLoader });
1003
- const signed = await signJsonLd({
1004
- "@context": "https://www.w3.org/ns/activitystreams",
1005
- id: "https://victim.example/activities/forged",
1006
- type: "Create",
1007
- actor: victim,
1008
- object: {
1009
- type: "Note",
1010
- content: "forged"
1011
- }
1012
- }, rsaPrivateKey3, keyId, { contextLoader: mockDocumentLoader });
1013
- const options = {
1014
- documentLoader(resource) {
1015
- if (resource === keyId.href) return Promise.resolve({
1016
- contextUrl: null,
1017
- documentUrl: resource,
1018
- document: {
1019
- "@context": "https://w3id.org/security/v1",
1020
- id: keyId.href,
1021
- type: "CryptographicKey",
1022
- owner: victim,
1023
- publicKeyPem
1024
- }
1025
- });
1026
- if (resource === victim || resource === mallory) return Promise.resolve({
1027
- contextUrl: null,
1028
- documentUrl: mallory,
1029
- document: {
1030
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
1031
- id: mallory,
1032
- type: "Person",
1033
- publicKey: keyId.href
1034
- }
1035
- });
1036
- return mockDocumentLoader(resource);
1037
- },
1038
- contextLoader: mockDocumentLoader
1039
- };
1040
- assertEquals(await verifySignature(signed, options), null);
1041
- assertFalse(await verifyJsonLd(signed, options));
1042
- });
1043
- //#endregion
1044
- export {};