@fedify/fedify 2.5.0-dev.2687 → 2.5.0-dev.2710
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/federation/mod.cjs +1 -1
- package/dist/federation/mod.js +1 -1
- package/dist/{federation-pFFwPyoZ.cjs → federation-JvzYDx0P.cjs} +3 -3
- package/dist/{http-CXX-QPzs.cjs → http-BG5cDmTS.cjs} +1 -1
- package/dist/{http-T7h9GBAN.js → http-MUf125Jc.js} +1 -1
- package/dist/{kv-cache-C6XX_fwz.cjs → kv-cache-A2po7h0_.cjs} +1 -1
- package/dist/{kv-cache-EFcb1kkU.js → kv-cache-CbWc1BZA.js} +1 -1
- package/dist/{middleware-Bj91r7r2.js → middleware-DzzdJ7Wz.js} +3 -3
- package/dist/mod.cjs +4 -4
- package/dist/mod.js +4 -4
- package/dist/{portable-collection-Do5QA2oy.js → portable-collection-CAer9RWN.js} +1 -1
- package/dist/{portable-collection-BOl9oKrt.cjs → portable-collection-d8w7TCn9.cjs} +1 -1
- package/dist/sig/mod.cjs +2 -2
- package/dist/sig/mod.js +2 -2
- package/dist/utils/mod.cjs +1 -1
- package/dist/utils/mod.js +1 -1
- package/package.json +22 -9
- package/skills/fedify/SKILL.md +10 -0
- package/dist/accept-CPVqki78.mjs +0 -145
- package/dist/activity-listener-CELFAodc.mjs +0 -44
- package/dist/assert-D1Eafmd_.mjs +0 -23
- package/dist/assert_equals-Z6IcEbWU.mjs +0 -987
- package/dist/assert_exists-cffSpJ7X.mjs +0 -28
- package/dist/assert_false-CPdRnc3E.mjs +0 -23
- package/dist/assert_greater_or_equal-BlafOF4-.mjs +0 -31
- package/dist/assert_instance_of-mrXWWNY-.mjs +0 -37
- package/dist/assert_not_equals-CpPK2t89.mjs +0 -30
- package/dist/assert_rejects-CTptdYck.mjs +0 -39
- package/dist/assert_strict_equals-CYvBmkpC.mjs +0 -42
- package/dist/assert_throws-BYITOvPO.mjs +0 -74
- package/dist/assertion_error-B-cx0fFA.mjs +0 -31
- package/dist/audience-CHQ-FlLD.mjs +0 -95
- package/dist/builder-D1FP_5nQ.mjs +0 -911
- package/dist/circuit-breaker-XJ53md4S.mjs +0 -544
- package/dist/circuit-breaker-test-utils-DW6YC_Pe.mjs +0 -14
- package/dist/client-5SIFzW3q.mjs +0 -441
- package/dist/codec-C6rTrpIp.mjs +0 -147
- package/dist/collection-CnnP1UAv.mjs +0 -44
- package/dist/compat/outgoing-jsonld.test.d.mts +0 -2
- package/dist/compat/outgoing-jsonld.test.mjs +0 -257
- package/dist/compat/public-audience.test.d.mts +0 -2
- package/dist/compat/public-audience.test.mjs +0 -187
- package/dist/compat/secured-document.test.d.mts +0 -2
- package/dist/compat/secured-document.test.mjs +0 -58
- package/dist/compat/transformers.test.d.mts +0 -2
- package/dist/compat/transformers.test.mjs +0 -62
- package/dist/compound-proof-DSHhnOEW.mjs +0 -1019
- package/dist/context-LgGFFSz7.mjs +0 -146
- package/dist/deno-C50ikGBU.mjs +0 -8
- package/dist/dist-_geWsuaI.mjs +0 -189
- package/dist/docloader-BY-SEID0.mjs +0 -136
- package/dist/esm-BHXXx4Wx.mjs +0 -1233
- package/dist/exporter-DVG68ozH.mjs +0 -263
- package/dist/federation/audience.test.d.mts +0 -2
- package/dist/federation/audience.test.mjs +0 -130
- package/dist/federation/builder.test.d.mts +0 -2
- package/dist/federation/builder.test.mjs +0 -396
- package/dist/federation/circuit-breaker.test.d.mts +0 -2
- package/dist/federation/circuit-breaker.test.mjs +0 -1277
- package/dist/federation/collection.test.d.mts +0 -2
- package/dist/federation/collection.test.mjs +0 -21
- package/dist/federation/compound-fanout.test.d.mts +0 -2
- package/dist/federation/compound-fanout.test.mjs +0 -231
- package/dist/federation/handler-compound-proof.test.d.mts +0 -2
- package/dist/federation/handler-compound-proof.test.mjs +0 -384
- package/dist/federation/handler.test.d.mts +0 -2
- package/dist/federation/handler.test.mjs +0 -5445
- package/dist/federation/hashlink-media.test.d.mts +0 -2
- package/dist/federation/hashlink-media.test.mjs +0 -422
- package/dist/federation/idempotency.test.d.mts +0 -2
- package/dist/federation/idempotency.test.mjs +0 -207
- package/dist/federation/inbox-actorless.test.d.mts +0 -2
- package/dist/federation/inbox-actorless.test.mjs +0 -522
- package/dist/federation/inbox-authentication.test.d.mts +0 -2
- package/dist/federation/inbox-authentication.test.mjs +0 -220
- package/dist/federation/inbox-report.test.d.mts +0 -2
- package/dist/federation/inbox-report.test.mjs +0 -719
- package/dist/federation/inbox-view.test.d.mts +0 -2
- package/dist/federation/inbox-view.test.mjs +0 -369
- package/dist/federation/inbox.test.d.mts +0 -2
- package/dist/federation/inbox.test.mjs +0 -139
- package/dist/federation/keycache.test.d.mts +0 -2
- package/dist/federation/keycache.test.mjs +0 -337
- package/dist/federation/kv.test.d.mts +0 -2
- package/dist/federation/kv.test.mjs +0 -88
- package/dist/federation/metrics.test.d.mts +0 -2
- package/dist/federation/metrics.test.mjs +0 -634
- package/dist/federation/middleware.test.d.mts +0 -2
- package/dist/federation/middleware.test.mjs +0 -9314
- package/dist/federation/mq.test.d.mts +0 -2
- package/dist/federation/mq.test.mjs +0 -591
- package/dist/federation/negotiation.test.d.mts +0 -2
- package/dist/federation/negotiation.test.mjs +0 -18
- package/dist/federation/outbound-body.test.d.mts +0 -2
- package/dist/federation/outbound-body.test.mjs +0 -149
- package/dist/federation/outbound-capture.test.d.mts +0 -2
- package/dist/federation/outbound-capture.test.mjs +0 -394
- package/dist/federation/outbound-dispatch.test.d.mts +0 -2
- package/dist/federation/outbound-dispatch.test.mjs +0 -368
- package/dist/federation/outbound-document.test.d.mts +0 -2
- package/dist/federation/outbound-document.test.mjs +0 -171
- package/dist/federation/outbound-provenance.test.d.mts +0 -2
- package/dist/federation/outbound-provenance.test.mjs +0 -543
- package/dist/federation/outbound-report.test.d.mts +0 -2
- package/dist/federation/outbound-report.test.mjs +0 -5475
- package/dist/federation/outbound-workers.test.d.mts +0 -2
- package/dist/federation/outbound-workers.test.mjs +0 -64
- package/dist/federation/outbound-workflow.test.d.mts +0 -2
- package/dist/federation/outbound-workflow.test.mjs +0 -154
- package/dist/federation/outgoing-proof.test.d.mts +0 -2
- package/dist/federation/outgoing-proof.test.mjs +0 -933
- package/dist/federation/portable-actor.test.d.mts +0 -2
- package/dist/federation/portable-actor.test.mjs +0 -496
- package/dist/federation/portable-chain.test.d.mts +0 -2
- package/dist/federation/portable-chain.test.mjs +0 -370
- package/dist/federation/portable-collection.test.d.mts +0 -2
- package/dist/federation/portable-collection.test.mjs +0 -832
- package/dist/federation/portable-delivery.test.d.mts +0 -2
- package/dist/federation/portable-delivery.test.mjs +0 -845
- package/dist/federation/portable-gateway-keys.test.d.mts +0 -2
- package/dist/federation/portable-gateway-keys.test.mjs +0 -692
- package/dist/federation/portable-inbox.test.d.mts +0 -2
- package/dist/federation/portable-inbox.test.mjs +0 -1960
- package/dist/federation/portable-parse-uri.test.d.mts +0 -2
- package/dist/federation/portable-parse-uri.test.mjs +0 -348
- package/dist/federation/portable-route-activity.test.d.mts +0 -2
- package/dist/federation/portable-route-activity.test.mjs +0 -259
- package/dist/federation/portable.test.d.mts +0 -2
- package/dist/federation/portable.test.mjs +0 -1072
- package/dist/federation/retry.test.d.mts +0 -2
- package/dist/federation/retry.test.mjs +0 -42
- package/dist/federation/router.test.d.mts +0 -2
- package/dist/federation/router.test.mjs +0 -123
- package/dist/federation/send.test.d.mts +0 -2
- package/dist/federation/send.test.mjs +0 -1421
- package/dist/federation/tasks/codec.test.d.mts +0 -2
- package/dist/federation/tasks/codec.test.mjs +0 -302
- package/dist/federation/tasks/enqueue.test.d.mts +0 -2
- package/dist/federation/tasks/enqueue.test.mjs +0 -1095
- package/dist/federation/tasks/tasks.test.d.mts +0 -2
- package/dist/federation/tasks/tasks.test.mjs +0 -1229
- package/dist/federation/temporal.test.d.mts +0 -2
- package/dist/federation/temporal.test.mjs +0 -71
- package/dist/federation/webfinger.test.d.mts +0 -2
- package/dist/federation/webfinger.test.mjs +0 -944
- package/dist/http-BXbQQZDM.mjs +0 -1449
- package/dist/inbox-authentication-CgonVRkg.mjs +0 -198
- package/dist/inbox-cS97XzOD.mjs +0 -399
- package/dist/inbox-view-D-d0Ar6o.mjs +0 -385
- package/dist/key-owner-evidence-APB6NpSk.mjs +0 -108
- package/dist/keycache-N2opu4-3.mjs +0 -221
- package/dist/keys-DIJNHW-Y.mjs +0 -120
- package/dist/kv-DBRWVx3Q.mjs +0 -104
- package/dist/kv-DCHkaJ9-.mjs +0 -92
- package/dist/kv-cache-fgbLHGVL.mjs +0 -121
- package/dist/ld-BpkhkDGj.mjs +0 -1752
- package/dist/map-local-context-conflict-DOYEEJ3u.mjs +0 -204
- package/dist/map-local-create-note-B0SeXJms.mjs +0 -214
- package/dist/metrics-Uqf8GomB.mjs +0 -818
- package/dist/middleware-DcXzz-YK.mjs +0 -9971
- package/dist/middleware-DgwZkvJR.mjs +0 -5
- package/dist/mq-eF96QxUT.mjs +0 -288
- package/dist/negotiation-BAKO9nih.mjs +0 -96
- package/dist/nodeinfo/client.test.d.mts +0 -2
- package/dist/nodeinfo/client.test.mjs +0 -1364
- package/dist/nodeinfo/handler.test.d.mts +0 -2
- package/dist/nodeinfo/handler.test.mjs +0 -94
- package/dist/nodeinfo/types.test.d.mts +0 -2
- package/dist/nodeinfo/types.test.mjs +0 -192
- package/dist/otel/exporter.test.d.mts +0 -2
- package/dist/otel/exporter.test.mjs +0 -887
- package/dist/outbound-body-CckPA5gc.mjs +0 -83
- package/dist/outbound-capture-DVgnRzlf.mjs +0 -184
- package/dist/outbound-document-BMgwLXTY.mjs +0 -179
- package/dist/outgoing-jsonld-4IJqPYos.mjs +0 -205
- package/dist/owner-BVenIFg1.mjs +0 -267
- package/dist/portable-collection-DIk9gpjL.mjs +0 -418
- package/dist/portable-key-C7pVaHNR.mjs +0 -549
- package/dist/portable-key-id-Ca30-hOa.mjs +0 -248
- package/dist/proof-BlfZ95--.mjs +0 -1420
- package/dist/public-audience--klBIOk1.mjs +0 -197
- package/dist/retry-zX5xw5e0.mjs +0 -34
- package/dist/router-u5O5KCQr.mjs +0 -156
- package/dist/secured-document-CxzZZ9nL.mjs +0 -35
- package/dist/send-DEGHPGFk.mjs +0 -710
- package/dist/sig/accept.test.d.mts +0 -2
- package/dist/sig/accept.test.mjs +0 -416
- package/dist/sig/compound-proof-discovery.test.d.mts +0 -2
- package/dist/sig/compound-proof-discovery.test.mjs +0 -331
- package/dist/sig/compound-proof-producer.test.d.mts +0 -2
- package/dist/sig/compound-proof-producer.test.mjs +0 -107
- package/dist/sig/compound-proof-verification.test.d.mts +0 -2
- package/dist/sig/compound-proof-verification.test.mjs +0 -1017
- package/dist/sig/compound-proof.test.d.mts +0 -2
- package/dist/sig/compound-proof.test.mjs +0 -411
- package/dist/sig/http.test.d.mts +0 -2
- package/dist/sig/http.test.mjs +0 -3328
- package/dist/sig/key-owner-evidence.test.d.mts +0 -2
- package/dist/sig/key-owner-evidence.test.mjs +0 -100
- package/dist/sig/key.test.d.mts +0 -2
- package/dist/sig/key.test.mjs +0 -1250
- package/dist/sig/ld.test.d.mts +0 -2
- package/dist/sig/ld.test.mjs +0 -1044
- package/dist/sig/mitra-receive-interop.test.d.mts +0 -2
- package/dist/sig/mitra-receive-interop.test.mjs +0 -260
- package/dist/sig/mitra-send-interop.test.d.mts +0 -2
- package/dist/sig/mitra-send-interop.test.mjs +0 -461
- package/dist/sig/owner.test.d.mts +0 -2
- package/dist/sig/owner.test.mjs +0 -202
- package/dist/sig/portable-collection.test.d.mts +0 -2
- package/dist/sig/portable-collection.test.mjs +0 -697
- package/dist/sig/portable-interop.test.d.mts +0 -2
- package/dist/sig/portable-interop.test.mjs +0 -156
- package/dist/sig/portable-key-id.test.d.mts +0 -2
- package/dist/sig/portable-key-id.test.mjs +0 -67
- package/dist/sig/portable-key.test.d.mts +0 -2
- package/dist/sig/portable-key.test.mjs +0 -1438
- package/dist/sig/proof.test.d.mts +0 -2
- package/dist/sig/proof.test.mjs +0 -2638
- package/dist/sig/tootik-request-interop.test.d.mts +0 -2
- package/dist/sig/tootik-request-interop.test.mjs +0 -190
- package/dist/sig/tootik-send-interop.test.d.mts +0 -2
- package/dist/sig/tootik-send-interop.test.mjs +0 -331
- package/dist/sig/verification.test.d.mts +0 -2
- package/dist/sig/verification.test.mjs +0 -310
- package/dist/std__assert-DvMDRPes.mjs +0 -8
- package/dist/tasks-BCUmQbbz.mjs +0 -77
- package/dist/temporal-B4oQ8HpW.mjs +0 -95
- package/dist/testing/context.test.d.mts +0 -2
- package/dist/testing/context.test.mjs +0 -19
- package/dist/testing/kv.test.d.mts +0 -2
- package/dist/testing/kv.test.mjs +0 -101
- package/dist/testing/mod.d.mts +0 -6099
- package/dist/testing/mod.mjs +0 -9
- package/dist/testing-vrnD5Uaa.mjs +0 -8
- package/dist/types-DE_LV1JB.mjs +0 -46
- package/dist/utils/docloader.test.d.mts +0 -2
- package/dist/utils/docloader.test.mjs +0 -1076
- package/dist/utils/kv-cache.test.d.mts +0 -2
- package/dist/utils/kv-cache.test.mjs +0 -261
- package/dist/verification-C3954hQh.mjs +0 -5
- package/dist/verification-Dpfcw8ml.mjs +0 -105
- package/dist/vocab/cjs.test.d.mts +0 -2
- package/dist/vocab/cjs.test.mjs +0 -27
package/dist/sig/key.test.mjs
DELETED
|
@@ -1,1250 +0,0 @@
|
|
|
1
|
-
import "temporal-polyfill";
|
|
2
|
-
import "urlpattern-polyfill";
|
|
3
|
-
globalThis.addEventListener = () => {};
|
|
4
|
-
import { t as assertEquals } from "../assert_equals-Z6IcEbWU.mjs";
|
|
5
|
-
import { t as assertFalse } from "../assert_false-CPdRnc3E.mjs";
|
|
6
|
-
import { t as assertThrows } from "../assert_throws-BYITOvPO.mjs";
|
|
7
|
-
import "../std__assert-DvMDRPes.mjs";
|
|
8
|
-
import { t as assertRejects } from "../assert_rejects-CTptdYck.mjs";
|
|
9
|
-
import { t as assertStrictEquals } from "../assert_strict_equals-CYvBmkpC.mjs";
|
|
10
|
-
import { t as assert } from "../assert-D1Eafmd_.mjs";
|
|
11
|
-
import { C as fetchKey, D as validateCryptoKey, E as importJwk, T as generateCryptoKeyPair, w as fetchKeyDetailed, x as exportJwk, y as wrapContextLoaderForJsonLd } from "../ld-BpkhkDGj.mjs";
|
|
12
|
-
import { c as rsaPublicKey3, i as rsaPrivateKey2, o as rsaPublicKey1, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-DIJNHW-Y.mjs";
|
|
13
|
-
import { CryptographicKey, Multikey, Person } from "@fedify/vocab";
|
|
14
|
-
import { FetchError, UrlError, exportDidKey, getDocumentLoader } from "@fedify/vocab-runtime";
|
|
15
|
-
import { createTestMeterProvider, createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
|
|
16
|
-
//#region src/sig/key.test.ts
|
|
17
|
-
test("validateCryptoKey()", async () => {
|
|
18
|
-
const pkcs1v15 = await crypto.subtle.generateKey({
|
|
19
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
20
|
-
modulusLength: 2048,
|
|
21
|
-
publicExponent: new Uint8Array([
|
|
22
|
-
1,
|
|
23
|
-
0,
|
|
24
|
-
1
|
|
25
|
-
]),
|
|
26
|
-
hash: "SHA-256"
|
|
27
|
-
}, true, ["sign", "verify"]);
|
|
28
|
-
validateCryptoKey(pkcs1v15.privateKey, "private");
|
|
29
|
-
validateCryptoKey(pkcs1v15.privateKey);
|
|
30
|
-
validateCryptoKey(pkcs1v15.publicKey, "public");
|
|
31
|
-
validateCryptoKey(pkcs1v15.publicKey);
|
|
32
|
-
const ed25519 = await crypto.subtle.generateKey("Ed25519", true, ["sign", "verify"]);
|
|
33
|
-
validateCryptoKey(ed25519.privateKey, "private");
|
|
34
|
-
validateCryptoKey(ed25519.privateKey);
|
|
35
|
-
validateCryptoKey(ed25519.publicKey, "public");
|
|
36
|
-
validateCryptoKey(ed25519.publicKey);
|
|
37
|
-
assertThrows(() => validateCryptoKey(pkcs1v15.privateKey, "public"), TypeError, "The key is not a public key.");
|
|
38
|
-
assertThrows(() => validateCryptoKey(pkcs1v15.publicKey, "private"), TypeError, "The key is not a private key.");
|
|
39
|
-
assertThrows(() => validateCryptoKey(ed25519.privateKey, "public"), TypeError, "The key is not a public key.");
|
|
40
|
-
assertThrows(() => validateCryptoKey(ed25519.publicKey, "private"), TypeError, "The key is not a private key.");
|
|
41
|
-
const ecdsa = await crypto.subtle.generateKey({
|
|
42
|
-
name: "ECDSA",
|
|
43
|
-
namedCurve: "P-256"
|
|
44
|
-
}, true, ["sign", "verify"]);
|
|
45
|
-
assertThrows(() => validateCryptoKey(ecdsa.publicKey), TypeError, "only RSASSA-PKCS1-v1_5 and Ed25519");
|
|
46
|
-
const pkcs1v15Sha512 = await crypto.subtle.generateKey({
|
|
47
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
48
|
-
modulusLength: 2048,
|
|
49
|
-
publicExponent: new Uint8Array([
|
|
50
|
-
1,
|
|
51
|
-
0,
|
|
52
|
-
1
|
|
53
|
-
]),
|
|
54
|
-
hash: "SHA-512"
|
|
55
|
-
}, true, ["sign", "verify"]);
|
|
56
|
-
assertThrows(() => validateCryptoKey(pkcs1v15Sha512.privateKey), TypeError, "hash algorithm for RSASSA-PKCS1-v1_5 keys must be SHA-256");
|
|
57
|
-
});
|
|
58
|
-
test("generateCryptoKeyPair()", async () => {
|
|
59
|
-
const rsaKeyPair = await generateCryptoKeyPair();
|
|
60
|
-
assertEquals(rsaKeyPair.privateKey.algorithm, {
|
|
61
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
62
|
-
hash: { name: "SHA-256" },
|
|
63
|
-
modulusLength: 4096,
|
|
64
|
-
publicExponent: new Uint8Array([
|
|
65
|
-
1,
|
|
66
|
-
0,
|
|
67
|
-
1
|
|
68
|
-
])
|
|
69
|
-
});
|
|
70
|
-
validateCryptoKey(rsaKeyPair.privateKey, "private");
|
|
71
|
-
validateCryptoKey(rsaKeyPair.publicKey, "public");
|
|
72
|
-
const rsaKeyPair2 = await generateCryptoKeyPair("RSASSA-PKCS1-v1_5");
|
|
73
|
-
assertEquals(rsaKeyPair2.privateKey.algorithm, {
|
|
74
|
-
name: "RSASSA-PKCS1-v1_5",
|
|
75
|
-
hash: { name: "SHA-256" },
|
|
76
|
-
modulusLength: 4096,
|
|
77
|
-
publicExponent: new Uint8Array([
|
|
78
|
-
1,
|
|
79
|
-
0,
|
|
80
|
-
1
|
|
81
|
-
])
|
|
82
|
-
});
|
|
83
|
-
validateCryptoKey(rsaKeyPair2.privateKey, "private");
|
|
84
|
-
validateCryptoKey(rsaKeyPair2.publicKey, "public");
|
|
85
|
-
const ed25519KeyPair = await generateCryptoKeyPair("Ed25519");
|
|
86
|
-
assertEquals(ed25519KeyPair.privateKey.algorithm, { name: "Ed25519" });
|
|
87
|
-
validateCryptoKey(ed25519KeyPair.privateKey, "private");
|
|
88
|
-
validateCryptoKey(ed25519KeyPair.publicKey, "public");
|
|
89
|
-
});
|
|
90
|
-
const rsaPublicJwk = {
|
|
91
|
-
alg: "RS256",
|
|
92
|
-
kty: "RSA",
|
|
93
|
-
e: "AQAB",
|
|
94
|
-
n: "oRmBtnxbdFutoRd1GLGwwGTrsqlRRWUe11hHQaoRLGf5LwQ0tIc6I9q-dynliw-2kxYsLn9SH2je6HcTYOolgW7F_cOWXZQN04b-OiYcU1ConAhLjmn4k1uKawJ614y0ScPNd8PQ-CljsnlPxbq9ofaCMe2BV3B6y09aCuGFJ0nxn1_ubjmIBIWWFTAznoz1J9BhJDGyt3IO3ABy3f9zDVlR32L_n5VIkXnxkjUKdzMAOzYb62kuKOp1iznRTPrV71SNtivJMwSh_LVgBrmZjtIn_oim-KyX_fdLU3tQ7VClyqmJzyAjccOH6Qj6nFTPh-vX07gqN8IlLT2uye4waw",
|
|
95
|
-
key_ops: ["verify"],
|
|
96
|
-
ext: true
|
|
97
|
-
};
|
|
98
|
-
const rsaPrivateJwk = {
|
|
99
|
-
alg: "RS256",
|
|
100
|
-
kty: "RSA",
|
|
101
|
-
d: "f-Pa2L7Sb4YUSa1wlSEC-0li35uQ3DFRkY0QTG2xYnpMFGoXWTV9D1epGrqU8pePzias_mCvFiZPx2Y4aRiYm68P2Mu7hCBz9XfWPN1iYTXIFM51BOLVpk3mjdsTICkgOusJI0m9jDR3ZAjwLj14K6qhYvd0VbECmoItLjQoW64Sc9iDgD3CvGoTqv71oTfW70cy-Ve1xQ9CThAmMOTKe6rYCUTA8tMZcPszifZ4iOasOjgvRxyel86LqGNtyslY8k86gQlMtFpR3VeZV_8otAWZn0mDc4vVU8HUO-DzYiIFdAcVxfPJh6tx7snCTsdzze_98OEAK4EWYBn7vsGFeQ",
|
|
102
|
-
dp: "lrXReSkZQXSmSxQ1TimV5kMt96gSu4_r-OGIabVmoG5irhjMyN08Jjc3qK9oZS3uNM-LxAOg4OdzefjsF9IMfZJl6wuLd85g_l4BHSaEk5zC8l3QugX1IU9XZ7wDxXUrutMoNtZXDtdbveAMtHNZlIu-qmEBDWzkqJiz2WpW-AE",
|
|
103
|
-
dq: "TCLoYcX0ywuNA9DSU6v94KmBh1e_IELEFVbJb5vvLKlAK-ycMK0rfzC1co9Hhkski1LskTnxnoqwZ5oF-7X10eZvy3Te_FHSl0IsTar8ST2-MRtGh2UjTdvP_nnygj4GcXvKfngjPEfthDzVfVMeR38oDhDxMFD5AaY_v9aMH_U",
|
|
104
|
-
e: "AQAB",
|
|
105
|
-
n: "oRmBtnxbdFutoRd1GLGwwGTrsqlRRWUe11hHQaoRLGf5LwQ0tIc6I9q-dynliw-2kxYsLn9SH2je6HcTYOolgW7F_cOWXZQN04b-OiYcU1ConAhLjmn4k1uKawJ614y0ScPNd8PQ-CljsnlPxbq9ofaCMe2BV3B6y09aCuGFJ0nxn1_ubjmIBIWWFTAznoz1J9BhJDGyt3IO3ABy3f9zDVlR32L_n5VIkXnxkjUKdzMAOzYb62kuKOp1iznRTPrV71SNtivJMwSh_LVgBrmZjtIn_oim-KyX_fdLU3tQ7VClyqmJzyAjccOH6Qj6nFTPh-vX07gqN8IlLT2uye4waw",
|
|
106
|
-
p: "xuDd7tE_47NWwvDTpB403X13EPA3768MlNpl_v_BGiuP-1uvWUnsOVZB0F3HXSVg1sBVNtec46v7OU0P693gvYUhouTmSQpayY_VFqMklprWgs7cfneqbeDzv3C4Fw5waY-vjoINDsE1jYELUnl5cVjXXyxuGFG-IaLJKmHmHX0",
|
|
107
|
-
q: "z17X2t9zO6WcMp6W04gXdKmniJlxekOrOmWnrX9AwaM8NYCLN3y23r59nqNP9aUAWG1eoGFmav2rYQitWhz_VsEu2pQUsfsYKZYHchu5p_jCYwuM3rIg7aCbhtGv_tBoWAf1NvKMhtp2es0ZaHZCzKDGSOkIYDOB-ZDmNigWigc",
|
|
108
|
-
qi: "KC6gWhVM_x7iQgl-gEoSh_iM1Jf314ZLJKAAz1DsTHMi5yuCkCMmmY7h6jlkAJVngK3KIf5LPoAeUoGJ26E1kocbRU_nZBftMDVXHCYICz8qMQXR5euN_5SeJnu_VWXH-CY83MKhPYAorWSZ1-G9gh-C16LlRMzJwoE6h5QNeNo",
|
|
109
|
-
key_ops: ["sign"],
|
|
110
|
-
ext: true
|
|
111
|
-
};
|
|
112
|
-
test("exportJwk()", async () => {
|
|
113
|
-
assertEquals(await exportJwk(rsaPrivateKey2), rsaPrivateJwk);
|
|
114
|
-
assertEquals(await exportJwk(rsaPublicKey2.publicKey), rsaPublicJwk);
|
|
115
|
-
});
|
|
116
|
-
test("importJwk()", async () => {
|
|
117
|
-
assertEquals(await importJwk(rsaPrivateJwk, "private"), rsaPrivateKey2);
|
|
118
|
-
assertEquals(await importJwk(rsaPublicJwk, "public"), rsaPublicKey2.publicKey);
|
|
119
|
-
assertRejects(() => importJwk(rsaPublicJwk, "private"));
|
|
120
|
-
assertRejects(() => importJwk(rsaPrivateJwk, "public"));
|
|
121
|
-
});
|
|
122
|
-
test("fetchKey()", async () => {
|
|
123
|
-
const cache = {};
|
|
124
|
-
const options = {
|
|
125
|
-
documentLoader: mockDocumentLoader,
|
|
126
|
-
contextLoader: mockDocumentLoader,
|
|
127
|
-
keyCache: {
|
|
128
|
-
get(keyId) {
|
|
129
|
-
return Promise.resolve(cache[keyId.href]);
|
|
130
|
-
},
|
|
131
|
-
set(keyId, key) {
|
|
132
|
-
cache[keyId.href] = key;
|
|
133
|
-
return Promise.resolve();
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
};
|
|
137
|
-
assertEquals(await fetchKey("https://example.com/nothing", CryptographicKey, options), {
|
|
138
|
-
key: null,
|
|
139
|
-
cached: false
|
|
140
|
-
});
|
|
141
|
-
assertEquals(cache, { "https://example.com/nothing": null });
|
|
142
|
-
assertEquals(await fetchKey("https://example.com/nothing", CryptographicKey, options), {
|
|
143
|
-
key: null,
|
|
144
|
-
cached: true
|
|
145
|
-
});
|
|
146
|
-
assertEquals(cache, { "https://example.com/nothing": null });
|
|
147
|
-
assertEquals(await fetchKey("https://example.com/object", CryptographicKey, options), {
|
|
148
|
-
key: null,
|
|
149
|
-
cached: false
|
|
150
|
-
});
|
|
151
|
-
assertEquals(cache, {
|
|
152
|
-
"https://example.com/nothing": null,
|
|
153
|
-
"https://example.com/object": null
|
|
154
|
-
});
|
|
155
|
-
assertEquals(await fetchKey("https://example.com/key", CryptographicKey, options), {
|
|
156
|
-
key: rsaPublicKey1,
|
|
157
|
-
cached: false
|
|
158
|
-
});
|
|
159
|
-
assertEquals(cache, {
|
|
160
|
-
"https://example.com/nothing": null,
|
|
161
|
-
"https://example.com/object": null,
|
|
162
|
-
"https://example.com/key": rsaPublicKey1
|
|
163
|
-
});
|
|
164
|
-
assertEquals(await fetchKey("https://example.com/key", CryptographicKey, options), {
|
|
165
|
-
key: rsaPublicKey1,
|
|
166
|
-
cached: true
|
|
167
|
-
});
|
|
168
|
-
assertEquals(cache, {
|
|
169
|
-
"https://example.com/nothing": null,
|
|
170
|
-
"https://example.com/object": null,
|
|
171
|
-
"https://example.com/key": rsaPublicKey1
|
|
172
|
-
});
|
|
173
|
-
assertEquals(await fetchKey("https://example.com/person#no-key", CryptographicKey, options), {
|
|
174
|
-
key: null,
|
|
175
|
-
cached: false
|
|
176
|
-
});
|
|
177
|
-
assertEquals(cache, {
|
|
178
|
-
"https://example.com/nothing": null,
|
|
179
|
-
"https://example.com/object": null,
|
|
180
|
-
"https://example.com/key": rsaPublicKey1,
|
|
181
|
-
"https://example.com/person#no-key": null
|
|
182
|
-
});
|
|
183
|
-
assertEquals(await fetchKey("https://example.com/person2#key3", CryptographicKey, options), {
|
|
184
|
-
key: rsaPublicKey3,
|
|
185
|
-
cached: false
|
|
186
|
-
});
|
|
187
|
-
assertEquals(cache, {
|
|
188
|
-
"https://example.com/nothing": null,
|
|
189
|
-
"https://example.com/object": null,
|
|
190
|
-
"https://example.com/key": rsaPublicKey1,
|
|
191
|
-
"https://example.com/person#no-key": null,
|
|
192
|
-
"https://example.com/person2#key3": rsaPublicKey3
|
|
193
|
-
});
|
|
194
|
-
assertEquals(await fetchKey("https://example.com/person2#key3", CryptographicKey, options), {
|
|
195
|
-
key: rsaPublicKey3,
|
|
196
|
-
cached: true
|
|
197
|
-
});
|
|
198
|
-
assertEquals(cache, {
|
|
199
|
-
"https://example.com/nothing": null,
|
|
200
|
-
"https://example.com/object": null,
|
|
201
|
-
"https://example.com/key": rsaPublicKey1,
|
|
202
|
-
"https://example.com/person#no-key": null,
|
|
203
|
-
"https://example.com/person2#key3": rsaPublicKey3
|
|
204
|
-
});
|
|
205
|
-
assertEquals(await fetchKey("https://example.com/person2#key4", Multikey, options), {
|
|
206
|
-
key: ed25519Multikey,
|
|
207
|
-
cached: false
|
|
208
|
-
});
|
|
209
|
-
assertEquals(cache, {
|
|
210
|
-
"https://example.com/nothing": null,
|
|
211
|
-
"https://example.com/object": null,
|
|
212
|
-
"https://example.com/key": rsaPublicKey1,
|
|
213
|
-
"https://example.com/person#no-key": null,
|
|
214
|
-
"https://example.com/person2#key3": rsaPublicKey3,
|
|
215
|
-
"https://example.com/person2#key4": ed25519Multikey
|
|
216
|
-
});
|
|
217
|
-
assertEquals(await fetchKey("https://example.com/person2#key4", Multikey, options), {
|
|
218
|
-
key: ed25519Multikey,
|
|
219
|
-
cached: true
|
|
220
|
-
});
|
|
221
|
-
assertEquals(await fetchKey("https://example.com/key", CryptographicKey, {
|
|
222
|
-
...options,
|
|
223
|
-
keyCache: void 0
|
|
224
|
-
}), {
|
|
225
|
-
key: rsaPublicKey1,
|
|
226
|
-
cached: false
|
|
227
|
-
});
|
|
228
|
-
assertEquals(await fetchKey("https://example.com/users/handle", CryptographicKey, options), {
|
|
229
|
-
key: new CryptographicKey({
|
|
230
|
-
id: new URL("https://example.com/users/handle#main-key"),
|
|
231
|
-
publicKey: await importJwk({
|
|
232
|
-
kty: "RSA",
|
|
233
|
-
alg: "RS256",
|
|
234
|
-
n: "oRmBtnxbdFutoRd1GLGwwGTrsqlRRWUe11hHQaoRLGf5LwQ0tIc6I9q-dynliw-2kxYsLn9SH2je6HcTYOolgW7F_cOWXZQN04b-OiYcU1ConAhLjmn4k1uKawJ614y0ScPNd8PQ-CljsnlPxbq9ofaCMe2BV3B6y09aCuGFJ0nxn1_ubjmIBIWWFTAznoz1J9BhJDGyt3IO3ABy3f9zDVlR32L_n5VIkXnxkjUKdzMAOzYb62kuKOp1iznRTPrV71SNtivJMwSh_LVgBrmZjtIn_oim-KyX_fdLU3tQ7VClyqmJzyAjccOH6Qj6nFTPh-vX07gqN8IlLT2uye4waw",
|
|
235
|
-
e: "AQAB",
|
|
236
|
-
key_ops: ["verify"],
|
|
237
|
-
ext: true
|
|
238
|
-
}, "public")
|
|
239
|
-
}),
|
|
240
|
-
cached: false
|
|
241
|
-
});
|
|
242
|
-
});
|
|
243
|
-
test("fetchKeyDetailed()", async () => {
|
|
244
|
-
const cache = { "https://example.com/nothing": null };
|
|
245
|
-
let documentLoaderCalls = 0;
|
|
246
|
-
const [tracerProvider, exporter] = createTestTracerProvider();
|
|
247
|
-
const options = {
|
|
248
|
-
documentLoader(url) {
|
|
249
|
-
documentLoaderCalls++;
|
|
250
|
-
return mockDocumentLoader(url);
|
|
251
|
-
},
|
|
252
|
-
contextLoader: mockDocumentLoader,
|
|
253
|
-
tracerProvider,
|
|
254
|
-
keyCache: {
|
|
255
|
-
get(keyId) {
|
|
256
|
-
return Promise.resolve(cache[keyId.href]);
|
|
257
|
-
},
|
|
258
|
-
set(keyId, key) {
|
|
259
|
-
cache[keyId.href] = key;
|
|
260
|
-
return Promise.resolve();
|
|
261
|
-
}
|
|
262
|
-
}
|
|
263
|
-
};
|
|
264
|
-
assertEquals(await fetchKeyDetailed("https://example.com/nothing", CryptographicKey, options), {
|
|
265
|
-
key: null,
|
|
266
|
-
cached: true
|
|
267
|
-
});
|
|
268
|
-
assertEquals(documentLoaderCalls, 0);
|
|
269
|
-
assertEquals(await fetchKeyDetailed("https://example.com/key", CryptographicKey, options), {
|
|
270
|
-
key: rsaPublicKey1,
|
|
271
|
-
cached: false
|
|
272
|
-
});
|
|
273
|
-
assertEquals(documentLoaderCalls, 2);
|
|
274
|
-
const spans = exporter.getSpans("activitypub.fetch_key");
|
|
275
|
-
assertEquals(spans.length, 2);
|
|
276
|
-
assertEquals(spans[0].attributes["activitypub.actor.key.cached"], true);
|
|
277
|
-
assertEquals(spans[1].attributes["activitypub.actor.key.cached"], false);
|
|
278
|
-
});
|
|
279
|
-
test("fetchKeyDetailed() returns detailed fetch errors", async () => {
|
|
280
|
-
const goneKeyId = new URL("https://example.com/gone-key");
|
|
281
|
-
const goneResult = await fetchKeyDetailed(goneKeyId, CryptographicKey, {
|
|
282
|
-
documentLoader(url) {
|
|
283
|
-
if (url === goneKeyId.href) throw new FetchError(goneKeyId, `HTTP 410: ${goneKeyId.href}`, new Response(null, { status: 410 }));
|
|
284
|
-
return mockDocumentLoader(url);
|
|
285
|
-
},
|
|
286
|
-
contextLoader: mockDocumentLoader
|
|
287
|
-
});
|
|
288
|
-
assertEquals(goneResult.key, null);
|
|
289
|
-
assertEquals(goneResult.cached, false);
|
|
290
|
-
const goneError = goneResult.fetchError;
|
|
291
|
-
assertEquals(goneError != null && "status" in goneError, true);
|
|
292
|
-
if (goneError == null || !("status" in goneError)) throw new Error("Expected HTTP fetch error details.");
|
|
293
|
-
assertEquals(goneError.status, 410);
|
|
294
|
-
assertEquals(goneError.response.status, 410);
|
|
295
|
-
const failure = /* @__PURE__ */ new TypeError("boom");
|
|
296
|
-
const errorResult = await fetchKeyDetailed("https://example.com/error-key", CryptographicKey, {
|
|
297
|
-
documentLoader() {
|
|
298
|
-
throw failure;
|
|
299
|
-
},
|
|
300
|
-
contextLoader: mockDocumentLoader
|
|
301
|
-
});
|
|
302
|
-
assertEquals(errorResult.key, null);
|
|
303
|
-
assertEquals(errorResult.cached, false);
|
|
304
|
-
const detailedError = errorResult.fetchError;
|
|
305
|
-
assertEquals(detailedError != null && "error" in detailedError, true);
|
|
306
|
-
if (detailedError == null || !("error" in detailedError)) throw new Error("Expected non-HTTP fetch error details.");
|
|
307
|
-
assertEquals(detailedError.error, failure);
|
|
308
|
-
});
|
|
309
|
-
test("fetchKey() resolves did:key Multikeys without document loading", async () => {
|
|
310
|
-
const did = await exportDidKey(ed25519PublicKey.publicKey);
|
|
311
|
-
const keyId = `${did}#${did.slice(8)}`;
|
|
312
|
-
const expectedKey = new Multikey({
|
|
313
|
-
id: new URL(keyId),
|
|
314
|
-
controller: new URL(did),
|
|
315
|
-
publicKey: ed25519PublicKey.publicKey
|
|
316
|
-
});
|
|
317
|
-
const cache = { [keyId]: null };
|
|
318
|
-
let documentLoaderCalls = 0;
|
|
319
|
-
const options = {
|
|
320
|
-
documentLoader() {
|
|
321
|
-
documentLoaderCalls++;
|
|
322
|
-
throw new TypeError("did:key must not use the document loader");
|
|
323
|
-
},
|
|
324
|
-
contextLoader: mockDocumentLoader,
|
|
325
|
-
keyCache: {
|
|
326
|
-
get(keyId) {
|
|
327
|
-
return Promise.resolve(cache[keyId.href]);
|
|
328
|
-
},
|
|
329
|
-
set(keyId, key) {
|
|
330
|
-
cache[keyId.href] = key;
|
|
331
|
-
return Promise.resolve();
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
};
|
|
335
|
-
assertEquals(await fetchKey(keyId, Multikey, options), {
|
|
336
|
-
key: expectedKey,
|
|
337
|
-
cached: false
|
|
338
|
-
});
|
|
339
|
-
assertEquals(documentLoaderCalls, 0);
|
|
340
|
-
assertEquals(cache[keyId], expectedKey);
|
|
341
|
-
assertEquals(await fetchKey(keyId, Multikey, options), {
|
|
342
|
-
key: expectedKey,
|
|
343
|
-
cached: true
|
|
344
|
-
});
|
|
345
|
-
assertEquals(documentLoaderCalls, 0);
|
|
346
|
-
});
|
|
347
|
-
test("fetchKey() validates cached did:key Multikeys", async () => {
|
|
348
|
-
const did = await exportDidKey(ed25519PublicKey.publicKey);
|
|
349
|
-
const keyId = `${did}#${did.slice(8)}`;
|
|
350
|
-
const wrongKeyPair = await generateCryptoKeyPair("Ed25519");
|
|
351
|
-
const cachedKey = new Multikey({
|
|
352
|
-
id: new URL(keyId),
|
|
353
|
-
controller: new URL(did),
|
|
354
|
-
publicKey: wrongKeyPair.publicKey
|
|
355
|
-
});
|
|
356
|
-
const expectedKey = new Multikey({
|
|
357
|
-
id: new URL(keyId),
|
|
358
|
-
controller: new URL(did),
|
|
359
|
-
publicKey: ed25519PublicKey.publicKey
|
|
360
|
-
});
|
|
361
|
-
const cache = { [keyId]: cachedKey };
|
|
362
|
-
let documentLoaderCalls = 0;
|
|
363
|
-
assertEquals(await fetchKey(keyId, Multikey, {
|
|
364
|
-
documentLoader() {
|
|
365
|
-
documentLoaderCalls++;
|
|
366
|
-
throw new TypeError("did:key must not use the document loader");
|
|
367
|
-
},
|
|
368
|
-
contextLoader: mockDocumentLoader,
|
|
369
|
-
keyCache: {
|
|
370
|
-
get(keyId) {
|
|
371
|
-
return Promise.resolve(cache[keyId.href]);
|
|
372
|
-
},
|
|
373
|
-
set(keyId, key) {
|
|
374
|
-
cache[keyId.href] = key;
|
|
375
|
-
return Promise.resolve();
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}), {
|
|
379
|
-
key: expectedKey,
|
|
380
|
-
cached: false
|
|
381
|
-
});
|
|
382
|
-
assertEquals(documentLoaderCalls, 0);
|
|
383
|
-
assertEquals(cache[keyId], expectedKey);
|
|
384
|
-
});
|
|
385
|
-
test("fetchKey() rejects unsupported did:key values locally", async () => {
|
|
386
|
-
const invalidKeyId = "did:key:z6MksHj1MJnidCtDiyYW9ugNFftoX9fLK4bornTxmMZ6X7vq#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK";
|
|
387
|
-
const cache = {};
|
|
388
|
-
let documentLoaderCalls = 0;
|
|
389
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
390
|
-
assertEquals(await fetchKey(invalidKeyId, Multikey, {
|
|
391
|
-
documentLoader() {
|
|
392
|
-
documentLoaderCalls++;
|
|
393
|
-
throw new TypeError("did:key must not use the document loader");
|
|
394
|
-
},
|
|
395
|
-
contextLoader: mockDocumentLoader,
|
|
396
|
-
meterProvider,
|
|
397
|
-
keyCache: {
|
|
398
|
-
get(keyId) {
|
|
399
|
-
return Promise.resolve(cache[keyId.href]);
|
|
400
|
-
},
|
|
401
|
-
set(keyId, key) {
|
|
402
|
-
cache[keyId.href] = key;
|
|
403
|
-
return Promise.resolve();
|
|
404
|
-
}
|
|
405
|
-
}
|
|
406
|
-
}), {
|
|
407
|
-
key: null,
|
|
408
|
-
cached: false
|
|
409
|
-
});
|
|
410
|
-
assertEquals(documentLoaderCalls, 0);
|
|
411
|
-
assertEquals(cache, {});
|
|
412
|
-
assertEquals(recorder.getMeasurement("activitypub.key.lookup")?.attributes["activitypub.lookup.result"], "invalid");
|
|
413
|
-
});
|
|
414
|
-
test("fetchKeyDetailed() resolves did:key without fetchError", async () => {
|
|
415
|
-
const did = await exportDidKey(ed25519PublicKey.publicKey);
|
|
416
|
-
const result = await fetchKeyDetailed(`${did}#${did.slice(8)}`, Multikey, {
|
|
417
|
-
documentLoader() {
|
|
418
|
-
throw new TypeError("did:key must not use the document loader");
|
|
419
|
-
},
|
|
420
|
-
contextLoader: mockDocumentLoader
|
|
421
|
-
});
|
|
422
|
-
assertEquals(result.key instanceof Multikey, true);
|
|
423
|
-
assertEquals(result.cached, false);
|
|
424
|
-
assertEquals(result.fetchError, void 0);
|
|
425
|
-
});
|
|
426
|
-
test("fetchKeyDetailed() rejects invalid did:key without fetchError", async () => {
|
|
427
|
-
const invalidKeyId = "did:key:z6MksHj1MJnidCtDiyYW9ugNFftoX9fLK4bornTxmMZ6X7vq#z6MkhaXgBZDvotDkL5257faiztiGiC2QtKLGpbnnEGta2doK";
|
|
428
|
-
const cache = {};
|
|
429
|
-
let documentLoaderCalls = 0;
|
|
430
|
-
const result = await fetchKeyDetailed(invalidKeyId, Multikey, {
|
|
431
|
-
documentLoader() {
|
|
432
|
-
documentLoaderCalls++;
|
|
433
|
-
throw new TypeError("did:key must not use the document loader");
|
|
434
|
-
},
|
|
435
|
-
contextLoader: mockDocumentLoader,
|
|
436
|
-
keyCache: {
|
|
437
|
-
get(keyId) {
|
|
438
|
-
return Promise.resolve(cache[keyId.href]);
|
|
439
|
-
},
|
|
440
|
-
set(keyId, key) {
|
|
441
|
-
cache[keyId.href] = key;
|
|
442
|
-
return Promise.resolve();
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
});
|
|
446
|
-
assertEquals(result.key, null);
|
|
447
|
-
assertEquals(result.cached, false);
|
|
448
|
-
assertEquals(result.fetchError, void 0);
|
|
449
|
-
assertEquals(documentLoaderCalls, 0);
|
|
450
|
-
assertEquals(cache, {});
|
|
451
|
-
});
|
|
452
|
-
test("fetchKey() does not resolve did:key as CryptographicKey", async () => {
|
|
453
|
-
const did = await exportDidKey(ed25519PublicKey.publicKey);
|
|
454
|
-
const keyId = `${did}#${did.slice(8)}`;
|
|
455
|
-
let cacheGets = 0;
|
|
456
|
-
let documentLoaderCalls = 0;
|
|
457
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, {
|
|
458
|
-
documentLoader() {
|
|
459
|
-
documentLoaderCalls++;
|
|
460
|
-
throw new TypeError("did:key must not use the document loader");
|
|
461
|
-
},
|
|
462
|
-
contextLoader: mockDocumentLoader,
|
|
463
|
-
keyCache: {
|
|
464
|
-
get() {
|
|
465
|
-
cacheGets++;
|
|
466
|
-
throw new TypeError("did:key must not check the cache");
|
|
467
|
-
},
|
|
468
|
-
set() {
|
|
469
|
-
throw new TypeError("did:key must not write to the cache");
|
|
470
|
-
}
|
|
471
|
-
}
|
|
472
|
-
}), {
|
|
473
|
-
key: null,
|
|
474
|
-
cached: false
|
|
475
|
-
});
|
|
476
|
-
assertEquals(cacheGets, 0);
|
|
477
|
-
assertEquals(documentLoaderCalls, 0);
|
|
478
|
-
});
|
|
479
|
-
test("fetchKey() records did:key lookup metrics", async () => {
|
|
480
|
-
const did = await exportDidKey(ed25519PublicKey.publicKey);
|
|
481
|
-
const keyId = `${did}#${did.slice(8)}`;
|
|
482
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
483
|
-
assertEquals((await fetchKey(keyId, Multikey, {
|
|
484
|
-
documentLoader: mockDocumentLoader,
|
|
485
|
-
contextLoader: mockDocumentLoader,
|
|
486
|
-
meterProvider
|
|
487
|
-
})).cached, false);
|
|
488
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
489
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
|
|
490
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
|
|
491
|
-
assertEquals(counter?.attributes["activitypub.remote.host"], "");
|
|
492
|
-
});
|
|
493
|
-
test("fetchKey() records activitypub.key.lookup with hit on cached key", async () => {
|
|
494
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
495
|
-
const cache = {};
|
|
496
|
-
const options = {
|
|
497
|
-
documentLoader: mockDocumentLoader,
|
|
498
|
-
contextLoader: mockDocumentLoader,
|
|
499
|
-
keyCache: {
|
|
500
|
-
get(keyId) {
|
|
501
|
-
return Promise.resolve(cache[keyId.href]);
|
|
502
|
-
},
|
|
503
|
-
set(keyId, key) {
|
|
504
|
-
cache[keyId.href] = key;
|
|
505
|
-
return Promise.resolve();
|
|
506
|
-
}
|
|
507
|
-
},
|
|
508
|
-
meterProvider
|
|
509
|
-
};
|
|
510
|
-
await fetchKey("https://example.com/key", CryptographicKey, options);
|
|
511
|
-
recorder.clear();
|
|
512
|
-
assertEquals((await fetchKey("https://example.com/key", CryptographicKey, options)).cached, true);
|
|
513
|
-
const counters = recorder.getMeasurements("activitypub.key.lookup");
|
|
514
|
-
assertEquals(counters.length, 1);
|
|
515
|
-
assertEquals(counters[0].attributes["activitypub.lookup.kind"], "public_key");
|
|
516
|
-
assertEquals(counters[0].attributes["activitypub.lookup.result"], "hit");
|
|
517
|
-
assertEquals(counters[0].attributes["activitypub.cache.enabled"], true);
|
|
518
|
-
assertEquals(counters[0].attributes["activitypub.remote.host"], "example.com");
|
|
519
|
-
const duration = recorder.getMeasurement("activitypub.key.lookup.duration");
|
|
520
|
-
assertEquals(duration?.type, "histogram");
|
|
521
|
-
assertEquals(duration?.attributes["activitypub.lookup.result"], "hit");
|
|
522
|
-
});
|
|
523
|
-
test("fetchKey() records activitypub.key.lookup with fetched on cache miss", async () => {
|
|
524
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
525
|
-
assertEquals((await fetchKey("https://example.com/key", CryptographicKey, {
|
|
526
|
-
documentLoader: mockDocumentLoader,
|
|
527
|
-
contextLoader: mockDocumentLoader,
|
|
528
|
-
meterProvider
|
|
529
|
-
})).cached, false);
|
|
530
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
531
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "fetched");
|
|
532
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
|
|
533
|
-
assertEquals(counter?.attributes["activitypub.remote.host"], "example.com");
|
|
534
|
-
assertEquals(recorder.getMeasurement("activitypub.key.lookup.duration")?.attributes["activitypub.lookup.result"], "fetched");
|
|
535
|
-
});
|
|
536
|
-
test("fetchKey() records not_found and status code on HTTP 404", async () => {
|
|
537
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
538
|
-
const missingKeyId = new URL("https://example.com/missing-key");
|
|
539
|
-
const documentLoader = (url) => {
|
|
540
|
-
if (url === missingKeyId.href) throw new FetchError(missingKeyId, `HTTP 404: ${missingKeyId.href}`, new Response(null, { status: 404 }));
|
|
541
|
-
return mockDocumentLoader(url);
|
|
542
|
-
};
|
|
543
|
-
assertEquals((await fetchKey(missingKeyId, CryptographicKey, {
|
|
544
|
-
documentLoader,
|
|
545
|
-
contextLoader: mockDocumentLoader,
|
|
546
|
-
meterProvider
|
|
547
|
-
})).key, null);
|
|
548
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
549
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "not_found");
|
|
550
|
-
assertEquals(counter?.attributes["http.response.status_code"], 404);
|
|
551
|
-
assertEquals(counter?.attributes["activitypub.cache.enabled"], false);
|
|
552
|
-
assertEquals(counter?.attributes["activitypub.remote.host"], "example.com");
|
|
553
|
-
});
|
|
554
|
-
test("fetchKey() records network_error on TypeError from the document loader", async () => {
|
|
555
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
556
|
-
const documentLoader = () => {
|
|
557
|
-
throw new TypeError("connect failed");
|
|
558
|
-
};
|
|
559
|
-
await fetchKey("https://example.com/key", CryptographicKey, {
|
|
560
|
-
documentLoader,
|
|
561
|
-
contextLoader: mockDocumentLoader,
|
|
562
|
-
meterProvider
|
|
563
|
-
});
|
|
564
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
565
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "network_error");
|
|
566
|
-
assertEquals("http.response.status_code" in counter.attributes, false);
|
|
567
|
-
});
|
|
568
|
-
test("fetchKeyDetailed() records activitypub.key.lookup with the same taxonomy", async () => {
|
|
569
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
570
|
-
const goneKeyId = new URL("https://example.com/gone-key");
|
|
571
|
-
const documentLoader = (url) => {
|
|
572
|
-
if (url === goneKeyId.href) throw new FetchError(goneKeyId, `HTTP 410: ${goneKeyId.href}`, new Response(null, { status: 410 }));
|
|
573
|
-
return mockDocumentLoader(url);
|
|
574
|
-
};
|
|
575
|
-
await fetchKeyDetailed(goneKeyId, CryptographicKey, {
|
|
576
|
-
documentLoader,
|
|
577
|
-
contextLoader: mockDocumentLoader,
|
|
578
|
-
meterProvider
|
|
579
|
-
});
|
|
580
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
581
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], "not_found");
|
|
582
|
-
assertEquals(counter?.attributes["http.response.status_code"], 410);
|
|
583
|
-
});
|
|
584
|
-
test("fetchKey() works when meterProvider is omitted", async () => {
|
|
585
|
-
assertEquals((await fetchKey("https://example.com/key", CryptographicKey, {
|
|
586
|
-
documentLoader: mockDocumentLoader,
|
|
587
|
-
contextLoader: mockDocumentLoader
|
|
588
|
-
})).cached, false);
|
|
589
|
-
});
|
|
590
|
-
test("fetchKey() rejects standalone keys with a mismatched id", async () => {
|
|
591
|
-
for (const { keyId, standaloneKey, fetch } of [{
|
|
592
|
-
keyId: "https://example.com/key",
|
|
593
|
-
standaloneKey: rsaPublicKey1,
|
|
594
|
-
fetch: (keyId, options) => fetchKey(keyId, CryptographicKey, options)
|
|
595
|
-
}, {
|
|
596
|
-
keyId: "https://example.com/multikey",
|
|
597
|
-
standaloneKey: ed25519Multikey,
|
|
598
|
-
fetch: (keyId, options) => fetchKey(keyId, Multikey, options)
|
|
599
|
-
}]) {
|
|
600
|
-
const cache = {};
|
|
601
|
-
const options = {
|
|
602
|
-
async documentLoader(resource) {
|
|
603
|
-
if (resource === keyId) return {
|
|
604
|
-
contextUrl: null,
|
|
605
|
-
documentUrl: resource,
|
|
606
|
-
document: {
|
|
607
|
-
...await standaloneKey.toJsonLd({ contextLoader: mockDocumentLoader }),
|
|
608
|
-
id: "https://example.com/different-key"
|
|
609
|
-
}
|
|
610
|
-
};
|
|
611
|
-
return await mockDocumentLoader(resource);
|
|
612
|
-
},
|
|
613
|
-
contextLoader: mockDocumentLoader,
|
|
614
|
-
keyCache: {
|
|
615
|
-
get(keyId) {
|
|
616
|
-
return Promise.resolve(cache[keyId.href]);
|
|
617
|
-
},
|
|
618
|
-
set(keyId, key) {
|
|
619
|
-
cache[keyId.href] = key;
|
|
620
|
-
return Promise.resolve();
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
};
|
|
624
|
-
assertEquals(await fetch(keyId, options), {
|
|
625
|
-
key: null,
|
|
626
|
-
cached: false
|
|
627
|
-
});
|
|
628
|
-
assertEquals(cache, { [keyId]: null });
|
|
629
|
-
assertEquals(await fetch(keyId, options), {
|
|
630
|
-
key: null,
|
|
631
|
-
cached: true
|
|
632
|
-
});
|
|
633
|
-
}
|
|
634
|
-
});
|
|
635
|
-
test("fetchKey() returns null for a malformed actor publicKey", async () => {
|
|
636
|
-
const actorId = "https://example.com/malformed-public-key";
|
|
637
|
-
const keyId = "https://example.com/malformed-public-key#main-key";
|
|
638
|
-
const cache = {};
|
|
639
|
-
const options = {
|
|
640
|
-
async documentLoader(resource) {
|
|
641
|
-
if (resource === actorId) return {
|
|
642
|
-
contextUrl: null,
|
|
643
|
-
documentUrl: resource,
|
|
644
|
-
document: {
|
|
645
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
646
|
-
id: actorId,
|
|
647
|
-
type: "Person",
|
|
648
|
-
publicKey: keyId
|
|
649
|
-
}
|
|
650
|
-
};
|
|
651
|
-
if (resource === keyId) return {
|
|
652
|
-
contextUrl: null,
|
|
653
|
-
documentUrl: resource,
|
|
654
|
-
document: {
|
|
655
|
-
"@context": "https://w3id.org/security/v1",
|
|
656
|
-
id: keyId,
|
|
657
|
-
type: "Key",
|
|
658
|
-
owner: actorId,
|
|
659
|
-
publicKeyPem: "not a public key"
|
|
660
|
-
}
|
|
661
|
-
};
|
|
662
|
-
return await mockDocumentLoader(resource);
|
|
663
|
-
},
|
|
664
|
-
contextLoader: mockDocumentLoader,
|
|
665
|
-
keyCache: {
|
|
666
|
-
get(keyId) {
|
|
667
|
-
return Promise.resolve(cache[keyId.href]);
|
|
668
|
-
},
|
|
669
|
-
set(keyId, key) {
|
|
670
|
-
cache[keyId.href] = key;
|
|
671
|
-
return Promise.resolve();
|
|
672
|
-
}
|
|
673
|
-
}
|
|
674
|
-
};
|
|
675
|
-
assertEquals(await fetchKey(actorId, CryptographicKey, options), {
|
|
676
|
-
key: null,
|
|
677
|
-
cached: false
|
|
678
|
-
});
|
|
679
|
-
assertEquals(cache, { [actorId]: null });
|
|
680
|
-
assertEquals(await fetchKey(actorId, CryptographicKey, options), {
|
|
681
|
-
key: null,
|
|
682
|
-
cached: true
|
|
683
|
-
});
|
|
684
|
-
});
|
|
685
|
-
for (const cls of [CryptographicKey, Multikey]) for (const location of [
|
|
686
|
-
"actor",
|
|
687
|
-
"key",
|
|
688
|
-
"owner"
|
|
689
|
-
]) test(`fetchKey() handles JSON-LD context failures in ${cls.name} ${location} documents`, async (t) => {
|
|
690
|
-
const actorId = new URL("https://example.com/context-actor");
|
|
691
|
-
const keyId = new URL(`${actorId.href}#key`);
|
|
692
|
-
const key = cls === CryptographicKey ? rsaPublicKey1.clone({
|
|
693
|
-
id: keyId,
|
|
694
|
-
owner: actorId
|
|
695
|
-
}) : ed25519Multikey.clone({
|
|
696
|
-
id: keyId,
|
|
697
|
-
controller: actorId
|
|
698
|
-
});
|
|
699
|
-
const actorDocument = await new Person({
|
|
700
|
-
id: actorId,
|
|
701
|
-
...key instanceof CryptographicKey ? { publicKeys: [key] } : { assertionMethods: [key] }
|
|
702
|
-
}).toJsonLd({ contextLoader: mockDocumentLoader });
|
|
703
|
-
const keyDocument = await key.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
704
|
-
const contextUrl = `https://example.com/context/${cls.name}/${location}`;
|
|
705
|
-
const transportErrors = [
|
|
706
|
-
/* @__PURE__ */ new TypeError("fetch failed"),
|
|
707
|
-
/* @__PURE__ */ new TypeError("error reading a body from connection"),
|
|
708
|
-
globalThis.Object.assign(/* @__PURE__ */ new TypeError("The socket connection was closed unexpectedly."), { code: "ECONNRESET" }),
|
|
709
|
-
globalThis.Object.assign(/* @__PURE__ */ new TypeError("Network request failed"), { code: "ECONNRESET" }),
|
|
710
|
-
new TypeError("Network request failed", { cause: globalThis.Object.assign(/* @__PURE__ */ new Error("connection refused"), { code: "ECONNREFUSED" }) }),
|
|
711
|
-
new FetchError(contextUrl, "HTTP 503"),
|
|
712
|
-
new FetchError(contextUrl, "HTTP 503", new Response("unavailable", { status: 503 })),
|
|
713
|
-
new UrlError("DNS lookup failed", { reason: "dns" }),
|
|
714
|
-
globalThis.Object.assign(/* @__PURE__ */ new Error("request aborted"), { name: "AbortError" })
|
|
715
|
-
];
|
|
716
|
-
const programmingErrors = [
|
|
717
|
-
/* @__PURE__ */ new Error("loader bug"),
|
|
718
|
-
/* @__PURE__ */ new ReferenceError("loader bug"),
|
|
719
|
-
/* @__PURE__ */ new TypeError("loader bug"),
|
|
720
|
-
"loader bug",
|
|
721
|
-
null,
|
|
722
|
-
void 0
|
|
723
|
-
];
|
|
724
|
-
const cases = [
|
|
725
|
-
{ kind: "inline" },
|
|
726
|
-
{
|
|
727
|
-
kind: "url",
|
|
728
|
-
wrapped: false
|
|
729
|
-
},
|
|
730
|
-
{
|
|
731
|
-
kind: "url",
|
|
732
|
-
wrapped: true
|
|
733
|
-
},
|
|
734
|
-
{
|
|
735
|
-
kind: "wrapped",
|
|
736
|
-
error: /* @__PURE__ */ new TypeError("Invalid URL string.")
|
|
737
|
-
},
|
|
738
|
-
{
|
|
739
|
-
kind: "remote",
|
|
740
|
-
document: 123
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
kind: "remote",
|
|
744
|
-
document: "not JSON"
|
|
745
|
-
},
|
|
746
|
-
{
|
|
747
|
-
kind: "remote",
|
|
748
|
-
document: { "@context": contextUrl }
|
|
749
|
-
},
|
|
750
|
-
...transportErrors.map((error) => ({
|
|
751
|
-
kind: "transport",
|
|
752
|
-
error
|
|
753
|
-
})),
|
|
754
|
-
...programmingErrors.map((error) => ({
|
|
755
|
-
kind: "programming",
|
|
756
|
-
error
|
|
757
|
-
})),
|
|
758
|
-
...location === "key" ? [{
|
|
759
|
-
kind: "transport",
|
|
760
|
-
error: /* @__PURE__ */ new TypeError("fetch failed"),
|
|
761
|
-
fallback: true
|
|
762
|
-
}, {
|
|
763
|
-
kind: "programming",
|
|
764
|
-
error: /* @__PURE__ */ new ReferenceError("fallback bug"),
|
|
765
|
-
fallback: true
|
|
766
|
-
}] : []
|
|
767
|
-
];
|
|
768
|
-
for (const scenario of cases) {
|
|
769
|
-
const description = "error" in scenario ? scenario.error instanceof Error ? `${scenario.error.name}: ${scenario.error.message}` : String(scenario.error) : "document" in scenario ? JSON.stringify(scenario.document) : "invalid type mapping";
|
|
770
|
-
await t.step(`${scenario.kind}: ${description}${"fallback" in scenario ? " (fallback)" : ""}`, async () => {
|
|
771
|
-
const cache = {};
|
|
772
|
-
let fetchError = { error: /* @__PURE__ */ new Error("stale fetch error") };
|
|
773
|
-
const [meterProvider, recorder] = createTestMeterProvider();
|
|
774
|
-
let recovered = false;
|
|
775
|
-
let contextLoads = 0;
|
|
776
|
-
const options = {
|
|
777
|
-
meterProvider,
|
|
778
|
-
documentLoader(resource) {
|
|
779
|
-
const document = structuredClone(resource === keyId.href && location !== "actor" ? keyDocument : actorDocument);
|
|
780
|
-
if (location === "actor" || location === "key" && resource === keyId.href || location === "owner" && resource === actorId.href) {
|
|
781
|
-
const context = scenario.kind === "inline" ? { broken: {
|
|
782
|
-
"@id": "https://example.com/ns#broken",
|
|
783
|
-
"@type": "not-an-absolute-iri"
|
|
784
|
-
} } : scenario.kind === "url" ? "http://[" : contextUrl;
|
|
785
|
-
document["@context"] = [document["@context"], context].flat();
|
|
786
|
-
}
|
|
787
|
-
return Promise.resolve({
|
|
788
|
-
contextUrl: null,
|
|
789
|
-
documentUrl: resource,
|
|
790
|
-
document
|
|
791
|
-
});
|
|
792
|
-
},
|
|
793
|
-
async contextLoader(resource) {
|
|
794
|
-
if (scenario.kind === "url" && resource === "http://[") {
|
|
795
|
-
const loader = getDocumentLoader();
|
|
796
|
-
return await (scenario.wrapped ? wrapContextLoaderForJsonLd(loader) : loader)(resource);
|
|
797
|
-
}
|
|
798
|
-
if (scenario.kind === "wrapped" && resource === contextUrl) return await wrapContextLoaderForJsonLd(() => Promise.reject(scenario.error))(resource);
|
|
799
|
-
if (resource !== contextUrl) return await mockDocumentLoader(resource);
|
|
800
|
-
contextLoads++;
|
|
801
|
-
if (!recovered && "error" in scenario && (!("fallback" in scenario) || contextLoads > 1)) throw scenario.error;
|
|
802
|
-
return {
|
|
803
|
-
contextUrl: null,
|
|
804
|
-
documentUrl: resource,
|
|
805
|
-
document: !recovered && "document" in scenario ? scenario.document : { "@context": {} }
|
|
806
|
-
};
|
|
807
|
-
},
|
|
808
|
-
keyCache: {
|
|
809
|
-
get: (id) => Promise.resolve(cache[id.href]),
|
|
810
|
-
set(id, value) {
|
|
811
|
-
cache[id.href] = value;
|
|
812
|
-
return Promise.resolve();
|
|
813
|
-
},
|
|
814
|
-
getFetchError: () => Promise.resolve(fetchError),
|
|
815
|
-
setFetchError(_id, error) {
|
|
816
|
-
fetchError = error ?? void 0;
|
|
817
|
-
return Promise.resolve();
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
const lookup = () => fetchKey(keyId, cls, options);
|
|
822
|
-
if (scenario.kind === "programming" && "error" in scenario) {
|
|
823
|
-
assertStrictEquals(await assertRejects(lookup), scenario.error);
|
|
824
|
-
assertEquals(cache, {});
|
|
825
|
-
assertStrictEquals(await assertRejects(() => fetchKeyDetailed(keyId, cls, options)), scenario.error);
|
|
826
|
-
assertEquals(cache, {});
|
|
827
|
-
return;
|
|
828
|
-
}
|
|
829
|
-
assertEquals(await lookup(), {
|
|
830
|
-
key: null,
|
|
831
|
-
cached: false
|
|
832
|
-
});
|
|
833
|
-
if (scenario.kind === "transport") {
|
|
834
|
-
const counter = recorder.getMeasurement("activitypub.key.lookup");
|
|
835
|
-
const duration = recorder.getMeasurement("activitypub.key.lookup.duration");
|
|
836
|
-
const status = scenario.error instanceof FetchError ? scenario.error.response?.status : void 0;
|
|
837
|
-
const expected = status != null ? "error" : scenario.error instanceof TypeError || scenario.error instanceof FetchError || scenario.error instanceof Error && scenario.error.name === "AbortError" ? "network_error" : "error";
|
|
838
|
-
assertEquals(counter?.attributes["activitypub.lookup.result"], expected);
|
|
839
|
-
assertEquals(duration?.attributes["activitypub.lookup.result"], expected);
|
|
840
|
-
assertEquals(counter?.attributes["http.response.status_code"], status);
|
|
841
|
-
}
|
|
842
|
-
assertEquals(cache, { [keyId.href]: null });
|
|
843
|
-
const detailed = await fetchKeyDetailed(keyId, cls, options);
|
|
844
|
-
assertEquals(detailed.cached, true);
|
|
845
|
-
if (scenario.kind === "transport" || scenario.kind === "wrapped") {
|
|
846
|
-
assert(detailed.fetchError != null);
|
|
847
|
-
if (scenario.error instanceof FetchError && scenario.error.response != null) {
|
|
848
|
-
assert("status" in detailed.fetchError);
|
|
849
|
-
assertEquals(detailed.fetchError.status, 503);
|
|
850
|
-
assertEquals(await detailed.fetchError.response.text(), "unavailable");
|
|
851
|
-
} else {
|
|
852
|
-
assert("error" in detailed.fetchError);
|
|
853
|
-
assertStrictEquals(detailed.fetchError.error, scenario.error);
|
|
854
|
-
}
|
|
855
|
-
} else assertEquals(detailed.fetchError, void 0);
|
|
856
|
-
const previousLoads = contextLoads;
|
|
857
|
-
assertEquals(await lookup(), {
|
|
858
|
-
key: null,
|
|
859
|
-
cached: true
|
|
860
|
-
});
|
|
861
|
-
assertEquals(contextLoads, previousLoads);
|
|
862
|
-
delete cache[keyId.href];
|
|
863
|
-
fetchError = void 0;
|
|
864
|
-
const fresh = await fetchKeyDetailed(keyId, cls, options);
|
|
865
|
-
assertEquals(fresh.cached, false);
|
|
866
|
-
assertEquals(fresh.key, null);
|
|
867
|
-
if (scenario.kind === "transport" || scenario.kind === "wrapped") {
|
|
868
|
-
assert(fresh.fetchError != null);
|
|
869
|
-
if (scenario.error instanceof FetchError && scenario.error.response != null) {
|
|
870
|
-
assert("status" in fresh.fetchError);
|
|
871
|
-
assertEquals(fresh.fetchError.status, 503);
|
|
872
|
-
assertEquals(await fresh.fetchError.response.text(), "unavailable");
|
|
873
|
-
} else {
|
|
874
|
-
assert("error" in fresh.fetchError);
|
|
875
|
-
assertStrictEquals(fresh.fetchError.error, scenario.error);
|
|
876
|
-
}
|
|
877
|
-
} else assertEquals(fresh.fetchError, void 0);
|
|
878
|
-
if (scenario.kind === "transport") {
|
|
879
|
-
delete cache[keyId.href];
|
|
880
|
-
recovered = true;
|
|
881
|
-
const result = await lookup();
|
|
882
|
-
assertEquals(result.cached, false);
|
|
883
|
-
assertEquals(result.key?.id, keyId);
|
|
884
|
-
assert(result.key?.publicKey != null);
|
|
885
|
-
}
|
|
886
|
-
});
|
|
887
|
-
}
|
|
888
|
-
});
|
|
889
|
-
test("fetchKey() rejects a key whose owner does not link back", async () => {
|
|
890
|
-
const keyId = "https://attacker.example/key";
|
|
891
|
-
const keyDocument = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
892
|
-
const serveKeyOwnedBy = (owner) => ({
|
|
893
|
-
documentLoader(resource) {
|
|
894
|
-
if (resource === keyId) return Promise.resolve({
|
|
895
|
-
contextUrl: null,
|
|
896
|
-
documentUrl: resource,
|
|
897
|
-
document: {
|
|
898
|
-
...keyDocument,
|
|
899
|
-
id: keyId,
|
|
900
|
-
owner
|
|
901
|
-
}
|
|
902
|
-
});
|
|
903
|
-
return mockDocumentLoader(resource);
|
|
904
|
-
},
|
|
905
|
-
contextLoader: mockDocumentLoader
|
|
906
|
-
});
|
|
907
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, serveKeyOwnedBy("https://example.com/person")), {
|
|
908
|
-
key: null,
|
|
909
|
-
cached: false
|
|
910
|
-
});
|
|
911
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, serveKeyOwnedBy("https://impersonated.invalid/users/victim")), {
|
|
912
|
-
key: null,
|
|
913
|
-
cached: false
|
|
914
|
-
});
|
|
915
|
-
});
|
|
916
|
-
test("fetchKey() rejects a Multikey whose controller does not link back", async () => {
|
|
917
|
-
const keyId = "https://attacker.example/multikey";
|
|
918
|
-
const keyDocument = await ed25519Multikey.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
919
|
-
assertEquals(await fetchKey(keyId, Multikey, {
|
|
920
|
-
documentLoader(resource) {
|
|
921
|
-
if (resource === keyId) return Promise.resolve({
|
|
922
|
-
contextUrl: null,
|
|
923
|
-
documentUrl: resource,
|
|
924
|
-
document: {
|
|
925
|
-
...keyDocument,
|
|
926
|
-
id: keyId,
|
|
927
|
-
controller: "https://example.com/person2"
|
|
928
|
-
}
|
|
929
|
-
});
|
|
930
|
-
return mockDocumentLoader(resource);
|
|
931
|
-
},
|
|
932
|
-
contextLoader: mockDocumentLoader
|
|
933
|
-
}), {
|
|
934
|
-
key: null,
|
|
935
|
-
cached: false
|
|
936
|
-
});
|
|
937
|
-
});
|
|
938
|
-
test("fetchKey() rejects an actor document from another origin", async () => {
|
|
939
|
-
const keyId = "https://attacker.example/key";
|
|
940
|
-
const impersonated = "https://example.com/person";
|
|
941
|
-
const { publicKeyPem } = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
942
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, {
|
|
943
|
-
documentLoader(resource) {
|
|
944
|
-
if (resource === keyId) return Promise.resolve({
|
|
945
|
-
contextUrl: null,
|
|
946
|
-
documentUrl: resource,
|
|
947
|
-
document: {
|
|
948
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
949
|
-
id: impersonated,
|
|
950
|
-
type: "Person",
|
|
951
|
-
publicKey: [{
|
|
952
|
-
id: `${impersonated}#main-key`,
|
|
953
|
-
type: "CryptographicKey",
|
|
954
|
-
owner: impersonated,
|
|
955
|
-
publicKeyPem
|
|
956
|
-
}]
|
|
957
|
-
}
|
|
958
|
-
});
|
|
959
|
-
return mockDocumentLoader(resource);
|
|
960
|
-
},
|
|
961
|
-
contextLoader: mockDocumentLoader
|
|
962
|
-
}), {
|
|
963
|
-
key: null,
|
|
964
|
-
cached: false
|
|
965
|
-
});
|
|
966
|
-
});
|
|
967
|
-
test("fetchKey() rejects a key that disowns the actor document holding it", async () => {
|
|
968
|
-
const actorId = "https://attacker.example/actor";
|
|
969
|
-
const keyId = `${actorId}#main-key`;
|
|
970
|
-
const { publicKeyPem } = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
971
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, {
|
|
972
|
-
documentLoader(resource) {
|
|
973
|
-
if (resource === keyId || resource === actorId) return Promise.resolve({
|
|
974
|
-
contextUrl: null,
|
|
975
|
-
documentUrl: resource,
|
|
976
|
-
document: {
|
|
977
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
978
|
-
id: actorId,
|
|
979
|
-
type: "Person",
|
|
980
|
-
publicKey: [{
|
|
981
|
-
id: keyId,
|
|
982
|
-
type: "CryptographicKey",
|
|
983
|
-
owner: "https://example.com/person",
|
|
984
|
-
publicKeyPem
|
|
985
|
-
}]
|
|
986
|
-
}
|
|
987
|
-
});
|
|
988
|
-
return mockDocumentLoader(resource);
|
|
989
|
-
},
|
|
990
|
-
contextLoader: mockDocumentLoader
|
|
991
|
-
}), {
|
|
992
|
-
key: null,
|
|
993
|
-
cached: false
|
|
994
|
-
});
|
|
995
|
-
});
|
|
996
|
-
test("fetchKey() records the owner its actor document establishes", async () => {
|
|
997
|
-
const { key } = await fetchKey("https://example.com/users/handle#main-key", CryptographicKey, {
|
|
998
|
-
documentLoader: mockDocumentLoader,
|
|
999
|
-
contextLoader: mockDocumentLoader
|
|
1000
|
-
});
|
|
1001
|
-
assertEquals(key?.ownerId, new URL("https://example.com/users/handle"));
|
|
1002
|
-
});
|
|
1003
|
-
test("fetchKey() accepts a key document that leaves its id implicit", async () => {
|
|
1004
|
-
const keyId = "https://example.com/key";
|
|
1005
|
-
const keyDocument = await rsaPublicKey1.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1006
|
-
delete keyDocument.id;
|
|
1007
|
-
const { key } = await fetchKey(keyId, CryptographicKey, {
|
|
1008
|
-
documentLoader(resource) {
|
|
1009
|
-
if (resource === keyId) return Promise.resolve({
|
|
1010
|
-
contextUrl: null,
|
|
1011
|
-
documentUrl: resource,
|
|
1012
|
-
document: keyDocument
|
|
1013
|
-
});
|
|
1014
|
-
return mockDocumentLoader(resource);
|
|
1015
|
-
},
|
|
1016
|
-
contextLoader: mockDocumentLoader
|
|
1017
|
-
});
|
|
1018
|
-
assertEquals(key?.id, new URL(keyId));
|
|
1019
|
-
assertEquals(key?.ownerId, new URL("https://example.com/person"));
|
|
1020
|
-
assert(key?.publicKey != null);
|
|
1021
|
-
});
|
|
1022
|
-
test("fetchKey() records the controller an actor document establishes", async () => {
|
|
1023
|
-
const actorId = "https://example.com/multikey-actor";
|
|
1024
|
-
const keyId = `${actorId}#assertion`;
|
|
1025
|
-
const { publicKeyMultibase } = await ed25519Multikey.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1026
|
-
const { key } = await fetchKey(keyId, Multikey, {
|
|
1027
|
-
documentLoader(resource) {
|
|
1028
|
-
if (resource === actorId || resource === keyId) return Promise.resolve({
|
|
1029
|
-
contextUrl: null,
|
|
1030
|
-
documentUrl: actorId,
|
|
1031
|
-
document: {
|
|
1032
|
-
"@context": [
|
|
1033
|
-
"https://www.w3.org/ns/activitystreams",
|
|
1034
|
-
"https://w3id.org/security/v1",
|
|
1035
|
-
"https://w3id.org/security/multikey/v1",
|
|
1036
|
-
"https://w3id.org/security/data-integrity/v1",
|
|
1037
|
-
"https://www.w3.org/ns/did/v1"
|
|
1038
|
-
],
|
|
1039
|
-
id: actorId,
|
|
1040
|
-
type: "Person",
|
|
1041
|
-
assertionMethod: [{
|
|
1042
|
-
id: keyId,
|
|
1043
|
-
type: "Multikey",
|
|
1044
|
-
publicKeyMultibase
|
|
1045
|
-
}]
|
|
1046
|
-
}
|
|
1047
|
-
});
|
|
1048
|
-
return mockDocumentLoader(resource);
|
|
1049
|
-
},
|
|
1050
|
-
contextLoader: mockDocumentLoader
|
|
1051
|
-
});
|
|
1052
|
-
assertEquals(key?.controllerId, new URL(actorId));
|
|
1053
|
-
assert(key?.publicKey != null);
|
|
1054
|
-
});
|
|
1055
|
-
test("fetchKey() rejects a key whose owner redirects to another actor", async () => {
|
|
1056
|
-
const keyId = "https://evil.example/keys/1";
|
|
1057
|
-
const victim = "https://victim.example/users/alice";
|
|
1058
|
-
const mallory = "https://evil.example/users/mallory";
|
|
1059
|
-
const { publicKeyPem } = await rsaPublicKey3.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1060
|
-
const cache = {};
|
|
1061
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, {
|
|
1062
|
-
documentLoader(resource) {
|
|
1063
|
-
if (resource === keyId) return Promise.resolve({
|
|
1064
|
-
contextUrl: null,
|
|
1065
|
-
documentUrl: resource,
|
|
1066
|
-
document: {
|
|
1067
|
-
"@context": "https://w3id.org/security/v1",
|
|
1068
|
-
id: keyId,
|
|
1069
|
-
type: "CryptographicKey",
|
|
1070
|
-
owner: victim,
|
|
1071
|
-
publicKeyPem
|
|
1072
|
-
}
|
|
1073
|
-
});
|
|
1074
|
-
if (resource === victim || resource === mallory) return Promise.resolve({
|
|
1075
|
-
contextUrl: null,
|
|
1076
|
-
documentUrl: mallory,
|
|
1077
|
-
document: {
|
|
1078
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
1079
|
-
id: mallory,
|
|
1080
|
-
type: "Person",
|
|
1081
|
-
publicKey: keyId
|
|
1082
|
-
}
|
|
1083
|
-
});
|
|
1084
|
-
return mockDocumentLoader(resource);
|
|
1085
|
-
},
|
|
1086
|
-
contextLoader: mockDocumentLoader,
|
|
1087
|
-
keyCache: {
|
|
1088
|
-
get(keyId) {
|
|
1089
|
-
return Promise.resolve(cache[keyId.href]);
|
|
1090
|
-
},
|
|
1091
|
-
set(keyId, key) {
|
|
1092
|
-
cache[keyId.href] = key;
|
|
1093
|
-
return Promise.resolve();
|
|
1094
|
-
}
|
|
1095
|
-
}
|
|
1096
|
-
}), {
|
|
1097
|
-
key: null,
|
|
1098
|
-
cached: false
|
|
1099
|
-
});
|
|
1100
|
-
assertEquals(cache, { [keyId]: null });
|
|
1101
|
-
});
|
|
1102
|
-
test("fetchKey() rejects a key whose owner resolves to another actor on the same origin", async () => {
|
|
1103
|
-
const keyId = "https://victim.example/keys/bob";
|
|
1104
|
-
const victim = "https://victim.example/users/alice";
|
|
1105
|
-
const bob = "https://victim.example/users/bob";
|
|
1106
|
-
const { publicKeyPem } = await rsaPublicKey3.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1107
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, {
|
|
1108
|
-
documentLoader(resource) {
|
|
1109
|
-
if (resource === keyId) return Promise.resolve({
|
|
1110
|
-
contextUrl: null,
|
|
1111
|
-
documentUrl: resource,
|
|
1112
|
-
document: {
|
|
1113
|
-
"@context": "https://w3id.org/security/v1",
|
|
1114
|
-
id: keyId,
|
|
1115
|
-
type: "CryptographicKey",
|
|
1116
|
-
owner: victim,
|
|
1117
|
-
publicKeyPem
|
|
1118
|
-
}
|
|
1119
|
-
});
|
|
1120
|
-
if (resource === victim || resource === bob) return Promise.resolve({
|
|
1121
|
-
contextUrl: null,
|
|
1122
|
-
documentUrl: resource,
|
|
1123
|
-
document: {
|
|
1124
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
1125
|
-
id: bob,
|
|
1126
|
-
type: "Person",
|
|
1127
|
-
publicKey: keyId
|
|
1128
|
-
}
|
|
1129
|
-
});
|
|
1130
|
-
return mockDocumentLoader(resource);
|
|
1131
|
-
},
|
|
1132
|
-
contextLoader: mockDocumentLoader
|
|
1133
|
-
}), {
|
|
1134
|
-
key: null,
|
|
1135
|
-
cached: false
|
|
1136
|
-
});
|
|
1137
|
-
});
|
|
1138
|
-
test("fetchKey() rejects a Multikey whose controller redirects to another actor", async () => {
|
|
1139
|
-
const keyId = "https://evil.example/keys/ed25519";
|
|
1140
|
-
const victim = "https://victim.example/users/alice";
|
|
1141
|
-
const mallory = "https://evil.example/users/mallory";
|
|
1142
|
-
const multikeyDocument = await ed25519Multikey.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1143
|
-
assertEquals(await fetchKey(keyId, Multikey, {
|
|
1144
|
-
documentLoader(resource) {
|
|
1145
|
-
if (resource === keyId) return Promise.resolve({
|
|
1146
|
-
contextUrl: null,
|
|
1147
|
-
documentUrl: resource,
|
|
1148
|
-
document: {
|
|
1149
|
-
...multikeyDocument,
|
|
1150
|
-
id: keyId,
|
|
1151
|
-
controller: victim
|
|
1152
|
-
}
|
|
1153
|
-
});
|
|
1154
|
-
if (resource === victim || resource === mallory) return Promise.resolve({
|
|
1155
|
-
contextUrl: null,
|
|
1156
|
-
documentUrl: mallory,
|
|
1157
|
-
document: {
|
|
1158
|
-
"@context": [
|
|
1159
|
-
"https://www.w3.org/ns/activitystreams",
|
|
1160
|
-
"https://w3id.org/security/v1",
|
|
1161
|
-
"https://w3id.org/security/multikey/v1",
|
|
1162
|
-
"https://w3id.org/security/data-integrity/v1",
|
|
1163
|
-
"https://www.w3.org/ns/did/v1"
|
|
1164
|
-
],
|
|
1165
|
-
id: mallory,
|
|
1166
|
-
type: "Person",
|
|
1167
|
-
assertionMethod: [keyId]
|
|
1168
|
-
}
|
|
1169
|
-
});
|
|
1170
|
-
return mockDocumentLoader(resource);
|
|
1171
|
-
},
|
|
1172
|
-
contextLoader: mockDocumentLoader
|
|
1173
|
-
}), {
|
|
1174
|
-
key: null,
|
|
1175
|
-
cached: false
|
|
1176
|
-
});
|
|
1177
|
-
});
|
|
1178
|
-
test("fetchKey() accepts an owner whose document URL differs from its id", async () => {
|
|
1179
|
-
const keyId = "https://victim.example/keys/alice";
|
|
1180
|
-
const alice = "https://victim.example/users/alice";
|
|
1181
|
-
const { publicKeyPem } = await rsaPublicKey3.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1182
|
-
const { key, cached } = await fetchKey(keyId, CryptographicKey, {
|
|
1183
|
-
documentLoader(resource) {
|
|
1184
|
-
if (resource === keyId) return Promise.resolve({
|
|
1185
|
-
contextUrl: null,
|
|
1186
|
-
documentUrl: resource,
|
|
1187
|
-
document: {
|
|
1188
|
-
"@context": "https://w3id.org/security/v1",
|
|
1189
|
-
id: keyId,
|
|
1190
|
-
type: "CryptographicKey",
|
|
1191
|
-
owner: alice,
|
|
1192
|
-
publicKeyPem
|
|
1193
|
-
}
|
|
1194
|
-
});
|
|
1195
|
-
if (resource === alice) return Promise.resolve({
|
|
1196
|
-
contextUrl: null,
|
|
1197
|
-
documentUrl: `${alice}.json`,
|
|
1198
|
-
document: {
|
|
1199
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
1200
|
-
id: alice,
|
|
1201
|
-
type: "Person",
|
|
1202
|
-
publicKey: keyId
|
|
1203
|
-
}
|
|
1204
|
-
});
|
|
1205
|
-
return mockDocumentLoader(resource);
|
|
1206
|
-
},
|
|
1207
|
-
contextLoader: mockDocumentLoader
|
|
1208
|
-
});
|
|
1209
|
-
assertFalse(cached);
|
|
1210
|
-
assertEquals(key?.id, new URL(keyId));
|
|
1211
|
-
assertEquals(key?.ownerId, new URL(alice));
|
|
1212
|
-
});
|
|
1213
|
-
test("fetchKey() rejects an owner reached through a normalization redirect", async () => {
|
|
1214
|
-
const keyId = "https://victim.example/keys/alice";
|
|
1215
|
-
const canonical = "https://victim.example/users/alice";
|
|
1216
|
-
const nonCanonical = "https://victim.example/users/Alice";
|
|
1217
|
-
const { publicKeyPem } = await rsaPublicKey3.toJsonLd({ contextLoader: mockDocumentLoader });
|
|
1218
|
-
assertEquals(await fetchKey(keyId, CryptographicKey, {
|
|
1219
|
-
documentLoader(resource) {
|
|
1220
|
-
if (resource === keyId) return Promise.resolve({
|
|
1221
|
-
contextUrl: null,
|
|
1222
|
-
documentUrl: resource,
|
|
1223
|
-
document: {
|
|
1224
|
-
"@context": "https://w3id.org/security/v1",
|
|
1225
|
-
id: keyId,
|
|
1226
|
-
type: "CryptographicKey",
|
|
1227
|
-
owner: nonCanonical,
|
|
1228
|
-
publicKeyPem
|
|
1229
|
-
}
|
|
1230
|
-
});
|
|
1231
|
-
if (resource === canonical || resource === nonCanonical) return Promise.resolve({
|
|
1232
|
-
contextUrl: null,
|
|
1233
|
-
documentUrl: canonical,
|
|
1234
|
-
document: {
|
|
1235
|
-
"@context": ["https://www.w3.org/ns/activitystreams", "https://w3id.org/security/v1"],
|
|
1236
|
-
id: canonical,
|
|
1237
|
-
type: "Person",
|
|
1238
|
-
publicKey: keyId
|
|
1239
|
-
}
|
|
1240
|
-
});
|
|
1241
|
-
return mockDocumentLoader(resource);
|
|
1242
|
-
},
|
|
1243
|
-
contextLoader: mockDocumentLoader
|
|
1244
|
-
}), {
|
|
1245
|
-
key: null,
|
|
1246
|
-
cached: false
|
|
1247
|
-
});
|
|
1248
|
-
});
|
|
1249
|
-
//#endregion
|
|
1250
|
-
export {};
|