@fedify/fedify 2.3.0-dev.1145 → 2.3.0-dev.1150
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/{builder-ShiR1K6b.mjs → builder-Bjm1Jq9n.mjs} +2 -2
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-DI2gRbyN.d.cts → context-CRXCkTM6.d.cts} +48 -6
- package/dist/{context-DCtsSHDv.d.ts → context-MgCh7YGu.d.ts} +48 -6
- package/dist/{deno-h0TWFuEz.mjs → deno-CKFE6Uya.mjs} +1 -1
- package/dist/{docloader-BdDN0Aqx.mjs → docloader-B-ZE1cZf.mjs} +2 -2
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +1363 -44
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1667 -163
- 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/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +8 -8
- package/dist/federation/temporal.test.d.mts +2 -0
- package/dist/federation/temporal.test.mjs +71 -0
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{getMachineId-bsd-etIyxDet.mjs → getMachineId-bsd-BY01PL1n.mjs} +1 -1
- package/dist/{getMachineId-darwin-D23zTf4g.mjs → getMachineId-darwin-Dr1gkBkp.mjs} +1 -1
- package/dist/{getMachineId-win-Dpap6v5i.mjs → getMachineId-win-QEYwcJiy.mjs} +1 -1
- package/dist/{http-7kAB7PVx.cjs → http-DQYEA7AZ.cjs} +1 -1
- package/dist/{http-B2hxA7dO.js → http-WbS1gKzr.js} +1 -1
- package/dist/{http-QzW9IWfs.mjs → http-vHCgbhTg.mjs} +3 -3
- package/dist/{key-Dh2OK1XQ.mjs → key-N0zP_oJA.mjs} +2 -2
- package/dist/{kv-cache-b22dNkjt.js → kv-cache-DM2O-Yjy.js} +1 -1
- package/dist/{kv-cache-DCPp-MT0.cjs → kv-cache-Dsg_bi4N.cjs} +1 -1
- package/dist/{kv-cache-EZRIPZXD.mjs → kv-cache-GXXZEemD.mjs} +1 -1
- package/dist/{ld-eZbar1rr.mjs → ld-BwKhquPx.mjs} +302 -6
- package/dist/{metrics-E0hAHtLZ.mjs → metrics-7Vy9FvEw.mjs} +1 -1
- package/dist/{middleware-BrGIM_Ra.js → middleware-BscgvU-m.js} +428 -99
- package/dist/{middleware-BUl1BH4x.cjs → middleware-D_iXrYHJ.cjs} +429 -99
- package/dist/{middleware-mToCR2tG.mjs → middleware-Db1_qAFG.mjs} +1 -1
- package/dist/{middleware-CyJDCmNg.mjs → middleware-ZuUcO0t1.mjs} +348 -108
- package/dist/{mod-CI9fduEi.d.cts → mod-C7HOzGqH.d.cts} +1 -1
- package/dist/{mod-CkRiJHGA.d.ts → mod-CpQHB3Ys.d.ts} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.d.cts +2 -2
- package/dist/mod.d.ts +2 -2
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/{owner-ByO_Fw6U.mjs → owner-FD0H_vpj.mjs} +2 -2
- package/dist/{proof-jVqClF49.cjs → proof-CYK8T8IS.cjs} +353 -3
- package/dist/{proof-BkRyFchv.js → proof-I3EokKN-.js} +300 -4
- package/dist/{proof-CSo0S8OK.mjs → proof-V_lafPmA.mjs} +3 -3
- package/dist/{send-jzrTV1FU.mjs → send-Cc2_10tF.mjs} +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +558 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +1 -1
- package/dist/temporal-BkmBfs__.mjs +95 -0
- package/dist/testing/mod.d.mts +48 -6
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +7 -7
- /package/dist/{execAsync-DCBrgFiV.mjs → execAsync-Dxb7rNf3.mjs} +0 -0
- /package/dist/{getMachineId-linux-ObI47Hql.mjs → getMachineId-linux-Bbhofx-s.mjs} +0 -0
- /package/dist/{getMachineId-unsupported-Ddu-PFeh.mjs → getMachineId-unsupported-dIOte2Ct.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-_VvV0h9f.mjs} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { O as name, _ as measureSignatureKeyFetch, d as validateCryptoKey, f as getDurationMs, k as version, p as getFederationMetrics, s as fetchKey } from "./http-
|
|
3
|
+
import { O as name, _ as measureSignatureKeyFetch, d as validateCryptoKey, f as getDurationMs, k as version, p as getFederationMetrics, s as fetchKey } from "./http-WbS1gKzr.js";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, PUBLIC_COLLECTION, getTypeId, isActor } from "@fedify/vocab";
|
|
6
6
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -15,6 +15,290 @@ const logger$3 = getLogger([
|
|
|
15
15
|
"sig",
|
|
16
16
|
"ld"
|
|
17
17
|
]);
|
|
18
|
+
const localContext = [
|
|
19
|
+
"https://w3id.org/identity/v1",
|
|
20
|
+
"https://www.w3.org/ns/activitystreams",
|
|
21
|
+
"https://w3id.org/security/v1",
|
|
22
|
+
"https://w3id.org/security/data-integrity/v1"
|
|
23
|
+
];
|
|
24
|
+
const localContextUrls = new Set(localContext);
|
|
25
|
+
const builtInContextLoader = getDocumentLoader();
|
|
26
|
+
const disallowedJsonLdKeywords = new Set([
|
|
27
|
+
"@graph",
|
|
28
|
+
"@included",
|
|
29
|
+
"@reverse"
|
|
30
|
+
]);
|
|
31
|
+
/** @internal */
|
|
32
|
+
var UnsafeJsonLdError = class extends TypeError {
|
|
33
|
+
keyword;
|
|
34
|
+
constructor(keyword) {
|
|
35
|
+
super(`Unsupported JSON-LD keyword: ${keyword}.`);
|
|
36
|
+
this.keyword = keyword;
|
|
37
|
+
this.name = "UnsafeJsonLdError";
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
/** @internal */
|
|
41
|
+
var InvalidContextReferenceError = class extends TypeError {
|
|
42
|
+
reference;
|
|
43
|
+
constructor(reference) {
|
|
44
|
+
super(`Invalid JSON-LD context reference: ${reference}.`);
|
|
45
|
+
this.reference = reference;
|
|
46
|
+
this.name = "InvalidContextReferenceError";
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
function createLoadingRemoteContextFailedError(reference, cause) {
|
|
50
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
51
|
+
const error = /* @__PURE__ */ new Error(`Dereferencing a URL did not result in a valid JSON-LD context: ${reference}. ${message}`);
|
|
52
|
+
error.name = "jsonld.InvalidUrl";
|
|
53
|
+
error.details = {
|
|
54
|
+
code: "loading remote context failed",
|
|
55
|
+
url: reference
|
|
56
|
+
};
|
|
57
|
+
error.cause = cause;
|
|
58
|
+
return error;
|
|
59
|
+
}
|
|
60
|
+
/** @internal */
|
|
61
|
+
function isClearlyMalformedContextReference(reference) {
|
|
62
|
+
for (const char of reference) {
|
|
63
|
+
const code = char.charCodeAt(0);
|
|
64
|
+
if (code <= 32 || code === 127) return true;
|
|
65
|
+
}
|
|
66
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(reference) && !URL.canParse(reference)) return true;
|
|
67
|
+
for (let i = 0; i < reference.length; i++) {
|
|
68
|
+
if (reference[i] !== "%") continue;
|
|
69
|
+
if (i + 2 >= reference.length || !/[0-9A-Fa-f]/.test(reference[i + 1]) || !/[0-9A-Fa-f]/.test(reference[i + 2])) return true;
|
|
70
|
+
i += 2;
|
|
71
|
+
}
|
|
72
|
+
if (reference.startsWith("./") || reference.startsWith("../") || reference.startsWith("/") || reference.startsWith("//")) {
|
|
73
|
+
for (const char of reference) if ("[]<>\"\\^`{|}".includes(char)) return true;
|
|
74
|
+
}
|
|
75
|
+
return false;
|
|
76
|
+
}
|
|
77
|
+
function cloneRemoteDocument(remoteDocument) {
|
|
78
|
+
return structuredClone(remoteDocument);
|
|
79
|
+
}
|
|
80
|
+
function createMemoizedDocumentLoader(documentLoader) {
|
|
81
|
+
const cache = /* @__PURE__ */ new Map();
|
|
82
|
+
return async (url, options) => {
|
|
83
|
+
const cacheKey = URL.canParse(url) ? new URL(url).href : url;
|
|
84
|
+
let remoteDocument = cache.get(cacheKey);
|
|
85
|
+
if (remoteDocument == null) {
|
|
86
|
+
remoteDocument = Promise.resolve(documentLoader(url, options)).then(cloneRemoteDocument);
|
|
87
|
+
remoteDocument.catch(() => {
|
|
88
|
+
if (cache.get(cacheKey) === remoteDocument) cache.delete(cacheKey);
|
|
89
|
+
});
|
|
90
|
+
cache.set(cacheKey, remoteDocument);
|
|
91
|
+
}
|
|
92
|
+
return cloneRemoteDocument(await remoteDocument);
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
/** @internal */
|
|
96
|
+
function wrapContextLoaderForJsonLd(contextLoader) {
|
|
97
|
+
const loader = contextLoader ?? builtInContextLoader;
|
|
98
|
+
return async (url, options) => {
|
|
99
|
+
try {
|
|
100
|
+
return await loader(url, options);
|
|
101
|
+
} catch (error) {
|
|
102
|
+
if (!isInvalidUrlTypeError(error)) throw error;
|
|
103
|
+
if (isClearlyMalformedContextReference(url)) throw new InvalidContextReferenceError(url);
|
|
104
|
+
throw createLoadingRemoteContextFailedError(url, error);
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
/** @internal */
|
|
109
|
+
function getNormalizationContextLoader(contextLoader) {
|
|
110
|
+
const loader = wrapContextLoaderForJsonLd(contextLoader);
|
|
111
|
+
return createMemoizedDocumentLoader(async (url, options) => {
|
|
112
|
+
if (URL.canParse(url)) {
|
|
113
|
+
const normalizedUrl = new URL(url).href;
|
|
114
|
+
if (localContextUrls.has(normalizedUrl)) return await builtInContextLoader(normalizedUrl, options);
|
|
115
|
+
}
|
|
116
|
+
return await loader(url, options);
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
/** @internal */
|
|
120
|
+
async function compactJsonLd(jsonLd, contextLoader) {
|
|
121
|
+
const hasLds = typeof jsonLd === "object" && jsonLd != null && "signature" in jsonLd;
|
|
122
|
+
const signature = hasLds ? jsonLd.signature : void 0;
|
|
123
|
+
const normalizationContextLoader = getNormalizationContextLoader(contextLoader);
|
|
124
|
+
const document = hasLds ? detachSignature(jsonLd) : jsonLd;
|
|
125
|
+
await assertNoGraphBeforeCompaction(document, normalizationContextLoader);
|
|
126
|
+
const compacted = await jsonld.compact(document, localContext, { documentLoader: normalizationContextLoader });
|
|
127
|
+
if (hasLds && typeof compacted === "object" && compacted != null) compacted.signature = signature;
|
|
128
|
+
assertSafeJsonLd(compacted);
|
|
129
|
+
return compacted;
|
|
130
|
+
}
|
|
131
|
+
function createInvalidRemoteContextError(reference) {
|
|
132
|
+
const error = /* @__PURE__ */ new Error(`Dereferencing a URL did not result in a JSON object. The response was valid JSON, but it was not a JSON object. URL: "${reference}".`);
|
|
133
|
+
error.name = "jsonld.InvalidUrl";
|
|
134
|
+
error.details = {
|
|
135
|
+
code: "invalid remote context",
|
|
136
|
+
url: reference
|
|
137
|
+
};
|
|
138
|
+
return error;
|
|
139
|
+
}
|
|
140
|
+
function getRemoteContext(remoteDocument, reference) {
|
|
141
|
+
const { contextUrl, documentUrl } = remoteDocument;
|
|
142
|
+
let { document } = remoteDocument;
|
|
143
|
+
if (typeof document === "string") document = JSON.parse(document);
|
|
144
|
+
if (typeof document !== "object" || document == null || Array.isArray(document)) throw createInvalidRemoteContextError(reference);
|
|
145
|
+
let context = "@context" in document ? document["@context"] : {};
|
|
146
|
+
if (contextUrl != null) context = Array.isArray(context) ? [...context, contextUrl] : [context, contextUrl];
|
|
147
|
+
return {
|
|
148
|
+
context,
|
|
149
|
+
baseUrl: documentUrl ?? reference
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
function createGraphAliasContextState() {
|
|
153
|
+
return {
|
|
154
|
+
graphTerms: /* @__PURE__ */ new Set(),
|
|
155
|
+
jsonTerms: /* @__PURE__ */ new Set(),
|
|
156
|
+
propertyContexts: /* @__PURE__ */ new Map(),
|
|
157
|
+
termTargets: /* @__PURE__ */ new Map()
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
function cloneGraphAliasContextState(state) {
|
|
161
|
+
return {
|
|
162
|
+
graphTerms: new Set(state.graphTerms),
|
|
163
|
+
jsonTerms: new Set(state.jsonTerms),
|
|
164
|
+
propertyContexts: new Map(state.propertyContexts),
|
|
165
|
+
termTargets: new Map(state.termTargets)
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function resolveContextTarget(target, state) {
|
|
169
|
+
if (target === "@graph") return target;
|
|
170
|
+
const mapped = state.termTargets.get(target);
|
|
171
|
+
if (mapped == null) return target;
|
|
172
|
+
return mapped;
|
|
173
|
+
}
|
|
174
|
+
function getDirectContextTarget(definition) {
|
|
175
|
+
if (definition === null) return null;
|
|
176
|
+
if (typeof definition === "string") return definition;
|
|
177
|
+
if (typeof definition === "object" && definition != null && "@id" in definition) {
|
|
178
|
+
const id = definition["@id"];
|
|
179
|
+
if (id === null) return null;
|
|
180
|
+
if (typeof id === "string") return id;
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
function isJsonTypedDefinition(definition) {
|
|
184
|
+
return typeof definition === "object" && definition != null && "@type" in definition && definition["@type"] === "@json";
|
|
185
|
+
}
|
|
186
|
+
function resolveLocalContextTarget(target, state, localTargets, seen = /* @__PURE__ */ new Set()) {
|
|
187
|
+
if (target === "@graph") return target;
|
|
188
|
+
if (seen.has(target)) return target;
|
|
189
|
+
seen.add(target);
|
|
190
|
+
if (localTargets.has(target)) {
|
|
191
|
+
const localTarget = localTargets.get(target);
|
|
192
|
+
return localTarget == null ? target : resolveLocalContextTarget(localTarget, state, localTargets, seen);
|
|
193
|
+
}
|
|
194
|
+
return resolveContextTarget(target, state);
|
|
195
|
+
}
|
|
196
|
+
function refreshGraphAliases(state) {
|
|
197
|
+
state.graphTerms.clear();
|
|
198
|
+
for (const [term, target] of state.termTargets) if (target === "@graph") state.graphTerms.add(term);
|
|
199
|
+
}
|
|
200
|
+
function normalizeContextReference(reference, baseUrl) {
|
|
201
|
+
if (baseUrl != null) return new URL(reference, baseUrl).href;
|
|
202
|
+
return URL.canParse(reference) ? new URL(reference).href : reference;
|
|
203
|
+
}
|
|
204
|
+
/** @internal */
|
|
205
|
+
function isInvalidUrlTypeError(error) {
|
|
206
|
+
const code = error.code;
|
|
207
|
+
return error instanceof TypeError && (code === "ERR_INVALID_URL" || /^Invalid URL(?::|$)/.test(error.message) || / cannot be parsed as a URL\.?$/.test(error.message));
|
|
208
|
+
}
|
|
209
|
+
async function applyGraphAliasContext(state, context, documentLoader, remoteContextCache, baseUrl = null, processingContexts = /* @__PURE__ */ new Set()) {
|
|
210
|
+
if (context === null) return createGraphAliasContextState();
|
|
211
|
+
let nextState = cloneGraphAliasContextState(state);
|
|
212
|
+
if (Array.isArray(context)) {
|
|
213
|
+
for (const item of context) nextState = await applyGraphAliasContext(nextState, item, documentLoader, remoteContextCache, baseUrl, processingContexts);
|
|
214
|
+
return nextState;
|
|
215
|
+
}
|
|
216
|
+
if (typeof context === "string") {
|
|
217
|
+
const reference = normalizeContextReference(context, baseUrl);
|
|
218
|
+
const cacheKey = `${baseUrl ?? ""}\n${reference}`;
|
|
219
|
+
if (processingContexts.has(cacheKey)) return nextState;
|
|
220
|
+
processingContexts.add(cacheKey);
|
|
221
|
+
try {
|
|
222
|
+
let remoteContext = remoteContextCache.get(cacheKey);
|
|
223
|
+
if (remoteContext == null) {
|
|
224
|
+
remoteContext = (async () => {
|
|
225
|
+
try {
|
|
226
|
+
return getRemoteContext(await documentLoader(reference), reference);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
if (reference === context && isInvalidUrlTypeError(error) && isClearlyMalformedContextReference(context)) throw new InvalidContextReferenceError(context);
|
|
229
|
+
throw error;
|
|
230
|
+
}
|
|
231
|
+
})();
|
|
232
|
+
remoteContextCache.set(cacheKey, remoteContext);
|
|
233
|
+
}
|
|
234
|
+
const loadedRemoteContext = await remoteContext;
|
|
235
|
+
return await applyGraphAliasContext(nextState, loadedRemoteContext.context, documentLoader, remoteContextCache, loadedRemoteContext.baseUrl, processingContexts);
|
|
236
|
+
} finally {
|
|
237
|
+
processingContexts.delete(cacheKey);
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
if (typeof context === "object" && context != null) {
|
|
241
|
+
if ("@import" in context && typeof context["@import"] === "string") nextState = await applyGraphAliasContext(nextState, context["@import"], documentLoader, remoteContextCache, baseUrl, processingContexts);
|
|
242
|
+
const localTargets = /* @__PURE__ */ new Map();
|
|
243
|
+
for (const [term, definition] of globalThis.Object.entries(context)) {
|
|
244
|
+
if (term.startsWith("@")) continue;
|
|
245
|
+
const target = getDirectContextTarget(definition);
|
|
246
|
+
if (target == null) localTargets.set(term, null);
|
|
247
|
+
else if (typeof target === "string") localTargets.set(term, target);
|
|
248
|
+
else localTargets.delete(term);
|
|
249
|
+
}
|
|
250
|
+
for (const [term, definition] of globalThis.Object.entries(context)) {
|
|
251
|
+
if (term.startsWith("@")) continue;
|
|
252
|
+
if (localTargets.has(term)) {
|
|
253
|
+
const directTarget = localTargets.get(term);
|
|
254
|
+
if (directTarget == null) nextState.termTargets.set(term, null);
|
|
255
|
+
else nextState.termTargets.set(term, resolveLocalContextTarget(directTarget, nextState, localTargets));
|
|
256
|
+
} else nextState.termTargets.delete(term);
|
|
257
|
+
if (typeof definition === "object" && definition != null && "@context" in definition) nextState.propertyContexts.set(term, {
|
|
258
|
+
context: definition["@context"],
|
|
259
|
+
baseUrl
|
|
260
|
+
});
|
|
261
|
+
else nextState.propertyContexts.delete(term);
|
|
262
|
+
if (isJsonTypedDefinition(definition)) nextState.jsonTerms.add(term);
|
|
263
|
+
else nextState.jsonTerms.delete(term);
|
|
264
|
+
}
|
|
265
|
+
refreshGraphAliases(nextState);
|
|
266
|
+
}
|
|
267
|
+
return nextState;
|
|
268
|
+
}
|
|
269
|
+
async function assertNoGraphBeforeCompaction(jsonLd, documentLoader, inheritedState = createGraphAliasContextState(), propertyContext, remoteContextCache = /* @__PURE__ */ new Map()) {
|
|
270
|
+
if (Array.isArray(jsonLd)) {
|
|
271
|
+
for (const item of jsonLd) await assertNoGraphBeforeCompaction(item, documentLoader, inheritedState, propertyContext, remoteContextCache);
|
|
272
|
+
return;
|
|
273
|
+
}
|
|
274
|
+
if (typeof jsonLd !== "object" || jsonLd == null) return;
|
|
275
|
+
const jsonLiteralWrapper = isJsonLiteralWrapper(jsonLd);
|
|
276
|
+
let state = inheritedState;
|
|
277
|
+
if (propertyContext !== void 0) state = await applyGraphAliasContext(state, propertyContext.context, documentLoader, remoteContextCache, propertyContext.baseUrl);
|
|
278
|
+
if ("@context" in jsonLd) state = await applyGraphAliasContext(state, jsonLd["@context"], documentLoader, remoteContextCache);
|
|
279
|
+
for (const [key, value] of globalThis.Object.entries(jsonLd)) {
|
|
280
|
+
if (key === "@context") continue;
|
|
281
|
+
if (jsonLiteralWrapper && key === "@value") continue;
|
|
282
|
+
if (key === "@graph" || state.graphTerms.has(key)) throw new UnsafeJsonLdError("@graph");
|
|
283
|
+
if (state.jsonTerms.has(key)) continue;
|
|
284
|
+
await assertNoGraphBeforeCompaction(value, documentLoader, state, state.propertyContexts.get(key), remoteContextCache);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function isJsonLiteralWrapper(value) {
|
|
288
|
+
return "@value" in value && (value["@type"] === "@json" || value.type === "@json");
|
|
289
|
+
}
|
|
290
|
+
/** @internal */
|
|
291
|
+
function assertSafeJsonLd(jsonLd) {
|
|
292
|
+
if (Array.isArray(jsonLd)) for (const item of jsonLd) assertSafeJsonLd(item);
|
|
293
|
+
else if (typeof jsonLd === "object" && jsonLd != null) {
|
|
294
|
+
const jsonLiteralWrapper = isJsonLiteralWrapper(jsonLd);
|
|
295
|
+
for (const [key, value] of globalThis.Object.entries(jsonLd)) {
|
|
296
|
+
if (disallowedJsonLdKeywords.has(key)) throw new UnsafeJsonLdError(key);
|
|
297
|
+
if (jsonLiteralWrapper && key === "@value") continue;
|
|
298
|
+
assertSafeJsonLd(value);
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
18
302
|
/**
|
|
19
303
|
* Attaches a LD signature to the given JSON-LD document.
|
|
20
304
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
@@ -269,13 +553,25 @@ function getLdSignatureObject(jsonLd) {
|
|
|
269
553
|
* @returns `true` if the document is authentic; `false` otherwise.
|
|
270
554
|
*/
|
|
271
555
|
async function verifyJsonLd(jsonLd, options = {}) {
|
|
556
|
+
return await verifyJsonLdInternal(jsonLd, options, true);
|
|
557
|
+
}
|
|
558
|
+
/** @internal */
|
|
559
|
+
async function verifyCompactJsonLd(jsonLd, options = {}) {
|
|
560
|
+
return await verifyJsonLdInternal(jsonLd, options, false);
|
|
561
|
+
}
|
|
562
|
+
async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
272
563
|
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.verify", async (span) => {
|
|
273
564
|
const start = performance.now();
|
|
274
565
|
let verified = false;
|
|
275
566
|
let threw = false;
|
|
276
567
|
let signatureType;
|
|
277
568
|
try {
|
|
278
|
-
const
|
|
569
|
+
const verificationOptions = hasSignature(jsonLd) ? {
|
|
570
|
+
...options,
|
|
571
|
+
contextLoader: getNormalizationContextLoader(options.contextLoader)
|
|
572
|
+
} : options;
|
|
573
|
+
const compacted = compact ? hasSignature(jsonLd) ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
|
|
574
|
+
const object = await Object$1.fromJsonLd(compacted, verificationOptions);
|
|
279
575
|
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
280
576
|
span.setAttribute("activitypub.object.type", getTypeId(object).href);
|
|
281
577
|
const sig = getLdSignatureObject(jsonLd);
|
|
@@ -289,7 +585,7 @@ async function verifyJsonLd(jsonLd, options = {}) {
|
|
|
289
585
|
}
|
|
290
586
|
const attributions = new Set(object.attributionIds.map((uri) => uri.href));
|
|
291
587
|
if (object instanceof Activity) for (const uri of object.actorIds) attributions.add(uri.href);
|
|
292
|
-
const key = await verifySignature(
|
|
588
|
+
const key = await verifySignature(compacted, verificationOptions);
|
|
293
589
|
if (key == null) return false;
|
|
294
590
|
if (key.ownerId == null) {
|
|
295
591
|
logger$3.debug("Key {keyId} has no owner.", { keyId: key.id?.href });
|
|
@@ -1105,4 +1401,4 @@ async function verifyObject(cls, jsonLd, options = {}) {
|
|
|
1105
1401
|
return object;
|
|
1106
1402
|
}
|
|
1107
1403
|
//#endregion
|
|
1108
|
-
export { verifyProof as a, getKeyOwner as c,
|
|
1404
|
+
export { verifySignature as C, verifyJsonLd as S, hasSignatureLike as _, verifyProof as a, signJsonLd as b, getKeyOwner as c, attachSignature as d, compactJsonLd as f, hasSignature as g, getNormalizationContextLoader as h, verifyObject as i, InvalidContextReferenceError as l, detachSignature as m, hasProofLike as n, normalizeOutgoingActivityJsonLd as o, createSignature as p, signObject as r, doesActorOwnKey as s, createProof as t, assertSafeJsonLd as u, isClearlyMalformedContextReference as v, wrapContextLoaderForJsonLd as w, verifyCompactJsonLd as x, isInvalidUrlTypeError as y };
|
|
@@ -1,9 +1,9 @@
|
|
|
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 { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-
|
|
6
|
-
import { n as fetchKey, o as validateCryptoKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-CKFE6Uya.mjs";
|
|
5
|
+
import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-7Vy9FvEw.mjs";
|
|
6
|
+
import { n as fetchKey, o as validateCryptoKey } from "./key-N0zP_oJA.mjs";
|
|
7
7
|
import { n as preloadedOnlyDocumentLoader } from "./public-audience-N3pyOx2p.mjs";
|
|
8
8
|
import { r as normalizeOutgoingActivityJsonLd } from "./outgoing-jsonld-BgFLCJQ_.mjs";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -1,9 +1,9 @@
|
|
|
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 { n as getDurationMs, r as getFederationMetrics } from "./metrics-
|
|
6
|
-
import { n as doubleKnock } from "./http-
|
|
4
|
+
import { n as version, t as name } from "./deno-CKFE6Uya.mjs";
|
|
5
|
+
import { n as getDurationMs, r as getFederationMetrics } from "./metrics-7Vy9FvEw.mjs";
|
|
6
|
+
import { n as doubleKnock } from "./http-vHCgbhTg.mjs";
|
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
|
8
8
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
9
9
|
//#region src/federation/send.ts
|
package/dist/sig/http.test.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { n as assertGreaterOrEqual, r as assertFalse, t as assertRejects } from
|
|
|
7
7
|
import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
|
|
8
8
|
import { t as assert } from "../assert-OguE97r2.mjs";
|
|
9
9
|
import { t as esm_default } from "../esm-BQRw925N.mjs";
|
|
10
|
-
import { t as exportJwk } from "../key-
|
|
11
|
-
import { a as parseRfc9421Signature, c as timingSafeEqual, i as formatRfc9421SignatureParameters, l as verifyRequest, n as doubleKnock, o as parseRfc9421SignatureInput, r as formatRfc9421Signature, s as signRequest, t as createRfc9421SignatureBase, u as verifyRequestDetailed } from "../http-
|
|
10
|
+
import { t as exportJwk } from "../key-N0zP_oJA.mjs";
|
|
11
|
+
import { a as parseRfc9421Signature, c as timingSafeEqual, i as formatRfc9421SignatureParameters, l as verifyRequest, n as doubleKnock, o as parseRfc9421SignatureInput, r as formatRfc9421Signature, s as signRequest, t as createRfc9421SignatureBase, u as verifyRequestDetailed } from "../http-vHCgbhTg.mjs";
|
|
12
12
|
import { i as rsaPrivateKey2, l as rsaPublicKey5, o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-C3kae-6B.mjs";
|
|
13
13
|
import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
14
14
|
import { FetchError, exportSpki } from "@fedify/vocab-runtime";
|
package/dist/sig/key.test.mjs
CHANGED
|
@@ -5,7 +5,7 @@ import { t as assertEquals } from "../assert_equals-C-ZRDbaf.mjs";
|
|
|
5
5
|
import "../std__assert-BBjXFNOb.mjs";
|
|
6
6
|
import { t as assertRejects } from "../assert_rejects-DN60FHPX.mjs";
|
|
7
7
|
import { t as assertThrows } from "../assert_throws-BOkhLGYc.mjs";
|
|
8
|
-
import { a as importJwk, i as generateCryptoKeyPair, n as fetchKey, o as validateCryptoKey, r as fetchKeyDetailed, t as exportJwk } from "../key-
|
|
8
|
+
import { a as importJwk, i as generateCryptoKeyPair, n as fetchKey, o as validateCryptoKey, r as fetchKeyDetailed, t as exportJwk } from "../key-N0zP_oJA.mjs";
|
|
9
9
|
import { c as rsaPublicKey3, i as rsaPrivateKey2, o as rsaPublicKey1, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-C3kae-6B.mjs";
|
|
10
10
|
import { CryptographicKey, Multikey } from "@fedify/vocab";
|
|
11
11
|
import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|