@fedify/fedify 2.0.36-dev.2647 → 2.0.36-dev.2729

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.
Files changed (71) hide show
  1. package/dist/{builder-Cv8baeaM.mjs → builder-DifMW7os.mjs} +3 -3
  2. package/dist/callback-CJd-aCRE.d.mts +2223 -0
  3. package/dist/compat/mod.d.cts +1 -1
  4. package/dist/compat/mod.d.ts +1 -1
  5. package/dist/compat/transformers.test.mjs +1 -1
  6. package/dist/{context-C00pWP8x.d.ts → context-CgpkmUFq.d.ts} +23 -12
  7. package/dist/{context-ao-qb3eP.d.cts → context-DGC1C_UU.d.cts} +23 -12
  8. package/dist/{deno-Bk4jrob6.mjs → deno-CZYDJcbZ.mjs} +1 -1
  9. package/dist/{docloader-w8xGNWvP.mjs → docloader-DXZDJeg3.mjs} +2 -2
  10. package/dist/federation/builder.test.mjs +1 -1
  11. package/dist/federation/handler.test.mjs +6 -6
  12. package/dist/federation/idempotency.test.mjs +2 -2
  13. package/dist/federation/inbox.test.mjs +1 -1
  14. package/dist/federation/middleware.test.mjs +105 -7
  15. package/dist/federation/mod.cjs +1 -1
  16. package/dist/federation/mod.d.cts +2 -2
  17. package/dist/federation/mod.d.ts +2 -2
  18. package/dist/federation/mod.js +1 -1
  19. package/dist/federation/send.test.mjs +3 -3
  20. package/dist/federation/temporal.test.mjs +1 -1
  21. package/dist/federation/webfinger.test.mjs +1 -1
  22. package/dist/{http-C1v_vvt4.js → http-6beU7KiN.js} +6 -4
  23. package/dist/{http-Cd8UD1ym.d.ts → http-B57wVmZ3.d.cts} +3 -3
  24. package/dist/{http-CDK9iAjb.mjs → http-BEyjd3P7.mjs} +6 -4
  25. package/dist/{http-B9ZWGTaN.cjs → http-CU9dab8F.cjs} +6 -4
  26. package/dist/{http-DFqAb11b.d.cts → http-CURWmZlP.d.ts} +3 -3
  27. package/dist/{inbox-DAm48Q_C.mjs → inbox-DO4a9FKE.mjs} +1 -1
  28. package/dist/{key-C8OKWl8g.mjs → key-DjCiTRyO.mjs} +3 -2
  29. package/dist/{kv-cache-BFFwfQPZ.cjs → kv-cache-DFybNxHG.cjs} +1 -1
  30. package/dist/{kv-cache-B1Y7_B63.js → kv-cache-DPBGlPnW.js} +1 -1
  31. package/dist/{ld-gUJKeHbH.mjs → ld-B5pG0yhd.mjs} +20 -7
  32. package/dist/{middleware-3t8hmtzt.cjs → middleware-Bdvdue5B.cjs} +1 -1
  33. package/dist/{middleware-D-DIq_jJ.js → middleware-BqQbaTiu.js} +15 -7
  34. package/dist/{middleware-_yMwRAE9.cjs → middleware-ClxSuYs7.cjs} +16 -8
  35. package/dist/{middleware-DLxdIffl.mjs → middleware-DnnYzTPv.mjs} +23 -14
  36. package/dist/{middleware-LgcMsPlF.mjs → middleware-Dsw0i5sQ.mjs} +1 -1
  37. package/dist/{mod-DtRh015i.d.ts → mod-BqnolIm8.d.ts} +1 -1
  38. package/dist/{mod-6uJWdCc0.d.cts → mod-BzKteaAe.d.cts} +1 -1
  39. package/dist/{mod-DGP89q0u.d.ts → mod-CIjZ1RmH.d.ts} +3 -3
  40. package/dist/{mod-BPDfu4Ey.d.cts → mod-DaQ6pIH3.d.cts} +3 -3
  41. package/dist/{mod-CL9Ep0uo.d.ts → mod-DmmcsbU8.d.cts} +12 -7
  42. package/dist/{mod-BA6vqC2S.d.cts → mod-fnE_D0lV.d.ts} +12 -7
  43. package/dist/mod.cjs +4 -4
  44. package/dist/mod.d.cts +7 -7
  45. package/dist/mod.d.ts +7 -7
  46. package/dist/mod.js +4 -4
  47. package/dist/nodeinfo/handler.test.mjs +1 -1
  48. package/dist/{owner-BenEndHH.mjs → owner-Dmlm2oR_.mjs} +2 -2
  49. package/dist/{proof-DF1RSNYg.cjs → proof-BGPhmUJL.cjs} +20 -7
  50. package/dist/{proof-BvtZYI3N.js → proof-iPBfQoMT.js} +20 -7
  51. package/dist/{proof-Bo9pmjQJ.mjs → proof-v76wU5Lv.mjs} +4 -3
  52. package/dist/{send-PTFa5PEa.mjs → send-C830qz95.mjs} +2 -2
  53. package/dist/sig/http.test.mjs +2 -2
  54. package/dist/sig/key-types.test.d.mts +218 -0
  55. package/dist/sig/key-types.test.mjs +8 -0
  56. package/dist/sig/key.test.mjs +2 -2
  57. package/dist/sig/ld.test.mjs +156 -4
  58. package/dist/sig/mod.cjs +2 -2
  59. package/dist/sig/mod.d.cts +3 -3
  60. package/dist/sig/mod.d.ts +3 -3
  61. package/dist/sig/mod.js +2 -2
  62. package/dist/sig/owner.test.mjs +1 -1
  63. package/dist/sig/proof.test.mjs +2 -2
  64. package/dist/{temporal-CNbx4A18.mjs → temporal-Bm5DL5mq.mjs} +1 -1
  65. package/dist/testing/mod.d.mts +2 -2123
  66. package/dist/utils/docloader.test.mjs +2 -2
  67. package/dist/utils/mod.cjs +1 -1
  68. package/dist/utils/mod.d.cts +1 -1
  69. package/dist/utils/mod.d.ts +1 -1
  70. package/dist/utils/mod.js +1 -1
  71. package/package.json +5 -5
