@fedify/fedify 2.4.6-dev.2628 → 2.4.6

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 (133) hide show
  1. package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
  2. package/dist/{builder-kj5boG2l.mjs → builder-CadJYxhX.mjs} +2 -2
  3. package/dist/callback-DPDs_dxC.d.mts +5280 -0
  4. package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
  5. package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
  6. package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
  7. package/dist/compat/attachment-arrays.test.d.mts +2 -0
  8. package/dist/compat/attachment-arrays.test.mjs +255 -0
  9. package/dist/compat/mod.cjs +1 -1
  10. package/dist/compat/mod.d.cts +1 -1
  11. package/dist/compat/mod.d.ts +1 -1
  12. package/dist/compat/mod.js +1 -1
  13. package/dist/compat/outgoing-jsonld.test.mjs +1 -1
  14. package/dist/compat/transformers.test.mjs +1 -1
  15. package/dist/{compound-proof-BoNAYSHt.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
  16. package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
  17. package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
  18. package/dist/{deno-ksnVeCA7.mjs → deno-BKSRi6w3.mjs} +1 -1
  19. package/dist/{docloader-BhVNi06k.mjs → docloader-BcDiJfFl.mjs} +2 -2
  20. package/dist/federation/attachment-responses.test.d.mts +2 -0
  21. package/dist/federation/attachment-responses.test.mjs +182 -0
  22. package/dist/federation/builder.test.mjs +1 -1
  23. package/dist/federation/compound-fanout.test.mjs +4 -4
  24. package/dist/federation/delivery-attachments.test.d.mts +2 -0
  25. package/dist/federation/delivery-attachments.test.mjs +288 -0
  26. package/dist/federation/handler-compound-proof.test.mjs +3 -3
  27. package/dist/federation/handler.test.mjs +206 -14
  28. package/dist/federation/hashlink-media.test.mjs +2 -2
  29. package/dist/federation/idempotency.test.mjs +2 -2
  30. package/dist/federation/inbox-report.test.mjs +5 -5
  31. package/dist/federation/inbox.test.mjs +1 -1
  32. package/dist/federation/metrics.test.mjs +1 -1
  33. package/dist/federation/middleware.test.mjs +1188 -13
  34. package/dist/federation/mod.cjs +1 -1
  35. package/dist/federation/mod.d.cts +3 -3
  36. package/dist/federation/mod.d.ts +3 -3
  37. package/dist/federation/mod.js +1 -1
  38. package/dist/federation/outgoing-proof.test.mjs +4 -4
  39. package/dist/federation/portable-actor.test.mjs +3 -3
  40. package/dist/federation/portable-chain.test.mjs +3 -3
  41. package/dist/federation/portable-collection.test.mjs +4 -4
  42. package/dist/federation/portable-delivery.test.mjs +2 -2
  43. package/dist/federation/portable-gateway-keys.test.mjs +5 -5
  44. package/dist/federation/portable-inbox.test.mjs +4 -4
  45. package/dist/federation/portable-parse-uri.test.mjs +1 -1
  46. package/dist/federation/portable-route-activity.test.mjs +2 -2
  47. package/dist/federation/portable.test.mjs +3 -3
  48. package/dist/federation/send.test.mjs +293 -3
  49. package/dist/federation/tasks/enqueue.test.mjs +1 -1
  50. package/dist/federation/tasks/tasks.test.mjs +2 -2
  51. package/dist/federation/temporal.test.mjs +25 -1
  52. package/dist/federation/webfinger.test.mjs +1 -1
  53. package/dist/{federation-BtPz9sr3.cjs → federation-CM4nzbhO.cjs} +501 -145
  54. package/dist/{http-BSARoDPh.mjs → http-B6sfb5xN.mjs} +8 -6
  55. package/dist/{http-rH230xCD.js → http-BwgldAIk.js} +2803 -2633
  56. package/dist/{http-CeVcKQMZ.cjs → http-Tj9eQ_rd.cjs} +2640 -2458
  57. package/dist/{inbox-BdZenpZQ.mjs → inbox-B7NVkb8j.mjs} +2 -2
  58. package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
  59. package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
  60. package/dist/{kv-cache-CNfNI_95.js → kv-cache-C-5yfTw-.js} +1 -1
  61. package/dist/{kv-cache-Cxn7pNMx.mjs → kv-cache-CvWuigft.mjs} +1 -1
  62. package/dist/{kv-cache-BpGIONmd.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
  63. package/dist/{ld-DJZrjNuN.mjs → ld-BGnZDnia.mjs} +176 -24
  64. package/dist/ld-signature-D1tFSFK8.mjs +23 -0
  65. package/dist/{metrics-DtxsYIkN.mjs → metrics-DHUP4F1-.mjs} +1 -1
  66. package/dist/{middleware-DyEjt33n.mjs → middleware-CUb31OGG.mjs} +1 -1
  67. package/dist/{middleware-DDvck2q9.js → middleware-DX8wADUa.js} +452 -98
  68. package/dist/{middleware-DblGj642.mjs → middleware-mRXKHq68.mjs} +445 -176
  69. package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
  70. package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
  71. package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
  72. package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
  73. package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
  74. package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
  75. package/dist/mod.cjs +6 -6
  76. package/dist/mod.d.cts +8 -8
  77. package/dist/mod.d.ts +8 -8
  78. package/dist/mod.js +6 -6
  79. package/dist/nodeinfo/client.test.mjs +432 -4
  80. package/dist/nodeinfo/handler.test.mjs +1 -1
  81. package/dist/nodeinfo/mod.cjs +1 -1
  82. package/dist/nodeinfo/mod.d.cts +1 -1
  83. package/dist/nodeinfo/mod.d.ts +1 -1
  84. package/dist/nodeinfo/mod.js +1 -1
  85. package/dist/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
  86. package/dist/{owner-2vfqhUJw.mjs → owner-DEiBiiqR.mjs} +4 -4
  87. package/dist/{portable-collection-Cs--KD5A.cjs → portable-collection--h11WDIi.cjs} +3 -2
  88. package/dist/{portable-collection-DKJwGO8S.mjs → portable-collection-D0-tInp2.mjs} +2 -2
  89. package/dist/{portable-collection-B7AQ_dW7.js → portable-collection-M6d5I5JQ.js} +3 -2
  90. package/dist/{portable-key-DXGepvtD.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
  91. package/dist/portable-verifier-CPA86vIP.js +22 -0
  92. package/dist/portable-verifier-DiLU8c9T.cjs +26 -0
  93. package/dist/{proof-DW0FK6Cp.mjs → proof-C4pwAF2k.mjs} +31 -11
  94. package/dist/{send-CqsocpvF.mjs → send-ivzJCtb-.mjs} +100 -22
  95. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  96. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  97. package/dist/sig/compound-proof-verification.test.mjs +2 -2
  98. package/dist/sig/compound-proof.test.mjs +3 -3
  99. package/dist/sig/http.test.mjs +2 -2
  100. package/dist/sig/key-types.test.d.mts +162 -0
  101. package/dist/sig/key-types.test.mjs +8 -0
  102. package/dist/sig/key.test.mjs +1 -1
  103. package/dist/sig/ld.test.mjs +572 -7
  104. package/dist/sig/mitra-receive-interop.test.mjs +4 -4
  105. package/dist/sig/mitra-send-interop.test.mjs +3 -3
  106. package/dist/sig/mod.cjs +2 -2
  107. package/dist/sig/mod.d.cts +3 -3
  108. package/dist/sig/mod.d.ts +3 -3
  109. package/dist/sig/mod.js +2 -2
  110. package/dist/sig/owner.test.mjs +1 -1
  111. package/dist/sig/portable-collection.test.mjs +1 -1
  112. package/dist/sig/portable-interop.test.mjs +3 -3
  113. package/dist/sig/portable-key.test.mjs +5 -5
  114. package/dist/sig/proof.test.mjs +100 -6
  115. package/dist/sig/tootik-request-interop.test.mjs +4 -4
  116. package/dist/sig/tootik-send-interop.test.mjs +3 -3
  117. package/dist/sig/verification.test.mjs +3 -3
  118. package/dist/{temporal-Dm2E1-vs.mjs → temporal-B6OlxwK_.mjs} +3 -5
  119. package/dist/testing/kv.test.mjs +1 -1
  120. package/dist/testing/mod.d.mts +3 -5045
  121. package/dist/{transformers-DAtXl_Kc.js → transformers-BlJ53iKs.js} +3 -2
  122. package/dist/{transformers-BalCrSsr.cjs → transformers-aIK89ibB.cjs} +3 -2
  123. package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
  124. package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
  125. package/dist/utils/docloader.test.mjs +2 -2
  126. package/dist/utils/kv-cache.test.mjs +1 -1
  127. package/dist/utils/mod.cjs +1 -1
  128. package/dist/utils/mod.d.cts +1 -1
  129. package/dist/utils/mod.d.ts +1 -1
  130. package/dist/utils/mod.js +1 -1
  131. package/dist/utils/portable-verifier.test.d.mts +2 -0
  132. package/dist/utils/portable-verifier.test.mjs +126 -0
  133. package/package.json +6 -6
@@ -2,8 +2,8 @@ import { Temporal } from "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as getAuthenticationOrigin } from "./portable-key-id-Ca30-hOa.mjs";
5
- import { n as version, t as name } from "./deno-ksnVeCA7.mjs";
6
- import { g as recordInboxActivity, n as getDurationMs, r as getFederationMetrics } from "./metrics-DtxsYIkN.mjs";
5
+ import { n as version, t as name } from "./deno-BKSRi6w3.mjs";
6
+ import { g as recordInboxActivity, n as getDurationMs, r as getFederationMetrics } from "./metrics-DHUP4F1-.mjs";
7
7
  import { getLogger } from "@logtape/logtape";
8
8
  import { getTypeId } from "@fedify/vocab";
9
9
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
@@ -1,6 +1,6 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { Actor, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1 } from "@fedify/vocab";
3
- import { DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
3
+ import { CryptoKeyLike, DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
4
4
  import { MeterProvider, TracerProvider } from "@opentelemetry/api";
5
5
  //#region src/sig/proof.d.ts
6
6
  /**
@@ -40,7 +40,7 @@ interface CreateProofOptions {
40
40
  * @throws {TypeError} If the private key is invalid or unsupported.
41
41
  * @since 0.10.0
42
42
  */
43
- declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
43
+ declare function createProof(object: Object$1, privateKey: CryptoKeyLike, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
44
44
  /**
45
45
  * Options for {@link signObject}.
46
46
  * @since 0.10.0
@@ -67,7 +67,7 @@ interface SignObjectOptions extends CreateProofOptions {
67
67
  * @throws {TypeError} If the private key is invalid or unsupported.
68
68
  * @since 0.10.0
69
69
  */
70
- declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKey, keyId: URL, options?: SignObjectOptions): Promise<T>;
70
+ declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKeyLike, keyId: URL, options?: SignObjectOptions): Promise<T>;
71
71
  /**
72
72
  * Options for {@link verifyProof}.
73
73
  * @since 0.10.0
@@ -548,7 +548,7 @@ interface Rfc9421SignRequestOptions {
548
548
  * @returns The signed request.
549
549
  * @throws {TypeError} If the private key is invalid or unsupported.
550
550
  */
551
- declare function signRequest(request: Request, privateKey: CryptoKey, keyId: URL, options?: SignRequestOptions): Promise<Request>;
551
+ declare function signRequest(request: Request, privateKey: CryptoKeyLike, keyId: URL, options?: SignRequestOptions): Promise<Request>;
552
552
  /**
553
553
  * Options for {@link verifyRequest}.
554
554
  */
@@ -901,7 +901,7 @@ declare function generateCryptoKeyPair(algorithm?: "RSASSA-PKCS1-v1_5" | "Ed2551
901
901
  * serialization and storage.
902
902
  * @throws {TypeError} If the key is invalid or unsupported.
903
903
  */
904
- declare function exportJwk(key: CryptoKey): Promise<JsonWebKey>;
904
+ declare function exportJwk(key: CryptoKeyLike): Promise<JsonWebKey>;
905
905
  /**
906
906
  * Imports a key from JWK format.
907
907
  * @param jwk The key in JWK format.
@@ -1,7 +1,7 @@
1
1
  /// <reference lib="esnext.temporal" />
2
2
  import { Actor, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1 } from "@fedify/vocab";
3
3
  import { MeterProvider, TracerProvider } from "@opentelemetry/api";
4
- import { DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
4
+ import { CryptoKeyLike, DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
5
5
  //#region src/sig/proof.d.ts
6
6
  /**
7
7
  * Checks if the given JSON-LD document has a DataIntegrityProof-like object,
@@ -40,7 +40,7 @@ interface CreateProofOptions {
40
40
  * @throws {TypeError} If the private key is invalid or unsupported.
41
41
  * @since 0.10.0
42
42
  */
43
- declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
43
+ declare function createProof(object: Object$1, privateKey: CryptoKeyLike, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
44
44
  /**
45
45
  * Options for {@link signObject}.
46
46
  * @since 0.10.0
@@ -67,7 +67,7 @@ interface SignObjectOptions extends CreateProofOptions {
67
67
  * @throws {TypeError} If the private key is invalid or unsupported.
68
68
  * @since 0.10.0
69
69
  */
70
- declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKey, keyId: URL, options?: SignObjectOptions): Promise<T>;
70
+ declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKeyLike, keyId: URL, options?: SignObjectOptions): Promise<T>;
71
71
  /**
72
72
  * Options for {@link verifyProof}.
73
73
  * @since 0.10.0
@@ -548,7 +548,7 @@ interface Rfc9421SignRequestOptions {
548
548
  * @returns The signed request.
549
549
  * @throws {TypeError} If the private key is invalid or unsupported.
550
550
  */
551
- declare function signRequest(request: Request, privateKey: CryptoKey, keyId: URL, options?: SignRequestOptions): Promise<Request>;
551
+ declare function signRequest(request: Request, privateKey: CryptoKeyLike, keyId: URL, options?: SignRequestOptions): Promise<Request>;
552
552
  /**
553
553
  * Options for {@link verifyRequest}.
554
554
  */
@@ -901,7 +901,7 @@ declare function generateCryptoKeyPair(algorithm?: "RSASSA-PKCS1-v1_5" | "Ed2551
901
901
  * serialization and storage.
902
902
  * @throws {TypeError} If the key is invalid or unsupported.
903
903
  */
904
- declare function exportJwk(key: CryptoKey): Promise<JsonWebKey>;
904
+ declare function exportJwk(key: CryptoKeyLike): Promise<JsonWebKey>;
905
905
  /**
906
906
  * Imports a key from JWK format.
907
907
  * @param jwk The key in JWK format.
@@ -1,6 +1,6 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { G as validateCryptoKey, ot as recordDocumentCache, t as doubleKnockScoped } from "./http-rH230xCD.js";
3
+ import { G as validateCryptoKey, ot as recordDocumentCache, t as doubleKnockScoped } from "./http-BwgldAIk.js";
4
4
  import { getLogger } from "@logtape/logtape";
5
5
  import { FetchError, UrlError, createActivityPubRequest, getRemoteDocument, logRequest, preloadedContexts, resolveDocumentLoaderTimeout, withDocumentLoaderTimeout } from "@fedify/vocab-runtime";
6
6
  import { curry } from "es-toolkit";
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "temporal-polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { p as recordDocumentCache } from "./metrics-DtxsYIkN.mjs";
4
+ import { p as recordDocumentCache } from "./metrics-DHUP4F1-.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,5 +1,5 @@
1
1
  const { URLPattern } = require("urlpattern-polyfill");
2
- const require_http = require("./http-CeVcKQMZ.cjs");
2
+ const require_http = require("./http-Tj9eQ_rd.cjs");
3
3
  let _logtape_logtape = require("@logtape/logtape");
4
4
  let _fedify_vocab_runtime = require("@fedify/vocab-runtime");
5
5
  let es_toolkit = require("es-toolkit");
@@ -3,16 +3,36 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { c as isPortableActorDocument, d as isPortableUri, l as isPortableId, m as parseKeyIdString, s as isCompatibleKeyId } from "./portable-key-id-Ca30-hOa.mjs";
5
5
  import { a as verificationObservation, i as triedKey, n as observeCheck, t as observeAttempt } from "./verification-Dpfcw8ml.mjs";
6
- import { n as version, t as name } from "./deno-ksnVeCA7.mjs";
7
- import { _ as recordKeyLookup, n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch, t as classifyFetchError } from "./metrics-DtxsYIkN.mjs";
6
+ import { n as version, t as name } from "./deno-BKSRi6w3.mjs";
7
+ import { _ as recordKeyLookup, n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch, t as classifyFetchError } from "./metrics-DHUP4F1-.mjs";
8
8
  import { n as attachKeyOwnerEvidence, t as MAX_PORTABLE_KEY_TTL } from "./key-owner-evidence-APB6NpSk.mjs";
9
9
  import { getLogger } from "@logtape/logtape";
10
10
  import { Activity, CryptographicKey, Multikey, Object as Object$1, getTypeId, isActor } from "@fedify/vocab";
11
11
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
12
- import { FetchError, UrlError, getDocumentLoader, parseDidKeyVerificationMethod } from "@fedify/vocab-runtime";
12
+ import { FetchError, UrlError, getDocumentLoader, parseDidKeyVerificationMethod, preloadedContexts } from "@fedify/vocab-runtime";
13
+ import { asCryptoKey } from "@fedify/vocab-runtime/internal";
13
14
  import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
14
15
  import { encodeHex } from "byte-encodings/hex";
15
16
  import jsonld from "@fedify/vocab-runtime/jsonld";
17
+ //#region src/utils/portable-verifier.ts
18
+ /**
19
+ * Gets the default FEP-ef61 portable object verifier of a vocabulary object,
20
+ * so that Fedify can pass it on to a clone of the object explicitly, since
21
+ * `clone()` does not inherit it.
22
+ *
23
+ * This reads the protected `_verifyPortableObject` accessor of generated
24
+ * vocabulary classes, which is an internal cross-package contract with
25
+ * `@fedify/vocab-tools`.
26
+ *
27
+ * @param object The vocabulary object.
28
+ * @returns The object's default verifier, or `undefined` if it has none.
29
+ * @internal
30
+ */
31
+ function getDefaultPortableObjectVerifier(object) {
32
+ const verifier = Reflect.get(object, "_verifyPortableObject");
33
+ return typeof verifier === "function" ? verifier : void 0;
34
+ }
35
+ //#endregion
16
36
  //#region src/sig/key.ts
17
37
  /** Classifies decoding failures without hiding unexpected loader errors. */
18
38
  function classifyKeyJsonLdError(error, seen = /* @__PURE__ */ new Set()) {
@@ -124,7 +144,7 @@ function generateCryptoKeyPair(algorithm) {
124
144
  */
125
145
  async function exportJwk(key) {
126
146
  validateCryptoKey(key);
127
- const jwk = await crypto.subtle.exportKey("jwk", key);
147
+ const jwk = await crypto.subtle.exportKey("jwk", asCryptoKey(key));
128
148
  if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
129
149
  return jwk;
130
150
  }
@@ -684,7 +704,7 @@ async function resolveFetchedKey(document, cacheKey, documentUrl, keyId, cls, {
684
704
  }
685
705
  let key = null;
686
706
  let ownerDocument = null;
687
- if (object instanceof cls && (object.id == null || object.id.href === keyId)) key = object.id == null ? object.clone({ id: cacheKey }) : object;
707
+ if (object instanceof cls && (object.id == null || object.id.href === keyId)) key = object.id == null ? object.clone({ id: cacheKey }, { verifyPortableObject: getDefaultPortableObjectVerifier(object) }) : object;
688
708
  else if (isActor(object)) {
689
709
  if (object.id == null || isPortableId(object.id) || object.id.origin !== documentUrl.origin) {
690
710
  logger.debug("Failed to verify; the document served at {documentUrl} claims to be the actor {actorId}, which belongs to another origin.", {
@@ -774,7 +794,7 @@ async function resolveFetchedKey(document, cacheKey, documentUrl, keyId, cls, {
774
794
  cached: false
775
795
  };
776
796
  }
777
- if (ownerDocument != null && claimedOwnerId == null) key = key instanceof CryptographicKey ? key.clone({ owner: ownerDocument.id }) : key.clone({ controller: ownerDocument.id });
797
+ if (ownerDocument != null && claimedOwnerId == null) key = key instanceof CryptographicKey ? key.clone({ owner: ownerDocument.id }, { verifyPortableObject: getDefaultPortableObjectVerifier(key) }) : key.clone({ controller: ownerDocument.id }, { verifyPortableObject: getDefaultPortableObjectVerifier(key) });
778
798
  else if (claimedOwnerId != null && claimedOwnerId.href !== ownerDocument?.id?.href) {
779
799
  if (await verifyKeyOwnershipInternal(key, {
780
800
  documentLoader,
@@ -1353,24 +1373,110 @@ function assertSafeJsonLd(jsonLd) {
1353
1373
  }
1354
1374
  }
1355
1375
  }
1376
+ const signatureTermDefinition = { "signature": "https://w3id.org/security#signature" };
1377
+ const signatureDefiningContexts = /* @__PURE__ */ new Set(["https://w3id.org/identity/v1", "https://w3id.org/security/v1"]);
1378
+ const signatureFreeContexts = getSignatureFreeContexts();
1379
+ function getSignatureFreeContexts() {
1380
+ const urls = /* @__PURE__ */ new Set();
1381
+ for (const [url, document] of globalThis.Object.entries(preloadedContexts)) {
1382
+ if (typeof document !== "object" || document == null) continue;
1383
+ const context = document["@context"];
1384
+ if (typeof context !== "object" || context == null || Array.isArray(context)) continue;
1385
+ const record = context;
1386
+ if (!globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) urls.add(url);
1387
+ }
1388
+ return urls;
1389
+ }
1390
+ function getContextEntryEffect(entry) {
1391
+ if (entry == null) return "resets";
1392
+ if (typeof entry === "string") {
1393
+ if (signatureDefiningContexts.has(entry)) return "defines";
1394
+ if (signatureFreeContexts.has(entry)) return "absent";
1395
+ return "unknown";
1396
+ }
1397
+ if (typeof entry !== "object") return "absent";
1398
+ const record = entry;
1399
+ if (globalThis.Object.prototype.hasOwnProperty.call(record, "signature")) {
1400
+ const definition = record["signature"];
1401
+ const contextProtected = record["@protected"] === true;
1402
+ const imported = globalThis.Object.prototype.hasOwnProperty.call(record, "@import");
1403
+ if (definition == null) {
1404
+ if (contextProtected) return "defines";
1405
+ return imported ? "unknown" : "resets";
1406
+ }
1407
+ if (typeof definition === "object" && !Array.isArray(definition)) {
1408
+ const term = definition;
1409
+ const protectedTerm = contextProtected || term["@protected"] === true;
1410
+ if (globalThis.Object.prototype.hasOwnProperty.call(term, "@id") && term["@id"] == null) {
1411
+ if (protectedTerm) return "defines";
1412
+ return imported ? "unknown" : "resets";
1413
+ }
1414
+ }
1415
+ return "defines";
1416
+ }
1417
+ if (globalThis.Object.prototype.hasOwnProperty.call(record, "@import")) return "unknown";
1418
+ return "absent";
1419
+ }
1420
+ function getSignatureTermState(context) {
1421
+ if (context == null) return "absent";
1422
+ if (!Array.isArray(context)) {
1423
+ const effect = getContextEntryEffect(context);
1424
+ return effect === "defines" ? "defined" : effect === "unknown" ? "unknown" : "absent";
1425
+ }
1426
+ let state = "absent";
1427
+ for (const entry of context) {
1428
+ const effect = getContextEntryEffect(entry);
1429
+ if (effect === "defines") state = "defined";
1430
+ else if (effect === "resets") state = "absent";
1431
+ else if (effect === "unknown" && state !== "defined") state = "unknown";
1432
+ }
1433
+ return state;
1434
+ }
1435
+ function prepareSignatureDocument(jsonLd) {
1436
+ if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) return jsonLd;
1437
+ const document = jsonLd;
1438
+ if (document["proof"] != null) return { ...document };
1439
+ const context = document["@context"];
1440
+ if (getSignatureTermState(context) !== "absent") return { ...document };
1441
+ const definition = { ...signatureTermDefinition };
1442
+ return {
1443
+ ...document,
1444
+ "@context": context == null ? [definition] : Array.isArray(context) ? [...context, definition] : [context, definition]
1445
+ };
1446
+ }
1356
1447
  /**
1357
1448
  * Attaches a LD signature to the given JSON-LD document.
1449
+ *
1450
+ * When the document's context does not already define the `signature`
1451
+ * property, the returned document adds a minimal inline context for it.
1452
+ * Without that definition, expanding the attached signature would produce a
1453
+ * blank node predicate, which is not valid RDF. Documents that already carry
1454
+ * a `proof` are left unchanged, since a new context definition would invalidate
1455
+ * the proof. Documents whose context includes an unrecognized remote context
1456
+ * are also left unchanged, since that context may already define `signature`.
1358
1457
  * @param jsonLd The JSON-LD document to attach the signature to. It is not
1359
1458
  * modified.
1360
1459
  * @param signature The signature to attach.
1361
1460
  * @returns The JSON-LD document with the attached signature.
1362
1461
  * @throws {TypeError} If the input document is not a valid JSON-LD document.
1462
+ * Top-level arrays are rejected, since a Linked Data
1463
+ * Signature is attached to a single node.
1363
1464
  * @since 1.0.0
1364
1465
  */
1365
1466
  function attachSignature(jsonLd, signature) {
1366
- if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
1367
- return {
1368
- ...jsonLd,
1369
- signature
1370
- };
1467
+ if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd)) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
1468
+ const output = prepareSignatureDocument(jsonLd);
1469
+ output.signature = signature;
1470
+ return output;
1371
1471
  }
1372
1472
  /**
1373
1473
  * Creates a LD signature for the given JSON-LD document.
1474
+ *
1475
+ * If the document's context does not define the `signature` property, the
1476
+ * signature is computed over the document with a minimal inline definition
1477
+ * added. Use {@link attachSignature} to attach the signature to that exact
1478
+ * document. Documents that already carry a `proof`, or whose context includes
1479
+ * an unrecognized remote context, are hashed unchanged.
1374
1480
  * @param jsonLd The JSON-LD document to sign.
1375
1481
  * @param privateKey The private key to sign the document.
1376
1482
  * @param keyId The ID of the public key that corresponds to the private key.
@@ -1384,14 +1490,17 @@ async function createSignature(jsonLd, privateKey, keyId, { contextLoader, creat
1384
1490
  validateCryptoKey(privateKey, "private");
1385
1491
  if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
1386
1492
  const options = {
1387
- "@context": "https://w3id.org/identity/v1",
1388
1493
  creator: keyId.href,
1389
1494
  created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
1390
1495
  };
1391
- const message = await hashJsonLd(options, contextLoader) + await hashJsonLd(jsonLd, contextLoader);
1496
+ const message = await hashJsonLd({
1497
+ "@context": "https://w3id.org/identity/v1",
1498
+ ...options
1499
+ }, contextLoader) + await hashJsonLd(prepareSignatureDocument(jsonLd), contextLoader);
1392
1500
  const messageBytes = new TextEncoder().encode(message);
1393
- const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, messageBytes);
1501
+ const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", asCryptoKey(privateKey), messageBytes);
1394
1502
  return {
1503
+ "@context": "https://w3id.org/security/v1",
1395
1504
  ...options,
1396
1505
  type: "RsaSignature2017",
1397
1506
  signatureValue: encodeBase64(signature)
@@ -1430,6 +1539,24 @@ async function signJsonLd(jsonLd, privateKey, keyId, options) {
1430
1539
  }
1431
1540
  });
1432
1541
  }
1542
+ /** @internal */
1543
+ function hasVerifiableSignature(jsonLd) {
1544
+ if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || !("signature" in jsonLd)) return false;
1545
+ const signature = jsonLd.signature;
1546
+ if (typeof signature !== "object" || signature == null || Array.isArray(signature)) return false;
1547
+ 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";
1548
+ }
1549
+ /** @internal */
1550
+ function describeSignatureShape(jsonLd) {
1551
+ if (typeof jsonLd !== "object" || jsonLd == null || !("signature" in jsonLd)) return null;
1552
+ const signature = jsonLd.signature;
1553
+ const properties = typeof signature === "object" && signature != null ? globalThis.Object.keys(signature) : [];
1554
+ return {
1555
+ signatureKind: signature == null ? String(signature) : Array.isArray(signature) ? "array" : typeof signature,
1556
+ signatureProperties: properties.sort().slice(0, 20).map((p) => p.slice(0, 80)),
1557
+ signaturePropertyCount: properties.length
1558
+ };
1559
+ }
1433
1560
  /**
1434
1561
  * Checks if the given JSON-LD document has a Linked Data Signature-like
1435
1562
  * object, without restricting it to a single suite-specific shape.
@@ -1494,6 +1621,10 @@ function detachSignature(jsonLd) {
1494
1621
  * `activitypub.signature.key_fetch.duration`, since the rest of the work
1495
1622
  * that the verification-duration metric is meant to cover happens in
1496
1623
  * `verifyJsonLd`.
1624
+ *
1625
+ * Unmapped properties discarded during JSON-LD processing are tolerated, but
1626
+ * their values are not authenticated by the signature. Other unsafe
1627
+ * canonicalization warnings, including relative IRIs, remain rejected.
1497
1628
  * @param jsonLd The JSON-LD document to verify.
1498
1629
  * @param options Options for verifying the signature.
1499
1630
  * @returns The public key that signed the document or `null` if the signature
@@ -1501,7 +1632,11 @@ function detachSignature(jsonLd) {
1501
1632
  * @since 1.0.0
1502
1633
  */
1503
1634
  async function verifySignature(jsonLd, options = {}) {
1504
- if (!hasSignature(jsonLd)) return null;
1635
+ if (!hasVerifiableSignature(jsonLd)) {
1636
+ const shape = describeSignatureShape(jsonLd);
1637
+ if (shape != null) logger.debug("Linked Data Signature has an unsupported shape: {signatureKind}; properties: {signatureProperties}.", shape);
1638
+ return null;
1639
+ }
1505
1640
  if (options[verificationObservation]?.attempt != null && options[verificationObservation]?.check == null) {
1506
1641
  const declared = getLdSignatureObject(jsonLd)?.creator;
1507
1642
  return await observeCheck(options, { mechanism: "linkedData" }, typeof declared === "string" ? declared : null, (observation) => verifySignature(jsonLd, {
@@ -1520,7 +1655,14 @@ async function verifySignature(jsonLd, options = {}) {
1520
1655
  });
1521
1656
  return null;
1522
1657
  }
1523
- const { key, cached } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(new URL(sig.creator), CryptographicKey, options));
1658
+ let creator;
1659
+ try {
1660
+ creator = new URL(sig.creator);
1661
+ } catch {
1662
+ logger.debug("Failed to verify; signature creator is not a valid URL.");
1663
+ return null;
1664
+ }
1665
+ const { key, cached } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(creator, CryptographicKey, options));
1524
1666
  if (key == null) return null;
1525
1667
  const sigOpts = {
1526
1668
  ...sig,
@@ -1531,7 +1673,7 @@ async function verifySignature(jsonLd, options = {}) {
1531
1673
  delete sigOpts.signatureValue;
1532
1674
  let sigOptsHash;
1533
1675
  try {
1534
- sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
1676
+ sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader, "verify");
1535
1677
  } catch (error) {
1536
1678
  logger.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
1537
1679
  signatureOptions: sigOpts,
@@ -1543,7 +1685,7 @@ async function verifySignature(jsonLd, options = {}) {
1543
1685
  delete document.signature;
1544
1686
  let docHash;
1545
1687
  try {
1546
- docHash = await hashJsonLd(document, options.contextLoader);
1688
+ docHash = await hashJsonLd(document, options.contextLoader, "verify");
1547
1689
  } catch (error) {
1548
1690
  logger.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
1549
1691
  document,
@@ -1561,7 +1703,7 @@ async function verifySignature(jsonLd, options = {}) {
1561
1703
  keyId: sig.creator,
1562
1704
  ...sig
1563
1705
  });
1564
- const { key } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(new URL(sig.creator), CryptographicKey, {
1706
+ const { key } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(creator, CryptographicKey, {
1565
1707
  ...options,
1566
1708
  keyCache: bypassKeyCacheReads(options.keyCache)
1567
1709
  }));
@@ -1608,6 +1750,8 @@ function getLdSignatureObject(jsonLd) {
1608
1750
  * Signatures. If the document is signed, this function verifies the signature
1609
1751
  * and checks if the document is attributed to the owner of the public key.
1610
1752
  * If the document is not signed, this function returns `false`.
1753
+ * Unmapped properties discarded during JSON-LD processing are not
1754
+ * authenticated, even when verification succeeds.
1611
1755
  * @param jsonLd The JSON-LD document to verify.
1612
1756
  * @param options Options for verifying the document.
1613
1757
  * @returns `true` if the document is authentic; `false` otherwise.
@@ -1634,11 +1778,12 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
1634
1778
  let threw = false;
1635
1779
  let signatureType;
1636
1780
  try {
1637
- const verificationOptions = hasSignature(jsonLd) ? {
1781
+ const hasLdSignature = hasVerifiableSignature(jsonLd);
1782
+ const verificationOptions = hasLdSignature ? {
1638
1783
  ...options,
1639
1784
  contextLoader: getNormalizationContextLoader(options.contextLoader)
1640
1785
  } : options;
1641
- const compacted = compact ? hasSignature(jsonLd) ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
1786
+ const compacted = compact ? hasLdSignature ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
1642
1787
  const object = await Object$1.fromJsonLd(compacted, verificationOptions);
1643
1788
  observation?.parsedObject?.(object);
1644
1789
  if (observation?.subject != null) observation.subject.id = object.id == null ? null : new URL(object.id.href);
@@ -1697,13 +1842,20 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
1697
1842
  }
1698
1843
  });
1699
1844
  }
1700
- async function hashJsonLd(jsonLd, contextLoader) {
1845
+ const tolerableVerificationWarnings = /* @__PURE__ */ new Set(["blank node predicate", "invalid property"]);
1846
+ function handleVerificationEvent({ event, next }) {
1847
+ if (event.level === "warning" && !tolerableVerificationWarnings.has(event.code)) throw new TypeError(`Unsafe JSON-LD canonicalization warning: ${event.code}`);
1848
+ next();
1849
+ }
1850
+ async function hashJsonLd(jsonLd, contextLoader, mode = "sign") {
1701
1851
  const canon = await jsonld.canonize(jsonLd, {
1702
1852
  format: "application/n-quads",
1703
- documentLoader: contextLoader ?? getDocumentLoader()
1853
+ documentLoader: contextLoader ?? getDocumentLoader(),
1854
+ safe: mode === "sign",
1855
+ eventHandler: mode === "verify" ? handleVerificationEvent : void 0
1704
1856
  });
1705
1857
  const encoder = new TextEncoder();
1706
1858
  return encodeHex(await crypto.subtle.digest("SHA-256", encoder.encode(canon)));
1707
1859
  }
1708
1860
  //#endregion
1709
- export { generateCryptoKeyPair as C, verifyKeyOwnership as E, fetchKeyDetailed as S, validateCryptoKey as T, wrapContextLoaderForJsonLd as _, compactJsonLd as a, fetchActorDocument as b, getNormalizationContextLoader as c, isClearlyMalformedContextReference as d, isInvalidUrlTypeError as f, verifySignature as g, verifyJsonLd as h, attachSignature as i, hasSignature as l, verifyCompactJsonLd as m, UnsafeJsonLdError as n, createSignature as o, signJsonLd as p, assertSafeJsonLd as r, detachSignature as s, InvalidContextReferenceError as t, hasSignatureLike as u, bypassKeyCacheReads as v, importJwk as w, fetchKey as x, exportJwk as y };
1861
+ export { fetchKey as C, validateCryptoKey as D, importJwk as E, verifyKeyOwnership as O, fetchActorDocument as S, generateCryptoKeyPair as T, verifyJsonLd as _, compactJsonLd as a, bypassKeyCacheReads as b, detachSignature as c, hasSignatureLike as d, hasVerifiableSignature as f, verifyCompactJsonLd as g, signJsonLd as h, attachSignature as i, getDefaultPortableObjectVerifier as k, 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, fetchKeyDetailed as w, exportJwk as x, wrapContextLoaderForJsonLd as y };
@@ -0,0 +1,23 @@
1
+ import "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 "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-ksnVeCA7.mjs";
4
+ import { n as version, t as name } from "./deno-BKSRi6w3.mjs";
5
5
  import { metrics } from "@opentelemetry/api";
6
6
  import { FetchError } from "@fedify/vocab-runtime";
7
7
  //#region src/federation/metrics.ts
@@ -1,5 +1,5 @@
1
1
  import "temporal-polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as FederationImpl } from "./middleware-DblGj642.mjs";
4
+ import { n as FederationImpl } from "./middleware-mRXKHq68.mjs";
5
5
  export { FederationImpl };