@fedify/fedify 2.0.36-dev.2734 → 2.0.36-dev.2760

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.
Files changed (66) hide show
  1. package/dist/{builder-D0y_1xPt.mjs → builder-CyuiJaas.mjs} +3 -3
  2. package/dist/compat/transformers.test.mjs +2 -2
  3. package/dist/{deno-CvHOP0XE.mjs → deno-Bbso5CSl.mjs} +1 -1
  4. package/dist/{docloader-QmdzA0HA.mjs → docloader-CP5VuWA0.mjs} +2 -2
  5. package/dist/federation/builder.test.mjs +2 -2
  6. package/dist/federation/collection.test.mjs +1 -1
  7. package/dist/federation/handler.test.mjs +206 -15
  8. package/dist/federation/idempotency.test.mjs +3 -3
  9. package/dist/federation/inbox.test.mjs +1 -1
  10. package/dist/federation/keycache.test.mjs +2 -2
  11. package/dist/federation/kv.test.mjs +1 -1
  12. package/dist/federation/middleware.test.mjs +102 -8
  13. package/dist/federation/mod.cjs +1 -1
  14. package/dist/federation/mod.js +1 -1
  15. package/dist/federation/negotiation.test.mjs +1 -1
  16. package/dist/federation/retry.test.mjs +1 -1
  17. package/dist/federation/send.test.mjs +3 -3
  18. package/dist/federation/temporal.test.mjs +1 -1
  19. package/dist/federation/webfinger.test.mjs +2 -2
  20. package/dist/{http-DM--MHnA.mjs → http-Cp7sQLeG.mjs} +2 -2
  21. package/dist/{http-CacZaxQy.js → http-D03Qcwc-.js} +1 -1
  22. package/dist/{http-CIiwaoIn.cjs → http-DBBUPm9V.cjs} +1 -1
  23. package/dist/{inbox-BgsnvP5o.mjs → inbox-DTuh59nR.mjs} +1 -1
  24. package/dist/{key-RrdwitZu.mjs → key-CsY0Ifod.mjs} +1 -1
  25. package/dist/{kv-cache--kqYNgl4.cjs → kv-cache-BpjVni_0.cjs} +1 -1
  26. package/dist/{kv-cache-DO77nN26.js → kv-cache-CVxDhqGp.js} +1 -1
  27. package/dist/{ld-BpBoDQsD.mjs → ld-dYjiHKj1.mjs} +38 -8
  28. package/dist/ld-signature-_KYhPsqt.mjs +23 -0
  29. package/dist/{middleware-ByORyvfD.cjs → middleware-2zkNwQvz.cjs} +1 -1
  30. package/dist/{middleware-DoMxpm9r.mjs → middleware-3x7W0auZ.mjs} +31 -27
  31. package/dist/{middleware-DkQNfZyL.cjs → middleware-5EN1mHvx.cjs} +18 -14
  32. package/dist/{middleware-BcLbgxfC.js → middleware-DFR4tBL2.js} +17 -13
  33. package/dist/{middleware-j3sV7iws.mjs → middleware-DvCyN-xk.mjs} +1 -1
  34. package/dist/mod.cjs +4 -4
  35. package/dist/mod.js +4 -4
  36. package/dist/nodeinfo/client.test.mjs +1 -1
  37. package/dist/nodeinfo/handler.test.mjs +2 -2
  38. package/dist/nodeinfo/types.test.mjs +1 -1
  39. package/dist/otel/exporter.test.mjs +1 -1
  40. package/dist/{owner-zSUyR5Fs.mjs → owner-A1Xol6Zh.mjs} +2 -2
  41. package/dist/{proof-qxFPzf3D.cjs → proof-CCZCT2xF.cjs} +43 -22
  42. package/dist/{proof-C90umkRN.mjs → proof-DCqYLXDl.mjs} +2 -2
  43. package/dist/{proof-DJvdhpXO.js → proof-DGOXBmlo.js} +36 -21
  44. package/dist/{send-BE4hcPfe.mjs → send-yQno-6bP.mjs} +2 -2
  45. package/dist/sig/http.test.mjs +2 -2
  46. package/dist/sig/key-types.test.d.mts +1 -1
  47. package/dist/sig/key.test.mjs +2 -2
  48. package/dist/sig/ld.test.mjs +223 -4
  49. package/dist/sig/mod.cjs +2 -2
  50. package/dist/sig/mod.js +2 -2
  51. package/dist/sig/owner.test.mjs +1 -1
  52. package/dist/sig/proof.test.mjs +26 -3
  53. package/dist/{temporal-BQUGkj5T.mjs → temporal-C26UV3h7.mjs} +1 -1
  54. package/dist/testing/mod.d.mts +1 -1
  55. package/dist/utils/docloader.test.mjs +2 -2
  56. package/dist/utils/mod.cjs +1 -1
  57. package/dist/utils/mod.js +1 -1
  58. package/package.json +6 -6
  59. /package/dist/{callback-CJd-aCRE.d.mts → callback-BFMEE_9V.d.mts} +0 -0
  60. /package/dist/{client-DGNacEx_.mjs → client-DLAWT9ep.mjs} +0 -0
  61. /package/dist/{collection-DI6YzYpd.mjs → collection-ChgDTHLz.mjs} +0 -0
  62. /package/dist/{keycache-DBD6fzl1.mjs → keycache-crDMn2HK.mjs} +0 -0
  63. /package/dist/{kv-mI4Ix2EU.mjs → kv-BrZHNugx.mjs} +0 -0
  64. /package/dist/{negotiation-TWEs6Cl8.mjs → negotiation-BehA2uul.mjs} +0 -0
  65. /package/dist/{retry-Ddbq3AcK.mjs → retry-B_E3V_Dx.mjs} +0 -0
  66. /package/dist/{types-MNlFfxjv.mjs → types-C37hquWI.mjs} +0 -0
