@fedify/fedify 2.3.16-dev.2845 → 2.3.16
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/attachment-arrays-BlfpZlWF.mjs +16 -0
- package/dist/{builder-B9apzaoK.mjs → builder-D4GE1Gmi.mjs} +3 -3
- package/dist/callback-kR_sx2zZ.d.mts +2661 -0
- package/dist/{client-BIBzqEIp.d.cts → client-9DPcy_Yx.d.ts} +16 -0
- package/dist/{client-jE7oGvRh.d.ts → client-B3ruDgWg.d.cts} +16 -0
- package/dist/{client-DpUNYKla.mjs → client-DFgYVbUA.mjs} +86 -11
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-CE_Tj_Oc.d.cts → context-CEE8vl-b.d.cts} +31 -14
- package/dist/{context-H_5tZXg-.d.ts → context-CTJwXHRu.d.ts} +31 -14
- package/dist/{deno-CgHxPWA-.mjs → deno-FtdqgHJA.mjs} +1 -1
- package/dist/{docloader-CYscMv4m.mjs → docloader-B9iU4DP2.mjs} +2 -2
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/circuit-breaker.test.mjs +2 -2
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1191 -16
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +293 -3
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CfxAK-RL.cjs → http-2RyDQ0tE.cjs} +6 -4
- package/dist/{http-DmP0sr2l.d.ts → http-Bs5mXWlH.d.ts} +3 -3
- package/dist/{http-CZPYFK3b.d.cts → http-D8DgRhHU.d.cts} +3 -3
- package/dist/{http-dzXtCtOp.mjs → http-D8tiOrZf.mjs} +7 -5
- package/dist/{http-BzIb8Gk0.js → http-mLeLYFj-.js} +6 -4
- package/dist/{inbox-BMytDl21.mjs → inbox-Dy8awbi8.mjs} +2 -2
- package/dist/{key-fdTPEBhG.mjs → key-o1SmN5s0.mjs} +4 -3
- package/dist/{kv-cache-ShxnSuNt.mjs → kv-cache-BwUrzCVO.mjs} +1 -1
- package/dist/{kv-cache-dQUFD_pa.cjs → kv-cache-CI6Z0WiS.cjs} +1 -1
- package/dist/{kv-cache-CwqJUNNd.js → kv-cache-Dsq8C8D8.js} +1 -1
- package/dist/{ld-B8mU49Dg.mjs → ld-DCKrqj9y.mjs} +155 -22
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{metrics-C0ZYkgVy.mjs → metrics-CaoYRhNH.mjs} +1 -1
- package/dist/{middleware-DK_kGeMl.mjs → middleware-4p3opEMT.mjs} +1 -1
- package/dist/{middleware-9mBkHYci.cjs → middleware-CP-8P7kk.cjs} +492 -117
- package/dist/{middleware-D0GPqg_7.js → middleware-Cce0nLDw.js} +491 -117
- package/dist/{middleware-Hr9ci9uD.mjs → middleware-D31fNcY4.mjs} +399 -109
- package/dist/{mod-C_gFmeNq.d.cts → mod-BD0-_vya.d.ts} +31 -13
- package/dist/{mod-HQXFvOHs.d.ts → mod-BMX6nsHP.d.cts} +31 -13
- package/dist/{mod-CDFFESfL.d.ts → mod-BTvP5Hva.d.ts} +1 -1
- package/dist/{mod-DMjhnFbg.d.ts → mod-DgMTlwUO.d.ts} +3 -3
- package/dist/{mod-DDVkmZ_h.d.cts → mod-Q1Fo3FJk.d.cts} +3 -3
- package/dist/{mod-DDjtbkZO.d.cts → mod-n51LED4J.d.cts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +432 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/{outgoing-jsonld-D4iTv7uM.mjs → outgoing-jsonld-BZEAVK_Q.mjs} +38 -8
- package/dist/{owner-BqnaV4zl.mjs → owner-Bdj0nHhf.mjs} +2 -2
- package/dist/{proof-BSRF2hIP.js → proof-B9XJiyz-.js} +1030 -858
- package/dist/{proof-D9VX-J1n.cjs → proof-CmcP8yqP.cjs} +1243 -1059
- package/dist/{proof-BvpOtXRD.mjs → proof-DrbjYma9.mjs} +41 -16
- package/dist/{send-BPel6SCW.mjs → send-VD_WG3dN.mjs} +100 -22
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/proof.test.mjs +96 -4
- package/dist/{temporal-CaD1O1QX.mjs → temporal-CMvoB-vD.mjs} +3 -5
- package/dist/testing/mod.d.mts +2 -2476
- package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
- package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
- 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.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -6
- /package/dist/{activity-listener-tztVvlNb.mjs → activity-listener-BeTGV3wc.mjs} +0 -0
- /package/dist/{circuit-breaker-D1fxthDI.mjs → circuit-breaker-B1fLHmg2.mjs} +0 -0
- /package/dist/{circuit-breaker-test-utils-CAdwjgMi.mjs → circuit-breaker-test-utils-BGHm_MsT.mjs} +0 -0
- /package/dist/{collection-Cc3DVAhE.mjs → collection-Dp5ky45w.mjs} +0 -0
- /package/dist/{negotiation-DDstyBvc.mjs → negotiation-DC8nG6J_.mjs} +0 -0
- /package/dist/{public-audience-Dp4ZScSr.mjs → public-audience-rnYUGj8a.mjs} +0 -0
- /package/dist/{retry-CXg_MBI-.mjs → retry-C4G_vIgv.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { p as recordDocumentCache } from "./metrics-
|
|
4
|
+
import { p as recordDocumentCache } from "./metrics-CaoYRhNH.mjs";
|
|
5
5
|
import { getLogger } from "@logtape/logtape";
|
|
6
6
|
import { preloadedContexts } from "@fedify/vocab-runtime";
|
|
7
7
|
//#region src/utils/kv-cache.ts
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
require("./chunk-DDcVe30Y.cjs");
|
|
4
|
-
const require_http = require("./http-
|
|
4
|
+
const require_http = require("./http-2RyDQ0tE.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
|
|
7
7
|
let es_toolkit = require("es-toolkit");
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { T as recordDocumentCache, f as validateCryptoKey, t as doubleKnockScoped } from "./http-
|
|
3
|
+
import { T as recordDocumentCache, f as validateCryptoKey, t as doubleKnockScoped } from "./http-mLeLYFj-.js";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest, preloadedContexts } from "@fedify/vocab-runtime";
|
|
6
6
|
import { curry } from "es-toolkit";
|
|
@@ -1,13 +1,14 @@
|
|
|
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, s as measureSignatureKeyFetch } from "./metrics-
|
|
6
|
-
import { r as fetchKey, s as validateCryptoKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-FtdqgHJA.mjs";
|
|
5
|
+
import { n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch } from "./metrics-CaoYRhNH.mjs";
|
|
6
|
+
import { r as fetchKey, s as validateCryptoKey } from "./key-o1SmN5s0.mjs";
|
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
|
8
8
|
import { Activity, CryptographicKey, Object as Object$1, getTypeId } from "@fedify/vocab";
|
|
9
9
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
10
|
-
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
10
|
+
import { getDocumentLoader, preloadedContexts } from "@fedify/vocab-runtime";
|
|
11
|
+
import { asCryptoKey } from "@fedify/vocab-runtime/internal";
|
|
11
12
|
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
12
13
|
import { encodeHex } from "byte-encodings/hex";
|
|
13
14
|
import jsonld from "@fedify/vocab-runtime/jsonld";
|
|
@@ -301,24 +302,110 @@ function assertSafeJsonLd(jsonLd) {
|
|
|
301
302
|
}
|
|
302
303
|
}
|
|
303
304
|
}
|
|
305
|
+
const signatureTermDefinition = { "signature": "https://w3id.org/security#signature" };
|
|
306
|
+
const signatureDefiningContexts = new Set(["https://w3id.org/identity/v1", "https://w3id.org/security/v1"]);
|
|
307
|
+
const signatureFreeContexts = getSignatureFreeContexts();
|
|
308
|
+
function getSignatureFreeContexts() {
|
|
309
|
+
const urls = /* @__PURE__ */ new Set();
|
|
310
|
+
for (const [url, document] of globalThis.Object.entries(preloadedContexts)) {
|
|
311
|
+
if (typeof document !== "object" || document == null) continue;
|
|
312
|
+
const context = document["@context"];
|
|
313
|
+
if (typeof context !== "object" || context == null || Array.isArray(context)) continue;
|
|
314
|
+
const record = context;
|
|
315
|
+
if (!globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) urls.add(url);
|
|
316
|
+
}
|
|
317
|
+
return urls;
|
|
318
|
+
}
|
|
319
|
+
function getContextEntryEffect(entry) {
|
|
320
|
+
if (entry == null) return "resets";
|
|
321
|
+
if (typeof entry === "string") {
|
|
322
|
+
if (signatureDefiningContexts.has(entry)) return "defines";
|
|
323
|
+
if (signatureFreeContexts.has(entry)) return "absent";
|
|
324
|
+
return "unknown";
|
|
325
|
+
}
|
|
326
|
+
if (typeof entry !== "object") return "absent";
|
|
327
|
+
const record = entry;
|
|
328
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) {
|
|
329
|
+
const definition = record["signature"];
|
|
330
|
+
const contextProtected = record["@protected"] === true;
|
|
331
|
+
const imported = globalThis.Object.prototype.hasOwnProperty.call(record, "@import");
|
|
332
|
+
if (definition == null) {
|
|
333
|
+
if (contextProtected) return "defines";
|
|
334
|
+
return imported ? "unknown" : "resets";
|
|
335
|
+
}
|
|
336
|
+
if (typeof definition === "object" && !Array.isArray(definition)) {
|
|
337
|
+
const term = definition;
|
|
338
|
+
const protectedTerm = contextProtected || term["@protected"] === true;
|
|
339
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(term, "@id") && term["@id"] == null) {
|
|
340
|
+
if (protectedTerm) return "defines";
|
|
341
|
+
return imported ? "unknown" : "resets";
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
return "defines";
|
|
345
|
+
}
|
|
346
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(record, "@import")) return "unknown";
|
|
347
|
+
return "absent";
|
|
348
|
+
}
|
|
349
|
+
function getSignatureTermState(context) {
|
|
350
|
+
if (context == null) return "absent";
|
|
351
|
+
if (!Array.isArray(context)) {
|
|
352
|
+
const effect = getContextEntryEffect(context);
|
|
353
|
+
return effect === "defines" ? "defined" : effect === "unknown" ? "unknown" : "absent";
|
|
354
|
+
}
|
|
355
|
+
let state = "absent";
|
|
356
|
+
for (const entry of context) {
|
|
357
|
+
const effect = getContextEntryEffect(entry);
|
|
358
|
+
if (effect === "defines") state = "defined";
|
|
359
|
+
else if (effect === "resets") state = "absent";
|
|
360
|
+
else if (effect === "unknown" && state !== "defined") state = "unknown";
|
|
361
|
+
}
|
|
362
|
+
return state;
|
|
363
|
+
}
|
|
364
|
+
function prepareSignatureDocument(jsonLd) {
|
|
365
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) return jsonLd;
|
|
366
|
+
const document = jsonLd;
|
|
367
|
+
if (document["proof"] != null) return { ...document };
|
|
368
|
+
const context = document["@context"];
|
|
369
|
+
if (getSignatureTermState(context) !== "absent") return { ...document };
|
|
370
|
+
const definition = { ...signatureTermDefinition };
|
|
371
|
+
return {
|
|
372
|
+
...document,
|
|
373
|
+
"@context": context == null ? [definition] : Array.isArray(context) ? [...context, definition] : [context, definition]
|
|
374
|
+
};
|
|
375
|
+
}
|
|
304
376
|
/**
|
|
305
377
|
* Attaches a LD signature to the given JSON-LD document.
|
|
378
|
+
*
|
|
379
|
+
* When the document's context does not already define the `signature`
|
|
380
|
+
* property, the returned document adds a minimal inline context for it.
|
|
381
|
+
* Without that definition, expanding the attached signature would produce a
|
|
382
|
+
* blank node predicate, which is not valid RDF. Documents that already carry
|
|
383
|
+
* a `proof` are left unchanged, since a new context definition would invalidate
|
|
384
|
+
* the proof. Documents whose context includes an unrecognized remote context
|
|
385
|
+
* are also left unchanged, since that context may already define `signature`.
|
|
306
386
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
307
387
|
* modified.
|
|
308
388
|
* @param signature The signature to attach.
|
|
309
389
|
* @returns The JSON-LD document with the attached signature.
|
|
310
390
|
* @throws {TypeError} If the input document is not a valid JSON-LD document.
|
|
391
|
+
* Top-level arrays are rejected, since a Linked Data
|
|
392
|
+
* Signature is attached to a single node.
|
|
311
393
|
* @since 1.0.0
|
|
312
394
|
*/
|
|
313
395
|
function attachSignature(jsonLd, signature) {
|
|
314
|
-
if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
};
|
|
396
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
397
|
+
const output = prepareSignatureDocument(jsonLd);
|
|
398
|
+
output.signature = signature;
|
|
399
|
+
return output;
|
|
319
400
|
}
|
|
320
401
|
/**
|
|
321
402
|
* Creates a LD signature for the given JSON-LD document.
|
|
403
|
+
*
|
|
404
|
+
* If the document's context does not define the `signature` property, the
|
|
405
|
+
* signature is computed over the document with a minimal inline definition
|
|
406
|
+
* added. Use {@link attachSignature} to attach the signature to that exact
|
|
407
|
+
* document. Documents that already carry a `proof`, or whose context includes
|
|
408
|
+
* an unrecognized remote context, are hashed unchanged.
|
|
322
409
|
* @param jsonLd The JSON-LD document to sign.
|
|
323
410
|
* @param privateKey The private key to sign the document.
|
|
324
411
|
* @param keyId The ID of the public key that corresponds to the private key.
|
|
@@ -332,14 +419,17 @@ async function createSignature(jsonLd, privateKey, keyId, { contextLoader, creat
|
|
|
332
419
|
validateCryptoKey(privateKey, "private");
|
|
333
420
|
if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
334
421
|
const options = {
|
|
335
|
-
"@context": "https://w3id.org/identity/v1",
|
|
336
422
|
creator: keyId.href,
|
|
337
423
|
created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
338
424
|
};
|
|
339
|
-
const message = await hashJsonLd(
|
|
425
|
+
const message = await hashJsonLd({
|
|
426
|
+
"@context": "https://w3id.org/identity/v1",
|
|
427
|
+
...options
|
|
428
|
+
}, contextLoader) + await hashJsonLd(prepareSignatureDocument(jsonLd), contextLoader);
|
|
340
429
|
const messageBytes = new TextEncoder().encode(message);
|
|
341
|
-
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, messageBytes);
|
|
430
|
+
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", asCryptoKey(privateKey), messageBytes);
|
|
342
431
|
return {
|
|
432
|
+
"@context": "https://w3id.org/security/v1",
|
|
343
433
|
...options,
|
|
344
434
|
type: "RsaSignature2017",
|
|
345
435
|
signatureValue: encodeBase64(signature)
|
|
@@ -378,6 +468,24 @@ async function signJsonLd(jsonLd, privateKey, keyId, options) {
|
|
|
378
468
|
}
|
|
379
469
|
});
|
|
380
470
|
}
|
|
471
|
+
/** @internal */
|
|
472
|
+
function hasVerifiableSignature(jsonLd) {
|
|
473
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || !("signature" in jsonLd)) return false;
|
|
474
|
+
const signature = jsonLd.signature;
|
|
475
|
+
if (typeof signature !== "object" || signature == null || Array.isArray(signature)) return false;
|
|
476
|
+
return "type" in signature && signature.type === "RsaSignature2017" && "creator" in signature && typeof signature.creator === "string" && (!("created" in signature) || typeof signature.created === "string") && "signatureValue" in signature && typeof signature.signatureValue === "string";
|
|
477
|
+
}
|
|
478
|
+
/** @internal */
|
|
479
|
+
function describeSignatureShape(jsonLd) {
|
|
480
|
+
if (typeof jsonLd !== "object" || jsonLd == null || !("signature" in jsonLd)) return null;
|
|
481
|
+
const signature = jsonLd.signature;
|
|
482
|
+
const properties = typeof signature === "object" && signature != null ? globalThis.Object.keys(signature) : [];
|
|
483
|
+
return {
|
|
484
|
+
signatureKind: signature == null ? String(signature) : Array.isArray(signature) ? "array" : typeof signature,
|
|
485
|
+
signatureProperties: properties.sort().slice(0, 20).map((p) => p.slice(0, 80)),
|
|
486
|
+
signaturePropertyCount: properties.length
|
|
487
|
+
};
|
|
488
|
+
}
|
|
381
489
|
/**
|
|
382
490
|
* Checks if the given JSON-LD document has a Linked Data Signature-like
|
|
383
491
|
* object, without restricting it to a single suite-specific shape.
|
|
@@ -442,6 +550,10 @@ function detachSignature(jsonLd) {
|
|
|
442
550
|
* `activitypub.signature.key_fetch.duration`, since the rest of the work
|
|
443
551
|
* that the verification-duration metric is meant to cover happens in
|
|
444
552
|
* `verifyJsonLd`.
|
|
553
|
+
*
|
|
554
|
+
* Unmapped properties discarded during JSON-LD processing are tolerated, but
|
|
555
|
+
* their values are not authenticated by the signature. Other unsafe
|
|
556
|
+
* canonicalization warnings, including relative IRIs, remain rejected.
|
|
445
557
|
* @param jsonLd The JSON-LD document to verify.
|
|
446
558
|
* @param options Options for verifying the signature.
|
|
447
559
|
* @returns The public key that signed the document or `null` if the signature
|
|
@@ -449,7 +561,11 @@ function detachSignature(jsonLd) {
|
|
|
449
561
|
* @since 1.0.0
|
|
450
562
|
*/
|
|
451
563
|
async function verifySignature(jsonLd, options = {}) {
|
|
452
|
-
if (!
|
|
564
|
+
if (!hasVerifiableSignature(jsonLd)) {
|
|
565
|
+
const shape = describeSignatureShape(jsonLd);
|
|
566
|
+
if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
|
|
567
|
+
return null;
|
|
568
|
+
}
|
|
453
569
|
const sig = jsonLd.signature;
|
|
454
570
|
let signature;
|
|
455
571
|
try {
|
|
@@ -461,7 +577,14 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
461
577
|
});
|
|
462
578
|
return null;
|
|
463
579
|
}
|
|
464
|
-
|
|
580
|
+
let creator;
|
|
581
|
+
try {
|
|
582
|
+
creator = new URL(sig.creator);
|
|
583
|
+
} catch {
|
|
584
|
+
logger.debug("Failed to verify; signature creator is not a valid URL.");
|
|
585
|
+
return null;
|
|
586
|
+
}
|
|
587
|
+
const { key, cached } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(creator, CryptographicKey, options));
|
|
465
588
|
if (key == null) return null;
|
|
466
589
|
const sigOpts = {
|
|
467
590
|
...sig,
|
|
@@ -472,7 +595,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
472
595
|
delete sigOpts.signatureValue;
|
|
473
596
|
let sigOptsHash;
|
|
474
597
|
try {
|
|
475
|
-
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
|
|
598
|
+
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader, "verify");
|
|
476
599
|
} catch (error) {
|
|
477
600
|
logger.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
|
|
478
601
|
signatureOptions: sigOpts,
|
|
@@ -484,7 +607,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
484
607
|
delete document.signature;
|
|
485
608
|
let docHash;
|
|
486
609
|
try {
|
|
487
|
-
docHash = await hashJsonLd(document, options.contextLoader);
|
|
610
|
+
docHash = await hashJsonLd(document, options.contextLoader, "verify");
|
|
488
611
|
} catch (error) {
|
|
489
612
|
logger.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
|
|
490
613
|
document,
|
|
@@ -501,7 +624,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
501
624
|
keyId: sig.creator,
|
|
502
625
|
...sig
|
|
503
626
|
});
|
|
504
|
-
const { key } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(
|
|
627
|
+
const { key } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(creator, CryptographicKey, {
|
|
505
628
|
...options,
|
|
506
629
|
keyCache: {
|
|
507
630
|
get: () => Promise.resolve(void 0),
|
|
@@ -550,6 +673,8 @@ function getLdSignatureObject(jsonLd) {
|
|
|
550
673
|
* Signatures. If the document is signed, this function verifies the signature
|
|
551
674
|
* and checks if the document is attributed to the owner of the public key.
|
|
552
675
|
* If the document is not signed, this function returns `false`.
|
|
676
|
+
* Unmapped properties discarded during JSON-LD processing are not
|
|
677
|
+
* authenticated, even when verification succeeds.
|
|
553
678
|
* @param jsonLd The JSON-LD document to verify.
|
|
554
679
|
* @param options Options for verifying the document.
|
|
555
680
|
* @returns `true` if the document is authentic; `false` otherwise.
|
|
@@ -568,11 +693,12 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
|
568
693
|
let threw = false;
|
|
569
694
|
let signatureType;
|
|
570
695
|
try {
|
|
571
|
-
const
|
|
696
|
+
const hasLdSignature = hasVerifiableSignature(jsonLd);
|
|
697
|
+
const verificationOptions = hasLdSignature ? {
|
|
572
698
|
...options,
|
|
573
699
|
contextLoader: getNormalizationContextLoader(options.contextLoader)
|
|
574
700
|
} : options;
|
|
575
|
-
const compacted = compact ?
|
|
701
|
+
const compacted = compact ? hasLdSignature ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
|
|
576
702
|
const object = await Object$1.fromJsonLd(compacted, verificationOptions);
|
|
577
703
|
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
578
704
|
span.setAttribute("activitypub.object.type", getTypeId(object).href);
|
|
@@ -614,13 +740,20 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
|
614
740
|
}
|
|
615
741
|
});
|
|
616
742
|
}
|
|
617
|
-
|
|
743
|
+
const tolerableVerificationWarnings = new Set(["blank node predicate", "invalid property"]);
|
|
744
|
+
function handleVerificationEvent({ event, next }) {
|
|
745
|
+
if (event.level === "warning" && !tolerableVerificationWarnings.has(event.code)) throw new TypeError(`Unsafe JSON-LD canonicalization warning: ${event.code}`);
|
|
746
|
+
next();
|
|
747
|
+
}
|
|
748
|
+
async function hashJsonLd(jsonLd, contextLoader, mode = "sign") {
|
|
618
749
|
const canon = await jsonld.canonize(jsonLd, {
|
|
619
750
|
format: "application/n-quads",
|
|
620
|
-
documentLoader: contextLoader ?? getDocumentLoader()
|
|
751
|
+
documentLoader: contextLoader ?? getDocumentLoader(),
|
|
752
|
+
safe: mode === "sign",
|
|
753
|
+
eventHandler: mode === "verify" ? handleVerificationEvent : void 0
|
|
621
754
|
});
|
|
622
755
|
const encoder = new TextEncoder();
|
|
623
756
|
return encodeHex(await crypto.subtle.digest("SHA-256", encoder.encode(canon)));
|
|
624
757
|
}
|
|
625
758
|
//#endregion
|
|
626
|
-
export {
|
|
759
|
+
export { verifyJsonLd as _, compactJsonLd as a, detachSignature as c, hasSignatureLike as d, hasVerifiableSignature as f, verifyCompactJsonLd as g, signJsonLd as h, attachSignature as i, getNormalizationContextLoader as l, isInvalidUrlTypeError as m, UnsafeJsonLdError as n, createSignature as o, isClearlyMalformedContextReference as p, assertSafeJsonLd as r, describeSignatureShape as s, InvalidContextReferenceError as t, hasSignature as u, verifySignature as v, wrapContextLoaderForJsonLd as y };
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
//#region src/testing/ld-signature.ts
|
|
5
|
+
const ldSignatureWithoutCreated = {
|
|
6
|
+
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
7
|
+
"id": "https://example.com/activities/1",
|
|
8
|
+
"type": "Create",
|
|
9
|
+
"actor": "https://example.com/person2",
|
|
10
|
+
"object": {
|
|
11
|
+
"id": "https://example.com/notes/1",
|
|
12
|
+
"type": "Note",
|
|
13
|
+
"attributedTo": "https://example.com/person2",
|
|
14
|
+
"content": "hi"
|
|
15
|
+
},
|
|
16
|
+
"signature": {
|
|
17
|
+
"type": "RsaSignature2017",
|
|
18
|
+
"creator": "https://example.com/person2#key3",
|
|
19
|
+
"signatureValue": "xUGTqQ94q+3bhvorwJx42sa7nCuR2ggtJYjwhqsueMCOLEmTEpeGGhG4mRKjFDt/ZegE9Icbxau6YL6WeQxWLMwYs7vucAE6948UlDFn1l3M+papmwgbNpOnk/baj9NMzChtqwOIQ1ka5bJAZjTo5FgG1YBmMibTHb6GN5ULzxjTlch93tcBx/LVwdPU1MyYHHz55hiMQZkw9AZ521PebCrm8eUjsXHwjijeh7/GIFWW3bmwk1dHRxJbUmmQlxBxmaLXQ8aVkFN3R00FBUjnn54Bp+nQJI/VXcKs3nFYGZ9EsMQcXlYCbOuOfPAPWiqdLSOhDZtuisIcZcvOiZ/tgA5RlXro0AXv0f3gKpkoxPBsUIIM0gBeb6+MTbSAk6IqPf0qy81V0XEjEMKSZNGDeULH+zMFodtw07EmfR/y/3i9ge3htd7vQQ0XKLLUfBddzMqS+8AAuSl4ObAlWAM2xuw/4yuQ3AIQy9RtsiEjDSO1NtUK5wRXCeXo++CkVpODDdxNtWdZD6GzfX9PAuIfHlWE+CLDaY/iH4fWxumLu15dD9vVDjlYAAS/ZNOyiPSCh4mLZ65sKIp8UkPstYRBKcjiRJhKUh1Br8TvTt/j/iC9SnFw/8uiCkLYd6yhdgXQafocPIa6eeb4m/EhF1HY0v+6qKR5JOBT6mTA/BPRmWg="
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
//#endregion
|
|
23
|
+
export { ldSignatureWithoutCreated as t };
|
|
@@ -1,7 +1,7 @@
|
|
|
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-
|
|
4
|
+
import { n as version, t as name } from "./deno-FtdqgHJA.mjs";
|
|
5
5
|
import { metrics } from "@opentelemetry/api";
|
|
6
6
|
import { FetchError } from "@fedify/vocab-runtime";
|
|
7
7
|
//#region src/federation/metrics.ts
|