@fedify/fedify 2.2.0-dev.898 → 2.2.0-dev.924

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 (64) hide show
  1. package/dist/{builder-BxNYaOv9.mjs → builder-FoLsluZw.mjs} +3 -3
  2. package/dist/compat/public-audience.test.d.mts +2 -0
  3. package/dist/compat/public-audience.test.mjs +178 -0
  4. package/dist/compat/transformers.test.mjs +2 -2
  5. package/dist/{deno-DJv-tEfT.mjs → deno-BukNyK1t.mjs} +1 -1
  6. package/dist/{docloader-iGAzD_2N.mjs → docloader-BgBM76TI.mjs} +2 -2
  7. package/dist/federation/builder.test.mjs +2 -2
  8. package/dist/federation/collection.test.mjs +1 -1
  9. package/dist/federation/handler.test.mjs +4 -4
  10. package/dist/federation/idempotency.test.mjs +3 -3
  11. package/dist/federation/inbox.test.mjs +1 -1
  12. package/dist/federation/keycache.test.mjs +2 -2
  13. package/dist/federation/kv.test.mjs +1 -1
  14. package/dist/federation/middleware.test.mjs +17 -7
  15. package/dist/federation/mod.cjs +1 -1
  16. package/dist/federation/mod.js +1 -1
  17. package/dist/federation/mq.test.mjs +15 -8
  18. package/dist/federation/negotiation.test.mjs +1 -1
  19. package/dist/federation/retry.test.mjs +1 -1
  20. package/dist/federation/send.test.mjs +3 -3
  21. package/dist/federation/webfinger.test.mjs +2 -2
  22. package/dist/{http-COBccATS.cjs → http-1uLerNXX.cjs} +1 -1
  23. package/dist/{http-ETgJ0kEf.mjs → http-DSghOjS0.mjs} +2 -2
  24. package/dist/{http-IT-3f4WJ.js → http-DiNUVHGB.js} +1 -1
  25. package/dist/{key-BdVfyalZ.mjs → key-DAfSmMg7.mjs} +1 -1
  26. package/dist/{kv-cache-NdVl1dI9.js → kv-cache-Dq9VS_Jn.js} +1 -1
  27. package/dist/{kv-cache-DoM8wkoM.cjs → kv-cache-ia7oECIG.cjs} +1 -1
  28. package/dist/{ld-BIwbyijT.mjs → ld-DYpo7uUC.mjs} +2 -2
  29. package/dist/{middleware-D2WkRjr9.mjs → middleware-CjJ_aBdD.mjs} +1 -1
  30. package/dist/{middleware-AcyKcnPJ.cjs → middleware-Dt0fC6dK.cjs} +5 -4
  31. package/dist/{middleware-MrcBc-JA.mjs → middleware-aawr753E.mjs} +17 -15
  32. package/dist/{middleware-PwlQ2vwv.js → middleware-olp7n2S4.js} +4 -3
  33. package/dist/{middleware-BdLMFU46.cjs → middleware-rZ0jYYM9.cjs} +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-ELkycVNn.mjs → owner-B0_w8O-Y.mjs} +2 -2
  41. package/dist/{proof-CdHJBGaI.mjs → proof-DDZ2W7TX.mjs} +36 -31
  42. package/dist/{proof-CngGDTG-.js → proof-DdnQ5edt.js} +218 -41
  43. package/dist/{proof-D3NCoYW3.cjs → proof-DgRfG4AE.cjs} +221 -38
  44. package/dist/public-audience-eovWqzOF.mjs +181 -0
  45. package/dist/{send-Bsg41P7e.mjs → send-DMLb0UwP.mjs} +2 -2
  46. package/dist/sig/http.test.mjs +2 -2
  47. package/dist/sig/key.test.mjs +1 -1
  48. package/dist/sig/ld.test.mjs +2 -2
  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 +60 -2
  53. package/dist/utils/docloader.test.mjs +2 -2
  54. package/dist/utils/mod.cjs +1 -1
  55. package/dist/utils/mod.js +1 -1
  56. package/package.json +5 -5
  57. /package/dist/{activity-listener-Ck3JZ_hR.mjs → activity-listener-CFzUqoCS.mjs} +0 -0
  58. /package/dist/{client-DEpOVgY1.mjs → client-DVu6Fmom.mjs} +0 -0
  59. /package/dist/{collection-BD6-SZ6O.mjs → collection-BQRKGS7L.mjs} +0 -0
  60. /package/dist/{keycache-CCSwkQcY.mjs → keycache-C2t1kvP5.mjs} +0 -0
  61. /package/dist/{kv-tL2TOE9X.mjs → kv-C-TG81Sv.mjs} +0 -0
  62. /package/dist/{negotiation-DnsfFF8I.mjs → negotiation-xb0QR3u_.mjs} +0 -0
  63. /package/dist/{retry-B_E3V_Dx.mjs → retry-CJL0poaU.mjs} +0 -0
  64. /package/dist/{types-DCP0WLdt.mjs → types-CGUnLkU3.mjs} +0 -0