@@ -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-CIiwaoIn.cjs");
4
+ const require_http = require("./http-DBBUPm9V.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");
@@ -467,20 +467,23 @@ async function signJsonLd(jsonLd, privateKey, keyId, options) {
467
467
  }
468
468
  });
469
469
  }
470
- /**
471
- * Checks if the given JSON-LD document has a Linked Data Signature.
472
- * @param jsonLd The JSON-LD document to check.
473
- * @returns `true` if the document has a signature; `false` otherwise.
474
- * @since 1.0.0
475
- */
476
- function hasSignature(jsonLd) {
477
- if (typeof jsonLd !== "object" || jsonLd == null) return false;
478
- if ("signature" in jsonLd) {
479
- const signature = jsonLd.signature;
480
- if (typeof signature !== "object" || signature == null) return false;
481
- 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";
482
- }
483
- return false;
470
+ /** @internal */
471
+ function hasVerifiableSignature(jsonLd) {
472
+ if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || !("signature" in jsonLd)) return false;
473
+ const signature = jsonLd.signature;
474
+ if (typeof signature !== "object" || signature == null || Array.isArray(signature)) return false;
475
+ 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";
476
+ }
477
+ /** @internal */
478
+ function describeSignatureShape(jsonLd) {
479
+ if (typeof jsonLd !== "object" || jsonLd == null || !("signature" in jsonLd)) return null;
480
+ const signature = jsonLd.signature;
481
+ const properties = typeof signature === "object" && signature != null ? globalThis.Object.keys(signature) : [];
482
+ return {
483
+ signatureKind: signature == null ? String(signature) : Array.isArray(signature) ? "array" : typeof signature,
484
+ signatureProperties: properties.sort().slice(0, 20).map((p) => p.slice(0, 80)),
485
+ signaturePropertyCount: properties.length
486
+ };
484
487
  }
485
488
  /**
486
489
  * Detaches Linked Data Signatures from the given JSON-LD document.
@@ -507,7 +510,11 @@ function detachSignature(jsonLd) {
507
510
  * @since 1.0.0
508
511
  */
509
512
  async function verifySignature(jsonLd, options = {}) {
510
- if (!hasSignature(jsonLd)) return null;
513
+ if (!hasVerifiableSignature(jsonLd)) {
514
+ const shape = describeSignatureShape(jsonLd);
515
+ if (shape != null) logger$2.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
516
+ return null;
517
+ }
511
518
  const sig = jsonLd.signature;
512
519
  let signature;
513
520
  try {
@@ -519,7 +526,14 @@ async function verifySignature(jsonLd, options = {}) {
519
526
  });
520
527
  return null;
521
528
  }
522
- const { key, cached } = await require_http.fetchKey(new URL(sig.creator), _fedify_vocab.CryptographicKey, options);
529
+ let creator;
530
+ try {
531
+ creator = new URL(sig.creator);
532
+ } catch {
533
+ logger$2.debug("Failed to verify; signature creator is not a valid URL.");
534
+ return null;
535
+ }
536
+ const { key, cached } = await require_http.fetchKey(creator, _fedify_vocab.CryptographicKey, options);
523
537
  if (key == null) return null;
524
538
  const sigOpts = {
525
539
  ...sig,
@@ -559,7 +573,7 @@ async function verifySignature(jsonLd, options = {}) {
559
573
  keyId: sig.creator,
560
574
  ...sig
561
575
  });