@@ -0,0 +1,218 @@
1
+ import { Temporal } from "@js-temporal/polyfill";
2
+ import { URLPattern } from "urlpattern-polyfill";
3
+ import { a as ActorCallbackSetters, c as SenderKeyPair, d as exportJwk, l as HttpMessageSignaturesSpecDeterminer, n as Context, r as InboxContext, s as InboxListenerSetters, t as ActorKeyPairsDispatcher, u as signRequest } from "../callback-CJd-aCRE.mjs";
4
+ import { Activity, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1, Recipient } from "@fedify/vocab";
5
+ import { TracerProvider } from "@opentelemetry/api";
6
+ import { AuthenticatedDocumentLoaderFactory, CryptoKeyLike, CryptoKeyPairLike, DocumentLoader, DocumentLoaderFactoryOptions, exportMultibaseKey, exportSpki } from "@fedify/vocab-runtime";
7
+
8
+ //#region src/utils/docloader.d.ts
9
+ /**
10
+ * Options for {@link getAuthenticatedDocumentLoader}.
11
+ * @see {@link getAuthenticatedDocumentLoader}
12
+ * @since 1.3.0
13
+ */
14
+ interface GetAuthenticatedDocumentLoaderOptions extends DocumentLoaderFactoryOptions {
15
+ /**
16
+ * An optional spec determiner for HTTP Message Signatures.
17
+ * It determines the spec to use for signing requests.
18
+ * It is used for double-knocking
19
+ * (see <https://swicg.github.io/activitypub-http-signature/#how-to-upgrade-supported-versions>).
20
+ * @since 1.6.0
21
+ */
22
+ specDeterminer?: HttpMessageSignaturesSpecDeterminer;
23
+ /**
24
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
25
+ * is used.
26
+ * @since 1.6.0
27
+ */
28
+ tracerProvider?: TracerProvider;
29
+ }
30
+ /**
31
+ * Gets an authenticated {@link DocumentLoader} for the given identity.
32
+ * Note that an authenticated document loader intentionally does not cache
33
+ * the fetched documents.
34
+ * At most 20 HTTP redirects and alternate document links are followed in total
35
+ * per call. Revisiting a URL within that chain throws a {@link FetchError}.
36
+ * @param identity The identity to get the document loader for.
37
+ * The actor's key pair.
38
+ * @param options The options for the document loader.
39
+ * @returns The authenticated document loader.
40
+ * @throws {TypeError} If the key is invalid or unsupported.
41
+ * @since 0.4.0
42
+ */
43
+ declare function getAuthenticatedDocumentLoader(identity: {
44
+ keyId: URL;
45
+ privateKey: CryptoKeyLike;
46
+ }, options?: GetAuthenticatedDocumentLoaderOptions): DocumentLoader;
47
+ //#endregion
48
+ //#region src/sig/ld.d.ts
49
+ /**
50
+ * A signature of a JSON-LD document.
51
+ * @since 1.0.0
52
+ */
53
+ interface Signature {
54
+ "@context"?: "https://w3id.org/identity/v1" | "https://w3id.org/security/v1";
55
+ type: "RsaSignature2017";
56
+ id?: string;
57
+ creator: string;
58
+ created: string;
59
+ signatureValue: string;
60
+ }
61
+ /**
62
+ * Options for creating Linked Data Signatures.
63
+ * @since 1.0.0
64
+ */
65
+ interface CreateSignatureOptions {
66
+ /**
67
+ * The context loader for loading remote JSON-LD contexts.
68
+ */
69
+ contextLoader?: DocumentLoader;
70
+ /**
71
+ * The time when the signature was created. If not specified, the current
72
+ * time will be used.
73
+ */
74
+ created?: Temporal.Instant;
75
+ }
76
+ /**
77
+ * Creates a LD signature for the given JSON-LD document.
78
+ *
79
+ * If the document's context does not define the `signature` property, the
80
+ * signature is computed over the document with a minimal inline definition
81
+ * added. Use {@link attachSignature} to attach the signature to that exact
82
+ * document. Documents that already carry a `proof`, or whose context includes
83
+ * an unrecognized remote context, are hashed unchanged.
84
+ * @param jsonLd The JSON-LD document to sign.
85
+ * @param privateKey The private key to sign the document.
86
+ * @param keyId The ID of the public key that corresponds to the private key.
87
+ * @param options Additional options for creating the signature.
88
+ * See also {@link CreateSignatureOptions}.
89
+ * @return The created signature.
90
+ * @throws {TypeError} If the private key is invalid or unsupported.
91
+ * @since 1.0.0
92
+ */
93
+ declare function createSignature(jsonLd: unknown, privateKey: CryptoKeyLike, keyId: URL, {
94
+ contextLoader,
95
+ created
96
+ }?: CreateSignatureOptions): Promise<Signature>;
97
+ /**
98
+ * Options for signing JSON-LD documents.
99
+ * @since 1.0.0
100
+ */
101
+ interface SignJsonLdOptions extends CreateSignatureOptions {
102
+ /**
103
+ * The OpenTelemetry tracer provider for tracing the signing process.
104
+ * If omitted, the global tracer provider is used.
105
+ * @since 1.3.0
106
+ */
107
+ tracerProvider?: TracerProvider;
108
+ }
109
+ /**
110
+ * Signs the given JSON-LD document with the private key and returns the signed
111
+ * JSON-LD document.
112
+ * @param jsonLd The JSON-LD document to sign.
113
+ * @param privateKey The private key to sign the document.
114
+ * @param keyId The key ID to use in the signature. It will be used by the
115
+ * verifier to fetch the corresponding public key.
116
+ * @param options Additional options for signing the document.
117
+ * See also {@link SignJsonLdOptions}.
118
+ * @returns The signed JSON-LD document.
119
+ * @throws {TypeError} If the private key is invalid or unsupported.
120
+ * @since 1.0.0
121
+ */
122
+ declare function signJsonLd(jsonLd: unknown, privateKey: CryptoKeyLike, keyId: URL, options: SignJsonLdOptions): Promise<{
123
+ signature: Signature;
124
+ }>;
125
+ //#endregion
126
+ //#region src/sig/proof.d.ts
127
+ /**
128
+ * Options for {@link createProof}.
129
+ * @since 0.10.0
130
+ */
131
+ interface CreateProofOptions {
132
+ /**
133
+ * The context loader for loading remote JSON-LD contexts.
134
+ */
135
+ contextLoader?: DocumentLoader;
136
+ /**
137
+ * The JSON-LD context to use for serializing the object to sign.
138
+ */
139
+ context?: string | Record<string, string> | (string | Record<string, string>)[];
140
+ /**
141
+ * The time when the proof was created. If not specified, the current time
142
+ * will be used.
143
+ */
144
+ created?: Temporal.Instant;
145
+ }
146
+ /**
147
+ * Creates a proof for the given object.
148
+ * @param object The object to create a proof for.
149
+ * @param privateKey The private key to sign the proof with.
150
+ * @param keyId The key ID to use in the proof. It will be used by the verifier.
151
+ * @param options Additional options. See also {@link CreateProofOptions}.
152
+ * @returns The created proof.
153
+ * @throws {TypeError} If the private key is invalid or unsupported.
154
+ * @since 0.10.0
155
+ */
156
+ declare function createProof(object: Object$1, privateKey: CryptoKeyLike, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
157
+ /**
158
+ * Options for {@link signObject}.
159
+ * @since 0.10.0
160
+ */
161
+ interface SignObjectOptions extends CreateProofOptions {
162
+ /**
163
+ * The document loader for loading remote JSON-LD documents.
164
+ */
165
+ documentLoader?: DocumentLoader;
166
+ /**
167
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
168
+ * is used.
169
+ * @since 1.3.0
170
+ */
171
+ tracerProvider?: TracerProvider;
172
+ }
173
+ /**
174
+ * Signs the given object with the private key and returns the signed object.
175
+ * @param object The object to create a proof for.
176
+ * @param privateKey The private key to sign the proof with.
177
+ * @param keyId The key ID to use in the proof. It will be used by the verifier.
178
+ * @param options Additional options. See also {@link SignObjectOptions}.
179
+ * @returns The signed object.
180
+ * @throws {TypeError} If the private key is invalid or unsupported.
181
+ * @since 0.10.0
182
+ */
183
+ declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKeyLike, keyId: URL, options?: SignObjectOptions): Promise<T>;
184
+ //#endregion
185
+ //#region src/sig/key-types.test.d.ts
186
+ /**
187
+ * Asserts at compile time that `T` is assignable to `U`.
188
+ */
189
+ type AssertAssignable<T extends U, U> = T;
190
+ /**
191
+ * The key usages Node.js adds on top of the DOM and Web Worker ones since
192
+ * Node.js 24.7, when ML-KEM support was added to its Web Crypto API.
193
+ */
194
+ type NodeKeyUsage = KeyUsage | "encapsulateBits" | "decapsulateBits" | "encapsulateKey" | "decapsulateKey";
195
+ /**
196
+ * Mirrors `import("node:crypto").webcrypto.CryptoKey`, whose `usages` array
197
+ * has a wider element type than the ambient `CryptoKey`.
198
+ */
199
+ interface NodeCryptoKey extends Omit<CryptoKey, "usages"> {
200
+ readonly usages: NodeKeyUsage[];
201
+ }
202
+ /**
203
+ * Mirrors `import("node:crypto").webcrypto.CryptoKeyPair`.
204
+ */
205
+ interface NodeCryptoKeyPair {
206
+ readonly privateKey: NodeCryptoKey;
207
+ readonly publicKey: NodeCryptoKey;
208
+ }
209
+ /**
210
+ * These are compile-time assertions. A regression in any of the public
211
+ * signatures fails `deno check` even though nothing here runs.
212
+ */
213
+ type NodeKeyTypeChecks = [AssertAssignable<NodeCryptoKey, CryptoKeyLike>, AssertAssignable<NodeCryptoKeyPair, CryptoKeyPairLike>, AssertAssignable<(context: Context<void>, identifier: string) => NodeCryptoKeyPair[] | Promise<NodeCryptoKeyPair[]>, ActorKeyPairsDispatcher<void, CryptoKeyPairLike>>, AssertAssignable<ActorKeyPairsDispatcher<void, CryptoKeyPairLike>, Parameters<ActorCallbackSetters<void>["setKeyPairsDispatcher"]>[0]>, AssertAssignable<SenderKeyPair["privateKey"], CryptoKey>, AssertAssignable<NodeCryptoKey, SenderKeyPair<CryptoKeyLike>["privateKey"]>, AssertAssignable<(context: Context<void>) => SenderKeyPair<CryptoKeyLike>, Parameters<InboxListenerSetters<void>["setSharedKeyDispatcher"]>[0]>, AssertAssignable<Parameters<AuthenticatedDocumentLoaderFactory>[0]["privateKey"], CryptoKey>, AssertAssignable<NodeCryptoKey, Parameters<typeof getAuthenticatedDocumentLoader>[0]["privateKey"]>, AssertAssignable<NodeCryptoKey, Parameters<typeof signRequest>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof createProof>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof signObject>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof createSignature>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof signJsonLd>[1]>, AssertAssignable<NodeCryptoKey, Parameters<typeof exportJwk>[0]>, AssertAssignable<NodeCryptoKey, Parameters<typeof exportSpki>[0]>, AssertAssignable<NodeCryptoKey, Parameters<typeof exportMultibaseKey>[0]>, AssertAssignable<NodeCryptoKey, NonNullable<ConstructorParameters<typeof CryptographicKey>[0]["publicKey"]>>, AssertAssignable<NodeCryptoKey, NonNullable<ConstructorParameters<typeof Multikey>[0]["publicKey"]>>, AssertAssignable<NodeCryptoKey, NonNullable<NonNullable<Parameters<CryptographicKey["clone"]>[0]>["publicKey"]>>, AssertAssignable<NodeCryptoKey, NonNullable<NonNullable<Parameters<Multikey["clone"]>[0]>["publicKey"]>>, AssertAssignable<Context<void>["getDocumentLoader"], (identity: {
214
+ keyId: URL;
215
+ privateKey: NodeCryptoKey;
216
+ }) => unknown>, AssertAssignable<Context<void>["sendActivity"], (sender: SenderKeyPair<NodeCryptoKey>, recipients: Recipient, activity: Activity) => Promise<void>>, AssertAssignable<InboxContext<void>["forwardActivity"], (forwarder: SenderKeyPair<NodeCryptoKey>, recipients: Recipient) => Promise<void>>];
217
+ //#endregion
218
+ export { NodeKeyTypeChecks };
@@ -0,0 +1,8 @@
1
+ import "@js-temporal/polyfill";
2
+ import "urlpattern-polyfill";
3
+ globalThis.addEventListener = () => {};
4
+ import { test } from "@fedify/fixture";
5
+ //#region src/sig/key-types.test.ts
6
+ test("Node.js Web Crypto keys are accepted by the public key types", () => {});
7
+ //#endregion
8
+ export {};
@@ -6,9 +6,9 @@ import { n as assertStrictEquals } from "../std__assert-DflMZha5.mjs";
6
6
  import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as assert } from "../assert-BhQd8QHP.mjs";
