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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (244) hide show
  1. package/dist/federation/mod.cjs +1 -1
  2. package/dist/federation/mod.js +1 -1
  3. package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
  4. package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
  5. package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
  6. package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
  7. package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
  8. package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
  9. package/dist/mod.cjs +4 -4
  10. package/dist/mod.js +4 -4
  11. package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
  12. package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
  13. package/dist/sig/mod.cjs +2 -2
  14. package/dist/sig/mod.js +2 -2
  15. package/dist/utils/mod.cjs +1 -1
  16. package/dist/utils/mod.js +1 -1
  17. package/package.json +22 -9
  18. package/skills/fedify/SKILL.md +10 -0
  19. package/dist/accept-CPVqki78.mjs +0 -145
  20. package/dist/activity-listener-CELFAodc.mjs +0 -44
  21. package/dist/assert-D1Eafmd_.mjs +0 -23
  22. package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
  23. package/dist/assert_exists-cffSpJ7X.mjs +0 -28
  24. package/dist/assert_false-CPdRnc3E.mjs +0 -23
  25. package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
  26. package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
  27. package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
  28. package/dist/assert_rejects-CTptdYck.mjs +0 -39
  29. package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
  30. package/dist/assert_throws-BYITOvPO.mjs +0 -74
  31. package/dist/assertion_error-B-cx0fFA.mjs +0 -31
  32. package/dist/audience-CHQ-FlLD.mjs +0 -95
  33. package/dist/builder-D1FP_5nQ.mjs +0 -911
  34. package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
  35. package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
  36. package/dist/client-5SIFzW3q.mjs +0 -441
  37. package/dist/codec-C6rTrpIp.mjs +0 -147
  38. package/dist/collection-CnnP1UAv.mjs +0 -44
  39. package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
  40. package/dist/compat/outgoing-jsonld.test.mjs +0 -257
  41. package/dist/compat/public-audience.test.d.mts +0 -2
  42. package/dist/compat/public-audience.test.mjs +0 -187
  43. package/dist/compat/secured-document.test.d.mts +0 -2
  44. package/dist/compat/secured-document.test.mjs +0 -58
  45. package/dist/compat/transformers.test.d.mts +0 -2
  46. package/dist/compat/transformers.test.mjs +0 -62
  47. package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
  48. package/dist/context-LgGFFSz7.mjs +0 -146
  49. package/dist/deno-C50ikGBU.mjs +0 -8
  50. package/dist/dist-_geWsuaI.mjs +0 -189
  51. package/dist/docloader-BY-SEID0.mjs +0 -136
  52. package/dist/esm-BHXXx4Wx.mjs +0 -1233
  53. package/dist/exporter-DVG68ozH.mjs +0 -263
  54. package/dist/federation/audience.test.d.mts +0 -2
  55. package/dist/federation/audience.test.mjs +0 -130
  56. package/dist/federation/builder.test.d.mts +0 -2
  57. package/dist/federation/builder.test.mjs +0 -396
  58. package/dist/federation/circuit-breaker.test.d.mts +0 -2
  59. package/dist/federation/circuit-breaker.test.mjs +0 -1277
  60. package/dist/federation/collection.test.d.mts +0 -2
  61. package/dist/federation/collection.test.mjs +0 -21
  62. package/dist/federation/compound-fanout.test.d.mts +0 -2
  63. package/dist/federation/compound-fanout.test.mjs +0 -231
  64. package/dist/federation/handler-compound-proof.test.d.mts +0 -2
  65. package/dist/federation/handler-compound-proof.test.mjs +0 -384
  66. package/dist/federation/handler.test.d.mts +0 -2
  67. package/dist/federation/handler.test.mjs +0 -5445
  68. package/dist/federation/hashlink-media.test.d.mts +0 -2
  69. package/dist/federation/hashlink-media.test.mjs +0 -422
  70. package/dist/federation/idempotency.test.d.mts +0 -2
  71. package/dist/federation/idempotency.test.mjs +0 -207
  72. package/dist/federation/inbox-actorless.test.d.mts +0 -2
  73. package/dist/federation/inbox-actorless.test.mjs +0 -522
  74. package/dist/federation/inbox-authentication.test.d.mts +0 -2
  75. package/dist/federation/inbox-authentication.test.mjs +0 -220
  76. package/dist/federation/inbox-report.test.d.mts +0 -2
  77. package/dist/federation/inbox-report.test.mjs +0 -719
  78. package/dist/federation/inbox-view.test.d.mts +0 -2
  79. package/dist/federation/inbox-view.test.mjs +0 -369
  80. package/dist/federation/inbox.test.d.mts +0 -2
  81. package/dist/federation/inbox.test.mjs +0 -139
  82. package/dist/federation/keycache.test.d.mts +0 -2
  83. package/dist/federation/keycache.test.mjs +0 -337
  84. package/dist/federation/kv.test.d.mts +0 -2
  85. package/dist/federation/kv.test.mjs +0 -88
  86. package/dist/federation/metrics.test.d.mts +0 -2
  87. package/dist/federation/metrics.test.mjs +0 -634
  88. package/dist/federation/middleware.test.d.mts +0 -2
  89. package/dist/federation/middleware.test.mjs +0 -9314
  90. package/dist/federation/mq.test.d.mts +0 -2
  91. package/dist/federation/mq.test.mjs +0 -591
  92. package/dist/federation/negotiation.test.d.mts +0 -2
  93. package/dist/federation/negotiation.test.mjs +0 -18
  94. package/dist/federation/outbound-body.test.d.mts +0 -2
  95. package/dist/federation/outbound-body.test.mjs +0 -149
  96. package/dist/federation/outbound-capture.test.d.mts +0 -2
  97. package/dist/federation/outbound-capture.test.mjs +0 -394
  98. package/dist/federation/outbound-dispatch.test.d.mts +0 -2
  99. package/dist/federation/outbound-dispatch.test.mjs +0 -368
  100. package/dist/federation/outbound-document.test.d.mts +0 -2
  101. package/dist/federation/outbound-document.test.mjs +0 -171
  102. package/dist/federation/outbound-provenance.test.d.mts +0 -2
  103. package/dist/federation/outbound-provenance.test.mjs +0 -543
  104. package/dist/federation/outbound-report.test.d.mts +0 -2
  105. package/dist/federation/outbound-report.test.mjs +0 -5475
  106. package/dist/federation/outbound-workers.test.d.mts +0 -2
  107. package/dist/federation/outbound-workers.test.mjs +0 -64
  108. package/dist/federation/outbound-workflow.test.d.mts +0 -2
  109. package/dist/federation/outbound-workflow.test.mjs +0 -154
  110. package/dist/federation/outgoing-proof.test.d.mts +0 -2
  111. package/dist/federation/outgoing-proof.test.mjs +0 -933
  112. package/dist/federation/portable-actor.test.d.mts +0 -2
  113. package/dist/federation/portable-actor.test.mjs +0 -496
  114. package/dist/federation/portable-chain.test.d.mts +0 -2
  115. package/dist/federation/portable-chain.test.mjs +0 -370
  116. package/dist/federation/portable-collection.test.d.mts +0 -2
  117. package/dist/federation/portable-collection.test.mjs +0 -832
  118. package/dist/federation/portable-delivery.test.d.mts +0 -2
  119. package/dist/federation/portable-delivery.test.mjs +0 -845
  120. package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
  121. package/dist/federation/portable-gateway-keys.test.mjs +0 -692
  122. package/dist/federation/portable-inbox.test.d.mts +0 -2
  123. package/dist/federation/portable-inbox.test.mjs +0 -1960
  124. package/dist/federation/portable-parse-uri.test.d.mts +0 -2
  125. package/dist/federation/portable-parse-uri.test.mjs +0 -348
  126. package/dist/federation/portable-route-activity.test.d.mts +0 -2
  127. package/dist/federation/portable-route-activity.test.mjs +0 -259
  128. package/dist/federation/portable.test.d.mts +0 -2
  129. package/dist/federation/portable.test.mjs +0 -1072
  130. package/dist/federation/retry.test.d.mts +0 -2
  131. package/dist/federation/retry.test.mjs +0 -42
  132. package/dist/federation/router.test.d.mts +0 -2
  133. package/dist/federation/router.test.mjs +0 -123
  134. package/dist/federation/send.test.d.mts +0 -2
  135. package/dist/federation/send.test.mjs +0 -1421
  136. package/dist/federation/tasks/codec.test.d.mts +0 -2
  137. package/dist/federation/tasks/codec.test.mjs +0 -302
  138. package/dist/federation/tasks/enqueue.test.d.mts +0 -2
  139. package/dist/federation/tasks/enqueue.test.mjs +0 -1095
  140. package/dist/federation/tasks/tasks.test.d.mts +0 -2
  141. package/dist/federation/tasks/tasks.test.mjs +0 -1229
  142. package/dist/federation/temporal.test.d.mts +0 -2
  143. package/dist/federation/temporal.test.mjs +0 -71
  144. package/dist/federation/webfinger.test.d.mts +0 -2
  145. package/dist/federation/webfinger.test.mjs +0 -944
  146. package/dist/http-BXbQQZDM.mjs +0 -1449
  147. package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
  148. package/dist/inbox-cS97XzOD.mjs +0 -399
  149. package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
  150. package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
  151. package/dist/keycache-N2opu4-3.mjs +0 -221
  152. package/dist/keys-DIJNHW-Y.mjs +0 -120
  153. package/dist/kv-DBRWVx3Q.mjs +0 -104
  154. package/dist/kv-DCHkaJ9-.mjs +0 -92
  155. package/dist/kv-cache-fgbLHGVL.mjs +0 -121
  156. package/dist/ld-BpkhkDGj.mjs +0 -1752
  157. package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
  158. package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
  159. package/dist/metrics-Uqf8GomB.mjs +0 -818
  160. package/dist/middleware-DcXzz-YK.mjs +0 -9971
  161. package/dist/middleware-DgwZkvJR.mjs +0 -5
  162. package/dist/mq-eF96QxUT.mjs +0 -288
  163. package/dist/negotiation-BAKO9nih.mjs +0 -96
  164. package/dist/nodeinfo/client.test.d.mts +0 -2
  165. package/dist/nodeinfo/client.test.mjs +0 -1364
  166. package/dist/nodeinfo/handler.test.d.mts +0 -2
  167. package/dist/nodeinfo/handler.test.mjs +0 -94
  168. package/dist/nodeinfo/types.test.d.mts +0 -2
  169. package/dist/nodeinfo/types.test.mjs +0 -192
  170. package/dist/otel/exporter.test.d.mts +0 -2
  171. package/dist/otel/exporter.test.mjs +0 -887
  172. package/dist/outbound-body-CckPA5gc.mjs +0 -83
  173. package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
  174. package/dist/outbound-document-BMgwLXTY.mjs +0 -179
  175. package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
  176. package/dist/owner-BVenIFg1.mjs +0 -267
  177. package/dist/portable-collection-DIk9gpjL.mjs +0 -418
  178. package/dist/portable-key-C7pVaHNR.mjs +0 -549
  179. package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
  180. package/dist/proof-BlfZ95--.mjs +0 -1420
  181. package/dist/public-audience--klBIOk1.mjs +0 -197
  182. package/dist/retry-zX5xw5e0.mjs +0 -34
  183. package/dist/router-u5O5KCQr.mjs +0 -156
  184. package/dist/secured-document-CxzZZ9nL.mjs +0 -35
  185. package/dist/send-DEGHPGFk.mjs +0 -710
  186. package/dist/sig/accept.test.d.mts +0 -2
  187. package/dist/sig/accept.test.mjs +0 -416
  188. package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
  189. package/dist/sig/compound-proof-discovery.test.mjs +0 -331
  190. package/dist/sig/compound-proof-producer.test.d.mts +0 -2
  191. package/dist/sig/compound-proof-producer.test.mjs +0 -107
  192. package/dist/sig/compound-proof-verification.test.d.mts +0 -2
  193. package/dist/sig/compound-proof-verification.test.mjs +0 -1017
  194. package/dist/sig/compound-proof.test.d.mts +0 -2
  195. package/dist/sig/compound-proof.test.mjs +0 -411
  196. package/dist/sig/http.test.d.mts +0 -2
  197. package/dist/sig/http.test.mjs +0 -3328
  198. package/dist/sig/key-owner-evidence.test.d.mts +0 -2
  199. package/dist/sig/key-owner-evidence.test.mjs +0 -100
  200. package/dist/sig/key.test.d.mts +0 -2
  201. package/dist/sig/key.test.mjs +0 -1250
  202. package/dist/sig/ld.test.d.mts +0 -2
  203. package/dist/sig/ld.test.mjs +0 -1044
  204. package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
  205. package/dist/sig/mitra-receive-interop.test.mjs +0 -260
  206. package/dist/sig/mitra-send-interop.test.d.mts +0 -2
  207. package/dist/sig/mitra-send-interop.test.mjs +0 -461
  208. package/dist/sig/owner.test.d.mts +0 -2
  209. package/dist/sig/owner.test.mjs +0 -202
  210. package/dist/sig/portable-collection.test.d.mts +0 -2
  211. package/dist/sig/portable-collection.test.mjs +0 -697
  212. package/dist/sig/portable-interop.test.d.mts +0 -2
  213. package/dist/sig/portable-interop.test.mjs +0 -156
  214. package/dist/sig/portable-key-id.test.d.mts +0 -2
  215. package/dist/sig/portable-key-id.test.mjs +0 -67
  216. package/dist/sig/portable-key.test.d.mts +0 -2
  217. package/dist/sig/portable-key.test.mjs +0 -1438
  218. package/dist/sig/proof.test.d.mts +0 -2
  219. package/dist/sig/proof.test.mjs +0 -2638
  220. package/dist/sig/tootik-request-interop.test.d.mts +0 -2
  221. package/dist/sig/tootik-request-interop.test.mjs +0 -190
  222. package/dist/sig/tootik-send-interop.test.d.mts +0 -2
  223. package/dist/sig/tootik-send-interop.test.mjs +0 -331
  224. package/dist/sig/verification.test.d.mts +0 -2
  225. package/dist/sig/verification.test.mjs +0 -310
  226. package/dist/std__assert-DvMDRPes.mjs +0 -8
  227. package/dist/tasks-BCUmQbbz.mjs +0 -77
  228. package/dist/temporal-B4oQ8HpW.mjs +0 -95
  229. package/dist/testing/context.test.d.mts +0 -2
  230. package/dist/testing/context.test.mjs +0 -19
  231. package/dist/testing/kv.test.d.mts +0 -2
  232. package/dist/testing/kv.test.mjs +0 -101
  233. package/dist/testing/mod.d.mts +0 -6099
  234. package/dist/testing/mod.mjs +0 -9
  235. package/dist/testing-vrnD5Uaa.mjs +0 -8
  236. package/dist/types-DE_LV1JB.mjs +0 -46
  237. package/dist/utils/docloader.test.d.mts +0 -2
  238. package/dist/utils/docloader.test.mjs +0 -1076
  239. package/dist/utils/kv-cache.test.d.mts +0 -2
  240. package/dist/utils/kv-cache.test.mjs +0 -261
  241. package/dist/verification-C3954hQh.mjs +0 -5
  242. package/dist/verification-Dpfcw8ml.mjs +0 -105
  243. package/dist/vocab/cjs.test.d.mts +0 -2
  244. package/dist/vocab/cjs.test.mjs +0 -27