562
- const { key } = await require_http.fetchKey(new URL(sig.creator), _fedify_vocab.CryptographicKey, {
576
+ const { key } = await require_http.fetchKey(creator, _fedify_vocab.CryptographicKey, {
563
577
  ...options,
564
578
  keyCache: {
565
579
  get: () => Promise.resolve(void 0),
@@ -597,11 +611,12 @@ async function verifyCompactJsonLd(jsonLd, options = {}) {
597
611
  async function verifyJsonLdInternal(jsonLd, options, compact) {
598
612
  return await (options.tracerProvider ?? _opentelemetry_api.trace.getTracerProvider()).getTracer(require_http.name, require_http.version).startActiveSpan("ld_signatures.verify", async (span) => {
599
613
  try {
600
- const verificationOptions = hasSignature(jsonLd) ? {
614
+ const hasLdSignature = hasVerifiableSignature(jsonLd);
615
+ const verificationOptions = hasLdSignature ? {
601
616
  ...options,
602
617
  contextLoader: getNormalizationContextLoader(options.contextLoader)
603
618
  } : options;
604
- const compacted = compact ? hasSignature(jsonLd) ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
619
+ const compacted = compact ? hasLdSignature ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
605
620
  const object = await _fedify_vocab.Object.fromJsonLd(compacted, verificationOptions);
606
621
  if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
607
622
  span.setAttribute("activitypub.object.type", (0, _fedify_vocab.getTypeId)(object).href);
@@ -1115,6 +1130,12 @@ Object.defineProperty(exports, "createSignature", {
1115
1130
  return createSignature;
1116
1131
  }
1117
1132
  });
1133
+ Object.defineProperty(exports, "describeSignatureShape", {
1134
+ enumerable: true,
1135
+ get: function() {
1136
+ return describeSignatureShape;
1137
+ }
1138
+ });
1118
1139
  Object.defineProperty(exports, "detachSignature", {
1119
1140
  enumerable: true,
1120
1141
  get: function() {
@@ -1139,10 +1160,10 @@ Object.defineProperty(exports, "getNormalizationContextLoader", {
1139
1160
  return getNormalizationContextLoader;
1140
1161
  }
1141
1162
  });
1142
- Object.defineProperty(exports, "hasSignature", {
1163
+ Object.defineProperty(exports, "hasVerifiableSignature", {
1143
1164
  enumerable: true,
1144
1165
  get: function() {
1145
- return hasSignature;
1166
+ return hasVerifiableSignature;
1146
1167
  }
1147
1168
  });
1148
1169
  Object.defineProperty(exports, "isClearlyMalformedContextReference", {
@@ -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-CvHOP0XE.mjs";
5
- import { o as validateCryptoKey, r as fetchKey } from "./key-RrdwitZu.mjs";
4
+ import { n as version, t as name } from "./deno-Bbso5CSl.mjs";
5
+ import { o as validateCryptoKey, r as fetchKey } from "./key-CsY0Ifod.mjs";
6
6
  import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
7
7
  import { SpanStatusCode, trace } from "@opentelemetry/api";
8
8
  import { asCryptoKey } from "@fedify/vocab-runtime/internal";
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { a as fetchActorDocument, d as name, f as version, i as exportJwk, l as validateCryptoKey, o as fetchKey, u as verifyKeyOwnership } from "./http-CacZaxQy.js";
3
+ import { a as fetchActorDocument, d as name, f as version, i as exportJwk, l as validateCryptoKey, o as fetchKey, u as verifyKeyOwnership } from "./http-D03Qcwc-.js";
4
4
  import { getLogger } from "@logtape/logtape";
5
5
  import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, getTypeId, isActor } from "@fedify/vocab";
6
6
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
@@ -464,20 +464,23 @@ async function signJsonLd(jsonLd, privateKey, keyId, options) {
464
464
  }
465
465
  });
466
466
  }
467
- /**
468
- * Checks if the given JSON-LD document has a Linked Data Signature.
469
- * @param jsonLd The JSON-LD document to check.
470
- * @returns `true` if the document has a signature; `false` otherwise.
471
- * @since 1.0.0
472
- */
473
- function hasSignature(jsonLd) {
474
- if (typeof jsonLd !== "object" || jsonLd == null) return false;
475
- if ("signature" in jsonLd) {
476
- const signature = jsonLd.signature;
477
- if (typeof signature !== "object" || signature == null) return false;
478
- 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";
479
- }
480
- return false;
467
+ /** @internal */
468
+ function hasVerifiableSignature(jsonLd) {
469
+ if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || !("signature" in jsonLd)) return false;
470
+ const signature = jsonLd.signature;
471
+ if (typeof signature !== "object" || signature == null || Array.isArray(signature)) return false;
472
+ 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";
473
+ }
474
+ /** @internal */
475
+ function describeSignatureShape(jsonLd) {
476
+ if (typeof jsonLd !== "object" || jsonLd == null || !("signature" in jsonLd)) return null;
477
+ const signature = jsonLd.signature;
478
+ const properties = typeof signature === "object" && signature != null ? globalThis.Object.keys(signature) : [];
479
+ return {
480
+ signatureKind: signature == null ? String(signature) : Array.isArray(signature) ? "array" : typeof signature,
481
+ signatureProperties: properties.sort().slice(0, 20).map((p) => p.slice(0, 80)),
482
+ signaturePropertyCount: properties.length
483
+ };
481
484
  }
482
485
  /**
483
486
  * Detaches Linked Data Signatures from the given JSON-LD document.
@@ -504,7 +507,11 @@ function detachSignature(jsonLd) {
504
507
  * @since 1.0.0
505
508
  */
506
509
  async function verifySignature(jsonLd, options = {}) {
507
- if (!hasSignature(jsonLd)) return null;
510
+ if (!hasVerifiableSignature(jsonLd)) {
511
+ const shape = describeSignatureShape(jsonLd);
512
+ if (shape != null) logger$2.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
513
+ return null;
514
+ }
508
515
  const sig = jsonLd.signature;
509
516
  let signature;
510
517
  try {
@@ -516,7 +523,14 @@ async function verifySignature(jsonLd, options = {}) {
516
523
  });
517
524
  return null;
518
525
  }
519
- const { key, cached } = await fetchKey(new URL(sig.creator), CryptographicKey, options);
526
+ let creator;
527
+ try {
528
+ creator = new URL(sig.creator);
529
+ } catch {
530
+ logger$2.debug("Failed to verify; signature creator is not a valid URL.");
531
+ return null;
532
+ }
533
+ const { key, cached } = await fetchKey(creator, CryptographicKey, options);
520
534
  if (key == null) return null;
521
535
  const sigOpts = {
522
536
  ...sig,
@@ -556,7 +570,7 @@ async function verifySignature(jsonLd, options = {}) {
556
570
  keyId: sig.creator,
557
571
  ...sig
558
572
  });
559
- const { key } = await fetchKey(new URL(sig.creator), CryptographicKey, {
573
+ const { key } = await fetchKey(creator, CryptographicKey, {
560
574
  ...options,
561
575
  keyCache: {
562
576
  get: () => Promise.resolve(void 0),
@@ -594,11 +608,12 @@ async function verifyCompactJsonLd(jsonLd, options = {}) {
594
608
  async function verifyJsonLdInternal(jsonLd, options, compact) {
595
609
  return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.verify", async (span) => {
596
610
  try {
597
- const verificationOptions = hasSignature(jsonLd) ? {
611
+ const hasLdSignature = hasVerifiableSignature(jsonLd);
612
+ const verificationOptions = hasLdSignature ? {
598
613
  ...options,
599
614
  contextLoader: getNormalizationContextLoader(options.contextLoader)
600
615
  } : options;
601
- const compacted = compact ? hasSignature(jsonLd) ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
616
+ const compacted = compact ? hasLdSignature ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
602
617
  const object = await Object$1.fromJsonLd(compacted, verificationOptions);
603
618
  if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
604
619
  span.setAttribute("activitypub.object.type", getTypeId(object).href);
@@ -1076,4 +1091,4 @@ async function verifyObject(cls, jsonLd, options = {}) {
1076
1091
  return object;
1077
1092
  }
1078
1093
  //#endregion
1079
- export { signJsonLd as _, doesActorOwnKey as a, verifySignature as b, assertSafeJsonLd as c, createSignature as d, detachSignature as f, isInvalidUrlTypeError as g, isClearlyMalformedContextReference as h, verifyProof as i, attachSignature as l, hasSignature as m, signObject as n, getKeyOwner as o, getNormalizationContextLoader as p, verifyObject as r, InvalidContextReferenceError as s, createProof as t, compactJsonLd as u, verifyCompactJsonLd as v, wrapContextLoaderForJsonLd as x, verifyJsonLd as y };
1094
+ export { wrapContextLoaderForJsonLd as S, isInvalidUrlTypeError as _, doesActorOwnKey as a, verifyJsonLd as b, assertSafeJsonLd as c, createSignature as d, describeSignatureShape as f, isClearlyMalformedContextReference as g, hasVerifiableSignature as h, verifyProof as i, attachSignature as l, getNormalizationContextLoader as m, signObject as n, getKeyOwner as o, detachSignature as p, verifyObject as r, InvalidContextReferenceError as s, createProof as t, compactJsonLd as u, signJsonLd as v, verifySignature as x, verifyCompactJsonLd as y };
@@ -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-CvHOP0XE.mjs";
5
- import { r as doubleKnockScoped } from "./http-DM--MHnA.mjs";
4
+ import { n as version, t as name } from "./deno-Bbso5CSl.mjs";
5
+ import { r as doubleKnockScoped } from "./http-Cp7sQLeG.mjs";
6
6
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
7
7
  import { FetchError, UrlError } from "@fedify/vocab-runtime";
8
8
  import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
@@ -7,8 +7,8 @@ import { i as assertExists, t as assertStringIncludes } from "../std__assert-Dfl
7
7
  import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
8
8
  import { t as assert } from "../assert-BhQd8QHP.mjs";
9
9
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
10
- import { t as exportJwk } from "../key-RrdwitZu.mjs";
11
- import { a as formatRfc9421SignatureParameters, c as signRequest, i as formatRfc9421Signature, l as timingSafeEqual, n as doubleKnock, o as parseRfc9421Signature, r as doubleKnockScoped, s as parseRfc9421SignatureInput, t as createRfc9421SignatureBase, u as verifyRequest } from "../http-DM--MHnA.mjs";
10
+ import { t as exportJwk } from "../key-CsY0Ifod.mjs";
11
+ import { a as formatRfc9421SignatureParameters, c as signRequest, i as formatRfc9421Signature, l as timingSafeEqual, n as doubleKnock, o as parseRfc9421Signature, r as doubleKnockScoped, s as parseRfc9421SignatureInput, t as createRfc9421SignatureBase, u as verifyRequest } from "../http-Cp7sQLeG.mjs";
12
12
  import { i as rsaPrivateKey2, l as rsaPublicKey5, o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-CCxRJhWa.mjs";
13
13
  import { mockDocumentLoader, test } from "@fedify/fixture";
14
14
  import { FetchError, exportSpki } from "@fedify/vocab-runtime";
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { a as ActorCallbackSetters, c as SenderKeyPair, d as exportJwk, l as HttpMessageSignaturesSpecDeterminer, n as Context, r as InboxContext, s as InboxListenerSetters, t as ActorKeyPairsDispatcher, u as signRequest } from "../callback-CJd-aCRE.mjs";
3
+ import { a as ActorCallbackSetters, c as SenderKeyPair, d as exportJwk, l as HttpMessageSignaturesSpecDeterminer, n as Context, r as InboxContext, s as InboxListenerSetters, t as ActorKeyPairsDispatcher, u as signRequest } from "../callback-BFMEE_9V.mjs";
4
4
  import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, Recipient } from "@fedify/vocab";
5
5
  import { TracerProvider } from "@opentelemetry/api";
6
6
  import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, DocumentLoaderFactoryOptions, exportMultibaseKey, exportSpki } from "@fedify/vocab-runtime";
@@ -6,9 +6,9 @@ import { n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
6
6
  import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as assert } from "../assert-BhQd8QHP.mjs";
8
8
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
9
- import { a as importJwk, i as generateCryptoKeyPair, o as validateCryptoKey, r as fetchKey, t as exportJwk } from "../key-RrdwitZu.mjs";
9
+ import { a as importJwk, i as generateCryptoKeyPair, o as validateCryptoKey, r as fetchKey, t as exportJwk } from "../key-CsY0Ifod.mjs";
10
10
  import { c as rsaPublicKey3, i as rsaPrivateKey2, o as rsaPublicKey1, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
11
- import { g as wrapContextLoaderForJsonLd } from "../ld-BpBoDQsD.mjs";
11
+ import { v as wrapContextLoaderForJsonLd } from "../ld-dYjiHKj1.mjs";
12
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
13
13
  import { CryptographicKey, Multikey, Person } from "@fedify/vocab";
14
14
  import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
@@ -5,11 +5,13 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
6
6
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
8
- import { i as generateCryptoKeyPair } from "../key-RrdwitZu.mjs";
8
+ import { i as generateCryptoKeyPair } from "../key-CsY0Ifod.mjs";
9
9
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
10
- import { a as compactJsonLd, d as isInvalidUrlTypeError, f as signJsonLd, h as verifySignature, i as attachSignature, m as verifyJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature } from "../ld-BpBoDQsD.mjs";
10
+ import { _ as verifySignature, a as compactJsonLd, c as detachSignature, d as hasVerifiableSignature, g as verifyJsonLd, i as attachSignature, m as signJsonLd, n as UnsafeJsonLdError, o as createSignature, p as isInvalidUrlTypeError, s as describeSignatureShape, u as hasSignature } from "../ld-dYjiHKj1.mjs";
11
+ import { t as ldSignatureWithoutCreated } from "../ld-signature-_KYhPsqt.mjs";
11
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
13
  import { Create, CryptographicKey, Note } from "@fedify/vocab";
14
+ import { configure, reset } from "@logtape/logtape";
13
15
  import { encodeBase64 } from "byte-encodings/base64";
14
16
  import jsonld from "@fedify/vocab-runtime/jsonld";
15
17
  //#region src/sig/ld.test.ts
@@ -112,6 +114,8 @@ test("createSignature()", async () => {
112
114
  type: "Create"
113
115
  };
114
116
  const sig = await createSignature(doc, rsaPrivateKey2, rsaPublicKey2.id, { contextLoader: mockDocumentLoader });
117
+ assertEquals(typeof sig.created, "string");
118
+ assert(hasSignature(attachSignature(doc, sig)));
115
119
  assertEquals(sig["@context"], "https://w3id.org/security/v1");
116
120
  assertEquals(await verifySignature(attachSignature(doc, sig), {
117
121
  documentLoader: mockDocumentLoader,
@@ -121,12 +125,15 @@ test("createSignature()", async () => {
121
125
  assertRejects(() => createSignature(doc, ed25519PrivateKey, ed25519Multikey.id, { contextLoader: mockDocumentLoader }), TypeError);
122
126
  });
123
127
  test("signJsonLd()", async () => {
124
- assert(await verifyJsonLd(await signJsonLd({
128
+ const signed = await signJsonLd({
125
129
  "@context": "https://www.w3.org/ns/activitystreams",
126
130
  id: "https://example.com/1",
127
131
  type: "Create",
128
132
  actor: "https://example.com/person2"
129
- }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader }), {
133
+ }, rsaPrivateKey3, rsaPublicKey3.id, { contextLoader: mockDocumentLoader });
134
+ assert(hasSignature(signed));
135
+ assertEquals(typeof signed.signature.created, "string");
136
+ assert(await verifyJsonLd(signed, {
130
137
  documentLoader: mockDocumentLoader,
131
138
  contextLoader: mockDocumentLoader
132
139
  }));
@@ -561,6 +568,218 @@ test("verification still rejects malformed JSON-LD", async () => {
561
568
  assertEquals(await verifySignature(malformed, options), null);
562
569
  assertEquals((await assertRejects(() => verifyJsonLd(malformed, options), Error)).name, "jsonld.SyntaxError");
563
570
  });
571
+ test("Linked Data verification without created", async (t) => {
572
+ const options = {
573
+ documentLoader: mockDocumentLoader,
574
+ contextLoader: mockDocumentLoader
575
+ };
576
+ await t.step("verifies the independently signed options", async () => {
577
+ assertFalse(hasSignature(ldSignatureWithoutCreated));
578
+ assertEquals(await verifySignature(ldSignatureWithoutCreated, options), rsaPublicKey3);
579
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, options));
580
+ });
581
+ await t.step("uses normalization contexts with a restrictive loader", async () => {
582
+ assert(await verifyJsonLd(ldSignatureWithoutCreated, {
583
+ ...options,
584
+ contextLoader: async (url) => {
585
+ if (url !== "https://w3id.org/security/v1" && url !== "https://w3id.org/security/data-integrity/v1") return await mockDocumentLoader(url);
586
+ throw new Error(`Unexpected context: ${url}`);
587
+ }
588
+ }));
589
+ });
590
+ await t.step("rejects tampering with the signed timestamp or content", async () => {
591
+ const inserted = {
592
+ ...ldSignatureWithoutCreated,
593
+ signature: {
594
+ ...ldSignatureWithoutCreated.signature,
595
+ created: "2024-09-12T16:50:46Z"
596
+ }
597
+ };
598
+ const removed = structuredClone(testVector);
599
+ Reflect.deleteProperty(removed.signature, "created");
600
+ const changed = structuredClone(testVector);
601
+ changed.signature.created = "2024-09-13T16:50:46Z";
602
+ const changedContent = structuredClone(ldSignatureWithoutCreated);
603
+ changedContent.object.content = "tampered";
604
+ for (const doc of [
605
+ inserted,
606
+ removed,
607
+ changed,
608
+ changedContent
609
+ ]) {
610
+ assertEquals(await verifySignature(doc, options), null);
611
+ assertFalse(await verifyJsonLd(doc, options));
612
+ }
613
+ });
614
+ await t.step("still rejects graph restructuring", async () => {
615
+ const { signature, ...document } = ldSignatureWithoutCreated;
616
+ await assertRejects(() => verifyJsonLd({
617
+ "@context": document["@context"],
618
+ "@graph": [document],
619
+ signature
620
+ }, options), UnsafeJsonLdError, "Unsupported JSON-LD keyword: @graph.");
621
+ });
622
+ });
623
+ test("Linked Data verification rejects malformed creator URLs", async () => {
624
+ let keyLoads = 0;
625
+ const options = {
626
+ documentLoader: (url) => {
627
+ keyLoads++;
628
+ return mockDocumentLoader(url);
629
+ },
630
+ contextLoader: mockDocumentLoader
631
+ };
632
+ for (const creator of [
633
+ "not a URL",
634
+ "",
635
+ "/keys/main",
636
+ "https://["
637
+ ]) for (const withCreated of [false, true]) {
638
+ const input = {
639
+ ...ldSignatureWithoutCreated,
640
+ signature: {
641
+ ...ldSignatureWithoutCreated.signature,
642
+ creator,
643
+ ...withCreated ? { created: "2024-09-12T16:50:46Z" } : {}
644
+ }
645
+ };
646
+ assert(hasVerifiableSignature(input));
647
+ assertEquals(await verifySignature(input, options), null);
648
+ assertFalse(await verifyJsonLd(input, options));
649
+ }
650
+ assertEquals(keyLoads, 0);
651
+ });
652
+ test("Linked Data verification distinguishes malformed and absent signatures", async () => {
653
+ const signature = {
654
+ type: "RsaSignature2017",
655
+ creator: "https://example.com/private-creator-sentinel#key",
656
+ signatureValue: "private-signature-sentinel"
657
+ };
658
+ assert(hasVerifiableSignature({ signature }));
659
+ assertFalse(hasSignature({ signature }));
660
+ for (const created of [
661
+ "2024-09-12T16:50:46Z",
662
+ "not a date",
663
+ ""
664
+ ]) {
665
+ const doc = { signature: {
666
+ ...signature,
667
+ created
668
+ } };
669
+ assert(hasVerifiableSignature(doc));
670
+ assert(hasSignature(doc));
671
+ }
672
+ const malformed = [
673
+ null,
674
+ [],
675
+ "signature",
676
+ {},
677
+ {
678
+ ...signature,
679
+ type: "OtherSignature"
680
+ },
681
+ {
682
+ ...signature,
683
+ type: ["RsaSignature2017"]
684
+ },
685
+ {
686
+ ...signature,
687
+ creator: {}
688
+ },
689
+ {
690
+ ...signature,
691
+ signatureValue: 1
692
+ },
693
+ ...[
694
+ void 0,
695
+ null,
696
+ 123,
697
+ {},
698
+ []
699
+ ].map((created) => ({
700
+ ...signature,
701
+ created
702
+ }))
703
+ ];
704
+ const records = [];
705
+ await configure({
706
+ sinks: { buffer: (record) => records.push(record) },
707
+ loggers: [{
708
+ category: [
709
+ "fedify",
710
+ "sig",
711
+ "ld"
712
+ ],
713
+ sinks: ["buffer"],
714
+ lowestLevel: "debug"
715
+ }, {
716
+ category: ["logtape", "meta"],
717
+ sinks: []
718
+ }],
719
+ reset: true
720
+ });
721
+ let keyLoads = 0;
722
+ const options = {
723
+ documentLoader: (url) => {
724
+ keyLoads++;
725
+ return mockDocumentLoader(url);
726
+ },
727
+ contextLoader: mockDocumentLoader
728
+ };
729
+ try {
730
+ for (const value of malformed) {
731
+ const doc = { signature: value };
732
+ assertFalse(hasVerifiableSignature(doc));
733
+ assertEquals(await verifySignature(doc, options), null);
734
+ }
735
+ assertEquals(keyLoads, 0);
736
+ assertEquals(records.length, malformed.length);
737
+ for (const record of records) {
738
+ assertEquals(record.level, "debug");
739
+ assertFalse(JSON.stringify(record).includes(signature.creator));
740
+ assertFalse(JSON.stringify(record).includes(signature.signatureValue));
741
+ }
742
+ assertEquals(records.at(-1)?.properties, {
743
+ signatureKind: "object",
744
+ signatureProperties: [
745
+ "created",
746
+ "creator",
747
+ "signatureValue",
748
+ "type"
749
+ ],
750
+ signaturePropertyCount: 4
751
+ });
752
+ for (const absent of [
753
+ null,
754
+ [],
755
+ 1,
756
+ {},
757
+ { type: "Create" }
758
+ ]) {
759
+ assertEquals(await verifySignature(absent, options), null);
760
+ assertFalse(hasVerifiableSignature(absent));
761
+ assertEquals(describeSignatureShape(absent), null);
762
+ }
763
+ assertEquals(records.length, malformed.length);
764
+ assertFalse(await verifyJsonLd({
765
+ ...ldSignatureWithoutCreated,
766
+ signature: {
767
+ ...signature,
768
+ created: 123
769
+ }
770
+ }, options));
771
+ assertEquals(records.length, malformed.length + 1);
772
+ assertEquals(keyLoads, 0);
773
+ } finally {
774
+ await reset();
775
+ }
776
+ const shape = describeSignatureShape({ signature: globalThis.Object.fromEntries(Array.from({ length: 30 }, (_, i) => [`field${i}`.padEnd(200, "x"), "secret"])) });
777
+ assertEquals(shape?.signaturePropertyCount, 30);
778
+ assertEquals(shape?.signatureProperties.length, 20);
779
+ assert(shape?.signatureProperties.every((name) => name.length === 80));
780
+ assertEquals(describeSignatureShape({ signature: null })?.signatureKind, "null");
781
+ assertEquals(describeSignatureShape({ signature: [] })?.signatureKind, "array");
782
+ });
564
783
  test("compactJsonLd() with restrictive context loader", async () => {
565
784
  const restrictiveContextLoader = async (resource) => {
566
785
  const url = new URL(resource).href;
package/dist/sig/mod.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_http = require("../http-CIiwaoIn.cjs");
5
- const require_proof = require("../proof-qxFPzf3D.cjs");
4
+ const require_http = require("../http-DBBUPm9V.cjs");
5
+ const require_proof = require("../proof-CCZCT2xF.cjs");
6
6
  exports.attachSignature = require_proof.attachSignature;
7
7
  exports.createProof = require_proof.createProof;
8
8
  exports.createSignature = require_proof.createSignature;
package/dist/sig/mod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "../http-CacZaxQy.js";
4
- import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "../proof-DJvdhpXO.js";
3
+ import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "../http-D03Qcwc-.js";
4
+ import { a as doesActorOwnKey, b as verifyJsonLd, d as createSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, p as detachSignature, r as verifyObject, t as createProof, v as signJsonLd, x as verifySignature } from "../proof-DGOXBmlo.js";
5
5
  export { attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };
@@ -6,7 +6,7 @@ import "../std__assert-DflMZha5.mjs";
6
6
  import { r as assertFalse } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as assert } from "../assert-BhQd8QHP.mjs";
8
8
  import { o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-CCxRJhWa.mjs";
9
- import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-zSUyR5Fs.mjs";
9
+ import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-A1Xol6Zh.mjs";
10
10
  import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
11
11
  import { Create, CryptographicKey, lookupObject } from "@fedify/vocab";
12
12
  //#region src/sig/owner.test.ts
@@ -6,10 +6,10 @@ import "../std__assert-DflMZha5.mjs";
6
6
  import { n as assertInstanceOf } from "../assert-BhQd8QHP.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
8
8
  import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
9
- import { f as signJsonLd, h as verifySignature, s as detachSignature } from "../ld-BpBoDQsD.mjs";
10
- import { i as verifyProof, n as signObject, r as verifyObject, t as createProof } from "../proof-C90umkRN.mjs";
9
+ import { _ as verifySignature, c as detachSignature, m as signJsonLd } from "../ld-dYjiHKj1.mjs";
10
+ import { i as verifyProof, n as signObject, r as verifyObject, t as createProof } from "../proof-DCqYLXDl.mjs";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
- import { Create, DataIntegrityProof, Multikey, Note, Place } from "@fedify/vocab";
12
+ import { Create, DataIntegrityProof, Multikey, Note, OrderedCollectionPage, Place } from "@fedify/vocab";
13
13
  import { decodeMultibase, importMultibaseKey } from "@fedify/vocab-runtime";
14
14
  import { decodeHex, encodeHex } from "byte-encodings/hex";
15
15
  //#region src/sig/proof.test.ts
@@ -153,6 +153,29 @@ test("signObject()", async () => {
153
153
  contextLoader: mockDocumentLoader
154
154
  }), TypeError, "Unsupported algorithm");
155
155
  });
156
+ test("collection serialization preserves cached object integrity proofs", async () => {
157
+ const options = {
158
+ documentLoader: mockDocumentLoader,
159
+ contextLoader: mockDocumentLoader
160
+ };
161
+ const source = await (await signObject(fep8b32TestVectorActivity, fep8b32TestVectorPrivateKey, fep8b32TestVectorKeyId, {
162
+ ...options,
163
+ created: Temporal.Instant.from("2023-02-24T23:36:38Z")
164
+ })).toJsonLd(options);
165
+ assertInstanceOf(await verifyObject(Create, source, options), Create);
166
+ const cached = await Create.fromJsonLd(source, options);
167
+ const json = await new OrderedCollectionPage({
168
+ id: new URL("https://server.example/outbox?page=1"),
169
+ items: [cached]
170
+ }).toJsonLd(options);
171
+ assertEquals(json.orderedItems[0], source);
172
+ assertEquals(await cached.toJsonLd(), source);
173
+ assertInstanceOf(await verifyObject(Create, json.orderedItems[0], options), Create);
174
+ const restored = await OrderedCollectionPage.fromJsonLd(json, options);
175
+ const items = await Array.fromAsync(restored.getItems(options));
176
+ assertEquals(items.length, 1);
177
+ assertEquals(await items[0].toJsonLd(), source);
178
+ });
156
179
  test("signObject() migrates proofs from an older context", async () => {
157
180
  const oldContext = [
158
181
  "https://w3id.org/identity/v1",
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { c as getNormalizationContextLoader } from "./ld-BpBoDQsD.mjs";
4
+ import { l as getNormalizationContextLoader } from "./ld-dYjiHKj1.mjs";
5
5
  import jsonld from "@fedify/vocab-runtime/jsonld";
6
6
  import { normalizeDateTimeLiteral } from "@fedify/vocab-runtime/temporal";
7
7
  //#region src/federation/temporal.ts
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { i as RequestContext, o as Federation, r as InboxContext } from "../callback-CJd-aCRE.mjs";
3
+ import { i as RequestContext, o as Federation, r as InboxContext } from "../callback-BFMEE_9V.mjs";
4
4
  import { testDefinitions } from "@fedify/fixture";
5
5
 
6
6
  //#region src/testing/context.d.ts