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

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-C0zalE9W.cjs} +8 -3
  4. package/dist/{http-T7h9GBAN.js → http-BC5Bd3-E.js} +1 -1
  5. package/dist/{http-CXX-QPzs.cjs → http-Dqzgc4Rj.cjs} +1 -1
  6. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CQ0u0Ry0.js} +1 -1
  7. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-ihEHdx1v.cjs} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-Bgm3A90j.js} +8 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-DZ_XqNUM.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-nvog8lS6.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 +35 -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,933 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { t as esm_default } from "../esm-BHXXx4Wx.mjs";
5
- import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
6
- import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
7
- import "../std__assert-DvMDRPes.mjs";
8
- import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
9
- import { t as assert } from "../assert-D1Eafmd_.mjs";
10
- import { s as detachSignature, x as exportJwk } from "../ld-BpkhkDGj.mjs";
11
- import { s as signObject } from "../proof-BlfZ95--.mjs";
12
- import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
13
- import { C as getEmbeddedFirstGateway, S as getCompactRootId, c as assertPortableActorActivity, n as FederationImpl, o as createFederation, w as warnCompatibleIdsInJson } from "../middleware-DcXzz-YK.mjs";
14
- import { o as verifyCompoundPortableObjectProofs } from "../compound-proof-DSHhnOEW.mjs";
15
- import { configure, reset } from "@logtape/logtape";
16
- import { Accept, Announce, Create, Follow, Note, Person } from "@fedify/vocab";
17
- import { exportDidKey, parseIri } from "@fedify/vocab-runtime";
18
- import { mockDocumentLoader, test } from "@fedify/fixture";
19
- //#region src/federation/outgoing-proof.test.ts
20
- const options = {
21
- contextLoader: mockDocumentLoader,
22
- documentLoader: mockDocumentLoader
23
- };
24
- const created = Temporal.Instant.from("2023-02-24T23:36:38Z");
25
- const childContext = [
26
- "https://www.w3.org/ns/activitystreams",
27
- "https://w3id.org/security/data-integrity/v1",
28
- { ex: "https://example.com/ns#" }
29
- ];
30
- const limits = {
31
- maxDepth: 64,
32
- maxMaps: 1e4,
33
- maxProofs: 32,
34
- maxBytes: 10 * 1024 * 1024
35
- };
36
- const recipient = {
37
- id: new URL("https://example.com/users/bob"),
38
- inboxId: new URL("https://example.com/inbox")
39
- };
40
- const rsaKey = {
41
- keyId: rsaPublicKey2.id,
42
- privateKey: rsaPrivateKey2
43
- };
44
- async function didKey(pair) {
45
- const { privateKey, publicKey } = pair ?? await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
46
- const did = await exportDidKey(publicKey);
47
- return {
48
- did,
49
- keyId: new URL(`${did}#${did.substring(8)}`),
50
- privateKey,
51
- publicKey
52
- };
53
- }
54
- function sender(key) {
55
- return {
56
- keyId: key.keyId,
57
- privateKey: key.privateKey
58
- };
59
- }
60
- async function signedChild(owner) {
61
- return await signObject(new Note({
62
- id: parseIri(`ap+ef61://${owner.did}/objects/${crypto.randomUUID()}`),
63
- attribution: parseIri(`ap+ef61://${owner.did}/actor`),
64
- content: "A portable note"
65
- }), owner.privateKey, owner.keyId, {
66
- ...options,
67
- context: childContext,
68
- created
69
- });
70
- }
71
- function portableCreate(owner, object) {
72
- return new Create({
73
- id: parseIri(`ap+ef61://${owner.did}/activities/${crypto.randomUUID()}`),
74
- actor: parseIri(`ap+ef61://${owner.did}/actor`),
75
- object
76
- });
77
- }
78
- function httpCreate(object) {
79
- return new Create({
80
- id: new URL(`https://example.com/activities/${crypto.randomUUID()}`),
81
- actor: new URL("https://example.com/users/alice"),
82
- object
83
- });
84
- }
85
- function createQueue() {
86
- const queued = [];
87
- return {
88
- queued,
89
- queue: {
90
- enqueue(message) {
91
- queued.push(message);
92
- return Promise.resolve();
93
- },
94
- listen() {
95
- return Promise.resolve();
96
- }
97
- }
98
- };
99
- }
100
- function createTestFederation(queue) {
101
- const federation = new FederationImpl({
102
- kv: new MemoryKvStore(),
103
- queue,
104
- manuallyStartQueue: true,
105
- contextLoaderFactory: () => mockDocumentLoader,
106
- documentLoaderFactory: () => mockDocumentLoader
107
- });
108
- federation.allowPrivateAddress = true;
109
- federation.setInboxListeners("/users/{identifier}/inbox", "/inbox");
110
- return federation;
111
- }
112
- /**
113
- * Captures what is POSTed to the recipient's inbox while `run` executes.
114
- */
115
- async function capture(run) {
116
- const bodies = [];
117
- const requests = [];
118
- esm_default.spyGlobal();
119
- try {
120
- esm_default.post(recipient.inboxId.href, async (cl) => {
121
- const body = await cl.request.text();
122
- requests.push(new Request(cl.request.url, {
123
- method: cl.request.method,
124
- headers: cl.request.headers,
125
- body
126
- }));
127
- bodies.push(JSON.parse(body));
128
- return new Response(null, { status: 202 });
129
- });
130
- await run();
131
- } finally {
132
- esm_default.hardReset();
133
- }
134
- return {
135
- bodies,
136
- requests
137
- };
138
- }
139
- function proofOf(document) {
140
- const proof = document.proof;
141
- assert(proof != null && typeof proof === "object" && !Array.isArray(proof), `expected exactly one direct proof, got ${JSON.stringify(proof)}`);
142
- return proof;
143
- }
144
- async function assertCompoundVerifies(body) {
145
- const result = await verifyCompoundPortableObjectProofs(detachSignature(body), limits, options);
146
- assertEquals(result.status, "ok");
147
- assert(result.status === "ok" && result.verified);
148
- }
149
- test("a portable activity with one Ed25519 key gets one direct proof", async () => {
150
- const owner = await didKey();
151
- const child = await signedChild(await didKey());
152
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
153
- const { bodies, requests } = await capture(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, portableCreate(owner, child)));
154
- assertEquals(bodies.length, 1);
155
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
156
- assert(requests[0].headers.has("Signature"));
157
- assertEquals(bodies[0].signature, void 0);
158
- await assertCompoundVerifies(bodies[0]);
159
- });
160
- test("a portable activity is signed only by the key matching its DID", async () => {
161
- const owner = await didKey();
162
- const other = await didKey();
163
- const childOwner = await didKey();
164
- const child = await signedChild(childOwner);
165
- for (const keys of [[other, owner], [owner, other]]) {
166
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
167
- const { bodies, requests } = await capture(() => ctx.sendActivity([
168
- rsaKey,
169
- ...keys.map(sender),
170
- sender(childOwner)
171
- ], recipient, portableCreate(owner, child)));
172
- assertEquals(bodies.length, 1);
173
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
174
- assert(requests[0].headers.has("Signature"));
175
- const embedded = bodies[0].object;
176
- assertEquals(embedded["@context"], childContext);
177
- assertEquals(proofOf(embedded).verificationMethod, childOwner.keyId.href);
178
- await assertCompoundVerifies(bodies[0]);
179
- }
180
- });
181
- test("a portable activity without exactly one DID-matching key is rejected", async () => {
182
- const owner = await didKey();
183
- const child = await signedChild(await didKey());
184
- const cases = [
185
- [
186
- "no key matches",
187
- [sender(await didKey()), sender(await didKey())],
188
- "none of its 2 Ed25519 keys"
189
- ],
190
- [
191
- "a same-origin key ID is not a DID URL",
192
- [{
193
- keyId: parseIri(`ap+ef61://${owner.did}/actor#main-key`),
194
- privateKey: owner.privateKey
195
- }, sender(await didKey())],
196
- "none of its 1 Ed25519 keys"
197
- ],
198
- [
199
- "several keys match",
200
- [sender(owner), {
201
- keyId: new URL(`${owner.did}#second`),
202
- privateKey: owner.privateKey
203
- }],
204
- "2 of its Ed25519 keys"
205
- ]
206
- ];
207
- for (const [name, keys, message] of cases) {
208
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
209
- const { bodies } = await capture(() => assertRejects(() => ctx.sendActivity([rsaKey, ...keys], recipient, portableCreate(owner, child)), TypeError, message));
210
- assertEquals(bodies.length, 0, name);
211
- }
212
- });
213
- test("a non-portable activity embedding portable objects needs one key", async () => {
214
- const child = await signedChild(await didKey());
215
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
216
- const keys = [sender(await didKey()), sender(await didKey())];
217
- assertEquals((await capture(() => assertRejects(() => ctx.sendActivity([rsaKey, ...keys], recipient, httpCreate(child)), TypeError, "exactly one Ed25519 key"))).bodies.length, 0);
218
- const key = {
219
- keyId: ed25519PublicKey.id,
220
- privateKey: ed25519PrivateKey
221
- };
222
- const accepted = await capture(() => ctx.sendActivity([rsaKey, key], recipient, httpCreate(child)));
223
- assertEquals(accepted.bodies.length, 1);
224
- assertEquals(proofOf(accepted.bodies[0]).verificationMethod, ed25519PublicKey.id.href);
225
- });
226
- test("a non-portable activity embedding compatible-ID objects needs one key", async () => {
227
- const owner = await didKey();
228
- const compatibleId = (path) => new URL(`https://gw.example/.well-known/apgateway/${owner.did}${path}`);
229
- const child = await signObject(new Note({
230
- id: compatibleId(`/objects/${crypto.randomUUID()}`),
231
- attribution: compatibleId("/actor"),
232
- content: "A portable note"
233
- }), owner.privateKey, owner.keyId, {
234
- ...options,
235
- context: childContext,
236
- created
237
- });
238
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
239
- const keys = [sender(await didKey()), sender(await didKey())];
240
- assertEquals((await capture(() => assertRejects(() => ctx.sendActivity([rsaKey, ...keys], recipient, httpCreate(child)), TypeError, "exactly one Ed25519 key"))).bodies.length, 0);
241
- const key = {
242
- keyId: ed25519PublicKey.id,
243
- privateKey: ed25519PrivateKey
244
- };
245
- const accepted = await capture(() => ctx.sendActivity([rsaKey, key], recipient, httpCreate(child)));
246
- assertEquals(accepted.bodies.length, 1);
247
- await assertCompoundVerifies(accepted.bodies[0]);
248
- });
249
- test("an activity without portable objects is still signed by every key", async () => {
250
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
251
- const keys = [await didKey(), await didKey()];
252
- const { bodies } = await capture(() => ctx.sendActivity([rsaKey, ...keys.map(sender)], recipient, httpCreate(new Note({ content: "Hello" }))));
253
- assertEquals(bodies.length, 1);
254
- const proofs = bodies[0].proof;
255
- assert(Array.isArray(proofs));
256
- assertEquals(proofs.map((proof) => proof.verificationMethod), keys.map((key) => key.keyId.href));
257
- });
258
- test("a pre-signed portable activity is not re-signed", async () => {
259
- const owner = await didKey();
260
- const activity = await signObject(portableCreate(owner, await signedChild(await didKey())), owner.privateKey, owner.keyId, {
261
- ...options,
262
- created
263
- });
264
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
265
- const keys = [sender(await didKey()), sender(await didKey())];
266
- const { bodies } = await capture(() => ctx.sendActivity([rsaKey, ...keys], recipient, activity));
267
- assertEquals(bodies.length, 1);
268
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
269
- await assertCompoundVerifies(bodies[0]);
270
- });
271
- test("a portable activity carrying a proof set is not delivered", async () => {
272
- const owner = await didKey();
273
- const second = {
274
- ...owner,
275
- keyId: new URL(`${owner.did}#second`)
276
- };
277
- let activity = portableCreate(owner, await signedChild(owner));
278
- for (const key of [owner, second]) activity = await signObject(activity, key.privateKey, key.keyId, {
279
- ...options,
280
- created
281
- });
282
- assertEquals((await capture(() => assertRejects(() => createTestFederation().createContext(new URL("https://example.com/")).sendActivity(rsaKey, recipient, activity), TypeError, "JSON Pointer \"/proof\""))).bodies.length, 0);
283
- const outbox = createQueue();
284
- await assertRejects(() => createTestFederation(outbox.queue).createContext(new URL("https://example.com/")).sendActivity(rsaKey, recipient, activity, { fanout: "skip" }), TypeError, "JSON Pointer \"/proof\"");
285
- assertEquals(outbox.queued.length, 0);
286
- const fanout = createQueue();
287
- await assertRejects(() => createTestFederation(fanout.queue).createContext(new URL("https://example.com/")).sendActivity(rsaKey, recipient, activity, { fanout: "force" }), TypeError, "JSON Pointer \"/proof\"");
288
- assertEquals(fanout.queued.length, 0);
289
- });
290
- test("a proof set on an embedded map is not delivered either", async () => {
291
- const owner = await didKey();
292
- let child = await signedChild(owner);
293
- child = await signObject(child, owner.privateKey, new URL(`${owner.did}#b`), {
294
- ...options,
295
- created
296
- });
297
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
298
- const { bodies } = await capture(() => assertRejects(() => ctx.sendActivity(rsaKey, recipient, httpCreate(child)), TypeError, "JSON Pointer \"/object/proof\""));
299
- assertEquals(bodies.length, 0);
300
- });
301
- test("a received signed object rebuilt inside a portable activity is not delivered", async () => {
302
- const followerKey = await didKey();
303
- const signedFollow = await signObject(new Follow({
304
- id: new URL("https://example.com/follows/1"),
305
- actor: new URL("https://example.com/users/bob"),
306
- object: parseIri("ap+ef61://did:key:z6Mkabc/actor")
307
- }), followerKey.privateKey, new URL("https://example.com/users/bob#key"), {
308
- ...options,
309
- created
310
- });
311
- const follow = await Follow.fromJsonLd(await signedFollow.toJsonLd({
312
- format: "compact",
313
- ...options
314
- }), options);
315
- const owner = await didKey();
316
- const accept = (object) => new Accept({
317
- id: parseIri(`ap+ef61://${owner.did}/accepts/${crypto.randomUUID()}`),
318
- actor: parseIri(`ap+ef61://${owner.did}/actor`),
319
- object
320
- });
321
- const unsigned = accept(follow);
322
- const presigned = await signObject(accept(follow), owner.privateKey, owner.keyId, {
323
- ...options,
324
- created
325
- });
326
- const cases = [[unsigned, [rsaKey, sender(owner)]], [presigned, [rsaKey]]];
327
- for (const [activity, keys] of cases) {
328
- assertEquals((await capture(() => assertRejects(() => createTestFederation().createContext(new URL("https://example.com/")).sendActivity(keys, recipient, activity), TypeError, "JSON Pointer \"/object\""))).bodies.length, 0);
329
- const fanout = createQueue();
330
- await assertRejects(() => createTestFederation(fanout.queue).createContext(new URL("https://example.com/")).sendActivity(keys, recipient, activity, { fanout: "force" }), TypeError, "JSON Pointer \"/object\"");
331
- assertEquals(fanout.queued.length, 0);
332
- }
333
- const { bodies } = await capture(() => createTestFederation().createContext(new URL("https://example.com/")).sendActivity([rsaKey, sender(owner)], recipient, accept(follow.id)));
334
- assertEquals(bodies.length, 1);
335
- await assertCompoundVerifies(bodies[0]);
336
- });
337
- test("forced fanout selects the DID-matching key before enqueueing", async () => {
338
- const owner = await didKey();
339
- const childOwner = await didKey();
340
- const child = await signedChild(childOwner);
341
- const { queue, queued } = createQueue();
342
- const federation = createTestFederation(queue);
343
- const ctx = federation.createContext(new URL("https://example.com/"));
344
- const { bodies } = await capture(async () => {
345
- await ctx.sendActivity([
346
- rsaKey,
347
- sender(await didKey()),
348
- sender(owner)
349
- ], recipient, portableCreate(owner, child), { fanout: "force" });
350
- assertEquals(queued.length, 1);
351
- const message = queued[0];
352
- assertEquals(message.type, "fanout");
353
- assertEquals(message.keys.length, 3);
354
- assertEquals(message.keys[0].keyId, rsaKey.keyId.href);
355
- for (const message of queued) await federation.processQueuedTask(void 0, message);
356
- });
357
- assertEquals(bodies.length, 1);
358
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
359
- const embedded = bodies[0].object;
360
- assertEquals(embedded["@context"], childContext);
361
- assertEquals(proofOf(embedded).verificationMethod, childOwner.keyId.href);
362
- await assertCompoundVerifies(bodies[0]);
363
- });
364
- test("the fanout worker selects one key for an unsigned portable activity", async () => {
365
- const owner = await didKey();
366
- const child = await signedChild(await didKey());
367
- const federation = createTestFederation();
368
- const message = async (activity) => ({
369
- type: "fanout",
370
- id: crypto.randomUUID(),
371
- baseUrl: "https://example.com",
372
- keys: await Promise.all([
373
- rsaKey,
374
- sender(await didKey()),
375
- sender(owner)
376
- ].map(async (key) => ({
377
- keyId: key.keyId.href,
378
- privateKey: await exportJwk(key.privateKey)
379
- }))),
380
- inboxes: { [recipient.inboxId.href]: {
381
- actorIds: [recipient.id.href],
382
- sharedInbox: false
383
- } },
384
- activity: await activity.toJsonLd({
385
- format: "compact",
386
- ...options
387
- }),
388
- activityId: activity.id.href,
389
- activityType: "https://www.w3.org/ns/activitystreams#Create",
390
- traceContext: {}
391
- });
392
- const byId = new Create({
393
- id: parseIri(`ap+ef61://${owner.did}/activities/${crypto.randomUUID()}`),
394
- actor: parseIri(`ap+ef61://${owner.did}/actor`),
395
- object: child.id
396
- });
397
- const { bodies } = await capture(async () => federation.processQueuedTask(void 0, await message(byId)));
398
- assertEquals(bodies.length, 1);
399
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
400
- await assertCompoundVerifies(bodies[0]);
401
- const embedded = await message(portableCreate(owner, child));
402
- assertEquals((await capture(() => assertRejects(() => federation.processQueuedTask(void 0, embedded), TypeError, "JSON Pointer \"/object\""))).bodies.length, 0);
403
- });
404
- test("actor key pairs follow the compound-proof key selection too", async () => {
405
- const dispatched = [];
406
- const federation = createTestFederation();
407
- federation.setActorDispatcher("/users/{identifier}", (ctx, identifier) => new Person({
408
- id: ctx.getActorUri(identifier),
409
- inbox: ctx.getInboxUri(identifier)
410
- })).setKeyPairsDispatcher(() => dispatched);
411
- const ctx = federation.createContext(new URL("https://example.com/"));
412
- const owner = await didKey();
413
- const child = await signedChild(await didKey());
414
- const other = await didKey();
415
- dispatched.push({
416
- privateKey: rsaPrivateKey2,
417
- publicKey: rsaPublicKey2.publicKey
418
- }, {
419
- privateKey: owner.privateKey,
420
- publicKey: owner.publicKey
421
- }, {
422
- privateKey: other.privateKey,
423
- publicKey: other.publicKey
424
- });
425
- assertEquals((await capture(() => assertRejects(() => ctx.sendActivity({ identifier: "alice" }, recipient, portableCreate(owner, child)), TypeError, "none of its 2 Ed25519 keys"))).bodies.length, 0);
426
- dispatched.splice(2);
427
- const presigned = await signObject(portableCreate(owner, child), owner.privateKey, owner.keyId, {
428
- ...options,
429
- created
430
- });
431
- const kept = await capture(() => ctx.sendActivity({ identifier: "alice" }, recipient, presigned));
432
- assertEquals(kept.bodies.length, 1);
433
- assertEquals(proofOf(kept.bodies[0]).verificationMethod, owner.keyId.href);
434
- const ordinary = await signObject(httpCreate(new Note({ content: "Hello" })), owner.privateKey, owner.keyId, {
435
- ...options,
436
- created
437
- });
438
- const appended = await capture(() => ctx.sendActivity({ identifier: "alice" }, recipient, ordinary));
439
- assertEquals(appended.bodies.length, 1);
440
- const proofs = appended.bodies[0].proof;
441
- assert(Array.isArray(proofs));
442
- assertEquals(proofs.map((proof) => proof.verificationMethod), [owner.keyId.href, "https://example.com/users/alice#multikey-2"]);
443
- });
444
- test("a Fedify inbox accepts a portable activity Fedify produced", async () => {
445
- const owner = await didKey();
446
- const child = await signedChild(await didKey());
447
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
448
- const other = await didKey();
449
- const { requests } = await capture(() => ctx.sendActivity([sender(other), sender(owner)], recipient, portableCreate(owner, child)));
450
- assertEquals(requests.length, 1);
451
- let received = 0;
452
- const receiving = createFederation({
453
- kv: new MemoryKvStore(),
454
- contextLoaderFactory: () => mockDocumentLoader,
455
- documentLoaderFactory: () => mockDocumentLoader
456
- });
457
- receiving.setActorDispatcher("/users/{identifier}", () => null);
458
- receiving.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
459
- received++;
460
- });
461
- assertEquals([(await receiving.fetch(requests[0], { contextData: void 0 })).status, received], [202, 1]);
462
- });
463
- const gateway = "https://gw.example";
464
- function compatibleId(did, path, origin = gateway) {
465
- return new URL(`${origin}/.well-known/apgateway/${did}${path}`);
466
- }
467
- function compatibleCreate(owner, object, { id, actor } = {}) {
468
- return new Create({
469
- id: id ?? compatibleId(owner.did, `/activities/${crypto.randomUUID()}`),
470
- actor: actor ?? compatibleId(owner.did, "/actor"),
471
- object
472
- });
473
- }
474
- test("a compatible-ID activity is signed only by the key matching its DID", async () => {
475
- const owner = await didKey();
476
- const childOwner = await didKey();
477
- const child = await signedChild(childOwner);
478
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
479
- const { bodies, requests } = await capture(async () => ctx.sendActivity([
480
- rsaKey,
481
- sender(await didKey()),
482
- sender(owner),
483
- sender(childOwner)
484
- ], recipient, compatibleCreate(owner, child)));
485
- assertEquals(bodies.length, 1);
486
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
487
- assert(requests[0].headers.has("Signature"));
488
- assertEquals(bodies[0].signature, void 0);
489
- await assertCompoundVerifies(bodies[0]);
490
- });
491
- test("a compatible-ID actor's activity needs an ID of the actor's DID", async () => {
492
- const owner = await didKey();
493
- const other = await didKey();
494
- const cases = [
495
- [
496
- "a compatible activity ID of another DID",
497
- compatibleCreate(owner, void 0, { id: compatibleId(other.did, "/activities/1") }),
498
- "with the same DID"
499
- ],
500
- [
501
- "an ap: activity ID of another DID",
502
- compatibleCreate(owner, void 0, { id: parseIri(`ap://${other.did}/activities/1`) }),
503
- "with the same DID"
504
- ],
505
- [
506
- "an ordinary activity ID",
507
- compatibleCreate(owner, void 0, { id: new URL("https://gw.example/activities/1") }),
508
- "with the same DID"
509
- ],
510
- [
511
- "a malformed compatible activity ID",
512
- compatibleCreate(owner, void 0, { id: new URL(compatibleId(owner.did, "/activities/1").href + "?@gateway=https%3A%2F%2Fgw.example") }),
513
- "with the same DID"
514
- ],
515
- [
516
- "a malformed compatible actor ID",
517
- compatibleCreate(owner, void 0, { actor: new URL(compatibleId(owner.did, "/actor").href + "?@gateway=https%3A%2F%2Fgw.example") }),
518
- "malformed FEP-ef61 portable ID"
519
- ],
520
- [
521
- "compatible actors of different DIDs",
522
- new Create({
523
- id: compatibleId(owner.did, "/activities/1"),
524
- actors: [compatibleId(owner.did, "/actor"), compatibleId(other.did, "/actor")]
525
- }),
526
- "different DIDs"
527
- ]
528
- ];
529
- for (const [name, activity, message] of cases) {
530
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
531
- const { bodies } = await capture(() => assertRejects(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, activity), TypeError, message));
532
- assertEquals(bodies.length, 0, name);
533
- }
534
- });
535
- test("a compatible-ID activity without exactly one DID-matching key is rejected", async () => {
536
- const owner = await didKey();
537
- const cases = [
538
- [
539
- "no key matches",
540
- [sender(await didKey())],
541
- "none of its 1 Ed25519 keys"
542
- ],
543
- [
544
- "only a gateway key",
545
- [{
546
- keyId: compatibleId(owner.did, "/actor#main-key"),
547
- privateKey: owner.privateKey
548
- }],
549
- "none of its 0 Ed25519 keys"
550
- ],
551
- [
552
- "several keys match",
553
- [sender(owner), {
554
- keyId: new URL(`${owner.did}#second`),
555
- privateKey: owner.privateKey
556
- }],
557
- "2 of its Ed25519 keys"
558
- ]
559
- ];
560
- for (const [name, keys, message] of cases) {
561
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
562
- const { bodies } = await capture(() => assertRejects(() => ctx.sendActivity([rsaKey, ...keys], recipient, compatibleCreate(owner)), TypeError, message));
563
- assertEquals(bodies.length, 0, name);
564
- }
565
- });
566
- test("compatible and ap: IDs of the same DID can be mixed", async () => {
567
- const owner = await didKey();
568
- const activities = [
569
- compatibleCreate(owner, void 0, { id: parseIri(`ap://${owner.did}/activities/${crypto.randomUUID()}`) }),
570
- compatibleCreate(owner, void 0, { actor: parseIri(`ap+ef61://${owner.did}/actor`) }),
571
- compatibleCreate(owner, void 0, { id: compatibleId(owner.did, "/activities/1", "https://other.example") })
572
- ];
573
- for (const activity of activities) {
574
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
575
- const { bodies } = await capture(async () => ctx.sendActivity([
576
- rsaKey,
577
- sender(await didKey()),
578
- sender(owner)
579
- ], recipient, activity));
580
- assertEquals(bodies.length, 1, activity.id?.href);
581
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
582
- }
583
- });
584
- test("a pre-signed compatible-ID activity is not re-signed", async () => {
585
- const owner = await didKey();
586
- const activity = await signObject(compatibleCreate(owner, await signedChild(await didKey())), owner.privateKey, owner.keyId, {
587
- ...options,
588
- created
589
- });
590
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
591
- const { bodies } = await capture(async () => ctx.sendActivity([
592
- rsaKey,
593
- sender(await didKey()),
594
- sender(await didKey())
595
- ], recipient, activity));
596
- assertEquals(bodies.length, 1);
597
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
598
- await assertCompoundVerifies(bodies[0]);
599
- });
600
- test("forced fanout selects the DID-matching key for a compatible-ID activity", async () => {
601
- const owner = await didKey();
602
- const { queue, queued } = createQueue();
603
- const federation = createTestFederation(queue);
604
- const ctx = federation.createContext(new URL("https://example.com/"));
605
- const { bodies } = await capture(async () => {
606
- await ctx.sendActivity([
607
- rsaKey,
608
- sender(await didKey()),
609
- sender(owner)
610
- ], recipient, compatibleCreate(owner, await signedChild(await didKey())), { fanout: "force" });
611
- assertEquals(queued.length, 1);
612
- for (const message of queued) await federation.processQueuedTask(void 0, message);
613
- });
614
- assertEquals(bodies.length, 1);
615
- assertEquals(proofOf(bodies[0]).verificationMethod, owner.keyId.href);
616
- await assertCompoundVerifies(bodies[0]);
617
- });
618
- test("a Fedify inbox accepts an activity Fedify produced for a compatible-ID actor", async () => {
619
- const owner = await didKey();
620
- const child = await signedChild(await didKey());
621
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
622
- const { requests } = await capture(async () => ctx.sendActivity([sender(await didKey()), sender(owner)], recipient, compatibleCreate(owner, child)));
623
- assertEquals(requests.length, 1);
624
- let received = 0;
625
- const receiving = createFederation({
626
- kv: new MemoryKvStore(),
627
- contextLoaderFactory: () => mockDocumentLoader,
628
- documentLoaderFactory: () => mockDocumentLoader
629
- });
630
- receiving.setActorDispatcher("/users/{identifier}", () => null);
631
- receiving.setInboxListeners("/users/{identifier}/inbox", "/inbox").on(Create, () => {
632
- received++;
633
- });
634
- const body = await requests[0].text();
635
- const deliver = (json) => receiving.fetch(new Request(requests[0].url, {
636
- method: "POST",
637
- headers: requests[0].headers,
638
- body: json
639
- }), { contextData: void 0 });
640
- assertEquals([(await deliver(body)).status, received], [202, 1]);
641
- const forged = JSON.parse(body);
642
- forged.actor = compatibleId((await didKey()).did, "/actor").href;
643
- assertEquals([(await deliver(JSON.stringify(forged))).status, received], [401, 1]);
644
- });
645
- async function captureLogs(run) {
646
- const records = [];
647
- await reset();
648
- try {
649
- await configure({
650
- sinks: { buffer: (record) => records.push(record) },
651
- filters: {},
652
- loggers: [{
653
- category: ["logtape", "meta"],
654
- sinks: []
655
- }, {
656
- category: [],
657
- sinks: ["buffer"],
658
- lowestLevel: "warning"
659
- }]
660
- });
661
- await run();
662
- } finally {
663
- await reset();
664
- }
665
- return records.filter((record) => record.category[0] === "fedify");
666
- }
667
- test("sendActivity warns for compatible IDs off the actor's first gateway", async () => {
668
- const owner = await didKey();
669
- const ownerId = parseIri(`ap://${owner.did}/users/alice`);
670
- const federation = createTestFederation();
671
- let actorCalls = 0;
672
- federation.setActorDispatcher("/users/{identifier}", (_ctx, identifier) => {
673
- actorCalls++;
674
- return identifier === "alice" ? new Person({
675
- id: ownerId,
676
- gateways: [new URL("https://primary.example"), new URL("https://secondary.example")]
677
- }) : null;
678
- });
679
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
680
- const child = await signObject(new Note({
681
- id: compatibleId(owner.did, "/notes/1", "https://secondary.example"),
682
- attribution: ownerId,
683
- content: "Hello"
684
- }), owner.privateKey, owner.keyId, {
685
- ...options,
686
- context: childContext,
687
- created
688
- });
689
- const activity = new Create({
690
- id: compatibleId(owner.did, "/activities/1", "https://secondary.example"),
691
- actor: ownerId,
692
- object: child
693
- });
694
- const records = await captureLogs(async () => {
695
- const { bodies } = await capture(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, activity));
696
- assertEquals(bodies.length, 1);
697
- assertEquals(bodies[0].id, activity.id?.href);
698
- });
699
- assertEquals(records.filter((r) => r.properties.kind === "activity").length, 1);
700
- assertEquals(records.filter((r) => r.properties.kind === "object").length, 1);
701
- assertEquals(actorCalls, 1);
702
- });
703
- test("sendActivity skips first-gateway and portable IDs", async () => {
704
- const owner = await didKey();
705
- const ownerId = parseIri(`ap://${owner.did}/users/alice`);
706
- const federation = createTestFederation();
707
- federation.setActorDispatcher("/users/{identifier}", (_ctx, identifier) => identifier === "alice" ? new Person({
708
- id: ownerId,
709
- gateways: [new URL("https://primary.example")]
710
- }) : null);
711
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
712
- for (const id of [compatibleId(owner.did, "/activities/first", "https://primary.example"), parseIri(`ap://${owner.did}/activities/portable`)]) assertEquals((await captureLogs(() => capture(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, new Create({
713
- id,
714
- actor: ownerId
715
- }))))).filter((r) => r.properties.kind != null), []);
716
- const plain = federation.createContext(new URL("https://example.com/"));
717
- assertEquals((await captureLogs(() => capture(() => plain.sendActivity([rsaKey, sender(owner)], recipient, new Create({
718
- id: compatibleId(owner.did, "/activities/unknown-gateway", "https://secondary.example"),
719
- actor: ownerId
720
- }))))).filter((r) => r.properties.kind != null), []);
721
- });
722
- test("fanout warns once before enqueueing a compatible activity", async () => {
723
- const owner = await didKey();
724
- const ownerId = parseIri(`ap://${owner.did}/users/alice`);
725
- const { queue, queued } = createQueue();
726
- const federation = createTestFederation(queue);
727
- federation.setActorDispatcher("/users/{identifier}", () => new Person({
728
- id: ownerId,
729
- gateways: [new URL("https://primary.example")]
730
- }));
731
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
732
- assertEquals((await captureLogs(() => capture(async () => {
733
- await ctx.sendActivity([rsaKey, sender(owner)], recipient, new Create({
734
- id: compatibleId(owner.did, "/activities/fanout", "https://secondary.example"),
735
- actor: ownerId
736
- }), { fanout: "force" });
737
- assertEquals(queued.length, 1);
738
- for (const message of queued) await federation.processQueuedTask(void 0, message);
739
- }))).filter((r) => r.properties.kind === "activity").length, 1);
740
- });
741
- test("an embedded actor supplies gateways to a plain send context", async () => {
742
- const owner = await didKey();
743
- const ownerId = parseIri(`ap://${owner.did}/users/alice`);
744
- const federation = new FederationImpl({
745
- kv: new MemoryKvStore(),
746
- contextLoaderFactory: () => mockDocumentLoader,
747
- documentLoaderFactory: () => mockDocumentLoader,
748
- activityTransformers: []
749
- });
750
- federation.allowPrivateAddress = true;
751
- const ctx = federation.createContext(new URL("https://example.com/"));
752
- const activity = await signObject(new Create({
753
- id: compatibleId(owner.did, "/activities/embedded-actor", "https://secondary.example"),
754
- actor: new Person({
755
- id: ownerId,
756
- gateways: [new URL("https://primary.example")]
757
- })
758
- }), owner.privateKey, owner.keyId, {
759
- ...options,
760
- created
761
- });
762
- assertEquals(getEmbeddedFirstGateway(await activity.toJsonLd({
763
- format: "compact",
764
- contextLoader: mockDocumentLoader
765
- }), ownerId, owner.did)?.origin, "https://primary.example");
766
- assertEquals((await captureLogs(() => capture(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, activity)))).filter((r) => r.properties.kind === "activity").length, 1);
767
- });
768
- test("sendActivity checks a locally owned embedded object independently", async () => {
769
- const alice = await didKey();
770
- const bob = await didKey();
771
- const aliceId = parseIri(`ap://${alice.did}/users/alice`);
772
- const bobId = parseIri(`ap://${bob.did}/users/bob`);
773
- const federation = createTestFederation();
774
- federation.setActorDispatcher("/users/{identifier}", (_ctx, identifier) => identifier === "alice" ? new Person({
775
- id: aliceId,
776
- gateways: [new URL("https://primary.example")]
777
- }) : identifier === "bob" ? new Person({
778
- id: bobId,
779
- gateways: [new URL("https://bob.example")]
780
- }) : null);
781
- const child = await signObject(new Note({
782
- id: compatibleId(bob.did, "/notes/1", "https://secondary.example"),
783
- attribution: bobId,
784
- content: "Bob's note"
785
- }), bob.privateKey, bob.keyId, {
786
- ...options,
787
- context: childContext,
788
- created
789
- });
790
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
791
- assertEquals((await captureLogs(() => capture(() => ctx.sendActivity([rsaKey, sender(alice)], recipient, new Announce({
792
- id: parseIri(`ap://${alice.did}/activities/announce`),
793
- actor: aliceId,
794
- object: child
795
- }))))).filter((r) => r.properties.kind === "object").map((r) => r.properties.id), [child.id?.href]);
796
- });
797
- test("sendActivity in an actor dispatcher does not re-enter it", async () => {
798
- const owner = await didKey();
799
- const ownerId = parseIri(`ap://${owner.did}/users/alice`);
800
- const federation = createTestFederation();
801
- let calls = 0;
802
- federation.setActorDispatcher("/users/{identifier}", async (ctx) => {
803
- calls++;
804
- await ctx.sendActivity([rsaKey, sender(owner)], recipient, new Create({
805
- id: compatibleId(owner.did, "/activities/from-dispatcher", "https://secondary.example"),
806
- actor: ownerId
807
- }));
808
- return new Person({
809
- id: ownerId,
810
- gateways: [new URL("https://primary.example")]
811
- });
812
- });
813
- await capture(async () => {
814
- assertEquals((await federation.fetch(new Request("https://example.com/users/alice", { headers: { Accept: "application/activity+json" } }), { contextData: void 0 })).status, 200);
815
- });
816
- assertEquals(calls, 1);
817
- });
818
- test("sendActivity still delivers when the diagnostic actor lookup fails", async () => {
819
- const owner = await didKey();
820
- const ownerId = parseIri(`ap://${owner.did}/users/alice`);
821
- const federation = createTestFederation();
822
- federation.setActorDispatcher("/users/{identifier}", () => {
823
- throw new Error("Actor storage unavailable");
824
- });
825
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
826
- const id = compatibleId(owner.did, "/activities/lookup-fails", "https://secondary.example");
827
- assertEquals((await captureLogs(async () => {
828
- const { bodies } = await capture(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, new Create({
829
- id,
830
- actor: ownerId
831
- })));
832
- assertEquals(bodies.length, 1);
833
- assertEquals(bodies[0].id, id.href);
834
- })).filter((r) => r.properties.kind != null), []);
835
- });
836
- test("warning checks later local actors when the first is missing", async () => {
837
- const owner = await didKey();
838
- const missing = parseIri(`ap://${owner.did}/users/missing`);
839
- const alice = parseIri(`ap://${owner.did}/users/alice`);
840
- const federation = createTestFederation();
841
- federation.setActorDispatcher("/users/{identifier}", (_ctx, identifier) => identifier === "alice" ? new Person({
842
- id: alice,
843
- gateways: [new URL("https://primary.example")]
844
- }) : null);
845
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
846
- assertEquals((await captureLogs(() => warnCompatibleIdsInJson({
847
- id: compatibleId(owner.did, "/activities/multi", "https://secondary.example").href,
848
- type: "Create",
849
- actor: [missing.href, alice.href]
850
- }, ctx))).filter((r) => r.properties.kind === "activity").length, 1);
851
- });
852
- test("warning ignores an embedded gateway key", async () => {
853
- const owner = await didKey();
854
- const actorId = parseIri(`ap://${owner.did}/users/alice`);
855
- const records = await captureLogs(() => warnCompatibleIdsInJson({
856
- id: compatibleId(owner.did, "/activities/1", "https://secondary.example").href,
857
- type: "Create",
858
- actor: {
859
- id: actorId.href,
860
- type: "Person",
861
- gateways: ["https://primary.example"],
862
- publicKey: [{
863
- id: compatibleId(owner.did, "/users/alice/keys/1", "https://secondary.example").href,
864
- type: ["CryptographicKey"]
865
- }, {
866
- id: compatibleId(owner.did, "/users/alice/keys/2", "https://secondary.example").href,
867
- type: "sec:Key"
868
- }]
869
- }
870
- }));
871
- assertEquals(records.filter((r) => r.properties.kind === "activity").length, 1);
872
- assertEquals(records.filter((r) => r.properties.kind === "object"), []);
873
- });
874
- test("warning resolves a signed child's local ownership alias", async () => {
875
- const alice = await didKey();
876
- const bob = await didKey();
877
- const aliceId = parseIri(`ap://${alice.did}/users/alice`);
878
- const bobId = parseIri(`ap://${bob.did}/users/bob`);
879
- const federation = createTestFederation();
880
- federation.setActorDispatcher("/users/{identifier}", (_ctx, identifier) => identifier === "bob" ? new Person({
881
- id: bobId,
882
- gateways: [new URL("https://primary.example")]
883
- }) : null);
884
- const ctx = federation.createContext(new Request("https://example.com/"), void 0);
885
- assertEquals((await captureLogs(() => warnCompatibleIdsInJson({
886
- id: parseIri(`ap://${alice.did}/activities/announce`).href,
887
- type: "Announce",
888
- actor: aliceId.href,
889
- object: {
890
- "@context": ["https://www.w3.org/ns/activitystreams", {
891
- by: {
892
- "@id": "as:attributedTo",
893
- "@type": "@id"
894
- },
895
- identifier: "@id"
896
- }],
897
- identifier: compatibleId(bob.did, "/notes/1", "https://secondary.example").href,
898
- type: "Note",
899
- by: bobId.href
900
- }
901
- }, ctx))).filter((r) => r.properties.kind === "object").length, 1);
902
- });
903
- test("warning reads an inline alias of the serialized root ID", async () => {
904
- const id = compatibleId((await didKey()).did, "/notes/1", "https://secondary.example");
905
- assertEquals(getCompactRootId({
906
- "@context": ["https://www.w3.org/ns/activitystreams", { identifier: "@id" }],
907
- identifier: id.href,
908
- type: "Note"
909
- })?.href, id.href);
910
- });
911
- test("an activity on another gateway than its compatible-ID actor is warned about", async () => {
912
- const owner = await didKey();
913
- const warnings = (activity) => captureLogs(() => assertPortableActorActivity(activity)).then((records) => records.map((r) => r.properties.activityId));
914
- const other = compatibleId(owner.did, "/activities/1", "https://other.example");
915
- assertEquals(await warnings(compatibleCreate(owner, void 0, { id: other })), [other.href]);
916
- assertEquals(await warnings(compatibleCreate(owner)), []);
917
- assertEquals(await warnings(compatibleCreate(owner, void 0, { id: parseIri(`ap://${owner.did}/activities/1`) })), []);
918
- assertEquals(await warnings(compatibleCreate(owner, void 0, {
919
- id: other,
920
- actor: parseIri(`ap://${owner.did}/actor`)
921
- })), []);
922
- });
923
- test("an unsigned activity with a malformed compatible ID is rejected", async () => {
924
- const owner = await didKey();
925
- const ctx = createTestFederation().createContext(new URL("https://example.com/"));
926
- const { bodies } = await capture(() => assertRejects(() => ctx.sendActivity([rsaKey, sender(owner)], recipient, new Create({
927
- id: new URL(compatibleId(owner.did, "/activities/1").href + "?@gateway=https%3A%2F%2Fgw.example"),
928
- actor: new URL("https://example.com/users/alice")
929
- })), TypeError, "malformed FEP-ef61 portable ID"));
930
- assertEquals(bodies.length, 0);
931
- });
932
- //#endregion
933
- export {};