@fedify/fedify 2.2.0-pr.709.20 → 2.2.0-pr.710.24
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-6NAlCn-K.mjs → builder-CKJTVRhn.mjs} +3 -3
- package/dist/compat/public-audience.test.d.mts +2 -0
- package/dist/compat/public-audience.test.mjs +162 -0
- package/dist/compat/transformers.test.mjs +2 -2
- package/dist/{deno-CWoVKoBl.mjs → deno-cvysscWX.mjs} +1 -1
- package/dist/{docloader-z8BYCZvY.mjs → docloader-BuEazLeK.mjs} +2 -2
- package/dist/federation/builder.test.mjs +2 -2
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +4 -4
- package/dist/federation/idempotency.test.mjs +3 -3
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/keycache.test.mjs +2 -2
- package/dist/federation/kv.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +17 -7
- package/dist/federation/mod.cjs +1 -1
- 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 +3 -3
- package/dist/federation/webfinger.test.mjs +2 -2
- package/dist/{http-cyerYP3k.js → http-B0Tu7TW-.js} +1 -1
- package/dist/{http-B0CGWLm2.cjs → http-BJ7XtRRp.cjs} +1 -1
- package/dist/{http-Cl7YijGX.mjs → http-Dy22pK-t.mjs} +2 -2
- package/dist/{key-DgOxeSHC.mjs → key-DXBoO6CC.mjs} +1 -1
- package/dist/{kv-cache-BhCk5dX_.js → kv-cache-Bxbq9e39.js} +1 -1
- package/dist/{kv-cache-BzAyTibN.cjs → kv-cache-x4KOTSSC.cjs} +1 -1
- package/dist/{ld-BqJAwT8x.mjs → ld-BW_1mHgq.mjs} +2 -2
- package/dist/{middleware-DeRKEGtq.mjs → middleware-BdpMBegR.mjs} +1 -1
- package/dist/{middleware-Dlfri269.mjs → middleware-Bu0zxHoX.mjs} +17 -15
- package/dist/{middleware-CmlDuNnT.js → middleware-COjNuA6A.js} +4 -3
- package/dist/{middleware-CPDkGhht.cjs → middleware-CRFf7Wb6.cjs} +1 -1
- package/dist/{middleware-Dr7gPlVB.cjs → middleware-QpqLtpW9.cjs} +5 -4
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/client.test.mjs +1 -1
- package/dist/nodeinfo/handler.test.mjs +2 -2
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +1 -1
- package/dist/{owner-CBLQ-vDw.mjs → owner-CBdNJRwZ.mjs} +2 -2
- package/dist/{proof-DZpF7E4g.mjs → proof-7MA0dp2c.mjs} +36 -31
- package/dist/{proof-CchoRjI8.cjs → proof-B__J6A1_.cjs} +221 -38
- package/dist/{proof-sJxm6hBB.js → proof-Bfx0NdYz.js} +218 -41
- package/dist/public-audience-5WWE-JTr.mjs +181 -0
- package/dist/{send-Ckd6J9RF.mjs → send-9BckNAN-.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 +2 -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 +60 -2
- 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 +16 -7
- package/skills/fedify/SKILL.md +462 -0
- /package/dist/{activity-listener-Ck3JZ_hR.mjs → activity-listener-CFzUqoCS.mjs} +0 -0
- /package/dist/{client-DEpOVgY1.mjs → client-DVu6Fmom.mjs} +0 -0
- /package/dist/{collection-BD6-SZ6O.mjs → collection-BQRKGS7L.mjs} +0 -0
- /package/dist/{keycache-CCSwkQcY.mjs → keycache-C2t1kvP5.mjs} +0 -0
- /package/dist/{kv-tL2TOE9X.mjs → kv-C-TG81Sv.mjs} +0 -0
- /package/dist/{negotiation-DnsfFF8I.mjs → negotiation-xb0QR3u_.mjs} +0 -0
- /package/dist/{retry-B_E3V_Dx.mjs → retry-CJL0poaU.mjs} +0 -0
- /package/dist/{types-DCP0WLdt.mjs → types-CGUnLkU3.mjs} +0 -0
package/dist/mod.cjs
CHANGED
|
@@ -4,11 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
|
4
4
|
require("./chunk-DDcVe30Y.cjs");
|
|
5
5
|
const require_transformers = require("./transformers-NeAONrAq.cjs");
|
|
6
6
|
require("./compat/mod.cjs");
|
|
7
|
-
const require_http = require("./http-
|
|
8
|
-
const require_middleware = require("./middleware-
|
|
9
|
-
const require_proof = require("./proof-
|
|
7
|
+
const require_http = require("./http-BJ7XtRRp.cjs");
|
|
8
|
+
const require_middleware = require("./middleware-QpqLtpW9.cjs");
|
|
9
|
+
const require_proof = require("./proof-B__J6A1_.cjs");
|
|
10
10
|
const require_types = require("./types-KC4QAoxe.cjs");
|
|
11
|
-
const require_kv_cache = require("./kv-cache-
|
|
11
|
+
const require_kv_cache = require("./kv-cache-x4KOTSSC.cjs");
|
|
12
12
|
const require_federation_mod = require("./federation/mod.cjs");
|
|
13
13
|
require("./nodeinfo/mod.cjs");
|
|
14
14
|
require("./runtime/mod.cjs");
|
package/dist/mod.js
CHANGED
|
@@ -3,11 +3,11 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
import "./chunk-nlSIicah.js";
|
|
4
4
|
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-ve6e2xcg.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 { a as verifyProof, c as
|
|
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-B0Tu7TW-.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-COjNuA6A.js";
|
|
8
|
+
import { a as verifyProof, c as getKeyOwner, d as detachSignature, f as hasSignatureLike, h as verifySignature, i as verifyObject, l as attachSignature, m as verifyJsonLd, n as hasProofLike, p as signJsonLd, r as signObject, s as doesActorOwnKey, t as createProof, u as createSignature } from "./proof-Bfx0NdYz.js";
|
|
9
9
|
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-hvL8ElAs.js";
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-Bxbq9e39.js";
|
|
11
11
|
import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
|
|
12
12
|
import "./nodeinfo/mod.js";
|
|
13
13
|
import "./runtime/mod.js";
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as esm_default } from "../esm-DVILvP5e.mjs";
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-Duiq_YC9.mjs";
|
|
7
|
-
import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-
|
|
7
|
+
import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-DVu6Fmom.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/nodeinfo/client.test.ts
|
|
10
10
|
test("getNodeInfo()", async (t) => {
|
|
@@ -4,8 +4,8 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
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-Duiq_YC9.mjs";
|
|
7
|
-
import { t as MemoryKvStore } from "../kv-
|
|
8
|
-
import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-
|
|
7
|
+
import { t as MemoryKvStore } from "../kv-C-TG81Sv.mjs";
|
|
8
|
+
import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-Bu0zxHoX.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
|
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
|
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import "../std__assert-Duiq_YC9.mjs";
|
|
6
6
|
import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
|
|
7
|
-
import { t as nodeInfoToJson } from "../types-
|
|
7
|
+
import { t as nodeInfoToJson } from "../types-CGUnLkU3.mjs";
|
|
8
8
|
import { test } from "@fedify/fixture";
|
|
9
9
|
//#region src/nodeinfo/types.test.ts
|
|
10
10
|
test("nodeInfoToJson()", () => {
|
|
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
|
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
4
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
5
5
|
import "../std__assert-Duiq_YC9.mjs";
|
|
6
|
-
import { t as MemoryKvStore } from "../kv-
|
|
6
|
+
import { t as MemoryKvStore } from "../kv-C-TG81Sv.mjs";
|
|
7
7
|
import { test } from "@fedify/fixture";
|
|
8
8
|
import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
|
|
9
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -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-cvysscWX.mjs";
|
|
5
|
+
import "./key-DXBoO6CC.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,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 fetchKey, o as validateCryptoKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-cvysscWX.mjs";
|
|
5
|
+
import { n as fetchKey, o as validateCryptoKey } from "./key-DXBoO6CC.mjs";
|
|
6
|
+
import { t as normalizePublicAudience } from "./public-audience-5WWE-JTr.mjs";
|
|
6
7
|
import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
|
|
7
8
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
9
|
import { getLogger } from "@logtape/logtape";
|
|
@@ -56,11 +57,12 @@ function hasProofLike(jsonLd) {
|
|
|
56
57
|
async function createProof(object, privateKey, keyId, { contextLoader, context, created } = {}) {
|
|
57
58
|
validateCryptoKey(privateKey, "private");
|
|
58
59
|
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
59
|
-
|
|
60
|
+
let compactMsg = await object.clone({ proofs: [] }).toJsonLd({
|
|
60
61
|
format: "compact",
|
|
61
62
|
contextLoader,
|
|
62
63
|
context
|
|
63
64
|
});
|
|
65
|
+
compactMsg = await normalizePublicAudience(compactMsg, contextLoader);
|
|
64
66
|
const msgCanon = serialize(compactMsg);
|
|
65
67
|
const encoder = new TextEncoder();
|
|
66
68
|
const msgBytes = encoder.encode(msgCanon);
|
|
@@ -155,27 +157,25 @@ async function verifyProof(jsonLd, proof, options = {}) {
|
|
|
155
157
|
});
|
|
156
158
|
}
|
|
157
159
|
async function verifyProofInternal(jsonLd, proof, options) {
|
|
158
|
-
if (typeof jsonLd !== "object" || proof.cryptosuite !== "eddsa-jcs-2022" || proof.verificationMethodId == null || proof.proofPurpose !== "assertionMethod" || proof.proofValue == null || proof.created == null) return null;
|
|
160
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || proof.cryptosuite !== "eddsa-jcs-2022" || proof.verificationMethodId == null || proof.proofPurpose !== "assertionMethod" || proof.proofValue == null || proof.created == null) return null;
|
|
159
161
|
const publicKeyPromise = fetchKey(proof.verificationMethodId, Multikey, options);
|
|
160
|
-
const
|
|
162
|
+
const proofConfig = {
|
|
161
163
|
"@context": jsonLd["@context"],
|
|
162
164
|
type: "DataIntegrityProof",
|
|
163
165
|
cryptosuite: proof.cryptosuite,
|
|
164
166
|
verificationMethod: proof.verificationMethodId.href,
|
|
165
167
|
proofPurpose: proof.proofPurpose,
|
|
166
168
|
created: proof.created.toString()
|
|
167
|
-
}
|
|
169
|
+
};
|
|
168
170
|
const encoder = new TextEncoder();
|
|
169
|
-
const proofBytes = encoder.encode(
|
|
171
|
+
const proofBytes = encoder.encode(serialize(proofConfig));
|
|
170
172
|
const proofDigest = await crypto.subtle.digest("SHA-256", proofBytes);
|
|
171
173
|
const msg = { ...jsonLd };
|
|
172
174
|
if ("proof" in msg) delete msg.proof;
|
|
173
|
-
|
|
174
|
-
const
|
|
175
|
-
const
|
|
176
|
-
|
|
177
|
-
digest.set(new Uint8Array(proofDigest), 0);
|
|
178
|
-
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
175
|
+
if ("https://w3id.org/security#proof" in msg) delete msg["https://w3id.org/security#proof"];
|
|
176
|
+
const candidates = [msg];
|
|
177
|
+
const normalized = await normalizePublicAudience(msg, options.contextLoader);
|
|
178
|
+
if (normalized !== msg) candidates.push(normalized);
|
|
179
179
|
let fetchedKey;
|
|
180
180
|
try {
|
|
181
181
|
fetchedKey = await publicKeyPromise;
|
|
@@ -204,7 +204,7 @@ async function verifyProofInternal(jsonLd, proof, options) {
|
|
|
204
204
|
return await verifyProof(jsonLd, proof, {
|
|
205
205
|
...options,
|
|
206
206
|
keyCache: {
|
|
207
|
-
get: () => Promise.resolve(
|
|
207
|
+
get: () => Promise.resolve(void 0),
|
|
208
208
|
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
209
209
|
}
|
|
210
210
|
});
|
|
@@ -215,27 +215,32 @@ async function verifyProofInternal(jsonLd, proof, options) {
|
|
|
215
215
|
});
|
|
216
216
|
return null;
|
|
217
217
|
}
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
logger.debug("Failed to verify the proof with the fetched key {keyId}:\n{proof}", {
|
|
218
|
+
const digest = new Uint8Array(proofDigest.byteLength + 32);
|
|
219
|
+
digest.set(new Uint8Array(proofDigest), 0);
|
|
220
|
+
for (const candidate of candidates) {
|
|
221
|
+
const msgBytes = encoder.encode(serialize(candidate));
|
|
222
|
+
const msgDigest = await crypto.subtle.digest("SHA-256", msgBytes);
|
|
223
|
+
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
224
|
+
if (await crypto.subtle.verify("Ed25519", publicKey.publicKey, proof.proofValue.slice(), digest)) return publicKey;
|
|
225
|
+
}
|
|
226
|
+
if (fetchedKey.cached) {
|
|
227
|
+
logger.debug("Failed to verify the proof with the cached key {keyId}; retrying with the freshly fetched key...", {
|
|
233
228
|
keyId: proof.verificationMethodId.href,
|
|
234
229
|
proof
|
|
235
230
|
});
|
|
236
|
-
return
|
|
231
|
+
return await verifyProof(jsonLd, proof, {
|
|
232
|
+
...options,
|
|
233
|
+
keyCache: {
|
|
234
|
+
get: () => Promise.resolve(void 0),
|
|
235
|
+
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
236
|
+
}
|
|
237
|
+
});
|
|
237
238
|
}
|
|
238
|
-
|
|
239
|
+
logger.debug("Failed to verify the proof with the fetched key {keyId}:\n{proof}", {
|
|
240
|
+
keyId: proof.verificationMethodId.href,
|
|
241
|
+
proof
|
|
242
|
+
});
|
|
243
|
+
return null;
|
|
239
244
|
}
|
|
240
245
|
/**
|
|
241
246
|
* Verifies the given object. It will verify all the proofs in the object,
|
|
@@ -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-BJ7XtRRp.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");
|
|
@@ -13,7 +13,7 @@ _fedify_vocab_runtime_jsonld = require_chunk.__toESM(_fedify_vocab_runtime_jsonl
|
|
|
13
13
|
let json_canon = require("json-canon");
|
|
14
14
|
json_canon = require_chunk.__toESM(json_canon);
|
|
15
15
|
//#region src/sig/ld.ts
|
|
16
|
-
const logger$
|
|
16
|
+
const logger$2 = (0, _logtape_logtape.getLogger)([
|
|
17
17
|
"fedify",
|
|
18
18
|
"sig",
|
|
19
19
|
"ld"
|
|
@@ -161,7 +161,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
161
161
|
try {
|
|
162
162
|
signature = (0, byte_encodings_base64.decodeBase64)(sig.signatureValue);
|
|
163
163
|
} catch (error) {
|
|
164
|
-
logger$
|
|
164
|
+
logger$2.debug("Failed to verify; invalid base64 signatureValue: {signatureValue}", {
|
|
165
165
|
...sig,
|
|
166
166
|
error
|
|
167
167
|
});
|
|
@@ -180,7 +180,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
180
180
|
try {
|
|
181
181
|
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
|
|
182
182
|
} catch (error) {
|
|
183
|
-
logger$
|
|
183
|
+
logger$2.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
|
|
184
184
|
signatureOptions: sigOpts,
|
|
185
185
|
error
|
|
186
186
|
});
|
|
@@ -192,7 +192,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
192
192
|
try {
|
|
193
193
|
docHash = await hashJsonLd(document, options.contextLoader);
|
|
194
194
|
} catch (error) {
|
|
195
|
-
logger$
|
|
195
|
+
logger$2.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
|
|
196
196
|
document,
|
|
197
197
|
error
|
|
198
198
|
});
|
|
@@ -203,7 +203,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
203
203
|
const messageBytes = encoder.encode(message);
|
|
204
204
|
if (await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes)) return key;
|
|
205
205
|
if (cached) {
|
|
206
|
-
logger$
|
|
206
|
+
logger$2.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
|
|
207
207
|
keyId: sig.creator,
|
|
208
208
|
...sig
|
|
209
209
|
});
|
|
@@ -217,7 +217,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
217
217
|
if (key == null) return null;
|
|
218
218
|
return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes) ? key : null;
|
|
219
219
|
}
|
|
220
|
-
logger$
|
|
220
|
+
logger$2.debug("Failed to verify with the fetched key {keyId}; signature {signatureValue} is invalid. Check if the key is correct or if the signed message is correct. The message to sign is:\n{message}", {
|
|
221
221
|
keyId: sig.creator,
|
|
222
222
|
...sig,
|
|
223
223
|
message
|
|
@@ -249,12 +249,12 @@ async function verifyJsonLd(jsonLd, options = {}) {
|
|
|
249
249
|
const key = await verifySignature(jsonLd, options);
|
|
250
250
|
if (key == null) return false;
|
|
251
251
|
if (key.ownerId == null) {
|
|
252
|
-
logger$
|
|
252
|
+
logger$2.debug("Key {keyId} has no owner.", { keyId: key.id?.href });
|
|
253
253
|
return false;
|
|
254
254
|
}
|
|
255
255
|
attributions.delete(key.ownerId.href);
|
|
256
256
|
if (attributions.size > 0) {
|
|
257
|
-
logger$
|
|
257
|
+
logger$2.debug("Some attributions are not authenticated by the Linked Data Signatures: {attributions}.", { attributions: [...attributions] });
|
|
258
258
|
return false;
|
|
259
259
|
}
|
|
260
260
|
return true;
|
|
@@ -389,6 +389,179 @@ async function getKeyOwner(keyId, options) {
|
|
|
389
389
|
return null;
|
|
390
390
|
}
|
|
391
391
|
//#endregion
|
|
392
|
+
//#region src/compat/public-audience.ts
|
|
393
|
+
const logger$1 = (0, _logtape_logtape.getLogger)([
|
|
394
|
+
"fedify",
|
|
395
|
+
"compat",
|
|
396
|
+
"public-audience"
|
|
397
|
+
]);
|
|
398
|
+
const PUBLIC_ADDRESSING_FIELDS = new Set([
|
|
399
|
+
"to",
|
|
400
|
+
"cc",
|
|
401
|
+
"bto",
|
|
402
|
+
"bcc",
|
|
403
|
+
"audience"
|
|
404
|
+
]);
|
|
405
|
+
const preloadedOnlyDocumentLoader = (url) => {
|
|
406
|
+
if (url in _fedify_vocab_runtime.preloadedContexts) return Promise.resolve({
|
|
407
|
+
contextUrl: null,
|
|
408
|
+
documentUrl: url,
|
|
409
|
+
document: _fedify_vocab_runtime.preloadedContexts[url]
|
|
410
|
+
});
|
|
411
|
+
return Promise.reject(/* @__PURE__ */ new Error("Refusing to fetch a non-preloaded JSON-LD context: " + url));
|
|
412
|
+
};
|
|
413
|
+
const AS_CONTEXT_URL = "https://www.w3.org/ns/activitystreams";
|
|
414
|
+
const MAX_TRAVERSAL_DEPTH = 64;
|
|
415
|
+
const KNOWN_SAFE_CONTEXT_URLS = new Set(Object.keys(_fedify_vocab_runtime.preloadedContexts));
|
|
416
|
+
function hasPublicCurieInAddressing(value, parentKey, depth = 0) {
|
|
417
|
+
if (typeof value === "string") return parentKey != null && PUBLIC_ADDRESSING_FIELDS.has(parentKey) && (value === "as:Public" || value === "Public");
|
|
418
|
+
if (depth >= MAX_TRAVERSAL_DEPTH) return false;
|
|
419
|
+
if (Array.isArray(value)) return value.some((item) => hasPublicCurieInAddressing(item, parentKey, depth + 1));
|
|
420
|
+
if (typeof value !== "object" || value == null) return false;
|
|
421
|
+
const record = value;
|
|
422
|
+
for (const key of Object.keys(record)) {
|
|
423
|
+
if (key === "@context") continue;
|
|
424
|
+
if (hasPublicCurieInAddressing(record[key], key, depth + 1)) return true;
|
|
425
|
+
}
|
|
426
|
+
return false;
|
|
427
|
+
}
|
|
428
|
+
function rewritePublicAudience(value, parentKey, depth = 0) {
|
|
429
|
+
if (typeof value === "string" && parentKey != null && PUBLIC_ADDRESSING_FIELDS.has(parentKey) && (value === "as:Public" || value === "Public")) return _fedify_vocab.PUBLIC_COLLECTION.href;
|
|
430
|
+
if (depth >= MAX_TRAVERSAL_DEPTH) return value;
|
|
431
|
+
if (Array.isArray(value)) {
|
|
432
|
+
let changed = false;
|
|
433
|
+
const mapped = value.map((item) => {
|
|
434
|
+
const rewritten = rewritePublicAudience(item, parentKey, depth + 1);
|
|
435
|
+
if (rewritten !== item) changed = true;
|
|
436
|
+
return rewritten;
|
|
437
|
+
});
|
|
438
|
+
return changed ? mapped : value;
|
|
439
|
+
}
|
|
440
|
+
if (typeof value !== "object" || value == null) return value;
|
|
441
|
+
const record = value;
|
|
442
|
+
let changed = false;
|
|
443
|
+
const normalized = {};
|
|
444
|
+
for (const key of Object.keys(record)) {
|
|
445
|
+
const rewritten = key === "@context" ? record[key] : rewritePublicAudience(record[key], key, depth + 1);
|
|
446
|
+
if (rewritten !== record[key]) changed = true;
|
|
447
|
+
normalized[key] = rewritten;
|
|
448
|
+
}
|
|
449
|
+
return changed ? normalized : value;
|
|
450
|
+
}
|
|
451
|
+
/**
|
|
452
|
+
* Reports whether `value` carries an `@context` property anywhere inside
|
|
453
|
+
* its subtree (not counting the value itself). A nested `@context` can
|
|
454
|
+
* introduce a local term-definition scope that redefines `as:` or `Public`
|
|
455
|
+
* even when the top-level `@context` is safe, so the fast path must defer
|
|
456
|
+
* to the URDNA2015 equivalence check whenever one is present.
|
|
457
|
+
*/
|
|
458
|
+
function hasNestedContext(value, depth = 0) {
|
|
459
|
+
if (depth >= MAX_TRAVERSAL_DEPTH) return true;
|
|
460
|
+
if (Array.isArray(value)) return value.some((item) => hasNestedContext(item, depth + 1));
|
|
461
|
+
if (typeof value !== "object" || value == null) return false;
|
|
462
|
+
const record = value;
|
|
463
|
+
for (const key of Object.keys(record)) {
|
|
464
|
+
if (key === "@context") return true;
|
|
465
|
+
if (hasNestedContext(record[key], depth + 1)) return true;
|
|
466
|
+
}
|
|
467
|
+
return false;
|
|
468
|
+
}
|
|
469
|
+
/**
|
|
470
|
+
* Checks whether the `@context` of a JSON-LD document is guaranteed not
|
|
471
|
+
* to redefine the `as:` prefix or the bare `Public` term. Only documents
|
|
472
|
+
* whose `@context` is a string, or an array of strings, drawn from Fedify's
|
|
473
|
+
* preloaded context set AND including the ActivityStreams URL qualify,
|
|
474
|
+
* AND no nested subtree carries its own `@context` that might redefine
|
|
475
|
+
* those terms within a local scope. When all of that holds the rewrite
|
|
476
|
+
* is provably semantics-preserving and the URDNA2015 equivalence check
|
|
477
|
+
* can be skipped. Any other shape (unknown external URLs, inline
|
|
478
|
+
* objects at the top level, nested `@context` blocks) is treated as
|
|
479
|
+
* potentially unsafe.
|
|
480
|
+
*/
|
|
481
|
+
function hasKnownSafeContext(jsonLd) {
|
|
482
|
+
if (typeof jsonLd !== "object" || jsonLd == null) return false;
|
|
483
|
+
const record = jsonLd;
|
|
484
|
+
if (!Object.hasOwn(record, "@context")) return false;
|
|
485
|
+
const ctx = record["@context"];
|
|
486
|
+
const entries = typeof ctx === "string" ? [ctx] : Array.isArray(ctx) ? ctx : null;
|
|
487
|
+
if (entries == null || entries.length === 0) return false;
|
|
488
|
+
let hasAs = false;
|
|
489
|
+
for (const entry of entries) {
|
|
490
|
+
if (typeof entry !== "string") return false;
|
|
491
|
+
if (!KNOWN_SAFE_CONTEXT_URLS.has(entry)) return false;
|
|
492
|
+
if (entry === AS_CONTEXT_URL) hasAs = true;
|
|
493
|
+
}
|
|
494
|
+
if (!hasAs) return false;
|
|
495
|
+
for (const key of Object.keys(record)) {
|
|
496
|
+
if (key === "@context") continue;
|
|
497
|
+
if (hasNestedContext(record[key])) return false;
|
|
498
|
+
}
|
|
499
|
+
return true;
|
|
500
|
+
}
|
|
501
|
+
/**
|
|
502
|
+
* Rewrites the compact `as:Public` / `Public` CURIE appearing in activity
|
|
503
|
+
* addressing fields (`to`, `cc`, `bto`, `bcc`, `audience`) to the fully
|
|
504
|
+
* expanded `https://www.w3.org/ns/activitystreams#Public` URI.
|
|
505
|
+
*
|
|
506
|
+
* Several ActivityPub implementations, Lemmy among them, match these
|
|
507
|
+
* fields as plain URLs without running JSON-LD expansion, and silently
|
|
508
|
+
* drop activities whose public addressing appears in CURIE form. This
|
|
509
|
+
* helper works around that gap.
|
|
510
|
+
*
|
|
511
|
+
* For documents whose `@context` is drawn entirely from Fedify's
|
|
512
|
+
* preloaded context set and includes the ActivityStreams URL, the
|
|
513
|
+
* rewrite is applied directly: the content of every preloaded non-AS
|
|
514
|
+
* context is known not to redefine the `as:` prefix or the bare `Public`
|
|
515
|
+
* term, so the semantics are preserved by construction. Any other
|
|
516
|
+
* shape (an inline object, an unknown external URL, and so on) is
|
|
517
|
+
* treated as potentially unsafe and gated on a JSON-LD equivalence
|
|
518
|
+
* check; both forms are canonicalized with URDNA2015 and the resulting
|
|
519
|
+
* N-Quads are compared. When they differ, the original document is
|
|
520
|
+
* returned unchanged. Canonicalization failures also fall back to the
|
|
521
|
+
* original document.
|
|
522
|
+
*
|
|
523
|
+
* When no `contextLoader` is supplied the helper falls back to an
|
|
524
|
+
* internal loader that resolves only the URLs in Fedify's
|
|
525
|
+
* preloaded-contexts set and rejects every other URL without issuing a
|
|
526
|
+
* network request. That behaviour is deliberately narrower than
|
|
527
|
+
* `@fedify/vocab-runtime`'s `getDocumentLoader()`, which after its
|
|
528
|
+
* `validatePublicUrl` check will happily fetch non-preloaded URLs: the
|
|
529
|
+
* helper is reached from verification paths (`verifyProof()` /
|
|
530
|
+
* `verifyObject()`) that operate on inbound, potentially adversarial
|
|
531
|
+
* JSON-LD, and a default loader that fetches attacker-supplied
|
|
532
|
+
* `@context` URLs on the caller's behalf would be an SSRF vector.
|
|
533
|
+
* Canonicalization failures against the restricted loader fall back to
|
|
534
|
+
* the original document, same as any other canonicalization error.
|
|
535
|
+
* Callers that genuinely need the remote-fetch loader (for example
|
|
536
|
+
* applications that sign local JSON-LD against a custom vocabulary)
|
|
537
|
+
* should pass a `contextLoader` explicitly.
|
|
538
|
+
*
|
|
539
|
+
* Must be called before any signing step that canonicalizes the
|
|
540
|
+
* compact form byte-for-byte (for example, Object Integrity Proofs
|
|
541
|
+
* using the `eddsa-jcs-2022` cryptosuite), so the signed payload
|
|
542
|
+
* matches what is sent on the wire.
|
|
543
|
+
*/
|
|
544
|
+
async function normalizePublicAudience(jsonLd, contextLoader) {
|
|
545
|
+
if (!hasPublicCurieInAddressing(jsonLd)) return jsonLd;
|
|
546
|
+
const normalized = rewritePublicAudience(jsonLd);
|
|
547
|
+
if (hasKnownSafeContext(jsonLd)) return normalized;
|
|
548
|
+
const loader = contextLoader ?? preloadedOnlyDocumentLoader;
|
|
549
|
+
try {
|
|
550
|
+
const [before, after] = await Promise.all([_fedify_vocab_runtime_jsonld.default.canonize(jsonLd, {
|
|
551
|
+
format: "application/n-quads",
|
|
552
|
+
documentLoader: loader
|
|
553
|
+
}), _fedify_vocab_runtime_jsonld.default.canonize(normalized, {
|
|
554
|
+
format: "application/n-quads",
|
|
555
|
+
documentLoader: loader
|
|
556
|
+
})]);
|
|
557
|
+
if (before === after) return normalized;
|
|
558
|
+
logger$1.warn("Expanding the public audience CURIE to its full URI would change the canonical form of the activity; sending the activity as is. This usually means the active JSON-LD context redefines the `as:` prefix or the bare `Public` term.");
|
|
559
|
+
} catch (error) {
|
|
560
|
+
logger$1.debug("Failed to verify public audience normalization equivalence via JSON-LD canonicalization; sending the activity as is.\n{error}", { error });
|
|
561
|
+
}
|
|
562
|
+
return jsonLd;
|
|
563
|
+
}
|
|
564
|
+
//#endregion
|
|
392
565
|
//#region src/sig/proof.ts
|
|
393
566
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
394
567
|
"fedify",
|
|
@@ -437,11 +610,12 @@ function hasProofLike(jsonLd) {
|
|
|
437
610
|
async function createProof(object, privateKey, keyId, { contextLoader, context, created } = {}) {
|
|
438
611
|
require_http.validateCryptoKey(privateKey, "private");
|
|
439
612
|
if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
440
|
-
|
|
613
|
+
let compactMsg = await object.clone({ proofs: [] }).toJsonLd({
|
|
441
614
|
format: "compact",
|
|
442
615
|
contextLoader,
|
|
443
616
|
context
|
|
444
617
|
});
|
|
618
|
+
compactMsg = await normalizePublicAudience(compactMsg, contextLoader);
|
|
445
619
|
const msgCanon = (0, json_canon.default)(compactMsg);
|
|
446
620
|
const encoder = new TextEncoder();
|
|
447
621
|
const msgBytes = encoder.encode(msgCanon);
|
|
@@ -536,27 +710,25 @@ async function verifyProof(jsonLd, proof, options = {}) {
|
|
|
536
710
|
});
|
|
537
711
|
}
|
|
538
712
|
async function verifyProofInternal(jsonLd, proof, options) {
|
|
539
|
-
if (typeof jsonLd !== "object" || proof.cryptosuite !== "eddsa-jcs-2022" || proof.verificationMethodId == null || proof.proofPurpose !== "assertionMethod" || proof.proofValue == null || proof.created == null) return null;
|
|
713
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || proof.cryptosuite !== "eddsa-jcs-2022" || proof.verificationMethodId == null || proof.proofPurpose !== "assertionMethod" || proof.proofValue == null || proof.created == null) return null;
|
|
540
714
|
const publicKeyPromise = require_http.fetchKey(proof.verificationMethodId, _fedify_vocab.Multikey, options);
|
|
541
|
-
const
|
|
715
|
+
const proofConfig = {
|
|
542
716
|
"@context": jsonLd["@context"],
|
|
543
717
|
type: "DataIntegrityProof",
|
|
544
718
|
cryptosuite: proof.cryptosuite,
|
|
545
719
|
verificationMethod: proof.verificationMethodId.href,
|
|
546
720
|
proofPurpose: proof.proofPurpose,
|
|
547
721
|
created: proof.created.toString()
|
|
548
|
-
}
|
|
722
|
+
};
|
|
549
723
|
const encoder = new TextEncoder();
|
|
550
|
-
const proofBytes = encoder.encode(
|
|
724
|
+
const proofBytes = encoder.encode((0, json_canon.default)(proofConfig));
|
|
551
725
|
const proofDigest = await crypto.subtle.digest("SHA-256", proofBytes);
|
|
552
726
|
const msg = { ...jsonLd };
|
|
553
727
|
if ("proof" in msg) delete msg.proof;
|
|
554
|
-
|
|
555
|
-
const
|
|
556
|
-
const
|
|
557
|
-
|
|
558
|
-
digest.set(new Uint8Array(proofDigest), 0);
|
|
559
|
-
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
728
|
+
if ("https://w3id.org/security#proof" in msg) delete msg["https://w3id.org/security#proof"];
|
|
729
|
+
const candidates = [msg];
|
|
730
|
+
const normalized = await normalizePublicAudience(msg, options.contextLoader);
|
|
731
|
+
if (normalized !== msg) candidates.push(normalized);
|
|
560
732
|
let fetchedKey;
|
|
561
733
|
try {
|
|
562
734
|
fetchedKey = await publicKeyPromise;
|
|
@@ -585,7 +757,7 @@ async function verifyProofInternal(jsonLd, proof, options) {
|
|
|
585
757
|
return await verifyProof(jsonLd, proof, {
|
|
586
758
|
...options,
|
|
587
759
|
keyCache: {
|
|
588
|
-
get: () => Promise.resolve(
|
|
760
|
+
get: () => Promise.resolve(void 0),
|
|
589
761
|
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
590
762
|
}
|
|
591
763
|
});
|
|
@@ -596,27 +768,32 @@ async function verifyProofInternal(jsonLd, proof, options) {
|
|
|
596
768
|
});
|
|
597
769
|
return null;
|
|
598
770
|
}
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
610
|
-
}
|
|
611
|
-
});
|
|
612
|
-
}
|
|
613
|
-
logger.debug("Failed to verify the proof with the fetched key {keyId}:\n{proof}", {
|
|
771
|
+
const digest = new Uint8Array(proofDigest.byteLength + 32);
|
|
772
|
+
digest.set(new Uint8Array(proofDigest), 0);
|
|
773
|
+
for (const candidate of candidates) {
|
|
774
|
+
const msgBytes = encoder.encode((0, json_canon.default)(candidate));
|
|
775
|
+
const msgDigest = await crypto.subtle.digest("SHA-256", msgBytes);
|
|
776
|
+
digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
|
|
777
|
+
if (await crypto.subtle.verify("Ed25519", publicKey.publicKey, proof.proofValue.slice(), digest)) return publicKey;
|
|
778
|
+
}
|
|
779
|
+
if (fetchedKey.cached) {
|
|
780
|
+
logger.debug("Failed to verify the proof with the cached key {keyId}; retrying with the freshly fetched key...", {
|
|
614
781
|
keyId: proof.verificationMethodId.href,
|
|
615
782
|
proof
|
|
616
783
|
});
|
|
617
|
-
return
|
|
784
|
+
return await verifyProof(jsonLd, proof, {
|
|
785
|
+
...options,
|
|
786
|
+
keyCache: {
|
|
787
|
+
get: () => Promise.resolve(void 0),
|
|
788
|
+
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
789
|
+
}
|
|
790
|
+
});
|
|
618
791
|
}
|
|
619
|
-
|
|
792
|
+
logger.debug("Failed to verify the proof with the fetched key {keyId}:\n{proof}", {
|
|
793
|
+
keyId: proof.verificationMethodId.href,
|
|
794
|
+
proof
|
|
795
|
+
});
|
|
796
|
+
return null;
|
|
620
797
|
}
|
|
621
798
|
/**
|
|
622
799
|
* Verifies the given object. It will verify all the proofs in the object,
|
|
@@ -705,6 +882,12 @@ Object.defineProperty(exports, "hasSignatureLike", {
|
|
|
705
882
|
return hasSignatureLike;
|
|
706
883
|
}
|
|
707
884
|
});
|
|
885
|
+
Object.defineProperty(exports, "normalizePublicAudience", {
|
|
886
|
+
enumerable: true,
|
|
887
|
+
get: function() {
|
|
888
|
+
return normalizePublicAudience;
|
|
889
|
+
}
|
|
890
|
+
});
|
|
708
891
|
Object.defineProperty(exports, "signJsonLd", {
|
|
709
892
|
enumerable: true,
|
|
710
893
|
get: function() {
|