8
8
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
9
- import { a as importJwk, i as generateCryptoKeyPair, o as validateCryptoKey, r as fetchKey, t as exportJwk } from "../key-C8OKWl8g.mjs";
9
+ import { a as importJwk, i as generateCryptoKeyPair, o as validateCryptoKey, r as fetchKey, t as exportJwk } from "../key-DjCiTRyO.mjs";
10
10
  import { c as rsaPublicKey3, i as rsaPrivateKey2, o as rsaPublicKey1, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
11
- import { g as wrapContextLoaderForJsonLd } from "../ld-gUJKeHbH.mjs";
11
+ import { g as wrapContextLoaderForJsonLd } from "../ld-B5pG0yhd.mjs";
12
12
  import { mockDocumentLoader, test } from "@fedify/fixture";
13
13
  import { CryptographicKey, Multikey, Person } from "@fedify/vocab";
14
14
  import { FetchError, UrlError, getDocumentLoader } from "@fedify/vocab-runtime";
@@ -5,11 +5,11 @@ import { t as assertEquals } from "../assert_equals-Ew3jOFa3.mjs";
5
5
  import { r as assertFalse, t as assertThrows } from "../assert_throws-D4DNWrux.mjs";
6
6
  import { n as assertInstanceOf, t as assert } from "../assert-BhQd8QHP.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
8
- import { i as generateCryptoKeyPair } from "../key-C8OKWl8g.mjs";
8
+ import { i as generateCryptoKeyPair } from "../key-DjCiTRyO.mjs";
9
9
  import { a as rsaPrivateKey3, c as rsaPublicKey3, i as rsaPrivateKey2, n as ed25519PrivateKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
10
- import { a as compactJsonLd, d as isInvalidUrlTypeError, f as signJsonLd, h as verifySignature, i as attachSignature, m as verifyJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature } from "../ld-gUJKeHbH.mjs";
10
+ import { a as compactJsonLd, d as isInvalidUrlTypeError, f as signJsonLd, h as verifySignature, i as attachSignature, m as verifyJsonLd, n as UnsafeJsonLdError, o as createSignature, s as detachSignature } from "../ld-B5pG0yhd.mjs";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
- import { CryptographicKey } from "@fedify/vocab";
12
+ import { Create, CryptographicKey, Note } from "@fedify/vocab";
13
13
  import { encodeBase64 } from "byte-encodings/base64";
14
14
  import jsonld from "@fedify/vocab-runtime/jsonld";
15
15
  //#region src/sig/ld.test.ts
@@ -412,6 +412,155 @@ test("verifyJsonLd()", async () => {
412
412
  contextLoader: mockDocumentLoader
413
413
  }));
414
414
  });
