@fedify/fedify 2.2.19 → 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.
- package/dist/attachment-arrays-CalAATqD.mjs +16 -0
- package/dist/{builder-UmydCxtK.mjs → builder-4ImvtjG4.mjs} +3 -3
- package/dist/callback-0KrwzutD.d.mts +2607 -0
- package/dist/{client-CSddvgWN.d.ts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CAM_bQXx.d.cts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-9F_u23dc.mjs → client-XYMC0Mmk.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-tJbL_Hkw.d.cts → context-CjWuov0g.d.cts} +57 -14
- package/dist/{context-OkwEpc3-.d.ts → context-DZqI2LJD.d.ts} +57 -14
- package/dist/{deno-CD-8UlUi.mjs → deno-AWk3S2Ug.mjs} +1 -1
- package/dist/docloader-Bogpjg4d.mjs +125 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1567 -30
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-BBBUbwKh.mjs → http-B3wCvgu8.mjs} +199 -99
- package/dist/{http-DrUG4fPS.cjs → http-BNaPJVnF.cjs} +178 -107
- package/dist/{http-DJK2udgX.js → http-BpdLaGy8.js} +177 -106
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{inbox-Dca_0fwc.mjs → inbox-DLy6WBXU.mjs} +1 -1
- package/dist/{key-DolXUaLH.mjs → key-Bhc8cQC7.mjs} +3 -2
- package/dist/{kv-cache-Bk3V1Tiu.cjs → kv-cache-Bj3CY9Jo.cjs} +59 -17
- package/dist/{kv-cache-DDm80t1K.js → kv-cache-CvjLUQTf.js} +60 -18
- package/dist/{ld-rTdIfZ63.mjs → ld-DTeykI0e.mjs} +153 -21
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{middleware-BWOwEGpy.cjs → middleware-BSQP4d9p.cjs} +642 -149
- package/dist/{middleware-B4-Rzdi3.cjs → middleware-CWOzxb3o.cjs} +1 -1
- package/dist/{middleware-DYK_res8.mjs → middleware-DkMsC5mQ.mjs} +1 -1
- package/dist/{middleware-BimXKBcP.js → middleware-Dx1iwFk8.js} +641 -149
- package/dist/{middleware-CpXoRHs3.mjs → middleware-dlGvSrXl.mjs} +452 -122
- package/dist/{mod-D2JyWtW3.d.cts → mod-BmxqcEnU.d.ts} +30 -13
- package/dist/{mod-a6kmB8xD.d.cts → mod-DWEx2D4q.d.cts} +1 -1
- package/dist/{mod-DQGjRJUG.d.ts → mod-DnPmz3-S.d.ts} +1 -1
- package/dist/{mod-ej_rLx8h.d.ts → mod-INjDw-m0.d.cts} +30 -13
- package/dist/{mod-B6LmugJ4.d.ts → mod-REfljt0T.d.ts} +4 -10
- package/dist/{mod-V2vDnYNu.d.cts → mod-UvIGUHqW.d.cts} +4 -10
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +764 -18
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
- package/dist/{owner-CVfzyM5V.mjs → owner-BsA7qMHB.mjs} +2 -2
- package/dist/{proof-gOGM-sJS.mjs → proof-C63Hqt9N.mjs} +40 -15
- package/dist/{proof-DhaTTn-P.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
- package/dist/{proof-CaQ4KG6y.js → proof-QV_o5ZqS.js} +1174 -1003
- package/dist/send-CAdpwbFX.mjs +416 -0
- package/dist/sig/http.test.mjs +528 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +96 -4
- package/dist/{temporal-CA4Y9hBJ.mjs → temporal-B3JGkVgk.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2396
- package/dist/{types-DRPjmHVV.cjs → types-BWx7zw3Y.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-Dx_w2JSM.js} +188 -64
- package/dist/utils/docloader.test.mjs +318 -34
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -6
- package/dist/docloader-D1ghurDJ.mjs +0 -83
- package/dist/send-D35Va72B.mjs +0 -260
- /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
- /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as preloadedOnlyDocumentLoader, t as normalizePublicAudience } from "./public-audience-
|
|
4
|
+
import { n as preloadedOnlyDocumentLoader, t as normalizePublicAudience } from "./public-audience-4g3_Ze4y.mjs";
|
|
5
5
|
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
6
6
|
import { getLogger } from "@logtape/logtape";
|
|
7
7
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
@@ -166,38 +166,68 @@ function getLogSafeJsonLdMetadata(jsonLd) {
|
|
|
166
166
|
* the semantic-preservation check to succeed; otherwise canonicalization
|
|
167
167
|
* failures leave the original document unchanged.
|
|
168
168
|
*/
|
|
169
|
-
async function normalizeAttachmentArrays(jsonLd, contextLoader) {
|
|
169
|
+
async function normalizeAttachmentArrays(jsonLd, contextLoader, preserveSecured = false) {
|
|
170
170
|
const normalized = wrapScalarAttachments(jsonLd);
|
|
171
171
|
if (normalized === jsonLd) return jsonLd;
|
|
172
172
|
if (exceedsTraversalDepth(jsonLd)) {
|
|
173
173
|
logger.debug("Skipping attachment array normalization because the JSON-LD document exceeds the safe traversal depth; leaving it unchanged.");
|
|
174
174
|
return jsonLd;
|
|
175
175
|
}
|
|
176
|
-
|
|
177
|
-
const
|
|
176
|
+
const sourceLoader = contextLoader ?? preloadedOnlyDocumentLoader;
|
|
177
|
+
const pending = /* @__PURE__ */ new Map();
|
|
178
|
+
const loader = (url, options) => {
|
|
179
|
+
let result = pending.get(url);
|
|
180
|
+
if (result == null) {
|
|
181
|
+
result = sourceLoader(url, options);
|
|
182
|
+
pending.set(url, result);
|
|
183
|
+
}
|
|
184
|
+
return result;
|
|
185
|
+
};
|
|
178
186
|
try {
|
|
179
|
-
|
|
187
|
+
if (preserveSecured) {
|
|
188
|
+
if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: loader }))) return jsonLd;
|
|
189
|
+
}
|
|
190
|
+
if (!preserveSecured && hasKnownSafeContext(jsonLd)) return normalized;
|
|
191
|
+
const [before, after] = await Promise.allSettled([jsonld.canonize(jsonLd, {
|
|
180
192
|
format: "application/n-quads",
|
|
181
193
|
documentLoader: loader
|
|
182
194
|
}), jsonld.canonize(normalized, {
|
|
183
195
|
format: "application/n-quads",
|
|
184
196
|
documentLoader: loader
|
|
185
197
|
})]);
|
|
186
|
-
if (before ===
|
|
198
|
+
if (before.status === "rejected") throw before.reason;
|
|
199
|
+
if (after.status === "rejected") throw after.reason;
|
|
200
|
+
if (before.value === after.value) return normalized;
|
|
187
201
|
logger.warn("Wrapping scalar attachment values in arrays would change the canonical form of the JSON-LD document; leaving it unchanged. This usually means the active JSON-LD context redefines the `attachment` term. Document: {id}; type: {type}; context: {context}.", getLogSafeJsonLdMetadata(jsonLd));
|
|
188
202
|
} catch (error) {
|
|
189
203
|
logger.debug("Failed to verify attachment array normalization equivalence via JSON-LD canonicalization; leaving the JSON-LD document unchanged.\n{error}", { error });
|
|
190
204
|
}
|
|
191
205
|
return jsonLd;
|
|
192
206
|
}
|
|
207
|
+
function hasSecurityPredicate(value) {
|
|
208
|
+
if (Array.isArray(value)) return value.some(hasSecurityPredicate);
|
|
209
|
+
if (typeof value !== "object" || value == null) return false;
|
|
210
|
+
const record = value;
|
|
211
|
+
if (Object.hasOwn(record, "@value")) return false;
|
|
212
|
+
for (const [key, child] of Object.entries(record)) {
|
|
213
|
+
if (key === "https://w3id.org/security#proof" || key === "https://w3id.org/security#signature") return true;
|
|
214
|
+
if (hasSecurityPredicate(child)) return true;
|
|
215
|
+
}
|
|
216
|
+
return false;
|
|
217
|
+
}
|
|
193
218
|
/**
|
|
194
219
|
* Applies Fedify's internal JSON-LD wire-format interoperability workarounds
|
|
195
220
|
* to locally generated outgoing activities before they are signed, enqueued,
|
|
196
221
|
* or sent.
|
|
197
222
|
*/
|
|
198
|
-
async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader) {
|
|
223
|
+
async function normalizeOutgoingActivityJsonLd(jsonLd, contextLoader, preserveSecured = false) {
|
|
224
|
+
if (preserveSecured) try {
|
|
225
|
+
if (hasSecurityPredicate(await jsonld.expand(jsonLd, { documentLoader: contextLoader ?? preloadedOnlyDocumentLoader }))) return jsonLd;
|
|
226
|
+
} catch {
|
|
227
|
+
return jsonLd;
|
|
228
|
+
}
|
|
199
229
|
jsonLd = await normalizePublicAudience(jsonLd, contextLoader);
|
|
200
|
-
return await normalizeAttachmentArrays(jsonLd, contextLoader);
|
|
230
|
+
return await normalizeAttachmentArrays(jsonLd, contextLoader, preserveSecured);
|
|
201
231
|
}
|
|
202
232
|
//#endregion
|
|
203
233
|
export { normalizeAttachmentArrays as n, normalizeOutgoingActivityJsonLd as r, isPreloadedContextAttachmentSafe as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-AWk3S2Ug.mjs";
|
|
5
|
+
import { c as verifyKeyOwnership, n as fetchActorDocument, t as exportJwk } from "./key-Bhc8cQC7.mjs";
|
|
6
6
|
import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
7
7
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
8
|
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
@@ -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-
|
|
5
|
-
import { r as fetchKey, s as validateCryptoKey } from "./key-
|
|
6
|
-
import { n as preloadedOnlyDocumentLoader } from "./public-audience-
|
|
7
|
-
import { r as normalizeOutgoingActivityJsonLd } from "./outgoing-jsonld-
|
|
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,
|
|
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
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
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
|
-
|
|
110
|
-
|
|
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);
|