@fedify/fedify 2.4.6-dev.2837 → 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.
- package/dist/attachment-arrays-5yDbmjEb.mjs +16 -0
- package/dist/{builder-DYeeuJIZ.mjs → builder-CadJYxhX.mjs} +2 -2
- package/dist/callback-DPDs_dxC.d.mts +5280 -0
- package/dist/{client-3InDZbba.d.cts → client-DLHsPY7X.d.cts} +16 -0
- package/dist/{client-3InDZbba.d.ts → client-DLHsPY7X.d.ts} +16 -0
- package/dist/{client-5SIFzW3q.mjs → client-DU3owZBD.mjs} +86 -11
- package/dist/compat/attachment-arrays.test.d.mts +2 -0
- package/dist/compat/attachment-arrays.test.mjs +255 -0
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/outgoing-jsonld.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{compound-proof-CxRUa-wY.mjs → compound-proof-CbWKyg2H.mjs} +2 -2
- package/dist/{context-D0gFIgev.d.cts → context-DUwicVx-.d.cts} +31 -14
- package/dist/{context-CVOOd9pD.d.ts → context-iGMHITvS.d.ts} +31 -14
- package/dist/{deno-CRpGtqm6.mjs → deno-BKSRi6w3.mjs} +1 -1
- package/dist/{docloader-CZtA3Qjh.mjs → docloader-BcDiJfFl.mjs} +2 -2
- package/dist/federation/attachment-responses.test.d.mts +2 -0
- package/dist/federation/attachment-responses.test.mjs +182 -0
- package/dist/federation/builder.test.mjs +1 -1
- package/dist/federation/compound-fanout.test.mjs +4 -4
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler-compound-proof.test.mjs +3 -3
- package/dist/federation/handler.test.mjs +206 -14
- package/dist/federation/hashlink-media.test.mjs +2 -2
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox-report.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +1 -1
- package/dist/federation/metrics.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1188 -13
- package/dist/federation/mod.cjs +1 -1
- package/dist/federation/mod.d.cts +3 -3
- package/dist/federation/mod.d.ts +3 -3
- package/dist/federation/mod.js +1 -1
- package/dist/federation/outgoing-proof.test.mjs +4 -4
- package/dist/federation/portable-actor.test.mjs +3 -3
- package/dist/federation/portable-chain.test.mjs +3 -3
- package/dist/federation/portable-collection.test.mjs +4 -4
- package/dist/federation/portable-delivery.test.mjs +2 -2
- package/dist/federation/portable-gateway-keys.test.mjs +5 -5
- package/dist/federation/portable-inbox.test.mjs +4 -4
- package/dist/federation/portable-parse-uri.test.mjs +1 -1
- package/dist/federation/portable-route-activity.test.mjs +2 -2
- package/dist/federation/portable.test.mjs +3 -3
- package/dist/federation/send.test.mjs +293 -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 +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{federation-DkIcc4TV.cjs → federation-CM4nzbhO.cjs} +500 -144
- package/dist/{http-G2ORncQt.mjs → http-B6sfb5xN.mjs} +8 -6
- package/dist/{http-DnJvGLuL.js → http-BwgldAIk.js} +2798 -2629
- package/dist/{http-DWIArxRV.cjs → http-Tj9eQ_rd.cjs} +2634 -2453
- package/dist/{inbox-WfHbmNbc.mjs → inbox-B7NVkb8j.mjs} +2 -2
- package/dist/{key-VEL1QqHF.d.cts → key-CIdQA7Pc.d.cts} +5 -5
- package/dist/{key-CyCcut3h.d.ts → key-CjtBFzaE.d.ts} +5 -5
- package/dist/{kv-cache-CSJwIUzA.js → kv-cache-C-5yfTw-.js} +1 -1
- package/dist/{kv-cache-C9jAD4VW.mjs → kv-cache-CvWuigft.mjs} +1 -1
- package/dist/{kv-cache-C7b-sBZL.cjs → kv-cache-Vbq0yM7W.cjs} +1 -1
- package/dist/{ld-CKWvh95H.mjs → ld-BGnZDnia.mjs} +155 -22
- package/dist/ld-signature-D1tFSFK8.mjs +23 -0
- package/dist/{metrics-Og1y_3kX.mjs → metrics-DHUP4F1-.mjs} +1 -1
- package/dist/{middleware-BLnbBpsz.mjs → middleware-CUb31OGG.mjs} +1 -1
- package/dist/{middleware-ClfuKN0B.js → middleware-DX8wADUa.js} +451 -97
- package/dist/{middleware-CcNRQv7R.mjs → middleware-mRXKHq68.mjs} +355 -86
- package/dist/{mod-B1Qt5cQQ.d.ts → mod-B6s6hA4y.d.ts} +3 -3
- package/dist/{mod-ss0wBUH1.d.cts → mod-CJf5GcVD.d.cts} +3 -3
- package/dist/{mod-makPMVMg.d.cts → mod-CSlxqNto.d.cts} +1 -1
- package/dist/{mod-CpyjFA9s.d.ts → mod-D2DiA8u5.d.cts} +29 -7
- package/dist/{mod-BTxJG7ZH.d.cts → mod-DKRf1FLm.d.ts} +29 -7
- package/dist/{mod-B5COx5Wd.d.ts → mod-Dqu6Dl1k.d.ts} +1 -1
- package/dist/mod.cjs +5 -5
- package/dist/mod.d.cts +8 -8
- package/dist/mod.d.ts +8 -8
- package/dist/mod.js +5 -5
- package/dist/nodeinfo/client.test.mjs +432 -4
- package/dist/nodeinfo/handler.test.mjs +1 -1
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.d.cts +1 -1
- package/dist/nodeinfo/mod.d.ts +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/{outgoing-jsonld-4IJqPYos.mjs → outgoing-jsonld-Dsca6G_Y.mjs} +35 -4
- package/dist/{owner-DxVC0b0R.mjs → owner-DEiBiiqR.mjs} +3 -3
- package/dist/{portable-collection-8BzIIWJb.cjs → portable-collection--h11WDIi.cjs} +1 -1
- package/dist/{portable-collection-pWL8BrQk.mjs → portable-collection-D0-tInp2.mjs} +2 -2
- package/dist/{portable-collection-Bz3Zn527.js → portable-collection-M6d5I5JQ.js} +1 -1
- package/dist/{portable-key-BGmzMBYm.mjs → portable-key-CyVJpWWJ.mjs} +1 -1
- package/dist/{proof-Cgvg3rEH.mjs → proof-C4pwAF2k.mjs} +29 -9
- package/dist/{send-DheMZ6fh.mjs → send-ivzJCtb-.mjs} +100 -22
- 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 +2 -2
- package/dist/sig/compound-proof.test.mjs +3 -3
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +162 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +1 -1
- package/dist/sig/ld.test.mjs +572 -7
- package/dist/sig/mitra-receive-interop.test.mjs +4 -4
- package/dist/sig/mitra-send-interop.test.mjs +3 -3
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +2 -2
- package/dist/sig/owner.test.mjs +1 -1
- package/dist/sig/portable-collection.test.mjs +1 -1
- package/dist/sig/portable-interop.test.mjs +3 -3
- package/dist/sig/portable-key.test.mjs +5 -5
- package/dist/sig/proof.test.mjs +100 -6
- package/dist/sig/tootik-request-interop.test.mjs +4 -4
- package/dist/sig/tootik-send-interop.test.mjs +3 -3
- package/dist/sig/verification.test.mjs +3 -3
- package/dist/{temporal-B7odHbLs.mjs → temporal-B6OlxwK_.mjs} +3 -5
- package/dist/testing/kv.test.mjs +1 -1
- package/dist/testing/mod.d.mts +3 -5045
- package/dist/{types-DUjZb4i6.js → types-BbCbtwZp.js} +86 -11
- package/dist/{types-hKCCjii0.cjs → types-C8gac_AD.cjs} +85 -10
- 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/dist/utils/portable-verifier.test.mjs +3 -3
- 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-
|
|
6
|
-
import { g as recordInboxActivity, n as getDurationMs, r as getFederationMetrics } from "./metrics-
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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:
|
|
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-
|
|
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-
|
|
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-
|
|
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,13 +3,14 @@ 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-
|
|
7
|
-
import { _ as recordKeyLookup, n as getDurationMs, r as getFederationMetrics, s as measureSignatureKeyFetch, t as classifyFetchError } from "./metrics-
|
|
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";
|
|
@@ -143,7 +144,7 @@ function generateCryptoKeyPair(algorithm) {
|
|
|
143
144
|
*/
|
|
144
145
|
async function exportJwk(key) {
|
|
145
146
|
validateCryptoKey(key);
|
|
146
|
-
const jwk = await crypto.subtle.exportKey("jwk", key);
|
|
147
|
+
const jwk = await crypto.subtle.exportKey("jwk", asCryptoKey(key));
|
|
147
148
|
if (jwk.crv === "Ed25519") jwk.alg = "Ed25519";
|
|
148
149
|
return jwk;
|
|
149
150
|
}
|
|
@@ -1372,24 +1373,110 @@ function assertSafeJsonLd(jsonLd) {
|
|
|
1372
1373
|
}
|
|
1373
1374
|
}
|
|
1374
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
|
+
}
|
|
1375
1447
|
/**
|
|
1376
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`.
|
|
1377
1457
|
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
1378
1458
|
* modified.
|
|
1379
1459
|
* @param signature The signature to attach.
|
|
1380
1460
|
* @returns The JSON-LD document with the attached signature.
|
|
1381
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.
|
|
1382
1464
|
* @since 1.0.0
|
|
1383
1465
|
*/
|
|
1384
1466
|
function attachSignature(jsonLd, signature) {
|
|
1385
|
-
if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
};
|
|
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;
|
|
1390
1471
|
}
|
|
1391
1472
|
/**
|
|
1392
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.
|
|
1393
1480
|
* @param jsonLd The JSON-LD document to sign.
|
|
1394
1481
|
* @param privateKey The private key to sign the document.
|
|
1395
1482
|
* @param keyId The ID of the public key that corresponds to the private key.
|
|
@@ -1403,14 +1490,17 @@ async function createSignature(jsonLd, privateKey, keyId, { contextLoader, creat
|
|
|
1403
1490
|
validateCryptoKey(privateKey, "private");
|
|
1404
1491
|
if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
1405
1492
|
const options = {
|
|
1406
|
-
"@context": "https://w3id.org/identity/v1",
|
|
1407
1493
|
creator: keyId.href,
|
|
1408
1494
|
created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
1409
1495
|
};
|
|
1410
|
-
const message = await hashJsonLd(
|
|
1496
|
+
const message = await hashJsonLd({
|
|
1497
|
+
"@context": "https://w3id.org/identity/v1",
|
|
1498
|
+
...options
|
|
1499
|
+
}, contextLoader) + await hashJsonLd(prepareSignatureDocument(jsonLd), contextLoader);
|
|
1411
1500
|
const messageBytes = new TextEncoder().encode(message);
|
|
1412
|
-
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);
|
|
1413
1502
|
return {
|
|
1503
|
+
"@context": "https://w3id.org/security/v1",
|
|
1414
1504
|
...options,
|
|
1415
1505
|
type: "RsaSignature2017",
|
|
1416
1506
|
signatureValue: encodeBase64(signature)
|
|
@@ -1449,6 +1539,24 @@ async function signJsonLd(jsonLd, privateKey, keyId, options) {
|
|
|
1449
1539
|
}
|
|
1450
1540
|
});
|
|
1451
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
|
+
}
|
|
1452
1560
|
/**
|
|
1453
1561
|
* Checks if the given JSON-LD document has a Linked Data Signature-like
|
|
1454
1562
|
* object, without restricting it to a single suite-specific shape.
|
|
@@ -1513,6 +1621,10 @@ function detachSignature(jsonLd) {
|
|
|
1513
1621
|
* `activitypub.signature.key_fetch.duration`, since the rest of the work
|
|
1514
1622
|
* that the verification-duration metric is meant to cover happens in
|
|
1515
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.
|
|
1516
1628
|
* @param jsonLd The JSON-LD document to verify.
|
|
1517
1629
|
* @param options Options for verifying the signature.
|
|
1518
1630
|
* @returns The public key that signed the document or `null` if the signature
|
|
@@ -1520,7 +1632,11 @@ function detachSignature(jsonLd) {
|
|
|
1520
1632
|
* @since 1.0.0
|
|
1521
1633
|
*/
|
|
1522
1634
|
async function verifySignature(jsonLd, options = {}) {
|
|
1523
|
-
if (!
|
|
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
|
+
}
|
|
1524
1640
|
if (options[verificationObservation]?.attempt != null && options[verificationObservation]?.check == null) {
|
|
1525
1641
|
const declared = getLdSignatureObject(jsonLd)?.creator;
|
|
1526
1642
|
return await observeCheck(options, { mechanism: "linkedData" }, typeof declared === "string" ? declared : null, (observation) => verifySignature(jsonLd, {
|
|
@@ -1539,7 +1655,14 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
1539
1655
|
});
|
|
1540
1656
|
return null;
|
|
1541
1657
|
}
|
|
1542
|
-
|
|
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));
|
|
1543
1666
|
if (key == null) return null;
|
|
1544
1667
|
const sigOpts = {
|
|
1545
1668
|
...sig,
|
|
@@ -1550,7 +1673,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
1550
1673
|
delete sigOpts.signatureValue;
|
|
1551
1674
|
let sigOptsHash;
|
|
1552
1675
|
try {
|
|
1553
|
-
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
|
|
1676
|
+
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader, "verify");
|
|
1554
1677
|
} catch (error) {
|
|
1555
1678
|
logger.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
|
|
1556
1679
|
signatureOptions: sigOpts,
|
|
@@ -1562,7 +1685,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
1562
1685
|
delete document.signature;
|
|
1563
1686
|
let docHash;
|
|
1564
1687
|
try {
|
|
1565
|
-
docHash = await hashJsonLd(document, options.contextLoader);
|
|
1688
|
+
docHash = await hashJsonLd(document, options.contextLoader, "verify");
|
|
1566
1689
|
} catch (error) {
|
|
1567
1690
|
logger.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
|
|
1568
1691
|
document,
|
|
@@ -1580,7 +1703,7 @@ async function verifySignature(jsonLd, options = {}) {
|
|
|
1580
1703
|
keyId: sig.creator,
|
|
1581
1704
|
...sig
|
|
1582
1705
|
});
|
|
1583
|
-
const { key } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(
|
|
1706
|
+
const { key } = await measureSignatureKeyFetch(options.meterProvider, "linked_data", () => fetchKey(creator, CryptographicKey, {
|
|
1584
1707
|
...options,
|
|
1585
1708
|
keyCache: bypassKeyCacheReads(options.keyCache)
|
|
1586
1709
|
}));
|
|
@@ -1627,6 +1750,8 @@ function getLdSignatureObject(jsonLd) {
|
|
|
1627
1750
|
* Signatures. If the document is signed, this function verifies the signature
|
|
1628
1751
|
* and checks if the document is attributed to the owner of the public key.
|
|
1629
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.
|
|
1630
1755
|
* @param jsonLd The JSON-LD document to verify.
|
|
1631
1756
|
* @param options Options for verifying the document.
|
|
1632
1757
|
* @returns `true` if the document is authentic; `false` otherwise.
|
|
@@ -1653,11 +1778,12 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
|
1653
1778
|
let threw = false;
|
|
1654
1779
|
let signatureType;
|
|
1655
1780
|
try {
|
|
1656
|
-
const
|
|
1781
|
+
const hasLdSignature = hasVerifiableSignature(jsonLd);
|
|
1782
|
+
const verificationOptions = hasLdSignature ? {
|
|
1657
1783
|
...options,
|
|
1658
1784
|
contextLoader: getNormalizationContextLoader(options.contextLoader)
|
|
1659
1785
|
} : options;
|
|
1660
|
-
const compacted = compact ?
|
|
1786
|
+
const compacted = compact ? hasLdSignature ? await compactJsonLd(jsonLd, options.contextLoader) : jsonLd : jsonLd;
|
|
1661
1787
|
const object = await Object$1.fromJsonLd(compacted, verificationOptions);
|
|
1662
1788
|
observation?.parsedObject?.(object);
|
|
1663
1789
|
if (observation?.subject != null) observation.subject.id = object.id == null ? null : new URL(object.id.href);
|
|
@@ -1716,13 +1842,20 @@ async function verifyJsonLdInternal(jsonLd, options, compact) {
|
|
|
1716
1842
|
}
|
|
1717
1843
|
});
|
|
1718
1844
|
}
|
|
1719
|
-
|
|
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") {
|
|
1720
1851
|
const canon = await jsonld.canonize(jsonLd, {
|
|
1721
1852
|
format: "application/n-quads",
|
|
1722
|
-
documentLoader: contextLoader ?? getDocumentLoader()
|
|
1853
|
+
documentLoader: contextLoader ?? getDocumentLoader(),
|
|
1854
|
+
safe: mode === "sign",
|
|
1855
|
+
eventHandler: mode === "verify" ? handleVerificationEvent : void 0
|
|
1723
1856
|
});
|
|
1724
1857
|
const encoder = new TextEncoder();
|
|
1725
1858
|
return encodeHex(await crypto.subtle.digest("SHA-256", encoder.encode(canon)));
|
|
1726
1859
|
}
|
|
1727
1860
|
//#endregion
|
|
1728
|
-
export {
|
|
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-
|
|
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
|