@fedify/fedify 2.4.0-dev.2256 → 2.4.0-dev.2259

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 (105) hide show
  1. package/dist/{builder-DvSQqk2l.mjs → builder-CBNa1Uw2.mjs} +8 -2
  2. package/dist/compat/mod.d.cts +1 -1
  3. package/dist/compat/mod.d.ts +1 -1
  4. package/dist/compat/transformers.test.mjs +1 -1
  5. package/dist/{compound-proof-5bg_j_ye.mjs → compound-proof-CMPv4UK0.mjs} +20 -3
  6. package/dist/{context-CtI307_A.d.ts → context-7NyiqIcg.d.ts} +111 -2
  7. package/dist/{context-B6X-t8gI.d.cts → context-tsYPJ2Ew.d.cts} +111 -2
  8. package/dist/{deno-AmcRMq5z.mjs → deno-C8XaXmPB.mjs} +1 -1
  9. package/dist/{docloader-CIP_SG39.mjs → docloader-CpdFLwAg.mjs} +2 -2
  10. package/dist/federation/builder.test.mjs +1 -1
  11. package/dist/federation/compound-fanout.test.mjs +3 -3
  12. package/dist/federation/handler-compound-proof.test.mjs +3 -3
  13. package/dist/federation/handler.test.mjs +76 -5
  14. package/dist/federation/hashlink-media.test.mjs +2 -2
  15. package/dist/federation/idempotency.test.mjs +2 -2
  16. package/dist/federation/inbox-report.test.d.mts +2 -0
  17. package/dist/federation/inbox-report.test.mjs +475 -0
  18. package/dist/federation/metrics.test.mjs +1 -1
  19. package/dist/federation/middleware.test.mjs +7 -7
  20. package/dist/federation/mod.cjs +1 -1
  21. package/dist/federation/mod.d.cts +4 -3
  22. package/dist/federation/mod.d.ts +4 -3
  23. package/dist/federation/mod.js +1 -1
  24. package/dist/federation/outgoing-proof.test.mjs +5 -5
  25. package/dist/federation/portable-actor.test.mjs +3 -3
  26. package/dist/federation/portable-chain.test.mjs +3 -3
  27. package/dist/federation/portable-collection.test.mjs +4 -4
  28. package/dist/federation/portable-delivery.test.mjs +2 -2
  29. package/dist/federation/portable-gateway-keys.test.mjs +4 -4
  30. package/dist/federation/portable-inbox.test.mjs +67 -6
  31. package/dist/federation/portable-parse-uri.test.mjs +1 -1
  32. package/dist/federation/portable-route-activity.test.mjs +2 -2
  33. package/dist/federation/portable.test.mjs +3 -3
  34. package/dist/federation/send.test.mjs +3 -3
  35. package/dist/federation/tasks/enqueue.test.mjs +1 -1
  36. package/dist/federation/tasks/tasks.test.mjs +2 -2
  37. package/dist/federation/temporal.test.mjs +1 -1
  38. package/dist/federation/webfinger.test.mjs +1 -1
  39. package/dist/{federation-BDzIgqOd.cjs → federation-D6giSGUT.cjs} +524 -118
  40. package/dist/{http-DkqWu-sm.mjs → http-BqSbUEiQ.mjs} +141 -98
  41. package/dist/{http-1fZ83jj7.cjs → http-Cki-npuA.cjs} +447 -110
  42. package/dist/{http-BGb3QioZ.js → http-OMtKlbx1.js} +430 -111
  43. package/dist/{http-BrwKINQn.d.cts → key-C1nv7_jD.d.ts} +638 -229
  44. package/dist/{http-DGx0KOws.d.ts → key-DYxuyd-s.d.cts} +638 -229
  45. package/dist/{key-CEsu7oaD.mjs → key-DecAtABm.mjs} +30 -3
  46. package/dist/{kv-cache-CJS4mImS.mjs → kv-cache-CWWlMv-s.mjs} +1 -1
  47. package/dist/{kv-cache-BEWuZSB4.cjs → kv-cache-D73yVcE5.cjs} +1 -1
  48. package/dist/{kv-cache-CGhEgt98.js → kv-cache-J0v3UbUn.js} +1 -1
  49. package/dist/{ld-Cf4CPWN_.mjs → ld-UsN-TIPh.mjs} +40 -5
  50. package/dist/{metrics-CocsZP0E.mjs → metrics-DWCn4VXX.mjs} +2 -1
  51. package/dist/{middleware-BfYke3YQ.js → middleware-BqzfIlUO.js} +524 -118
  52. package/dist/{middleware-Dxn0E9ES.mjs → middleware-CkjwiEBd.mjs} +512 -127
  53. package/dist/{middleware-Cne_jMZo.mjs → middleware-DHn2q0L1.mjs} +1 -1
  54. package/dist/{mod-C7_2j7VT.d.cts → mod-BojP2Bw3.d.cts} +1 -1
  55. package/dist/{mod-BlLwewYe.d.ts → mod-CavhAgLw.d.cts} +5 -255
  56. package/dist/{mod-VHYh1lTK.d.cts → mod-CtpF2BU5.d.ts} +5 -255
  57. package/dist/{mod-B8MI1mpi.d.ts → mod-DEZXwV6J.d.ts} +1 -1
  58. package/dist/{mod-DFL6IxYQ.d.cts → mod-Dw-nPxQh.d.cts} +1 -1
  59. package/dist/{mod-BhTaDR5H.d.ts → mod-Xj5P4s4d.d.ts} +1 -1
  60. package/dist/mod.cjs +4 -4
  61. package/dist/mod.d.cts +7 -7
  62. package/dist/mod.d.ts +7 -7
  63. package/dist/mod.js +4 -4
  64. package/dist/nodeinfo/handler.test.mjs +1 -1
  65. package/dist/{owner-DSJ7nFgy.mjs → owner-CEBn81LD.mjs} +3 -3
  66. package/dist/{portable-collection-r-mHg1PV.cjs → portable-collection-DqTUBKY7.cjs} +1 -1
  67. package/dist/{portable-collection-BuBV6xTo.js → portable-collection-ZkUNjtb7.js} +1 -1
  68. package/dist/{portable-collection-qskqXJrH.mjs → portable-collection-qFSYw4TG.mjs} +2 -2
  69. package/dist/{portable-key-woGH_1nn.mjs → portable-key-LlMkP-vz.mjs} +1 -1
  70. package/dist/{proof-8WiH_-Gq.mjs → proof-BHRf_jMG.mjs} +133 -16
  71. package/dist/{send-JKzZBgPU.mjs → send-DjG8DDU_.mjs} +3 -3
  72. package/dist/sig/compound-proof-discovery.test.mjs +1 -1
  73. package/dist/sig/compound-proof-producer.test.mjs +1 -1
  74. package/dist/sig/compound-proof-verification.test.mjs +19 -2
  75. package/dist/sig/compound-proof.test.mjs +2 -2
  76. package/dist/sig/http.test.mjs +2 -2
  77. package/dist/sig/key.test.mjs +1 -1
  78. package/dist/sig/ld.test.mjs +2 -2
  79. package/dist/sig/mitra-receive-interop.test.mjs +4 -4
  80. package/dist/sig/mitra-send-interop.test.mjs +3 -3
  81. package/dist/sig/mod.cjs +2 -2
  82. package/dist/sig/mod.d.cts +2 -2
  83. package/dist/sig/mod.d.ts +2 -2
  84. package/dist/sig/mod.js +2 -2
  85. package/dist/sig/owner.test.mjs +1 -1
  86. package/dist/sig/portable-collection.test.mjs +1 -1
  87. package/dist/sig/portable-interop.test.mjs +3 -3
  88. package/dist/sig/portable-key.test.mjs +6 -6
  89. package/dist/sig/proof.test.mjs +76 -3
  90. package/dist/sig/tootik-request-interop.test.mjs +4 -4
  91. package/dist/sig/tootik-send-interop.test.mjs +3 -3
  92. package/dist/sig/verification.test.d.mts +2 -0
  93. package/dist/sig/verification.test.mjs +310 -0
  94. package/dist/{temporal-CT3fRaMH.mjs → temporal-BRFH_dte.mjs} +1 -1
  95. package/dist/testing/kv.test.mjs +1 -1
  96. package/dist/testing/mod.d.mts +315 -28
  97. package/dist/utils/docloader.test.mjs +2 -2
  98. package/dist/utils/kv-cache.test.mjs +1 -1
  99. package/dist/utils/mod.cjs +1 -1
  100. package/dist/utils/mod.d.cts +1 -1
  101. package/dist/utils/mod.d.ts +1 -1
  102. package/dist/utils/mod.js +1 -1
  103. package/dist/verification-C3954hQh.mjs +5 -0
  104. package/dist/verification-Dpfcw8ml.mjs +105 -0
  105. package/package.json +7 -7
