@fedify/fedify 2.2.3-dev.1098 → 2.2.3
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-mqtih91o.mjs → builder-CaVN56-q.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-BPMgyX7m.d.ts → context-BU-1O90h.d.ts} +48 -6
- package/dist/{context-DwkhwUX9.d.cts → context-DVA8wHZ0.d.cts} +48 -6
- package/dist/{deno-CziVFvS6.mjs → deno-DMg4SgCb.mjs} +1 -1
- package/dist/{docloader-fI9DeYyB.mjs → docloader-Da15YRxG.mjs} +2 -2
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +1363 -43
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1584 -80
- 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 +3 -3
- 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/{http-D8qsXrUS.js → http-BPPaA2uz.js} +1 -1
- package/dist/{http-BDCGf4Ac.mjs → http-C_edJspG.mjs} +2 -2
- package/dist/{http-kPc328Pc.cjs → http-Cl0Q2bUO.cjs} +1 -1
- package/dist/{key-D3TgMhcs.mjs → key-BAQuZEU1.mjs} +1 -1
- package/dist/{kv-cache-D_eVhctK.js → kv-cache-C4DGZ_t4.js} +1 -1
- package/dist/{kv-cache-zxW74Wfd.cjs → kv-cache-DmGi6uC-.cjs} +1 -1
- package/dist/ld-tusP_XxG.mjs +573 -0
- package/dist/{middleware-xR9KxICq.cjs → middleware-0V-9qj7m.cjs} +399 -73
- package/dist/{middleware-gXlDLkok.js → middleware-Ar1QOOPG.js} +396 -71
- package/dist/{middleware-2gmMVy8b.mjs → middleware-D9k0Knum.mjs} +314 -78
- package/dist/{middleware-BuOXw_hM.cjs → middleware-OQPBzyvx.cjs} +1 -1
- package/dist/{middleware-CfaiRKQ9.mjs → middleware-madKLp2f.mjs} +1 -1
- package/dist/{mod-CNAHY39V.d.ts → mod-BVt6iTmH.d.ts} +1 -1
- package/dist/{mod-Bi6WOdti.d.cts → mod-q-NFLW6B.d.cts} +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-DBSV2TSl.mjs → owner-DRHNR5YO.mjs} +2 -2
- package/dist/{proof-tz91vdtN.mjs → proof-DLhLRv3m.mjs} +2 -2
- package/dist/{proof-CZDkoeWG.cjs → proof-DfrItHmh.cjs} +351 -3
- package/dist/{proof-z93OkIov.js → proof-SQ4cQs3A.js} +298 -4
- package/dist/{send-CNjG31rJ.mjs → send-C7tim5U9.mjs} +2 -2
- 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-LL61Ddf2.mjs +95 -0
- package/dist/testing/mod.d.mts +48 -6
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +5 -5
- package/dist/ld-D_u8mdpv.mjs +0 -279
- /package/dist/{retry-bMXBL97A.mjs → retry-v_sGLH1d.mjs} +0 -0
package/dist/mod.d.ts
CHANGED
|
@@ -2,10 +2,10 @@
|
|
|
2
2
|
import { a as InboundService, c as OutboundService, d as Software, f as Usage, i as parseNodeInfo, l as Protocol, n as ParseNodeInfoOptions, o as JsonValue, p as nodeInfoToJson, r as getNodeInfo, s as NodeInfo, t as GetNodeInfoOptions, u as Services } from "./client-CSddvgWN.js";
|
|
3
3
|
import { C as exportJwk, D as importJwk, E as generateCryptoKeyPair, S as KeyCache, T as fetchKeyDetailed, _ as validateAcceptSignature, a as VerifyRequestDetailedResult, b as FetchKeyOptions, c as signRequest, d as AcceptSignatureMember, f as AcceptSignatureParameters, g as parseAcceptSignature, h as fulfillAcceptSignature, i as SignRequestOptions, l as verifyRequest, m as formatAcceptSignature, n as HttpMessageSignaturesSpecDeterminer, o as VerifyRequestFailureReason, p as FulfillAcceptSignatureResult, r as Rfc9421SignRequestOptions, s as VerifyRequestOptions, t as HttpMessageSignaturesSpec, u as verifyRequestDetailed, v as FetchKeyDetailedResult, w as fetchKey, x as FetchKeyResult, y as FetchKeyErrorResult } from "./http-BDZeS5om.js";
|
|
4
4
|
import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "./owner-CnngXDNJ.js";
|
|
5
|
-
import { $ as ActorAliasMapper, A as FederationKvPrefixes, B as Router, C as IdempotencyKeyCallback, Ct as SendActivityError, D as ObjectCallbackSetters, Dt as digest, E as InboxListenerSetters, Et as buildCollectionSynchronizationHeader, F as RetryContext, G as respondWithObject, H as RouterOptions, I as RetryPolicy, J as InProcessMessageQueueOptions, K as respondWithObjectIfAcceptable, L as createExponentialBackoffPolicy, M as FederationQueueOptions, N as createFederation, O as OutboxListenerSetters, Ot as ActivityTransformer, P as CreateExponentialBackoffPolicyOptions, Q as ParallelMessageQueue, R as Message, S as FederationStartQueueOptions, St as WebFingerLinksDispatcher, T as InboxChallengePolicy, Tt as PageItems, U as RouterRouteResult, V as RouterError, W as RespondWithObjectOptions, X as MessageQueueEnqueueOptions, Y as MessageQueue, Z as MessageQueueListenOptions, _ as Federatable, _t as OutboxListenerErrorHandler, a as GetSignedKeyOptions, at as CollectionCursor, b as FederationFetchOptions, bt as UnverifiedActivityHandler, c as ParseUriResult, ct as CustomCollectionCursor, d as SendActivityOptions, dt as InboxListener, et as ActorDispatcher, f as SendActivityOptionsForCollection, ft as NodeInfoDispatcher, g as CustomCollectionCallbackSetters, gt as OutboxListener, h as ConstructorWithTypeId, ht as OutboxErrorHandler, i as GetActorOptions, it as CollectionCounter, j as FederationOrigin, k as Rfc6570Expression, l as RequestContext, lt as CustomCollectionDispatcher, m as CollectionCallbackSetters, mt as ObjectDispatcher, n as Context, nt as ActorKeyPairsDispatcher, o as InboxContext, ot as CollectionDispatcher, p as ActorCallbackSetters, pt as ObjectAuthorizePredicate, q as InProcessMessageQueue, r as ForwardActivityOptions, rt as AuthorizePredicate, s as OutboxContext, st as CustomCollectionCounter, t as ActorKeyPair, tt as ActorHandleMapper, u as RouteActivityOptions, ut as InboxErrorHandler, v as Federation, vt as OutboxPermanentFailureHandler, w as IdempotencyStrategy, wt as SenderKeyPair, x as FederationOptions, xt as UnverifiedActivityReason, y as FederationBuilder, yt as SharedInboxKeyDispatcher, z as createFederationBuilder } from "./context-
|
|
5
|
+
import { $ as ActorAliasMapper, A as FederationKvPrefixes, B as Router, C as IdempotencyKeyCallback, Ct as SendActivityError, D as ObjectCallbackSetters, Dt as digest, E as InboxListenerSetters, Et as buildCollectionSynchronizationHeader, F as RetryContext, G as respondWithObject, H as RouterOptions, I as RetryPolicy, J as InProcessMessageQueueOptions, K as respondWithObjectIfAcceptable, L as createExponentialBackoffPolicy, M as FederationQueueOptions, N as createFederation, O as OutboxListenerSetters, Ot as ActivityTransformer, P as CreateExponentialBackoffPolicyOptions, Q as ParallelMessageQueue, R as Message, S as FederationStartQueueOptions, St as WebFingerLinksDispatcher, T as InboxChallengePolicy, Tt as PageItems, U as RouterRouteResult, V as RouterError, W as RespondWithObjectOptions, X as MessageQueueEnqueueOptions, Y as MessageQueue, Z as MessageQueueListenOptions, _ as Federatable, _t as OutboxListenerErrorHandler, a as GetSignedKeyOptions, at as CollectionCursor, b as FederationFetchOptions, bt as UnverifiedActivityHandler, c as ParseUriResult, ct as CustomCollectionCursor, d as SendActivityOptions, dt as InboxListener, et as ActorDispatcher, f as SendActivityOptionsForCollection, ft as NodeInfoDispatcher, g as CustomCollectionCallbackSetters, gt as OutboxListener, h as ConstructorWithTypeId, ht as OutboxErrorHandler, i as GetActorOptions, it as CollectionCounter, j as FederationOrigin, k as Rfc6570Expression, l as RequestContext, lt as CustomCollectionDispatcher, m as CollectionCallbackSetters, mt as ObjectDispatcher, n as Context, nt as ActorKeyPairsDispatcher, o as InboxContext, ot as CollectionDispatcher, p as ActorCallbackSetters, pt as ObjectAuthorizePredicate, q as InProcessMessageQueue, r as ForwardActivityOptions, rt as AuthorizePredicate, s as OutboxContext, st as CustomCollectionCounter, t as ActorKeyPair, tt as ActorHandleMapper, u as RouteActivityOptions, ut as InboxErrorHandler, v as Federation, vt as OutboxPermanentFailureHandler, w as IdempotencyStrategy, wt as SenderKeyPair, x as FederationOptions, xt as UnverifiedActivityReason, y as FederationBuilder, yt as SharedInboxKeyDispatcher, z as createFederationBuilder } from "./context-BU-1O90h.js";
|
|
6
6
|
import { a as MemoryKvStore, i as KvStoreSetOptions, n as KvStore, r as KvStoreListEntry, t as KvKey } from "./kv-D6hNiMTK.js";
|
|
7
7
|
import { actorDehydrator, autoIdAssigner, getDefaultActivityTransformers } from "./compat/mod.js";
|
|
8
|
-
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-
|
|
8
|
+
import { n as handleWebFinger, t as WebFingerHandlerParameters } from "./mod-BVt6iTmH.js";
|
|
9
9
|
import { _ as hasSignatureLike, a as createProof, b as verifySignature, c as verifyObject, d as SignJsonLdOptions, f as VerifyJsonLdOptions, g as detachSignature, h as createSignature, i as VerifyProofOptions, l as verifyProof, m as attachSignature, n as SignObjectOptions, o as hasProofLike, p as VerifySignatureOptions, r as VerifyObjectOptions, s as signObject, t as CreateProofOptions, u as CreateSignatureOptions, v as signJsonLd, y as verifyJsonLd } from "./mod-DHO9lk3D.js";
|
|
10
10
|
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./mod-BhU_H1I_.js";
|
|
11
11
|
export * from "@fedify/vocab-runtime";
|
package/dist/mod.js
CHANGED
|
@@ -3,11 +3,11 @@ import { URLPattern } from "urlpattern-polyfill";
|
|
|
3
3
|
import "./chunk-CRNNMoPX.js";
|
|
4
4
|
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-BGMIq1cs.js";
|
|
5
5
|
import "./compat/mod.js";
|
|
6
|
-
import { a as verifyRequestDetailed, c as fetchKeyDetailed, f as formatAcceptSignature, h as validateAcceptSignature, i as verifyRequest, l as generateCryptoKeyPair, m as parseAcceptSignature, o as exportJwk, p as fulfillAcceptSignature, r as signRequest, s as fetchKey, u as importJwk } from "./http-
|
|
7
|
-
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-
|
|
8
|
-
import {
|
|
6
|
+
import { a as verifyRequestDetailed, c as fetchKeyDetailed, f as formatAcceptSignature, h as validateAcceptSignature, i as verifyRequest, l as generateCryptoKeyPair, m as parseAcceptSignature, o as exportJwk, p as fulfillAcceptSignature, r as signRequest, s as fetchKey, u as importJwk } from "./http-BPPaA2uz.js";
|
|
7
|
+
import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-Ar1QOOPG.js";
|
|
8
|
+
import { C as verifySignature, S as verifyJsonLd, _ as hasSignatureLike, a as verifyProof, b as signJsonLd, c as getKeyOwner, d as attachSignature, i as verifyObject, m as detachSignature, n as hasProofLike, p as createSignature, r as signObject, s as doesActorOwnKey, t as createProof } from "./proof-SQ4cQs3A.js";
|
|
9
9
|
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-CAY3OdLq.js";
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-C4DGZ_t4.js";
|
|
11
11
|
import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
|
|
12
12
|
import "./nodeinfo/mod.js";
|
|
13
13
|
import "./runtime/mod.js";
|
|
@@ -5,7 +5,7 @@ import { r as createRequestContext } from "../context-Dk_tacqz.mjs";
|
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-CRDpx_HF.mjs";
|
|
7
7
|
import { t as MemoryKvStore } from "../kv-rV3vodCc.mjs";
|
|
8
|
-
import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-
|
|
8
|
+
import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-D9k0Knum.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
|
@@ -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 "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-DMg4SgCb.mjs";
|
|
5
|
+
import "./key-BAQuZEU1.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,8 +1,8 @@
|
|
|
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 fetchKey, o as validateCryptoKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-DMg4SgCb.mjs";
|
|
5
|
+
import { n as fetchKey, o as validateCryptoKey } from "./key-BAQuZEU1.mjs";
|
|
6
6
|
import { n as preloadedOnlyDocumentLoader } from "./public-audience-DYFHzm_c.mjs";
|
|
7
7
|
import { r as normalizeOutgoingActivityJsonLd } from "./outgoing-jsonld-CNmZLixq.mjs";
|
|
8
8
|
import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
const require_chunk = require("./chunk-DDcVe30Y.cjs");
|
|
4
|
-
const require_http = require("./http-
|
|
4
|
+
const require_http = require("./http-Cl0Q2bUO.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
let _fedify_vocab = require("@fedify/vocab");
|
|
7
7
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -18,6 +18,288 @@ const logger$3 = (0, _logtape_logtape.getLogger)([
|
|
|
18
18
|
"sig",
|
|
19
19
|
"ld"
|
|
20
20
|
]);
|
|
21
|
+
const localContext = [
|
|
22
|
+
"https://w3id.org/identity/v1",
|
|
23
|
+
"https://www.w3.org/ns/activitystreams",
|
|
24
|
+
"https://w3id.org/security/v1",
|
|
25
|
+
"https://w3id.org/security/data-integrity/v1"
|
|
26
|
+
];
|
|
27
|
+
const localContextUrls = new Set(localContext);
|
|
28
|
+
const builtInContextLoader = (0, _fedify_vocab_runtime.getDocumentLoader)();
|
|
29
|
+
const disallowedJsonLdKeywords = new Set([
|
|
30
|
+
"@graph",
|
|
31
|
+
"@included",
|
|
32
|
+
"@reverse"
|
|
33
|
+
]);
|
|
34
|
+
/** @internal */
|
|
35
|
+
var UnsafeJsonLdError = class extends TypeError {
|
|
36
|
+
constructor(keyword) {
|
|
37
|
+
super(`Unsupported JSON-LD keyword: ${keyword}.`);
|
|
38
|
+
this.keyword = keyword;
|
|
39
|
+
this.name = "UnsafeJsonLdError";
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
/** @internal */
|
|
43
|
+
var InvalidContextReferenceError = class extends TypeError {
|
|
44
|
+
constructor(reference) {
|
|
45
|
+
super(`Invalid JSON-LD context reference: ${reference}.`);
|
|
46
|
+
this.reference = reference;
|
|
47
|
+
this.name = "InvalidContextReferenceError";
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
function createLoadingRemoteContextFailedError(reference, cause) {
|
|
51
|
+
const message = cause instanceof Error ? cause.message : String(cause);
|
|
52
|
+
const error = /* @__PURE__ */ new Error(`Dereferencing a URL did not result in a valid JSON-LD context: ${reference}. ${message}`);
|
|
53
|
+
error.name = "jsonld.InvalidUrl";
|
|
54
|
+
error.details = {
|
|
55
|
+
code: "loading remote context failed",
|
|
56
|
+
url: reference
|
|
57
|
+
};
|
|
58
|
+
error.cause = cause;
|
|
59
|
+
return error;
|
|
60
|
+
}
|
|
61
|
+
/** @internal */
|
|
62
|
+
function isClearlyMalformedContextReference(reference) {
|
|
63
|
+
for (const char of reference) {
|
|
64
|
+
const code = char.charCodeAt(0);
|
|
65
|
+
if (code <= 32 || code === 127) return true;
|
|
66
|
+
}
|
|
67
|
+
if (/^[A-Za-z][A-Za-z0-9+.-]*:/.test(reference) && !URL.canParse(reference)) return true;
|
|
68
|
+
for (let i = 0; i < reference.length; i++) {
|
|
69
|
+
if (reference[i] !== "%") continue;
|
|
70
|
+
if (i + 2 >= reference.length || !/[0-9A-Fa-f]/.test(reference[i + 1]) || !/[0-9A-Fa-f]/.test(reference[i + 2])) return true;
|
|
71
|
+
i += 2;
|
|
72
|
+
}
|
|
73
|
+
if (reference.startsWith("./") || reference.startsWith("../") || reference.startsWith("/") || reference.startsWith("//")) {
|
|
74
|
+
for (const char of reference) if ("[]<>\"\\^`{|}".includes(char)) return true;
|
|
75
|
+
}
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
function cloneRemoteDocument(remoteDocument) {
|
|
79
|
+
return structuredClone(remoteDocument);
|
|
80
|
+
}
|
|
81
|
+
function createMemoizedDocumentLoader(documentLoader) {
|
|
82
|
+
const cache = /* @__PURE__ */ new Map();
|
|
83
|
+
return async (url, options) => {
|
|
84
|
+
const cacheKey = URL.canParse(url) ? new URL(url).href : url;
|
|
85
|
+
let remoteDocument = cache.get(cacheKey);
|
|
86
|
+
if (remoteDocument == null) {
|
|
87
|
+
remoteDocument = Promise.resolve(documentLoader(url, options)).then(cloneRemoteDocument);
|
|
88
|
+
remoteDocument.catch(() => {
|
|
89
|
+
if (cache.get(cacheKey) === remoteDocument) cache.delete(cacheKey);
|
|
90
|
+
});
|
|
91
|
+
cache.set(cacheKey, remoteDocument);
|
|
92
|
+
}
|
|
93
|
+
return cloneRemoteDocument(await remoteDocument);
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
/** @internal */
|
|
97
|
+
function wrapContextLoaderForJsonLd(contextLoader) {
|
|
98
|
+
const loader = contextLoader ?? builtInContextLoader;
|
|
99
|
+
return async (url, options) => {
|
|
100
|
+
try {
|
|
101
|
+
return await loader(url, options);
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (!isInvalidUrlTypeError(error)) throw error;
|
|
104
|
+
if (isClearlyMalformedContextReference(url)) throw new InvalidContextReferenceError(url);
|
|
105
|
+
throw createLoadingRemoteContextFailedError(url, error);
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
/** @internal */
|
|
110
|
+
function getNormalizationContextLoader(contextLoader) {
|
|
111
|
+
const loader = wrapContextLoaderForJsonLd(contextLoader);
|
|
112
|
+
return createMemoizedDocumentLoader(async (url, options) => {
|
|
113
|
+
if (URL.canParse(url)) {
|
|
114
|
+
const normalizedUrl = new URL(url).href;
|
|
115
|
+
if (localContextUrls.has(normalizedUrl)) return await builtInContextLoader(normalizedUrl, options);
|
|
116
|
+
}
|
|
117
|
+
return await loader(url, options);
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
/** @internal */
|
|
121
|
+
async function compactJsonLd(jsonLd, contextLoader) {
|
|
122
|
+
const hasLds = typeof jsonLd === "object" && jsonLd != null && "signature" in jsonLd;
|
|
123
|
+
const signature = hasLds ? jsonLd.signature : void 0;
|
|
124
|
+
const normalizationContextLoader = getNormalizationContextLoader(contextLoader);
|
|
125
|
+
const document = hasLds ? detachSignature(jsonLd) : jsonLd;
|
|
126
|
+
await assertNoGraphBeforeCompaction(document, normalizationContextLoader);
|
|
127
|
+
const compacted = await _fedify_vocab_runtime_jsonld.default.compact(document, localContext, { documentLoader: normalizationContextLoader });
|
|
128
|
+
if (hasLds && typeof compacted === "object" && compacted != null) compacted.signature = signature;
|
|
129
|
+
assertSafeJsonLd(compacted);
|
|
130
|
+
return compacted;
|
|
131
|
+
}
|
|
132
|
+
function createInvalidRemoteContextError(reference) {
|
|
133
|
+
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}".`);
|
|
134
|
+
error.name = "jsonld.InvalidUrl";
|
|
135
|
+
error.details = {
|
|
136
|
+
code: "invalid remote context",
|
|
137
|
+
url: reference
|
|
138
|
+
};
|
|
139
|
+
return error;
|
|
140
|
+
}
|
|
141
|
+
function getRemoteContext(remoteDocument, reference) {
|
|
142
|
+
const { contextUrl, documentUrl } = remoteDocument;
|
|
143
|
+
let { document } = remoteDocument;
|
|
144
|
+
if (typeof document === "string") document = JSON.parse(document);
|
|
145
|
+
if (typeof document !== "object" || document == null || Array.isArray(document)) throw createInvalidRemoteContextError(reference);
|
|
146
|
+
let context = "@context" in document ? document["@context"] : {};
|
|
147
|
+
if (contextUrl != null) context = Array.isArray(context) ? [...context, contextUrl] : [context, contextUrl];
|
|
148
|
+
return {
|
|
149
|
+
context,
|
|
150
|
+
baseUrl: documentUrl ?? reference
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function createGraphAliasContextState() {
|
|
154
|
+
return {
|
|
155
|
+
graphTerms: /* @__PURE__ */ new Set(),
|
|
156
|
+
jsonTerms: /* @__PURE__ */ new Set(),
|
|
157
|
+
propertyContexts: /* @__PURE__ */ new Map(),
|
|
158
|
+
termTargets: /* @__PURE__ */ new Map()
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
function cloneGraphAliasContextState(state) {
|
|
162
|
+
return {
|
|
163
|
+
graphTerms: new Set(state.graphTerms),
|
|
164
|
+
jsonTerms: new Set(state.jsonTerms),
|
|
165
|
+
propertyContexts: new Map(state.propertyContexts),
|
|
166
|
+
termTargets: new Map(state.termTargets)
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
function resolveContextTarget(target, state) {
|
|
170
|
+
if (target === "@graph") return target;
|
|
171
|
+
const mapped = state.termTargets.get(target);
|
|
172
|
+
if (mapped == null) return target;
|
|
173
|
+
return mapped;
|
|
174
|
+
}
|
|
175
|
+
function getDirectContextTarget(definition) {
|
|
176
|
+
if (definition === null) return null;
|
|
177
|
+
if (typeof definition === "string") return definition;
|
|
178
|
+
if (typeof definition === "object" && definition != null && "@id" in definition) {
|
|
179
|
+
const id = definition["@id"];
|
|
180
|
+
if (id === null) return null;
|
|
181
|
+
if (typeof id === "string") return id;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
function isJsonTypedDefinition(definition) {
|
|
185
|
+
return typeof definition === "object" && definition != null && "@type" in definition && definition["@type"] === "@json";
|
|
186
|
+
}
|
|
187
|
+
function resolveLocalContextTarget(target, state, localTargets, seen = /* @__PURE__ */ new Set()) {
|
|
188
|
+
if (target === "@graph") return target;
|
|
189
|
+
if (seen.has(target)) return target;
|
|
190
|
+
seen.add(target);
|
|
191
|
+
if (localTargets.has(target)) {
|
|
192
|
+
const localTarget = localTargets.get(target);
|
|
193
|
+
return localTarget == null ? target : resolveLocalContextTarget(localTarget, state, localTargets, seen);
|
|
194
|
+
}
|
|
195
|
+
return resolveContextTarget(target, state);
|
|
196
|
+
}
|
|
197
|
+
function refreshGraphAliases(state) {
|
|
198
|
+
state.graphTerms.clear();
|
|
199
|
+
for (const [term, target] of state.termTargets) if (target === "@graph") state.graphTerms.add(term);
|
|
200
|
+
}
|
|
201
|
+
function normalizeContextReference(reference, baseUrl) {
|
|
202
|
+
if (baseUrl != null) return new URL(reference, baseUrl).href;
|
|
203
|
+
return URL.canParse(reference) ? new URL(reference).href : reference;
|
|
204
|
+
}
|
|
205
|
+
/** @internal */
|
|
206
|
+
function isInvalidUrlTypeError(error) {
|
|
207
|
+
const code = error.code;
|
|
208
|
+
return error instanceof TypeError && (code === "ERR_INVALID_URL" || /^Invalid URL(?::|$)/.test(error.message) || / cannot be parsed as a URL\.?$/.test(error.message));
|
|
209
|
+
}
|
|
210
|
+
async function applyGraphAliasContext(state, context, documentLoader, remoteContextCache, baseUrl = null, processingContexts = /* @__PURE__ */ new Set()) {
|
|
211
|
+
if (context === null) return createGraphAliasContextState();
|
|
212
|
+
let nextState = cloneGraphAliasContextState(state);
|
|
213
|
+
if (Array.isArray(context)) {
|
|
214
|
+
for (const item of context) nextState = await applyGraphAliasContext(nextState, item, documentLoader, remoteContextCache, baseUrl, processingContexts);
|
|
215
|
+
return nextState;
|
|
216
|
+
}
|
|
217
|
+
if (typeof context === "string") {
|
|
218
|
+
const reference = normalizeContextReference(context, baseUrl);
|
|
219
|
+
const cacheKey = `${baseUrl ?? ""}\n${reference}`;
|
|
220
|
+
if (processingContexts.has(cacheKey)) return nextState;
|
|
221
|
+
processingContexts.add(cacheKey);
|
|
222
|
+
try {
|
|
223
|
+
let remoteContext = remoteContextCache.get(cacheKey);
|
|
224
|
+
if (remoteContext == null) {
|
|
225
|
+
remoteContext = (async () => {
|
|
226
|
+
try {
|
|
227
|
+
return getRemoteContext(await documentLoader(reference), reference);
|
|
228
|
+
} catch (error) {
|
|
229
|
+
if (reference === context && isInvalidUrlTypeError(error) && isClearlyMalformedContextReference(context)) throw new InvalidContextReferenceError(context);
|
|
230
|
+
throw error;
|
|
231
|
+
}
|
|
232
|
+
})();
|
|
233
|
+
remoteContextCache.set(cacheKey, remoteContext);
|
|
234
|
+
}
|
|
235
|
+
const loadedRemoteContext = await remoteContext;
|
|
236
|
+
return await applyGraphAliasContext(nextState, loadedRemoteContext.context, documentLoader, remoteContextCache, loadedRemoteContext.baseUrl, processingContexts);
|
|
237
|
+
} finally {
|
|
238
|
+
processingContexts.delete(cacheKey);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
if (typeof context === "object" && context != null) {
|
|
242
|
+
if ("@import" in context && typeof context["@import"] === "string") nextState = await applyGraphAliasContext(nextState, context["@import"], documentLoader, remoteContextCache, baseUrl, processingContexts);
|
|
243
|
+
const localTargets = /* @__PURE__ */ new Map();
|
|
244
|
+
for (const [term, definition] of globalThis.Object.entries(context)) {
|
|
245
|
+
if (term.startsWith("@")) continue;
|
|
246
|
+
const target = getDirectContextTarget(definition);
|
|
247
|
+
if (target == null) localTargets.set(term, null);
|
|
248
|
+
else if (typeof target === "string") localTargets.set(term, target);
|
|
249
|
+
else localTargets.delete(term);
|
|
250
|
+
}
|
|
251
|
+
for (const [term, definition] of globalThis.Object.entries(context)) {
|
|
252
|
+
if (term.startsWith("@")) continue;
|
|
253
|
+
if (localTargets.has(term)) {
|
|
254
|
+
const directTarget = localTargets.get(term);
|
|
255
|
+
if (directTarget == null) nextState.termTargets.set(term, null);
|
|
256
|
+
else nextState.termTargets.set(term, resolveLocalContextTarget(directTarget, nextState, localTargets));
|
|
257
|
+
} else nextState.termTargets.delete(term);
|
|
258
|
+
if (typeof definition === "object" && definition != null && "@context" in definition) nextState.propertyContexts.set(term, {
|
|
259
|
+
context: definition["@context"],
|
|
260
|
+
baseUrl
|
|
261
|
+
});
|
|
262
|
+
else nextState.propertyContexts.delete(term);
|
|
263
|
+
if (isJsonTypedDefinition(definition)) nextState.jsonTerms.add(term);
|
|
264
|
+
else nextState.jsonTerms.delete(term);
|
|
265
|
+
}
|
|
266
|
+
refreshGraphAliases(nextState);
|
|
267
|
+
}
|
|
268
|
+
return nextState;
|
|
269
|
+
}
|
|
270
|
+
async function assertNoGraphBeforeCompaction(jsonLd, documentLoader, inheritedState = createGraphAliasContextState(), propertyContext, remoteContextCache = /* @__PURE__ */ new Map()) {
|
|
271
|
+
if (Array.isArray(jsonLd)) {
|
|
272
|
+
for (const item of jsonLd) await assertNoGraphBeforeCompaction(item, documentLoader, inheritedState, propertyContext, remoteContextCache);
|
|
273
|
+
return;
|
|
274
|
+
}
|
|
275
|
+
if (typeof jsonLd !== "object" || jsonLd == null) return;
|
|
276
|
+
const jsonLiteralWrapper = isJsonLiteralWrapper(jsonLd);
|
|
277
|
+
let state = inheritedState;
|
|
278
|
+
if (propertyContext !== void 0) state = await applyGraphAliasContext(state, propertyContext.context, documentLoader, remoteContextCache, propertyContext.baseUrl);
|
|
279
|
+
if ("@context" in jsonLd) state = await applyGraphAliasContext(state, jsonLd["@context"], documentLoader, remoteContextCache);
|
|
280
|
+
for (const [key, value] of globalThis.Object.entries(jsonLd)) {
|
|
281
|
+
if (key === "@context") continue;
|
|
282
|
+
if (jsonLiteralWrapper && key === "@value") continue;
|
|
283
|
+
if (key === "@graph" || state.graphTerms.has(key)) throw new UnsafeJsonLdError("@graph");
|
|
284
|
+
if (state.jsonTerms.has(key)) continue;
|
|
285
|
+
await assertNoGraphBeforeCompaction(value, documentLoader, state, state.propertyContexts.get(key), remoteContextCache);
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
function isJsonLiteralWrapper(value) {
|
|
289
|
+
return "@value" in value && (value["@type"] === "@json" || value.type === "@json");
|
|
290
|
+
}
|
|
291
|
+
/** @internal */
|
|
292
|
+
function assertSafeJsonLd(jsonLd) {
|
|
293
|
+
if (Array.isArray(jsonLd)) for (const item of jsonLd) assertSafeJsonLd(item);
|
|
294
|
+
else if (typeof jsonLd === "object" && jsonLd != null) {
|
|
295
|
+
const jsonLiteralWrapper = isJsonLiteralWrapper(jsonLd);
|
|
296
|
+
for (const [key, value] of globalThis.Object.entries(jsonLd)) {
|
|
297
|
+
if (disallowedJsonLdKeywords.has(key)) throw new UnsafeJsonLdError(key);
|
|
298
|
+
if (jsonLiteralWrapper && key === "@value") continue;
|
|
299
|
+
assertSafeJsonLd(value);
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
}
|
|
21
303
|
/**
|
|
22
304
|
* Attaches a LD signature to the given JSON-LD document.
|
|
23
305
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
@@ -234,9 +516,21 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
234
516
|
* @returns `true` if the document is authentic; `false` otherwise.
|
|
235
517
|
*/
|
|
236
518
|
async function verifyJsonLd(jsonLd, options = {}) {
|
|
519
|
+
return await verifyJsonLdInternal(jsonLd, options, true);
|
|
520
|
+
}
|
|
521
|
+
/** @internal */
|
|
522
|
+
async function verifyCompactJsonLd(jsonLd, options = {}) {
|
|
523
|
+
return await verifyJsonLdInternal(jsonLd, options, false);
|
|
524
|
+
}
|
|
525
|
+
async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
237
526
|
return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version).startActiveSpan("ld_signatures.verify", async (span) => {
|
|
238
527
|
try {
|
|
239
|
-
const
|
|
528
|
+
const verificationOptions = hasSignature(jsonLd) ? {
|
|
529
|
+
...options,
|
|
530
|
+
contextLoader: getNormalizationContextLoader(options.contextLoader)
|
|
531
|
+
} : options;
|
|
532
|
+
const compacted = compact ? hasSignature(jsonLd) ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
|
|
533
|
+
const object = await _fedify_vocab.Object.fromJsonLd(compacted, verificationOptions);
|
|
240
534
|
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
241
535
|
span.setAttribute("activitypub.object.type", (0, _fedify_vocab.getTypeId)(object).href);
|
|
242
536
|
if (typeof jsonLd === "object" && jsonLd != null && "signature" in jsonLd && typeof jsonLd.signature === "object" && jsonLd.signature != null) {
|
|
@@ -246,7 +540,7 @@ async function verifyJsonLd(jsonLd, options = {}) {
|
|
|
246
540
|
}
|
|
247
541
|
const attributions = new Set(object.attributionIds.map((uri) => uri.href));
|
|
248
542
|
if (object instanceof _fedify_vocab.Activity) for (const uri of object.actorIds) attributions.add(uri.href);
|
|
249
|
-
const key = await verifySignature(
|
|
543
|
+
const key = await verifySignature(compacted, verificationOptions);
|
|
250
544
|
if (key == null) return false;
|
|
251
545
|
if (key.ownerId == null) {
|
|
252
546
|
logger$3.debug("Key {keyId} has no owner.", { keyId: key.id?.href });
|
|
@@ -1041,12 +1335,30 @@ async function verifyObject(cls, jsonLd, options = {}) {
|
|
|
1041
1335
|
return object;
|
|
1042
1336
|
}
|
|
1043
1337
|
//#endregion
|
|
1338
|
+
Object.defineProperty(exports, "InvalidContextReferenceError", {
|
|
1339
|
+
enumerable: true,
|
|
1340
|
+
get: function() {
|
|
1341
|
+
return InvalidContextReferenceError;
|
|
1342
|
+
}
|
|
1343
|
+
});
|
|
1344
|
+
Object.defineProperty(exports, "assertSafeJsonLd", {
|
|
1345
|
+
enumerable: true,
|
|
1346
|
+
get: function() {
|
|
1347
|
+
return assertSafeJsonLd;
|
|
1348
|
+
}
|
|
1349
|
+
});
|
|
1044
1350
|
Object.defineProperty(exports, "attachSignature", {
|
|
1045
1351
|
enumerable: true,
|
|
1046
1352
|
get: function() {
|
|
1047
1353
|
return attachSignature;
|
|
1048
1354
|
}
|
|
1049
1355
|
});
|
|
1356
|
+
Object.defineProperty(exports, "compactJsonLd", {
|
|
1357
|
+
enumerable: true,
|
|
1358
|
+
get: function() {
|
|
1359
|
+
return compactJsonLd;
|
|
1360
|
+
}
|
|
1361
|
+
});
|
|
1050
1362
|
Object.defineProperty(exports, "createProof", {
|
|
1051
1363
|
enumerable: true,
|
|
1052
1364
|
get: function() {
|
|
@@ -1077,18 +1389,42 @@ Object.defineProperty(exports, "getKeyOwner", {
|
|
|
1077
1389
|
return getKeyOwner;
|
|
1078
1390
|
}
|
|
1079
1391
|
});
|
|
1392
|
+
Object.defineProperty(exports, "getNormalizationContextLoader", {
|
|
1393
|
+
enumerable: true,
|
|
1394
|
+
get: function() {
|
|
1395
|
+
return getNormalizationContextLoader;
|
|
1396
|
+
}
|
|
1397
|
+
});
|
|
1080
1398
|
Object.defineProperty(exports, "hasProofLike", {
|
|
1081
1399
|
enumerable: true,
|
|
1082
1400
|
get: function() {
|
|
1083
1401
|
return hasProofLike;
|
|
1084
1402
|
}
|
|
1085
1403
|
});
|
|
1404
|
+
Object.defineProperty(exports, "hasSignature", {
|
|
1405
|
+
enumerable: true,
|
|
1406
|
+
get: function() {
|
|
1407
|
+
return hasSignature;
|
|
1408
|
+
}
|
|
1409
|
+
});
|
|
1086
1410
|
Object.defineProperty(exports, "hasSignatureLike", {
|
|
1087
1411
|
enumerable: true,
|
|
1088
1412
|
get: function() {
|
|
1089
1413
|
return hasSignatureLike;
|
|
1090
1414
|
}
|
|
1091
1415
|
});
|
|
1416
|
+
Object.defineProperty(exports, "isClearlyMalformedContextReference", {
|
|
1417
|
+
enumerable: true,
|
|
1418
|
+
get: function() {
|
|
1419
|
+
return isClearlyMalformedContextReference;
|
|
1420
|
+
}
|
|
1421
|
+
});
|
|
1422
|
+
Object.defineProperty(exports, "isInvalidUrlTypeError", {
|
|
1423
|
+
enumerable: true,
|
|
1424
|
+
get: function() {
|
|
1425
|
+
return isInvalidUrlTypeError;
|
|
1426
|
+
}
|
|
1427
|
+
});
|
|
1092
1428
|
Object.defineProperty(exports, "normalizeOutgoingActivityJsonLd", {
|
|
1093
1429
|
enumerable: true,
|
|
1094
1430
|
get: function() {
|
|
@@ -1107,6 +1443,12 @@ Object.defineProperty(exports, "signObject", {
|
|
|
1107
1443
|
return signObject;
|
|
1108
1444
|
}
|
|
1109
1445
|
});
|
|
1446
|
+
Object.defineProperty(exports, "verifyCompactJsonLd", {
|
|
1447
|
+
enumerable: true,
|
|
1448
|
+
get: function() {
|
|
1449
|
+
return verifyCompactJsonLd;
|
|
1450
|
+
}
|
|
1451
|
+
});
|
|
1110
1452
|
Object.defineProperty(exports, "verifyJsonLd", {
|
|
1111
1453
|
enumerable: true,
|
|
1112
1454
|
get: function() {
|
|
@@ -1131,3 +1473,9 @@ Object.defineProperty(exports, "verifySignature", {
|
|
|
1131
1473
|
return verifySignature;
|
|
1132
1474
|
}
|
|
1133
1475
|
});
|
|
1476
|
+
Object.defineProperty(exports, "wrapContextLoaderForJsonLd", {
|
|
1477
|
+
enumerable: true,
|
|
1478
|
+
get: function() {
|
|
1479
|
+
return wrapContextLoaderForJsonLd;
|
|
1480
|
+
}
|
|
1481
|
+
});
|