@@ -2,23 +2,24 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { n as RouterError } from "./router-CrMLXoOr.mjs";
5
- import { n as version, t as name } from "./deno-DJv-tEfT.mjs";
5
+ import { n as version, t as name } from "./deno-BukNyK1t.mjs";
6
6
  import { t as formatAcceptSignature } from "./accept-Dd__NiUL.mjs";
7
- import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-BdVfyalZ.mjs";
8
- import { l as verifyRequest, o as parseRfc9421SignatureInput, u as verifyRequestDetailed } from "./http-ETgJ0kEf.mjs";
9
- import { t as getAuthenticatedDocumentLoader } from "./docloader-iGAzD_2N.mjs";
7
+ import { a as importJwk, o as validateCryptoKey, t as exportJwk } from "./key-DAfSmMg7.mjs";
8
+ import { l as verifyRequest, o as parseRfc9421SignatureInput, u as verifyRequestDetailed } from "./http-DSghOjS0.mjs";
9
+ import { t as getAuthenticatedDocumentLoader } from "./docloader-BgBM76TI.mjs";
10
10
  import { n as kvCache } from "./kv-cache-B01V7s3h.mjs";
11
- import { a as signJsonLd, i as hasSignatureLike, o as verifyJsonLd, r as detachSignature } from "./ld-BIwbyijT.mjs";
12
- import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-ELkycVNn.mjs";
13
- import { i as verifyObject, n as hasProofLike, r as signObject } from "./proof-CdHJBGaI.mjs";
14
- import { t as getNodeInfo } from "./client-DEpOVgY1.mjs";
15
- import { t as nodeInfoToJson } from "./types-DCP0WLdt.mjs";
16
- import { t as FederationBuilderImpl } from "./builder-BxNYaOv9.mjs";
17
- import { t as buildCollectionSynchronizationHeader } from "./collection-BD6-SZ6O.mjs";
18
- import { t as KvKeyCache } from "./keycache-CCSwkQcY.mjs";
19
- import { t as acceptsJsonLd } from "./negotiation-DnsfFF8I.mjs";
20
- import { t as createExponentialBackoffPolicy } from "./retry-B_E3V_Dx.mjs";
21
- import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "./send-Bsg41P7e.mjs";
11
+ import { a as signJsonLd, i as hasSignatureLike, o as verifyJsonLd, r as detachSignature } from "./ld-DYpo7uUC.mjs";
12
+ import { n as getKeyOwner, t as doesActorOwnKey } from "./owner-B0_w8O-Y.mjs";
13
+ import { t as normalizePublicAudience } from "./public-audience-eovWqzOF.mjs";
14
+ import { i as verifyObject, n as hasProofLike, r as signObject } from "./proof-DDZ2W7TX.mjs";
15
+ import { t as getNodeInfo } from "./client-DVu6Fmom.mjs";
16
+ import { t as nodeInfoToJson } from "./types-CGUnLkU3.mjs";
17
+ import { t as FederationBuilderImpl } from "./builder-FoLsluZw.mjs";
18
+ import { t as buildCollectionSynchronizationHeader } from "./collection-BQRKGS7L.mjs";
19
+ import { t as KvKeyCache } from "./keycache-C2t1kvP5.mjs";
20
+ import { t as acceptsJsonLd } from "./negotiation-xb0QR3u_.mjs";
21
+ import { t as createExponentialBackoffPolicy } from "./retry-CJL0poaU.mjs";
22
+ import { n as extractInboxes, r as sendActivity, t as SendActivityError } from "./send-DMLb0UwP.mjs";
22
23
  import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, Tombstone, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
