@fedify/fedify 2.1.30 → 2.1.32
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-DZ4JHJD8.mjs +111 -0
- package/dist/{builder-CTpfuuVp.mjs → builder--sc-rozj.mjs} +3 -3
- package/dist/callback-BARPujV7.d.mts +2388 -0
- package/dist/{client-CAM_bQXx.d.cts → client-9DPcy_Yx.d.ts} +16 -1
- package/dist/{client-CSddvgWN.d.ts → client-B3ruDgWg.d.cts} +16 -1
- package/dist/{client-CjDMsn4a.mjs → client-cpPaW7Ww.mjs} +189 -65
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +254 -0
- 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-DLLaDau8.d.ts → context-DE2YrQwM.d.ts} +56 -13
- package/dist/{context-BNwv9Q1v.d.cts → context-y6ZUQCMf.d.cts} +56 -13
- package/dist/{deno-BATJ1hq6.mjs → deno-L23b3Hba.mjs} +1 -1
- package/dist/docloader-DUXr9k_O.mjs +124 -0
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +280 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1559 -26
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +723 -68
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CK3efjgM.js → http-BtbMAgTA.js} +176 -105
- package/dist/{http-Dl00HXr4.d.ts → http-C8qLHs_Z.d.cts} +3 -4
- package/dist/{http-BoR1M3W7.cjs → http-D5woFKA_.cjs} +177 -106
- package/dist/{http-DqZhyEso.d.cts → http-D8WmcRAF.d.ts} +3 -4
- package/dist/{http-Bjd6I92u.mjs → http-HX6wVyJh.mjs} +198 -98
- package/dist/{inbox-9MlBGgs9.mjs → inbox-CL7A0HXT.mjs} +1 -1
- package/dist/{key-ClQh9Qqh.mjs → key-Dai3f5yI.mjs} +3 -2
- package/dist/{kv-cache-BxSx_Iyp.cjs → kv-cache-B0V_e231.cjs} +59 -17
- package/dist/{kv-cache-ImApO425.js → kv-cache-BsDg-cT8.js} +60 -18
- package/dist/{ld-Crg0Xmwr.mjs → ld-DN6x1iZ8.mjs} +153 -21
- package/dist/ld-signature-DoZcbsZR.mjs +23 -0
- package/dist/{middleware-jL9p9V9G.cjs → middleware-Cl6k5Hrm.cjs} +1 -1
- package/dist/{middleware-CmD3lpy4.cjs → middleware-CrfRuKCf.cjs} +728 -143
- package/dist/{middleware-CE0b69gj.mjs → middleware-DiquMgtt.mjs} +444 -115
- package/dist/{middleware-C2AJFk8W.js → middleware-DunNtbo9.js} +727 -143
- package/dist/{middleware-Bi5D6DBT.mjs → middleware-SnQS8eIb.mjs} +1 -1
- package/dist/{mod-DiuFTYUt.d.cts → mod-CehHJOV4.d.cts} +30 -13
- package/dist/{mod-CWJNbyju.d.ts → mod-DLJpnqdw.d.ts} +1 -1
- package/dist/{mod-BLDHhuW0.d.ts → mod-Mh3oIuRK.d.ts} +30 -13
- package/dist/{mod-DNEgTI8M.d.ts → mod-REfljt0T.d.ts} +4 -9
- package/dist/{mod-Cn9GJ5ex.d.cts → mod-UvIGUHqW.d.cts} +4 -9
- package/dist/{mod-BmlfRBmU.d.cts → mod-sTa1Zzxk.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 +764 -19
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +292 -30
- package/dist/otel/mod.cjs +36 -30
- package/dist/otel/mod.d.cts +13 -0
- package/dist/otel/mod.d.ts +13 -0
- package/dist/otel/mod.js +36 -30
- package/dist/{owner-BRoKojK1.mjs → owner-DwyDorZI.mjs} +2 -2
- package/dist/{proof-CHXVlsH_.cjs → proof-Be-4K4jn.cjs} +193 -46
- package/dist/{proof-DMIAezxz.mjs → proof-DYjmyrHh.mjs} +38 -13
- package/dist/{proof-7R4s10TJ.js → proof-Du4-5SHY.js} +187 -46
- package/dist/send-BGSfQkIK.mjs +416 -0
- package/dist/sig/http.test.mjs +506 -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 +95 -3
- package/dist/{temporal-DR0JahMu.mjs → temporal-CNCchWly.mjs} +3 -5
- package/dist/testing/mod.d.mts +1 -2177
- package/dist/{types-DRPjmHVV.cjs → types-B5wRhemi.cjs} +187 -63
- package/dist/{types-miAYfiGO.js → types-CXy2lRVU.js} +188 -64
- package/dist/utils/docloader.test.mjs +316 -32
- 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 +7 -7
- package/dist/docloader-OLWc7P2D.mjs +0 -82
- package/dist/send-BHIt_8ia.mjs +0 -260
- /package/dist/{collection-BD6-SZ6O.mjs → collection-DnoYNwBC.mjs} +0 -0
- /package/dist/{negotiation-BehA2uul.mjs → negotiation-xb0QR3u_.mjs} +0 -0
- /package/dist/{retry-B_E3V_Dx.mjs → retry-CI1flGDD.mjs} +0 -0
- /package/dist/{types-DCP0WLdt.mjs → types-s4mCTGkT.mjs} +0 -0
|
@@ -1,11 +1,12 @@
|
|
|
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 { r as fetchKey, s as validateCryptoKey } from "./key-
|
|
4
|
+
import { n as version, t as name } from "./deno-L23b3Hba.mjs";
|
|
5
|
+
import { r as fetchKey, s as validateCryptoKey } from "./key-Dai3f5yI.mjs";
|
|
6
6
|
import { Activity, CryptographicKey, Object as Object$1, getTypeId } from "@fedify/vocab";
|
|
7
7
|
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
|
-
import { getDocumentLoader } from "@fedify/vocab-runtime";
|
|
8
|
+
import { getDocumentLoader, preloadedContexts } from "@fedify/vocab-runtime";
|
|
9
|
+
import { asCryptoKey } from "@fedify/vocab-runtime/internal";
|
|
9
10
|
import { getLogger } from "@logtape/logtape";
|
|
10
11
|
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
11
12
|
import { encodeHex } from "byte-encodings/hex";
|
|
@@ -298,24 +299,110 @@ function assertSafeJsonLd(jsonLd) {
|
|
|
298
299
|
}
|
|
299
300
|
}
|
|
300
301
|
}
|
|
302
|
+
const signatureTermDefinition = { "signature": "https://w3id.org/security#signature" };
|
|
303
|
+
const signatureDefiningContexts = new Set(["https://w3id.org/identity/v1", "https://w3id.org/security/v1"]);
|
|
304
|
+
const signatureFreeContexts = getSignatureFreeContexts();
|
|
305
|
+
function getSignatureFreeContexts() {
|
|
306
|
+
const urls = /* @__PURE__ */ new Set();
|
|
307
|
+
for (const [url, document] of globalThis.Object.entries(preloadedContexts)) {
|
|
308
|
+
if (typeof document !== "object" || document == null) continue;
|
|
309
|
+
const context = document["@context"];
|
|
310
|
+
if (typeof context !== "object" || context == null || Array.isArray(context)) continue;
|
|
311
|
+
const record = context;
|
|
312
|
+
if (!globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) urls.add(url);
|
|
313
|
+
}
|
|
314
|
+
return urls;
|
|
315
|
+
}
|
|
316
|
+
function getContextEntryEffect(entry) {
|
|
317
|
+
if (entry == null) return "resets";
|
|
318
|
+
if (typeof entry === "string") {
|
|
319
|
+
if (signatureDefiningContexts.has(entry)) return "defines";
|
|
320
|
+
if (signatureFreeContexts.has(entry)) return "absent";
|
|
321
|
+
return "unknown";
|
|
322
|
+
}
|
|
323
|
+
if (typeof entry !== "object") return "absent";
|
|
324
|
+
const record = entry;
|
|
325
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) {
|
|
326
|
+
const definition = record["signature"];
|
|
327
|
+
const contextProtected = record["@protected"] === true;
|
|
328
|
+
const imported = globalThis.Object.prototype.hasOwnProperty.call(record, "@import");
|
|
329
|
+
if (definition == null) {
|
|
330
|
+
if (contextProtected) return "defines";
|
|
331
|
+
return imported ? "unknown" : "resets";
|
|
332
|
+
}
|
|
333
|
+
if (typeof definition === "object" && !Array.isArray(definition)) {
|
|
334
|
+
const term = definition;
|
|
335
|
+
const protectedTerm = contextProtected || term["@protected"] === true;
|
|
336
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(term, "@id") && term["@id"] == null) {
|
|
337
|
+
if (protectedTerm) return "defines";
|
|
338
|
+
return imported ? "unknown" : "resets";
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return "defines";
|
|
342
|
+
}
|
|
343
|
+
if (globalThis.Object.prototype.hasOwnProperty.call(record, "@import")) return "unknown";
|
|
344
|
+
return "absent";
|
|
345
|
+
}
|
|
346
|
+
function getSignatureTermState(context) {
|
|
347
|
+
if (context == null) return "absent";
|
|
348
|
+
if (!Array.isArray(context)) {
|
|
349
|
+
const effect = getContextEntryEffect(context);
|
|
350
|
+
return effect === "defines" ? "defined" : effect === "unknown" ? "unknown" : "absent";
|
|
351
|
+
}
|
|
352
|
+
let state = "absent";
|
|
353
|
+
for (const entry of context) {
|
|
354
|
+
const effect = getContextEntryEffect(entry);
|
|
355
|
+
if (effect === "defines") state = "defined";
|
|
356
|
+
else if (effect === "resets") state = "absent";
|
|
357
|
+
else if (effect === "unknown" && state !== "defined") state = "unknown";
|
|
358
|
+
}
|
|
359
|
+
return state;
|
|
360
|
+
}
|
|
361
|
+
function prepareSignatureDocument(jsonLd) {
|
|
362
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) return jsonLd;
|
|
363
|
+
const document = jsonLd;
|
|
364
|
+
if (document["proof"] != null) return { ...document };
|
|
365
|
+
const context = document["@context"];
|
|
366
|
+
if (getSignatureTermState(context) !== "absent") return { ...document };
|
|
367
|
+
const definition = { ...signatureTermDefinition };
|
|
368
|
+
return {
|
|
369
|
+
...document,
|
|
370
|
+
"@context": context == null ? [definition] : Array.isArray(context) ? [...context, definition] : [context, definition]
|
|
371
|
+
};
|
|
372
|
+
}
|
|
301
373
|
/**
|
|
302
374
|
* Attaches a LD signature to the given JSON-LD document.
|
|
375
|
+
*
|
|
376
|
+
* When the document's context does not already define the `signature`
|
|
377
|
+
* property, the returned document adds a minimal inline context for it.
|
|
378
|
+
* Without that definition, expanding the attached signature would produce a
|
|
379
|
+
* blank node predicate, which is not valid RDF. Documents that already carry
|
|
380
|
+
* a `proof` are left unchanged, since a new context definition would invalidate
|
|
381
|
+
* the proof. Documents whose context includes an unrecognized remote context
|
|
382
|
+
* are also left unchanged, since that context may already define `signature`.
|
|
303
383
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
304
384
|
* modified.
|
|
305
385
|
* @param signature The signature to attach.
|
|
306
386
|
* @returns The JSON-LD document with the attached signature.
|
|
307
387
|
* @throws {TypeError} If the input document is not a valid JSON-LD document.
|
|
388
|
+
* Top-level arrays are rejected, since a Linked Data
|
|
389
|
+
* Signature is attached to a single node.
|
|
308
390
|
* @since 1.0.0
|
|
309
391
|
*/
|
|
310
392
|
function attachSignature(jsonLd, signature) {
|
|
311
|
-
if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
};
|
|
393
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
394
|
+
const output = prepareSignatureDocument(jsonLd);
|
|
395
|
+
output.signature = signature;
|
|
396
|
+
return output;
|
|
316
397
|
}
|
|
317
398
|
/**
|
|
318
399
|
* Creates a LD signature for the given JSON-LD document.
|
|
400
|
+
*
|
|
401
|
+
* If the document's context does not define the `signature` property, the
|
|
402
|
+
* signature is computed over the document with a minimal inline definition
|
|
403
|
+
* added. Use {@link attachSignature} to attach the signature to that exact
|
|
404
|
+
* document. Documents that already carry a `proof`, or whose context includes
|
|
405
|
+
* an unrecognized remote context, are hashed unchanged.
|
|
319
406
|
* @param jsonLd The JSON-LD document to sign.
|
|
320
407
|
* @param privateKey The private key to sign the document.
|
|
321
408
|
* @param keyId The ID of the public key that corresponds to the private key.
|
|
@@ -329,14 +416,17 @@ async function createSignature(jsonLd, privateKey, keyId, { contextLoader, creat
|
|
|
329
416
|
validateCryptoKey(privateKey, "private");
|
|
330
417
|
if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
331
418
|
const options = {
|
|
332
|
-
"@context": "https://w3id.org/identity/v1",
|
|
333
419
|
creator: keyId.href,
|
|
334
420
|
created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
335
421
|
};
|
|
336
|
-
const message = await hashJsonLd(
|
|
422
|
+
const message = await hashJsonLd({
|
|
423
|
+
"@context": "https://w3id.org/identity/v1",
|
|
424
|
+
...options
|
|
425
|
+
}, contextLoader) + await hashJsonLd(prepareSignatureDocument(jsonLd), contextLoader);
|
|
337
426
|
const messageBytes = new TextEncoder().encode(message);
|
|
338
|
-
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, messageBytes);
|
|
427
|
+
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", asCryptoKey(privateKey), messageBytes);
|
|
339
428
|
return {
|
|
429
|
+
"@context": "https://w3id.org/security/v1",
|
|
340
430
|
...options,
|
|
341
431
|
type: "RsaSignature2017",
|
|
342
432
|
signatureValue: encodeBase64(signature)
|
|
@@ -375,6 +465,24 @@ async function signJsonLd(jsonLd, privateKey, keyId, options) {
|
|
|
375
465
|
}
|
|
376
466
|
});
|
|
377
467
|
}
|
|
468
|
+
/** @internal */
|
|
469
|
+
function hasVerifiableSignature(jsonLd) {
|
|
470
|
+
if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || !("signature" in jsonLd)) return false;
|
|
471
|
+
const signature = jsonLd.signature;
|
|
472
|
+
if (typeof signature !== "object" || signature == null || Array.isArray(signature)) return false;
|
|
473
|
+
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";
|
|
474
|
+
}
|
|
475
|
+
/** @internal */
|
|
476
|
+
function describeSignatureShape(jsonLd) {
|
|
477
|
+
if (typeof jsonLd !== "object" || jsonLd == null || !("signature" in jsonLd)) return null;
|
|
478
|
+
const signature = jsonLd.signature;
|
|
479
|
+
const properties = typeof signature === "object" && signature != null ? globalThis.Object.keys(signature) : [];
|
|
480
|
+
return {
|
|
481
|
+
signatureKind: signature == null ? String(signature) : Array.isArray(signature) ? "array" : typeof signature,
|
|
482
|
+
signatureProperties: properties.sort().slice(0, 20).map((p) => p.slice(0, 80)),
|
|
483
|
+
signaturePropertyCount: properties.length
|
|
484
|
+
};
|
|
485
|
+
}
|
|
378
486
|
/**
|
|
379
487
|
* Checks if the given JSON-LD document has a Linked Data Signature.
|
|
380
488
|
* @param jsonLd The JSON-LD document to check.
|
|
@@ -405,6 +513,9 @@ function detachSignature(jsonLd) {
|
|
|
405
513
|
}
|
|
406
514
|
/**
|
|
407
515
|
* Verifies Linked Data Signatures of the given JSON-LD document.
|
|
516
|
+
* Unmapped properties discarded during JSON-LD processing are tolerated, but
|
|
517
|
+
* their values are not authenticated by the signature. Other unsafe
|
|
518
|
+
* canonicalization warnings, including relative IRIs, remain rejected.
|
|
408
519
|
* @param jsonLd The JSON-LD document to verify.
|
|
409
520
|
* @param options Options for verifying the signature.
|
|
410
521
|
* @returns The public key that signed the document or `null` if the signature
|
|
@@ -412,7 +523,11 @@ function detachSignature(jsonLd) {
|
|
|
412
523
|
* @since 1.0.0
|
|
413
524
|
*/
|
|
414
525
|
async function verifySignature(jsonLd, options = {}) {
|
|
415
|
-
if (!
|
|
526
|
+
if (!hasVerifiableSignature(jsonLd)) {
|
|
527
|
+
const shape = describeSignatureShape(jsonLd);
|
|
528
|
+
if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
|
|
529
|
+
return null;
|
|
530
|
+
}
|
|
416
531
|
const sig = jsonLd.signature;
|
|
417
532
|
let signature;
|
|
418
533
|
try {
|
|
@@ -424,7 +539,14 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
424
539
|
});
|
|
425
540
|
return null;
|
|
426
541
|
}
|
|
427
|
-
|
|
542
|
+
let creator;
|
|
543
|
+
try {
|
|
544
|
+
creator = new URL(sig.creator);
|
|
545
|
+
} catch {
|
|
546
|
+
logger.debug("Failed to verify; signature creator is not a valid URL.");
|
|
547
|
+
return null;
|
|
548
|
+
}
|
|
549
|
+
const { key, cached } = await fetchKey(creator, CryptographicKey, options);
|
|
428
550
|
if (key == null) return null;
|
|
429
551
|
const sigOpts = {
|
|
430
552
|
...sig,
|
|
@@ -435,7 +557,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
435
557
|
delete sigOpts.signatureValue;
|
|
436
558
|
let sigOptsHash;
|
|
437
559
|
try {
|
|
438
|
-
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
|
|
560
|
+
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader, "verify");
|
|
439
561
|
} catch (error) {
|
|
440
562
|
logger.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
|
|
441
563
|
signatureOptions: sigOpts,
|
|
@@ -447,7 +569,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
447
569
|
delete document.signature;
|
|
448
570
|
let docHash;
|
|
449
571
|
try {
|
|
450
|
-
docHash = await hashJsonLd(document, options.contextLoader);
|
|
572
|
+
docHash = await hashJsonLd(document, options.contextLoader, "verify");
|
|
451
573
|
} catch (error) {
|
|
452
574
|
logger.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
|
|
453
575
|
document,
|
|
@@ -464,7 +586,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
464
586
|
keyId: sig.creator,
|
|
465
587
|
...sig
|
|
466
588
|
});
|
|
467
|
-
const { key } = await fetchKey(
|
|
589
|
+
const { key } = await fetchKey(creator, CryptographicKey, {
|
|
468
590
|
...options,
|
|
469
591
|
keyCache: {
|
|
470
592
|
get: () => Promise.resolve(void 0),
|
|
@@ -486,6 +608,8 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
486
608
|
* Signatures. If the document is signed, this function verifies the signature
|
|
487
609
|
* and checks if the document is attributed to the owner of the public key.
|
|
488
610
|
* If the document is not signed, this function returns `false`.
|
|
611
|
+
* Unmapped properties discarded during JSON-LD processing are not
|
|
612
|
+
* authenticated, even when verification succeeds.
|
|
489
613
|
* @param jsonLd The JSON-LD document to verify.
|
|
490
614
|
* @param options Options for verifying the document.
|
|
491
615
|
* @returns `true` if the document is authentic; `false` otherwise.
|
|
@@ -500,11 +624,12 @@ async function verifyCompactJsonLd(jsonLd, options = {}) {
|
|
|
500
624
|
async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
501
625
|
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.verify", async (span) => {
|
|
502
626
|
try {
|
|
503
|
-
const
|
|
627
|
+
const hasLdSignature = hasVerifiableSignature(jsonLd);
|
|
628
|
+
const verificationOptions = hasLdSignature ? {
|
|
504
629
|
...options,
|
|
505
630
|
contextLoader: getNormalizationContextLoader(options.contextLoader)
|
|
506
631
|
} : options;
|
|
507
|
-
const compacted = compact ?
|
|
632
|
+
const compacted = compact ? hasLdSignature ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
|
|
508
633
|
const object = await Object$1.fromJsonLd(compacted, verificationOptions);
|
|
509
634
|
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
510
635
|
span.setAttribute("activitypub.object.type", getTypeId(object).href);
|
|
@@ -538,13 +663,20 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
|
538
663
|
}
|
|
539
664
|
});
|
|
540
665
|
}
|
|
541
|
-
|
|
666
|
+
const tolerableVerificationWarnings = new Set(["blank node predicate", "invalid property"]);
|
|
667
|
+
function handleVerificationEvent({ event, next }) {
|
|
668
|
+
if (event.level === "warning" && !tolerableVerificationWarnings.has(event.code)) throw new TypeError(`Unsafe JSON-LD canonicalization warning: ${event.code}`);
|
|
669
|
+
next();
|
|
670
|
+
}
|
|
671
|
+
async function hashJsonLd(jsonLd, contextLoader, mode = "sign") {
|
|
542
672
|
const canon = await jsonld.canonize(jsonLd, {
|
|
543
673
|
format: "application/n-quads",
|
|
544
|
-
documentLoader: contextLoader ?? getDocumentLoader()
|
|
674
|
+
documentLoader: contextLoader ?? getDocumentLoader(),
|
|
675
|
+
safe: mode === "sign",
|
|
676
|
+
eventHandler: mode === "verify" ? handleVerificationEvent : void 0
|
|
545
677
|
});
|
|
546
678
|
const encoder = new TextEncoder();
|
|
547
679
|
return encodeHex(await crypto.subtle.digest("SHA-256", encoder.encode(canon)));
|
|
548
680
|
}
|
|
549
681
|
//#endregion
|
|
550
|
-
export { compactJsonLd as a,
|
|
682
|
+
export { verifySignature as _, compactJsonLd as a, detachSignature as c, hasVerifiableSignature as d, isClearlyMalformedContextReference as f, verifyJsonLd as g, verifyCompactJsonLd as h, attachSignature as i, getNormalizationContextLoader as l, signJsonLd as m, UnsafeJsonLdError as n, createSignature as o, isInvalidUrlTypeError as p, assertSafeJsonLd as r, describeSignatureShape as s, InvalidContextReferenceError as t, hasSignature as u, wrapContextLoaderForJsonLd as v };
|
|
@@ -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,4 +1,4 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
|
-
const require_middleware = require("./middleware-
|
|
3
|
+
const require_middleware = require("./middleware-CrfRuKCf.cjs");
|
|
4
4
|
exports.FederationImpl = require_middleware.FederationImpl;
|