@@ -1,1017 +0,0 @@
1
- import "temporal-polyfill";
2
- import "urlpattern-polyfill";
3
- globalThis.addEventListener = () => {};
4
- import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
5
- import "../std__assert-DvMDRPes.mjs";
6
- import { t as assert } from "../assert-D1Eafmd_.mjs";
7
- import { c as verifyMapLocalProof, f as verifyPortableObjectProofPolicy } from "../proof-BlfZ95--.mjs";
8
- import { n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2 } from "../keys-DIJNHW-Y.mjs";
9
- import { a as inspectCompoundPortableObjectApplicability, o as verifyCompoundPortableObjectProofs, s as verifyCompoundProofDocuments, t as containsCompoundPortableObject } from "../compound-proof-DSHhnOEW.mjs";
10
- import { t as map_local_create_note_default } from "../map-local-create-note-B0SeXJms.mjs";
11
- import { t as map_local_context_conflict_default } from "../map-local-context-conflict-DOYEEJ3u.mjs";
12
- import { CryptographicKey, Multikey, Person } from "@fedify/vocab";
13
- import { encodeMultibase, exportDidKey, parseIri } from "@fedify/vocab-runtime";
14
- import { mockDocumentLoader, test } from "@fedify/fixture";
15
- import serialize from "json-canon";
16
- //#region src/sig/compound-proof-verification.test.ts
17
- const limits = {
18
- maxDepth: 16,
19
- maxMaps: 32,
20
- maxProofs: 8,
21
- maxBytes: 16384
22
- };
23
- const options = {
24
- contextLoader: mockDocumentLoader,
25
- documentLoader() {
26
- throw new TypeError("did:key must not use the document loader");
27
- }
28
- };
29
- function createInlineProofContext() {
30
- return {
31
- id: "@id",
32
- type: "@type",
33
- Note: "https://www.w3.org/ns/activitystreams#Note",
34
- attributedTo: {
35
- "@id": "https://www.w3.org/ns/activitystreams#attributedTo",
36
- "@type": "@id"
37
- },
38
- content: "https://www.w3.org/ns/activitystreams#content",
39
- DataIntegrityProof: "https://w3id.org/security#DataIntegrityProof",
40
- cryptosuite: "https://w3id.org/security#cryptosuite",
41
- verificationMethod: {
42
- "@id": "https://w3id.org/security#verificationMethod",
43
- "@type": "@id"
44
- },
45
- proofPurpose: {
46
- "@id": "https://w3id.org/security#proofPurpose",
47
- "@type": "@vocab"
48
- },
49
- assertionMethod: "https://w3id.org/security#assertionMethod",
50
- created: {
51
- "@id": "http://purl.org/dc/terms/created",
52
- "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
53
- },
54
- proofValue: "https://w3id.org/security#proofValue",
55
- proof: "https://w3id.org/security#proof"
56
- };
57
- }
58
- function asRecord(value) {
59
- assert(value != null && typeof value === "object" && !Array.isArray(value));
60
- return value;
61
- }
62
- async function sha256(value) {
63
- return new Uint8Array(await crypto.subtle.digest("SHA-256", new TextEncoder().encode(value)));
64
- }
65
- async function secureRawDocument(unsecuredDocument, privateJwk, verificationMethod, proofContext = unsecuredDocument["@context"]) {
66
- const proofConfiguration = {
67
- "@context": structuredClone(proofContext),
68
- type: "DataIntegrityProof",
69
- cryptosuite: "eddsa-jcs-2022",
70
- verificationMethod,
71
- proofPurpose: "assertionMethod",
72
- created: "2023-02-24T23:36:38Z"
73
- };
74
- const proofDigest = await sha256(serialize(proofConfiguration));
75
- const documentDigest = await sha256(serialize(unsecuredDocument));
76
- const input = new Uint8Array(proofDigest.length + documentDigest.length);
77
- input.set(proofDigest);
78
- input.set(documentDigest, proofDigest.length);
79
- const privateKey = await crypto.subtle.importKey("jwk", privateJwk, "Ed25519", false, ["sign"]);
80
- const signature = new Uint8Array(await crypto.subtle.sign("Ed25519", privateKey, input));
81
- return {
82
- ...unsecuredDocument,
83
- proof: {
84
- ...proofConfiguration,
85
- proofValue: new TextDecoder().decode(encodeMultibase("base58btc", signature))
86
- }
87
- };
88
- }
89
- test("verifyCompoundProofDocuments() verifies the recorded maps independently", async () => {
90
- for (const fixture of [map_local_create_note_default, map_local_context_conflict_default]) {
91
- const input = structuredClone(fixture.documents.finalSecuredCompound);
92
- const result = await verifyCompoundProofDocuments(input, limits, options);
93
- assertEquals(result.status, "ok");
94
- if (result.status !== "ok") continue;
95
- assert(result.verified);
96
- assertEquals(result.documents.map(({ path, verified }) => ({
97
- path,
98
- verified
99
- })), [{
100
- path: "/object",
101
- verified: true
102
- }, {
103
- path: "",
104
- verified: true
105
- }]);
106
- assertEquals(result.documents.map((document) => document.verified ? document.key.id?.href : null), [fixture.keys.inner.verificationMethod, fixture.keys.outer.verificationMethod]);
107
- assertEquals(result.snapshot, input);
108
- }
109
- });
110
- test("verifyCompoundProofDocuments() does not verify an empty proof set", async () => {
111
- const result = await verifyCompoundProofDocuments({
112
- "@context": "https://www.w3.org/ns/activitystreams",
113
- id: "https://example.com/notes/unsigned",
114
- type: "Note"
115
- }, limits, options);
116
- assertEquals(result.status, "ok");
117
- if (result.status !== "ok") return;
118
- assertEquals(result.verified, false);
119
- assertEquals(result.documents, []);
120
- assertEquals(result.statistics.proofCount, 0);
121
- });
122
- test("verifyCompoundProofDocuments() reports tampering and proof replacement per map", async () => {
123
- const tampered = structuredClone(map_local_create_note_default.documents.finalSecuredCompound);
124
- asRecord(tampered.object).content = "Tampered after both proofs";
125
- const tamperedResult = await verifyCompoundProofDocuments(tampered, limits, options);
126
- assertEquals(tamperedResult.status, "ok");
127
- if (tamperedResult.status === "ok") {
128
- assertEquals(tamperedResult.verified, false);
129
- assertEquals(tamperedResult.documents.map(({ path, verified }) => ({
130
- path,
131
- verified
132
- })), [{
133
- path: "/object",
134
- verified: false
135
- }, {
136
- path: "",
137
- verified: false
138
- }]);
139
- }
140
- const replaced = structuredClone(map_local_create_note_default.documents.finalSecuredCompound);
141
- asRecord(replaced.object).proof = structuredClone(map_local_create_note_default.documents.replacementInnerProof);
142
- const replacedResult = await verifyCompoundProofDocuments(replaced, limits, options);
143
- assertEquals(replacedResult.status, "ok");
144
- if (replacedResult.status === "ok") {
145
- assertEquals(replacedResult.verified, false);
146
- assertEquals(replacedResult.documents.map(({ path, verified }) => ({
147
- path,
148
- verified
149
- })), [{
150
- path: "/object",
151
- verified: true
152
- }, {
153
- path: "",
154
- verified: false
155
- }]);
156
- }
157
- });
158
- test("verifyCompoundProofDocuments() requires a local context on nested secured maps", async () => {
159
- const input = structuredClone(map_local_create_note_default.documents.finalSecuredCompound);
160
- delete asRecord(input.object)["@context"];
161
- const result = await verifyCompoundProofDocuments(input, limits, options);
162
- assertEquals(result.status, "ok");
163
- if (result.status !== "ok") return;
164
- assertEquals(result.verified, false);
165
- assertEquals(result.documents[0], {
166
- path: "/object",
167
- id: map_local_create_note_default.documents.securedInner.id,
168
- depth: 1,
169
- verified: false,
170
- reason: { type: "missingContext" }
171
- });
172
- });
173
- test("verifyCompoundProofDocuments() preserves proof aliases in the JCS input", async () => {
174
- const secured = await secureRawDocument({
175
- "@context": [
176
- "https://www.w3.org/ns/activitystreams",
177
- "https://w3id.org/security/data-integrity/v1",
178
- { integrityProof: "https://w3id.org/security#proof" }
179
- ],
180
- id: "https://example.com/notes/alias-bound",
181
- type: "Note",
182
- content: "Alias-bound content",
183
- integrityProof: "This value is signed data, not the direct proof."
184
- }, map_local_create_note_default.keys.outer.testPrivateKeyJwk, map_local_create_note_default.keys.outer.verificationMethod);
185
- const result = await verifyCompoundProofDocuments(secured, limits, options);
186
- assertEquals(result.status, "ok");
187
- if (result.status !== "ok") return;
188
- assert(result.verified);
189
- const tampered = structuredClone(secured);
190
- tampered.integrityProof = "Changed after signing";
191
- const tamperedResult = await verifyCompoundProofDocuments(tampered, limits, options);
192
- assertEquals(tamperedResult.status, "ok");
193
- if (tamperedResult.status === "ok") assertEquals(tamperedResult.verified, false);
194
- });
195
- test("verifyCompoundProofDocuments() preserves the received document context", async () => {
196
- const proofContext = ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"];
197
- const result = await verifyCompoundProofDocuments(await secureRawDocument({
198
- "@context": [...proofContext, { ex: "https://example.com/ns#" }],
199
- id: "https://example.com/notes/distinct-contexts",
200
- type: "Note",
201
- content: "The document context is part of the signed input."
202
- }, map_local_create_note_default.keys.outer.testPrivateKeyJwk, map_local_create_note_default.keys.outer.verificationMethod, proofContext), limits, options);
203
- assertEquals(result.status, "ok");
204
- if (result.status !== "ok") return;
205
- assert(result.verified);
206
- });
207
- test("verifyCompoundProofDocuments() authenticates only received JSON values", async () => {
208
- const secured = await secureRawDocument({
209
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
210
- id: "https://example.com/notes/attachment-array",
211
- type: "Note",
212
- attachment: ["https://example.com/images/1"]
213
- }, map_local_create_note_default.keys.outer.testPrivateKeyJwk, map_local_create_note_default.keys.outer.verificationMethod);
214
- const verified = await verifyCompoundProofDocuments(secured, limits, options);
215
- assertEquals(verified.status, "ok");
216
- if (verified.status !== "ok") return;
217
- assert(verified.verified);
218
- const tampered = structuredClone(secured);
219
- tampered.attachment = "https://example.com/images/1";
220
- const result = await verifyCompoundProofDocuments(tampered, limits, options);
221
- assertEquals(result.status, "ok");
222
- if (result.status === "ok") assertEquals(result.verified, false);
223
- });
224
- test("verifyCompoundProofDocuments() contains malformed contexts per map", async () => {
225
- const valid = await secureRawDocument({
226
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
227
- id: "https://example.com/notes/valid-sibling",
228
- type: "Note",
229
- content: "This sibling must still produce a result."
230
- }, map_local_create_note_default.keys.outer.testPrivateKeyJwk, map_local_create_note_default.keys.outer.verificationMethod);
231
- const malformed = structuredClone(valid);
232
- malformed["@context"] = 42;
233
- malformed.id = "https://example.com/notes/malformed-context";
234
- malformed.proof = {
235
- "@context": [],
236
- "@type": ["https://w3id.org/security#DataIntegrityProof"],
237
- "https://w3id.org/security#cryptosuite": [{ "@value": "eddsa-jcs-2022" }],
238
- "https://w3id.org/security#verificationMethod": [{ "@id": map_local_create_note_default.keys.outer.verificationMethod }],
239
- "https://w3id.org/security#proofPurpose": [{ "@id": "https://w3id.org/security#assertionMethod" }],
240
- "http://purl.org/dc/terms/created": [{
241
- "@value": "2023-02-24T23:36:38Z",
242
- "@type": "http://www.w3.org/2001/XMLSchema#dateTime"
243
- }],
244
- "https://w3id.org/security#proofValue": [{ "@value": asRecord(valid.proof).proofValue }]
245
- };
246
- const result = await verifyCompoundProofDocuments({
247
- malformed,
248
- valid
249
- }, limits, options);
250
- assertEquals(result.status, "ok");
251
- if (result.status !== "ok") return;
252
- assertEquals(result.verified, false);
253
- assertEquals(result.documents.map((document) => ({
254
- path: document.path,
255
- verified: document.verified,
256
- reason: document.verified ? void 0 : document.reason.type
257
- })), [{
258
- path: "/malformed",
259
- verified: false,
260
- reason: "invalidProof"
261
- }, {
262
- path: "/valid",
263
- verified: true,
264
- reason: void 0
265
- }]);
266
- });
267
- test("verifyCompoundProofDocuments() does not fetch proof contexts", async () => {
268
- let contextLoads = 0;
269
- const result = await verifyCompoundProofDocuments({
270
- "@context": "https://attacker.example/context",
271
- id: "https://example.com/notes/remote-context",
272
- type: "Note",
273
- proof: {
274
- type: "DataIntegrityProof",
275
- cryptosuite: "eddsa-jcs-2022",
276
- verificationMethod: map_local_create_note_default.keys.outer.verificationMethod,
277
- proofPurpose: "assertionMethod",
278
- created: "2023-02-24T23:36:38Z",
279
- proofValue: map_local_create_note_default.proofValues.outer
280
- }
281
- }, limits, {
282
- ...options,
283
- contextLoader() {
284
- contextLoads++;
285
- throw new TypeError("unexpected context fetch");
286
- }
287
- });
288
- assertEquals(result.status, "ok");
289
- if (result.status === "ok") assertEquals(result.verified, false);
290
- assertEquals(contextLoads, 0);
291
- });
292
- test("verifyCompoundPortableObjectProofs() applies policy to every portable map", async () => {
293
- let contextLoads = 0;
294
- const result = await verifyCompoundPortableObjectProofs(map_local_create_note_default.documents.finalSecuredCompound, limits, {
295
- ...options,
296
- contextLoader() {
297
- contextLoads++;
298
- throw new TypeError("unexpected context fetch");
299
- }
300
- });
301
- assertEquals(result.status, "ok");
302
- if (result.status !== "ok") return;
303
- assert(result.verified);
304
- assertEquals(contextLoads, 0);
305
- assertEquals(result.portableObjects.map((document) => ({
306
- path: document.path,
307
- verified: document.verified,
308
- keys: document.verified ? document.keys.map((key) => key.id?.href) : []
309
- })), [{
310
- path: "/object",
311
- verified: true,
312
- keys: [map_local_create_note_default.keys.inner.verificationMethod]
313
- }, {
314
- path: "",
315
- verified: true,
316
- keys: [map_local_create_note_default.keys.outer.verificationMethod]
317
- }]);
318
- });
319
- test("verifyCompoundPortableObjectProofs() reports unsigned portable maps", async () => {
320
- const context = ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"];
321
- const result = await verifyCompoundPortableObjectProofs({
322
- "@context": context,
323
- id: map_local_create_note_default.documents.outerUnsecuredDocument.id,
324
- type: "Create",
325
- actor: map_local_create_note_default.documents.outerUnsecuredDocument.actor,
326
- object: {
327
- "@context": structuredClone(context),
328
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
329
- type: "Note",
330
- attributedTo: map_local_create_note_default.documents.innerUnsecuredDocument.attributedTo,
331
- content: "Unsigned portable child"
332
- }
333
- }, limits, options);
334
- assertEquals(result.status, "ok");
335
- if (result.status !== "ok") return;
336
- assertEquals(result.verified, false);
337
- assertEquals(result.proofs, []);
338
- assertEquals(result.portableObjects.map((document) => ({
339
- path: document.path,
340
- verified: document.verified,
341
- reason: document.verified ? void 0 : document.reason.type
342
- })), [{
343
- path: "/object",
344
- verified: false,
345
- reason: "missingProof"
346
- }, {
347
- path: "",
348
- verified: false,
349
- reason: "missingProof"
350
- }]);
351
- });
352
- test("verifyCompoundPortableObjectProofs() reports policy before crypto failure", async () => {
353
- const mismatched = structuredClone(map_local_create_note_default.documents.finalSecuredCompound);
354
- asRecord(mismatched.object).id = map_local_create_note_default.documents.outerUnsecuredDocument.id;
355
- const result = await verifyCompoundPortableObjectProofs(mismatched, limits, options);
356
- assertEquals(result.status, "ok");
357
- if (result.status !== "ok") return;
358
- assertEquals(result.verified, false);
359
- const inner = result.portableObjects.find(({ path }) => path === "/object");
360
- assert(inner != null && !inner.verified);
361
- assertEquals(inner.reason.type, "verificationMethodMismatch");
362
- });
363
- test("verifyCompoundPortableObjectProofs() finds unsigned portable maps in arrays", async () => {
364
- const result = await verifyCompoundPortableObjectProofs({
365
- "@context": "https://www.w3.org/ns/activitystreams",
366
- id: "https://social.example/activities/1",
367
- type: "Create",
368
- attachment: [{
369
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
370
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
371
- type: "Note",
372
- content: "Unsigned portable attachment"
373
- }]
374
- }, limits, options);
375
- assertEquals(result.status, "ok");
376
- if (result.status !== "ok") return;
377
- assertEquals(result.verified, false);
378
- assertEquals(result.portableObjects.map((document) => ({
379
- path: document.path,
380
- reason: document.verified ? void 0 : document.reason.type
381
- })), [{
382
- path: "/attachment/0",
383
- reason: "missingProof"
384
- }]);
385
- });
386
- test("verifyCompoundPortableObjectProofs() ignores context definitions", async () => {
387
- const result = await verifyCompoundPortableObjectProofs({
388
- "@context": { portable: {
389
- "@id": map_local_create_note_default.documents.innerUnsecuredDocument.id,
390
- "@context": { proof: "https://w3id.org/security#proof" }
391
- } },
392
- id: "https://social.example/objects/1",
393
- type: "Note"
394
- }, limits, options);
395
- assertEquals(result.status, "ok");
396
- if (result.status !== "ok") return;
397
- assertEquals(result.verified, false);
398
- assertEquals(result.proofs, []);
399
- assertEquals(result.portableObjects, []);
400
- });
401
- test("verifyCompoundPortableObjectProofs() contains malformed portable IDs", async () => {
402
- const result = await verifyCompoundPortableObjectProofs({
403
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
404
- id: "ap://did%ZZkey/objects/1",
405
- type: "Note"
406
- }, limits, options);
407
- assertEquals(result.status, "ok");
408
- if (result.status !== "ok") return;
409
- assertEquals(result.verified, false);
410
- assertEquals(result.portableObjects.length, 1);
411
- const [object] = result.portableObjects;
412
- assert(!object.verified);
413
- assertEquals(object.reason, { type: "invalidPortableObject" });
414
- });
415
- test("verifyPortableObjectProofPolicy() binds policy to the verified key", async () => {
416
- const outerKey = await verifyMapLocalProof(map_local_create_note_default.documents.finalSecuredCompound, options);
417
- assert(outerKey != null);
418
- assertEquals(await verifyPortableObjectProofPolicy(map_local_create_note_default.documents.securedInner, outerKey, options), {
419
- verified: false,
420
- reason: {
421
- type: "invalidProof",
422
- proofIndex: 0
423
- }
424
- });
425
- });
426
- test("verifyPortableObjectProofPolicy() binds policy to the verified proof", async () => {
427
- const context = createInlineProofContext();
428
- context.proof = {
429
- "@id": "https://w3id.org/security#proof",
430
- "@context": { assertionMethod: "https://w3id.org/security#authentication" }
431
- };
432
- const secured = await secureRawDocument({
433
- "@context": context,
434
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
435
- type: "Note",
436
- attributedTo: map_local_create_note_default.documents.innerUnsecuredDocument.attributedTo,
437
- content: "Property-scoped proof purpose"
438
- }, map_local_create_note_default.keys.inner.testPrivateKeyJwk, map_local_create_note_default.keys.inner.verificationMethod);
439
- delete asRecord(secured.proof)["@context"];
440
- const key = await verifyMapLocalProof(secured, options);
441
- assert(key != null);
442
- assertEquals(await verifyPortableObjectProofPolicy(secured, key, options), {
443
- verified: false,
444
- reason: {
445
- type: "invalidProof",
446
- proofIndex: 0
447
- }
448
- });
449
- });
450
- test("verifyCompoundPortableObjectProofs() reports the policy-validated ID", async () => {
451
- const context = createInlineProofContext();
452
- context.id = "https://example.com/id";
453
- const result = await verifyCompoundPortableObjectProofs(await secureRawDocument({
454
- "@context": context,
455
- id: map_local_create_note_default.documents.outerUnsecuredDocument.id,
456
- "@id": map_local_create_note_default.documents.innerUnsecuredDocument.id,
457
- type: "Note",
458
- content: "Conflicting raw ID"
459
- }, map_local_create_note_default.keys.inner.testPrivateKeyJwk, map_local_create_note_default.keys.inner.verificationMethod), limits, options);
460
- assertEquals(result.status, "ok");
461
- if (result.status !== "ok") return;
462
- assert(result.verified);
463
- assertEquals(result.portableObjects.length, 1);
464
- assertEquals(result.portableObjects[0].id, map_local_create_note_default.documents.innerUnsecuredDocument.id);
465
- });
466
- const compatibleDid = await exportDidKey(ed25519PublicKey.publicKey);
467
- const compatibleVerificationMethod = `${compatibleDid}#${compatibleDid.slice(8)}`;
468
- const compatibleActorId = `https://gw.example/.well-known/apgateway/${compatibleDid}/actor`;
469
- const compatibleContext = ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"];
470
- async function signCompatible(document) {
471
- return await secureRawDocument(document, await crypto.subtle.exportKey("jwk", ed25519PrivateKey), compatibleVerificationMethod);
472
- }
473
- async function compatibleActor(id = compatibleActorId, keyBase = compatibleActorId) {
474
- const actorId = parseIri(id);
475
- return await new Person({
476
- id: actorId,
477
- inbox: new URL(`${keyBase}/inbox`),
478
- outbox: new URL(`${keyBase}/outbox`),
479
- gateways: [new URL("https://gw.example")],
480
- publicKey: new CryptographicKey({
481
- id: new URL(`${keyBase}#main-key`),
482
- owner: actorId,
483
- publicKey: rsaPublicKey2.publicKey
484
- }),
485
- assertionMethods: [new Multikey({
486
- id: new URL(`${keyBase}#ed25519-key`),
487
- controller: actorId,
488
- publicKey: ed25519PublicKey.publicKey
489
- })]
490
- }).toJsonLd({
491
- format: "compact",
492
- contextLoader: mockDocumentLoader
493
- });
494
- }
495
- test("verifyCompoundPortableObjectProofs() treats compatible-ID maps as portable", async () => {
496
- const note = {
497
- "@context": [...compatibleContext],
498
- id: `${compatibleActorId}/notes/1`,
499
- type: "Note",
500
- attributedTo: compatibleActorId,
501
- content: "Hello"
502
- };
503
- const ordinary = {
504
- "@context": [...compatibleContext],
505
- id: "https://social.example/activities/1",
506
- type: "Announce",
507
- actor: "https://social.example/users/bob",
508
- object: note
509
- };
510
- assertEquals(inspectCompoundPortableObjectApplicability(ordinary, limits), "present");
511
- assert(containsCompoundPortableObject(ordinary));
512
- const result = await verifyCompoundPortableObjectProofs(ordinary, limits, options);
513
- assert(result.status === "ok");
514
- assertEquals(result.verified, false);
515
- assertEquals(result.portableObjects.map((o) => [o.path, o.verified]), [["/object", false]]);
516
- const signed = await verifyCompoundPortableObjectProofs({
517
- ...ordinary,
518
- object: await signCompatible(note)
519
- }, limits, options);
520
- assert(signed.status === "ok");
521
- assert(signed.verified);
522
- });
523
- test("verifyCompoundPortableObjectProofs() checks compatible activity IDs", async () => {
524
- const create = (did) => ({
525
- "@context": [...compatibleContext],
526
- id: `https://gw.example/.well-known/apgateway/${did}/activities/1`,
527
- type: "Create",
528
- actor: compatibleActorId,
529
- object: "https://social.example/notes/1"
530
- });
531
- const own = await verifyCompoundPortableObjectProofs(await signCompatible(create(compatibleDid)), limits, options);
532
- assert(own.status === "ok");
533
- assert(own.verified);
534
- const forged = await verifyCompoundPortableObjectProofs(await signCompatible(create("did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK")), limits, options);
535
- assert(forged.status === "ok");
536
- assertEquals(forged.verified, false);
537
- const [object] = forged.portableObjects;
538
- assert(!object.verified);
539
- assertEquals(object.reason.type, "verificationMethodMismatch");
540
- });
541
- test("verifyCompoundPortableObjectProofs() exempts keys embedded in portable actors", async () => {
542
- let result = await verifyCompoundPortableObjectProofs(await signCompatible(await compatibleActor()), limits, options);
543
- assert(result.status === "ok");
544
- assert(result.verified);
545
- assertEquals(result.portableObjects.map((o) => o.path), [""]);
546
- const actorWithSetTerm = await compatibleActor();
547
- result = await verifyCompoundPortableObjectProofs(await signCompatible({
548
- ...actorWithSetTerm,
549
- "@context": [...actorWithSetTerm["@context"], { tags: {
550
- "@id": "https://example.com/tags",
551
- "@container": "@set"
552
- } }]
553
- }), limits, options);
554
- assert(result.status === "ok");
555
- assert(result.verified);
556
- assertEquals(result.portableObjects.map((o) => o.path), [""]);
557
- result = await verifyCompoundPortableObjectProofs(await signCompatible(await compatibleActor(`ap://${compatibleDid}/actor`)), limits, options);
558
- assert(result.status === "ok");
559
- assert(result.verified);
560
- result = await verifyCompoundPortableObjectProofs({
561
- "@context": [...compatibleContext],
562
- id: "https://social.example/activities/2",
563
- type: "Update",
564
- actor: "https://social.example/users/bob",
565
- object: await signCompatible(await compatibleActor())
566
- }, limits, options);
567
- assert(result.status === "ok");
568
- assert(result.verified);
569
- });
570
- test("verifyCompoundPortableObjectProofs() exempts only keys of the parent itself", async () => {
571
- const actor = await compatibleActor();
572
- const otherActorId = "https://gw.example/.well-known/apgateway/did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK/actor";
573
- const publicKey = actor.publicKey;
574
- const cases = {
575
- "a key of another actor": {
576
- ...actor,
577
- publicKey: {
578
- ...publicKey,
579
- id: `${otherActorId}#main-key`,
580
- owner: otherActorId
581
- }
582
- },
583
- "a key owned by another actor": {
584
- ...actor,
585
- publicKey: {
586
- ...publicKey,
587
- owner: otherActorId
588
- }
589
- },
590
- "a non-key object": {
591
- ...actor,
592
- publicKey: {
593
- id: `${compatibleActorId}#note`,
594
- type: "Note",
595
- content: "Not a key"
596
- }
597
- },
598
- "a key with extra content": {
599
- ...actor,
600
- publicKey: {
601
- ...publicKey,
602
- name: "Extra"
603
- }
604
- },
605
- "a key under another property": {
606
- ...actor,
607
- attachment: structuredClone(publicKey)
608
- },
609
- "a parent context with a keyword alias": {
610
- ...actor,
611
- "@context": [...actor["@context"], { kind: "@type" }]
612
- },
613
- "a parent context with a list container": {
614
- ...actor,
615
- "@context": [...actor["@context"], { tags: {
616
- "@id": "https://example.com/tags",
617
- "@container": "@list"
618
- } }]
619
- },
620
- "a key with a scoped context": {
621
- ...actor,
622
- publicKey: {
623
- ...publicKey,
624
- "@context": { CryptographicKey: {
625
- "@id": "https://w3id.org/security#Key",
626
- "@context": {}
627
- } }
628
- }
629
- }
630
- };
631
- for (const [name, document] of Object.entries(cases)) {
632
- const result = await verifyCompoundPortableObjectProofs(await signCompatible(document), limits, options);
633
- assert(result.status === "ok", name);
634
- assertEquals(result.verified, false, name);
635
- assert(result.portableObjects.find((o) => o.path === "")?.verified, name);
636
- assert(result.portableObjects.some((o) => o.path !== "" && !o.verified), name);
637
- }
638
- });
639
- /**
640
- * Rewrites the IDs of a {@link compatibleActor}'s keys as they are written,
641
- * e.g., as `ap:` URIs, which the serializer would canonicalize otherwise.
642
- */
643
- function withKeyIds(actor, keyBase, { id = actor.id, owner = id } = {}) {
644
- const [multikey] = actor.assertionMethod;
645
- return {
646
- ...actor,
647
- id,
648
- publicKey: {
649
- ...asRecord(actor.publicKey),
650
- id: `${keyBase}#main-key`,
651
- owner
652
- },
653
- assertionMethod: [{
654
- ...multikey,
655
- id: `${keyBase}#ed25519-key`,
656
- controller: owner
657
- }]
658
- };
659
- }
660
- const apActorId = `ap://${compatibleDid}/actor`;
661
- test("verifyCompoundPortableObjectProofs() exempts keys at ap: URIs embedded in portable actors", async () => {
662
- const actor = await compatibleActor();
663
- const encodedDid = encodeURIComponent(compatibleDid);
664
- const cases = {
665
- "ap: keys of an ap: actor": [apActorId, apActorId],
666
- "ap: keys of a compatible-ID actor": [compatibleActorId, apActorId],
667
- "ap+ef61: keys": [apActorId, `ap+ef61://${compatibleDid}/actor`],
668
- "keys with percent-encoded DIDs": [apActorId, `ap://${encodedDid}/actor`],
669
- "ap+ef61: keys of a percent-encoded actor": [`ap+ef61://${encodedDid}/actor`, `ap+ef61://${encodedDid}/actor`],
670
- "keys with an uppercase scheme": [apActorId, `AP://${compatibleDid}/actor`],
671
- "keys with location hints": [apActorId, `${apActorId}?@gateway=https%3A%2F%2Fgw.example`]
672
- };
673
- for (const [name, [id, keyBase]] of Object.entries(cases)) {
674
- const result = await verifyCompoundPortableObjectProofs(await signCompatible(withKeyIds(actor, keyBase, { id })), limits, options);
675
- assert(result.status === "ok", name);
676
- assert(result.verified, name);
677
- assertEquals(result.portableObjects.map((o) => o.path), [""], name);
678
- }
679
- const apActor = withKeyIds(actor, apActorId, { id: apActorId });
680
- const atIdKeys = (key) => {
681
- const { id, ...rest } = asRecord(key);
682
- return {
683
- ...rest,
684
- "@id": id
685
- };
686
- };
687
- const withAtIds = await verifyCompoundPortableObjectProofs(await signCompatible({
688
- ...apActor,
689
- publicKey: atIdKeys(apActor.publicKey),
690
- assertionMethod: apActor.assertionMethod.map(atIdKeys)
691
- }), limits, options);
692
- assert(withAtIds.status === "ok");
693
- assert(withAtIds.verified);
694
- assertEquals(withAtIds.portableObjects.map((o) => o.path), [""]);
695
- const withApTerm = await verifyCompoundPortableObjectProofs(await signCompatible({
696
- ...withKeyIds(actor, apActorId, { id: apActorId }),
697
- "@context": [...actor["@context"], { ap: "https://ap.example/" }]
698
- }), limits, options);
699
- assert(withApTerm.status === "ok");
700
- assert(withApTerm.verified);
701
- assertEquals(withApTerm.portableObjects.map((o) => o.path), [""]);
702
- const result = await verifyCompoundPortableObjectProofs(await signCompatible({
703
- "@context": [...compatibleContext],
704
- id: `ap://${compatibleDid}/activities/1`,
705
- type: "Update",
706
- actor: apActorId,
707
- object: await signCompatible(withKeyIds(actor, apActorId, { id: apActorId }))
708
- }), limits, options);
709
- assert(result.status === "ok");
710
- assert(result.verified);
711
- assertEquals(result.portableObjects.map((o) => o.path), ["/object", ""]);
712
- });
713
- test("verifyCompoundPortableObjectProofs() exempts only ap: keys of the parent itself", async () => {
714
- const actor = withKeyIds(await compatibleActor(), apActorId, { id: apActorId });
715
- const publicKey = asRecord(actor.publicKey);
716
- const otherDid = "did:key:z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK";
717
- const keyIds = {
718
- "a key of another actor": `ap://${compatibleDid}/other#main-key`,
719
- "a key of another DID": `ap://${otherDid}/actor#main-key`,
720
- "a key without a fragment": apActorId,
721
- "a key with an empty fragment": `${apActorId}#`,
722
- "a key with dot segments": `ap://${compatibleDid}/x/../actor#main-key`,
723
- "a key with encoded dot segments": `ap://${compatibleDid}/x/%2E%2E/actor#main-key`,
724
- "a key with an encoded slash": `${apActorId}%2F#main-key`,
725
- "a key with an encoded fragment delimiter": `${apActorId}%23main-key`,
726
- "a compatible key with dot segments": `https://gw.example/.well-known/apgateway/${compatibleDid}/x/../actor#main-key`
727
- };
728
- const cases = {};
729
- for (const [name, id] of Object.entries(keyIds)) cases[name] = {
730
- ...actor,
731
- publicKey: {
732
- ...publicKey,
733
- id
734
- }
735
- };
736
- Object.assign(cases, {
737
- "a key owned by another actor": {
738
- ...actor,
739
- publicKey: {
740
- ...publicKey,
741
- owner: `ap://${otherDid}/actor`
742
- }
743
- },
744
- "a key controlled by another actor": {
745
- ...actor,
746
- assertionMethod: actor.assertionMethod.map((key) => ({
747
- ...key,
748
- controller: `ap://${otherDid}/actor`
749
- }))
750
- },
751
- "a key with extra content": {
752
- ...actor,
753
- publicKey: {
754
- ...publicKey,
755
- name: "Extra"
756
- }
757
- },
758
- "a key with a scoped context": {
759
- ...actor,
760
- publicKey: {
761
- ...publicKey,
762
- "@context": { CryptographicKey: {
763
- "@id": "https://w3id.org/security#Key",
764
- "@context": {}
765
- } }
766
- }
767
- }
768
- });
769
- for (const [name, document] of Object.entries(cases)) {
770
- const result = await verifyCompoundPortableObjectProofs(await signCompatible(document), limits, options);
771
- assert(result.status === "ok", name);
772
- assertEquals(result.verified, false, name);
773
- assert(result.portableObjects.find((o) => o.path === "")?.verified, name);
774
- assert(result.portableObjects.some((o) => o.path !== "" && !o.verified), name);
775
- }
776
- const conflicting = await verifyCompoundPortableObjectProofs(await signCompatible({
777
- ...actor,
778
- publicKey: {
779
- ...publicKey,
780
- "@id": `ap://${compatibleDid}/other#main-key`
781
- }
782
- }), limits, options);
783
- assert(conflicting.status === "ok");
784
- assertEquals(conflicting.verified, false);
785
- });
786
- test("verifyCompoundPortableObjectProofs() exempts ap: keys only of verified actors", async () => {
787
- const actor = withKeyIds(await compatibleActor(), apActorId, { id: apActorId });
788
- const signed = await signCompatible(actor);
789
- const unverified = {
790
- "": true,
791
- "/object": false,
792
- "/object/publicKey": false,
793
- "/object/assertionMethod/0": false
794
- };
795
- const cases = {
796
- "an unsigned actor": [actor, unverified],
797
- "a tampered actor": [{
798
- ...signed,
799
- name: "Tampered"
800
- }, unverified],
801
- "an actor with a key with an invalid proof": [await signCompatible({
802
- ...actor,
803
- publicKey: {
804
- ...asRecord(actor.publicKey),
805
- "@context": [...compatibleContext],
806
- proof: asRecord(signed.proof)
807
- }
808
- }), {
809
- "": true,
810
- "/object": true,
811
- "/object/publicKey": false
812
- }]
813
- };
814
- for (const [name, [object, expected]] of Object.entries(cases)) {
815
- const result = await verifyCompoundPortableObjectProofs(await signCompatible({
816
- "@context": [...compatibleContext],
817
- id: `ap://${compatibleDid}/activities/1`,
818
- type: "Update",
819
- actor: apActorId,
820
- object
821
- }), limits, options);
822
- assert(result.status === "ok", name);
823
- assertEquals(result.verified, false, name);
824
- assertEquals(Object.fromEntries(result.portableObjects.map((o) => [o.path, o.verified])), expected, name);
825
- }
826
- });
827
- test("verifyCompoundPortableObjectProofs() leaves keys at DID URLs alone", async () => {
828
- const result = await verifyCompoundPortableObjectProofs(await signCompatible(withKeyIds(await compatibleActor(), compatibleDid, { id: apActorId })), limits, options);
829
- assert(result.status === "ok");
830
- assert(result.verified);
831
- assertEquals(result.portableObjects.map((o) => o.path), [""]);
832
- });
833
- test("compound proof observation does not throw for malformed subject IDs", async () => {
834
- const { verificationObservation } = await import("../verification-C3954hQh.mjs");
835
- const evidence = { attempts: [] };
836
- const result = await verifyCompoundPortableObjectProofs({
837
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
838
- id: "ap://did%ZZkey/objects/1",
839
- type: "Note",
840
- proof: {}
841
- }, limits, {
842
- ...options,
843
- [verificationObservation]: evidence
844
- });
845
- assertEquals(result.status, "ok");
846
- assert(result.status === "ok" && !result.verified);
847
- assertEquals(evidence.attempts[0].subject.id, null);
848
- assertEquals(evidence.attempts[0].subject.pointer, "");
849
- });
850
- test("compound portable policy rejects actor gateways before key work", async () => {
851
- const { verificationObservation } = await import("../verification-C3954hQh.mjs");
852
- for (const gateways of [
853
- void 0,
854
- [],
855
- ["https://gw.example/path"],
856
- ["https://gw.example"]
857
- ]) {
858
- const inner = await secureRawDocument({
859
- "@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/data-integrity/v1"],
860
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
861
- type: "Person",
862
- inbox: "https://inner.example/inbox",
863
- outbox: "https://inner.example/outbox",
864
- ...gateways === void 0 ? {} : { gateways }
865
- }, map_local_create_note_default.keys.inner.testPrivateKeyJwk, map_local_create_note_default.keys.inner.verificationMethod);
866
- const outer = await secureRawDocument({
867
- ...map_local_create_note_default.documents.outerUnsecuredDocument,
868
- object: inner
869
- }, map_local_create_note_default.keys.outer.testPrivateKeyJwk, map_local_create_note_default.keys.outer.verificationMethod);
870
- const reads = [];
871
- const evidence = { attempts: [] };
872
- const result = await verifyCompoundPortableObjectProofs(outer, limits, {
873
- ...options,
874
- keyCache: {
875
- get(id) {
876
- reads.push(id.href);
877
- return Promise.resolve(void 0);
878
- },
879
- async set() {}
880
- },
881
- [verificationObservation]: evidence
882
- });
883
- assert(result.status === "ok");
884
- const valid = gateways?.[0] === "https://gw.example";
885
- assertEquals(result.verified, valid);
886
- assertEquals(reads.sort(), (valid ? [map_local_create_note_default.keys.inner.verificationMethod, map_local_create_note_default.keys.outer.verificationMethod] : [map_local_create_note_default.keys.outer.verificationMethod]).sort());
887
- assertEquals(result.proofs.map((p) => [p.path, p.verified]), [["/object", valid], ["", true]]);
888
- assertEquals(result.snapshot, outer);
889
- assert(Object.isFrozen(result.snapshot));
890
- assert(Object.isFrozen(result.proofs));
891
- assert(Object.isFrozen(result.portableObjects));
892
- const child = result.portableObjects[0];
893
- if (!valid) {
894
- assert(!child.verified);
895
- assertEquals(child.reason.type, "invalidGateways");
896
- assertEquals(result.proofs[0], {
897
- path: "/object",
898
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
899
- depth: 1,
900
- verified: false,
901
- reason: { type: "invalidProof" }
902
- });
903
- const attempt = evidence.attempts.find((a) => a.subject.pointer === "/object");
904
- assert(attempt?.status === "rejected");
905
- assertEquals(attempt.reason, {
906
- type: "proofPolicy",
907
- reason: { type: "invalidGateways" }
908
- });
909
- assertEquals(attempt.checks, []);
910
- }
911
- }
912
- });
913
- test("compound portable policy skips doomed proofs without pruning parents", async () => {
914
- const context = createInlineProofContext();
915
- const scoped = createInlineProofContext();
916
- scoped.proof = {
917
- "@id": "https://w3id.org/security#proof",
918
- "@context": { assertionMethod: "https://w3id.org/security#authentication" }
919
- };
920
- const cases = [
921
- {
922
- id: map_local_create_note_default.documents.outerUnsecuredDocument.id,
923
- type: "Note",
924
- method: map_local_create_note_default.keys.inner.verificationMethod,
925
- context,
926
- reason: "verificationMethodMismatch"
927
- },
928
- {
929
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
930
- type: "Note",
931
- method: "https://attacker.example/key",
932
- context,
933
- reason: "unsupportedVerificationMethod"
934
- },
935
- {
936
- id: "ap://did%ZZkey/objects/1",
937
- type: "Note",
938
- method: map_local_create_note_default.keys.inner.verificationMethod,
939
- context,
940
- reason: "invalidPortableObject"
941
- },
942
- {
943
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
944
- type: "Link",
945
- method: map_local_create_note_default.keys.inner.verificationMethod,
946
- context: {
947
- ...context,
948
- Link: "https://www.w3.org/ns/activitystreams#Link",
949
- href: {
950
- "@id": "https://www.w3.org/ns/activitystreams#href",
951
- "@type": "@id"
952
- }
953
- },
954
- extra: { href: "https://example.com/resource" },
955
- reason: "unsupportedObjectType"
956
- },
957
- {
958
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
959
- type: "Note",
960
- method: map_local_create_note_default.keys.inner.verificationMethod,
961
- context: scoped,
962
- reason: "invalidProof"
963
- },
964
- {
965
- id: map_local_create_note_default.documents.innerUnsecuredDocument.id,
966
- type: "Note",
967
- method: map_local_create_note_default.keys.inner.verificationMethod,
968
- context,
969
- extra: { "@id": "https://example.com/ordinary" },
970
- reason: "notPortableObject"
971
- }
972
- ];
973
- for (const candidate of cases) {
974
- const child = await secureRawDocument({
975
- "@context": candidate.context,
976
- id: candidate.id,
977
- type: candidate.type,
978
- ...candidate.extra,
979
- content: "Rejected attachment"
980
- }, map_local_create_note_default.keys.inner.testPrivateKeyJwk, candidate.method);
981
- if (candidate.context === scoped) delete asRecord(child.proof)["@context"];
982
- const parent = {
983
- ...map_local_create_note_default.documents.outerUnsecuredDocument,
984
- id: "https://social.example/activities/1",
985
- attachment: [child]
986
- };
987
- delete parent.object;
988
- const outer = await secureRawDocument(parent, map_local_create_note_default.keys.outer.testPrivateKeyJwk, map_local_create_note_default.keys.outer.verificationMethod);
989
- const reads = [];
990
- let loads = 0;
991
- const result = await verifyCompoundPortableObjectProofs(outer, limits, {
992
- ...options,
993
- documentLoader() {
994
- loads++;
995
- throw new TypeError("unexpected key fetch");
996
- },
997
- keyCache: {
998
- get(id) {
999
- reads.push(id.href);
1000
- return Promise.resolve(void 0);
1001
- },
1002
- async set() {}
1003
- }
1004
- });
1005
- assert(result.status === "ok");
1006
- assertEquals(result.verified, false);
1007
- assertEquals(reads, [map_local_create_note_default.keys.outer.verificationMethod]);
1008
- assertEquals(loads, 0);
1009
- assertEquals(result.proofs.map((p) => [p.path, p.verified]), [["/attachment/0", false], ["", true]]);
1010
- const [rejected] = result.portableObjects;
1011
- assert(!rejected.verified);
1012
- assertEquals(rejected.reason.type, candidate.reason);
1013
- assertEquals(rejected.path, "/attachment/0");
1014
- }
1015
- });
1016
- //#endregion
1017
- export {};