@fedify/fedify 1.10.8 → 1.10.10
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/{actor-stZ3L5bm.mjs → actor-DZtfiGD5.mjs} +1 -1
- package/dist/{actor-BtdqoffI.js → actor-q2gTvEOg.js} +187 -187
- package/dist/{actor-CHbT9hXW.cjs → actor-yCME0Muf.cjs} +187 -187
- package/dist/{authdocloader-qSZCRtME.cjs → authdocloader-C9ucnURr.cjs} +3 -3
- package/dist/{authdocloader-BjFtWv8Q.js → authdocloader-CjcVKv5l.js} +3 -3
- package/dist/{authdocloader-DiNlCuEL.mjs → authdocloader-Dxs4mL_P.mjs} +3 -3
- package/dist/{builder-C06p3NRV.mjs → builder-DBBCeuJN.mjs} +4 -4
- package/dist/{client-aAP3RFq_.mjs → client-DfSKNItx.mjs} +1 -1
- package/dist/compat/mod.cjs +1 -1
- package/dist/compat/mod.d.cts +1 -1
- package/dist/compat/mod.d.ts +1 -1
- package/dist/compat/transformers.test.mjs +3 -3
- package/dist/{context-BzSr5FCW.d.cts → context-CC4UrGc5.d.cts} +48 -6
- package/dist/{context-CyacVopT.d.ts → context-xfiK4xM5.d.ts} +48 -6
- package/dist/{docloader-Cms83CjK.js → docloader-D8qb26Gj.js} +12 -3
- package/dist/{docloader--HMTXXhM.cjs → docloader-DR98w4wL.cjs} +12 -3
- package/dist/{esm-CfjSLJ-h.mjs → esm-onODA711.mjs} +1 -1
- package/dist/federation/builder.test.mjs +3 -3
- package/dist/federation/collection.test.mjs +1 -1
- package/dist/federation/handler.test.mjs +1362 -46
- package/dist/federation/idempotency.test.mjs +5 -5
- package/dist/federation/inbox.test.mjs +3 -3
- package/dist/federation/keycache.test.mjs +3 -3
- package/dist/federation/kv.test.mjs +1 -1
- package/dist/federation/middleware.test.mjs +1586 -82
- package/dist/federation/mod.cjs +2 -2
- package/dist/federation/mod.d.cts +1 -1
- package/dist/federation/mod.d.ts +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/federation/mq.test.mjs +3 -3
- package/dist/federation/retry.test.mjs +2 -2
- package/dist/federation/router.test.mjs +2 -2
- package/dist/federation/send.test.mjs +8 -8
- package/dist/federation/temporal.test.d.mts +2 -0
- package/dist/federation/temporal.test.mjs +71 -0
- package/dist/{http-CDZB3DBW.js → http-D6Qz3p20.js} +3 -3
- package/dist/{http-BPQ_zPRB.mjs → http-DyCX-dN3.mjs} +2 -2
- package/dist/{http-Bg-OkZtX.cjs → http-mdiWJYia.cjs} +3 -3
- package/dist/{inbox-Cnih7u27.mjs → inbox-BZN50kyQ.mjs} +7 -4
- package/dist/{key-C16D-kud.mjs → key-CSH0Pfat.mjs} +2 -2
- package/dist/{key-DGuUMBsU.cjs → key-DPzMtgeE.cjs} +1 -1
- package/dist/{key-Bbf-ITpM.cjs → key-DRfL8gil.cjs} +2 -2
- package/dist/{key-B0qYOng3.mjs → key-DXUAJBZu.mjs} +1 -1
- package/dist/{key-ASS7oK8n.js → key-TRp8WTUL.js} +2 -2
- package/dist/{keycache-CBPbgb7d.mjs → keycache-DETDxpbh.mjs} +1 -1
- package/dist/{keys-Br4iedk3.mjs → keys-8FIoKqmB.mjs} +1 -1
- package/dist/ld-BaJmhpEa.mjs +548 -0
- package/dist/{lookup-CA5RreoS.cjs → lookup-B7TLaXFf.cjs} +1 -1
- package/dist/{lookup-CpMB-hV5.js → lookup-C6wM-gq1.js} +1 -1
- package/dist/{lookup-CCcDhxO2.mjs → lookup-CX2yfN-X.mjs} +1 -1
- package/dist/{middleware-Bi5LcEMF.mjs → middleware-BJ7otoEC.mjs} +1 -1
- package/dist/{middleware-Crs1EVL7.mjs → middleware-BQ6evC7E.mjs} +320 -87
- package/dist/{middleware-BDTuu7QY.js → middleware-BXc5M6YG.js} +408 -83
- package/dist/{middleware-C90kKt44.cjs → middleware-DpVqFb2x.cjs} +411 -85
- package/dist/{middleware-BPTDstS-.cjs → middleware-cNynSnF6.cjs} +1 -1
- package/dist/mod.cjs +10 -10
- package/dist/mod.d.cts +1 -1
- package/dist/mod.d.ts +1 -1
- package/dist/mod.js +9 -9
- package/dist/nodeinfo/client.test.mjs +3 -3
- package/dist/nodeinfo/handler.test.mjs +2 -2
- package/dist/nodeinfo/mod.cjs +1 -1
- package/dist/nodeinfo/mod.js +1 -1
- package/dist/nodeinfo/semver.test.mjs +1 -1
- package/dist/nodeinfo/types.test.mjs +1 -1
- package/dist/otel/exporter.test.mjs +1 -1
- package/dist/otel/mod.cjs +1 -1
- package/dist/{owner-ncOJW9jU.mjs → owner-CLGVwm9P.mjs} +3 -3
- package/dist/{proof-BYdxNk_7.cjs → proof-BVB37JmB.cjs} +347 -5
- package/dist/{proof-Bd732W1s.mjs → proof-CAOvY-AP.mjs} +2 -2
- package/dist/{proof-JCn_Nftz.js → proof-DxQL08gJ.js} +300 -6
- package/dist/runtime/authdocloader.test.mjs +6 -6
- package/dist/runtime/docloader.test.mjs +4 -4
- package/dist/runtime/key.test.mjs +3 -3
- package/dist/runtime/langstr.test.mjs +2 -2
- package/dist/runtime/link.test.mjs +2 -2
- package/dist/runtime/mod.cjs +3 -3
- package/dist/runtime/mod.js +3 -3
- package/dist/runtime/multibase/multibase.test.mjs +2 -2
- package/dist/runtime/url.test.mjs +5 -2
- package/dist/{send-BUUNtAjI.mjs → send-BFClgq8T.mjs} +2 -2
- package/dist/sig/http.test.mjs +6 -6
- package/dist/sig/key.test.mjs +4 -4
- package/dist/sig/ld.test.mjs +561 -5
- package/dist/sig/mod.cjs +3 -3
- package/dist/sig/mod.js +3 -3
- package/dist/sig/owner.test.mjs +6 -6
- package/dist/sig/proof.test.mjs +4 -4
- package/dist/temporal-lmewfA7Y.mjs +95 -0
- package/dist/testing/docloader.test.mjs +1 -1
- package/dist/testing/mod.d.mts +48 -6
- package/dist/testing/mod.mjs +1 -1
- package/dist/{testing-CvmsaHLW.mjs → testing-B9FmxxlI.mjs} +2 -2
- package/dist/{transformers-Cd6Tdn3M.cjs → transformers-KRl8YJCO.cjs} +1 -1
- package/dist/{types-Dy8sMtkH.js → types-B0aIcMDF.js} +1 -1
- package/dist/{types-BVCtDIwE.cjs → types-DPWiFqle.cjs} +1 -1
- package/dist/vocab/actor.test.mjs +4 -4
- package/dist/vocab/cjs.test.mjs +1 -1
- package/dist/vocab/lookup.test.mjs +5 -5
- package/dist/vocab/mod.cjs +3 -3
- package/dist/vocab/mod.js +3 -3
- package/dist/vocab/type.test.mjs +2 -2
- package/dist/vocab/vocab.test.mjs +3 -3
- package/dist/{vocab-DcYXFzyR.mjs → vocab-DP9A9TjH.mjs} +197 -188
- package/dist/webfinger/handler.test.mjs +3 -3
- package/dist/webfinger/lookup.test.mjs +3 -3
- package/dist/webfinger/mod.cjs +1 -1
- package/dist/webfinger/mod.js +1 -1
- package/dist/x/cfworkers.cjs +1 -1
- package/dist/x/cfworkers.test.mjs +1 -1
- package/dist/x/hono.cjs +1 -1
- package/dist/x/hono.d.cts +1 -1
- package/dist/x/hono.d.ts +1 -1
- package/dist/x/sveltekit.cjs +1 -1
- package/dist/x/sveltekit.d.cts +1 -1
- package/dist/x/sveltekit.d.ts +1 -1
- package/package.json +1 -1
- package/dist/ld-7nQ68-rS.mjs +0 -254
- /package/dist/{denokv-NJPMXyK0.mjs → denokv-B0ZRIDsH.mjs} +0 -0
- /package/dist/{otel-0v4Zy01l.mjs → otel-D00WjYJ1.mjs} +0 -0
- /package/dist/{retry-Ddbq3AcK.mjs → retry-B_E3V_Dx.mjs} +0 -0
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { C as Person, h as Link, p as Image } from "../vocab-
|
|
5
|
-
import { i as createRequestContext, t as test } from "../testing-
|
|
4
|
+
import { C as Person, h as Link, p as Image } from "../vocab-DP9A9TjH.mjs";
|
|
5
|
+
import { i as createRequestContext, t as test } from "../testing-B9FmxxlI.mjs";
|
|
6
6
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
7
7
|
import "../std__assert-2v7gYiZp.mjs";
|
|
8
8
|
import { t as MemoryKvStore } from "../kv-OuT2IU64.mjs";
|
|
9
|
-
import { a as createFederation, m as handleWebFinger } from "../middleware-
|
|
9
|
+
import { a as createFederation, m as handleWebFinger } from "../middleware-BQ6evC7E.mjs";
|
|
10
10
|
//#region src/webfinger/handler.test.ts
|
|
11
11
|
test("handleWebFinger()", async (t) => {
|
|
12
12
|
const url = new URL("https://example.com/.well-known/webfinger");
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { W as lookupWebFinger } from "../vocab-
|
|
5
|
-
import { t as test } from "../testing-
|
|
4
|
+
import { W as lookupWebFinger } from "../vocab-DP9A9TjH.mjs";
|
|
5
|
+
import { t as test } from "../testing-B9FmxxlI.mjs";
|
|
6
6
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
7
7
|
import "../std__assert-2v7gYiZp.mjs";
|
|
8
|
-
import { t as esm_default } from "../esm-
|
|
8
|
+
import { t as esm_default } from "../esm-onODA711.mjs";
|
|
9
9
|
import { withTimeout } from "es-toolkit";
|
|
10
10
|
//#region src/webfinger/lookup.test.ts
|
|
11
11
|
test({
|
package/dist/webfinger/mod.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
const require_lookup = require("../lookup-
|
|
4
|
+
const require_lookup = require("../lookup-B7TLaXFf.cjs");
|
|
5
5
|
exports.lookupWebFinger = require_lookup.lookupWebFinger;
|
package/dist/webfinger/mod.js
CHANGED
package/dist/x/cfworkers.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
require("../docloader
|
|
4
|
+
require("../docloader-DR98w4wL.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
//#region src/x/cfworkers.ts
|
|
7
7
|
/**
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as test } from "../testing-
|
|
4
|
+
import { t as test } from "../testing-B9FmxxlI.mjs";
|
|
5
5
|
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
6
|
import "../std__assert-2v7gYiZp.mjs";
|
|
7
7
|
import { getLogger } from "@logtape/logtape";
|
package/dist/x/hono.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
require("../docloader
|
|
4
|
+
require("../docloader-DR98w4wL.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
//#region src/x/hono.ts
|
|
7
7
|
/**
|
package/dist/x/hono.d.cts
CHANGED
package/dist/x/hono.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { g as Federation } from "../context-
|
|
3
|
+
import { g as Federation } from "../context-xfiK4xM5.js";
|
|
4
4
|
|
|
5
5
|
//#region src/x/hono.d.ts
|
|
6
6
|
interface HonoRequest {
|
package/dist/x/sveltekit.cjs
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
const { Temporal } = require("@js-temporal/polyfill");
|
|
2
2
|
const { URLPattern } = require("urlpattern-polyfill");
|
|
3
3
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
4
|
-
require("../docloader
|
|
4
|
+
require("../docloader-DR98w4wL.cjs");
|
|
5
5
|
let _logtape_logtape = require("@logtape/logtape");
|
|
6
6
|
//#region src/x/sveltekit.ts
|
|
7
7
|
/**
|
package/dist/x/sveltekit.d.cts
CHANGED
package/dist/x/sveltekit.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Temporal } from "@js-temporal/polyfill";
|
|
2
2
|
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
-
import { g as Federation } from "../context-
|
|
3
|
+
import { g as Federation } from "../context-xfiK4xM5.js";
|
|
4
4
|
|
|
5
5
|
//#region src/x/sveltekit.d.ts
|
|
6
6
|
type RequestEvent = {
|
package/package.json
CHANGED
package/dist/ld-7nQ68-rS.mjs
DELETED
|
@@ -1,254 +0,0 @@
|
|
|
1
|
-
import "@js-temporal/polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { J as getDocumentLoader, U as getTypeId, ot as name, s as CryptographicKey, st as version, t as Activity, v as Object$1 } from "./vocab-DcYXFzyR.mjs";
|
|
5
|
-
import { a as validateCryptoKey, n as fetchKey } from "./key-C16D-kud.mjs";
|
|
6
|
-
import { getLogger } from "@logtape/logtape";
|
|
7
|
-
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
8
|
-
import jsonld from "jsonld";
|
|
9
|
-
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
10
|
-
import { encodeHex } from "byte-encodings/hex";
|
|
11
|
-
//#region src/sig/ld.ts
|
|
12
|
-
const logger = getLogger([
|
|
13
|
-
"fedify",
|
|
14
|
-
"sig",
|
|
15
|
-
"ld"
|
|
16
|
-
]);
|
|
17
|
-
/**
|
|
18
|
-
* Attaches a LD signature to the given JSON-LD document.
|
|
19
|
-
* @param jsonLd The JSON-LD document to attach the signature to. It is not
|
|
20
|
-
* modified.
|
|
21
|
-
* @param signature The signature to attach.
|
|
22
|
-
* @returns The JSON-LD document with the attached signature.
|
|
23
|
-
* @throws {TypeError} If the input document is not a valid JSON-LD document.
|
|
24
|
-
* @since 1.0.0
|
|
25
|
-
*/
|
|
26
|
-
function attachSignature(jsonLd, signature) {
|
|
27
|
-
if (typeof jsonLd !== "object" || jsonLd == null) throw new TypeError("Failed to attach signature; invalid JSON-LD document.");
|
|
28
|
-
return {
|
|
29
|
-
...jsonLd,
|
|
30
|
-
signature
|
|
31
|
-
};
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Creates a LD signature for the given JSON-LD document.
|
|
35
|
-
* @param jsonLd The JSON-LD document to sign.
|
|
36
|
-
* @param privateKey The private key to sign the document.
|
|
37
|
-
* @param keyId The ID of the public key that corresponds to the private key.
|
|
38
|
-
* @param options Additional options for creating the signature.
|
|
39
|
-
* See also {@link CreateSignatureOptions}.
|
|
40
|
-
* @return The created signature.
|
|
41
|
-
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
42
|
-
* @since 1.0.0
|
|
43
|
-
*/
|
|
44
|
-
async function createSignature(jsonLd, privateKey, keyId, { contextLoader, created } = {}) {
|
|
45
|
-
validateCryptoKey(privateKey, "private");
|
|
46
|
-
if (privateKey.algorithm.name !== "RSASSA-PKCS1-v1_5") throw new TypeError("Unsupported algorithm: " + privateKey.algorithm.name);
|
|
47
|
-
const options = {
|
|
48
|
-
"@context": "https://w3id.org/identity/v1",
|
|
49
|
-
creator: keyId.href,
|
|
50
|
-
created: created?.toString() ?? (/* @__PURE__ */ new Date()).toISOString()
|
|
51
|
-
};
|
|
52
|
-
const message = await hashJsonLd(options, contextLoader) + await hashJsonLd(jsonLd, contextLoader);
|
|
53
|
-
const messageBytes = new TextEncoder().encode(message);
|
|
54
|
-
const signature = await crypto.subtle.sign("RSASSA-PKCS1-v1_5", privateKey, messageBytes);
|
|
55
|
-
return {
|
|
56
|
-
...options,
|
|
57
|
-
type: "RsaSignature2017",
|
|
58
|
-
signatureValue: encodeBase64(signature)
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Signs the given JSON-LD document with the private key and returns the signed
|
|
63
|
-
* JSON-LD document.
|
|
64
|
-
* @param jsonLd The JSON-LD document to sign.
|
|
65
|
-
* @param privateKey The private key to sign the document.
|
|
66
|
-
* @param keyId The key ID to use in the signature. It will be used by the
|
|
67
|
-
* verifier to fetch the corresponding public key.
|
|
68
|
-
* @param options Additional options for signing the document.
|
|
69
|
-
* See also {@link SignJsonLdOptions}.
|
|
70
|
-
* @returns The signed JSON-LD document.
|
|
71
|
-
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
72
|
-
* @since 1.0.0
|
|
73
|
-
*/
|
|
74
|
-
async function signJsonLd(jsonLd, privateKey, keyId, options) {
|
|
75
|
-
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.sign", { attributes: { "ld_signatures.key_id": keyId.href } }, async (span) => {
|
|
76
|
-
try {
|
|
77
|
-
const signature = await createSignature(jsonLd, privateKey, keyId, options);
|
|
78
|
-
if (span.isRecording()) {
|
|
79
|
-
span.setAttribute("ld_signatures.type", signature.type);
|
|
80
|
-
span.setAttribute("ld_signatures.signature", encodeHex(decodeBase64(signature.signatureValue)));
|
|
81
|
-
}
|
|
82
|
-
return attachSignature(jsonLd, signature);
|
|
83
|
-
} catch (error) {
|
|
84
|
-
span.setStatus({
|
|
85
|
-
code: SpanStatusCode.ERROR,
|
|
86
|
-
message: String(error)
|
|
87
|
-
});
|
|
88
|
-
throw error;
|
|
89
|
-
} finally {
|
|
90
|
-
span.end();
|
|
91
|
-
}
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Checks if the given JSON-LD document has a Linked Data Signature.
|
|
96
|
-
* @param jsonLd The JSON-LD document to check.
|
|
97
|
-
* @returns `true` if the document has a signature; `false` otherwise.
|
|
98
|
-
* @since 1.0.0
|
|
99
|
-
*/
|
|
100
|
-
function hasSignature(jsonLd) {
|
|
101
|
-
if (typeof jsonLd !== "object" || jsonLd == null) return false;
|
|
102
|
-
if ("signature" in jsonLd) {
|
|
103
|
-
const signature = jsonLd.signature;
|
|
104
|
-
if (typeof signature !== "object" || signature == null) return false;
|
|
105
|
-
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";
|
|
106
|
-
}
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
/**
|
|
110
|
-
* Detaches Linked Data Signatures from the given JSON-LD document.
|
|
111
|
-
* @param jsonLd The JSON-LD document to modify.
|
|
112
|
-
* @returns The modified JSON-LD document. If the input document does not
|
|
113
|
-
* contain a signature, the original document is returned.
|
|
114
|
-
* @since 1.0.0
|
|
115
|
-
*/
|
|
116
|
-
function detachSignature(jsonLd) {
|
|
117
|
-
if (typeof jsonLd !== "object" || jsonLd == null) return jsonLd;
|
|
118
|
-
const doc = { ...jsonLd };
|
|
119
|
-
delete doc.signature;
|
|
120
|
-
return doc;
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Verifies Linked Data Signatures of the given JSON-LD document.
|
|
124
|
-
* @param jsonLd The JSON-LD document to verify.
|
|
125
|
-
* @param options Options for verifying the signature.
|
|
126
|
-
* @returns The public key that signed the document or `null` if the signature
|
|
127
|
-
* is invalid or the key is not found.
|
|
128
|
-
* @since 1.0.0
|
|
129
|
-
*/
|
|
130
|
-
async function verifySignature(jsonLd, options = {}) {
|
|
131
|
-
if (!hasSignature(jsonLd)) return null;
|
|
132
|
-
const sig = jsonLd.signature;
|
|
133
|
-
let signature;
|
|
134
|
-
try {
|
|
135
|
-
signature = decodeBase64(sig.signatureValue);
|
|
136
|
-
} catch (error) {
|
|
137
|
-
logger.debug("Failed to verify; invalid base64 signatureValue: {signatureValue}", {
|
|
138
|
-
...sig,
|
|
139
|
-
error
|
|
140
|
-
});
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
const { key, cached } = await fetchKey(new URL(sig.creator), CryptographicKey, options);
|
|
144
|
-
if (key == null) return null;
|
|
145
|
-
const sigOpts = {
|
|
146
|
-
...sig,
|
|
147
|
-
"@context": "https://w3id.org/identity/v1"
|
|
148
|
-
};
|
|
149
|
-
delete sigOpts.type;
|
|
150
|
-
delete sigOpts.id;
|
|
151
|
-
delete sigOpts.signatureValue;
|
|
152
|
-
let sigOptsHash;
|
|
153
|
-
try {
|
|
154
|
-
sigOptsHash = await hashJsonLd(sigOpts, options.contextLoader);
|
|
155
|
-
} catch (error) {
|
|
156
|
-
logger.warn("Failed to verify; failed to hash the signature options: {signatureOptions}\n{error}", {
|
|
157
|
-
signatureOptions: sigOpts,
|
|
158
|
-
error
|
|
159
|
-
});
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
const document = { ...jsonLd };
|
|
163
|
-
delete document.signature;
|
|
164
|
-
let docHash;
|
|
165
|
-
try {
|
|
166
|
-
docHash = await hashJsonLd(document, options.contextLoader);
|
|
167
|
-
} catch (error) {
|
|
168
|
-
logger.warn("Failed to verify; failed to hash the document: {document}\n{error}", {
|
|
169
|
-
document,
|
|
170
|
-
error
|
|
171
|
-
});
|
|
172
|
-
return null;
|
|
173
|
-
}
|
|
174
|
-
const encoder = new TextEncoder();
|
|
175
|
-
const message = sigOptsHash + docHash;
|
|
176
|
-
const messageBytes = encoder.encode(message);
|
|
177
|
-
if (await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes)) return key;
|
|
178
|
-
if (cached) {
|
|
179
|
-
logger.debug("Failed to verify with the cached key {keyId}; signature {signatureValue} is invalid. Retrying with the freshly fetched key...", {
|
|
180
|
-
keyId: sig.creator,
|
|
181
|
-
...sig
|
|
182
|
-
});
|
|
183
|
-
const { key } = await fetchKey(new URL(sig.creator), CryptographicKey, {
|
|
184
|
-
...options,
|
|
185
|
-
keyCache: {
|
|
186
|
-
get: () => Promise.resolve(void 0),
|
|
187
|
-
set: async (keyId, key) => await options.keyCache?.set(keyId, key)
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
if (key == null) return null;
|
|
191
|
-
return await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, signature.slice(), messageBytes) ? key : null;
|
|
192
|
-
}
|
|
193
|
-
logger.debug("Failed to verify with the fetched key {keyId}; signature {signatureValue} is invalid. Check if the key is correct or if the signed message is correct. The message to sign is:\n{message}", {
|
|
194
|
-
keyId: sig.creator,
|
|
195
|
-
...sig,
|
|
196
|
-
message
|
|
197
|
-
});
|
|
198
|
-
return null;
|
|
199
|
-
}
|
|
200
|
-
/**
|
|
201
|
-
* Verify the authenticity of the given JSON-LD document using Linked Data
|
|
202
|
-
* Signatures. If the document is signed, this function verifies the signature
|
|
203
|
-
* and checks if the document is attributed to the owner of the public key.
|
|
204
|
-
* If the document is not signed, this function returns `false`.
|
|
205
|
-
* @param jsonLd The JSON-LD document to verify.
|
|
206
|
-
* @param options Options for verifying the document.
|
|
207
|
-
* @returns `true` if the document is authentic; `false` otherwise.
|
|
208
|
-
*/
|
|
209
|
-
async function verifyJsonLd(jsonLd, options = {}) {
|
|
210
|
-
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("ld_signatures.verify", async (span) => {
|
|
211
|
-
try {
|
|
212
|
-
const object = await Object$1.fromJsonLd(jsonLd, options);
|
|
213
|
-
if (object.id != null) span.setAttribute("activitypub.object.id", object.id.href);
|
|
214
|
-
span.setAttribute("activitypub.object.type", getTypeId(object).href);
|
|
215
|
-
if (typeof jsonLd === "object" && jsonLd != null && "signature" in jsonLd && typeof jsonLd.signature === "object" && jsonLd.signature != null) {
|
|
216
|
-
if ("creator" in jsonLd.signature && typeof jsonLd.signature.creator === "string") span.setAttribute("ld_signatures.key_id", jsonLd.signature.creator);
|
|
217
|
-
if ("signatureValue" in jsonLd.signature && typeof jsonLd.signature.signatureValue === "string") span.setAttribute("ld_signatures.signature", jsonLd.signature.signatureValue);
|
|
218
|
-
if ("type" in jsonLd.signature && typeof jsonLd.signature.type === "string") span.setAttribute("ld_signatures.type", jsonLd.signature.type);
|
|
219
|
-
}
|
|
220
|
-
const attributions = new Set(object.attributionIds.map((uri) => uri.href));
|
|
221
|
-
if (object instanceof Activity) for (const uri of object.actorIds) attributions.add(uri.href);
|
|
222
|
-
const key = await verifySignature(jsonLd, options);
|
|
223
|
-
if (key == null) return false;
|
|
224
|
-
if (key.ownerId == null) {
|
|
225
|
-
logger.debug("Key {keyId} has no owner.", { keyId: key.id?.href });
|
|
226
|
-
return false;
|
|
227
|
-
}
|
|
228
|
-
attributions.delete(key.ownerId.href);
|
|
229
|
-
if (attributions.size > 0) {
|
|
230
|
-
logger.debug("Some attributions are not authenticated by the Linked Data Signatures: {attributions}.", { attributions: [...attributions] });
|
|
231
|
-
return false;
|
|
232
|
-
}
|
|
233
|
-
return true;
|
|
234
|
-
} catch (error) {
|
|
235
|
-
span.setStatus({
|
|
236
|
-
code: SpanStatusCode.ERROR,
|
|
237
|
-
message: String(error)
|
|
238
|
-
});
|
|
239
|
-
throw error;
|
|
240
|
-
} finally {
|
|
241
|
-
span.end();
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
async function hashJsonLd(jsonLd, contextLoader) {
|
|
246
|
-
const canon = await jsonld.canonize(jsonLd, {
|
|
247
|
-
format: "application/n-quads",
|
|
248
|
-
documentLoader: contextLoader ?? getDocumentLoader()
|
|
249
|
-
});
|
|
250
|
-
const encoder = new TextEncoder();
|
|
251
|
-
return encodeHex(await crypto.subtle.digest("SHA-256", encoder.encode(canon)));
|
|
252
|
-
}
|
|
253
|
-
//#endregion
|
|
254
|
-
export { signJsonLd as a, hasSignature as i, createSignature as n, verifyJsonLd as o, detachSignature as r, verifySignature as s, attachSignature as t };
|
|
File without changes
|
|
File without changes
|
|
File without changes
|