415
+ test("verifyJsonLd() tolerates unmapped document and signature properties", async () => {
416
+ const options = {
417
+ documentLoader: mockDocumentLoader,
418
+ contextLoader: mockDocumentLoader
419
+ };
420
+ const canonize = (input) => jsonld.canonize(input, {
421
+ format: "application/n-quads",
422
+ documentLoader: mockDocumentLoader,
423
+ safe: false
424
+ });
425
+ const withQuote = {
426
+ ...document,
427
+ object: {
428
+ ...document.object,
429
+ quoteUri: "https://example.com/quoted"
430
+ }
431
+ };
432
+ const sigOptions = {
433
+ "@context": "https://w3id.org/identity/v1",
434
+ creator: signature.creator,
435
+ created: signature.created
436
+ };
437
+ const extraOption = { quoteUri: "https://example.com/quoted" };
438
+ assertEquals(await canonize(withQuote), await canonize(document));
439
+ assertEquals(await canonize({
440
+ ...sigOptions,
441
+ ...extraOption
442
+ }), await canonize(sigOptions));
443
+ for (const input of [withQuote, {
444
+ ...sigOptions,
445
+ ...extraOption
446
+ }]) await assertRejects(() => jsonld.canonize(input, {
447
+ format: "application/n-quads",
448
+ documentLoader: mockDocumentLoader,
449
+ safe: true
450
+ }), Error, "Safe mode validation error.");
451
+ const expectedKey = await verifySignature(testVector, options);
452
+ assertInstanceOf(expectedKey, CryptographicKey);
453
+ for (const signed of [
454
+ {
455
+ ...withQuote,
456
+ signature
457
+ },
458
+ {
459
+ ...document,
460
+ signature: {
461
+ ...signature,
462
+ ...extraOption
463
+ }
464
+ },
465
+ {
466
+ ...withQuote,
467
+ signature: {
468
+ ...signature,
469
+ ...extraOption
470
+ }
471
+ }
472
+ ]) {
473
+ assertEquals(await verifySignature(signed, options), expectedKey);
474
+ assert(await verifyJsonLd(signed, options));
475
+ }
476
+ const tampered = {
477
+ ...withQuote,
478
+ object: {
479
+ ...withQuote.object,
480
+ content: "<p>Forged</p>"
481
+ },
482
+ signature
483
+ };
484
+ assertEquals(await verifySignature(tampered, options), null);
485
+ assertFalse(await verifyJsonLd(tampered, options));
486
+ });
487
+ test("verifyJsonLd() rejects relative IRIs despite unmapped properties", async () => {
488
+ const options = {
489
+ documentLoader: mockDocumentLoader,
490
+ contextLoader: mockDocumentLoader
491
+ };
492
+ const canonize = (input) => jsonld.canonize(input, {
493
+ format: "application/n-quads",
494
+ documentLoader: mockDocumentLoader,
495
+ safe: false
496
+ });
497
+ const withRelativeUrl = {
498
+ ...document,
499
+ object: {
500
+ ...document.object,
501
+ url: [document.object.url, "/evil"]
502
+ }
503
+ };
504
+ const note = await (await Create.fromJsonLd(withRelativeUrl, options)).getObject(options);
505
+ assertInstanceOf(note, Note);
506
+ assertEquals(note.urls.map((url) => url instanceof URL ? url.href : null), [document.object.url, "https://activitypub.academy/evil"]);
507
+ for (const input of [withRelativeUrl, {
508
+ ...document,
509
+ "https://example.com/extension": { "@id": "relative" }
510
+ }]) {
511
+ assertEquals(await canonize(input), await canonize(document));
512
+ for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) {
513
+ const signed = {
514
+ ...input,
515
+ ...extra,
516
+ signature
517
+ };
518
+ assertEquals(await verifySignature(signed, options), null);
519
+ assertFalse(await verifyJsonLd(signed, options));
520
+ }
521
+ }
522
+ const relativeOptions = {
523
+ ...testVector,
524
+ signature: {
525
+ ...signature,
526
+ nonce: { "@id": "relative" },
527
+ quoteUri: "https://example.com/quoted"
528
+ }
529
+ };
530
+ const sigOptions = {
531
+ "@context": "https://w3id.org/identity/v1",
532
+ creator: signature.creator,
533
+ created: signature.created
534
+ };
535
+ assertEquals(await canonize({
536
+ ...sigOptions,
537
+ nonce: relativeOptions.signature.nonce,
538
+ quoteUri: relativeOptions.signature.quoteUri
539
+ }), await canonize(sigOptions));
540
+ assertEquals(await verifySignature(relativeOptions, options), null);
541
+ assertFalse(await verifyJsonLd(relativeOptions, options));
542
+ });
543
+ test("signing still rejects unmapped properties", async () => {
544
+ const input = {
545
+ ...document,
546
+ quoteUri: "https://example.com/quoted"
547
+ };
548
+ const options = { contextLoader: mockDocumentLoader };
549
+ await assertRejects(() => createSignature(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
550
+ await assertRejects(() => signJsonLd(input, rsaPrivateKey3, rsaPublicKey3.id, options), Error, "Safe mode validation error.");
551
+ });
552
+ test("verification still rejects malformed JSON-LD", async () => {
553
+ const malformed = {
554
+ ...testVector,
555
+ "@context": 42
556
+ };
557
+ const options = {
558
+ documentLoader: mockDocumentLoader,
559
+ contextLoader: mockDocumentLoader
560
+ };
561
+ assertEquals(await verifySignature(malformed, options), null);
562
+ assertEquals((await assertRejects(() => verifyJsonLd(malformed, options), Error)).name, "jsonld.SyntaxError");
563
+ });
415
564
  test("compactJsonLd() with restrictive context loader", async () => {
416
565
  const restrictiveContextLoader = async (resource) => {
417
566
  const url = new URL(resource).href;
@@ -916,7 +1065,10 @@ test("verifyJsonLd() rejects unsafe JSON-LD keywords", async () => {
916
1065
  signature: signed.signature
917
1066
  }]
918
1067
  ];
919
- for (const [keyword, jsonLd] of cases) await assertRejects(() => verifyJsonLd(jsonLd, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
1068
+ for (const [keyword, jsonLd] of cases) for (const extra of [{}, { quoteUri: "https://example.com/quoted" }]) await assertRejects(() => verifyJsonLd({
1069
+ ...jsonLd,
1070
+ ...extra
1071
+ }, options), UnsafeJsonLdError, `Unsupported JSON-LD keyword: ${keyword}.`);
920
1072
  });
921
1073
  test("compactJsonLd() rejects unsafe JSON-LD keywords inside signature objects", async () => {
922
1074
  const signed = await signJsonLd({
package/dist/sig/mod.cjs CHANGED
@@ -1,8 +1,8 @@
1
1
  const { Temporal } = require("@js-temporal/polyfill");
2
2
  const { URLPattern } = require("urlpattern-polyfill");
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
4
- const require_http = require("../http-B9ZWGTaN.cjs");
5
- const require_proof = require("../proof-DF1RSNYg.cjs");
4
+ const require_http = require("../http-CU9dab8F.cjs");
5
+ const require_proof = require("../proof-BGPhmUJL.cjs");
6
6
  exports.attachSignature = require_proof.attachSignature;
7
7
  exports.createProof = require_proof.createProof;
8
8
  exports.createSignature = require_proof.createSignature;
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { a as signRequest, c as FetchKeyResult, d as fetchKey, f as generateCryptoKeyPair, i as VerifyRequestOptions, l as KeyCache, n as HttpMessageSignaturesSpecDeterminer, o as verifyRequest, p as importJwk, r as SignRequestOptions, s as FetchKeyOptions, t as HttpMessageSignaturesSpec, u as exportJwk } from "../http-DFqAb11b.cjs";
2
+ import { a as signRequest, c as FetchKeyResult, d as fetchKey, f as generateCryptoKeyPair, i as VerifyRequestOptions, l as KeyCache, n as HttpMessageSignaturesSpecDeterminer, o as verifyRequest, p as importJwk, r as SignRequestOptions, s as FetchKeyOptions, t as HttpMessageSignaturesSpec, u as exportJwk } from "../http-B57wVmZ3.cjs";
3
3
  import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-B3hNQCG8.cjs";
4
- import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "../mod-BA6vqC2S.cjs";
5
- export { CreateProofOptions, CreateSignatureOptions, DoesActorOwnKeyOptions, FetchKeyOptions, FetchKeyResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };
4
+ import { _ as detachSignature, a as VerifyObjectOptions, b as verifySignature, c as signObject, d as CreateSignatureOptions, f as SignJsonLdOptions, g as createSignature, h as attachSignature, i as SignObjectOptions, l as verifyObject, m as VerifySignatureOptions, n as CryptoKeyPairLike, o as VerifyProofOptions, p as VerifyJsonLdOptions, r as CreateProofOptions, s as createProof, t as CryptoKeyLike, u as verifyProof, v as signJsonLd, y as verifyJsonLd } from "../mod-DmmcsbU8.cjs";
5
+ export { CreateProofOptions, CreateSignatureOptions, CryptoKeyLike, CryptoKeyPairLike, DoesActorOwnKeyOptions, FetchKeyOptions, FetchKeyResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };
package/dist/sig/mod.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { a as signRequest, c as FetchKeyResult, d as fetchKey, f as generateCryptoKeyPair, i as VerifyRequestOptions, l as KeyCache, n as HttpMessageSignaturesSpecDeterminer, o as verifyRequest, p as importJwk, r as SignRequestOptions, s as FetchKeyOptions, t as HttpMessageSignaturesSpec, u as exportJwk } from "../http-Cd8UD1ym.js";
2
+ import { a as signRequest, c as FetchKeyResult, d as fetchKey, f as generateCryptoKeyPair, i as VerifyRequestOptions, l as KeyCache, n as HttpMessageSignaturesSpecDeterminer, o as verifyRequest, p as importJwk, r as SignRequestOptions, s as FetchKeyOptions, t as HttpMessageSignaturesSpec, u as exportJwk } from "../http-CURWmZlP.js";
3
3
  import { i as getKeyOwner, n as GetKeyOwnerOptions, r as doesActorOwnKey, t as DoesActorOwnKeyOptions } from "../owner-CiBPcC6F.js";
4
- import { _ as verifyJsonLd, a as createProof, c as verifyProof, d as VerifyJsonLdOptions, f as VerifySignatureOptions, g as signJsonLd, h as detachSignature, i as VerifyProofOptions, l as CreateSignatureOptions, m as createSignature, n as SignObjectOptions, o as signObject, p as attachSignature, r as VerifyObjectOptions, s as verifyObject, t as CreateProofOptions, u as SignJsonLdOptions, v as verifySignature } from "../mod-CL9Ep0uo.js";
5
- export { CreateProofOptions, CreateSignatureOptions, DoesActorOwnKeyOptions, FetchKeyOptions, FetchKeyResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };
4
+ import { _ as detachSignature, a as VerifyObjectOptions, b as verifySignature, c as signObject, d as CreateSignatureOptions, f as SignJsonLdOptions, g as createSignature, h as attachSignature, i as SignObjectOptions, l as verifyObject, m as VerifySignatureOptions, n as CryptoKeyPairLike, o as VerifyProofOptions, p as VerifyJsonLdOptions, r as CreateProofOptions, s as createProof, t as CryptoKeyLike, u as verifyProof, v as signJsonLd, y as verifyJsonLd } from "../mod-fnE_D0lV.js";
5
+ export { CreateProofOptions, CreateSignatureOptions, CryptoKeyLike, CryptoKeyPairLike, DoesActorOwnKeyOptions, FetchKeyOptions, FetchKeyResult, GetKeyOwnerOptions, HttpMessageSignaturesSpec, HttpMessageSignaturesSpecDeterminer, KeyCache, SignJsonLdOptions, SignObjectOptions, SignRequestOptions, VerifyJsonLdOptions, VerifyObjectOptions, VerifyProofOptions, VerifyRequestOptions, VerifySignatureOptions, attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };
package/dist/sig/mod.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import { URLPattern } from "urlpattern-polyfill";
3
- import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "../http-C1v_vvt4.js";
4
- import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "../proof-BvtZYI3N.js";
3
+ import { c as importJwk, i as exportJwk, n as signRequest, o as fetchKey, r as verifyRequest, s as generateCryptoKeyPair } from "../http-6beU7KiN.js";
4
+ import { _ as signJsonLd, a as doesActorOwnKey, b as verifySignature, d as createSignature, f as detachSignature, i as verifyProof, l as attachSignature, n as signObject, o as getKeyOwner, r as verifyObject, t as createProof, y as verifyJsonLd } from "../proof-iPBfQoMT.js";
5
5
  export { attachSignature, createProof, createSignature, detachSignature, doesActorOwnKey, exportJwk, fetchKey, generateCryptoKeyPair, getKeyOwner, importJwk, signJsonLd, signObject, signRequest, verifyJsonLd, verifyObject, verifyProof, verifyRequest, verifySignature };
@@ -6,7 +6,7 @@ import "../std__assert-DflMZha5.mjs";
6
6
  import { r as assertFalse } from "../assert_throws-D4DNWrux.mjs";
7
7
  import { t as assert } from "../assert-BhQd8QHP.mjs";
8
8
  import { o as rsaPublicKey1, s as rsaPublicKey2 } from "../keys-CCxRJhWa.mjs";
9
- import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-BenEndHH.mjs";
9
+ import { n as getKeyOwner, t as doesActorOwnKey } from "../owner-Dmlm2oR_.mjs";
10
10
  import { createTestTracerProvider, mockDocumentLoader, test } from "@fedify/fixture";
11
11
  import { Create, CryptographicKey, lookupObject } from "@fedify/vocab";
12
12
  //#region src/sig/owner.test.ts
@@ -6,8 +6,8 @@ import "../std__assert-DflMZha5.mjs";
6
6
  import { n as assertInstanceOf } from "../assert-BhQd8QHP.mjs";
7
7
  import { t as assertRejects } from "../assert_rejects-WyYSTDDX.mjs";
8
8
  import { i as rsaPrivateKey2, n as ed25519PrivateKey, r as ed25519PublicKey, s as rsaPublicKey2, t as ed25519Multikey } from "../keys-CCxRJhWa.mjs";
9
- import { f as signJsonLd, h as verifySignature, s as detachSignature } from "../ld-gUJKeHbH.mjs";
10
- import { i as verifyProof, n as signObject, r as verifyObject, t as createProof } from "../proof-Bo9pmjQJ.mjs";
9
+ import { f as signJsonLd, h as verifySignature, s as detachSignature } from "../ld-B5pG0yhd.mjs";
10
+ import { i as verifyProof, n as signObject, r as verifyObject, t as createProof } from "../proof-v76wU5Lv.mjs";
11
11
  import { mockDocumentLoader, test } from "@fedify/fixture";
12
12
  import { Create, DataIntegrityProof, Multikey, Note, Place } from "@fedify/vocab";
13
13
  import { decodeMultibase, importMultibaseKey } from "@fedify/vocab-runtime";
@@ -1,7 +1,7 @@
1
1
  import { Temporal } from "@js-temporal/polyfill";
2
2
  import "urlpattern-polyfill";
3
3
  globalThis.addEventListener = () => {};
4
- import { c as getNormalizationContextLoader } from "./ld-gUJKeHbH.mjs";
4
+ import { c as getNormalizationContextLoader } from "./ld-B5pG0yhd.mjs";
5
5
  import jsonld from "@fedify/vocab-runtime/jsonld";
6
6
  import { normalizeDateTimeLiteral } from "@fedify/vocab-runtime/temporal";
7
7
  //#region src/federation/temporal.ts