Skip to content

Commit 73ab7c3

Browse files
authored
Expose crypto-api as its own typedoc module (#4439)
Currently the crypto-api hierarchy is exposed only as a `Crypto` namespace under the "matrix" entrypoint in the documentation. This isn't really right: it's meant to be a separate entrypoint (in the same way as `types`, `testing` and `utils` are). This PR fixes that problem.
1 parent 3386c66 commit 73ab7c3

File tree

8 files changed

+37
-30
lines changed

8 files changed

+37
-30
lines changed

src/crypto-api/index.ts

+21-12
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,15 @@ import { BackupTrustInfo, KeyBackupCheck, KeyBackupInfo } from "./keybackup.ts";
2525
import { ISignatures } from "../@types/signed.ts";
2626
import { MatrixEvent } from "../models/event.ts";
2727

28+
/**
29+
* `matrix-js-sdk/lib/crypto-api`: End-to-end encryption support.
30+
*
31+
* The most important type is {@link CryptoApi}, an instance of which can be retrieved via
32+
* {@link MatrixClient.getCrypto}.
33+
*
34+
* @packageDocumentation
35+
*/
36+
2837
/**
2938
* Public interface to the cryptography parts of the js-sdk
3039
*
@@ -181,7 +190,7 @@ export interface CryptoApi {
181190
/**
182191
* Return whether we trust other user's signatures of their devices.
183192
*
184-
* @see {@link Crypto.CryptoApi#setTrustCrossSignedDevices}
193+
* @see {@link CryptoApi.setTrustCrossSignedDevices}
185194
*
186195
* @returns `true` if we trust cross-signed devices, otherwise `false`.
187196
*/
@@ -228,7 +237,7 @@ export interface CryptoApi {
228237
*
229238
* @throws an error if the device is unknown, or has not published any encryption keys.
230239
*
231-
* @remarks Fires {@link CryptoEvent#DeviceVerificationChanged}
240+
* @remarks Fires {@link matrix.CryptoEvent.DeviceVerificationChanged}
232241
*/
233242
setDeviceVerified(userId: string, deviceId: string, verified?: boolean): Promise<void>;
234243

@@ -259,7 +268,7 @@ export interface CryptoApi {
259268
*
260269
* @returns True if cross-signing is ready to be used on this device
261270
*
262-
* @throws May throw {@link ClientStoppedError} if the `MatrixClient` is stopped before or during the call.
271+
* @throws May throw {@link matrix.ClientStoppedError} if the `MatrixClient` is stopped before or during the call.
263272
*/
264273
isCrossSigningReady(): Promise<boolean>;
265274

@@ -327,7 +336,7 @@ export interface CryptoApi {
327336
* @returns The current status of cross-signing keys: whether we have public and private keys cached locally, and
328337
* whether the private keys are in secret storage.
329338
*
330-
* @throws May throw {@link ClientStoppedError} if the `MatrixClient` is stopped before or during the call.
339+
* @throws May throw {@link matrix.ClientStoppedError} if the `MatrixClient` is stopped before or during the call.
331340
*/
332341
getCrossSigningStatus(): Promise<CrossSigningStatus>;
333342

@@ -407,8 +416,8 @@ export interface CryptoApi {
407416
*
408417
* If an all-devices verification is already in flight, returns it. Otherwise, initiates a new one.
409418
*
410-
* To control the methods offered, set {@link ICreateClientOpts.verificationMethods} when creating the
411-
* MatrixClient.
419+
* To control the methods offered, set {@link matrix.ICreateClientOpts.verificationMethods} when creating the
420+
* `MatrixClient`.
412421
*
413422
* @returns a VerificationRequest when the request has been sent to the other party.
414423
*/
@@ -422,8 +431,8 @@ export interface CryptoApi {
422431
*
423432
* If a verification for this user/device is already in flight, returns it. Otherwise, initiates a new one.
424433
*
425-
* To control the methods offered, set {@link ICreateClientOpts.verificationMethods} when creating the
426-
* MatrixClient.
434+
* To control the methods offered, set {@link matrix.ICreateClientOpts.verificationMethods} when creating the
435+
* `MatrixClient`.
427436
*
428437
* @param userId - ID of the owner of the device to verify
429438
* @param deviceId - ID of the device to verify
@@ -480,7 +489,7 @@ export interface CryptoApi {
480489
/**
481490
* Determine if a key backup can be trusted.
482491
*
483-
* @param info - key backup info dict from {@link MatrixClient#getKeyBackupVersion}.
492+
* @param info - key backup info dict from {@link matrix.MatrixClient.getKeyBackupVersion}.
484493
*/
485494
isKeyBackupTrusted(info: KeyBackupInfo): Promise<BackupTrustInfo>;
486495

@@ -500,7 +509,7 @@ export interface CryptoApi {
500509
*
501510
* If there are existing backups they will be replaced.
502511
*
503-
* The decryption key will be saved in Secret Storage (the {@link SecretStorageCallbacks.getSecretStorageKey} Crypto
512+
* The decryption key will be saved in Secret Storage (the {@link matrix.SecretStorage.SecretStorageCallbacks.getSecretStorageKey} Crypto
504513
* callback will be called)
505514
* and the backup engine will be started.
506515
*/
@@ -841,9 +850,9 @@ export class DeviceVerificationStatus {
841850
* Check if we should consider this device "verified".
842851
*
843852
* A device is "verified" if either:
844-
* * it has been manually marked as such via {@link MatrixClient#setDeviceVerified}.
853+
* * it has been manually marked as such via {@link matrix.MatrixClient.setDeviceVerified}.
845854
* * it has been cross-signed with a verified signing key, **and** the client has been configured to trust
846-
* cross-signed devices via {@link Crypto.CryptoApi#setTrustCrossSignedDevices}.
855+
* cross-signed devices via {@link CryptoApi.setTrustCrossSignedDevices}.
847856
*
848857
* @returns true if this device is verified via any means.
849858
*/

src/crypto-api/keybackup.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export interface Aes256AuthData {
3535
* Information about a server-side key backup.
3636
*
3737
* Returned by [`GET /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3room_keysversion)
38-
* and hence {@link MatrixClient#getKeyBackupVersion}.
38+
* and hence {@link matrix.MatrixClient.getKeyBackupVersion}.
3939
*/
4040
export interface KeyBackupInfo {
4141
algorithm: string;
@@ -63,7 +63,7 @@ export interface BackupTrustInfo {
6363
}
6464

6565
/**
66-
* The result of {@link Crypto.CryptoApi.checkKeyBackupAndEnable}.
66+
* The result of {@link CryptoApi.checkKeyBackupAndEnable}.
6767
*/
6868
export interface KeyBackupCheck {
6969
backupInfo: KeyBackupInfo;

src/crypto-api/verification.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ export interface VerificationRequest
119119
*
120120
* If a verifier has already been created for this request, returns that verifier.
121121
*
122-
* This does *not* send the `m.key.verification.start` event - to do so, call {@link Crypto.Verifier#verify} on the
122+
* This does *not* send the `m.key.verification.start` event - to do so, call {@link Verifier.verify} on the
123123
* returned verifier.
124124
*
125125
* If no previous events have been sent, pass in `targetDevice` to set who to direct this request to.
@@ -281,7 +281,7 @@ export interface Verifier extends TypedEventEmitter<VerifierEvent, VerifierEvent
281281
* Cancel a verification.
282282
*
283283
* We will send an `m.key.verification.cancel` if the verification is still in flight. The verification promise
284-
* will reject, and a {@link Crypto.VerifierEvent#Cancel} will be emitted.
284+
* will reject, and a {@link crypto-api.VerifierEvent.Cancel | VerifierEvent.Cancel} will be emitted.
285285
*
286286
* @param e - the reason for the cancellation.
287287
*/

src/matrix.ts

+1-6
Original file line numberDiff line numberDiff line change
@@ -108,12 +108,7 @@ export type { ISSOFlow as SSOFlow, LoginFlow } from "./@types/auth.ts";
108108
export type { IHierarchyRelation as HierarchyRelation, IHierarchyRoom as HierarchyRoom } from "./@types/spaces.ts";
109109
export { LocationAssetType } from "./@types/location.ts";
110110

111-
/**
112-
* Types supporting cryptography.
113-
*
114-
* The most important is {@link Crypto.CryptoApi}, an instance of which can be retrieved via
115-
* {@link MatrixClient.getCrypto}.
116-
*/
111+
/** @deprecated Backwards-compatibility re-export. Import from `crypto-api` directly. */
117112
export * as Crypto from "./crypto-api/index.ts";
118113

119114
let cryptoStoreFactory = (): CryptoStore => new MemoryCryptoStore();

src/models/typed-event-emitter.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export class TypedEventEmitter<
6565
SuperclassArguments extends ListenerMap<any> = Arguments,
6666
> extends EventEmitter {
6767
/**
68-
* Alias for {@link TypedEventEmitter#on}.
68+
* Alias for {@link on}.
6969
*/
7070
public addListener<T extends Events | EventEmitterEvents>(
7171
event: T,
@@ -124,7 +124,7 @@ export class TypedEventEmitter<
124124
}
125125

126126
/**
127-
* Alias for {@link TypedEventEmitter#removeListener}
127+
* Alias for {@link removeListener}
128128
*/
129129
public off<T extends Events | EventEmitterEvents>(event: T, listener: Listener<Events, Arguments, T>): this {
130130
return super.off(event, listener);
@@ -139,7 +139,7 @@ export class TypedEventEmitter<
139139
* being added, and called, multiple times.
140140
*
141141
* By default, event listeners are invoked in the order they are added. The
142-
* {@link TypedEventEmitter#prependListener} method can be used as an alternative to add the
142+
* {@link prependListener} method can be used as an alternative to add the
143143
* event listener to the beginning of the listeners array.
144144
*
145145
* @param event - The name of the event.
@@ -158,7 +158,7 @@ export class TypedEventEmitter<
158158
* Returns a reference to the `EventEmitter`, so that calls can be chained.
159159
*
160160
* By default, event listeners are invoked in the order they are added.
161-
* The {@link TypedEventEmitter#prependOnceListener} method can be used as an alternative to add the
161+
* The {@link prependOnceListener} method can be used as an alternative to add the
162162
* event listener to the beginning of the listeners array.
163163
*
164164
* @param event - The name of the event.

src/secret-storage.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export interface SecretStorageCallbacks {
164164
* Descriptions of the secret storage keys are also stored in server-side storage, per the
165165
* [matrix specification](https://spec.matrix.org/v1.6/client-server-api/#key-storage), so
166166
* before a key can be used in this way, it must have been stored on the server. This is
167-
* done via {@link SecretStorage.ServerSideSecretStorage#addKey}.
167+
* done via {@link ServerSideSecretStorage#addKey}.
168168
*
169169
* Obviously the keys themselves are not stored server-side, so the js-sdk calls this callback
170170
* in order to retrieve a secret storage key from the application.

src/store/indexeddb.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ import { logger } from "../logger.ts";
2424
import { ISavedSync } from "./index.ts";
2525
import { IIndexedDBBackend } from "./indexeddb-backend.ts";
2626
import { ISyncResponse } from "../sync-accumulator.ts";
27-
import { TypedEventEmitter } from "../models/typed-event-emitter.ts";
27+
import { EventEmitterEvents, TypedEventEmitter } from "../models/typed-event-emitter.ts";
2828
import { IStateEventWithRoomId } from "../@types/search.ts";
2929
import { IndexedToDeviceBatch, ToDeviceBatchWithTxnId } from "../models/ToDeviceMessage.ts";
3030
import { IStoredClientOpts } from "../client.ts";
@@ -118,7 +118,10 @@ export class IndexedDBStore extends MemoryStore {
118118
}
119119
}
120120

121-
public on = this.emitter.on.bind(this.emitter);
121+
/** Re-exports `TypedEventEmitter.on` */
122+
public on(event: EventEmitterEvents | "degraded" | "closed", handler: (...args: any[]) => void): void {
123+
this.emitter.on(event, handler);
124+
}
122125

123126
/**
124127
* @returns Resolved when loaded from indexed db.

typedoc.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"$schema": "https://typedoc.org/schema.json",
33
"plugin": ["typedoc-plugin-mdn-links", "typedoc-plugin-missing-exports", "typedoc-plugin-coverage"],
44
"coverageLabel": "TypeDoc",
5-
"entryPoints": ["src/matrix.ts", "src/types.ts", "src/testing.ts", "src/utils/*.ts"],
5+
"entryPoints": ["src/matrix.ts", "src/crypto-api", "src/types.ts", "src/testing.ts", "src/utils/*.ts"],
66
"excludeExternals": true,
77
"out": "_docs"
88
}

0 commit comments

Comments
 (0)