@@ -1,297 +1,283 @@
1
1
  /// <reference lib="esnext.temporal" />
2
- import { Actor, CryptographicKey, Multikey } from "@fedify/vocab";
2
+ import { Actor, CryptographicKey, DataIntegrityProof, Multikey, Object as Object$1 } from "@fedify/vocab";
3
+ import { DocumentLoader, PortableObjectVerifier } from "@fedify/vocab-runtime";
3
4
  import { MeterProvider, TracerProvider } from "@opentelemetry/api";
4
- import { DocumentLoader } from "@fedify/vocab-runtime";
5
5
 
6
- //#region src/sig/portable-key.d.ts
6
+ //#region src/sig/proof.d.ts
7
7
  /**
8
- * The result of resolving a gateway key of a portable actor.
9
- * @internal
8
+ * Checks if the given JSON-LD document has a DataIntegrityProof-like object,
9
+ * without fully deserializing it into vocabulary classes.
10
+ * @param jsonLd The JSON-LD document to check.
11
+ * @returns `true` if the document has a proof-like object; `false` otherwise.
12
+ * @since 2.2.0
10
13
  */
11
- type PortableGatewayKeyResolution = {
14
+ declare function hasProofLike(jsonLd: unknown): boolean;
15
+ /**
16
+ * Options for {@link createProof}.
17
+ * @since 0.10.0
18
+ */
19
+ interface CreateProofOptions {
12
20
  /**
13
- * The document at the key ID is not a portable actor, so the key is
14
- * resolved as usual.
21
+ * The context loader for loading remote JSON-LD contexts.
15
22
  */
16
- readonly type: "legacy";
17
- } | {
18
- /** The document is a portable actor, but it does not vouch for the key. */readonly type: "rejected";
19
- readonly reason: string;
20
- } | {
21
- /** The portable actor's signed document vouches for the key. */readonly type: "verified";
22
- readonly actor: Actor;
23
- readonly key: CryptographicKey & {
24
- publicKey: CryptoKey;
25
- };
23
+ contextLoader?: DocumentLoader;
26
24
  /**
27
- * The expanded root node of the actor's document whose proof was
28
- * verified, from which {@link actor} was parsed.
25
+ * The JSON-LD context to use for serializing the object to sign.
29
26
  */
30
- readonly document: Record<string, unknown>;
27
+ context?: string | Record<string, string> | (string | Record<string, string>)[];
31
28
  /**
32
- * When the proof of the actor's document expires, if it does. The
33
- * document does not vouch for the key after that.
29
+ * The time when the proof was created. If not specified, the current time
30
+ * will be used.
34
31
  */
35
- readonly expires?: Temporal.Instant;
36
- };
32
+ created?: Temporal.Instant;
33
+ }
37
34
  /**
38
- * The result of resolving a key of a portable actor at an `ap:` or
39
- * `ap+ef61:` key ID.
40
- * @internal
35
+ * Creates a proof for the given object.
36
+ * @param object The object to create a proof for.
37
+ * @param privateKey The private key to sign the proof with.
38
+ * @param keyId The key ID to use in the proof. It will be used by the verifier.
39
+ * @param options Additional options. See also {@link CreateProofOptions}.
40
+ * @returns The created proof.
41
+ * @throws {TypeError} If the private key is invalid or unsupported.
42
+ * @since 0.10.0
41
43
  */
42
- type PortableActorKeyResolution = Exclude<PortableGatewayKeyResolution, {
43
- readonly type: "legacy";
44
- }> | {
44
+ declare function createProof(object: Object$1, privateKey: CryptoKey, keyId: URL, options?: CreateProofOptions): Promise<DataIntegrityProof>;
45
+ /**
46
+ * Options for {@link signObject}.
47
+ * @since 0.10.0
48
+ */
49
+ interface SignObjectOptions extends CreateProofOptions {
45
50
  /**
46
- * Whether the actor's document vouches for the key could not be
47
- * determined, e.g., because no gateway could be reached.
51
+ * The document loader for loading remote JSON-LD documents.
48
52
  */
49
- readonly type: "unavailable";
50
- readonly error: unknown;
53
+ documentLoader?: DocumentLoader;
51
54
  /**
52
- * Whether the failure can be cached as a failure to fetch the key, i.e.,
53
- * every gateway failed to serve the actor's document at all. A failure
54
- * that is not cacheable comes with an error that has no HTTP status,
55
- * since none of the statuses describes the lookup as a whole.
55
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
56
+ * is used.
57
+ * @since 1.3.0
56
58
  */
57
- readonly cacheable: boolean;
58
- };
59
- //#endregion
60
- //#region src/sig/key.d.ts
61
- /**
62
- * Generates a key pair which is appropriate for Fedify.
63
- * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
64
- * Ed25519 are supported.
65
- * @returns The generated key pair.
66
- * @throws {TypeError} If the algorithm is unsupported.
67
- */
68
- declare function generateCryptoKeyPair(algorithm?: "RSASSA-PKCS1-v1_5" | "Ed25519"): Promise<CryptoKeyPair>;
69
- /**
70
- * Exports a key in JWK format.
71
- * @param key The key to export. Either public or private key.
72
- * @returns The exported key in JWK format. The key is suitable for
73
- * serialization and storage.
74
- * @throws {TypeError} If the key is invalid or unsupported.
75
- */
76
- declare function exportJwk(key: CryptoKey): Promise<JsonWebKey>;
59
+ tracerProvider?: TracerProvider;
60
+ }
77
61
  /**
78
- * Imports a key from JWK format.
79
- * @param jwk The key in JWK format.
80
- * @param type Which type of key to import, either `"public"` or `"private"`.
81
- * @returns The imported key.
82
- * @throws {TypeError} If the key is invalid or unsupported.
62
+ * Signs the given object with the private key and returns the signed object.
63
+ * @param object The object to create a proof for.
64
+ * @param privateKey The private key to sign the proof with.
65
+ * @param keyId The key ID to use in the proof. It will be used by the verifier.
66
+ * @param options Additional options. See also {@link SignObjectOptions}.
67
+ * @returns The signed object.
68
+ * @throws {TypeError} If the private key is invalid or unsupported.
69
+ * @since 0.10.0
83
70
  */
