@fedify/fedify 2.2.20 → 2.2.21

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 (102) hide show
  1. package/dist/attachment-arrays-CalAATqD.mjs +16 -0
  2. package/dist/{builder-BolQ56ab.mjs → builder-4ImvtjG4.mjs} +3 -3
  3. package/dist/callback-0KrwzutD.d.mts +2607 -0
  4. package/dist/{client-jE7oGvRh.d.ts → client-9DPcy_Yx.d.ts} +16 -0
  5. package/dist/{client-BIBzqEIp.d.cts → client-B3ruDgWg.d.cts} +16 -0
  6. package/dist/{client-DhxaVgOv.mjs → client-XYMC0Mmk.mjs} +86 -11
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.d.cts +1 -1
  10. package/dist/compat/mod.d.ts +1 -1
  11. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  12. package/dist/compat/public-audience.test.mjs +1 -1
  13. package/dist/compat/transformers.test.mjs +1 -1
  14. package/dist/{context-CFQGaq5x.d.cts → context-CjWuov0g.d.cts} +31 -14
  15. package/dist/{context-DdbLVV_k.d.ts → context-DZqI2LJD.d.ts} +31 -14
  16. package/dist/{deno-BUj4roJc.mjs → deno-AWk3S2Ug.mjs} +1 -1
  17. package/dist/{docloader-CbtF_0cD.mjs → docloader-Bogpjg4d.mjs} +2 -2
  18. package/dist/federation/attachment-responses.test.d.mts +2 -0
  19. package/dist/federation/attachment-responses.test.mjs +182 -0
  20. package/dist/federation/builder.test.mjs +1 -1
  21. package/dist/federation/collection.test.mjs +1 -1
  22. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  23. package/dist/federation/delivery-attachments.test.mjs +288 -0
  24. package/dist/federation/handler.test.mjs +208 -16
  25. package/dist/federation/idempotency.test.mjs +2 -2
  26. package/dist/federation/inbox.test.mjs +2 -2
  27. package/dist/federation/middleware.test.mjs +1184 -8
  28. package/dist/federation/mod.cjs +1 -1
  29. package/dist/federation/mod.d.cts +2 -2
  30. package/dist/federation/mod.d.ts +2 -2
  31. package/dist/federation/mod.js +1 -1
  32. package/dist/federation/negotiation.test.mjs +1 -1
  33. package/dist/federation/retry.test.mjs +1 -1
  34. package/dist/federation/send.test.mjs +283 -3
  35. package/dist/federation/temporal.test.mjs +25 -1
  36. package/dist/federation/webfinger.test.mjs +1 -1
  37. package/dist/{http-CQMVisM0.mjs → http-B3wCvgu8.mjs} +6 -4
  38. package/dist/{http-D8I7LBfx.cjs → http-BNaPJVnF.cjs} +6 -4
  39. package/dist/{http-C5g_VrA_.js → http-BpdLaGy8.js} +6 -4
  40. package/dist/{http-9IFUxdkp.d.cts → http-C8qLHs_Z.d.cts} +3 -3
  41. package/dist/{http-SbfezERn.d.ts → http-D8WmcRAF.d.ts} +3 -3
  42. package/dist/{inbox-CD8IDILN.mjs → inbox-DLy6WBXU.mjs} +1 -1
  43. package/dist/{key-C3o3DGap.mjs → key-Bhc8cQC7.mjs} +3 -2
  44. package/dist/{kv-cache-DC9LcfoC.cjs → kv-cache-Bj3CY9Jo.cjs} +1 -1
  45. package/dist/{kv-cache-CSKXXleR.js → kv-cache-CvjLUQTf.js} +1 -1
  46. package/dist/{ld-ijSr-0AB.mjs → ld-DTeykI0e.mjs} +153 -21
  47. package/dist/ld-signature-Dgz_b89j.mjs +23 -0
  48. package/dist/{middleware-DNueR0GD.cjs → middleware-BSQP4d9p.cjs} +475 -107
  49. package/dist/{middleware-DmcY2TWS.cjs → middleware-CWOzxb3o.cjs} +1 -1
  50. package/dist/{middleware-yqqfI7oJ.mjs → middleware-DkMsC5mQ.mjs} +1 -1
  51. package/dist/{middleware-sjhz30sm.js → middleware-Dx1iwFk8.js} +474 -107
  52. package/dist/{middleware-CYAaUTi5.mjs → middleware-dlGvSrXl.mjs} +386 -96
  53. package/dist/{mod-BYWp77-z.d.cts → mod-BmxqcEnU.d.ts} +30 -13
  54. package/dist/{mod-CVSKw-5H.d.cts → mod-DWEx2D4q.d.cts} +1 -1
  55. package/dist/{mod-BuRRdsfD.d.ts → mod-DnPmz3-S.d.ts} +1 -1
  56. package/dist/{mod-CM5_J_cx.d.ts → mod-INjDw-m0.d.cts} +30 -13
  57. package/dist/{mod-BRnwh2oy.d.ts → mod-REfljt0T.d.ts} +3 -3
  58. package/dist/{mod-Co7LEK9X.d.cts → mod-UvIGUHqW.d.cts} +3 -3
  59. package/dist/mod.cjs +5 -5
  60. package/dist/mod.d.cts +8 -8
  61. package/dist/mod.d.ts +8 -8
  62. package/dist/mod.js +5 -5
  63. package/dist/nodeinfo/client.test.mjs +432 -4
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/nodeinfo/mod.cjs +1 -1
  66. package/dist/nodeinfo/mod.d.cts +1 -1
  67. package/dist/nodeinfo/mod.d.ts +1 -1
  68. package/dist/nodeinfo/mod.js +1 -1
  69. package/dist/nodeinfo/types.test.mjs +1 -1
  70. package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
  71. package/dist/{owner-B8kXzD0q.mjs → owner-BsA7qMHB.mjs} +2 -2
  72. package/dist/{proof-CBQOjOgA.mjs → proof-C63Hqt9N.mjs} +40 -15
  73. package/dist/{proof-qiuGJCD7.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
  74. package/dist/{proof-DKX6nASL.js → proof-QV_o5ZqS.js} +1174 -1003
  75. package/dist/{send-DRpisX_f.mjs → send-CAdpwbFX.mjs} +92 -21
  76. package/dist/sig/http.test.mjs +2 -2
  77. package/dist/sig/key-types.test.d.mts +218 -0
  78. package/dist/sig/key-types.test.mjs +8 -0
  79. package/dist/sig/key.test.mjs +2 -2
  80. package/dist/sig/ld.test.mjs +573 -8
  81. package/dist/sig/mod.cjs +2 -2
  82. package/dist/sig/mod.d.cts +3 -3
  83. package/dist/sig/mod.d.ts +3 -3
  84. package/dist/sig/mod.js +2 -2
  85. package/dist/sig/owner.test.mjs +1 -1
  86. package/dist/sig/proof.test.mjs +96 -4
  87. package/dist/{temporal-BQGEINad.mjs → temporal-B3JGkVgk.mjs} +3 -5
  88. package/dist/testing/mod.d.mts +2 -2422
  89. package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
  90. package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
  91. package/dist/utils/docloader.test.mjs +2 -2
  92. package/dist/utils/mod.cjs +1 -1
  93. package/dist/utils/mod.d.cts +1 -1
  94. package/dist/utils/mod.d.ts +1 -1
  95. package/dist/utils/mod.js +1 -1
  96. package/package.json +5 -5
  97. /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
  98. /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
  99. /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
  100. /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
  101. /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
  102. /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
@@ -1,12 +1,13 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-BUj4roJc.mjs";
5
- import { r as fetchKey, s as validateCryptoKey } from "./key-C3o3DGap.mjs";
6
- import { n as preloadedOnlyDocumentLoader } from "./public-audience-DpJqzPuh.mjs";
7
- import { r as normalizeOutgoingActivityJsonLd } from "./outgoing-jsonld-amccRMrV.mjs";
4
+ import { n as version, t as name } from "./deno-AWk3S2Ug.mjs";
5
+ import { r as fetchKey, s as validateCryptoKey } from "./key-Bhc8cQC7.mjs";
6
+ import { n as preloadedOnlyDocumentLoader } from "./public-audience-4g3_Ze4y.mjs";
7
+ import { r as normalizeOutgoingActivityJsonLd } from "./outgoing-jsonld-DHf_DYXp.mjs";
8
8
  import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
9
9
  import { SpanStatusCode, trace } from "@opentelemetry/api";
10
+ import { asCryptoKey } from "@fedify/vocab-runtime/internal";
10
11
  import { getLogger } from "@logtape/logtape";
11
12
  import { encodeHex } from "byte-encodings/hex";
12
13
  import serialize from "json-canon";
@@ -55,7 +56,10 @@ function hasProofLike(jsonLd) {
55
56
  * @throws {TypeError} If the private key is invalid or unsupported.
56
57
  * @since 0.10.0
57
58
  */
58
- async function createProof(object, privateKey, keyId, { contextLoader, context, created } = {}) {
59
+ async function createProof(object, privateKey, keyId, options = {}) {
60
+ return (await createProofInternal(object, privateKey, keyId, options)).proof;
61
+ }
62
+ async function createProofInternal(object, privateKey, keyId, { contextLoader, context, created } = {}) {
59
63
  validateCryptoKey(privateKey, "private");
60
64
  if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
61
65
  let compactMsg = await object.clone({ proofs: [] }).toJsonLd({
@@ -82,14 +86,26 @@ async function createProof(object, privateKey, keyId, { contextLoader, context,
82
86
  const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
83
87
  digest.set(new Uint8Array(proofDigest), 0);
84
88
  digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
85
- const sig = await crypto.subtle.sign("Ed25519", privateKey, digest);
86
- return new DataIntegrityProof({
87
- cryptosuite: "eddsa-jcs-2022",
88
- verificationMethod: keyId,
89
- proofPurpose: "assertionMethod",
90
- created: created ?? Temporal.Now.instant(),
91
- proofValue: new Uint8Array(sig)
92
- });
89
+ const sig = await crypto.subtle.sign("Ed25519", asCryptoKey(privateKey), digest);
90
+ return {
91
+ proof: new DataIntegrityProof({
92
+ cryptosuite: "eddsa-jcs-2022",
93
+ verificationMethod: keyId,
94
+ proofPurpose: "assertionMethod",
95
+ created: created ?? Temporal.Now.instant(),
96
+ proofValue: new Uint8Array(sig)
97
+ }),
98
+ jsonLd: compactMsg
99
+ };
100
+ }
101
+ function getJsonLdContextKey(value) {
102
+ const context = typeof value === "object" && value != null && !Array.isArray(value) ? value["@context"] ?? null : null;
103
+ return JSON.stringify(sortJsonKeys(context));
104
+ }
105
+ function sortJsonKeys(value) {
106
+ if (Array.isArray(value)) return value.map(sortJsonKeys);
107
+ if (typeof value !== "object" || value == null) return value;
108
+ return globalThis.Object.fromEntries(globalThis.Object.entries(value).sort(([a], [b]) => a < b ? -1 : a > b ? 1 : 0).map(([key, item]) => [key, sortJsonKeys(item)]));
93
109
  }
94
110
  /**
95
111
  * Signs the given object with the private key and returns the signed object.
@@ -105,9 +121,18 @@ async function signObject(object, privateKey, keyId, options = {}) {
105
121
  return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("object_integrity_proofs.sign", { attributes: { "activitypub.object.type": getTypeId(object).href } }, async (span) => {
106
122
  try {
107
123
  if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
124
+ const { proof, jsonLd } = await createProofInternal(object, privateKey, keyId, options);
108
125
  const existingProofs = [];
109
- for await (const proof of object.getProofs(options)) existingProofs.push(proof);
110
- const proof = await createProof(object, privateKey, keyId, options);
126
+ let hasProofs = object.proofIds.length > 0;
127
+ if (!hasProofs) for await (const _ of object.getProofs(options)) {
128
+ hasProofs = true;
129
+ break;
130
+ }
131
+ if (hasProofs) {
132
+ let sameContext = true;
133
+ if (options.context == null) sameContext = getJsonLdContextKey(await object.toJsonLd({ contextLoader: options.contextLoader })) === getJsonLdContextKey(jsonLd);
134
+ if (sameContext) for await (const existingProof of object.getProofs(options)) existingProofs.push(existingProof);
135
+ }
111
136
  if (span.isRecording()) {
112
137
  if (proof.cryptosuite != null) span.setAttribute("object_integrity_proofs.cryptosuite", proof.cryptosuite);
113
138
  if (proof.verificationMethodId != null) span.setAttribute("object_integrity_proofs.key_id", proof.verificationMethodId.href);