23
24
  import { lookupWebFinger } from "@fedify/webfinger";
24
25
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
@@ -2261,6 +2262,7 @@ var FederationImpl = class extends FederationBuilderImpl {
2261
2262
  format: "compact",
2262
2263
  contextLoader
2263
2264
  });
2265
+ jsonLd = await normalizePublicAudience(jsonLd, contextLoader);
2264
2266
  if (rsaKey == null) logger.warn("No supported key found to create a Linked Data signature for the activity {activityId}. The activity will be sent without a Linked Data signature. In order to create a Linked Data signature, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
2265
2267
  activityId,
2266
2268
  keys: keys.map((pair) => ({
@@ -2,10 +2,10 @@ import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  import { t as __exportAll } from "./chunk-nlSIicah.js";
4
4
  import { r as getDefaultActivityTransformers } from "./transformers-ve6e2xcg.js";
5
- import { _ as version, a as verifyRequestDetailed, d as validateCryptoKey, f as formatAcceptSignature, g as name, i as verifyRequest, n as parseRfc9421SignatureInput, o as exportJwk, t as doubleKnock, u as importJwk } from "./http-IT-3f4WJ.js";
6
- import { d as hasSignatureLike, f as signJsonLd, i as verifyObject, n as hasProofLike, o as doesActorOwnKey, p as verifyJsonLd, r as signObject, s as getKeyOwner, u as detachSignature } from "./proof-CngGDTG-.js";
5
+ import { _ as version, a as verifyRequestDetailed, d as validateCryptoKey, f as formatAcceptSignature, g as name, i as verifyRequest, n as parseRfc9421SignatureInput, o as exportJwk, t as doubleKnock, u as importJwk } from "./http-DiNUVHGB.js";
6
+ import { c as getKeyOwner, d as detachSignature, f as hasSignatureLike, i as verifyObject, m as verifyJsonLd, n as hasProofLike, o as normalizePublicAudience, p as signJsonLd, r as signObject, s as doesActorOwnKey } from "./proof-DdnQ5edt.js";
7
7
  import { n as getNodeInfo, t as nodeInfoToJson } from "./types-hvL8ElAs.js";
8
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-NdVl1dI9.js";
8
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-Dq9VS_Jn.js";
9
9
  import { getLogger, withContext } from "@logtape/logtape";
10
10
  import { Activity, Collection, CollectionPage, CryptographicKey, Link, Multikey, Object as Object$1, OrderedCollection, OrderedCollectionPage, Tombstone, getTypeId, lookupObject, traverseCollection } from "@fedify/vocab";
11
11
  import { SpanKind, SpanStatusCode, context, propagation, trace } from "@opentelemetry/api";
@@ -3291,6 +3291,7 @@ var FederationImpl = class extends FederationBuilderImpl {
3291
3291
  format: "compact",
3292
3292
  contextLoader
3293
3293
  });
3294
+ jsonLd = await normalizePublicAudience(jsonLd, contextLoader);
3294
3295
  if (rsaKey == null) logger.warn("No supported key found to create a Linked Data signature for the activity {activityId}. The activity will be sent without a Linked Data signature. In order to create a Linked Data signature, at least one RSASSA-PKCS1-v1_5 key must be provided.", {
3295
3296
  activityId,
3296
3297
  keys: keys.map((pair) => ({
@@ -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-AcyKcnPJ.cjs");
3
+ const require_middleware = require("./middleware-Dt0fC6dK.cjs");
4
4
  exports.FederationImpl = require_middleware.FederationImpl;
package/dist/mod.cjs CHANGED
@@ -4,11 +4,11 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
4
  require("./chunk-DDcVe30Y.cjs");
5
5
  const require_transformers = require("./transformers-NeAONrAq.cjs");
6
6
  require("./compat/mod.cjs");
7
- const require_http = require("./http-COBccATS.cjs");
8
- const require_middleware = require("./middleware-AcyKcnPJ.cjs");
9
- const require_proof = require("./proof-D3NCoYW3.cjs");
7
+ const require_http = require("./http-1uLerNXX.cjs");
8
+ const require_middleware = require("./middleware-Dt0fC6dK.cjs");
9
+ const require_proof = require("./proof-DgRfG4AE.cjs");
10
10
  const require_types = require("./types-KC4QAoxe.cjs");
11
- const require_kv_cache = require("./kv-cache-DoM8wkoM.cjs");
11
+ const require_kv_cache = require("./kv-cache-ia7oECIG.cjs");
12
12
  const require_federation_mod = require("./federation/mod.cjs");
13
13
  require("./nodeinfo/mod.cjs");
14
14
  require("./runtime/mod.cjs");
package/dist/mod.js CHANGED
@@ -3,11 +3,11 @@ import "urlpattern-polyfill";
3
3
  import "./chunk-nlSIicah.js";
4
4
  import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-ve6e2xcg.js";
5
5
  import "./compat/mod.js";
6
- import { a as verifyRequestDetailed, c as fetchKeyDetailed, f as formatAcceptSignature, h as validateAcceptSignature, i as verifyRequest, l as generateCryptoKeyPair, m as parseAcceptSignature, o as exportJwk, p as fulfillAcceptSignature, r as signRequest, s as fetchKey, u as importJwk } from "./http-IT-3f4WJ.js";
7
- import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-PwlQ2vwv.js";
8
- import { a as verifyProof, c as attachSignature, d as hasSignatureLike, f as signJsonLd, i as verifyObject, l as createSignature, m as verifySignature, n as hasProofLike, o as doesActorOwnKey, p as verifyJsonLd, r as signObject, s as getKeyOwner, t as createProof, u as detachSignature } from "./proof-CngGDTG-.js";
6
+ import { a as verifyRequestDetailed, c as fetchKeyDetailed, f as formatAcceptSignature, h as validateAcceptSignature, i as verifyRequest, l as generateCryptoKeyPair, m as parseAcceptSignature, o as exportJwk, p as fulfillAcceptSignature, r as signRequest, s as fetchKey, u as importJwk } from "./http-DiNUVHGB.js";
7
+ import { a as createExponentialBackoffPolicy, c as buildCollectionSynchronizationHeader, d as Router, f as RouterError, i as SendActivityError, l as digest, o as respondWithObject, r as handleWebFinger, s as respondWithObjectIfAcceptable, t as createFederation, u as createFederationBuilder } from "./middleware-olp7n2S4.js";
8
+ import { a as verifyProof, c as getKeyOwner, d as detachSignature, f as hasSignatureLike, h as verifySignature, i as verifyObject, l as attachSignature, m as verifyJsonLd, n as hasProofLike, p as signJsonLd, r as signObject, s as doesActorOwnKey, t as createProof, u as createSignature } from "./proof-DdnQ5edt.js";
9
9
  import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-hvL8ElAs.js";
10
- import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-NdVl1dI9.js";
10
+ import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-Dq9VS_Jn.js";
11
11
  import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue } from "./federation/mod.js";
12
12
  import "./nodeinfo/mod.js";
13
13
  import "./runtime/mod.js";
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as esm_default } from "../esm-DVILvP5e.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import "../std__assert-Duiq_YC9.mjs";
7
- import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-DEpOVgY1.mjs";
7
+ import { a as parseProtocol, c as parseUsage, i as parseOutboundService, n as parseInboundService, o as parseServices, r as parseNodeInfo, s as parseSoftware, t as getNodeInfo } from "../client-DVu6Fmom.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/nodeinfo/client.test.ts
10
10
  test("getNodeInfo()", async (t) => {
@@ -4,8 +4,8 @@ globalThis.addEventListener = () => {};
4
4
  import { r as createRequestContext } from "../context-Dk_tacqz.mjs";
5
5
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
6
6
  import "../std__assert-Duiq_YC9.mjs";
7
- import { t as MemoryKvStore } from "../kv-tL2TOE9X.mjs";
8
- import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-MrcBc-JA.mjs";
7
+ import { t as MemoryKvStore } from "../kv-C-TG81Sv.mjs";
8
+ import { _ as handleNodeInfoJrd, g as handleNodeInfo, o as createFederation } from "../middleware-aawr753E.mjs";
9
9
  import { test } from "@fedify/fixture";
10
10
  //#region src/nodeinfo/handler.test.ts
11
11
  test("handleNodeInfo()", async () => {
@@ -4,7 +4,7 @@ globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import "../std__assert-Duiq_YC9.mjs";
6
6
  import { t as assertThrows } from "../assert_throws-4NwKEy2q.mjs";
7
- import { t as nodeInfoToJson } from "../types-DCP0WLdt.mjs";
7
+ import { t as nodeInfoToJson } from "../types-CGUnLkU3.mjs";
8
8
  import { test } from "@fedify/fixture";
9
9
  //#region src/nodeinfo/types.test.ts
10
10
  test("nodeInfoToJson()", () => {
@@ -3,7 +3,7 @@ import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
4
  import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import "../std__assert-Duiq_YC9.mjs";
6
- import { t as MemoryKvStore } from "../kv-tL2TOE9X.mjs";
6
+ import { t as MemoryKvStore } from "../kv-C-TG81Sv.mjs";
7
7
  import { test } from "@fedify/fixture";
8
8
  import { SpanKind, SpanStatusCode, TraceFlags } from "@opentelemetry/api";
9
9
  import { getLogger } from "@logtape/logtape";
@@ -1,8 +1,8 @@
1
1
  import "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-DJv-tEfT.mjs";
5
- import "./key-BdVfyalZ.mjs";
4
+ import { n as version, t as name } from "./deno-BukNyK1t.mjs";
5
+ import "./key-DAfSmMg7.mjs";
6
6
  import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
7
7
  import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
8
8
  import { getDocumentLoader } from "@fedify/vocab-runtime";
@@ -1,8 +1,9 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { n as version, t as name } from "./deno-DJv-tEfT.mjs";
5
- import { n as fetchKey, o as validateCryptoKey } from "./key-BdVfyalZ.mjs";
4
+ import { n as version, t as name } from "./deno-BukNyK1t.mjs";
5
+ import { n as fetchKey, o as validateCryptoKey } from "./key-DAfSmMg7.mjs";
6
+ import { t as normalizePublicAudience } from "./public-audience-eovWqzOF.mjs";
6
7
  import { Activity, DataIntegrityProof, Multikey, getTypeId } from "@fedify/vocab";
7
8
  import { SpanStatusCode, trace } from "@opentelemetry/api";
8
9
  import { getLogger } from "@logtape/logtape";
@@ -56,11 +57,12 @@ function hasProofLike(jsonLd) {
56
57
  async function createProof(object, privateKey, keyId, { contextLoader, context, created } = {}) {
57
58
  validateCryptoKey(privateKey, "private");
58
59
  if (privateKey.algorithm.name !== "Ed25519") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
59
- const compactMsg = await object.clone({ proofs: [] }).toJsonLd({
60
+ let compactMsg = await object.clone({ proofs: [] }).toJsonLd({
60
61
  format: "compact",
61
62
  contextLoader,
62
63
  context
63
64
  });
65
+ compactMsg = await normalizePublicAudience(compactMsg, contextLoader);
64
66
  const msgCanon = serialize(compactMsg);
65
67
  const encoder = new TextEncoder();
66
68
  const msgBytes = encoder.encode(msgCanon);
@@ -155,27 +157,25 @@ async function verifyProof(jsonLd, proof, options = {}) {
155
157
  });
156
158
  }
157
159
  async function verifyProofInternal(jsonLd, proof, options) {
158
- if (typeof jsonLd !== "object" || proof.cryptosuite !== "eddsa-jcs-2022" || proof.verificationMethodId == null || proof.proofPurpose !== "assertionMethod" || proof.proofValue == null || proof.created == null) return null;
160
+ if (typeof jsonLd !== "object" || jsonLd == null || Array.isArray(jsonLd) || proof.cryptosuite !== "eddsa-jcs-2022" || proof.verificationMethodId == null || proof.proofPurpose !== "assertionMethod" || proof.proofValue == null || proof.created == null) return null;
159
161
  const publicKeyPromise = fetchKey(proof.verificationMethodId, Multikey, options);
160
- const proofCanon = serialize({
162
+ const proofConfig = {
161
163
  "@context": jsonLd["@context"],
162
164
  type: "DataIntegrityProof",
163
165
  cryptosuite: proof.cryptosuite,
164
166
  verificationMethod: proof.verificationMethodId.href,
165
167
  proofPurpose: proof.proofPurpose,
166
168
  created: proof.created.toString()
167
- });
169
+ };
168
170
  const encoder = new TextEncoder();
169
- const proofBytes = encoder.encode(proofCanon);
171
+ const proofBytes = encoder.encode(serialize(proofConfig));
170
172
  const proofDigest = await crypto.subtle.digest("SHA-256", proofBytes);
171
173
  const msg = { ...jsonLd };
172
174
  if ("proof" in msg) delete msg.proof;
173
- const msgCanon = serialize(msg);
174
- const msgBytes = encoder.encode(msgCanon);
175
- const msgDigest = await crypto.subtle.digest("SHA-256", msgBytes);
176
- const digest = new Uint8Array(proofDigest.byteLength + msgDigest.byteLength);
177
- digest.set(new Uint8Array(proofDigest), 0);
178
- digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
175
+ if ("https://w3id.org/security#proof" in msg) delete msg["https://w3id.org/security#proof"];
176
+ const candidates = [msg];
177
+ const normalized = await normalizePublicAudience(msg, options.contextLoader);
178
+ if (normalized !== msg) candidates.push(normalized);
179
179
  let fetchedKey;
180
180
  try {
181
181
  fetchedKey = await publicKeyPromise;
@@ -204,7 +204,7 @@ async function verifyProofInternal(jsonLd, proof, options) {
204
204
  return await verifyProof(jsonLd, proof, {
205
205
  ...options,
206
206
  keyCache: {
207
- get: () => Promise.resolve(null),
207
+ get: () => Promise.resolve(void 0),
208
208
  set: async (keyId, key) => await options.keyCache?.set(keyId, key)
209
209
  }
210
210
  });
@@ -215,27 +215,32 @@ async function verifyProofInternal(jsonLd, proof, options) {
215
215
  });
216
216
  return null;
217
217
  }
218
- if (!await crypto.subtle.verify("Ed25519", publicKey.publicKey, proof.proofValue.slice(), digest)) {
219
- if (fetchedKey.cached) {
220
- logger.debug("Failed to verify the proof with the cached key {keyId}; retrying with the freshly fetched key...", {
221
- keyId: proof.verificationMethodId.href,
222
- proof
223
- });
224
- return await verifyProof(jsonLd, proof, {
225
- ...options,
226
- keyCache: {
227
- get: () => Promise.resolve(void 0),
228
- set: async (keyId, key) => await options.keyCache?.set(keyId, key)
229
- }
230
- });
231
- }
232
- logger.debug("Failed to verify the proof with the fetched key {keyId}:\n{proof}", {
218
+ const digest = new Uint8Array(proofDigest.byteLength + 32);
219
+ digest.set(new Uint8Array(proofDigest), 0);
220
+ for (const candidate of candidates) {
221
+ const msgBytes = encoder.encode(serialize(candidate));
222
+ const msgDigest = await crypto.subtle.digest("SHA-256", msgBytes);
223
+ digest.set(new Uint8Array(msgDigest), proofDigest.byteLength);
224
+ if (await crypto.subtle.verify("Ed25519", publicKey.publicKey, proof.proofValue.slice(), digest)) return publicKey;
225
+ }
226
+ if (fetchedKey.cached) {
227
+ logger.debug("Failed to verify the proof with the cached key {keyId}; retrying with the freshly fetched key...", {
233
228
  keyId: proof.verificationMethodId.href,
234
229
  proof
235
230
  });
236
- return null;
231
+ return await verifyProof(jsonLd, proof, {
232
+ ...options,
233
+ keyCache: {
234
+ get: () => Promise.resolve(void 0),
235
+ set: async (keyId, key) => await options.keyCache?.set(keyId, key)
236
+ }
237
+ });
237
238
  }
238
- return publicKey;
239
+ logger.debug("Failed to verify the proof with the fetched key {keyId}:\n{proof}", {
240
+ keyId: proof.verificationMethodId.href,
241
+ proof
242
+ });
243
+ return null;
239
244
  }
240
245
  /**
241
246
  * Verifies the given object. It will verify all the proofs in the object,