@fedify/fedify 2.2.20 → 2.2.21
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-CalAATqD.mjs +16 -0
- package/dist/{builder-BolQ56ab.mjs → builder-4ImvtjG4.mjs} +3 -3
- package/dist/callback-0KrwzutD.d.mts +2607 -0
- package/dist/{client-jE7oGvRh.d.ts → client-9DPcy_Yx.d.ts} +16 -0
- package/dist/{client-BIBzqEIp.d.cts → client-B3ruDgWg.d.cts} +16 -0
- package/dist/{client-DhxaVgOv.mjs → client-XYMC0Mmk.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/public-audience.test.mjs +1 -1
- package/dist/compat/transformers.test.mjs +1 -1
- package/dist/{context-CFQGaq5x.d.cts → context-CjWuov0g.d.cts} +31 -14
- package/dist/{context-DdbLVV_k.d.ts → context-DZqI2LJD.d.ts} +31 -14
- package/dist/{deno-BUj4roJc.mjs → deno-AWk3S2Ug.mjs} +1 -1
- package/dist/{docloader-CbtF_0cD.mjs → docloader-Bogpjg4d.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/collection.test.mjs +1 -1
- package/dist/federation/delivery-attachments.test.d.mts +2 -0
- package/dist/federation/delivery-attachments.test.mjs +288 -0
- package/dist/federation/handler.test.mjs +208 -16
- package/dist/federation/idempotency.test.mjs +2 -2
- package/dist/federation/inbox.test.mjs +2 -2
- package/dist/federation/middleware.test.mjs +1184 -8
- 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/negotiation.test.mjs +1 -1
- package/dist/federation/retry.test.mjs +1 -1
- package/dist/federation/send.test.mjs +283 -3
- package/dist/federation/temporal.test.mjs +25 -1
- package/dist/federation/webfinger.test.mjs +1 -1
- package/dist/{http-CQMVisM0.mjs → http-B3wCvgu8.mjs} +6 -4
- package/dist/{http-D8I7LBfx.cjs → http-BNaPJVnF.cjs} +6 -4
- package/dist/{http-C5g_VrA_.js → http-BpdLaGy8.js} +6 -4
- package/dist/{http-9IFUxdkp.d.cts → http-C8qLHs_Z.d.cts} +3 -3
- package/dist/{http-SbfezERn.d.ts → http-D8WmcRAF.d.ts} +3 -3
- package/dist/{inbox-CD8IDILN.mjs → inbox-DLy6WBXU.mjs} +1 -1
- package/dist/{key-C3o3DGap.mjs → key-Bhc8cQC7.mjs} +3 -2
- package/dist/{kv-cache-DC9LcfoC.cjs → kv-cache-Bj3CY9Jo.cjs} +1 -1
- package/dist/{kv-cache-CSKXXleR.js → kv-cache-CvjLUQTf.js} +1 -1
- package/dist/{ld-ijSr-0AB.mjs → ld-DTeykI0e.mjs} +153 -21
- package/dist/ld-signature-Dgz_b89j.mjs +23 -0
- package/dist/{middleware-DNueR0GD.cjs → middleware-BSQP4d9p.cjs} +475 -107
- package/dist/{middleware-DmcY2TWS.cjs → middleware-CWOzxb3o.cjs} +1 -1
- package/dist/{middleware-yqqfI7oJ.mjs → middleware-DkMsC5mQ.mjs} +1 -1
- package/dist/{middleware-sjhz30sm.js → middleware-Dx1iwFk8.js} +474 -107
- package/dist/{middleware-CYAaUTi5.mjs → middleware-dlGvSrXl.mjs} +386 -96
- package/dist/{mod-BYWp77-z.d.cts → mod-BmxqcEnU.d.ts} +30 -13
- package/dist/{mod-CVSKw-5H.d.cts → mod-DWEx2D4q.d.cts} +1 -1
- package/dist/{mod-BuRRdsfD.d.ts → mod-DnPmz3-S.d.ts} +1 -1
- package/dist/{mod-CM5_J_cx.d.ts → mod-INjDw-m0.d.cts} +30 -13
- package/dist/{mod-BRnwh2oy.d.ts → mod-REfljt0T.d.ts} +3 -3
- package/dist/{mod-Co7LEK9X.d.cts → mod-UvIGUHqW.d.cts} +3 -3
- 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/nodeinfo/types.test.mjs +1 -1
- package/dist/{outgoing-jsonld-amccRMrV.mjs → outgoing-jsonld-DHf_DYXp.mjs} +38 -8
- package/dist/{owner-B8kXzD0q.mjs → owner-BsA7qMHB.mjs} +2 -2
- package/dist/{proof-CBQOjOgA.mjs → proof-C63Hqt9N.mjs} +40 -15
- package/dist/{proof-qiuGJCD7.cjs → proof-Dbz6ApNP.cjs} +1190 -1007
- package/dist/{proof-DKX6nASL.js → proof-QV_o5ZqS.js} +1174 -1003
- package/dist/{send-DRpisX_f.mjs → send-CAdpwbFX.mjs} +92 -21
- package/dist/sig/http.test.mjs +2 -2
- package/dist/sig/key-types.test.d.mts +218 -0
- package/dist/sig/key-types.test.mjs +8 -0
- package/dist/sig/key.test.mjs +2 -2
- package/dist/sig/ld.test.mjs +573 -8
- 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/proof.test.mjs +96 -4
- package/dist/{temporal-BQGEINad.mjs → temporal-B3JGkVgk.mjs} +3 -5
- package/dist/testing/mod.d.mts +2 -2422
- package/dist/{types-DOvyymM4.cjs → types-BWx7zw3Y.cjs} +85 -10
- package/dist/{types-B1_pRFE_.js → types-Dx_w2JSM.js} +86 -11
- package/dist/utils/docloader.test.mjs +2 -2
- 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 +5 -5
- /package/dist/{activity-listener-ell7W1s9.mjs → activity-listener-tztVvlNb.mjs} +0 -0
- /package/dist/{collection-D-HqUuA2.mjs → collection-CA3V5zyK.mjs} +0 -0
- /package/dist/{negotiation-SQvQgUqe.mjs → negotiation-VnHNB0Q5.mjs} +0 -0
- /package/dist/{public-audience-DpJqzPuh.mjs → public-audience-4g3_Ze4y.mjs} +0 -0
- /package/dist/{retry-v_sGLH1d.mjs → retry-CXg_MBI-.mjs} +0 -0
- /package/dist/{types-J53Kw7so.mjs → types-BFowWFTT.mjs} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import "@js-temporal/polyfill";
|
|
2
2
|
import "urlpattern-polyfill";
|
|
3
3
|
globalThis.addEventListener = () => {};
|
|
4
|
-
import { n as version, t as name } from "./deno-
|
|
5
|
-
import { r as doubleKnockScoped } from "./http-
|
|
4
|
+
import { n as version, t as name } from "./deno-AWk3S2Ug.mjs";
|
|
5
|
+
import { r as doubleKnockScoped } from "./http-B3wCvgu8.mjs";
|
|
6
6
|
import { SpanKind, SpanStatusCode, trace } from "@opentelemetry/api";
|
|
7
7
|
import { FetchError, UrlError } from "@fedify/vocab-runtime";
|
|
8
8
|
import { openDirectFetch, openPublicFetch } from "@fedify/vocab-runtime/internal";
|
|
@@ -40,7 +40,8 @@ function extractInboxes({ recipients, preferSharedInbox, excludeBaseUris }) {
|
|
|
40
40
|
* @param parameters The parameters for sending the activity.
|
|
41
41
|
* See also {@link SendActivityParameters}.
|
|
42
42
|
* @param deps The dependencies, for tests.
|
|
43
|
-
* @throws {
|
|
43
|
+
* @throws {FetchError} If the delivery times out before receiving a response.
|
|
44
|
+
* @throws {SendActivityError} If the inbox returns an unsuccessful response.
|
|
44
45
|
*/
|
|
45
46
|
function sendActivity(options, deps = {}) {
|
|
46
47
|
const tracerProvider = options.tracerProvider ?? trace.getTracerProvider();
|
|
@@ -67,7 +68,25 @@ function sendActivity(options, deps = {}) {
|
|
|
67
68
|
});
|
|
68
69
|
}
|
|
69
70
|
const MAX_ERROR_RESPONSE_BODY_BYTES = 1024;
|
|
70
|
-
|
|
71
|
+
const SEND_ACTIVITY_TIMEOUT_MS = 3e4;
|
|
72
|
+
function raceWithAbort(promise, signal) {
|
|
73
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
const onAbort = () => {
|
|
76
|
+
signal.removeEventListener("abort", onAbort);
|
|
77
|
+
reject(signal.reason);
|
|
78
|
+
};
|
|
79
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
80
|
+
promise.then((value) => {
|
|
81
|
+
signal.removeEventListener("abort", onAbort);
|
|
82
|
+
resolve(value);
|
|
83
|
+
}, (error) => {
|
|
84
|
+
signal.removeEventListener("abort", onAbort);
|
|
85
|
+
reject(error);
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
async function readLimitedResponseBody(response, maxBytes, signal) {
|
|
71
90
|
if (response.body == null) return "";
|
|
72
91
|
const reader = response.body.getReader();
|
|
73
92
|
const decoder = new TextDecoder();
|
|
@@ -76,7 +95,8 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
76
95
|
let truncated = false;
|
|
77
96
|
try {
|
|
78
97
|
while (true) {
|
|
79
|
-
|
|
98
|
+
signal.throwIfAborted();
|
|
99
|
+
const { done, value } = await raceWithAbort(reader.read(), signal);
|
|
80
100
|
if (done) break;
|
|
81
101
|
if (totalBytes + value.length > maxBytes) {
|
|
82
102
|
const remaining = maxBytes - totalBytes;
|
|
@@ -88,8 +108,10 @@ async function readLimitedResponseBody(response, maxBytes) {
|
|
|
88
108
|
totalBytes += value.length;
|
|
89
109
|
}
|
|
90
110
|
} finally {
|
|
91
|
-
if (truncated) reader.cancel().catch(() => {});
|
|
92
|
-
|
|
111
|
+
if (truncated || signal.aborted) reader.cancel().catch(() => {});
|
|
112
|
+
try {
|
|
113
|
+
reader.releaseLock();
|
|
114
|
+
} catch (_) {}
|
|
93
115
|
}
|
|
94
116
|
let result = chunks.join("");
|
|
95
117
|
if (truncated) result += "… (truncated)";
|
|
@@ -101,12 +123,24 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
101
123
|
"federation",
|
|
102
124
|
"outbox"
|
|
103
125
|
]);
|
|
104
|
-
const
|
|
126
|
+
const timeoutMs = deps.timeoutMs ?? SEND_ACTIVITY_TIMEOUT_MS;
|
|
127
|
+
const controller = new AbortController();
|
|
128
|
+
const { signal } = controller;
|
|
129
|
+
const openUnvalidatedHop = deps.openHop ?? (allowPrivateAddress ? openDirectFetch : (url) => openPublicFetch(url, { signal }));
|
|
105
130
|
let opened = false;
|
|
106
131
|
async function openHop(url) {
|
|
107
132
|
let session;
|
|
108
133
|
try {
|
|
109
|
-
|
|
134
|
+
signal.throwIfAborted();
|
|
135
|
+
const opening = openUnvalidatedHop(url);
|
|
136
|
+
opening.then((lateSession) => {
|
|
137
|
+
if (signal.aborted) closeAfterError(lateSession, logger);
|
|
138
|
+
}, () => {});
|
|
139
|
+
session = await raceWithAbort(opening, signal);
|
|
140
|
+
if (signal.aborted) {
|
|
141
|
+
closeAfterError(session, logger);
|
|
142
|
+
signal.throwIfAborted();
|
|
143
|
+
}
|
|
110
144
|
} catch (error) {
|
|
111
145
|
if (error instanceof UrlError && error.reason === "dns") {
|
|
112
146
|
logger.error("DNS resolution failed for URL: {url}", {
|
|
@@ -132,7 +166,8 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
132
166
|
method: "POST",
|
|
133
167
|
headers,
|
|
134
168
|
body: JSON.stringify(activity),
|
|
135
|
-
redirect: "manual"
|
|
169
|
+
redirect: "manual",
|
|
170
|
+
signal
|
|
136
171
|
});
|
|
137
172
|
let rsaKey = null;
|
|
138
173
|
for (const key of keys) if (key.privateKey.algorithm.name === "RSASSA-PKCS1-v1_5") {
|
|
@@ -147,18 +182,48 @@ async function sendActivityInternal({ activity, activityId, keys, inbox, allowPr
|
|
|
147
182
|
}))
|
|
148
183
|
});
|
|
149
184
|
let outcome;
|
|
185
|
+
const boundedSpecDeterminer = specDeterminer == null ? void 0 : {
|
|
186
|
+
determineSpec(origin) {
|
|
187
|
+
signal.throwIfAborted();
|
|
188
|
+
return raceWithAbort(Promise.resolve(specDeterminer.determineSpec(origin)), signal);
|
|
189
|
+
},
|
|
190
|
+
rememberSpec(origin, spec) {
|
|
191
|
+
if (signal.aborted) return;
|
|
192
|
+
try {
|
|
193
|
+
Promise.resolve(specDeterminer.rememberSpec(origin, spec)).catch((error) => logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
194
|
+
origin,
|
|
195
|
+
error
|
|
196
|
+
}));
|
|
197
|
+
} catch (error) {
|
|
198
|
+
logger.debug("Failed to remember the signature spec for {origin}: {error}", {
|
|
199
|
+
origin,
|
|
200
|
+
error
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
};
|
|
205
|
+
const timer = setTimeout(() => controller.abort(new DOMException("The delivery timed out.", "TimeoutError")), timeoutMs);
|
|
150
206
|
try {
|
|
151
|
-
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox)) : await doubleKnockScoped(request, rsaKey, {
|
|
207
|
+
outcome = rsaKey == null ? await fetchWithValidatedRedirects(request, openHop, (response) => consumeSendActivityResponse(response, inbox, signal), signal) : await doubleKnockScoped(request, rsaKey, {
|
|
152
208
|
tracerProvider,
|
|
153
|
-
specDeterminer
|
|
154
|
-
|
|
209
|
+
specDeterminer: boundedSpecDeterminer,
|
|
210
|
+
signal
|
|
211
|
+
}, openHop, (response) => consumeSendActivityResponse(response, inbox, signal));
|
|
155
212
|
} catch (error) {
|
|
156
|
-
|
|
213
|
+
let failureError = error;
|
|
214
|
+
if (signal.aborted && !(error instanceof SendActivityError)) {
|
|
215
|
+
const failure = new FetchError(inbox.href, `Timed out after ${timeoutMs} ms`);
|
|
216
|
+
failure.cause = signal.reason;
|
|
217
|
+
failureError = failure;
|
|
218
|
+
}
|
|
219
|
+
if (opened || signal.aborted) logger.error("Failed to send activity {activityId} to {inbox}:\n{error}", {
|
|
157
220
|
activityId,
|
|
158
221
|
inbox: inbox.href,
|
|
159
|
-
error
|
|
222
|
+
error: failureError
|
|
160
223
|
});
|
|
161
|
-
throw
|
|
224
|
+
throw failureError;
|
|
225
|
+
} finally {
|
|
226
|
+
clearTimeout(timer);
|
|
162
227
|
}
|
|
163
228
|
if (!outcome.ok) {
|
|
164
229
|
const { status, statusText, error } = outcome;
|
|
@@ -200,17 +265,18 @@ function cancelResponseBody(response, url) {
|
|
|
200
265
|
* session is open: the body of a successful response is cancelled, and at
|
|
201
266
|
* most 1 KiB of an error response body is read.
|
|
202
267
|
*/
|
|
203
|
-
async function consumeSendActivityResponse(response, inbox) {
|
|
268
|
+
async function consumeSendActivityResponse(response, inbox, signal) {
|
|
204
269
|
if (response.ok) {
|
|
205
270
|
cancelResponseBody(response, response.url || inbox.href);
|
|
206
271
|
return { ok: true };
|
|
207
272
|
}
|
|
208
273
|
let error;
|
|
209
274
|
try {
|
|
210
|
-
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES);
|
|
275
|
+
error = await readLimitedResponseBody(response, MAX_ERROR_RESPONSE_BODY_BYTES, signal);
|
|
211
276
|
} catch (_) {
|
|
212
277
|
error = "";
|
|
213
278
|
}
|
|
279
|
+
if (signal.aborted) error = "(timed out reading response body)";
|
|
214
280
|
return {
|
|
215
281
|
ok: false,
|
|
216
282
|
status: response.status,
|
|
@@ -229,7 +295,7 @@ async function consumeSendActivityResponse(response, inbox) {
|
|
|
229
295
|
* @param consume The function to consume the final response.
|
|
230
296
|
* @returns The value returned by `consume`.
|
|
231
297
|
*/
|
|
232
|
-
async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
298
|
+
async function fetchWithValidatedRedirects(request, openHop, consume, signal) {
|
|
233
299
|
const logger = getLogger([
|
|
234
300
|
"fedify",
|
|
235
301
|
"federation",
|
|
@@ -237,10 +303,14 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
237
303
|
]);
|
|
238
304
|
let body = await request.clone().text();
|
|
239
305
|
for (let redirects = 0;; redirects++) {
|
|
306
|
+
signal?.throwIfAborted();
|
|
240
307
|
const session = await openHop(request.url);
|
|
241
308
|
let response;
|
|
242
309
|
try {
|
|
243
|
-
response = await session.fetch(request, {
|
|
310
|
+
response = await session.fetch(request, {
|
|
311
|
+
redirect: "manual",
|
|
312
|
+
signal
|
|
313
|
+
});
|
|
244
314
|
} catch (error) {
|
|
245
315
|
await closeAfterError(session, logger);
|
|
246
316
|
throw error;
|
|
@@ -290,7 +360,8 @@ async function fetchWithValidatedRedirects(request, openHop, consume) {
|
|
|
290
360
|
method,
|
|
291
361
|
headers,
|
|
292
362
|
body,
|
|
293
|
-
redirect: "manual"
|
|
363
|
+
redirect: "manual",
|
|
364
|
+
signal: signal ?? request.signal
|
|
294
365
|
});
|
|
295
366
|
}
|
|
296
367
|
}
|
package/dist/sig/http.test.mjs
CHANGED
|
@@ -7,8 +7,8 @@ import { r as assertExists, t as assertStringIncludes } from "../std__assert-DNZ
|
|
|
7
7
|
import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
|
|
8
8
|
import { t as assert } from "../assert-BhQd8QHP.mjs";
|
|
9
9
|
import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
|
|
10
|
-
import { t as exportJwk } from "../key-
|
|
11
|
-
import { a as formatRfc9421SignatureParameters, c as signRequest, d as verifyRequestDetailed, i as formatRfc9421Signature, l as timingSafeEqual, n as doubleKnock, o as parseRfc9421Signature, r as doubleKnockScoped, s as parseRfc9421SignatureInput, t as createRfc9421SignatureBase, u as verifyRequest } from "../http-
|
|
10
|
+
import { t as exportJwk } from "../key-Bhc8cQC7.mjs";
|
|
11
|
+
import { a as formatRfc9421SignatureParameters, c as signRequest, d as verifyRequestDetailed, i as formatRfc9421Signature, l as timingSafeEqual, n as doubleKnock, o as parseRfc9421Signature, r as doubleKnockScoped, s as parseRfc9421SignatureInput, t as createRfc9421SignatureBase, u as verifyRequest } from "../http-B3wCvgu8.mjs";
|
|
12
12
|
import { i as rsaPrivateKey2, l as rsaPublicKey5, o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-BAK-tUlf.mjs";
|
|
13
13
|
import { t as KvKeyCache } from "../keycache-BimEQucx.mjs";
|
|
14
14
|
import { t as MemoryKvStore } from "../kv-mI4Ix2EU.mjs";
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import { URLPattern } from "urlpattern-polyfill";
|
|
3
|
+
import { c as InboxListenerSetters, d as signRequest, f as exportJwk, l as SenderKeyPair, n as Context, o as ActorCallbackSetters, r as InboxContext, t as ActorKeyPairsDispatcher, u as HttpMessageSignaturesSpecDeterminer } from "../callback-0KrwzutD.mjs";
|
|
4
|
+
import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, Recipient } from "@fedify/vocab";
|
|
5
|
+
import { TracerProvider } from "@opentelemetry/api";
|
|
6
|
+
import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, DocumentLoaderFactoryOptions, exportMultibaseKey, exportSpki } from "@fedify/vocab-runtime";
|
|
7
|
+
|
|
8
|
+
//#region src/utils/docloader.d.ts
|
|
9
|
+
/**
|
|
10
|
+
* Options for {@link getAuthenticatedDocumentLoader}.
|
|
11
|
+
* @see {@link getAuthenticatedDocumentLoader}
|
|
12
|
+
* @since 1.3.0
|
|
13
|
+
*/
|
|
14
|
+
interface GetAuthenticatedDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
|
|
15
|
+
/**
|
|
16
|
+
* An optional spec determiner for HTTP Message Signatures.
|
|
17
|
+
* It determines the spec to use for signing requests.
|
|
18
|
+
* It is used for double-knocking
|
|
19
|
+
* (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
|
|
20
|
+
* @since 1.6.0
|
|
21
|
+
*/
|
|
22
|
+
specDeterminer?: HttpMessageSignaturesSpecDeterminer;
|
|
23
|
+
/**
|
|
24
|
+
* The OpenTelemetry tracer provider. If omitted, the global tracer provider
|
|
25
|
+
* is used.
|
|
26
|
+
* @since 1.6.0
|
|
27
|
+
*/
|
|
28
|
+
tracerProvider?: TracerProvider;
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Gets an authenticated {@link DocumentLoader} for the given identity.
|
|
32
|
+
* Note that an authenticated document loader intentionally does not cache
|
|
33
|
+
* the fetched documents.
|
|
34
|
+
* At most 20 HTTP redirects and alternate document links are followed in total
|
|
35
|
+
* per call. Revisiting a URL within that chain throws a {@link FetchError}.
|
|
36
|
+
* @param identity The identity to get the document loader for.
|
|
37
|
+
* The actor's key pair.
|
|
38
|
+
* @param options The options for the document loader.
|
|
39
|
+
* @returns The authenticated document loader.
|
|
40
|
+
* @throws {TypeError} If the key is invalid or unsupported.
|
|
41
|
+
* @since 0.4.0
|
|
42
|
+
*/
|
|
43
|
+
declare function getAuthenticatedDocumentLoader(identity: {
|
|
44
|
+
keyId: URL;
|
|
45
|
+
privateKey: CryptoKeyLike;
|
|
46
|
+
}, options?: GetAuthenticatedDocumentLoaderOptions): DocumentLoader;
|
|
47
|
+
//#endregion
|
|
48
|
+
//#region src/sig/ld.d.ts
|
|
49
|
+
/**
|
|
50
|
+
* A signature of a JSON-LD document.
|
|
51
|
+
* @since 1.0.0
|
|
52
|
+
*/
|
|
53
|
+
interface Signature {
|
|
54
|
+
"@context"?: "https://w3id.org/identity/v1" | "https://w3id.org/security/v1";
|
|
55
|
+
type: "RsaSignature2017";
|
|
56
|
+
id?: string;
|
|
57
|
+
creator: string;
|
|
58
|
+
created: string;
|
|
59
|
+
signatureValue: string;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Options for creating Linked Data Signatures.
|
|
63
|
+
* @since 1.0.0
|
|
64
|
+
*/
|
|
65
|
+
interface CreateSignatureOptions {
|
|
66
|
+
/**
|
|
67
|
+
* The context loader for loading remote JSON-LD contexts.
|
|
68
|
+
*/
|
|
69
|
+
contextLoader?: DocumentLoader;
|
|
70
|
+
/**
|
|
71
|
+
* The time when the signature was created. If not specified, the current
|
|
72
|
+
* time will be used.
|
|
73
|
+
*/
|
|
74
|
+
created?: Temporal.Instant;
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Creates a LD signature for the given JSON-LD document.
|
|
78
|
+
*
|
|
79
|
+
* If the document's context does not define the `signature` property, the
|
|
80
|
+
* signature is computed over the document with a minimal inline definition
|
|
81
|
+
* added. Use {@link attachSignature} to attach the signature to that exact
|
|
82
|
+
* document. Documents that already carry a `proof`, or whose context includes
|
|
83
|
+
* an unrecognized remote context, are hashed unchanged.
|
|
84
|
+
* @param jsonLd The JSON-LD document to sign.
|
|
85
|
+
* @param privateKey The private key to sign the document.
|
|
86
|
+
* @param keyId The ID of the public key that corresponds to the private key.
|
|
87
|
+
* @param options Additional options for creating the signature.
|
|
88
|
+
* See also {@link CreateSignatureOptions}.
|
|
89
|
+
* @return The created signature.
|
|
90
|
+
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
91
|
+
* @since 1.0.0
|
|
92
|
+
*/
|
|
93
|
+
declare function createSignature(jsonLd: unknown, privateKey: CryptoKeyLike, keyId: URL, {
|
|
94
|
+
contextLoader,
|
|
95
|
+
created
|
|
96
|
+
}?: CreateSignatureOptions): Promise<Signature>;
|
|
97
|
+
/**
|
|
98
|
+
* Options for signing JSON-LD documents.
|
|
99
|
+
* @since 1.0.0
|
|
100
|
+
*/
|
|
101
|
+
interface SignJsonLdOptions extends CreateSignatureOptions {
|
|
102
|
+
/**
|
|
103
|
+
* The OpenTelemetry tracer provider for tracing the signing process.
|
|
104
|
+
* If omitted, the global tracer provider is used.
|
|
105
|
+
* @since 1.3.0
|
|
106
|
+
*/
|
|
107
|
+
tracerProvider?: TracerProvider;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Signs the given JSON-LD document with the private key and returns the signed
|
|
111
|
+
* JSON-LD document.
|
|
112
|
+
* @param jsonLd The JSON-LD document to sign.
|
|
113
|
+
* @param privateKey The private key to sign the document.
|
|
114
|
+
* @param keyId The key ID to use in the signature. It will be used by the
|
|
115
|
+
* verifier to fetch the corresponding public key.
|
|
116
|
+
* @param options Additional options for signing the document.
|
|
117
|
+
* See also {@link SignJsonLdOptions}.
|
|
118
|
+
* @returns The signed JSON-LD document.
|
|
119
|
+
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
120
|
+
* @since 1.0.0
|
|
121
|
+
*/
|
|
122
|
+
declare function signJsonLd(jsonLd: unknown, privateKey: CryptoKeyLike, keyId: URL, options: SignJsonLdOptions): Promise<{
|
|
123
|
+
signature: Signature;
|
|
124
|
+
}>;
|
|
125
|
+
//#endregion
|
|
126
|
+
//#region src/sig/proof.d.ts
|
|
127
|
+
/**
|
|
128
|
+
* Options for {@link createProof}.
|
|
129
|
+
* @since 0.10.0
|
|
130
|
+
*/
|
|
131
|
+
interface CreateProofOptions {
|
|
132
|
+
/**
|
|
133
|
+
* The context loader for loading remote JSON-LD contexts.
|
|
134
|
+
*/
|
|
135
|
+
contextLoader?: DocumentLoader;
|
|
136
|
+
/**
|
|
137
|
+
* The JSON-LD context to use for serializing the object to sign.
|
|
138
|
+
*/
|
|
139
|
+
context?: string | Record<string, string> | (string | Record<string, string>)[];
|
|
140
|
+
/**
|
|
141
|
+
* The time when the proof was created. If not specified, the current time
|
|
142
|
+
* will be used.
|
|
143
|
+
*/
|
|
144
|
+
created?: Temporal.Instant;
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
* Creates a proof for the given object.
|
|
148
|
+
* @param object The object to create a proof for.
|
|
149
|
+
* @param privateKey The private key to sign the proof with.
|
|
150
|
+
* @param keyId The key ID to use in the proof. It will be used by the verifier.
|
|
151
|
+
* @param options Additional options. See also {@link CreateProofOptions}.
|
|
152
|
+
* @returns The created proof.
|
|
153
|
+
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
154
|
+
* @since 0.10.0
|
|
155
|
+
*/
|
|
156
|
+
declare function createProof(object: Object$1, privateKey: CryptoKeyLike, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
|
|
157
|
+
/**
|
|
158
|
+
* Options for {@link signObject}.
|
|
159
|
+
* @since 0.10.0
|
|
160
|
+
*/
|
|
161
|
+
interface SignObjectOptions extends CreateProofOptions {
|
|
162
|
+
/**
|
|
163
|
+
* The document loader for loading remote JSON-LD documents.
|
|
164
|
+
*/
|
|
165
|
+
documentLoader?: DocumentLoader;
|
|
166
|
+
/**
|
|
167
|
+
* The OpenTelemetry tracer provider. If omitted, the global tracer provider
|
|
168
|
+
* is used.
|
|
169
|
+
* @since 1.3.0
|
|
170
|
+
*/
|
|
171
|
+
tracerProvider?: TracerProvider;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Signs the given object with the private key and returns the signed object.
|
|
175
|
+
* @param object The object to create a proof for.
|
|
176
|
+
* @param privateKey The private key to sign the proof with.
|
|
177
|
+
* @param keyId The key ID to use in the proof. It will be used by the verifier.
|
|
178
|
+
* @param options Additional options. See also {@link SignObjectOptions}.
|
|
179
|
+
* @returns The signed object.
|
|
180
|
+
* @throws {TypeError} If the private key is invalid or unsupported.
|
|
181
|
+
* @since 0.10.0
|
|
182
|
+
*/
|
|
183
|
+
declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKeyLike, keyId: URL, options?: SignObjectOptions): Promise<T>;
|
|
184
|
+
//#endregion
|
|
185
|
+
//#region src/sig/key-types.test.d.ts
|
|
186
|
+
/**
|
|
187
|
+
* Asserts at compile time that `T` is assignable to `U`.
|
|
188
|
+
*/
|
|
189
|
+
type AssertAssignable<T extends U, U> = T;
|
|
190
|
+
/**
|
|
191
|
+
* The key usages Node.js adds on top of the DOM and Web Worker ones since
|
|
192
|
+
* Node.js 24.7, when ML-KEM support was added to its Web Crypto API.
|
|
193
|
+
*/
|
|
194
|
+
type NodeKeyUsage = KeyUsage | "encapsulateBits" | "decapsulateBits" | "encapsulateKey" | "decapsulateKey";
|
|
195
|
+
/**
|
|
196
|
+
* Mirrors `import("node:crypto").webcrypto.CryptoKey`, whose `usages` array
|
|
197
|
+
* has a wider element type than the ambient `CryptoKey`.
|
|
198
|
+
*/
|
|
199
|
+
interface NodeCryptoKey extends Omit<CryptoKey, "usages"> {
|
|
200
|
+
readonly usages: NodeKeyUsage[];
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Mirrors `import("node:crypto").webcrypto.CryptoKeyPair`.
|
|
204
|
+
*/
|
|
205
|
+
interface NodeCryptoKeyPair {
|
|
206
|
+
readonly privateKey: NodeCryptoKey;
|
|
207
|
+
readonly publicKey: NodeCryptoKey;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* These are compile-time assertions. A regression in any of the public
|
|
211
|
+
* signatures fails `deno check` even though nothing here runs.
|
|
212
|
+
*/
|
|
213
|
+
type NodeKeyTypeChecks = [AssertAssignable<NodeCryptoKey, CryptoKeyLike>, AssertAssignable<NodeCryptoKeyPair, CryptoKeyPairLike>, AssertAssignable<(context: Context<void>, identifier: string) => NodeCryptoKeyPair[] | Promise<NodeCryptoKeyPair[]>, ActorKeyPairsDispatcher<void, CryptoKeyPairLike>>, AssertAssignable<ActorKeyPairsDispatcher<void, CryptoKeyPairLike>, Parameters<ActorCallbackSetters<void>["setKeyPairsDispatcher"]>[0]>, AssertAssignable<SenderKeyPair["privateKey"], CryptoKey>, AssertAssignable<NodeCryptoKey, SenderKeyPair<CryptoKeyLike>["privateKey"]>, AssertAssignable<(context: Context<void>) => SenderKeyPair<CryptoKeyLike>, Parameters<InboxListenerSetters<void>["setSharedKeyDispatcher"]>[0]>, AssertAssignable<Parameters<AuthenticatedDocumentLoaderFactory>[0]["privateKey"], CryptoKey>, AssertAssignable<NodeCryptoKey, Parameters<typeof getAuthenticatedDocumentLoader>[0]["privateKey"]>, AssertAssignable<NodeCryptoKey, Parameters<typeof signRequest>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof createProof>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof signObject>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof createSignature>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof signJsonLd>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof exportJwk>[0]>, AssertAssignable<NodeCryptoKey, Parameters<typeof exportSpki>[0]>, AssertAssignable<NodeCryptoKey, Parameters<typeof exportMultibaseKey>[0]>, AssertAssignable<NodeCryptoKey, NonNullable<ConstructorParameters<typeof CryptographicKey>[0]["publicKey"]>>, AssertAssignable<NodeCryptoKey, NonNullable<ConstructorParameters<typeof Multikey>[0]["publicKey"]>>, AssertAssignable<NodeCryptoKey, NonNullable<NonNullable<Parameters<CryptographicKey["clone"]>[0]>["publicKey"]>>, AssertAssignable<NodeCryptoKey, NonNullable<NonNullable<Parameters<Multikey["clone"]>[0]>["publicKey"]>>, AssertAssignable<Context<void>["getDocumentLoader"], (identity: {
|
|
214
|
+
keyId: URL;
|
|
215
|
+
privateKey: NodeCryptoKey;
|
|
216
|
+
}) => unknown>, AssertAssignable<Context<void>["sendActivity"], (sender: SenderKeyPair<NodeCryptoKey>, recipients: Recipient, activity: Activity) => Promise<void>>, AssertAssignable<InboxContext<void>["forwardActivity"], (forwarder: SenderKeyPair<NodeCryptoKey>, recipients: Recipient) => Promise<void>>];
|
|
217
|
+
//#endregion
|
|
218
|
+
export { NodeKeyTypeChecks };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { test } from "@fedify/fixture";
|
|
5
|
+
//#region src/sig/key-types.test.ts
|
|
6
|
+
test("Node.js Web Crypto keys are accepted by the public key types", () => {});
|
|
7
|
+
//#endregion
|
|
8
|
+
export {};
|
package/dist/sig/key.test.mjs
CHANGED
|
@@ -7,9 +7,9 @@ import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.m
|
|
|
7
7
|
import { t as assert } from "../assert-BhQd8QHP.mjs";
|
|
8
8
|
import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
|
|
9
9
|
import { t as assertStrictEquals } from "../assert_strict_equals-Dmjbg-bA.mjs";
|
|
10
|
-
import { a as generateCryptoKeyPair, i as fetchKeyDetailed, o as importJwk, r as fetchKey, s as validateCryptoKey, t as exportJwk } from "../key-
|
|
10
|
+
import { a as generateCryptoKeyPair, i as fetchKeyDetailed, o as importJwk, r as fetchKey, s as validateCryptoKey, t as exportJwk } from "../key-Bhc8cQC7.mjs";
|
|
11
11
|
import { c as rsaPublicKey3, i as rsaPrivateKey2, o as rsaPublicKey1, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-BAK-tUlf.mjs";
|
|
12
|
-
import {
|
|
12
|
+
import { y as wrapContextLoaderForJsonLd } from "../ld-DTeykI0e.mjs";
|
|
13
13
|
import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
14
14
|
import { CryptographicKey, Multikey, Person } from "@fedify/vocab";
|
|
15
15
|
import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
|