@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,2 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";
@@ -1,692 +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 { r as createRequestContext, t as createInboxContext } from "../context-LgGFFSz7.mjs";
6
- import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
7
- import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
8
- import "../std__assert-DvMDRPes.mjs";
9
- import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
10
- import { r as getVerifiedKeyOwnerEvidence } from "../key-owner-evidence-APB6NpSk.mjs";
11
- import { m as signJsonLd } from "../ld-BpkhkDGj.mjs";
12
- import { m as verifyRequestDetailed, p as verifyRequest, u as signRequest } from "../http-BXbQQZDM.mjs";
13
- import { a as rsaPrivateKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
14
- import { n as getAuthenticatedDocumentLoader } from "../docloader-BY-SEID0.mjs";
15
- import { f as handleInbox, n as FederationImpl, o as createFederation } from "../middleware-DcXzz-YK.mjs";
16
- import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-BVenIFg1.mjs";
17
- import { t as ActivityListenerSet } from "../activity-listener-CELFAodc.mjs";
18
- import { t as KvKeyCache } from "../keycache-N2opu4-3.mjs";
19
- import { Create, CryptographicKey, Person } from "@fedify/vocab";
20
- import { FetchError, encodeMultibase, exportDidKey, parseIri } from "@fedify/vocab-runtime";
21
- import { mockDocumentLoader, test } from "@fedify/fixture";
22
- import serialize from "json-canon";
23
- //#region src/federation/portable-gateway-keys.test.ts
24
- const did = await exportDidKey(ed25519PublicKey.publicKey);
25
- const didKeyId = new URL(`${did}#${did.slice(8)}`);
26
- const actorId = parseIri(`ap+ef61://${did}/actors/alice`);
27
- const gateway = "https://example.com";
28
- const otherGateway = "https://other.example";
29
- const compatibleActorId = (origin) => `${origin}/.well-known/apgateway/${did}/actors/alice`;
30
- const gatewayKeyId = new URL(`${compatibleActorId(gateway)}#main-key`);
31
- const ed25519GatewayKeyPair = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
32
- const rsaGatewayKeyPair = {
33
- privateKey: rsaPrivateKey2,
34
- publicKey: rsaPublicKey2.publicKey
35
- };
36
- const portableContext = [
37
- "https://www.w3.org/ns/activitystreams",
38
- "https://w3id.org/security/data-integrity/v1",
39
- "https://w3id.org/fep/ef61"
40
- ];
41
- const recipient = {
42
- id: new URL("https://example.com/users/bob"),
43
- inboxId: new URL("https://example.com/inbox")
44
- };
45
- async function sign(document) {
46
- const proofConfig = {
47
- "@context": document["@context"],
48
- type: "DataIntegrityProof",
49
- cryptosuite: "eddsa-jcs-2022",
50
- verificationMethod: didKeyId.href,
51
- proofPurpose: "assertionMethod",
52
- created: "2023-02-24T23:36:38Z"
53
- };
54
- const encoder = new TextEncoder();
55
- const digest = /* @__PURE__ */ new Uint8Array(64);
56
- digest.set(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(serialize(proofConfig)))), 0);
57
- digest.set(new Uint8Array(await crypto.subtle.digest("SHA-256", encoder.encode(serialize(document)))), 32);
58
- const signature = await crypto.subtle.sign("Ed25519", ed25519PrivateKey, digest);
59
- return {
60
- ...document,
61
- proof: {
62
- ...proofConfig,
63
- proofValue: new TextDecoder().decode(encodeMultibase("base58btc", new Uint8Array(signature)))
64
- }
65
- };
66
- }
67
- function createTestFederation(mapper) {
68
- const federation = new FederationImpl({
69
- kv: new MemoryKvStore(),
70
- manuallyStartQueue: true,
71
- contextLoaderFactory: () => mockDocumentLoader,
72
- documentLoaderFactory: () => mockDocumentLoader,
73
- authenticatedDocumentLoaderFactory: (identity, options) => getAuthenticatedDocumentLoader(identity, {
74
- ...options,
75
- allowPrivateAddress: true
76
- })
77
- });
78
- federation.allowPrivateAddress = true;
79
- const setters = federation.setActorDispatcher("/users/{identifier}", () => null).setKeyPairsDispatcher(() => [rsaGatewayKeyPair, ed25519GatewayKeyPair]);
80
- if (mapper != null) setters.mapPortableActorId((_ctx, id) => mapper(id));
81
- return federation;
82
- }
83
- function portableCreate(id = "1") {
84
- return new Create({
85
- id: parseIri(`ap+ef61://${did}/activities/${id}`),
86
- actor: actorId,
87
- object: new URL("https://example.com/notes/1")
88
- });
89
- }
90
- async function signedPortableCreate(id = "1") {
91
- const json = await portableCreate(id).toJsonLd({
92
- format: "compact",
93
- context: portableContext,
94
- contextLoader: mockDocumentLoader
95
- });
96
- return await Create.fromJsonLd(await sign(json), {
97
- contextLoader: mockDocumentLoader,
98
- documentLoader: mockDocumentLoader
99
- });
100
- }
101
- async function capture(run) {
102
- const bodies = [];
103
- const requests = [];
104
- esm_default.spyGlobal();
105
- try {
106
- esm_default.post(recipient.inboxId.href, async (cl) => {
107
- const body = await cl.request.text();
108
- requests.push(new Request(cl.request.url, {
109
- method: cl.request.method,
110
- headers: cl.request.headers,
111
- body
112
- }));
113
- bodies.push(JSON.parse(body));
114
- return new Response(null, { status: 202 });
115
- });
116
- await run();
117
- } finally {
118
- esm_default.hardReset();
119
- }
120
- return {
121
- bodies,
122
- requests
123
- };
124
- }
125
- function signatureKeyId(request) {
126
- return request.headers.get("Signature-Input")?.match(/keyid="([^"]+)"/)?.[1] ?? request.headers.get("Signature")?.match(/keyId="([^"]+)"/)?.[1];
127
- }
128
- test("Context.getActorKeyPairs() derives gateway keys for portable actors", async () => {
129
- const ctx = createTestFederation((id) => id === "alice" ? actorId : null).createContext(new URL(gateway));
130
- const keys = await ctx.getActorKeyPairs("alice");
131
- assertEquals(keys.map((k) => k.keyId.href), [gatewayKeyId.href, `${compatibleActorId(gateway)}#key-2`]);
132
- for (const key of keys) {
133
- assertEquals(key.cryptographicKey.id?.href, key.keyId.href);
134
- assertEquals(key.cryptographicKey.ownerId?.href, actorId.href);
135
- assertEquals(key.multikey.id?.href, key.keyId.href);
136
- assertEquals(key.multikey.controllerId?.href, actorId.href);
137
- }
138
- assertEquals((await ctx.getActorKeyPairs("bob")).map((k) => [k.keyId.href, k.multikey.id?.href]), [["https://example.com/users/bob#main-key", "https://example.com/users/bob#multikey-1"], ["https://example.com/users/bob#key-2", "https://example.com/users/bob#multikey-2"]]);
139
- const json = await new Person({
140
- id: actorId,
141
- gateways: [new URL(gateway)],
142
- publicKey: keys[0].cryptographicKey,
143
- assertionMethods: keys.map((k) => k.multikey)
144
- }).toJsonLd({
145
- format: "compact",
146
- contextLoader: mockDocumentLoader
147
- });
148
- const assertionMethod = json.assertionMethod;
149
- assertEquals(assertionMethod.map((k) => [k.id, k.controller]), [[gatewayKeyId.href, `ap+ef61://${did}/actors/alice`], [`${compatibleActorId(gateway)}#key-2`, `ap+ef61://${did}/actors/alice`]]);
150
- assertEquals(json.publicKey.id, gatewayKeyId.href);
151
- });
152
- test("Context.getActorKeyPairs() accepts compatible IDs as portable actor IDs", async () => {
153
- const published = new URL(compatibleActorId(otherGateway));
154
- const [key] = await createTestFederation(() => published).createContext(new URL(gateway)).getActorKeyPairs("alice");
155
- assertEquals(key.keyId.href, gatewayKeyId.href);
156
- assertEquals(key.cryptographicKey.ownerId?.href, published.href);
157
- });
158
- test("Context.getActorKeyPairs() propagates portable actor ID mapper errors", async () => {
159
- for (const id of [new URL(`${actorId.href}#me`), new URL("https://example.com/users/alice")]) {
160
- const ctx = createTestFederation(() => id).createContext(new URL(gateway));
161
- await assertRejects(() => ctx.getActorKeyPairs("alice"), TypeError);
162
- }
163
- const ctx = createTestFederation(() => {
164
- throw new RangeError("mapper failed");
165
- }).createContext(new URL(gateway));
166
- await assertRejects(() => ctx.getActorKeyPairs("alice"), RangeError);
167
- const federation = new FederationImpl({ kv: new MemoryKvStore() });
168
- federation.setActorDispatcher("/users/{identifier}", () => null).setKeyPairsDispatcher(() => {
169
- throw new Error("dispatcher failed");
170
- }).mapPortableActorId(() => actorId);
171
- assertEquals(await federation.createContext(new URL(gateway)).getActorKeyPairs("alice"), []);
172
- });
173
- test("Context.sendActivity() signs requests with gateway keys for portable actors", async () => {
174
- const ctx = createTestFederation(() => actorId).createContext(new URL(gateway));
175
- const activity = await signedPortableCreate();
176
- const { bodies, requests } = await capture(() => ctx.sendActivity({ identifier: "alice" }, recipient, activity));
177
- assertEquals(bodies.length, 1);
178
- assertEquals(signatureKeyId(requests[0]), gatewayKeyId.href);
179
- const proof = bodies[0].proof;
180
- assertEquals(Array.isArray(proof), false);
181
- assertEquals(proof.verificationMethod, didKeyId.href);
182
- assertEquals(bodies[0].signature, void 0);
183
- });
184
- test("Context.sendActivity() refuses portable activities gateway keys would sign", async () => {
185
- const ctx = createTestFederation(() => actorId).createContext(new URL(gateway));
186
- await assertRejects(() => ctx.sendActivity({ identifier: "alice" }, recipient, portableCreate()), TypeError);
187
- const httpActivity = new Create({
188
- id: new URL("https://example.com/activities/1"),
189
- actor: actorId,
190
- object: new URL("https://example.com/notes/1")
191
- });
192
- await assertRejects(() => ctx.sendActivity({ identifier: "alice" }, recipient, httpActivity), TypeError);
193
- await assertRejects(() => ctx.sendActivity({
194
- keyId: new URL("https://example.com/key"),
195
- privateKey: ed25519PrivateKey
196
- }, recipient, portableCreate()), TypeError);
197
- const { bodies } = await capture(() => ctx.sendActivity([{
198
- keyId: gatewayKeyId,
199
- privateKey: rsaPrivateKey2
200
- }, {
201
- keyId: didKeyId,
202
- privateKey: ed25519PrivateKey
203
- }], recipient, portableCreate()));
204
- assertEquals(bodies[0].proof.verificationMethod, didKeyId.href);
205
- });
206
- test("Context.sendActivity() never signs documents with gateway keys", async () => {
207
- const ctx = createTestFederation().createContext(new URL(gateway));
208
- const keys = [{
209
- keyId: gatewayKeyId,
210
- privateKey: rsaPrivateKey2
211
- }, {
212
- keyId: new URL(`${compatibleActorId(gateway)}#key-2`),
213
- privateKey: ed25519GatewayKeyPair.privateKey
214
- }];
215
- const activity = new Create({
216
- id: new URL("https://example.com/activities/1"),
217
- actor: new URL("https://example.com/users/bob"),
218
- object: new URL("https://example.com/notes/1")
219
- });
220
- const { bodies, requests } = await capture(() => ctx.sendActivity(keys, recipient, activity));
221
- assertEquals(signatureKeyId(requests[0]), gatewayKeyId.href);
222
- assertEquals(bodies[0].proof, void 0);
223
- assertEquals(bodies[0].signature, void 0);
224
- });
225
- test("Context.sendActivity() never signs documents with keys at ap: URIs", async () => {
226
- const ctx = createTestFederation().createContext(new URL(gateway));
227
- const keys = [{
228
- keyId: parseIri(`${actorId.href}#main-key`),
229
- privateKey: rsaPrivateKey2
230
- }, {
231
- keyId: parseIri(`${actorId.href}#key-2`),
232
- privateKey: ed25519GatewayKeyPair.privateKey
233
- }];
234
- const activity = new Create({
235
- id: new URL("https://example.com/activities/1"),
236
- actor: new URL("https://example.com/users/bob"),
237
- object: new URL("https://example.com/notes/1")
238
- });
239
- const { bodies } = await capture(() => ctx.sendActivity(keys, recipient, activity));
240
- assertEquals(bodies[0].proof, void 0);
241
- assertEquals(bodies[0].signature, void 0);
242
- });
243
- test("Context.getDocumentLoader() signs requests with gateway keys for portable actors", async () => {
244
- const documentLoader = await createTestFederation(() => actorId).createContext(new URL(gateway)).getDocumentLoader({ identifier: "alice" });
245
- let keyId;
246
- esm_default.spyGlobal();
247
- try {
248
- esm_default.get("https://example.com/notes/1", (cl) => {
249
- keyId = signatureKeyId(cl.request);
250
- return new Response(JSON.stringify({ id: cl.request.url }), { headers: { "Content-Type": "application/activity+json" } });
251
- });
252
- await documentLoader("https://example.com/notes/1");
253
- } finally {
254
- esm_default.hardReset();
255
- }
256
- assertEquals(keyId, gatewayKeyId.href);
257
- });
258
- async function actorDocument(gateways, id = actorId, signed = true) {
259
- const keys = await createTestFederation(() => id).createContext(new URL(gateway)).getActorKeyPairs("alice");
260
- const json = await new Person({
261
- id,
262
- inbox: parseIri(`${id.href}/inbox`),
263
- gateways: gateways.map((g) => new URL(g)),
264
- publicKey: keys[0].cryptographicKey,
265
- assertionMethods: keys.map((k) => k.multikey)
266
- }).toJsonLd({
267
- format: "compact",
268
- contextLoader: mockDocumentLoader
269
- });
270
- json["@context"] = [...json["@context"], "https://w3id.org/security/data-integrity/v1"];
271
- return signed ? await sign(json) : json;
272
- }
273
- function createLoader(responses) {
274
- return (url) => {
275
- const document = responses[url.replace(/#.*$/, "")];
276
- if (document == null) return mockDocumentLoader(url);
277
- return Promise.resolve({
278
- contextUrl: null,
279
- documentUrl: url,
280
- document: structuredClone(document)
281
- });
282
- };
283
- }
284
- async function deliver(body, gateways, { kv = new MemoryKvStore(), httpSignature = true, actor, documentLoader, keyId = gatewayKeyId } = {}) {
285
- documentLoader ??= createLoader({ [compatibleActorId(gateway)]: actor ?? await actorDocument(gateways) });
286
- const unsigned = new Request("https://local.example/inbox", {
287
- method: "POST",
288
- body: JSON.stringify(body),
289
- headers: { "Content-Type": "application/activity+json" }
290
- });
291
- const request = httpSignature ? await signRequest(unsigned, rsaPrivateKey2, keyId) : unsigned;
292
- const context = createRequestContext({
293
- federation: createFederation({ kv: new MemoryKvStore() }),
294
- request,
295
- url: new URL(request.url),
296
- data: void 0,
297
- documentLoader,
298
- contextLoader: mockDocumentLoader
299
- });
300
- let dispatched = 0;
301
- const inboxListeners = new ActivityListenerSet();
302
- inboxListeners.add(Create, () => {
303
- dispatched++;
304
- });
305
- const response = await handleInbox(request, {
306
- recipient: null,
307
- context,
308
- inboxContextFactory() {
309
- return createInboxContext({
310
- ...context,
311
- clone: void 0
312
- });
313
- },
314
- kv,
315
- kvPrefixes: {
316
- activityIdempotence: ["_fedify", "activityIdempotence"],
317
- publicKey: ["_fedify", "publicKey"],
318
- acceptSignatureNonce: ["_fedify", "acceptSignatureNonce"]
319
- },
320
- actorDispatcher() {
321
- return null;
322
- },
323
- inboxListeners,
324
- onNotFound() {
325
- return new Response("Not found", { status: 404 });
326
- },
327
- signatureTimeWindow: { minutes: 5 },
328
- skipSignatureVerification: false
329
- });
330
- lastResponseText = await response.text();
331
- return {
332
- status: response.status,
333
- dispatched
334
- };
335
- }
336
- let lastResponseText = "";
337
- async function createJson(id) {
338
- return await portableCreate(id).toJsonLd({
339
- format: "compact",
340
- context: portableContext,
341
- contextLoader: mockDocumentLoader
342
- });
343
- }
344
- test("handleInbox() requires proofs of portable actors despite gateway signatures", async () => {
345
- assertEquals(await deliver(await createJson("unsigned"), [gateway]), {
346
- status: 401,
347
- dispatched: 0
348
- });
349
- assertEquals(await deliver({
350
- ...await sign(await createJson("tampered")),
351
- object: "https://remote.example/notes/2"
352
- }, [gateway]), {
353
- status: 401,
354
- dispatched: 0
355
- });
356
- assertEquals(await deliver(await sign(await createJson("signed")), [gateway]), {
357
- status: 202,
358
- dispatched: 1
359
- });
360
- });
361
- const apKeyId = parseIri(`${actorId.href}?@gateway=${encodeURIComponent(gateway)}#main-key`);
362
- async function apActorDocument() {
363
- const json = await new Person({
364
- id: actorId,
365
- inbox: parseIri(`${actorId.href}/inbox`),
366
- gateways: [new URL(gateway)],
367
- publicKey: new CryptographicKey({
368
- id: parseIri(`${actorId.href}#main-key`),
369
- owner: actorId,
370
- publicKey: rsaPublicKey2.publicKey
371
- })
372
- }).toJsonLd({
373
- format: "compact",
374
- contextLoader: mockDocumentLoader
375
- });
376
- json["@context"] = [...json["@context"], "https://w3id.org/security/data-integrity/v1"];
377
- return await sign(json);
378
- }
379
- test("handleInbox() requires proofs of portable actors despite signatures with keys at ap: key IDs", async () => {
380
- const fetched = [];
381
- const inner = createLoader({ [compatibleActorId(gateway)]: await apActorDocument() });
382
- const documentLoader = (url, options) => {
383
- fetched.push(url);
384
- return inner(url, options);
385
- };
386
- assertEquals(await deliver(await createJson("unsigned"), [gateway], {
387
- documentLoader,
388
- keyId: apKeyId
389
- }), {
390
- status: 401,
391
- dispatched: 0
392
- });
393
- assertEquals(fetched.some((url) => url.startsWith(compatibleActorId(gateway))), true);
394
- assertEquals(await deliver(await sign(await createJson("signed")), [gateway], {
395
- documentLoader,
396
- keyId: apKeyId
397
- }), {
398
- status: 202,
399
- dispatched: 1
400
- });
401
- });
402
- test("RequestContext.getSignedKeyOwner() resolves keys at ap: key IDs", async () => {
403
- const documentLoader = createLoader({ [compatibleActorId(gateway)]: await apActorDocument() });
404
- const federation = new FederationImpl({
405
- kv: new MemoryKvStore(),
406
- contextLoaderFactory: () => mockDocumentLoader,
407
- documentLoaderFactory: () => documentLoader
408
- });
409
- const request = await signRequest(new Request("https://local.example/notes/1", { headers: { Accept: "application/activity+json" } }), rsaPrivateKey2, apKeyId);
410
- const ctx = federation.createContext(request, void 0);
411
- assertEquals((await ctx.getSignedKey())?.id?.href, apKeyId.href);
412
- assertEquals((await ctx.getSignedKeyOwner())?.id?.href, actorId.href);
413
- });
414
- test("handleInbox() fetches an unreachable gateway key once", async () => {
415
- const fetched = [];
416
- const documentLoader = (url) => {
417
- if (url.replace(/#.*$/, "") !== compatibleActorId(gateway)) return mockDocumentLoader(url);
418
- fetched.push(url);
419
- return Promise.reject(new FetchError(url, "HTTP 503", new Response(null, { status: 503 })));
420
- };
421
- const kv = new MemoryKvStore();
422
- for (let i = 0; i < 3; i++) {
423
- const { status } = await deliver(await createJson(`unreachable-${i}`), [gateway], {
424
- kv,
425
- documentLoader
426
- });
427
- assertEquals(status, 401);
428
- }
429
- assertEquals(fetched.length, 1);
430
- });
431
- test("handleInbox() does not need gateway signatures for portable actors", async () => {
432
- assertEquals(await deliver(await sign(await createJson("signed")), [otherGateway]), {
433
- status: 202,
434
- dispatched: 1
435
- });
436
- assertEquals(await deliver(await createJson("unsigned"), [otherGateway]), {
437
- status: 401,
438
- dispatched: 0
439
- });
440
- });
441
- test("handleInbox() does not take Linked Data Signatures for portable actors", async () => {
442
- const kv = new MemoryKvStore();
443
- await new KvKeyCache(kv, ["_fedify", "publicKey"]).set(rsaPublicKey2.id, new CryptographicKey({
444
- id: rsaPublicKey2.id,
445
- owner: actorId,
446
- publicKey: rsaPublicKey2.publicKey
447
- }));
448
- const ldSign = (document) => signJsonLd(document, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
449
- assertEquals(await deliver(await ldSign(await createJson("ld-only")), [gateway], {
450
- kv,
451
- httpSignature: false
452
- }), {
453
- status: 401,
454
- dispatched: 0
455
- });
456
- assertEquals(lastResponseText, "Failed to verify the request signature.");
457
- });
458
- const otherDid = await exportDidKey((await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"])).publicKey);
459
- function compatibleCreateJson(id, activityDid = did) {
460
- return {
461
- "@context": portableContext,
462
- id: `${gateway}/.well-known/apgateway/${activityDid}/activities/${id}`,
463
- type: "Create",
464
- actor: compatibleActorId(gateway),
465
- object: "https://example.com/notes/1"
466
- };
467
- }
468
- test("handleInbox() does not trust compatible-ID actors by web origin", async () => {
469
- const id = new URL(compatibleActorId(gateway));
470
- for (const signed of [true, false]) {
471
- const actor = await actorDocument([gateway], id, signed);
472
- assertEquals(await deliver(compatibleCreateJson(`unsigned-${signed}`), [gateway], { actor }), {
473
- status: 401,
474
- dispatched: 0
475
- }, `actor document signed: ${signed}`);
476
- }
477
- assertEquals(await deliver(await sign(compatibleCreateJson("signed")), [gateway], { actor: await actorDocument([gateway], id) }), {
478
- status: 202,
479
- dispatched: 1
480
- });
481
- });
482
- test("handleInbox() requires proofs of compatible-ID actors", async () => {
483
- assertEquals(await deliver(compatibleCreateJson("unsigned"), [gateway]), {
484
- status: 401,
485
- dispatched: 0
486
- });
487
- assertEquals(await deliver(await sign(compatibleCreateJson("signed")), [gateway]), {
488
- status: 202,
489
- dispatched: 1
490
- });
491
- assertEquals(await deliver(await sign(compatibleCreateJson("unsigned-request")), [gateway], { httpSignature: false }), {
492
- status: 202,
493
- dispatched: 1
494
- });
495
- });
496
- test("handleInbox() checks the DIDs of compatible activity IDs", async () => {
497
- for (const actor of [actorId.href, compatibleActorId(gateway)]) assertEquals(await deliver(await sign({
498
- ...compatibleCreateJson("forged", otherDid),
499
- actor
500
- }), [gateway]), {
501
- status: 401,
502
- dispatched: 0
503
- }, actor);
504
- assertEquals(await deliver(await sign({
505
- ...compatibleCreateJson("forged-ap"),
506
- id: `ap://${otherDid}/activities/forged-ap`
507
- }), [gateway]), {
508
- status: 401,
509
- dispatched: 0
510
- });
511
- assertEquals(await deliver(await sign({
512
- ...compatibleCreateJson("malformed"),
513
- id: `https://user@example.com/.well-known/apgateway/${did}/activities/2`
514
- }), [gateway]), {
515
- status: 401,
516
- dispatched: 0
517
- });
518
- });
519
- function countingLoader(responses) {
520
- const inner = createLoader(responses);
521
- let count = 0;
522
- return {
523
- documentLoader(url, options) {
524
- if (url.replace(/#.*$/, "") === compatibleActorId(gateway)) count++;
525
- return inner(url, options);
526
- },
527
- fetched: () => count
528
- };
529
- }
530
- async function signedRequest(keyId = gatewayKeyId, privateKey = rsaPrivateKey2, spec) {
531
- return await signRequest(new Request("https://local.example/notes/1", { headers: { Accept: "application/activity+json" } }), privateKey, keyId, spec == null ? {} : { spec });
532
- }
533
- test("handleInbox() fetches the actor of a gateway key once", async () => {
534
- for (const [keyId, actor] of [[gatewayKeyId, await actorDocument([gateway])], [apKeyId, await apActorDocument()]]) {
535
- const { documentLoader, fetched } = countingLoader({ [compatibleActorId(gateway)]: actor });
536
- const kv = new MemoryKvStore();
537
- for (let i = 0; i < 2; i++) {
538
- assertEquals(await deliver(await createJson(`once-${i}`), [gateway], {
539
- kv,
540
- documentLoader,
541
- keyId
542
- }), {
543
- status: 401,
544
- dispatched: 0
545
- });
546
- assertEquals(fetched(), 1);
547
- }
548
- }
549
- });
550
- test("RequestContext.getSignedKeyOwner() does not fetch the actor of a gateway key again", async () => {
551
- for (const [keyId, actor, gateways] of [[
552
- gatewayKeyId,
553
- await actorDocument([gateway, otherGateway]),
554
- [`${gateway}/`, `${otherGateway}/`]
555
- ], [
556
- apKeyId,
557
- await apActorDocument(),
558
- [`${gateway}/`]
559
- ]]) {
560
- const { documentLoader, fetched } = countingLoader({ [compatibleActorId(gateway)]: actor });
561
- const ctx = new FederationImpl({
562
- kv: new MemoryKvStore(),
563
- contextLoaderFactory: () => mockDocumentLoader,
564
- documentLoaderFactory: () => documentLoader
565
- }).createContext(await signedRequest(keyId), void 0);
566
- assertEquals((await ctx.getSignedKey())?.id?.href, keyId.href);
567
- assertEquals(fetched(), 1);
568
- const owner = await ctx.getSignedKeyOwner();
569
- assertEquals(owner?.id?.href, actorId.href);
570
- assertEquals(owner?.gateways.map((g) => g.href), [...gateways]);
571
- assertEquals(fetched(), 1);
572
- }
573
- });
574
- test("getKeyOwner() reuses the actor of a cached gateway key", async () => {
575
- for (const spec of [void 0, "rfc9421"]) {
576
- const { documentLoader, fetched } = countingLoader({ [compatibleActorId(gateway)]: await actorDocument([gateway]) });
577
- const options = {
578
- documentLoader,
579
- contextLoader: mockDocumentLoader,
580
- keyCache: new KvKeyCache(new MemoryKvStore(), ["pk"])
581
- };
582
- const fresh = await verifyRequest(await signedRequest(gatewayKeyId, rsaPrivateKey2, spec), options);
583
- const cached = await verifyRequest(await signedRequest(gatewayKeyId, rsaPrivateKey2, spec), options);
584
- assertEquals(fetched(), 1);
585
- for (const key of [fresh, cached]) assertEquals((await getKeyOwner(key, options))?.id?.href, actorId.href);
586
- assertEquals(fetched(), 1);
587
- }
588
- });
589
- test("doesActorOwnKey() checks the actor of a verified gateway key without fetching", async () => {
590
- const { documentLoader, fetched } = countingLoader({ [compatibleActorId(gateway)]: await actorDocument([gateway]) });
591
- const options = {
592
- documentLoader,
593
- contextLoader: mockDocumentLoader
594
- };
595
- const key = await verifyRequest(await signedRequest(), options);
596
- assertEquals(fetched(), 1);
597
- assertEquals(await doesActorOwnKey(portableCreate(), key, options), true);
598
- assertEquals(await doesActorOwnKey(new Create({
599
- id: parseIri(`ap+ef61://${otherDid}/activities/1`),
600
- actor: parseIri(`ap+ef61://${otherDid}/actors/alice`)
601
- }), key, options), false);
602
- assertEquals(fetched(), 1);
603
- });
604
- test("doesActorOwnKey() and getKeyOwner() fully check other gateway keys", async () => {
605
- const { documentLoader, fetched } = countingLoader({ [compatibleActorId(gateway)]: await actorDocument([gateway]) });
606
- const options = {
607
- documentLoader,
608
- contextLoader: mockDocumentLoader
609
- };
610
- const verified = await verifyRequest(await signedRequest(), options);
611
- assertEquals(fetched(), 1);
612
- const others = [new CryptographicKey({
613
- id: gatewayKeyId,
614
- owner: actorId,
615
- publicKey: rsaPublicKey2.publicKey
616
- }), verified.clone({})];
617
- let expected = 1;
618
- for (const key of others) {
619
- assertEquals(await doesActorOwnKey(portableCreate(), key, options), true);
620
- assertEquals(fetched(), ++expected);
621
- assertEquals((await getKeyOwner(key, options))?.id?.href, actorId.href);
622
- assertEquals(fetched(), ++expected);
623
- }
624
- const mutated = await verifyRequest(await signedRequest(), options);
625
- mutated.ownerId.href = parseIri(`ap+ef61://${otherDid}/actors/alice`).href;
626
- assertEquals(getVerifiedKeyOwnerEvidence(mutated), void 0);
627
- });
628
- test("verifyRequest() does not vouch for the owners of keys that fail to verify signatures", async () => {
629
- const documentLoader = createLoader({ [compatibleActorId(gateway)]: await actorDocument([gateway]) });
630
- const cachedKeys = [];
631
- const keyCache = new class extends KvKeyCache {
632
- compatibleKeyScope(scope) {
633
- const scoped = super.compatibleKeyScope(scope);
634
- return {
635
- ...scoped,
636
- set(keyId, key, options) {
637
- if (key instanceof CryptographicKey) cachedKeys.push(key);
638
- return scoped.set(keyId, key, options);
639
- }
640
- };
641
- }
642
- }(new MemoryKvStore(), ["pk"]);
643
- assertEquals((await verifyRequestDetailed(await signedRequest(gatewayKeyId, rsaPrivateKey3), {
644
- documentLoader,
645
- contextLoader: mockDocumentLoader,
646
- keyCache
647
- })).verified, false);
648
- assertEquals(cachedKeys.length, 1);
649
- assertEquals(getVerifiedKeyOwnerEvidence(cachedKeys[0]), void 0);
650
- });
651
- test("doesActorOwnKey() fully checks cached gateway keys cached without their actors", async () => {
652
- const { documentLoader, fetched } = countingLoader({ [compatibleActorId(gateway)]: await actorDocument([gateway]) });
653
- const kv = new MemoryKvStore();
654
- const options = {
655
- documentLoader,
656
- contextLoader: mockDocumentLoader,
657
- keyCache: new KvKeyCache(kv, ["pk"])
658
- };
659
- await verifyRequest(await signedRequest(), options);
660
- assertEquals(fetched(), 1);
661
- const entryKey = [
662
- "pk",
663
- "__compatible",
664
- "httpSignature",
665
- gatewayKeyId.href
666
- ];
667
- const { owner: _, ...entry } = await kv.get(entryKey) ?? {};
668
- await kv.set(entryKey, entry);
669
- const key = await verifyRequest(await signedRequest(), options);
670
- assertEquals(fetched(), 1);
671
- assertEquals(getVerifiedKeyOwnerEvidence(key), void 0);
672
- assertEquals(await doesActorOwnKey(portableCreate(), key, options), true);
673
- assertEquals(fetched(), 2);
674
- });
675
- test("Owners of verified gateway keys expire with their cache entries", async () => {
676
- const documentLoader = createLoader({ [compatibleActorId(gateway)]: await actorDocument([gateway]) });
677
- const now = Temporal.Now.instant();
678
- const keyCache = new KvKeyCache(new MemoryKvStore(), ["pk"], {
679
- keyTtl: Temporal.Duration.from({ minutes: 5 }),
680
- now: () => now
681
- });
682
- const key = await verifyRequest(await signedRequest(), {
683
- documentLoader,
684
- contextLoader: mockDocumentLoader,
685
- keyCache
686
- });
687
- const deadline = now.add({ minutes: 5 });
688
- assertEquals(getVerifiedKeyOwnerEvidence(key, deadline.subtract({ seconds: 1 }))?.expires, deadline);
689
- assertEquals(getVerifiedKeyOwnerEvidence(key, deadline), void 0);
690
- });
691
- //#endregion
692
- export {};
@@ -1,2 +0,0 @@
1
- import { Temporal } from "temporal-polyfill";
2
- import { URLPattern } from "urlpattern-polyfill";