84
- declare function importJwk(jwk: JsonWebKey, type: "public" | "private"): Promise<CryptoKey>;
71
+ declare function signObject<T extends Object$1>(object: T, privateKey: CryptoKey, keyId: URL, options?: SignObjectOptions): Promise<T>;
85
72
  /**
86
- * Options for {@link fetchKey}.
87
- * @since 1.3.0
73
+ * Options for {@link verifyProof}.
74
+ * @since 0.10.0
88
75
  */
89
- interface FetchKeyOptions {
76
+ interface VerifyProofOptions extends VerificationObservationOptions {
90
77
  /**
91
- * The document loader for loading remote JSON-LD documents.
78
+ * The security domain expected by the verifier. When specified, it must
79
+ * contain the same strings as the proof's `domain` option.
80
+ * @since 2.4.0
92
81
  */
93
- documentLoader?: DocumentLoader;
82
+ domain?: string | readonly string[];
83
+ /**
84
+ * The challenge expected by the verifier. When specified, it must exactly
85
+ * match the proof's `challenge` option.
86
+ * @since 2.4.0
87
+ */
88
+ challenge?: string;
94
89
  /**
95
90
  * The context loader for loading remote JSON-LD contexts.
96
91
  */
97
92
  contextLoader?: DocumentLoader;
98
93
  /**
94
+ * The document loader for loading remote JSON-LD documents.
95
+ */
96
+ documentLoader?: DocumentLoader;
97
+ /**
99
98
  * The key cache to use for caching public keys.
100
99
  * @since 0.12.0
101
100
  */
102
101
  keyCache?: KeyCache;
103
102
  /**
104
- * The OpenTelemetry tracer provider to use for tracing. If omitted,
105
- * the global tracer provider is used.
103
+ * The OpenTelemetry tracer provider. If omitted, the global tracer provider
104
+ * is used.
106
105
  * @since 1.3.0
107
106
  */
108
107
  tracerProvider?: TracerProvider;
109
108
  /**
110
- * The OpenTelemetry meter provider to use for recording
111
- * `activitypub.key.lookup` and `activitypub.key.lookup.duration`. If
112
- * omitted, the global meter provider is used.
109
+ * The OpenTelemetry meter provider. If omitted, the global meter provider
110
+ * is used.
113
111
  * @since 2.3.0
114
112
  */
115
113
  meterProvider?: MeterProvider;
116
- /**
117
- * An assertion by the caller that it has already bound this key's id to
118
- * whoever the key will be treated as speaking for, by means of its own that
119
- * key resolution cannot see.
120
- *
121
- * Key resolution normally settles ownership itself: it dereferences the
122
- * `owner`/`controller` a key claims and requires that actor's own document
123
- * to link back to the key, because the claim and the key document come from
124
- * the same host and so the claim proves nothing on its own. See
125
- * GHSA-q9f8-5hc7-898f.
126
- *
127
- * That check presumes the ActivityPub shape of ownership, where the owner
128
- * is an actor carrying a `publicKey`/`assertionMethod` list. It does not
129
- * fit every caller. Portable objects (FEP-ef61) bind a key to an object
130
- * structurally instead: {@link verifyPortableObjectProof} requires the
131
- * verification method's FEP-ef34 origin to equal the object id's own
132
- * authority, so the signer is pinned by the identifier being verified,
133
- * before any key is fetched. Demanding the ActivityPub check as well would
134
- * be impossible rather than merely redundant, since a DID dereferences to
135
- * a DID document, which is not an actor.
136
- *
137
- * This is not a way to accept whatever a key says about itself. The claim
138
- * still has to be corroborated, just from the key id rather than from
139
- * a second document: a key may name an owner only when the key id is that
140
- * owner's own (a `did:…#fragment` belongs to the DID it is a fragment of,
141
- * exactly as a key embedded in an actor document belongs to that actor).
142
- * A key naming anyone else falls back to the ordinary check and is rejected
143
- * if it cannot pass it, so a key admitted here is as sound as any other and
144
- * is cached like any other.
145
- * @internal
146
- */
147
- keyIdBoundByCaller?: boolean;
148
- /**
149
- * Resolves keys of [FEP-ef61] portable actors, which only HTTP Signature
150
- * verification passes, so that only it accepts them. Object Integrity
151
- * Proofs and Linked Data Signatures never do: such a key is rejected if
152
- * this is omitted.
153
- *
154
- * [FEP-ef61]: https://w3id.org/fep/ef61
155
- * @internal
156
- */
157
- portableKeyResolvers?: PortableKeyResolvers;
158
114
  }
159
115
  /**
160
- * Resolves keys of [FEP-ef61] portable actors for HTTP Signature
161
- * verification. See {@link FetchKeyOptions.portableKeyResolvers}.
162
- *
163
- * [FEP-ef61]: https://w3id.org/fep/ef61
164
- * @internal
116
+ * Options for {@link verifyPortableObjectProof}.
117
+ * @since 2.4.0
165
118
  */
166
- interface PortableKeyResolvers {
167
- /**
168
- * Resolves a gateway key, i.e., a key whose ID is a compatible identifier
169
- * and dereferences to a portable actor's document.
170
- */
171
- gatewayKey(document: unknown, actor: Actor, keyId: URL): Promise<PortableGatewayKeyResolution>;
172
- /**
173
- * Resolves a key of a portable actor itself, i.e., a key whose ID is an
174
- * `ap:` or `ap+ef61:` URI.
175
- */
176
- actorKey(keyId: URL): Promise<PortableActorKeyResolution>;
177
- }
119
+ interface VerifyPortableObjectProofOptions extends VerifyProofOptions {}
178
120
  /**
179
- * The result of {@link fetchKey}.
180
- * @since 1.3.0
121
+ * The reason why {@link verifyPortableObjectProof} could not verify a portable
122
+ * object proof.
123
+ * @since 2.4.0
181
124
  */
182
- interface FetchKeyResult<T extends CryptographicKey | Multikey> {
125
+ type VerifyPortableObjectProofFailureReason = {
183
126
  /**
184
- * The fetched (or cached) key.
127
+ * The document has neither a portable `ap:` or `ap+ef61:` ID nor an
128
+ * FEP-ef61 compatible identifier.
185
129
  */
186
- readonly key: T & {
187
- publicKey: CryptoKey;
188
- } | null;
130
+ readonly type: "notPortableObject";
131
+ } | {
189
132
  /**
190
- * Whether the key is fetched from the cache.
133
+ * The document is a portable collection without an Object Integrity
134
+ * Proof. Its trust policy is outside this verifier.
191
135
  */
192
- readonly cached: boolean;
193
- }
194
- /**
195
- * Detailed fetch failure information from {@link fetchKeyDetailed}.
196
- * @since 2.1.0
197
- */
198
- type FetchKeyErrorResult = {
199
- readonly status: number;
200
- readonly response: Response;
136
+ readonly type: "unsecuredCollection";
201
137
  } | {
202
- readonly error: Error;
138
+ /** The portable document is a core type outside FEP-ef61 proof policy. */readonly type: "unsupportedObjectType"; /** The FEP-2277 core type of the document. */
139
+ readonly objectType: "verificationMethod" | "publicKey" | "link";
140
+ } | {
141
+ /** A portable actor, activity, or object has no proof. */readonly type: "missingProof";
142
+ } | {
143
+ /**
144
+ * A portable actor's `gateways` is missing or empty, or has an item that
145
+ * is not an HTTP(S) URI with an empty path, query, and fragment.
146
+ * The document is rejected before its proofs are verified, so this
147
+ * reason does not mean that the proofs are valid.
148
+ */
149
+ readonly type: "invalidGateways";
150
+ } | {
151
+ /** The proof is malformed, unsupported, or cryptographically invalid. */readonly type: "invalidProof"; /** The zero-based index of the invalid proof. */
152
+ readonly proofIndex: number;
153
+ } | {
154
+ /** The proof's verification method is not a valid DID URL. */readonly type: "unsupportedVerificationMethod"; /** The zero-based index of the proof. */
155
+ readonly proofIndex: number; /** The unsupported verification method. */
156
+ readonly verificationMethod: URL;
157
+ } | {
158
+ /** The verification method DID does not match the portable ID authority. */readonly type: "verificationMethodMismatch"; /** The zero-based index of the proof. */
159
+ readonly proofIndex: number; /** The portable object ID. */
160
+ readonly objectId: URL; /** The mismatching verification method. */
161
+ readonly verificationMethod: URL;
203
162
  };
204
163
  /**
205
- * The result of {@link fetchKeyDetailed}.
206
- * @since 2.1.0
164
+ * The detailed result of {@link verifyPortableObjectProof}.
165
+ * @since 2.4.0
207
166
  */
208
- interface FetchKeyDetailedResult<T extends CryptographicKey | Multikey> extends FetchKeyResult<T> {
209
- /**
210
- * The error that occurred while fetching the key, if fetching failed before
211
- * a document could be parsed.
212
- */
213
- readonly fetchError?: FetchKeyErrorResult;
214
- }
215
- type FetchableKeyClass<T extends CryptographicKey | Multikey> = (new (...args: any[]) => T) & {
216
- fromJsonLd(jsonLd: unknown, options: {
217
- documentLoader?: DocumentLoader;
218
- contextLoader?: DocumentLoader;
219
- tracerProvider?: TracerProvider;
220
- }): Promise<T>;
167
+ type VerifyPortableObjectProofResult = {
168
+ /** Whether every Object Integrity Proof was verified. */readonly verified: true; /** The public keys used by the verified proofs, in proof order. */
169
+ readonly keys: readonly Multikey[];
170
+ } | {
171
+ /** Whether every Object Integrity Proof was verified. */readonly verified: false; /** Why portable proof verification did not succeed. */
172
+ readonly reason: VerifyPortableObjectProofFailureReason;
221
173
  };
222
174
  /**
223
- * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL.
224
- * If the given URL contains an {@link Actor} object, it tries to find
225
- * the corresponding key in the `publicKey` or `assertionMethod` property. *
226
- * Gateway keys of [FEP-ef61] portable actors, i.e., keys whose IDs are
227
- * compatible identifiers that dereference to portable actor documents, are
228
- * not resolved by this function, as they only authenticate HTTP requests;
229
- * use `verifyRequest()` or `getKeyOwner()` for them instead. Nor are keys
230
- * of portable actors whose IDs are `ap:` or `ap+ef61:` URIs, for the same
231
- * reason. Keys whose IDs are compatible identifiers or `ap:` or `ap+ef61:`
232
- * URIs are never read from or written to the key cache under their IDs,
233
- * except for failures to fetch them.
234
- *
235
- * [FEP-ef61]: https://w3id.org/fep/ef61
236
- * @template T The type of the key to fetch. Either {@link CryptographicKey}
237
- * or {@link Multikey}.
238
- * @param keyId The URL of the key.
239
- * @param cls The class of the key to fetch. Either {@link CryptographicKey}
240
- * or {@link Multikey}.
241
- * @param options Options for fetching the key. See {@link FetchKeyOptions}.
242
- * @returns The fetched key or `null` if the key is not found.
243
- * @since 1.3.0
175
+ * Verifies the given proof for the object.
176
+ * @param jsonLd The JSON-LD object to verify the proof for. Its proof
177
+ * properties are excluded from the message, but matching proof
178
+ * occurrences are used to authenticate the received proof
179
+ * configuration.
180
+ * @param proof The proof to verify.
181
+ * @param options Additional options. See also {@link VerifyProofOptions}.
182
+ * @returns The public key that was used to sign the proof, or `null` if the
183
+ * proof is invalid.
184
+ * @since 0.10.0
185
+ * @since 2.4.0 Matching proof configurations are authenticated.
244
186
  */
245
- declare function fetchKey<T extends CryptographicKey | Multikey>(keyId: URL | string, cls: FetchableKeyClass<T>, options?: FetchKeyOptions): Promise<FetchKeyResult<T>>;
187
+ declare function verifyProof(jsonLd: unknown, proof: DataIntegrityProof, options?: VerifyProofOptions): Promise<Multikey | null>;
246
188
  /**
247
- * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL,
248
- * preserving transport-level fetch failures for callers that need to inspect
249
- * why the key could not be loaded. *
250
- * Gateway keys of [FEP-ef61] portable actors, i.e., keys whose IDs are
251
- * compatible identifiers that dereference to portable actor documents, are
252
- * not resolved by this function, as they only authenticate HTTP requests;
253
- * use `verifyRequest()` or `getKeyOwner()` for them instead. Nor are keys
254
- * of portable actors whose IDs are `ap:` or `ap+ef61:` URIs, for the same
255
- * reason. Keys whose IDs are compatible identifiers or `ap:` or `ap+ef61:`
256
- * URIs are never read from or written to the key cache under their IDs,
257
- * except for failures to fetch them.
189
+ * Verifies the FEP-ef61 Object Integrity Proof policy for a portable object.
190
+ *
191
+ * This applies the FEP-2277 core-type classification to the top-level JSON-LD
192
+ * node. Portable actors, activities, and objects require proofs. A portable
193
+ * collection without a proof is reported separately so a caller can apply a
194
+ * gateway trust policy. Embedded portable objects are not traversed.
195
+ *
196
+ * A portable object is a document whose ID is an `ap:` or `ap+ef61:` URI, or
197
+ * an [FEP-ef61] compatible identifier such as
198
+ * `https://gw.example/.well-known/apgateway/did:key:z6Mk…/actor`, which
199
+ * stands for the portable ID `ap+ef61://did:key:z6Mk…/actor`.
200
+ *
201
+ * Every proof must use a DID URL whose DID matches the portable object's
202
+ * authority, i.e., the DID of its canonical portable ID, and every proof must
203
+ * pass {@link verifyProof}. A portable actor must also have a non-empty
204
+ * `gateways` list whose items are all HTTP(S) URIs with an empty path, query,
205
+ * and fragment; otherwise, it is rejected with the `invalidGateways` reason
206
+ * before its proofs are verified. The proofs are verified over the document as
207
+ * given; a compatible identifier is never rewritten into a portable ID.
208
+ * An unmapped literal `gateways` property is also accepted when every proof
209
+ * uses `eddsa-jcs-2022`, which authenticates the original JSON properties.
258
210
  *
259
211
  * [FEP-ef61]: https://w3id.org/fep/ef61
260
212
  *
261
- * @template T The type of the key to fetch. Either {@link CryptographicKey}
262
- * or {@link Multikey}.
263
- * @param keyId The URL of the key.
264
- * @param cls The class of the key to fetch. Either {@link CryptographicKey}
265
- * or {@link Multikey}.
266
- * @param options Options for fetching the key.
267
- * @returns The fetched key, or detailed fetch failure information.
268
- * @since 2.1.0
213
+ * @param jsonLd The JSON-LD document to verify.
214
+ * @param options Additional options. See also
215
+ * {@link VerifyPortableObjectProofOptions}.
216
+ * @returns The detailed portable proof-policy result.
217
+ * @throws {TypeError} If the input is not a single JSON-LD object or has a
218
+ * malformed portable ID or compatible identifier.
219
+ * @since 2.4.0
269
220
  */
270
- declare function fetchKeyDetailed<T extends CryptographicKey | Multikey>(keyId: URL | string, cls: FetchableKeyClass<T>, options?: FetchKeyOptions): Promise<FetchKeyDetailedResult<T>>;
221
+ declare function verifyPortableObjectProof(jsonLd: unknown, options?: VerifyPortableObjectProofOptions): Promise<VerifyPortableObjectProofResult>;
271
222
  /**
272
- * A cache for storing cryptographic keys.
273
- * @since 0.12.0
223
+ * Options for {@link verifyObject}.
224
+ * @since 0.10.0
274
225
  */
275
- interface KeyCache {
226
+ interface VerifyObjectOptions extends VerifyProofOptions {
276
227
  /**
277
- * Gets a key from the cache.
278
- * @param keyId The key ID.
279
- * @returns The key if found, `null` if the key is not available (e.g.,
280
- * fetching the key was tried but failed), or `undefined`
281
- * if the cache is not available.
282
- */
283
- get(keyId: URL): Promise<CryptographicKey | Multikey | null | undefined>;
284
- /**
285
- * Sets a key to the cache.
228
+ * The default [FEP-ef61] portable object verifier for the property
229
+ * accessors of the returned object and the objects obtained from it, e.g.,
230
+ * `Context.verifyPortableObject`. It is not used to verify the given
231
+ * object itself.
286
232
  *
287
- * Note that this caches unavailable keys (i.e., `null`) as well,
288
- * and it is recommended to make unavailable keys expire after a short period.
289
- * @param keyId The key ID.
290
- * @param key The key to cache. `null` means the key is not available
291
- * (e.g., fetching the key was tried but failed).
233
+ * [FEP-ef61]: https://w3id.org/fep/ef61
234
+ * @since 2.4.0
292
235
  */
293
- set(keyId: URL, key: CryptographicKey | Multikey | null): Promise<void>;
236
+ verifyPortableObject?: PortableObjectVerifier;
294
237
  }
238
+ /**
239
+ * Verifies the given object. It will verify all the proofs in the object,
240
+ * and succeed only if all the proofs are valid and all attributions and
241
+ * actors are authenticated by the proofs.
242
+ * @template T The type of the object to verify.
243
+ * @param cls The class of the object to verify. It must be a subclass of
244
+ * the {@link Object}.
245
+ * @param jsonLd The JSON-LD object to verify. It's assumed that the object
246
+ * is a compacted JSON-LD representation of a `T` with `@context`.
247
+ * @param options Additional options. See also {@link VerifyObjectOptions}.
248
+ * @returns The object if it's verified, or `null` if it's not.
249
+ * @throws {TypeError} If the object is invalid or unsupported.
250
+ * @since 0.10.0
251
+ */
252
+ declare function verifyObject<T extends Object$1>(cls: (new (...args: any[]) => T) & {
253
+ fromJsonLd(jsonLd: unknown, options: VerifyObjectOptions): Promise<T>;
254
+ }, jsonLd: unknown, options?: VerifyObjectOptions): Promise<T | null>;
255
+ //#endregion
256
+ //#region src/sig/compound-proof.d.ts
257
+ /** Why compound-proof discovery could not produce an atomic result. */
258
+ type CompoundProofDiscoveryFailureReason = {
259
+ readonly type: "invalidJsonTree";
260
+ readonly path: string;
261
+ } | {
262
+ readonly type: "unsupportedProofShape";
263
+ readonly path: string;
264
+ } | {
265
+ readonly type: "limitExceeded";
266
+ readonly limit: "depth" | "maps" | "proofs" | "bytes";
267
+ readonly maximum: number;
268
+ readonly actual: number;
269
+ readonly path: string;
270
+ };
271
+ /** Why a discovered map-local proof did not verify. */
272
+ type CompoundProofVerificationFailureReason = {
273
+ /** A nested secured map does not carry its own JSON-LD context. */readonly type: "missingContext";
274
+ } | {
275
+ /** The direct proof is malformed, unsupported, or invalid. */readonly type: "invalidProof";
276
+ };
277
+ /** Why one portable map did not pass compound proof policy. */
278
+ type CompoundPortableObjectFailureReason = CompoundProofVerificationFailureReason | VerifyPortableObjectProofFailureReason | {
279
+ /** The portable map could not be interpreted by the policy layer. */readonly type: "invalidPortableObject";
280
+ };
295
281
  //#endregion
296
282
  //#region src/sig/accept.d.ts
297
283
  /**
@@ -567,7 +553,7 @@ declare function signRequest(request: Request, privateKey: CryptoKey, keyId: URL
567
553
  /**
568
554
  * Options for {@link verifyRequest}.
569
555
  */
570
- interface VerifyRequestOptions {
556
+ interface VerifyRequestOptions extends VerificationObservationOptions {
571
557
  /**
572
558
  * The document loader to use for fetching the public key.
573
559
  */
@@ -713,4 +699,427 @@ interface HttpMessageSignaturesSpecDeterminer {
713
699
  rememberSpec(origin: string, spec: HttpMessageSignaturesSpec): void | Promise<void>;
714
700
  }
715
701
  //#endregion
716
- export { exportJwk as C, importJwk as D, generateCryptoKeyPair as E, KeyCache as S, fetchKeyDetailed as T, validateAcceptSignature as _, VerifyRequestDetailedResult as a, FetchKeyOptions as b, signRequest as c, AcceptSignatureMember as d, AcceptSignatureParameters as f, parseAcceptSignature as g, fulfillAcceptSignature as h, SignRequestOptions as i, verifyRequest as l, formatAcceptSignature as m, HttpMessageSignaturesSpecDeterminer as n, VerifyRequestFailureReason as o, FulfillAcceptSignatureResult as p, Rfc9421SignRequestOptions as r, VerifyRequestOptions as s, HttpMessageSignaturesSpec as t, verifyRequestDetailed as u, FetchKeyDetailedResult as v, fetchKey as w, FetchKeyResult as x, FetchKeyErrorResult as y };
702
+ //#region src/sig/verification.d.ts
703
+ /**
704
+ * A snapshot of a key actually used to check a signature.
705
+ * @since 2.4.0
706
+ */
707
+ type InboxVerificationKey = {
708
+ readonly type: "cryptographicKey";
709
+ readonly id: URL | null;
710
+ readonly ownerId: URL | null;
711
+ readonly publicKey: CryptoKey;
712
+ } | {
713
+ readonly type: "multikey";
714
+ readonly id: URL | null;
715
+ readonly controllerId: URL | null;
716
+ readonly publicKey: CryptoKey;
717
+ };
718
+ /**
719
+ * Why a cryptographic check failed.
720
+ * @since 2.4.0
721
+ */
722
+ type InboxSignatureFailureReason = {
723
+ readonly type: "invalidSignature";
724
+ } | {
725
+ readonly type: "keyFetchError";
726
+ readonly keyId: URL;
727
+ readonly result: FetchKeyErrorResult;
728
+ };
729
+ /**
730
+ * The signature or proof being checked.
731
+ * @since 2.4.0
732
+ */
733
+ type InboxSignatureIdentity = {
734
+ readonly mechanism: "http";
735
+ readonly spec: HttpMessageSignaturesSpec;
736
+ readonly label: string | null;
737
+ } | {
738
+ readonly mechanism: "linkedData";
739
+ } | {
740
+ readonly mechanism: "objectIntegrity";
741
+ readonly proofId: string | null; /** Index within this evaluation, not a global proof identifier. */
742
+ readonly proofIndex: number | null;
743
+ };
744
+ /**
745
+ * Evidence from one signature/proof, including cached-key retries.
746
+ * @since 2.4.0
747
+ */
748
+ type InboxSignatureCheck = InboxSignatureIdentity & {
749
+ /** The declaration as received, including invalid IRIs. */readonly declaredKeyId: string | null; /** Keys actually tried, in use order; refresh details are not a retry API. */
750
+ readonly triedKeys: readonly InboxVerificationKey[];
751
+ } & ({
752
+ readonly status: "verified";
753
+ readonly key: InboxVerificationKey;
754
+ } | {
755
+ readonly status: "rejected";
756
+ readonly reason: InboxSignatureFailureReason;
757
+ } | {
758
+ readonly status: "error";
759
+ readonly error: unknown;
760
+ });
761
+ /**
762
+ * A bounded proof-policy diagnostic.
763
+ * @since 2.4.0
764
+ */
765
+ type InboxProofPolicyFailureReason = VerifyPortableObjectProofFailureReason | CompoundPortableObjectFailureReason | CompoundProofDiscoveryFailureReason | {
766
+ readonly type: "invalidObjectId" | "invalidDocument" | "subjectMismatch";
767
+ };
768
+ /**
769
+ * Why a complete verification evaluation was rejected.
770
+ * @since 2.4.0
771
+ */
772
+ type InboxVerificationFailureReason = {
773
+ readonly type: "noSignature";
774
+ } | {
775
+ readonly type: "signatureVerificationFailed";
776
+ } | {
777
+ readonly type: "uncoveredAttribution";
778
+ readonly attributionIds: readonly URL[];
779
+ } | {
780
+ readonly type: "missingOwner";
781
+ } | {
782
+ readonly type: "proofPolicy";
783
+ readonly reason: InboxProofPolicyFailureReason;
784
+ };
785
+ /**
786
+ * A logical verification evaluation, separate from inbox authentication.
787
+ * @since 2.4.0
788
+ */
789
+ type InboxVerificationAttempt = {
790
+ readonly mechanism: "http" | "linkedData" | "objectIntegrity";
791
+ readonly subject: {
792
+ readonly id: URL | null; /** RFC 6901 pointer; empty for the root, null when unavailable. */
793
+ readonly pointer: string | null;
794
+ };
795
+ readonly checks: readonly InboxSignatureCheck[];
796
+ } & ({
797
+ readonly status: "verified"; /** Direct references to successful members of checks. */
798
+ readonly signatures: readonly Extract<InboxSignatureCheck, {
799
+ status: "verified";
800
+ }>[];
801
+ } | {
802
+ readonly status: "rejected";
803
+ readonly reason: InboxVerificationFailureReason;
804
+ } | {
805
+ readonly status: "error";
806
+ readonly error: unknown;
807
+ });
808
+ declare const verificationObservation: unique symbol;
809
+ interface VerificationObservationOptions {
810
+ [verificationObservation]?: VerificationObservation;
811
+ }
812
+ interface VerificationObservation {
813
+ readonly attempts: InboxVerificationAttempt[];
814
+ /** False for internal telemetry collectors; observers capture raw IDs by default. */
815
+ readonly captureRawKeyIds?: boolean;
816
+ readonly parsedObject?: (object: unknown) => void;
817
+ readonly subject?: {
818
+ id: URL | null;
819
+ pointer: string | null;
820
+ };
821
+ readonly attempt?: AttemptBuilder;
822
+ readonly check?: CheckBuilder;
823
+ }
824
+ interface AttemptBuilder {
825
+ checks: InboxSignatureCheck[];
826
+ reason?: InboxVerificationFailureReason;
827
+ }
828
+ interface CheckBuilder {
829
+ identity: InboxSignatureIdentity;
830
+ declaredKeyId: string | null;
831
+ triedKeys: InboxVerificationKey[];
832
+ reason?: InboxSignatureFailureReason;
833
+ }
834
+ //#endregion
835
+ //#region src/sig/portable-key.d.ts
836
+ /**
837
+ * The result of resolving a gateway key of a portable actor.
838
+ * @internal
839
+ */
840
+ type PortableGatewayKeyResolution = {
841
+ /**
842
+ * The document at the key ID is not a portable actor, so the key is
843
+ * resolved as usual.
844
+ */
845
+ readonly type: "legacy";
846
+ } | {
847
+ /** The document is a portable actor, but it does not vouch for the key. */readonly type: "rejected";
848
+ readonly reason: string;
849
+ } | {
850
+ /** The portable actor's signed document vouches for the key. */readonly type: "verified";
851
+ readonly actor: Actor;
852
+ readonly key: CryptographicKey & {
853
+ publicKey: CryptoKey;
854
+ };
855
+ /**
856
+ * The expanded root node of the actor's document whose proof was
857
+ * verified, from which {@link actor} was parsed.
858
+ */
859
+ readonly document: Record<string, unknown>;
860
+ /**
861
+ * When the proof of the actor's document expires, if it does. The
862
+ * document does not vouch for the key after that.
863
+ */
864
+ readonly expires?: Temporal.Instant;
865
+ };
866
+ /**
867
+ * The result of resolving a key of a portable actor at an `ap:` or
868
+ * `ap+ef61:` key ID.
869
+ * @internal
870
+ */
871
+ type PortableActorKeyResolution = Exclude<PortableGatewayKeyResolution, {
872
+ readonly type: "legacy";
873
+ }> | {
874
+ /**
875
+ * Whether the actor's document vouches for the key could not be
876
+ * determined, e.g., because no gateway could be reached.
877
+ */
878
+ readonly type: "unavailable";
879
+ readonly error: unknown;
880
+ /**
881
+ * Whether the failure can be cached as a failure to fetch the key, i.e.,
882
+ * every gateway failed to serve the actor's document at all. A failure
883
+ * that is not cacheable comes with an error that has no HTTP status,
884
+ * since none of the statuses describes the lookup as a whole.
885
+ */
886
+ readonly cacheable: boolean;
887
+ };
888
+ //#endregion
889
+ //#region src/sig/key.d.ts
890
+ /**
891
+ * Generates a key pair which is appropriate for Fedify.
892
+ * @param algorithm The algorithm to use. Currently only RSASSA-PKCS1-v1_5 and
893
+ * Ed25519 are supported.
894
+ * @returns The generated key pair.
895
+ * @throws {TypeError} If the algorithm is unsupported.
896
+ */
897
+ declare function generateCryptoKeyPair(algorithm?: "RSASSA-PKCS1-v1_5" | "Ed25519"): Promise<CryptoKeyPair>;
898
+ /**
899
+ * Exports a key in JWK format.
900
+ * @param key The key to export. Either public or private key.
901
+ * @returns The exported key in JWK format. The key is suitable for
902
+ * serialization and storage.
903
+ * @throws {TypeError} If the key is invalid or unsupported.
904
+ */
905
+ declare function exportJwk(key: CryptoKey): Promise<JsonWebKey>;
906
+ /**
907
+ * Imports a key from JWK format.
908
+ * @param jwk The key in JWK format.
909
+ * @param type Which type of key to import, either `"public"` or `"private"`.
910
+ * @returns The imported key.
911
+ * @throws {TypeError} If the key is invalid or unsupported.
912
+ */
913
+ declare function importJwk(jwk: JsonWebKey, type: "public" | "private"): Promise<CryptoKey>;
914
+ /**
915
+ * Options for {@link fetchKey}.
916
+ * @since 1.3.0
917
+ */
918
+ interface FetchKeyOptions extends VerificationObservationOptions {
919
+ /**
920
+ * The document loader for loading remote JSON-LD documents.
921
+ */
922
+ documentLoader?: DocumentLoader;
923
+ /**
924
+ * The context loader for loading remote JSON-LD contexts.
925
+ */
926
+ contextLoader?: DocumentLoader;
927
+ /**
928
+ * The key cache to use for caching public keys.
929
+ * @since 0.12.0
930
+ */
931
+ keyCache?: KeyCache;
932
+ /**
933
+ * The OpenTelemetry tracer provider to use for tracing. If omitted,
934
+ * the global tracer provider is used.
935
+ * @since 1.3.0
936
+ */
937
+ tracerProvider?: TracerProvider;
938
+ /**
939
+ * The OpenTelemetry meter provider to use for recording
940
+ * `activitypub.key.lookup` and `activitypub.key.lookup.duration`. If
941
+ * omitted, the global meter provider is used.
942
+ * @since 2.3.0
943
+ */
944
+ meterProvider?: MeterProvider;
945
+ /**
946
+ * An assertion by the caller that it has already bound this key's id to
947
+ * whoever the key will be treated as speaking for, by means of its own that
948
+ * key resolution cannot see.
949
+ *
950
+ * Key resolution normally settles ownership itself: it dereferences the
951
+ * `owner`/`controller` a key claims and requires that actor's own document
952
+ * to link back to the key, because the claim and the key document come from
953
+ * the same host and so the claim proves nothing on its own. See
954
+ * GHSA-q9f8-5hc7-898f.
955
+ *
956
+ * That check presumes the ActivityPub shape of ownership, where the owner
957
+ * is an actor carrying a `publicKey`/`assertionMethod` list. It does not
958
+ * fit every caller. Portable objects (FEP-ef61) bind a key to an object
959
+ * structurally instead: {@link verifyPortableObjectProof} requires the
960
+ * verification method's FEP-ef34 origin to equal the object id's own
961
+ * authority, so the signer is pinned by the identifier being verified,
962
+ * before any key is fetched. Demanding the ActivityPub check as well would
963
+ * be impossible rather than merely redundant, since a DID dereferences to
964
+ * a DID document, which is not an actor.
965
+ *
966
+ * This is not a way to accept whatever a key says about itself. The claim
967
+ * still has to be corroborated, just from the key id rather than from
968
+ * a second document: a key may name an owner only when the key id is that
969
+ * owner's own (a `did:…#fragment` belongs to the DID it is a fragment of,
970
+ * exactly as a key embedded in an actor document belongs to that actor).
971
+ * A key naming anyone else falls back to the ordinary check and is rejected
972
+ * if it cannot pass it, so a key admitted here is as sound as any other and
973
+ * is cached like any other.
974
+ * @internal
975
+ */
976
+ keyIdBoundByCaller?: boolean;
977
+ /**
978
+ * Resolves keys of [FEP-ef61] portable actors, which only HTTP Signature
979
+ * verification passes, so that only it accepts them. Object Integrity
980
+ * Proofs and Linked Data Signatures never do: such a key is rejected if
981
+ * this is omitted.
982
+ *
983
+ * [FEP-ef61]: https://w3id.org/fep/ef61
984
+ * @internal
985
+ */
986
+ portableKeyResolvers?: PortableKeyResolvers;
987
+ }
988
+ /**
989
+ * Resolves keys of [FEP-ef61] portable actors for HTTP Signature
990
+ * verification. See {@link FetchKeyOptions.portableKeyResolvers}.
991
+ *
992
+ * [FEP-ef61]: https://w3id.org/fep/ef61
993
+ * @internal
994
+ */
995
+ interface PortableKeyResolvers {
996
+ /**
997
+ * Resolves a gateway key, i.e., a key whose ID is a compatible identifier
998
+ * and dereferences to a portable actor's document.
999
+ */
1000
+ gatewayKey(document: unknown, actor: Actor, keyId: URL): Promise<PortableGatewayKeyResolution>;
1001
+ /**
1002
+ * Resolves a key of a portable actor itself, i.e., a key whose ID is an
1003
+ * `ap:` or `ap+ef61:` URI.
1004
+ */
1005
+ actorKey(keyId: URL): Promise<PortableActorKeyResolution>;
1006
+ }
1007
+ /**
1008
+ * The result of {@link fetchKey}.
1009
+ * @since 1.3.0
1010
+ */
1011
+ interface FetchKeyResult<T extends CryptographicKey | Multikey> {
1012
+ /**
1013
+ * The fetched (or cached) key.
1014
+ */
1015
+ readonly key: T & {
1016
+ publicKey: CryptoKey;
1017
+ } | null;
1018
+ /**
1019
+ * Whether the key is fetched from the cache.
1020
+ */
1021
+ readonly cached: boolean;
1022
+ }
1023
+ /**
1024
+ * Detailed fetch failure information from {@link fetchKeyDetailed}.
1025
+ * @since 2.1.0
1026
+ */
1027
+ type FetchKeyErrorResult = {
1028
+ readonly status: number;
1029
+ readonly response: Response;
1030
+ } | {
1031
+ readonly error: Error;
1032
+ };
1033
+ /**
1034
+ * The result of {@link fetchKeyDetailed}.
1035
+ * @since 2.1.0
1036
+ */
1037
+ interface FetchKeyDetailedResult<T extends CryptographicKey | Multikey> extends FetchKeyResult<T> {
1038
+ /**
1039
+ * The error that occurred while fetching the key, if fetching failed before
1040
+ * a document could be parsed.
1041
+ */
1042
+ readonly fetchError?: FetchKeyErrorResult;
1043
+ }
1044
+ type FetchableKeyClass<T extends CryptographicKey | Multikey> = (new (...args: any[]) => T) & {
1045
+ fromJsonLd(jsonLd: unknown, options: {
1046
+ documentLoader?: DocumentLoader;
1047
+ contextLoader?: DocumentLoader;
1048
+ tracerProvider?: TracerProvider;
1049
+ }): Promise<T>;
1050
+ };
1051
+ /**
1052
+ * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL.
1053
+ * If the given URL contains an {@link Actor} object, it tries to find
1054
+ * the corresponding key in the `publicKey` or `assertionMethod` property. *
1055
+ * Gateway keys of [FEP-ef61] portable actors, i.e., keys whose IDs are
1056
+ * compatible identifiers that dereference to portable actor documents, are
1057
+ * not resolved by this function, as they only authenticate HTTP requests;
1058
+ * use `verifyRequest()` or `getKeyOwner()` for them instead. Nor are keys
1059
+ * of portable actors whose IDs are `ap:` or `ap+ef61:` URIs, for the same
1060
+ * reason. Keys whose IDs are compatible identifiers or `ap:` or `ap+ef61:`
1061
+ * URIs are never read from or written to the key cache under their IDs,
1062
+ * except for failures to fetch them.
1063
+ *
1064
+ * [FEP-ef61]: https://w3id.org/fep/ef61
1065
+ * @template T The type of the key to fetch. Either {@link CryptographicKey}
1066
+ * or {@link Multikey}.
1067
+ * @param keyId The URL of the key.
1068
+ * @param cls The class of the key to fetch. Either {@link CryptographicKey}
1069
+ * or {@link Multikey}.
1070
+ * @param options Options for fetching the key. See {@link FetchKeyOptions}.
1071
+ * @returns The fetched key or `null` if the key is not found.
1072
+ * @since 1.3.0
1073
+ */
1074
+ declare function fetchKey<T extends CryptographicKey | Multikey>(keyId: URL | string, cls: FetchableKeyClass<T>, options?: FetchKeyOptions): Promise<FetchKeyResult<T>>;
1075
+ /**
1076
+ * Fetches a {@link CryptographicKey} or {@link Multikey} from the given URL,
1077
+ * preserving transport-level fetch failures for callers that need to inspect
1078
+ * why the key could not be loaded. *
1079
+ * Gateway keys of [FEP-ef61] portable actors, i.e., keys whose IDs are
1080
+ * compatible identifiers that dereference to portable actor documents, are
1081
+ * not resolved by this function, as they only authenticate HTTP requests;
1082
+ * use `verifyRequest()` or `getKeyOwner()` for them instead. Nor are keys
1083
+ * of portable actors whose IDs are `ap:` or `ap+ef61:` URIs, for the same
1084
+ * reason. Keys whose IDs are compatible identifiers or `ap:` or `ap+ef61:`
1085
+ * URIs are never read from or written to the key cache under their IDs,
1086
+ * except for failures to fetch them.
1087
+ *
1088
+ * [FEP-ef61]: https://w3id.org/fep/ef61
1089
+ *
1090
+ * @template T The type of the key to fetch. Either {@link CryptographicKey}
1091
+ * or {@link Multikey}.
1092
+ * @param keyId The URL of the key.
1093
+ * @param cls The class of the key to fetch. Either {@link CryptographicKey}
1094
+ * or {@link Multikey}.
1095
+ * @param options Options for fetching the key.
1096
+ * @returns The fetched key, or detailed fetch failure information.
1097
+ * @since 2.1.0
1098
+ */
1099
+ declare function fetchKeyDetailed<T extends CryptographicKey | Multikey>(keyId: URL | string, cls: FetchableKeyClass<T>, options?: FetchKeyOptions): Promise<FetchKeyDetailedResult<T>>;
1100
+ /**
1101
+ * A cache for storing cryptographic keys.
1102
+ * @since 0.12.0
1103
+ */
1104
+ interface KeyCache {
1105
+ /**
1106
+ * Gets a key from the cache.
1107
+ * @param keyId The key ID.
1108
+ * @returns The key if found, `null` if the key is not available (e.g.,
1109
+ * fetching the key was tried but failed), or `undefined`
1110
+ * if the cache is not available.
1111
+ */
1112
+ get(keyId: URL): Promise<CryptographicKey | Multikey | null | undefined>;
1113
+ /**
1114
+ * Sets a key to the cache.
1115
+ *
1116
+ * Note that this caches unavailable keys (i.e., `null`) as well,
1117
+ * and it is recommended to make unavailable keys expire after a short period.
1118
+ * @param keyId The key ID.
1119
+ * @param key The key to cache. `null` means the key is not available
1120
+ * (e.g., fetching the key was tried but failed).
1121
+ */
1122
+ set(keyId: URL, key: CryptographicKey | Multikey | null): Promise<void>;
1123
+ }
1124
+ //#endregion
1125
+ export { AcceptSignatureParameters as A, VerifyPortableObjectProofOptions as B, VerifyRequestDetailedResult as C, verifyRequest as D, signRequest as E, validateAcceptSignature as F, signObject as G, VerifyProofOptions as H, CreateProofOptions as I, verifyProof as J, verifyObject as K, SignObjectOptions as L, formatAcceptSignature as M, fulfillAcceptSignature as N, verifyRequestDetailed as O, parseAcceptSignature as P, VerifyObjectOptions as R, SignRequestOptions as S, VerifyRequestOptions as T, createProof as U, VerifyPortableObjectProofResult as V, hasProofLike as W, InboxVerificationKey as _, KeyCache as a, HttpMessageSignaturesSpecDeterminer as b, fetchKeyDetailed as c, InboxProofPolicyFailureReason as d, InboxSignatureCheck as f, InboxVerificationFailureReason as g, InboxVerificationAttempt as h, FetchKeyResult as i, FulfillAcceptSignatureResult as j, AcceptSignatureMember as k, generateCryptoKeyPair as l, InboxSignatureIdentity as m, FetchKeyErrorResult as n, exportJwk as o, InboxSignatureFailureReason as p, verifyPortableObjectProof as q, FetchKeyOptions as r, fetchKey as s, FetchKeyDetailedResult as t, importJwk as u, VerificationObservationOptions as v, VerifyRequestFailureReason as w, Rfc9421SignRequestOptions as x, HttpMessageSignaturesSpec as y, VerifyPortableObjectProofFailureReason as z };