@fedify/fedify 2.1.1 → 2.1.3
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/{accept-D7sAxyNa.js → accept-Dd__NiUL.mjs} +10 -8
- package/dist/{assert-MZs1qjMx.js → assert-ddO5KLpe.mjs} +5 -9
- package/dist/{assert_equals-DSbWqCm3.js → assert_equals-Ew3jOFa3.mjs} +55 -69
- package/dist/{assert_instance_of-DHz7EHNU.js → assert_instance_of-C4Ri6VuN.mjs} +5 -9
- package/dist/{assert_not_equals-f3m3epl3.js → assert_not_equals--wG9hV7u.mjs} +6 -13
- package/dist/{assert_rejects-0h7I2Esa.js → assert_rejects-B-qJtC9Z.mjs} +6 -11
- package/dist/{assert_throws-rjdMBf31.js → assert_throws-4NwKEy2q.mjs} +5 -10
- package/dist/{builder-DbKYZdSy.js → builder-BKo51w-F.mjs} +32 -41
- package/dist/{chunk-CGaQZ11T.cjs → chunk-DDcVe30Y.cjs} +23 -24
- package/dist/{chunk-DJNbSFdH.js → chunk-nlSIicah.js} +8 -8
- package/dist/{client-BxMZiQaD.d.ts → client-AtlibPOU.d.ts} +1 -1
- package/dist/{client-CoCIaTNO.js → client-DEpOVgY1.mjs} +9 -13
- package/dist/{client-C97KOq3x.d.cts → client-z-8dc-e1.d.cts} +1 -1
- package/dist/{collection-CSzG2j1P.js → collection-BD6-SZ6O.mjs} +7 -12
- package/dist/compat/mod.cjs +5 -8
- package/dist/compat/mod.d.cts +78 -6
- package/dist/compat/mod.d.ts +78 -6
- package/dist/compat/mod.js +4 -8
- package/dist/compat/transformers.test.mjs +62 -0
- package/dist/{context-DyJjQQ_H.d.ts → context-BOiMZBu5.d.ts} +9 -18
- package/dist/{context-BcqA-0BL.d.cts → context-BhZVy7RB.d.cts} +9 -18
- package/dist/{context-Aqenou7c.js → context-Juj6bdHC.mjs} +7 -11
- package/dist/deno-D5r_9RvZ.mjs +8 -0
- package/dist/{docloader-Ck0SCLXX.js → docloader-B9CXCw8i.mjs} +8 -14
- package/dist/{esm-nLm00z9V.js → esm-DVILvP5e.mjs} +50 -89
- package/dist/federation/builder.test.d.mts +2 -0
- package/dist/federation/{builder.test.js → builder.test.mjs} +21 -44
- package/dist/federation/collection.test.d.mts +2 -0
- package/dist/federation/collection.test.mjs +21 -0
- package/dist/federation/handler.test.d.mts +2 -0
- package/dist/federation/{handler.test.js → handler.test.mjs} +69 -131
- package/dist/federation/idempotency.test.d.mts +2 -0
- package/dist/federation/{idempotency.test.js → idempotency.test.mjs} +31 -63
- package/dist/federation/inbox.test.d.mts +2 -0
- package/dist/federation/{inbox.test.js → inbox.test.mjs} +8 -12
- package/dist/federation/keycache.test.d.mts +2 -0
- package/dist/federation/{keycache.test.js → keycache.test.mjs} +13 -19
- package/dist/federation/kv.test.d.mts +2 -0
- package/dist/federation/{kv.test.js → kv.test.mjs} +11 -22
- package/dist/federation/middleware.test.d.mts +2 -0
- package/dist/federation/{middleware.test.js → middleware.test.mjs} +173 -262
- package/dist/federation/mod.cjs +327 -16
- package/dist/federation/mod.d.cts +3 -6
- package/dist/federation/mod.d.ts +3 -6
- package/dist/federation/mod.js +322 -13
- package/dist/federation/mq.test.d.mts +2 -0
- package/dist/federation/{mq.test.js → mq.test.mjs} +21 -35
- package/dist/federation/negotiation.test.d.mts +2 -0
- package/dist/federation/{negotiation.test.js → negotiation.test.mjs} +9 -16
- package/dist/federation/retry.test.d.mts +2 -0
- package/dist/federation/{retry.test.js → retry.test.mjs} +8 -11
- package/dist/federation/router.test.d.mts +2 -0
- package/dist/federation/{router.test.js → router.test.mjs} +11 -16
- package/dist/federation/send.test.d.mts +2 -0
- package/dist/federation/{send.test.js → send.test.mjs} +22 -30
- package/dist/federation/webfinger.test.d.mts +2 -0
- package/dist/federation/{webfinger.test.js → webfinger.test.mjs} +22 -56
- package/dist/{http-DFzT4YFG.js → http-B53alCGi.mjs} +23 -43
- package/dist/{http-ca2xny58.cjs → http-BngkmEhl.cjs} +177 -302
- package/dist/{http-BudnHZE2.d.cts → http-CrGuipxe.d.cts} +1 -6
- package/dist/{http-EUQ6crVa.js → http-PS3wuU8D.js} +53 -184
- package/dist/{http-Dax_FIBo.d.ts → http-aQzN9Ayi.d.ts} +1 -6
- package/dist/{inbox-BMLz_-pL.js → inbox-CHsLu5ai.mjs} +18 -26
- package/dist/{key-CypuWa94.js → key-D9Np_ZXl.mjs} +29 -37
- package/dist/{keycache-CpGWAUbj.js → keycache-CCSwkQcY.mjs} +5 -10
- package/dist/{keys-BFve7QQv.js → keys-BAK-tUlf.mjs} +5 -9
- package/dist/{kv-BL4nlICN.d.cts → kv-CbLNp3zQ.d.cts} +1 -1
- package/dist/{kv-DXEUEP6z.d.ts → kv-GFYnFoOl.d.ts} +1 -1
- package/dist/{kv-cache-Bw2F2ABq.js → kv-cache-B01V7s3h.mjs} +4 -8
- package/dist/{kv-cache-SKgbvvu4.js → kv-cache-B2Qi5MGv.js} +6 -13
- package/dist/{kv-cache-BBJFLMW5.cjs → kv-cache-YCtINZK4.cjs} +27 -34
- package/dist/{kv-QzKcOQgP.js → kv-tL2TOE9X.mjs} +6 -10
- package/dist/{ld-CXLtTc0G.js → ld-BaxRFhDd.mjs} +17 -31
- package/dist/{middleware-CL6XaAFy.cjs → middleware-Bsv-7iX7.cjs} +532 -587
- package/dist/middleware-C37OmOz_.mjs +5 -0
- package/dist/middleware-CelV2xrI.cjs +4 -0
- package/dist/{middleware-CvS6hWm3.js → middleware-Dn1kk96N.js} +335 -382
- package/dist/{middleware-BHJ0xm0L.js → middleware-dFn6ozt5.mjs} +282 -317
- package/dist/{mod-Bx9jcLB8.d.cts → mod-B505FZBC.d.cts} +3 -3
- package/dist/{mod-em2Il1eD.d.cts → mod-Bp_CzKd4.d.cts} +2 -2
- package/dist/{mod-Cs2dYEwI.d.ts → mod-D7PAuO6k.d.ts} +3 -3
- package/dist/{mod-D6MdymW7.d.ts → mod-DKOAow7a.d.ts} +2 -2
- package/dist/{mod-Coe7KEgX.d.cts → mod-DoJBjjnO.d.cts} +2 -2
- package/dist/{mod-D6dOd--H.d.ts → mod-DvxszxXC.d.ts} +2 -2
- package/dist/mod.cjs +29 -74
- package/dist/mod.d.cts +11 -14
- package/dist/mod.d.ts +11 -15
- package/dist/mod.js +17 -71
- package/dist/{negotiation-BlAuS_nr.js → negotiation-DnsfFF8I.mjs} +7 -11
- package/dist/nodeinfo/client.test.d.mts +2 -0
- package/dist/nodeinfo/{client.test.js → client.test.mjs} +22 -40
- package/dist/nodeinfo/handler.test.d.mts +2 -0
- package/dist/nodeinfo/{handler.test.js → handler.test.mjs} +13 -43
- package/dist/nodeinfo/mod.cjs +5 -8
- package/dist/nodeinfo/mod.d.cts +2 -3
- package/dist/nodeinfo/mod.d.ts +2 -3
- package/dist/nodeinfo/mod.js +4 -8
- package/dist/nodeinfo/types.test.d.mts +2 -0
- package/dist/nodeinfo/{types.test.js → types.test.mjs} +9 -16
- package/dist/otel/exporter.test.d.mts +2 -0
- package/dist/otel/{exporter.test.js → exporter.test.mjs} +124 -178
- package/dist/otel/mod.cjs +15 -20
- package/dist/otel/mod.d.cts +2 -2
- package/dist/otel/mod.d.ts +2 -2
- package/dist/otel/mod.js +8 -14
- package/dist/{owner-gd0Q9FuU.d.ts → owner-74ARJ5TL.d.ts} +1 -1
- package/dist/{owner-1AbPBOOZ.d.cts → owner-CptqhsOy.d.cts} +1 -1
- package/dist/{owner-CwMai3jn.js → owner-dxM51u36.mjs} +11 -16
- package/dist/{proof-ZuJBOUoi.js → proof-CH5U0k7G.mjs} +21 -33
- package/dist/{proof-sCID81Ua.cjs → proof-D39qiki3.cjs} +133 -157
- package/dist/{proof-6Zw1FW7t.js → proof-Dpgqx9RS.js} +32 -58
- package/dist/{retry-mqLf4b-R.js → retry-B_E3V_Dx.mjs} +4 -7
- package/dist/{router-D9eI0s4b.js → router-CrMLXoOr.mjs} +4 -8
- package/dist/runtime/mod.cjs +11 -13
- package/dist/runtime/mod.d.cts +6 -2
- package/dist/runtime/mod.d.ts +0 -1
- package/dist/runtime/mod.js +4 -7
- package/dist/{send-BW73dy6Q.js → send-D1-4ZnQq.mjs} +8 -13
- package/dist/sig/accept.test.d.mts +2 -0
- package/dist/sig/{accept.test.js → accept.test.mjs} +35 -70
- package/dist/sig/http.test.d.mts +2 -0
- package/dist/sig/{http.test.js → http.test.mjs} +166 -280
- package/dist/sig/key.test.d.mts +2 -0
- package/dist/sig/{key.test.js → key.test.mjs} +11 -18
- package/dist/sig/ld.test.d.mts +2 -0
- package/dist/sig/{ld.test.js → ld.test.mjs} +22 -35
- package/dist/sig/mod.cjs +6 -9
- package/dist/sig/mod.d.cts +3 -3
- package/dist/sig/mod.d.ts +3 -3
- package/dist/sig/mod.js +5 -9
- package/dist/sig/owner.test.d.mts +2 -0
- package/dist/sig/{owner.test.js → owner.test.mjs} +19 -34
- package/dist/sig/proof.test.d.mts +2 -0
- package/dist/sig/{proof.test.js → proof.test.mjs} +16 -27
- package/dist/{std__assert-X-_kMxKM.js → std__assert-Duiq_YC9.mjs} +12 -24
- package/dist/testing/{mod.d.ts → mod.d.mts} +26 -90
- package/dist/testing/mod.mjs +6 -0
- package/dist/{transformers-3g8GZwkZ.cjs → transformers-NeAONrAq.cjs} +20 -25
- package/dist/{transformers-C3FLHUd6.js → transformers-ve6e2xcg.js} +3 -7
- package/dist/{types-CPz01LGH.js → types-DCP0WLdt.mjs} +4 -7
- package/dist/{types-Cd_hszr_.cjs → types-KC4QAoxe.cjs} +29 -34
- package/dist/{types-C93Ob9cU.js → types-hvL8ElAs.js} +8 -13
- package/dist/utils/docloader.test.d.mts +2 -0
- package/dist/utils/{docloader.test.js → docloader.test.mjs} +14 -25
- package/dist/utils/kv-cache.test.d.mts +2 -0
- package/dist/utils/{kv-cache.test.js → kv-cache.test.mjs} +25 -40
- package/dist/utils/mod.cjs +5 -9
- package/dist/utils/mod.d.cts +1 -3
- package/dist/utils/mod.d.ts +1 -3
- package/dist/utils/mod.js +4 -9
- package/dist/vocab/cjs.test.d.mts +2 -0
- package/dist/vocab/cjs.test.mjs +14 -0
- package/dist/vocab/mod.cjs +10 -12
- package/dist/vocab/mod.js +3 -5
- package/package.json +8 -8
- package/dist/compat/transformers.test.d.ts +0 -3
- package/dist/compat/transformers.test.js +0 -88
- package/dist/compat-Bb4NuTUO.js +0 -4
- package/dist/compat-DmDDELst.cjs +0 -4
- package/dist/deno-DH972JvX.js +0 -121
- package/dist/federation/builder.test.d.ts +0 -3
- package/dist/federation/collection.test.d.ts +0 -3
- package/dist/federation/collection.test.js +0 -32
- package/dist/federation/handler.test.d.ts +0 -3
- package/dist/federation/idempotency.test.d.ts +0 -3
- package/dist/federation/inbox.test.d.ts +0 -3
- package/dist/federation/keycache.test.d.ts +0 -3
- package/dist/federation/kv.test.d.ts +0 -3
- package/dist/federation/middleware.test.d.ts +0 -3
- package/dist/federation/mq.test.d.ts +0 -3
- package/dist/federation/negotiation.test.d.ts +0 -3
- package/dist/federation/retry.test.d.ts +0 -3
- package/dist/federation/router.test.d.ts +0 -3
- package/dist/federation/send.test.d.ts +0 -3
- package/dist/federation/webfinger.test.d.ts +0 -3
- package/dist/federation-Bp3HI26G.cjs +0 -350
- package/dist/federation-DaMfqRm4.js +0 -332
- package/dist/middleware-B8FJuMM0.js +0 -27
- package/dist/middleware-BVp930fR.js +0 -12
- package/dist/middleware-BvGP-uXy.cjs +0 -12
- package/dist/mod-B7QkWzrL.d.cts +0 -80
- package/dist/mod-Bh8mqlYw.d.cts +0 -9
- package/dist/mod-D6HodEq7.d.ts +0 -7
- package/dist/mod-SMHOMNpZ.d.ts +0 -82
- package/dist/mod-gq_Xfdz8.d.cts +0 -1
- package/dist/nodeinfo/client.test.d.ts +0 -3
- package/dist/nodeinfo/handler.test.d.ts +0 -3
- package/dist/nodeinfo/types.test.d.ts +0 -3
- package/dist/nodeinfo-DoESQxq5.js +0 -4
- package/dist/nodeinfo-DuMYTpbZ.cjs +0 -4
- package/dist/otel/exporter.test.d.ts +0 -3
- package/dist/runtime-c2Njxsry.cjs +0 -17
- package/dist/runtime-poamPCMb.js +0 -13
- package/dist/sig/accept.test.d.ts +0 -3
- package/dist/sig/http.test.d.ts +0 -3
- package/dist/sig/key.test.d.ts +0 -3
- package/dist/sig/ld.test.d.ts +0 -3
- package/dist/sig/owner.test.d.ts +0 -3
- package/dist/sig/proof.test.d.ts +0 -3
- package/dist/sig-BNhspNOf.js +0 -4
- package/dist/sig-vX39WyWI.cjs +0 -4
- package/dist/testing/mod.js +0 -10
- package/dist/utils/docloader.test.d.ts +0 -3
- package/dist/utils/kv-cache.test.d.ts +0 -3
- package/dist/utils-BQ9KqEK9.cjs +0 -4
- package/dist/utils-Dn5OPdSW.js +0 -4
- /package/dist/{mod-AGjRfPjT.d.ts → compat/transformers.test.d.mts} +0 -0
|
@@ -1,51 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import
|
|
7
|
-
import "../
|
|
8
|
-
import "../
|
|
9
|
-
import { MemoryKvStore } from "../kv-QzKcOQgP.js";
|
|
10
|
-
import "../deno-DH972JvX.js";
|
|
11
|
-
import { createFederation, handleWebFinger } from "../middleware-BHJ0xm0L.js";
|
|
12
|
-
import "../client-CoCIaTNO.js";
|
|
13
|
-
import "../router-D9eI0s4b.js";
|
|
14
|
-
import "../types-CPz01LGH.js";
|
|
15
|
-
import "../accept-D7sAxyNa.js";
|
|
16
|
-
import "../key-CypuWa94.js";
|
|
17
|
-
import "../http-DFzT4YFG.js";
|
|
18
|
-
import "../ld-CXLtTc0G.js";
|
|
19
|
-
import "../owner-CwMai3jn.js";
|
|
20
|
-
import "../proof-ZuJBOUoi.js";
|
|
21
|
-
import "../docloader-Ck0SCLXX.js";
|
|
22
|
-
import "../kv-cache-Bw2F2ABq.js";
|
|
23
|
-
import "../inbox-BMLz_-pL.js";
|
|
24
|
-
import "../builder-DbKYZdSy.js";
|
|
25
|
-
import "../collection-CSzG2j1P.js";
|
|
26
|
-
import "../keycache-CpGWAUbj.js";
|
|
27
|
-
import "../negotiation-BlAuS_nr.js";
|
|
28
|
-
import "../retry-mqLf4b-R.js";
|
|
29
|
-
import "../send-BW73dy6Q.js";
|
|
30
|
-
import "../std__assert-X-_kMxKM.js";
|
|
31
|
-
import "../assert_rejects-0h7I2Esa.js";
|
|
32
|
-
import "../assert_throws-rjdMBf31.js";
|
|
33
|
-
import "../assert_not_equals-f3m3epl3.js";
|
|
34
|
-
import { createRequestContext } from "../context-Aqenou7c.js";
|
|
1
|
+
import "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { n as createRequestContext } from "../context-Juj6bdHC.mjs";
|
|
5
|
+
import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
|
|
6
|
+
import "../std__assert-Duiq_YC9.mjs";
|
|
7
|
+
import { t as MemoryKvStore } from "../kv-tL2TOE9X.mjs";
|
|
8
|
+
import { a as createFederation, o as handleWebFinger } from "../middleware-dFn6ozt5.mjs";
|
|
35
9
|
import { test } from "@fedify/fixture";
|
|
36
10
|
import { Image, Link, Person } from "@fedify/vocab";
|
|
37
|
-
|
|
38
11
|
//#region src/federation/webfinger.test.ts
|
|
39
12
|
test("handleWebFinger()", async (t) => {
|
|
40
13
|
const url = new URL("https://example.com/.well-known/webfinger");
|
|
41
|
-
function createContext(url
|
|
42
|
-
const federation = createFederation({ kv: new MemoryKvStore() });
|
|
14
|
+
function createContext(url) {
|
|
43
15
|
const context = createRequestContext({
|
|
44
|
-
federation,
|
|
45
|
-
url
|
|
16
|
+
federation: createFederation({ kv: new MemoryKvStore() }),
|
|
17
|
+
url,
|
|
46
18
|
data: void 0,
|
|
47
19
|
getActorUri(identifier) {
|
|
48
|
-
return new URL(`${url
|
|
20
|
+
return new URL(`${url.origin}/users/${identifier}`);
|
|
49
21
|
},
|
|
50
22
|
async getActor(handle) {
|
|
51
23
|
return await actorDispatcher(context, handle);
|
|
@@ -55,10 +27,9 @@ test("handleWebFinger()", async (t) => {
|
|
|
55
27
|
if (uri.protocol === "acct:") return null;
|
|
56
28
|
if (!uri.pathname.startsWith("/users/")) return null;
|
|
57
29
|
const paths = uri.pathname.split("/");
|
|
58
|
-
const identifier = paths[paths.length - 1];
|
|
59
30
|
return {
|
|
60
31
|
type: "actor",
|
|
61
|
-
identifier
|
|
32
|
+
identifier: paths[paths.length - 1]
|
|
62
33
|
};
|
|
63
34
|
}
|
|
64
35
|
});
|
|
@@ -90,11 +61,10 @@ test("handleWebFinger()", async (t) => {
|
|
|
90
61
|
await t.step("no actor dispatcher", async () => {
|
|
91
62
|
const context = createContext(url);
|
|
92
63
|
const request = context.request;
|
|
93
|
-
|
|
64
|
+
assertEquals((await handleWebFinger(request, {
|
|
94
65
|
context,
|
|
95
66
|
onNotFound
|
|
96
|
-
});
|
|
97
|
-
assertEquals(response.status, 404);
|
|
67
|
+
})).status, 404);
|
|
98
68
|
assertEquals(onNotFoundCalled, request);
|
|
99
69
|
});
|
|
100
70
|
onNotFoundCalled = null;
|
|
@@ -114,8 +84,7 @@ test("handleWebFinger()", async (t) => {
|
|
|
114
84
|
const u = new URL(url);
|
|
115
85
|
u.searchParams.set("resource", " invalid ");
|
|
116
86
|
const context = createContext(u);
|
|
117
|
-
const
|
|
118
|
-
const response = await handleWebFinger(request, {
|
|
87
|
+
const response = await handleWebFinger(new Request(u), {
|
|
119
88
|
context,
|
|
120
89
|
actorDispatcher,
|
|
121
90
|
onNotFound
|
|
@@ -221,12 +190,11 @@ test("handleWebFinger()", async (t) => {
|
|
|
221
190
|
u.searchParams.set("resource", "acct:no-one@example.com");
|
|
222
191
|
const context = createContext(u);
|
|
223
192
|
const request = context.request;
|
|
224
|
-
|
|
193
|
+
assertEquals((await handleWebFinger(request, {
|
|
225
194
|
context,
|
|
226
195
|
actorDispatcher,
|
|
227
196
|
onNotFound
|
|
228
|
-
});
|
|
229
|
-
assertEquals(response.status, 404);
|
|
197
|
+
})).status, 404);
|
|
230
198
|
assertEquals(onNotFoundCalled, request);
|
|
231
199
|
});
|
|
232
200
|
onNotFoundCalled = null;
|
|
@@ -522,16 +490,14 @@ test("handleWebFinger()", async (t) => {
|
|
|
522
490
|
onNotFound
|
|
523
491
|
});
|
|
524
492
|
assertEquals(response.status, 200);
|
|
525
|
-
|
|
526
|
-
const expectedWithCustomLinks = {
|
|
493
|
+
assertEquals(await response.json(), {
|
|
527
494
|
...expected,
|
|
528
495
|
links: [...expected.links, {
|
|
529
496
|
rel: "http://ostatus.org/schema/1.0/subscribe",
|
|
530
497
|
template: "https://example.com/follow?acct={uri}"
|
|
531
498
|
}]
|
|
532
|
-
};
|
|
533
|
-
assertEquals(result, expectedWithCustomLinks);
|
|
499
|
+
});
|
|
534
500
|
});
|
|
535
501
|
});
|
|
536
|
-
|
|
537
|
-
|
|
502
|
+
//#endregion
|
|
503
|
+
export {};
|
|
@@ -1,20 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
import {
|
|
7
|
-
import { fulfillAcceptSignature, parseAcceptSignature, validateAcceptSignature } from "./accept-D7sAxyNa.js";
|
|
8
|
-
import { fetchKeyDetailed, validateCryptoKey } from "./key-CypuWa94.js";
|
|
1
|
+
import { Temporal } from "@js-temporal/polyfill";
|
|
2
|
+
import "urlpattern-polyfill";
|
|
3
|
+
globalThis.addEventListener = () => {};
|
|
4
|
+
import { n as version, t as name } from "./deno-D5r_9RvZ.mjs";
|
|
5
|
+
import { i as validateAcceptSignature, n as fulfillAcceptSignature, r as parseAcceptSignature } from "./accept-Dd__NiUL.mjs";
|
|
6
|
+
import { o as validateCryptoKey, r as fetchKeyDetailed } from "./key-D9Np_ZXl.mjs";
|
|
9
7
|
import { CryptographicKey } from "@fedify/vocab";
|
|
8
|
+
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
10
9
|
import { FetchError } from "@fedify/vocab-runtime";
|
|
11
10
|
import { getLogger } from "@logtape/logtape";
|
|
12
|
-
import { SpanStatusCode, trace } from "@opentelemetry/api";
|
|
13
11
|
import { ATTR_HTTP_REQUEST_HEADER, ATTR_HTTP_REQUEST_METHOD, ATTR_URL_FULL } from "@opentelemetry/semantic-conventions";
|
|
14
12
|
import { decodeBase64, encodeBase64 } from "byte-encodings/base64";
|
|
15
13
|
import { encodeHex } from "byte-encodings/hex";
|
|
16
14
|
import { Item, decodeDict, encodeItem } from "structured-field-values";
|
|
17
|
-
|
|
18
15
|
//#region src/sig/http.ts
|
|
19
16
|
const DEFAULT_MAX_REDIRECTION = 20;
|
|
20
17
|
/**
|
|
@@ -28,9 +25,7 @@ const DEFAULT_MAX_REDIRECTION = 20;
|
|
|
28
25
|
*/
|
|
29
26
|
async function signRequest(request, privateKey, keyId, options = {}) {
|
|
30
27
|
validateCryptoKey(privateKey, "private");
|
|
31
|
-
|
|
32
|
-
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
|
33
|
-
return await tracer.startActiveSpan("http_signatures.sign", async (span) => {
|
|
28
|
+
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.sign", async (span) => {
|
|
34
29
|
try {
|
|
35
30
|
const spec = options.spec ?? "draft-cavage-http-signatures-12";
|
|
36
31
|
let signed;
|
|
@@ -138,9 +133,7 @@ const derivedComponents = {
|
|
|
138
133
|
* @returns The formatted signature string.
|
|
139
134
|
*/
|
|
140
135
|
function formatRfc9421Signature(signature, components, parameters, label = "sig1") {
|
|
141
|
-
|
|
142
|
-
const signatureValue = `${label}=:${encodeBase64(signature)}:`;
|
|
143
|
-
return [signatureInputValue, signatureValue];
|
|
136
|
+
return [`${label}=(${components.map((c) => formatComponentId(c)).join(" ")});${parameters}`, `${label}=:${encodeBase64(signature)}:`];
|
|
144
137
|
}
|
|
145
138
|
/**
|
|
146
139
|
* Parse RFC 9421 Signature-Input header.
|
|
@@ -246,12 +239,11 @@ async function signRequestRfc9421(request, privateKey, keyId, span, currentTime,
|
|
|
246
239
|
value: "content-digest",
|
|
247
240
|
params: {}
|
|
248
241
|
}] : []];
|
|
249
|
-
const expires = rfc9421Options?.expires === true ? (currentTime.epochMilliseconds / 1e3 | 0) + 3600 : void 0;
|
|
250
242
|
const signatureParams = formatRfc9421SignatureParameters({
|
|
251
243
|
algorithm: "rsa-v1_5-sha256",
|
|
252
244
|
keyId,
|
|
253
245
|
created,
|
|
254
|
-
expires,
|
|
246
|
+
expires: rfc9421Options?.expires === true ? (currentTime.epochMilliseconds / 1e3 | 0) + 3600 : void 0,
|
|
255
247
|
nonce: rfc9421Options?.nonce,
|
|
256
248
|
tag: rfc9421Options?.tag
|
|
257
249
|
});
|
|
@@ -361,9 +353,7 @@ async function verifyRequest(request, options = {}) {
|
|
|
361
353
|
* @since 2.1.0
|
|
362
354
|
*/
|
|
363
355
|
async function verifyRequestDetailed(request, options = {}) {
|
|
364
|
-
|
|
365
|
-
const tracer = tracerProvider.getTracer(deno_default.name, deno_default.version);
|
|
366
|
-
return await tracer.startActiveSpan("http_signatures.verify", async (span) => {
|
|
356
|
+
return await (options.tracerProvider ?? trace.getTracerProvider()).getTracer(name, version).startActiveSpan("http_signatures.verify", async (span) => {
|
|
367
357
|
if (span.isRecording()) {
|
|
368
358
|
span.setAttribute(ATTR_HTTP_REQUEST_METHOD, request.method);
|
|
369
359
|
span.setAttribute(ATTR_URL_FULL, request.url);
|
|
@@ -558,8 +548,7 @@ async function verifyRequestDraft(request, span, { documentLoader, contextLoader
|
|
|
558
548
|
const message = headerNames.map((name) => `${name}: ` + (name === "(request-target)" ? `${request.method.toLowerCase()} ${new URL(request.url).pathname}` : name === "(created)" ? sigValues.created ?? "" : name === "(expires)" ? sigValues.expires ?? "" : name === "host" ? request.headers.get("host") ?? new URL(request.url).host : request.headers.get(name))).join("\n");
|
|
559
549
|
const sig = decodeBase64(signature);
|
|
560
550
|
span?.setAttribute("http_signatures.signature", encodeHex(sig));
|
|
561
|
-
|
|
562
|
-
if (!verified) {
|
|
551
|
+
if (!await crypto.subtle.verify("RSASSA-PKCS1-v1_5", key.publicKey, sig, new TextEncoder().encode(message))) {
|
|
563
552
|
if (cached) {
|
|
564
553
|
logger.debug("Failed to verify with the cached key {keyId}; signature {signature} is invalid. Retrying with the freshly fetched key...", {
|
|
565
554
|
keyId,
|
|
@@ -573,7 +562,7 @@ async function verifyRequestDraft(request, span, { documentLoader, contextLoader
|
|
|
573
562
|
currentTime,
|
|
574
563
|
keyCache: {
|
|
575
564
|
get: () => Promise.resolve(void 0),
|
|
576
|
-
set: async (keyId
|
|
565
|
+
set: async (keyId, key) => await keyCache?.set(keyId, key)
|
|
577
566
|
}
|
|
578
567
|
});
|
|
579
568
|
}
|
|
@@ -735,9 +724,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
|
|
|
735
724
|
failure = invalidSignatureResult(keyId);
|
|
736
725
|
continue;
|
|
737
726
|
}
|
|
738
|
-
|
|
739
|
-
const digestValid = await verifyRfc9421ContentDigest(contentDigestHeader, body);
|
|
740
|
-
if (!digestValid) {
|
|
727
|
+
if (!await verifyRfc9421ContentDigest(contentDigestHeader, await request.arrayBuffer())) {
|
|
741
728
|
logger.debug("Failed to verify; Content-Digest verification failed.", { contentDigest: contentDigestHeader });
|
|
742
729
|
failure = invalidSignatureResult(keyId);
|
|
743
730
|
continue;
|
|
@@ -795,8 +782,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
|
|
|
795
782
|
const signatureBaseBytes = new TextEncoder().encode(signatureBase);
|
|
796
783
|
span?.setAttribute("http_signatures.signature", encodeHex(sigBytes));
|
|
797
784
|
try {
|
|
798
|
-
|
|
799
|
-
if (verified) return {
|
|
785
|
+
if (await crypto.subtle.verify(algorithm, key.publicKey, sigBytes.slice(), signatureBaseBytes)) return {
|
|
800
786
|
verified: true,
|
|
801
787
|
key,
|
|
802
788
|
signatureLabel: sigName
|
|
@@ -810,7 +796,7 @@ async function verifyRequestRfc9421(request, span, { documentLoader, contextLoad
|
|
|
810
796
|
currentTime,
|
|
811
797
|
keyCache: {
|
|
812
798
|
get: () => Promise.resolve(void 0),
|
|
813
|
-
set: async (keyId
|
|
799
|
+
set: async (keyId, key) => await keyCache?.set(keyId, key)
|
|
814
800
|
},
|
|
815
801
|
spec: "rfc9421"
|
|
816
802
|
});
|
|
@@ -887,8 +873,7 @@ async function doubleKnockInternal(request, identity, options, redirected = 0, v
|
|
|
887
873
|
});
|
|
888
874
|
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
889
875
|
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
890
|
-
const
|
|
891
|
-
const redirectRequest = createRedirectRequest(request, location, body);
|
|
876
|
+
const redirectRequest = createRedirectRequest(request, response.headers.get("Location"), body);
|
|
892
877
|
if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
893
878
|
return doubleKnockInternal(redirectRequest, identity, {
|
|
894
879
|
...options,
|
|
@@ -936,13 +921,10 @@ async function doubleKnockInternal(request, identity, options, redirected = 0, v
|
|
|
936
921
|
redirect: "manual",
|
|
937
922
|
signal
|
|
938
923
|
});
|
|
939
|
-
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
body
|
|
944
|
-
});
|
|
945
|
-
}
|
|
924
|
+
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) return doubleKnock(createRedirectRequest(request, response.headers.get("Location"), body), identity, {
|
|
925
|
+
...options,
|
|
926
|
+
body
|
|
927
|
+
});
|
|
946
928
|
}
|
|
947
929
|
if (fulfilled && response.status < 300) {
|
|
948
930
|
await specDeterminer?.rememberSpec(origin, "rfc9421");
|
|
@@ -969,8 +951,7 @@ async function doubleKnockInternal(request, identity, options, redirected = 0, v
|
|
|
969
951
|
});
|
|
970
952
|
if (response.status >= 300 && response.status < 400 && response.headers.has("Location")) {
|
|
971
953
|
if (redirected >= DEFAULT_MAX_REDIRECTION) throw new FetchError(request.url, `Too many redirections (${redirected + 1})`);
|
|
972
|
-
const
|
|
973
|
-
const redirectRequest = createRedirectRequest(request, location, body);
|
|
954
|
+
const redirectRequest = createRedirectRequest(request, response.headers.get("Location"), body);
|
|
974
955
|
if (visited.has(redirectRequest.url)) throw new FetchError(request.url, `Redirect loop detected: ${redirectRequest.url}`);
|
|
975
956
|
return doubleKnockInternal(redirectRequest, identity, {
|
|
976
957
|
...options,
|
|
@@ -1007,6 +988,5 @@ function timingSafeEqual(a, b) {
|
|
|
1007
988
|
result |= lenA ^ lenB;
|
|
1008
989
|
return result === 0;
|
|
1009
990
|
}
|
|
1010
|
-
|
|
1011
991
|
//#endregion
|
|
1012
|
-
export {
|
|
992
|
+
export { parseRfc9421Signature as a, timingSafeEqual as c, formatRfc9421SignatureParameters as i, verifyRequest as l, doubleKnock as n, parseRfc9421SignatureInput as o, formatRfc9421Signature as r, signRequest as s, createRfc9421SignatureBase as t, verifyRequestDetailed as u };
|