@fedify/fedify 2.4.0-dev.2127 → 2.4.0-dev.2141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{builder-B2bgGYbP.mjs → builder-BI7H61zO.mjs} +3 -3
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-SVlHSzV7.mjs → compound-proof-D0H4LLvQ.mjs} +15 -20
- package/dist/{context-Ci5vuUr_.d.ts → context-B2C8nuN3.d.ts} +4 -3
- package/dist/{context-Bm6ldGvx.d.cts → context-CrDDVrbF.d.cts} +4 -3
- package/dist/{deno-Be9xoxps.mjs → deno-BXI_BLNy.mjs} +1 -1
- package/dist/{docloader-Dtuyb0ps.mjs → docloader-B5BIo7e9.mjs} +2 -2
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/compound-fanout.test.mjs +3 -3
- package/dist/federation/handler-compound-proof.test.mjs +64 -8
- package/dist/federation/handler.test.mjs +5 -5
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +7 -7
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +2 -2
- package/dist/federation/mod.d.ts +2 -2
- package/dist/federation/mod.js +1 -1
- package/dist/federation/outgoing-proof.test.mjs +6 -6
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +17 -5
- package/dist/federation/portable-gateway-keys.test.mjs +76 -5
- package/dist/federation/portable-inbox.test.mjs +9 -4
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +3 -3
- package/dist/federation/tasks/enqueue.test.mjs +1 -1
- package/dist/federation/tasks/tasks.test.mjs +2 -2
- package/dist/federation/temporal.test.mjs +1 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-B6IHuS6n.cjs → federation-DqDOPjWo.cjs} +23 -28
- package/dist/{http-D76Py0M4.d.cts → http-C-x_OLSp.d.ts} +57 -14
- package/dist/{http-BFeK9sBg.mjs → http-CEx2SZjf.mjs} +18 -12
- package/dist/{http-BrQgkJay.d.ts → http-CjezPjFX.d.cts} +57 -14
- package/dist/{http-Rmbiu-5S.js → http-D4KW2GTi.js} +376 -36
- package/dist/{http-o8l4QeUY.cjs → http-DSYQQn23.cjs} +392 -34
- package/dist/{key-Cc1b6pW9.mjs → key-C0giKuki.mjs} +103 -16
- package/dist/{kv-cache-tLKBfxHc.mjs → kv-cache-AWTrxTq3.mjs} +1 -1
- package/dist/{kv-cache-BUkgZAcX.cjs → kv-cache-BcsvaCCL.cjs} +1 -1
- package/dist/{kv-cache-BweDce2I.js → kv-cache-D_E-2K3i.js} +1 -1
- package/dist/{ld-DQNTIrAe.mjs → ld-CWDReGMZ.mjs} +3 -3
- package/dist/{metrics-DDE9S63Q.mjs → metrics-DxlVXwn5.mjs} +1 -1
- package/dist/{middleware-K9aLnf57.js → middleware-1mv9QR16.js} +23 -28
- package/dist/{middleware-CsQorLC_.mjs → middleware-B7stx5gy.mjs} +1 -1
- package/dist/{middleware-BdhvduR9.mjs → middleware-CAWRGSwH.mjs} +24 -24
- package/dist/{mod-AVir5nVI.d.cts → mod-B7SfEqIP.d.cts} +1 -1
- package/dist/{mod-Co53r-VP.d.ts → mod-Bz9tFXI2.d.ts} +1 -1
- package/dist/{mod-eVOUPbQE.d.ts → mod-C06GoL5Z.d.ts} +1 -1
- package/dist/{mod-Cwdt_CWU.d.ts → mod-CZetqT5h.d.ts} +1 -1
- package/dist/{mod-Cr79cQlc.d.cts → mod-D4g9ffEn.d.cts} +1 -1
- package/dist/{mod-Byt5tvAS.d.cts → mod-S--JxYjo.d.cts} +1 -1
- package/dist/mod.cjs +4 -4
- package/dist/mod.d.cts +5 -5
- package/dist/mod.d.ts +5 -5
- package/dist/mod.js +4 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/{owner-CCfdL83M.mjs → owner-CgoCOTUQ.mjs} +37 -4
- package/dist/{portable-collection-WXaHkNqC.mjs → portable-collection-0_5DyXMt.mjs} +2 -2
- package/dist/{portable-collection-DXogVs__.cjs → portable-collection-BD8fE3j3.cjs} +34 -1
- package/dist/{portable-collection-DdXsKBg4.js → portable-collection-CG9P_i0E.js} +34 -1
- package/dist/portable-key-BXkgMpw1.mjs +395 -0
- package/dist/{portable-key-id-T7lecIbt.mjs → portable-key-id-Bg259c4Z.mjs} +69 -2
- package/dist/{proof-CW8k0R1G.mjs → proof-B5s-W6Sm.mjs} +7 -6
- package/dist/{send--FORaIc4.mjs → send-BAJvkdNL.mjs} +3 -3
- package/dist/sig/compound-proof-discovery.test.mjs +1 -1
- package/dist/sig/compound-proof-producer.test.mjs +1 -1
- package/dist/sig/compound-proof-verification.test.mjs +196 -2
- package/dist/sig/compound-proof.test.mjs +2 -2
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +2 -2
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +2 -2
- package/dist/sig/mod.d.ts +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-key.test.mjs +479 -5
- package/dist/sig/proof.test.mjs +45 -3
- package/dist/{temporal-CffY_XOJ.mjs → temporal-BkCPJ_uC.mjs} +1 -1
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -2
- package/dist/utils/docloader.test.mjs +2 -2
- package/dist/utils/kv-cache.test.mjs +1 -1
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.d.cts +1 -1
- package/dist/utils/mod.d.ts +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +6 -6
- package/dist/portable-key-C-fPq_Yf.mjs +0 -214
package/dist/mod.js
CHANGED
|
@@ -3,11 +3,11 @@ import { URLPattern } from "urlpattern-polyfill";
|
|
|
3
3
|
import "./rolldown-runtime-BC-Eo5Mj.js";
|
|
4
4
|
import { n as autoIdAssigner, r as getDefaultActivityTransformers, t as actorDehydrator } from "./transformers-DAtXl_Kc.js";
|
|
5
5
|
import "./compat/mod.js";
|
|
6
|
-
import { B as
|
|
7
|
-
import { a as respondWithObjectIfAcceptable, c as digest, d as parseCircuitBreakerKvState, f as createFederationBuilder, i as respondWithObject, l as CircuitBreaker, n as handleWebFinger, o as SendActivityError, r as createExponentialBackoffPolicy, s as buildCollectionSynchronizationHeader, t as createFederation, u as normalizeCircuitBreakerOptions } from "./middleware-
|
|
6
|
+
import { B as fetchKeyDetailed, C as attachSignature, E as detachSignature, F as verifySignature, H as importJwk, L as exportJwk, M as signJsonLd, P as verifyJsonLd, T as createSignature, V as generateCryptoKeyPair, a as signRequest, d as createProof, dt as parseAcceptSignature, f as hasProofLike, ft as validateAcceptSignature, g as verifyPortableObjectProof, h as verifyObject, k as hasSignatureLike, lt as formatAcceptSignature, o as verifyRequest, p as signObject, s as verifyRequestDetailed, ut as fulfillAcceptSignature, y as verifyProof, z as fetchKey } from "./http-D4KW2GTi.js";
|
|
7
|
+
import { a as respondWithObjectIfAcceptable, c as digest, d as parseCircuitBreakerKvState, f as createFederationBuilder, i as respondWithObject, l as CircuitBreaker, n as handleWebFinger, o as SendActivityError, r as createExponentialBackoffPolicy, s as buildCollectionSynchronizationHeader, t as createFederation, u as normalizeCircuitBreakerOptions } from "./middleware-1mv9QR16.js";
|
|
8
8
|
import { n as getNodeInfo, r as parseNodeInfo, t as nodeInfoToJson } from "./types-C_cNlNVK.js";
|
|
9
|
-
import { n as doesActorOwnKey, r as getKeyOwner, t as verifyPortableObject } from "./portable-collection-
|
|
10
|
-
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-
|
|
9
|
+
import { n as doesActorOwnKey, r as getKeyOwner, t as verifyPortableObject } from "./portable-collection-CG9P_i0E.js";
|
|
10
|
+
import { n as getAuthenticatedDocumentLoader, t as kvCache } from "./kv-cache-D_E-2K3i.js";
|
|
11
11
|
import { InProcessMessageQueue, MemoryKvStore, ParallelMessageQueue, Router, RouterError } from "./federation/mod.js";
|
|
12
12
|
import "./nodeinfo/mod.js";
|
|
13
13
|
import "./runtime/mod.js";
|
|
@@ -5,7 +5,7 @@ import { r as createRequestContext } from "../context-DfSVPcJ8.mjs";
|
|
|
5
5
|
import { t as MemoryKvStore } from "../kv-DCHkaJ9-.mjs";
|
|
6
6
|
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
7
7
|
import "../std__assert-DvMDRPes.mjs";
|
|
8
|
-
import { C as handleNodeInfo, o as createFederation, w as handleNodeInfoJrd } from "../middleware-
|
|
8
|
+
import { C as handleNodeInfo, o as createFederation, w as handleNodeInfoJrd } from "../middleware-CAWRGSwH.mjs";
|
|
9
9
|
import { test } from "@fedify/fixture";
|
|
10
10
|
//#region src/nodeinfo/handler.test.ts
|
|
11
11
|
test("handleNodeInfo()", async () => {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import "temporal-polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import {
|
|
6
|
-
import { l as verifyKeyOwnership, n as exportJwk, r as fetchActorDocument } from "./key-
|
|
7
|
-
import { t as fetchPortableGatewayKey } from "./portable-key-
|
|
4
|
+
import { n as version, t as name } from "./deno-BXI_BLNy.mjs";
|
|
5
|
+
import { c as isPortableId, d as isSamePublicKey$1, o as isCompatibleKeyId, t as getCanonicalPortableId, u as isPortableUri } from "./portable-key-id-Bg259c4Z.mjs";
|
|
6
|
+
import { l as verifyKeyOwnership, n as exportJwk, r as fetchActorDocument } from "./key-C0giKuki.mjs";
|
|
7
|
+
import { n as resolvePortableActorKey, t as fetchPortableGatewayKey } from "./portable-key-BXkgMpw1.mjs";
|
|
8
8
|
import { getLogger } from "@logtape/logtape";
|
|
9
9
|
import { CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
10
10
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -44,6 +44,14 @@ async function doesActorOwnKey(activity, key, options) {
|
|
|
44
44
|
span.setAttribute("activitypub.key_ownership.method", "none");
|
|
45
45
|
return false;
|
|
46
46
|
}
|
|
47
|
+
if (key.id != null && isPortableUri(key.id)) {
|
|
48
|
+
const owner = await getPortableActorKeyOwner(key, options);
|
|
49
|
+
const ownerId = owner?.id == null ? null : getCanonicalPortableId(owner.id);
|
|
50
|
+
const verified = ownerId != null && ownerId === getCanonicalPortableId(actorId);
|
|
51
|
+
span.setAttribute("activitypub.key_ownership.verified", verified);
|
|
52
|
+
span.setAttribute("activitypub.key_ownership.method", "portable_actor_key");
|
|
53
|
+
return verified;
|
|
54
|
+
}
|
|
47
55
|
if (key.id != null && isCompatibleKeyId(key.id)) {
|
|
48
56
|
const owner = await getPortableGatewayKeyOwner(key, options);
|
|
49
57
|
if (owner !== void 0) {
|
|
@@ -143,6 +151,7 @@ async function getKeyOwner(keyId, options) {
|
|
|
143
151
|
tracerProvider
|
|
144
152
|
};
|
|
145
153
|
const id = keyId instanceof CryptographicKey ? keyId.id : keyId;
|
|
154
|
+
if (id != null && isPortableUri(id)) return await getPortableActorKeyOwner(keyId, fetchOptions);
|
|
146
155
|
if (id != null && isCompatibleKeyId(id)) {
|
|
147
156
|
const owner = await getPortableGatewayKeyOwner(keyId, fetchOptions);
|
|
148
157
|
if (owner !== void 0) return owner;
|
|
@@ -215,5 +224,29 @@ async function getPortableGatewayKeyOwner(key, options) {
|
|
|
215
224
|
}
|
|
216
225
|
return resolution.actor;
|
|
217
226
|
}
|
|
227
|
+
/**
|
|
228
|
+
* Resolves the owner of a key of an [FEP-ef61] portable actor at an `ap:` or
|
|
229
|
+
* `ap+ef61:` key ID.
|
|
230
|
+
*
|
|
231
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
232
|
+
* @param key The key, or its ID, which must be an `ap:` or `ap+ef61:` URI.
|
|
233
|
+
* @param options Options for fetching the key.
|
|
234
|
+
* @returns The portable actor if its signed document vouches for the key,
|
|
235
|
+
* and the given key, if any, has the same key material, or `null`
|
|
236
|
+
* if not.
|
|
237
|
+
*/
|
|
238
|
+
async function getPortableActorKeyOwner(key, options) {
|
|
239
|
+
const keyId = key instanceof CryptographicKey ? key.id : key;
|
|
240
|
+
if (keyId == null) return null;
|
|
241
|
+
const resolution = await resolvePortableActorKey(keyId, options);
|
|
242
|
+
if (resolution.type !== "verified") return null;
|
|
243
|
+
if (key instanceof CryptographicKey) {
|
|
244
|
+
if (key.publicKey == null || !await isSamePublicKey$1(key.publicKey, resolution.key.publicKey)) {
|
|
245
|
+
logger.debug("The key {keyId} does not have the same key material as the key its portable actor vouches for.", { keyId: keyId.href });
|
|
246
|
+
return null;
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
return resolution.actor;
|
|
250
|
+
}
|
|
218
251
|
//#endregion
|
|
219
252
|
export { getKeyOwner as n, doesActorOwnKey as t };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "temporal-polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { l as verifyPortableObjectProofWithRoot, s as verifyPortableObjectProof } from "./proof-
|
|
4
|
+
import { n as version, t as name } from "./deno-BXI_BLNy.mjs";
|
|
5
|
+
import { l as verifyPortableObjectProofWithRoot, s as verifyPortableObjectProof } from "./proof-B5s-W6Sm.mjs";
|
|
6
6
|
import { getLogger } from "@logtape/logtape";
|
|
7
7
|
import { CollectionPage, Object as Object$1, isActor } from "@fedify/vocab";
|
|
8
8
|
import { trace } from "@opentelemetry/api";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
2
|
-
const require_http = require("./http-
|
|
2
|
+
const require_http = require("./http-DSYQQn23.cjs");
|
|
3
3
|
let _logtape_logtape = require("@logtape/logtape");
|
|
4
4
|
let _fedify_vocab = require("@fedify/vocab");
|
|
5
5
|
let _opentelemetry_api = require("@opentelemetry/api");
|
|
@@ -40,6 +40,14 @@ async function doesActorOwnKey(activity, key, options) {
|
|
|
40
40
|
span.setAttribute("activitypub.key_ownership.method", "none");
|
|
41
41
|
return false;
|
|
42
42
|
}
|
|
43
|
+
if (key.id != null && require_http.isPortableUri(key.id)) {
|
|
44
|
+
const owner = await getPortableActorKeyOwner(key, options);
|
|
45
|
+
const ownerId = owner?.id == null ? null : require_http.getCanonicalPortableId(owner.id);
|
|
46
|
+
const verified = ownerId != null && ownerId === require_http.getCanonicalPortableId(actorId);
|
|
47
|
+
span.setAttribute("activitypub.key_ownership.verified", verified);
|
|
48
|
+
span.setAttribute("activitypub.key_ownership.method", "portable_actor_key");
|
|
49
|
+
return verified;
|
|
50
|
+
}
|
|
43
51
|
if (key.id != null && require_http.isCompatibleKeyId(key.id)) {
|
|
44
52
|
const owner = await getPortableGatewayKeyOwner(key, options);
|
|
45
53
|
if (owner !== void 0) {
|
|
@@ -139,6 +147,7 @@ async function getKeyOwner(keyId, options) {
|
|
|
139
147
|
tracerProvider
|
|
140
148
|
};
|
|
141
149
|
const id = keyId instanceof _fedify_vocab.CryptographicKey ? keyId.id : keyId;
|
|
150
|
+
if (id != null && require_http.isPortableUri(id)) return await getPortableActorKeyOwner(keyId, fetchOptions);
|
|
142
151
|
if (id != null && require_http.isCompatibleKeyId(id)) {
|
|
143
152
|
const owner = await getPortableGatewayKeyOwner(keyId, fetchOptions);
|
|
144
153
|
if (owner !== void 0) return owner;
|
|
@@ -211,6 +220,30 @@ async function getPortableGatewayKeyOwner(key, options) {
|
|
|
211
220
|
}
|
|
212
221
|
return resolution.actor;
|
|
213
222
|
}
|
|
223
|
+
/**
|
|
224
|
+
* Resolves the owner of a key of an [FEP-ef61] portable actor at an `ap:` or
|
|
225
|
+
* `ap+ef61:` key ID.
|
|
226
|
+
*
|
|
227
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
228
|
+
* @param key The key, or its ID, which must be an `ap:` or `ap+ef61:` URI.
|
|
229
|
+
* @param options Options for fetching the key.
|
|
230
|
+
* @returns The portable actor if its signed document vouches for the key,
|
|
231
|
+
* and the given key, if any, has the same key material, or `null`
|
|
232
|
+
* if not.
|
|
233
|
+
*/
|
|
234
|
+
async function getPortableActorKeyOwner(key, options) {
|
|
235
|
+
const keyId = key instanceof _fedify_vocab.CryptographicKey ? key.id : key;
|
|
236
|
+
if (keyId == null) return null;
|
|
237
|
+
const resolution = await require_http.resolvePortableActorKey(keyId, options);
|
|
238
|
+
if (resolution.type !== "verified") return null;
|
|
239
|
+
if (key instanceof _fedify_vocab.CryptographicKey) {
|
|
240
|
+
if (key.publicKey == null || !await require_http.isSamePublicKey(key.publicKey, resolution.key.publicKey)) {
|
|
241
|
+
logger$1.debug("The key {keyId} does not have the same key material as the key its portable actor vouches for.", { keyId: keyId.href });
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
return resolution.actor;
|
|
246
|
+
}
|
|
214
247
|
//#endregion
|
|
215
248
|
//#region src/sig/portable-collection.ts
|
|
216
249
|
const logger = (0, _logtape_logtape.getLogger)([
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "temporal-polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import {
|
|
3
|
+
import { Ct as name, L as exportJwk, R as fetchActorDocument, St as isSamePublicKey$1, W as verifyKeyOwnership, c as fetchPortableGatewayKey, g as verifyPortableObjectProof, l as resolvePortableActorKey, pt as getCanonicalPortableId, v as verifyPortableObjectProofWithRoot, vt as isCompatibleKeyId, wt as version, xt as isPortableUri, yt as isPortableId } from "./http-D4KW2GTi.js";
|
|
4
4
|
import { getLogger } from "@logtape/logtape";
|
|
5
5
|
import { CollectionPage, CryptographicKey, Object as Object$1, isActor } from "@fedify/vocab";
|
|
6
6
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
@@ -41,6 +41,14 @@ async function doesActorOwnKey(activity, key, options) {
|
|
|
41
41
|
span.setAttribute("activitypub.key_ownership.method", "none");
|
|
42
42
|
return false;
|
|
43
43
|
}
|
|
44
|
+
if (key.id != null && isPortableUri(key.id)) {
|
|
45
|
+
const owner = await getPortableActorKeyOwner(key, options);
|
|
46
|
+
const ownerId = owner?.id == null ? null : getCanonicalPortableId(owner.id);
|
|
47
|
+
const verified = ownerId != null && ownerId === getCanonicalPortableId(actorId);
|
|
48
|
+
span.setAttribute("activitypub.key_ownership.verified", verified);
|
|
49
|
+
span.setAttribute("activitypub.key_ownership.method", "portable_actor_key");
|
|
50
|
+
return verified;
|
|
51
|
+
}
|
|
44
52
|
if (key.id != null && isCompatibleKeyId(key.id)) {
|
|
45
53
|
const owner = await getPortableGatewayKeyOwner(key, options);
|
|
46
54
|
if (owner !== void 0) {
|
|
@@ -140,6 +148,7 @@ async function getKeyOwner(keyId, options) {
|
|
|
140
148
|
tracerProvider
|
|
141
149
|
};
|
|
142
150
|
const id = keyId instanceof CryptographicKey ? keyId.id : keyId;
|
|
151
|
+
if (id != null && isPortableUri(id)) return await getPortableActorKeyOwner(keyId, fetchOptions);
|
|
143
152
|
if (id != null && isCompatibleKeyId(id)) {
|
|
144
153
|
const owner = await getPortableGatewayKeyOwner(keyId, fetchOptions);
|
|
145
154
|
if (owner !== void 0) return owner;
|
|
@@ -212,6 +221,30 @@ async function getPortableGatewayKeyOwner(key, options) {
|
|
|
212
221
|
}
|
|
213
222
|
return resolution.actor;
|
|
214
223
|
}
|
|
224
|
+
/**
|
|
225
|
+
* Resolves the owner of a key of an [FEP-ef61] portable actor at an `ap:` or
|
|
226
|
+
* `ap+ef61:` key ID.
|
|
227
|
+
*
|
|
228
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
229
|
+
* @param key The key, or its ID, which must be an `ap:` or `ap+ef61:` URI.
|
|
230
|
+
* @param options Options for fetching the key.
|
|
231
|
+
* @returns The portable actor if its signed document vouches for the key,
|
|
232
|
+
* and the given key, if any, has the same key material, or `null`
|
|
233
|
+
* if not.
|
|
234
|
+
*/
|
|
235
|
+
async function getPortableActorKeyOwner(key, options) {
|
|
236
|
+
const keyId = key instanceof CryptographicKey ? key.id : key;
|
|
237
|
+
if (keyId == null) return null;
|
|
238
|
+
const resolution = await resolvePortableActorKey(keyId, options);
|
|
239
|
+
if (resolution.type !== "verified") return null;
|
|
240
|
+
if (key instanceof CryptographicKey) {
|
|
241
|
+
if (key.publicKey == null || !await isSamePublicKey$1(key.publicKey, resolution.key.publicKey)) {
|
|
242
|
+
logger$1.debug("The key {keyId} does not have the same key material as the key its portable actor vouches for.", { keyId: keyId.href });
|
|
243
|
+
return null;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return resolution.actor;
|
|
247
|
+
}
|
|
215
248
|
//#endregion
|
|
216
249
|
//#region src/sig/portable-collection.ts
|
|
217
250
|
const logger = getLogger([
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
import "temporal-polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { d as isSamePublicKey, i as getRawCanonicalPortableId, s as isPortableActorDocument, t as getCanonicalPortableId, u as isPortableUri } from "./portable-key-id-Bg259c4Z.mjs";
|
|
5
|
+
import { l as verifyPortableObjectProofWithRoot } from "./proof-B5s-W6Sm.mjs";
|
|
6
|
+
import { getLogger } from "@logtape/logtape";
|
|
7
|
+
import { CryptographicKey, Multikey, Object as Object$1 } from "@fedify/vocab";
|
|
8
|
+
import { FetchError, formatIri, getDocumentLoader, isGatewayUrl, parseIri, toCompatibleEf61Id } from "@fedify/vocab-runtime";
|
|
9
|
+
import { getPortableGatewayCandidates } from "@fedify/vocab-runtime/internal/portable-dereference";
|
|
10
|
+
//#region src/sig/portable-key.ts
|
|
11
|
+
const logger = getLogger([
|
|
12
|
+
"fedify",
|
|
13
|
+
"sig",
|
|
14
|
+
"key"
|
|
15
|
+
]);
|
|
16
|
+
const SEC = "https://w3id.org/security#";
|
|
17
|
+
/**
|
|
18
|
+
* Verifies that the signed document of a portable actor vouches for
|
|
19
|
+
* the gateway key with the given ID.
|
|
20
|
+
*
|
|
21
|
+
* A gateway key is accepted only if:
|
|
22
|
+
*
|
|
23
|
+
* - the document is an actor whose portable ID, i.e., its `ap:` ID or
|
|
24
|
+
* the canonical portable ID of its compatible identifier, is the one
|
|
25
|
+
* the key ID is the compatible identifier of;
|
|
26
|
+
* - the document has a valid [FEP-8b32] Object Integrity Proof made by
|
|
27
|
+
* the DID of its ID, i.e., it satisfies the [FEP-ef61] proof policy;
|
|
28
|
+
* - the document embeds a `Multikey` with that ID in its `assertionMethod`,
|
|
29
|
+
* whose `controller` is the actor, as [FEP-521a] requires, and a key
|
|
30
|
+
* embedded in its `publicKey` with the same ID agrees with it; or, if
|
|
31
|
+
* no `assertionMethod` entry has that ID, the document embeds
|
|
32
|
+
* a `CryptographicKey` with that ID in its `publicKey`, whose `owner` is
|
|
33
|
+
* the actor, as some publishers, e.g., tootik, list their RSA keys only
|
|
34
|
+
* there;
|
|
35
|
+
* - no more than one entry of either property has that ID; and
|
|
36
|
+
* - the key ID's origin is one of the actor's `gateways`.
|
|
37
|
+
*
|
|
38
|
+
* An entry has the key's ID if its ID is the key ID, or any compatible
|
|
39
|
+
* identifier on the same gateway, or the `ap:` or `ap+ef61:` URI, with the
|
|
40
|
+
* same canonical portable ID. Some publishers, e.g., Mitra, list the keys
|
|
41
|
+
* of portable actors under `ap:` URIs, but sign requests with compatible key
|
|
42
|
+
* IDs on their own gateways. IDs are compared as they are written in
|
|
43
|
+
* the signed document, so an ID that URL parsing would turn into another,
|
|
44
|
+
* e.g., by resolving dot segments, has no match.
|
|
45
|
+
*
|
|
46
|
+
* [FEP-8b32]: https://w3id.org/fep/8b32
|
|
47
|
+
* [FEP-ef61]: https://w3id.org/fep/ef61
|
|
48
|
+
* [FEP-521a]: https://w3id.org/fep/521a
|
|
49
|
+
*
|
|
50
|
+
* @param document The raw JSON-LD document served at the key ID.
|
|
51
|
+
* @param actor The parsed document, which must be a portable actor.
|
|
52
|
+
* @param keyId The key ID, which must be a compatible key ID.
|
|
53
|
+
* @param options Loaders and telemetry providers.
|
|
54
|
+
* @returns The verification result, which is never `legacy`.
|
|
55
|
+
* @internal
|
|
56
|
+
*/
|
|
57
|
+
function verifyPortableGatewayKeyDocument(document, actor, keyId, options = {}) {
|
|
58
|
+
return verifyPortableKeyDocument(document, actor, keyId, true, options);
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Verifies that the signed document of a portable actor vouches for the key
|
|
62
|
+
* with the given ID, either a gateway key at a compatible key ID, or a key of
|
|
63
|
+
* the actor itself at an `ap:` or `ap+ef61:` key ID. See
|
|
64
|
+
* {@link verifyPortableGatewayKeyDocument} for the rules; a key of the actor
|
|
65
|
+
* itself names no gateway, so instead of the key ID's origin being one of
|
|
66
|
+
* the actor's `gateways`, the actor only has to have a valid gateway, as
|
|
67
|
+
* FEP-ef61 requires of every portable actor.
|
|
68
|
+
*/
|
|
69
|
+
async function verifyPortableKeyDocument(document, actor, keyId, isGatewayKey, options) {
|
|
70
|
+
const reject = (reason) => {
|
|
71
|
+
logger.debug("Failed to verify key {keyId} of the portable actor {actorId}: {reason}", {
|
|
72
|
+
keyId: formatIri(keyId),
|
|
73
|
+
actorId: actor.id?.href,
|
|
74
|
+
reason
|
|
75
|
+
});
|
|
76
|
+
return {
|
|
77
|
+
type: "rejected",
|
|
78
|
+
reason
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
const keyBase = new URL(keyId.href);
|
|
82
|
+
keyBase.hash = "";
|
|
83
|
+
const claimedActorId = getCanonicalPortableId(keyBase);
|
|
84
|
+
const claimedKeyId = getCanonicalPortableId(keyId);
|
|
85
|
+
const actorId = actor.id == null ? null : getCanonicalPortableId(actor.id);
|
|
86
|
+
if (claimedActorId == null || claimedKeyId == null || actorId == null) return reject("The key ID or the actor ID is not a valid portable ID.");
|
|
87
|
+
if (claimedActorId !== actorId) return reject("The key ID is not a compatible identifier of the actor it dereferences to.");
|
|
88
|
+
let verification;
|
|
89
|
+
try {
|
|
90
|
+
verification = await verifyPortableObjectProofWithRoot(document, {
|
|
91
|
+
documentLoader: options.documentLoader,
|
|
92
|
+
contextLoader: options.contextLoader,
|
|
93
|
+
keyCache: options.keyCache,
|
|
94
|
+
tracerProvider: options.tracerProvider,
|
|
95
|
+
meterProvider: options.meterProvider
|
|
96
|
+
});
|
|
97
|
+
} catch (error) {
|
|
98
|
+
if (!(error instanceof TypeError)) throw error;
|
|
99
|
+
return reject(`The actor document is malformed: ${error.message}`);
|
|
100
|
+
}
|
|
101
|
+
const { result, root, expires } = verification;
|
|
102
|
+
if (!result.verified) return reject("The actor document does not satisfy the FEP-ef61 proof policy: " + result.reason.type);
|
|
103
|
+
if (root == null) return reject("The actor document could not be expanded.");
|
|
104
|
+
const refuse = (url) => Promise.reject(/* @__PURE__ */ new Error(`Refusing to fetch ${url}.`));
|
|
105
|
+
const parseEmbeddedPublicKey = async (node) => {
|
|
106
|
+
if (isReference(node)) return null;
|
|
107
|
+
let key;
|
|
108
|
+
try {
|
|
109
|
+
key = await CryptographicKey.fromJsonLd(node, {
|
|
110
|
+
documentLoader: refuse,
|
|
111
|
+
contextLoader: options.contextLoader,
|
|
112
|
+
tracerProvider: options.tracerProvider
|
|
113
|
+
});
|
|
114
|
+
} catch (error) {
|
|
115
|
+
if (!(error instanceof TypeError)) throw error;
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
return key.publicKey == null ? null : key;
|
|
119
|
+
};
|
|
120
|
+
let verifiedActor;
|
|
121
|
+
try {
|
|
122
|
+
verifiedActor = await Object$1.fromJsonLd(root, {
|
|
123
|
+
documentLoader: refuse,
|
|
124
|
+
contextLoader: options.contextLoader,
|
|
125
|
+
tracerProvider: options.tracerProvider
|
|
126
|
+
});
|
|
127
|
+
} catch (error) {
|
|
128
|
+
if (!(error instanceof TypeError)) throw error;
|
|
129
|
+
return reject("The verified actor document is malformed.");
|
|
130
|
+
}
|
|
131
|
+
const rootId = root["@id"];
|
|
132
|
+
if (!isPortableActorDocument(verifiedActor) || getCanonicalPortableId(verifiedActor.id) !== claimedActorId || typeof rootId !== "string" || getRawCanonicalPortableId(rootId) !== claimedActorId) return reject("The key ID is not a compatible identifier of the actor whose document is signed.");
|
|
133
|
+
actor = verifiedActor;
|
|
134
|
+
const findKeyNodes = (values) => findNodes(values, claimedKeyId, isGatewayKey ? keyId.origin : null);
|
|
135
|
+
const assertionNodes = findKeyNodes(root[`${SEC}assertionMethod`]);
|
|
136
|
+
const publicKeyNodes = findKeyNodes(root[`${SEC}publicKey`]);
|
|
137
|
+
if (assertionNodes.length > 1 || publicKeyNodes.length > 1) return reject("The actor document has more than one key with the ID.");
|
|
138
|
+
let publicKey;
|
|
139
|
+
if (assertionNodes.length > 0) {
|
|
140
|
+
if (isReference(assertionNodes[0])) return reject("The actor document does not embed the key in its assertionMethod.");
|
|
141
|
+
let multikey;
|
|
142
|
+
try {
|
|
143
|
+
multikey = await Multikey.fromJsonLd(assertionNodes[0], {
|
|
144
|
+
documentLoader: refuse,
|
|
145
|
+
contextLoader: options.contextLoader,
|
|
146
|
+
tracerProvider: options.tracerProvider
|
|
147
|
+
});
|
|
148
|
+
} catch (error) {
|
|
149
|
+
if (!(error instanceof TypeError)) throw error;
|
|
150
|
+
return reject("The key in the assertionMethod is malformed.");
|
|
151
|
+
}
|
|
152
|
+
if (multikey.publicKey == null) return reject("The key in the assertionMethod has no public key.");
|
|
153
|
+
if (multikey.controllerId == null || getCanonicalPortableId(multikey.controllerId) !== actorId) return reject("The controller of the key is not the actor.");
|
|
154
|
+
publicKey = multikey.publicKey;
|
|
155
|
+
if (publicKeyNodes.length > 0 && !isReference(publicKeyNodes[0])) {
|
|
156
|
+
const embedded = await parseEmbeddedPublicKey(publicKeyNodes[0]);
|
|
157
|
+
if (embedded == null || !await isSamePublicKey(embedded.publicKey, publicKey) || embedded.ownerId != null && getCanonicalPortableId(embedded.ownerId) !== actorId) return reject("The key in the publicKey does not agree with the one in the assertionMethod.");
|
|
158
|
+
}
|
|
159
|
+
} else {
|
|
160
|
+
if (publicKeyNodes.length < 1) return reject("The actor document embeds the key in neither its assertionMethod nor its publicKey.");
|
|
161
|
+
const embedded = await parseEmbeddedPublicKey(publicKeyNodes[0]);
|
|
162
|
+
if (embedded == null) return reject("The key in the publicKey is not embedded or malformed.");
|
|
163
|
+
if (embedded.ownerId == null || getCanonicalPortableId(embedded.ownerId) !== actorId) return reject("The owner of the key is not the actor.");
|
|
164
|
+
publicKey = embedded.publicKey;
|
|
165
|
+
}
|
|
166
|
+
if (isGatewayKey) {
|
|
167
|
+
if (!actor.gateways.some((gateway) => isGatewayUrl(gateway) && gateway.origin === keyId.origin)) return reject(`The gateway ${keyId.origin} is not listed in the actor's gateways.`);
|
|
168
|
+
} else if (!actor.gateways.some(isGatewayUrl)) return reject("The actor has no valid gateways.");
|
|
169
|
+
const key = new CryptographicKey({
|
|
170
|
+
id: keyId,
|
|
171
|
+
owner: actor.id,
|
|
172
|
+
publicKey
|
|
173
|
+
});
|
|
174
|
+
return {
|
|
175
|
+
type: "verified",
|
|
176
|
+
actor,
|
|
177
|
+
key,
|
|
178
|
+
...expires == null ? {} : { expires }
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Fetches the document at a compatible key ID, and resolves the key as
|
|
183
|
+
* a gateway key if the document is a portable actor.
|
|
184
|
+
*
|
|
185
|
+
* @param keyId The key ID, which must be a compatible key ID.
|
|
186
|
+
* @param options Loaders and telemetry providers.
|
|
187
|
+
* @returns `legacy` if the document cannot be fetched or is not a portable
|
|
188
|
+
* actor, which leaves the key to the usual resolution; otherwise,
|
|
189
|
+
* the result of {@link verifyPortableGatewayKeyDocument}.
|
|
190
|
+
* @internal
|
|
191
|
+
*/
|
|
192
|
+
async function fetchPortableGatewayKey(keyId, options = {}) {
|
|
193
|
+
const documentLoader = options.documentLoader ?? getDocumentLoader();
|
|
194
|
+
const contextLoader = options.contextLoader ?? getDocumentLoader();
|
|
195
|
+
let remoteDocument;
|
|
196
|
+
try {
|
|
197
|
+
remoteDocument = await documentLoader(keyId.href);
|
|
198
|
+
} catch (error) {
|
|
199
|
+
logger.debug("Failed to fetch key {keyId}: {error}", {
|
|
200
|
+
keyId: keyId.href,
|
|
201
|
+
error
|
|
202
|
+
});
|
|
203
|
+
return { type: "legacy" };
|
|
204
|
+
}
|
|
205
|
+
let object;
|
|
206
|
+
try {
|
|
207
|
+
object = await Object$1.fromJsonLd(remoteDocument.document, {
|
|
208
|
+
documentLoader,
|
|
209
|
+
contextLoader,
|
|
210
|
+
tracerProvider: options.tracerProvider
|
|
211
|
+
});
|
|
212
|
+
} catch (error) {
|
|
213
|
+
if (!(error instanceof TypeError)) throw error;
|
|
214
|
+
return { type: "legacy" };
|
|
215
|
+
}
|
|
216
|
+
if (!isPortableActorDocument(object)) return { type: "legacy" };
|
|
217
|
+
return await verifyPortableGatewayKeyDocument(remoteDocument.document, object, keyId, {
|
|
218
|
+
...options,
|
|
219
|
+
documentLoader,
|
|
220
|
+
contextLoader
|
|
221
|
+
});
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Resolves a key of a portable actor at an `ap:` or `ap+ef61:` key ID, e.g.,
|
|
225
|
+
* `ap://did:key:z6Mk…/actor#main-key`. Such a key ID names no gateway, so
|
|
226
|
+
* the actor's document, i.e., the key ID without its fragment, is fetched
|
|
227
|
+
* through the gateways in its `@gateway` location hints, one after another,
|
|
228
|
+
* until one of them serves a document that vouches for the key. Without
|
|
229
|
+
* location hints, the document loader is asked for the `ap:` URI itself,
|
|
230
|
+
* which only a custom document loader can resolve. The hints are chosen by
|
|
231
|
+
* whoever made the signature, but that does not matter: only a document with
|
|
232
|
+
* a valid proof by the DID of the key ID vouches for the key.
|
|
233
|
+
*
|
|
234
|
+
* The key is taken as a key of the actor itself, not of a gateway, so it is
|
|
235
|
+
* accepted by the rules of {@link verifyPortableGatewayKeyDocument}, except
|
|
236
|
+
* that it is listed under the `ap:` or `ap+ef61:` URI with the same canonical
|
|
237
|
+
* ID as the key ID, and that the actor only has to have a valid gateway.
|
|
238
|
+
* The key ID must have a fragment; a key served as a standalone document is
|
|
239
|
+
* not supported.
|
|
240
|
+
*
|
|
241
|
+
* If no gateway serves a document that vouches for the key, the result is
|
|
242
|
+
* `rejected` only if every gateway served a document that definitely does not
|
|
243
|
+
* vouch for it. If every gateway failed to serve a document at all, the
|
|
244
|
+
* result is a cacheable `unavailable`, with the error of the first gateway if
|
|
245
|
+
* every gateway responded with the same HTTP status, so that the status
|
|
246
|
+
* describes the whole lookup. Otherwise, e.g., if one gateway was
|
|
247
|
+
* unreachable and another served an invalid document, nothing tells what the
|
|
248
|
+
* unreachable gateway would have served, so the result is an `unavailable`
|
|
249
|
+
* that is not cacheable.
|
|
250
|
+
*
|
|
251
|
+
* @param keyId The key ID, which must be an `ap:` or `ap+ef61:` URI.
|
|
252
|
+
* @param options Loaders and telemetry providers.
|
|
253
|
+
* @returns The resolution, which is never `legacy`.
|
|
254
|
+
* @internal
|
|
255
|
+
*/
|
|
256
|
+
async function resolvePortableActorKey(keyId, options = {}) {
|
|
257
|
+
const documentLoader = options.documentLoader ?? getDocumentLoader();
|
|
258
|
+
const contextLoader = options.contextLoader ?? getDocumentLoader();
|
|
259
|
+
let formattedKeyId = keyId.href;
|
|
260
|
+
const reject = (reason) => {
|
|
261
|
+
logger.debug("Failed to verify key {keyId} of a portable actor: {reason}", {
|
|
262
|
+
keyId: formattedKeyId,
|
|
263
|
+
reason
|
|
264
|
+
});
|
|
265
|
+
return {
|
|
266
|
+
type: "rejected",
|
|
267
|
+
reason
|
|
268
|
+
};
|
|
269
|
+
};
|
|
270
|
+
if (!isPortableUri(keyId) || getCanonicalPortableId(keyId) == null) return reject("The key ID is not a valid ap: or ap+ef61: URI.");
|
|
271
|
+
formattedKeyId = formatIri(keyId);
|
|
272
|
+
if (keyId.hash === "" || keyId.hash === "#") return reject("The key ID has no fragment; only keys embedded in actor documents are supported.");
|
|
273
|
+
const actorUrl = new URL(keyId.href);
|
|
274
|
+
actorUrl.hash = "";
|
|
275
|
+
const requestUrls = [];
|
|
276
|
+
for (const gateway of getPortableGatewayCandidates(actorUrl)) try {
|
|
277
|
+
requestUrls.push(toCompatibleEf61Id(actorUrl, gateway).href);
|
|
278
|
+
} catch (error) {
|
|
279
|
+
if (!(error instanceof TypeError)) throw error;
|
|
280
|
+
return reject(`The key ID cannot be fetched from gateways: ${error}`);
|
|
281
|
+
}
|
|
282
|
+
if (requestUrls.length < 1) requestUrls.push(formatIri(actorUrl));
|
|
283
|
+
const attempts = [];
|
|
284
|
+
for (const url of requestUrls) {
|
|
285
|
+
let remoteDocument;
|
|
286
|
+
try {
|
|
287
|
+
remoteDocument = await documentLoader(url);
|
|
288
|
+
} catch (error) {
|
|
289
|
+
logger.debug("Failed to fetch the actor of key {keyId} from {url}: {error}", {
|
|
290
|
+
keyId: formattedKeyId,
|
|
291
|
+
url,
|
|
292
|
+
error
|
|
293
|
+
});
|
|
294
|
+
attempts.push({
|
|
295
|
+
type: "retrievalFailed",
|
|
296
|
+
error
|
|
297
|
+
});
|
|
298
|
+
continue;
|
|
299
|
+
}
|
|
300
|
+
let resolution;
|
|
301
|
+
try {
|
|
302
|
+
const object = await Object$1.fromJsonLd(remoteDocument.document, {
|
|
303
|
+
documentLoader,
|
|
304
|
+
contextLoader,
|
|
305
|
+
tracerProvider: options.tracerProvider
|
|
306
|
+
});
|
|
307
|
+
resolution = isPortableActorDocument(object) ? await verifyPortableKeyDocument(remoteDocument.document, object, keyId, false, {
|
|
308
|
+
...options,
|
|
309
|
+
documentLoader,
|
|
310
|
+
contextLoader
|
|
311
|
+
}) : {
|
|
312
|
+
type: "rejected",
|
|
313
|
+
reason: "The document is not a portable actor."
|
|
314
|
+
};
|
|
315
|
+
} catch (error) {
|
|
316
|
+
if (error instanceof TypeError) resolution = {
|
|
317
|
+
type: "rejected",
|
|
318
|
+
reason: `The document is malformed: ${error.message}`
|
|
319
|
+
};
|
|
320
|
+
else {
|
|
321
|
+
logger.debug("Failed to process the actor of key {keyId} served from {url}: {error}", {
|
|
322
|
+
keyId: formattedKeyId,
|
|
323
|
+
url,
|
|
324
|
+
error
|
|
325
|
+
});
|
|
326
|
+
attempts.push({
|
|
327
|
+
type: "indeterminate",
|
|
328
|
+
error
|
|
329
|
+
});
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
if (resolution.type === "verified") return resolution;
|
|
334
|
+
const reason = resolution.type === "rejected" ? resolution.reason : "The document is not a portable actor.";
|
|
335
|
+
logger.debug("The actor document served from {url} does not vouch for key {keyId}: {reason}", {
|
|
336
|
+
keyId: formattedKeyId,
|
|
337
|
+
url,
|
|
338
|
+
reason
|
|
339
|
+
});
|
|
340
|
+
attempts.push({
|
|
341
|
+
type: "rejected",
|
|
342
|
+
reason
|
|
343
|
+
});
|
|
344
|
+
}
|
|
345
|
+
const rejections = attempts.flatMap((a) => a.type === "rejected" ? [a.reason] : []);
|
|
346
|
+
if (rejections.length === attempts.length) return reject(rejections.join(" "));
|
|
347
|
+
const errors = attempts.flatMap((a) => a.type === "rejected" ? [] : [a.error]);
|
|
348
|
+
const aggregate = errors.length === 1 ? errors[0] : new AggregateError(errors, `Failed to fetch the actor of key ${formattedKeyId} from any of its gateways: ${requestUrls.join(", ")}`);
|
|
349
|
+
if (attempts.every((a) => a.type === "retrievalFailed")) {
|
|
350
|
+
const statuses = errors.map((error) => error instanceof FetchError ? error.response?.status : void 0);
|
|
351
|
+
return {
|
|
352
|
+
type: "unavailable",
|
|
353
|
+
error: statuses[0] != null && statuses.every((status) => status === statuses[0]) ? errors[0] : aggregate,
|
|
354
|
+
cacheable: true
|
|
355
|
+
};
|
|
356
|
+
}
|
|
357
|
+
return {
|
|
358
|
+
type: "unavailable",
|
|
359
|
+
error: new Error(`Could not determine whether the actor of key ${formattedKeyId} vouches for it.`, { cause: aggregate }),
|
|
360
|
+
cacheable: false
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
/**
|
|
364
|
+
* Finds the nodes that stand for the key with the given canonical portable
|
|
365
|
+
* ID. A node whose ID is an `ap:` or `ap+ef61:` URI stands for the key
|
|
366
|
+
* itself, e.g., Mitra lists the keys of portable actors that way while
|
|
367
|
+
* signing requests with compatible key IDs. A node whose ID is a compatible
|
|
368
|
+
* identifier stands for a gateway's key, so it matches only a compatible key
|
|
369
|
+
* ID on the same gateway; a key ID that names no gateway never selects
|
|
370
|
+
* a gateway's key, even with the same fragment.
|
|
371
|
+
* @param values The expanded values of a key property.
|
|
372
|
+
* @param canonicalKeyId The canonical portable ID of the key ID.
|
|
373
|
+
* @param gateway The origin of the gateway whose key the key ID names, or
|
|
374
|
+
* `null` if the key ID names no gateway.
|
|
375
|
+
*/
|
|
376
|
+
function findNodes(values, canonicalKeyId, gateway) {
|
|
377
|
+
if (!Array.isArray(values)) return [];
|
|
378
|
+
const nodes = [];
|
|
379
|
+
for (const value of values) {
|
|
380
|
+
if (value == null || typeof value !== "object" || Array.isArray(value)) continue;
|
|
381
|
+
const node = value;
|
|
382
|
+
const nodeId = node["@id"];
|
|
383
|
+
if (typeof nodeId !== "string") continue;
|
|
384
|
+
if (getRawCanonicalPortableId(nodeId) !== canonicalKeyId) continue;
|
|
385
|
+
const parsed = parseIri(nodeId);
|
|
386
|
+
if (isPortableUri(parsed) || parsed.origin === gateway) nodes.push(node);
|
|
387
|
+
}
|
|
388
|
+
return nodes;
|
|
389
|
+
}
|
|
390
|
+
/** A node with nothing but an `@id` is a reference, not an embedded key. */
|
|
391
|
+
function isReference(node) {
|
|
392
|
+
return Object.keys(node).every((key) => key === "@id");
|
|
393
|
+
}
|
|
394
|
+
//#endregion
|
|
395
|
+
export { resolvePortableActorKey as n, verifyPortableGatewayKeyDocument as r, fetchPortableGatewayKey as t };
|