feat: complete Ancestor quote bot with production-ready Docker support

This commit is contained in:
unfunny
2026-09-13 14:14:38 -04:00
parent f2016da05a
commit fe7351a7dc
1145 changed files with 30890 additions and 97684 deletions

View File

@@ -1,120 +0,0 @@
/**
* Cryptography-related events emitted by the {@link matrix.MatrixClient}.
*/
export declare enum CryptoEvent {
/**
* Fires when the trust status of a user changes.
* The payload is a pair (userId, userTrustLevel). The trust level is one of the values from UserVerificationStatus.
*/
UserTrustStatusChanged = "userTrustStatusChanged",
/**
* Fires when the key backup status changes.
* The payload is a boolean indicating whether the key backup is enabled.
*/
KeyBackupStatus = "crypto.keyBackupStatus",
/**
* Fires when we failed to back up the keys
* The payload is the error code of the error that occurred.
*/
KeyBackupFailed = "crypto.keyBackupFailed",
/**
* Fires when the number of sessions that can be backed up changes.
* The payload is the remaining number of sessions that can be backed up.
*/
KeyBackupSessionsRemaining = "crypto.keyBackupSessionsRemaining",
/**
* Fires when a new valid backup decryption key is in cache.
* This will happen when a secret is received from another session, from secret storage,
* or when a new backup is created from this session.
*
* The payload is the version of the backup for which we have the key for.
*
* This event is only fired by the rust crypto backend.
*/
KeyBackupDecryptionKeyCached = "crypto.keyBackupDecryptionKeyCached",
/**
* Fires when a key verification request is received.
* The payload is a VerificationRequest object representing the request.
*/
VerificationRequestReceived = "crypto.verificationRequestReceived",
/** @deprecated Use {@link DevicesUpdated} instead when using rust crypto */
WillUpdateDevices = "crypto.willUpdateDevices",
/**
* Fires whenever the stored devices for a user have been updated
* The payload is a pair (userIds, initialFetch).
*/
DevicesUpdated = "crypto.devicesUpdated",
/**
* Fires when the user's cross-signing keys have changed or cross-signing
* has been enabled/disabled. The client can use getStoredCrossSigningForUser
* with the user ID of the logged in user to check if cross-signing is
* enabled on the account. If enabled, it can test whether the current key
* is trusted using with checkUserTrust with the user ID of the logged
* in user. The checkOwnCrossSigningTrust function may be used to reconcile
* the trust in the account key.
*
* The cross-signing API is currently UNSTABLE and may change without notice.
* @experimental
*/
KeysChanged = "crossSigning.keysChanged",
/**
* Fires when data is being migrated from legacy crypto to rust crypto.
*
* The payload is a pair `(progress, total)`, where `progress` is the number of steps completed so far, and
* `total` is the total number of steps. When migration is complete, a final instance of the event is emitted, with
* `progress === total === -1`.
*/
LegacyCryptoStoreMigrationProgress = "crypto.legacyCryptoStoreMigrationProgress",
/**
* Fires when a new dehydrated device is created locally.
*
* After the client calls {@link CryptoApi.startDehydration}, this event
* will be fired every time a new dehydrated device is created. It may fire
* before `startDehydration` returns.
*/
DehydratedDeviceCreated = "dehydration.DehydratedDeviceCreated",
/**
* Fires when a new dehydrated device is successfully uploaded to the server.
*
* This should fire shortly after {@link DehydratedDeviceCreated} fires. If
* upload is unsuccessful, this will be reported either by an error thrown
* by {@link CryptoApi.startDehydration} (for errors that happen before
* `startDehydration` returns), or by firing {@link DehydratedDeviceRotationError}
* (for errors that happen during regular rotation of the dehydrated device)
*/
DehydratedDeviceUploaded = "dehydration.DehydratedDeviceUploaded",
/**
* Fires when rehydration has started.
*
* After the client calls {@link CryptoApi.startDehydration}, this event will
* fire if a dehydrated device is found and we attempt to rehydrate it.
*/
RehydrationStarted = "dehydration.RehydrationStarted",
/**
* Fires during rehydration, to inform the application of rehydration progress.
*
* The payload is a pair `[roomKeyCount: number, toDeviceCount: number]`,
* where `roomKeyCount` is the number of room keys that have been received
* so far, and `toDeviceCount` is the number of to-device messages received
* so far (including the messages containing room keys).
*/
RehydrationProgress = "dehydration.RehydrationProgress",
/** Fires when rehydration has completed successfully. */
RehydrationCompleted = "dehydration.RehydrationCompleted",
/** Fires when there was an error in rehydration.
*
* The payload is an error message as a string.
*/
RehydrationError = "dehydration.RehydrationError",
/**
* Fires when a dehydrated device key has been cached in the local database.
*/
DehydrationKeyCached = "dehydration.DehydrationKeyCached",
/**
* Fires when an error occurs during periodic rotation of the dehydrated device.
*
* The payload is an error message as a string.
*/
DehydratedDeviceRotationError = "dehydration.DehydratedDeviceRotationError"
}
//# sourceMappingURL=CryptoEvent.d.ts.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"CryptoEvent.d.ts","sourceRoot":"","sources":["../../src/crypto-api/CryptoEvent.ts"],"names":[],"mappings":"AAgBA;;GAEG;AACH,oBAAY,WAAW;IACnB;;;OAGG;IACH,sBAAsB,2BAA2B;IAEjD;;;OAGG;IACH,eAAe,2BAA2B;IAE1C;;;OAGG;IACH,eAAe,2BAA2B;IAE1C;;;OAGG;IACH,0BAA0B,sCAAsC;IAEhE;;;;;;;;OAQG;IACH,4BAA4B,wCAAwC;IAEpE;;;OAGG;IACH,2BAA2B,uCAAuC;IAElE,4EAA4E;IAC5E,iBAAiB,6BAA6B;IAE9C;;;OAGG;IACH,cAAc,0BAA0B;IAExC;;;;;;;;;;;OAWG;IACH,WAAW,6BAA6B;IAExC;;;;;;OAMG;IACH,kCAAkC,8CAA8C;IAEhF;;;;;;OAMG;IACH,uBAAuB,wCAAwC;IAE/D;;;;;;;;OAQG;IACH,wBAAwB,yCAAyC;IAEjE;;;;;OAKG;IACH,kBAAkB,mCAAmC;IAErD;;;;;;;OAOG;IACH,mBAAmB,oCAAoC;IAEvD,yDAAyD;IACzD,oBAAoB,qCAAqC;IAEzD;;;OAGG;IACH,gBAAgB,iCAAiC;IAEjD;;OAEG;IACH,oBAAoB,qCAAqC;IAEzD;;;;OAIG;IACH,6BAA6B,8CAA8C;CAC9E"}

View File

@@ -1,137 +0,0 @@
/*
* Copyright 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Cryptography-related events emitted by the {@link matrix.MatrixClient}.
*/
export let CryptoEvent = /*#__PURE__*/function (CryptoEvent) {
/**
* Fires when the trust status of a user changes.
* The payload is a pair (userId, userTrustLevel). The trust level is one of the values from UserVerificationStatus.
*/
CryptoEvent["UserTrustStatusChanged"] = "userTrustStatusChanged";
/**
* Fires when the key backup status changes.
* The payload is a boolean indicating whether the key backup is enabled.
*/
CryptoEvent["KeyBackupStatus"] = "crypto.keyBackupStatus";
/**
* Fires when we failed to back up the keys
* The payload is the error code of the error that occurred.
*/
CryptoEvent["KeyBackupFailed"] = "crypto.keyBackupFailed";
/**
* Fires when the number of sessions that can be backed up changes.
* The payload is the remaining number of sessions that can be backed up.
*/
CryptoEvent["KeyBackupSessionsRemaining"] = "crypto.keyBackupSessionsRemaining";
/**
* Fires when a new valid backup decryption key is in cache.
* This will happen when a secret is received from another session, from secret storage,
* or when a new backup is created from this session.
*
* The payload is the version of the backup for which we have the key for.
*
* This event is only fired by the rust crypto backend.
*/
CryptoEvent["KeyBackupDecryptionKeyCached"] = "crypto.keyBackupDecryptionKeyCached";
/**
* Fires when a key verification request is received.
* The payload is a VerificationRequest object representing the request.
*/
CryptoEvent["VerificationRequestReceived"] = "crypto.verificationRequestReceived";
/** @deprecated Use {@link DevicesUpdated} instead when using rust crypto */
CryptoEvent["WillUpdateDevices"] = "crypto.willUpdateDevices";
/**
* Fires whenever the stored devices for a user have been updated
* The payload is a pair (userIds, initialFetch).
*/
CryptoEvent["DevicesUpdated"] = "crypto.devicesUpdated";
/**
* Fires when the user's cross-signing keys have changed or cross-signing
* has been enabled/disabled. The client can use getStoredCrossSigningForUser
* with the user ID of the logged in user to check if cross-signing is
* enabled on the account. If enabled, it can test whether the current key
* is trusted using with checkUserTrust with the user ID of the logged
* in user. The checkOwnCrossSigningTrust function may be used to reconcile
* the trust in the account key.
*
* The cross-signing API is currently UNSTABLE and may change without notice.
* @experimental
*/
CryptoEvent["KeysChanged"] = "crossSigning.keysChanged";
/**
* Fires when data is being migrated from legacy crypto to rust crypto.
*
* The payload is a pair `(progress, total)`, where `progress` is the number of steps completed so far, and
* `total` is the total number of steps. When migration is complete, a final instance of the event is emitted, with
* `progress === total === -1`.
*/
CryptoEvent["LegacyCryptoStoreMigrationProgress"] = "crypto.legacyCryptoStoreMigrationProgress";
/**
* Fires when a new dehydrated device is created locally.
*
* After the client calls {@link CryptoApi.startDehydration}, this event
* will be fired every time a new dehydrated device is created. It may fire
* before `startDehydration` returns.
*/
CryptoEvent["DehydratedDeviceCreated"] = "dehydration.DehydratedDeviceCreated";
/**
* Fires when a new dehydrated device is successfully uploaded to the server.
*
* This should fire shortly after {@link DehydratedDeviceCreated} fires. If
* upload is unsuccessful, this will be reported either by an error thrown
* by {@link CryptoApi.startDehydration} (for errors that happen before
* `startDehydration` returns), or by firing {@link DehydratedDeviceRotationError}
* (for errors that happen during regular rotation of the dehydrated device)
*/
CryptoEvent["DehydratedDeviceUploaded"] = "dehydration.DehydratedDeviceUploaded";
/**
* Fires when rehydration has started.
*
* After the client calls {@link CryptoApi.startDehydration}, this event will
* fire if a dehydrated device is found and we attempt to rehydrate it.
*/
CryptoEvent["RehydrationStarted"] = "dehydration.RehydrationStarted";
/**
* Fires during rehydration, to inform the application of rehydration progress.
*
* The payload is a pair `[roomKeyCount: number, toDeviceCount: number]`,
* where `roomKeyCount` is the number of room keys that have been received
* so far, and `toDeviceCount` is the number of to-device messages received
* so far (including the messages containing room keys).
*/
CryptoEvent["RehydrationProgress"] = "dehydration.RehydrationProgress";
/** Fires when rehydration has completed successfully. */
CryptoEvent["RehydrationCompleted"] = "dehydration.RehydrationCompleted";
/** Fires when there was an error in rehydration.
*
* The payload is an error message as a string.
*/
CryptoEvent["RehydrationError"] = "dehydration.RehydrationError";
/**
* Fires when a dehydrated device key has been cached in the local database.
*/
CryptoEvent["DehydrationKeyCached"] = "dehydration.DehydrationKeyCached";
/**
* Fires when an error occurs during periodic rotation of the dehydrated device.
*
* The payload is an error message as a string.
*/
CryptoEvent["DehydratedDeviceRotationError"] = "dehydration.DehydratedDeviceRotationError";
return CryptoEvent;
}({});
//# sourceMappingURL=CryptoEvent.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,26 +0,0 @@
import { type CryptoEvent } from "./CryptoEvent.ts";
import { type VerificationRequest } from "./verification.ts";
import { type UserVerificationStatus } from "./index.ts";
import { type RustBackupCryptoEventMap } from "../rust-crypto/backup.ts";
import { type EmptyObject } from "../@types/common.ts";
/**
* A map of the {@link CryptoEvent} fired by the {@link CryptoApi} and their payloads.
*/
export type CryptoEventHandlerMap = {
[CryptoEvent.VerificationRequestReceived]: (request: VerificationRequest) => void;
[CryptoEvent.UserTrustStatusChanged]: (userId: string, userTrustLevel: UserVerificationStatus) => void;
[CryptoEvent.KeyBackupDecryptionKeyCached]: (version: string) => void;
[CryptoEvent.KeysChanged]: (data: EmptyObject) => void;
[CryptoEvent.WillUpdateDevices]: (users: string[], initialFetch: boolean) => void;
[CryptoEvent.DevicesUpdated]: (users: string[], initialFetch: boolean) => void;
[CryptoEvent.LegacyCryptoStoreMigrationProgress]: (progress: number, total: number) => void;
[CryptoEvent.DehydratedDeviceCreated]: () => void;
[CryptoEvent.DehydratedDeviceUploaded]: () => void;
[CryptoEvent.RehydrationStarted]: () => void;
[CryptoEvent.RehydrationProgress]: (roomKeyCount: number, toDeviceCount: number) => void;
[CryptoEvent.RehydrationCompleted]: () => void;
[CryptoEvent.RehydrationError]: (msg: string) => void;
[CryptoEvent.DehydrationKeyCached]: () => void;
[CryptoEvent.DehydratedDeviceRotationError]: (msg: string) => void;
} & RustBackupCryptoEventMap;
//# sourceMappingURL=CryptoEventHandlerMap.d.ts.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"CryptoEventHandlerMap.d.ts","sourceRoot":"","sources":["../../src/crypto-api/CryptoEventHandlerMap.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC;AACpD,OAAO,EAAE,KAAK,mBAAmB,EAAE,MAAM,mBAAmB,CAAC;AAC7D,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,YAAY,CAAC;AACzD,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AC;IAC/C,CAAC,WAAW,CAAC,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,CAAC,WAAW,CAAC,oBAAoB,CAAC,EAAE,MAAM,IAAI,CAAC;IAC/C,CAAC,WAAW,CAAC,6BAA6B,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CACtE,GAAG,wBAAwB,CAAC"}

View File

@@ -1,3 +0,0 @@
export {};
export {};
//# sourceMappingURL=CryptoEventHandlerMap.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"CryptoEventHandlerMap.js","names":[],"sources":["../../src/crypto-api/CryptoEventHandlerMap.ts"],"sourcesContent":["/*\n * Copyright 2024 The Matrix.org Foundation C.I.C.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { type CryptoEvent } from \"./CryptoEvent.ts\";\nimport { type VerificationRequest } from \"./verification.ts\";\nimport { type UserVerificationStatus } from \"./index.ts\";\nimport { type RustBackupCryptoEventMap } from \"../rust-crypto/backup.ts\";\nimport { type EmptyObject } from \"../@types/common.ts\";\n\n/**\n * A map of the {@link CryptoEvent} fired by the {@link CryptoApi} and their payloads.\n */\nexport type CryptoEventHandlerMap = {\n [CryptoEvent.VerificationRequestReceived]: (request: VerificationRequest) => void;\n [CryptoEvent.UserTrustStatusChanged]: (userId: string, userTrustLevel: UserVerificationStatus) => void;\n [CryptoEvent.KeyBackupDecryptionKeyCached]: (version: string) => void;\n [CryptoEvent.KeysChanged]: (data: EmptyObject) => void;\n [CryptoEvent.WillUpdateDevices]: (users: string[], initialFetch: boolean) => void;\n [CryptoEvent.DevicesUpdated]: (users: string[], initialFetch: boolean) => void;\n [CryptoEvent.LegacyCryptoStoreMigrationProgress]: (progress: number, total: number) => void;\n [CryptoEvent.DehydratedDeviceCreated]: () => void;\n [CryptoEvent.DehydratedDeviceUploaded]: () => void;\n [CryptoEvent.RehydrationStarted]: () => void;\n [CryptoEvent.RehydrationProgress]: (roomKeyCount: number, toDeviceCount: number) => void;\n [CryptoEvent.RehydrationCompleted]: () => void;\n [CryptoEvent.RehydrationError]: (msg: string) => void;\n [CryptoEvent.DehydrationKeyCached]: () => void;\n [CryptoEvent.DehydratedDeviceRotationError]: (msg: string) => void;\n} & RustBackupCryptoEventMap;\n"],"mappings":"","ignoreList":[]}

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@@ -1,435 +0,0 @@
import _defineProperty from "@babel/runtime/helpers/defineProperty";
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* `matrix-js-sdk/lib/crypto-api`: End-to-end encryption support.
*
* The most important type is {@link CryptoApi}, an instance of which can be retrieved via
* {@link MatrixClient.getCrypto}.
*
* @packageDocumentation
*/
/**
* The options to start device dehydration.
*/
/**
* Public interface to the cryptography parts of the js-sdk
*/
/** A reason code for a failure to decrypt an event. */
export let DecryptionFailureCode = /*#__PURE__*/function (DecryptionFailureCode) {
/** Message was encrypted with a Megolm session whose keys have not been shared with us. */
DecryptionFailureCode["MEGOLM_UNKNOWN_INBOUND_SESSION_ID"] = "MEGOLM_UNKNOWN_INBOUND_SESSION_ID";
/** A special case of {@link MEGOLM_UNKNOWN_INBOUND_SESSION_ID}: the sender has told us it is withholding the key. */
DecryptionFailureCode["MEGOLM_KEY_WITHHELD"] = "MEGOLM_KEY_WITHHELD";
/** A special case of {@link MEGOLM_KEY_WITHHELD}: the sender has told us it is withholding the key, because the current device is unverified. */
DecryptionFailureCode["MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE"] = "MEGOLM_KEY_WITHHELD_FOR_UNVERIFIED_DEVICE";
/** Message was encrypted with a Megolm session which has been shared with us, but in a later ratchet state. */
DecryptionFailureCode["OLM_UNKNOWN_MESSAGE_INDEX"] = "OLM_UNKNOWN_MESSAGE_INDEX";
/**
* Message was sent before the current device was created; there is no key backup on the server, so this
* decryption failure is expected.
*/
DecryptionFailureCode["HISTORICAL_MESSAGE_NO_KEY_BACKUP"] = "HISTORICAL_MESSAGE_NO_KEY_BACKUP";
/**
* Message was sent before the current device was created; there was a key backup on the server, but we don't
* seem to have access to the backup. (Probably we don't have the right key.)
*/
DecryptionFailureCode["HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED"] = "HISTORICAL_MESSAGE_BACKUP_UNCONFIGURED";
/**
* Message was sent before the current device was created; there was a (usable) key backup on the server, but we
* still can't decrypt. (Either the session isn't in the backup, or we just haven't gotten around to checking yet.)
*/
DecryptionFailureCode["HISTORICAL_MESSAGE_WORKING_BACKUP"] = "HISTORICAL_MESSAGE_WORKING_BACKUP";
/**
* Message was sent when the user was not a member of the room.
*/
DecryptionFailureCode["HISTORICAL_MESSAGE_USER_NOT_JOINED"] = "HISTORICAL_MESSAGE_USER_NOT_JOINED";
/**
* The sender's identity is not verified, but was previously verified.
*/
DecryptionFailureCode["SENDER_IDENTITY_PREVIOUSLY_VERIFIED"] = "SENDER_IDENTITY_PREVIOUSLY_VERIFIED";
/**
* The sender device is not cross-signed. This will only be used if the
* device isolation mode is set to `OnlySignedDevicesIsolationMode`.
*/
DecryptionFailureCode["UNSIGNED_SENDER_DEVICE"] = "UNSIGNED_SENDER_DEVICE";
/**
* We weren't able to link the message back to any known device. This will
* only be used if the device isolation mode is set to `OnlySignedDevicesIsolationMode`.
*/
DecryptionFailureCode["UNKNOWN_SENDER_DEVICE"] = "UNKNOWN_SENDER_DEVICE";
/** Unknown or unclassified error. */
DecryptionFailureCode["UNKNOWN_ERROR"] = "UNKNOWN_ERROR";
return DecryptionFailureCode;
}({});
/** Base {@link DeviceIsolationMode} kind. */
export let DeviceIsolationModeKind = /*#__PURE__*/function (DeviceIsolationModeKind) {
DeviceIsolationModeKind[DeviceIsolationModeKind["AllDevicesIsolationMode"] = 0] = "AllDevicesIsolationMode";
DeviceIsolationModeKind[DeviceIsolationModeKind["OnlySignedDevicesIsolationMode"] = 1] = "OnlySignedDevicesIsolationMode";
return DeviceIsolationModeKind;
}({});
/**
* A type of {@link DeviceIsolationMode}.
*
* Message encryption keys are shared with all devices in the room, except in case of
* verified user problems (see {@link errorOnVerifiedUserProblems}).
*
* Events from all senders are always decrypted (and should be decorated with message shields in case
* of authenticity warnings, see {@link EventEncryptionInfo}).
*
* `AllDevicesIsolationMode` is used in the legacy, non-'exclude insecure devices' mode in Element Web. It is not
* recommended (see {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4153 | MSC4153}).
*/
export class AllDevicesIsolationMode {
/**
*
* @param errorOnVerifiedUserProblems - Behavior when sharing keys to remote devices.
*
* If set to `true`, sharing keys will fail (i.e. message sending will fail) with an error if:
* - The user was previously verified but is not anymore, or:
* - A verified user has some unverified devices (not cross-signed).
*
* If `false`, the keys will be distributed as usual. In this case, the client UX should display
* warnings to inform the user about problematic devices/users, and stop them hitting this case.
*/
constructor(errorOnVerifiedUserProblems) {
_defineProperty(this, "kind", DeviceIsolationModeKind.AllDevicesIsolationMode);
this.errorOnVerifiedUserProblems = errorOnVerifiedUserProblems;
}
}
/**
* A type of {@link DeviceIsolationMode}.
*
* Message encryption keys are only shared with devices that have been cross-signed by their owner.
* Encryption will throw an error if a verified user replaces their identity.
*
* Events are decrypted only if they come from a cross-signed device. Other events will result in a decryption
* failure. (To access the failure reason, see {@link MatrixEvent.decryptionFailureReason}.)
*
* `OnlySignedDevicesIsolationMode` corresponds to the 'Exclude insecure devices' mode in Element Web, which is
* recommended by {@link https://github.com/matrix-org/matrix-spec-proposals/pull/4153 | MSC4153}.
*/
export class OnlySignedDevicesIsolationMode {
constructor() {
_defineProperty(this, "kind", DeviceIsolationModeKind.OnlySignedDevicesIsolationMode);
}
}
/**
* DeviceIsolationMode represents the mode of device isolation used when encrypting or decrypting messages.
* It can be one of two types: {@link AllDevicesIsolationMode} or {@link OnlySignedDevicesIsolationMode}.
*
* Only supported by rust Crypto.
*/
/**
* Options object for `CryptoApi.bootstrapCrossSigning`.
*/
/**
* Represents the ways in which we trust a user
*/
export class UserVerificationStatus {
/** @internal */
constructor(crossSigningVerified, crossSigningVerifiedBefore, known, needsUserApproval = false) {
/**
* Indicates if we have saved a known identity for this user. Typically, this means that we share a
* room with them (or have done in the past).
*
* If this is `false`, then the other flags ({@link isCrossSigningVerified}, {@link wasCrossSigningVerified},
* {@link needsUserApproval}) will also be `false`. This means that we haven't seen this user before.
*
* If this is `true`, then there are further possibilities:
*
* - If {@link isCrossSigningVerified} returns `true`, then we have cryptographically verified the current
* identity of this user: that is the highest form of trust we have.
*
* - If {@link needsUserApproval} is `true`, that means that the user has changed their identity.
*
* - Otherwise, the user is "TOFU trusted": we have a record of their identity, and, typically, will share
* encrypted content with them as long as they retain that identity.
*/
_defineProperty(this, "known", void 0);
/**
* Indicates if the identity has changed in a way that needs user approval.
*
* This happens if the identity has changed since we first saw it, *unless* the new identity has also been verified
* by our user (eg via an interactive verification).
*
* To rectify this, either:
*
* * Conduct a verification of the new identity via {@link CryptoApi.requestVerificationDM}.
* * Pin the new identity, via {@link CryptoApi.pinCurrentUserIdentity}.
*
* @returns true if the identity has changed in a way that needs user approval.
*/
_defineProperty(this, "needsUserApproval", void 0);
this.crossSigningVerified = crossSigningVerified;
this.crossSigningVerifiedBefore = crossSigningVerifiedBefore;
this.known = known;
this.needsUserApproval = needsUserApproval;
}
/**
* @returns true if this user is verified via any means
*/
isVerified() {
return this.isCrossSigningVerified();
}
/**
* @returns true if this user is verified via cross signing
*/
isCrossSigningVerified() {
return this.crossSigningVerified;
}
/**
* @returns true if we ever verified this user before (at least for
* the history of verifications observed by this device).
*/
wasCrossSigningVerified() {
return this.crossSigningVerifiedBefore;
}
/**
* @returns true if this user's key is trusted on first use
*
* @deprecated No longer supported, with the Rust crypto stack.
*/
isTofu() {
return false;
}
}
export class DeviceVerificationStatus {
constructor(opts) {
/**
* True if this device has been signed by its owner (and that signature verified).
*
* This doesn't necessarily mean that we have verified the device, since we may not have verified the
* owner's cross-signing key.
*/
_defineProperty(this, "signedByOwner", void 0);
/**
* True if this device has been verified via cross signing.
*
* This does *not* take into account `trustCrossSignedDevices`.
*/
_defineProperty(this, "crossSigningVerified", void 0);
/**
* TODO: tofu magic wtf does this do?
*/
_defineProperty(this, "tofu", void 0);
/**
* True if the device has been marked as locally verified.
*/
_defineProperty(this, "localVerified", void 0);
/**
* True if the client has been configured to trust cross-signed devices via {@link CryptoApi#setTrustCrossSignedDevices}.
*/
_defineProperty(this, "trustCrossSignedDevices", void 0);
this.signedByOwner = opts.signedByOwner ?? false;
this.crossSigningVerified = opts.crossSigningVerified ?? false;
this.tofu = opts.tofu ?? false;
this.localVerified = opts.localVerified ?? false;
this.trustCrossSignedDevices = opts.trustCrossSignedDevices ?? false;
}
/**
* Check if we should consider this device "verified".
*
* A device is "verified" if either:
* * it has been manually marked as such via {@link CryptoApi.setDeviceVerified}.
* * it has been cross-signed with a verified signing key, **and** the client has been configured to trust
* cross-signed devices via {@link CryptoApi.setTrustCrossSignedDevices}.
*
* @returns true if this device is verified via any means.
*/
isVerified() {
return this.localVerified || this.trustCrossSignedDevices && this.crossSigningVerified;
}
}
/**
* Enum representing the different stages of importing room keys.
*
* This is the type of the `stage` property of {@link ImportRoomKeyProgressData}.
*/
export let ImportRoomKeyStage = /*#__PURE__*/function (ImportRoomKeyStage) {
/**
* The stage where room keys are being fetched.
*
* @see {@link ImportRoomKeyFetchProgress}.
*/
ImportRoomKeyStage["Fetch"] = "fetch";
/**
* The stage where room keys are being loaded.
*
* @see {@link ImportRoomKeyLoadProgress}.
*/
ImportRoomKeyStage["LoadKeys"] = "load_keys";
return ImportRoomKeyStage;
}({});
/**
* Type representing the progress during the 'fetch' stage of the room key import process.
*
* @see {@link ImportRoomKeyProgressData}.
*/
/**
* Type representing the progress during the 'load_keys' stage of the room key import process.
*
* @see {@link ImportRoomKeyProgressData}.
*/
/**
* Room key import progress report.
* Used when calling {@link CryptoApi#importRoomKeys},
* {@link CryptoApi#importRoomKeysAsJson} or {@link CryptoApi#restoreKeyBackup} as the parameter of
* the progressCallback. Used to display feedback.
*/
/**
* Options object for {@link CryptoApi#importRoomKeys} and
* {@link CryptoApi#importRoomKeysAsJson}.
*/
/**
* The result of a call to {@link CryptoApi.getCrossSigningStatus}.
*/
/**
* Crypto callbacks provided by the application
*/
/**
* The result of a call to {@link CryptoApi.getSecretStorageStatus}.
*/
/**
* Parameter of {@link CryptoApi#bootstrapSecretStorage}
*/
/** Types of cross-signing key */
export let CrossSigningKey = /*#__PURE__*/function (CrossSigningKey) {
CrossSigningKey["Master"] = "master_key";
CrossSigningKey["SelfSigning"] = "self_signing_key";
CrossSigningKey["UserSigning"] = "user_signing_key";
return CrossSigningKey;
}({});
/** All of a user's cross-signing keys.
* @see https://spec.matrix.org/v1.7/client-server-api/#post_matrixclientv3keysdevice_signingupload
*/
/**
* Information on one of the cross-signing keys.
* @see https://spec.matrix.org/v1.7/client-server-api/#post_matrixclientv3keysdevice_signingupload
*/
/**
* Recovery key created by {@link CryptoApi#createRecoveryKeyFromPassphrase} or {@link CreateSecretStorageOpts#createSecretStorageKey}.
*/
/**
* Result type of {@link CryptoApi#getEncryptionInfoForEvent}.
*/
/**
* Types of shield to be shown for {@link EventEncryptionInfo#shieldColour}.
*/
export let EventShieldColour = /*#__PURE__*/function (EventShieldColour) {
EventShieldColour[EventShieldColour["NONE"] = 0] = "NONE";
EventShieldColour[EventShieldColour["GREY"] = 1] = "GREY";
EventShieldColour[EventShieldColour["RED"] = 2] = "RED";
return EventShieldColour;
}({});
/**
* Reason codes for {@link EventEncryptionInfo#shieldReason}.
*/
export let EventShieldReason = /*#__PURE__*/function (EventShieldReason) {
/** An unknown reason from the crypto library (if you see this, it is a bug in matrix-js-sdk). */
EventShieldReason[EventShieldReason["UNKNOWN"] = 0] = "UNKNOWN";
/** "Encrypted by an unverified user." */
EventShieldReason[EventShieldReason["UNVERIFIED_IDENTITY"] = 1] = "UNVERIFIED_IDENTITY";
/** "Encrypted by a device not verified by its owner." */
EventShieldReason[EventShieldReason["UNSIGNED_DEVICE"] = 2] = "UNSIGNED_DEVICE";
/** "Encrypted by an unknown or deleted device." */
EventShieldReason[EventShieldReason["UNKNOWN_DEVICE"] = 3] = "UNKNOWN_DEVICE";
/**
* "The authenticity of this encrypted message can't be guaranteed on this device."
*
* ie: the key has been forwarded, or retrieved from an insecure backup.
*/
EventShieldReason[EventShieldReason["AUTHENTICITY_NOT_GUARANTEED"] = 4] = "AUTHENTICITY_NOT_GUARANTEED";
/**
* The (deprecated) sender_key field in the event does not match the Ed25519 key of the device that sent us the
* decryption keys.
*
* @deprecated The sender_key field is not checked by matrix-sdk-crypto, and this value is therefore unused since
* the migration to matrix-sdk-crypto in v37.0.0.
*/
EventShieldReason[EventShieldReason["MISMATCHED_SENDER_KEY"] = 5] = "MISMATCHED_SENDER_KEY";
/**
* The event was sent unencrypted in an encrypted room.
*
* @deprecated This has never been used. The fact it is here was due to a misunderstanding of the behaviour of
* `matrix-sdk-crypto`.
*/
EventShieldReason[EventShieldReason["SENT_IN_CLEAR"] = 6] = "SENT_IN_CLEAR";
/**
* The sender was previously verified but changed their identity.
*/
EventShieldReason[EventShieldReason["VERIFICATION_VIOLATION"] = 7] = "VERIFICATION_VIOLATION";
/**
* The `sender` field on the event does not match the owner of the device
* that established the Megolm session.
*/
EventShieldReason[EventShieldReason["MISMATCHED_SENDER"] = 8] = "MISMATCHED_SENDER";
return EventShieldReason;
}({});
/** The result of a call to {@link CryptoApi.getOwnDeviceKeys} */
/**
* Information about the encryption of a successfully decrypted to-device message.
*/
/**
* An error thrown by loadSessionBackupPrivateKeyFromSecretStorage indicating
* that the decryption key found in secret storage does not match the public key
* of the latest backup.
*/
export class DecryptionKeyDoesNotMatchError extends Error {
constructor(message) {
super(message);
this.name = "DecryptionKeyDoesNotMatchError";
}
}
export * from "./verification.js";
export * from "./recovery-key.js";
export * from "./key-passphrase.js";
export * from "./CryptoEvent.js";
//# sourceMappingURL=index.js.map

File diff suppressed because one or more lines are too long

View File

@@ -1,11 +0,0 @@
/**
* Derive a recovery key from a passphrase and salt using PBKDF2.
* @see https://spec.matrix.org/v1.11/client-server-api/#deriving-keys-from-passphrases
*
* @param passphrase - The passphrase to derive the key from
* @param salt - The salt to use in the derivation
* @param iterations - The number of iterations to use in the derivation
* @param numBits - The number of bits to derive
*/
export declare function deriveRecoveryKeyFromPassphrase(passphrase: string, salt: string, iterations: number, numBits?: number): Promise<Uint8Array<ArrayBuffer>>;
//# sourceMappingURL=key-passphrase.d.ts.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"key-passphrase.d.ts","sourceRoot":"","sources":["../../src/crypto-api/key-passphrase.ts"],"names":[],"mappings":"AAkBA;;;;;;;;GAQG;AACH,wBAAsB,+BAA+B,CACjD,UAAU,EAAE,MAAM,EAClB,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,OAAO,SAAmB,GAC3B,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CAyBlC"}

View File

@@ -1,43 +0,0 @@
/*
* Copyright 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
const DEFAULT_BIT_SIZE = 256;
/**
* Derive a recovery key from a passphrase and salt using PBKDF2.
* @see https://spec.matrix.org/v1.11/client-server-api/#deriving-keys-from-passphrases
*
* @param passphrase - The passphrase to derive the key from
* @param salt - The salt to use in the derivation
* @param iterations - The number of iterations to use in the derivation
* @param numBits - The number of bits to derive
*/
export async function deriveRecoveryKeyFromPassphrase(passphrase, salt, iterations, numBits = DEFAULT_BIT_SIZE) {
if (!globalThis.crypto.subtle || !TextEncoder) {
throw new Error("Password-based backup is not available on this platform");
}
const key = await globalThis.crypto.subtle.importKey("raw", new TextEncoder().encode(passphrase), {
name: "PBKDF2"
}, false, ["deriveBits"]);
const keybits = await globalThis.crypto.subtle.deriveBits({
name: "PBKDF2",
salt: new TextEncoder().encode(salt),
iterations: iterations,
hash: "SHA-512"
}, key, numBits);
return new Uint8Array(keybits);
}
//# sourceMappingURL=key-passphrase.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"key-passphrase.js","names":[],"sources":["../../src/crypto-api/key-passphrase.ts"],"sourcesContent":["/*\n * Copyright 2024 The Matrix.org Foundation C.I.C.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nconst DEFAULT_BIT_SIZE = 256;\n\n/**\n * Derive a recovery key from a passphrase and salt using PBKDF2.\n * @see https://spec.matrix.org/v1.11/client-server-api/#deriving-keys-from-passphrases\n *\n * @param passphrase - The passphrase to derive the key from\n * @param salt - The salt to use in the derivation\n * @param iterations - The number of iterations to use in the derivation\n * @param numBits - The number of bits to derive\n */\nexport async function deriveRecoveryKeyFromPassphrase(\n passphrase: string,\n salt: string,\n iterations: number,\n numBits = DEFAULT_BIT_SIZE,\n): Promise<Uint8Array<ArrayBuffer>> {\n if (!globalThis.crypto.subtle || !TextEncoder) {\n throw new Error(\"Password-based backup is not available on this platform\");\n }\n\n const key = await globalThis.crypto.subtle.importKey(\n \"raw\",\n new TextEncoder().encode(passphrase),\n { name: \"PBKDF2\" },\n false,\n [\"deriveBits\"],\n );\n\n const keybits = await globalThis.crypto.subtle.deriveBits(\n {\n name: \"PBKDF2\",\n salt: new TextEncoder().encode(salt),\n iterations: iterations,\n hash: \"SHA-512\",\n },\n key,\n numBits,\n );\n\n return new Uint8Array(keybits);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,MAAM,gBAAgB,GAAG,GAAG;;AAE5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,eAAe,+BAA+B,CACjD,UAAkB,EAClB,IAAY,EACZ,UAAkB,EAClB,OAAO,GAAG,gBAAgB,EACM;EAChC,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE;IAC3C,MAAM,IAAI,KAAK,CAAC,yDAAyD,CAAC;EAC9E;EAEA,MAAM,GAAG,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,SAAS,CAChD,KAAK,EACL,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,UAAU,CAAC,EACpC;IAAE,IAAI,EAAE;EAAS,CAAC,EAClB,KAAK,EACL,CAAC,YAAY,CACjB,CAAC;EAED,MAAM,OAAO,GAAG,MAAM,UAAU,CAAC,MAAM,CAAC,MAAM,CAAC,UAAU,CACrD;IACI,IAAI,EAAE,QAAQ;IACd,IAAI,EAAE,IAAI,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC;IACpC,UAAU,EAAE,UAAU;IACtB,IAAI,EAAE;EACV,CAAC,EACD,GAAG,EACH,OACJ,CAAC;EAED,OAAO,IAAI,UAAU,CAAC,OAAO,CAAC;AAClC","ignoreList":[]}

View File

@@ -1,6 +1,4 @@
import { type ISigned } from "../@types/signed.ts";
import { type AESEncryptedSecretStoragePayload } from "../@types/AESEncryptedSecretStoragePayload.ts";
import { type ImportRoomKeyProgressData } from "./index.ts";
import { ISigned } from "../@types/signed";
export interface Curve25519AuthData {
public_key: string;
private_key_salt?: string;
@@ -14,81 +12,13 @@ export interface Aes256AuthData {
private_key_iterations?: number;
}
/**
* Information about a new server-side key backup.
*
* The type of the request body for [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.19/client-server-api/#post_matrixclientv3room_keysversion).
* Extra info of a recovery key
*/
export interface NewKeyBackupInfo {
export interface KeyBackupInfo {
algorithm: string;
auth_data: ISigned & (Curve25519AuthData | Aes256AuthData);
}
/**
* Information about an existing server-side key backup.
*
* Returned by [`GET /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3room_keysversion).
*/
export interface KeyBackupInfo extends NewKeyBackupInfo {
count: number;
etag: string;
version: string;
}
/**
* Information on whether a given server-side backup is trusted.
*/
export interface BackupTrustInfo {
/**
* Is this backup trusted?
*
* True if, and only if, there is a valid signature on the backup from a trusted device.
*/
readonly trusted: boolean;
/**
* True if this backup matches the stored decryption key.
*/
readonly matchesDecryptionKey: boolean;
}
/**
* The result of {@link CryptoApi.checkKeyBackupAndEnable}.
*/
export interface KeyBackupCheck {
backupInfo: KeyBackupInfo;
trustInfo: BackupTrustInfo;
}
export interface Curve25519SessionData {
ciphertext: string;
ephemeral: string;
mac: string;
}
export interface KeyBackupSession<T = Curve25519SessionData | AESEncryptedSecretStoragePayload> {
first_message_index: number;
forwarded_count: number;
is_verified: boolean;
session_data: T;
}
export interface KeyBackupRoomSessions {
[sessionId: string]: KeyBackupSession;
}
/**
* Extra parameters for {@link CryptoApi.restoreKeyBackup} and {@link CryptoApi.restoreKeyBackupWithPassphrase}.
*/
export interface KeyBackupRestoreOpts {
/**
* A callback which, if defined, will be called periodically to report ongoing progress of the backup restore process.
* @param progress
*/
progressCallback?: (progress: ImportRoomKeyProgressData) => void;
}
/**
* The result of {@link CryptoApi.restoreKeyBackup}.
*/
export interface KeyBackupRestoreResult {
/**
* The total number of keys that were found in the backup.
*/
total: number;
/**
* The number of keys that were imported.
*/
imported: number;
count?: number;
etag?: string;
version?: string;
}
//# sourceMappingURL=keybackup.d.ts.map

View File

@@ -1 +1 @@
{"version":3,"file":"keybackup.d.ts","sourceRoot":"","sources":["../../src/crypto-api/keybackup.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,OAAO,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,KAAK,gCAAgC,EAAE,MAAM,+CAA+C,CAAC;AACtG,OAAO,EAAE,KAAK,yBAAyB,EAAE,MAAM,YAAY,CAAC;AAE5D,MAAM,WAAW,kBAAkB;IAC/B,UAAU,EAAE,MAAM,CAAC;IACnB,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;IAChC,gBAAgB,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC7B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,GAAG,CAAC,kBAAkB,GAAG,cAAc,CAAC,CAAC;CAC9D;AAED;;;;GAIG;AACH,MAAM,WAAW,aAAc,SAAQ,gBAAgB;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,EAAE,MAAM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,CAAC;CAC7B;AAED,MAAM,WAAW,cAAc;IAC3B,EAAE,EAAE,MAAM,CAAC;IACX,GAAG,EAAE,MAAM,CAAC;IACZ,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,sBAAsB,CAAC,EAAE,MAAM,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,aAAa;IAC1B,SAAS,EAAE,MAAM,CAAC;IAClB,SAAS,EAAE,OAAO,GAAG,CAAC,kBAAkB,GAAG,cAAc,CAAC,CAAC;IAC3D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,OAAO,CAAC,EAAE,MAAM,CAAC;CACpB"}

View File

@@ -1,3 +1,6 @@
export {};
export {};
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
//# sourceMappingURL=keybackup.js.map

View File

@@ -1 +1 @@
{"version":3,"file":"keybackup.js","names":[],"sources":["../../src/crypto-api/keybackup.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { type ISigned } from \"../@types/signed.ts\";\nimport { type AESEncryptedSecretStoragePayload } from \"../@types/AESEncryptedSecretStoragePayload.ts\";\nimport { type ImportRoomKeyProgressData } from \"./index.ts\";\n\nexport interface Curve25519AuthData {\n public_key: string;\n private_key_salt?: string;\n private_key_iterations?: number;\n private_key_bits?: number;\n}\n\nexport interface Aes256AuthData {\n iv: string;\n mac: string;\n private_key_salt?: string;\n private_key_iterations?: number;\n}\n\n/**\n * Information about a new server-side key backup.\n *\n * The type of the request body for [`POST /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.19/client-server-api/#post_matrixclientv3room_keysversion).\n */\nexport interface NewKeyBackupInfo {\n algorithm: string;\n auth_data: ISigned & (Curve25519AuthData | Aes256AuthData);\n}\n\n/**\n * Information about an existing server-side key backup.\n *\n * Returned by [`GET /_matrix/client/v3/room_keys/version`](https://spec.matrix.org/v1.7/client-server-api/#get_matrixclientv3room_keysversion).\n */\nexport interface KeyBackupInfo extends NewKeyBackupInfo {\n count: number;\n etag: string;\n version: string; // number contained within\n}\n\n/**\n * Information on whether a given server-side backup is trusted.\n */\nexport interface BackupTrustInfo {\n /**\n * Is this backup trusted?\n *\n * True if, and only if, there is a valid signature on the backup from a trusted device.\n */\n readonly trusted: boolean;\n\n /**\n * True if this backup matches the stored decryption key.\n */\n readonly matchesDecryptionKey: boolean;\n}\n\n/**\n * The result of {@link CryptoApi.checkKeyBackupAndEnable}.\n */\nexport interface KeyBackupCheck {\n backupInfo: KeyBackupInfo;\n trustInfo: BackupTrustInfo;\n}\n\nexport interface Curve25519SessionData {\n ciphertext: string;\n ephemeral: string;\n mac: string;\n}\n\nexport interface KeyBackupSession<T = Curve25519SessionData | AESEncryptedSecretStoragePayload> {\n first_message_index: number;\n forwarded_count: number;\n is_verified: boolean;\n session_data: T;\n}\n\nexport interface KeyBackupRoomSessions {\n [sessionId: string]: KeyBackupSession;\n}\n\n/**\n * Extra parameters for {@link CryptoApi.restoreKeyBackup} and {@link CryptoApi.restoreKeyBackupWithPassphrase}.\n */\nexport interface KeyBackupRestoreOpts {\n /**\n * A callback which, if defined, will be called periodically to report ongoing progress of the backup restore process.\n * @param progress\n */\n progressCallback?: (progress: ImportRoomKeyProgressData) => void;\n}\n\n/**\n * The result of {@link CryptoApi.restoreKeyBackup}.\n */\nexport interface KeyBackupRestoreResult {\n /**\n * The total number of keys that were found in the backup.\n */\n total: number;\n /**\n * The number of keys that were imported.\n */\n imported: number;\n}\n"],"mappings":"","ignoreList":[]}
{"version":3,"file":"keybackup.js","names":[],"sources":["../../src/crypto-api/keybackup.ts"],"sourcesContent":["/*\nCopyright 2023 The Matrix.org Foundation C.I.C.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at\n\n http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n*/\n\nimport { ISigned } from \"../@types/signed\";\n\nexport interface Curve25519AuthData {\n public_key: string;\n private_key_salt?: string;\n private_key_iterations?: number;\n private_key_bits?: number;\n}\n\nexport interface Aes256AuthData {\n iv: string;\n mac: string;\n private_key_salt?: string;\n private_key_iterations?: number;\n}\n\n/**\n * Extra info of a recovery key\n */\nexport interface KeyBackupInfo {\n algorithm: string;\n auth_data: ISigned & (Curve25519AuthData | Aes256AuthData);\n count?: number;\n etag?: string;\n version?: string; // number contained within\n}\n"],"mappings":""}

View File

@@ -1,11 +0,0 @@
/**
* Encode a recovery key using the Matrix {@link https://spec.matrix.org/v1.11/appendices/#cryptographic-key-representation | Cryptographic key representation}
* @param key
*/
export declare function encodeRecoveryKey(key: ArrayLike<number>): string | undefined;
/**
* Decode a recovery key encoded with the Matrix {@link https://spec.matrix.org/v1.11/appendices/#cryptographic-key-representation | Cryptographic key representation} encoding.
* @param recoveryKey
*/
export declare function decodeRecoveryKey(recoveryKey: string): Uint8Array<ArrayBuffer>;
//# sourceMappingURL=recovery-key.d.ts.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"recovery-key.d.ts","sourceRoot":"","sources":["../../src/crypto-api/recovery-key.ts"],"names":[],"mappings":"AAuBA;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,SAAS,CAAC,MAAM,CAAC,GAAG,MAAM,GAAG,SAAS,CAa5E;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG,UAAU,CAAC,WAAW,CAAC,CAsB9E"}

View File

@@ -1,64 +0,0 @@
/*
* Copyright 2024 The Matrix.org Foundation C.I.C.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import bs58 from "bs58";
// picked arbitrarily but to try & avoid clashing with any bitcoin ones
// (which are also base58 encoded, but bitcoin's involve a lot more hashing)
const OLM_RECOVERY_KEY_PREFIX = [0x8b, 0x01];
const KEY_SIZE = 32;
/**
* Encode a recovery key using the Matrix {@link https://spec.matrix.org/v1.11/appendices/#cryptographic-key-representation | Cryptographic key representation}
* @param key
*/
export function encodeRecoveryKey(key) {
const buf = new Uint8Array(OLM_RECOVERY_KEY_PREFIX.length + key.length + 1);
buf.set(OLM_RECOVERY_KEY_PREFIX, 0);
buf.set(key, OLM_RECOVERY_KEY_PREFIX.length);
let parity = 0;
for (let i = 0; i < buf.length - 1; ++i) {
parity ^= buf[i];
}
buf[buf.length - 1] = parity;
const base58key = bs58.encode(buf);
return base58key.match(/.{1,4}/g)?.join(" ");
}
/**
* Decode a recovery key encoded with the Matrix {@link https://spec.matrix.org/v1.11/appendices/#cryptographic-key-representation | Cryptographic key representation} encoding.
* @param recoveryKey
*/
export function decodeRecoveryKey(recoveryKey) {
const result = bs58.decode(recoveryKey.replace(/ /g, ""));
let parity = 0;
for (const b of result) {
parity ^= b;
}
if (parity !== 0) {
throw new Error("Incorrect parity");
}
for (let i = 0; i < OLM_RECOVERY_KEY_PREFIX.length; ++i) {
if (result[i] !== OLM_RECOVERY_KEY_PREFIX[i]) {
throw new Error("Incorrect prefix");
}
}
if (result.length !== OLM_RECOVERY_KEY_PREFIX.length + KEY_SIZE + 1) {
throw new Error("Incorrect length");
}
return Uint8Array.from(result.slice(OLM_RECOVERY_KEY_PREFIX.length, OLM_RECOVERY_KEY_PREFIX.length + KEY_SIZE));
}
//# sourceMappingURL=recovery-key.js.map

View File

@@ -1 +0,0 @@
{"version":3,"file":"recovery-key.js","names":[],"sources":["../../src/crypto-api/recovery-key.ts"],"sourcesContent":["/*\n * Copyright 2024 The Matrix.org Foundation C.I.C.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport bs58 from \"bs58\";\n\n// picked arbitrarily but to try & avoid clashing with any bitcoin ones\n// (which are also base58 encoded, but bitcoin's involve a lot more hashing)\nconst OLM_RECOVERY_KEY_PREFIX = [0x8b, 0x01];\nconst KEY_SIZE = 32;\n\n/**\n * Encode a recovery key using the Matrix {@link https://spec.matrix.org/v1.11/appendices/#cryptographic-key-representation | Cryptographic key representation}\n * @param key\n */\nexport function encodeRecoveryKey(key: ArrayLike<number>): string | undefined {\n const buf = new Uint8Array(OLM_RECOVERY_KEY_PREFIX.length + key.length + 1);\n buf.set(OLM_RECOVERY_KEY_PREFIX, 0);\n buf.set(key, OLM_RECOVERY_KEY_PREFIX.length);\n\n let parity = 0;\n for (let i = 0; i < buf.length - 1; ++i) {\n parity ^= buf[i];\n }\n buf[buf.length - 1] = parity;\n const base58key = bs58.encode(buf);\n\n return base58key.match(/.{1,4}/g)?.join(\" \");\n}\n\n/**\n * Decode a recovery key encoded with the Matrix {@link https://spec.matrix.org/v1.11/appendices/#cryptographic-key-representation | Cryptographic key representation} encoding.\n * @param recoveryKey\n */\nexport function decodeRecoveryKey(recoveryKey: string): Uint8Array<ArrayBuffer> {\n const result = bs58.decode(recoveryKey.replace(/ /g, \"\"));\n\n let parity = 0;\n for (const b of result) {\n parity ^= b;\n }\n if (parity !== 0) {\n throw new Error(\"Incorrect parity\");\n }\n\n for (let i = 0; i < OLM_RECOVERY_KEY_PREFIX.length; ++i) {\n if (result[i] !== OLM_RECOVERY_KEY_PREFIX[i]) {\n throw new Error(\"Incorrect prefix\");\n }\n }\n\n if (result.length !== OLM_RECOVERY_KEY_PREFIX.length + KEY_SIZE + 1) {\n throw new Error(\"Incorrect length\");\n }\n\n return Uint8Array.from(result.slice(OLM_RECOVERY_KEY_PREFIX.length, OLM_RECOVERY_KEY_PREFIX.length + KEY_SIZE));\n}\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA,OAAO,IAAI,MAAM,MAAM;;AAEvB;AACA;AACA,MAAM,uBAAuB,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;AAC5C,MAAM,QAAQ,GAAG,EAAE;;AAEnB;AACA;AACA;AACA;AACA,OAAO,SAAS,iBAAiB,CAAC,GAAsB,EAAsB;EAC1E,MAAM,GAAG,GAAG,IAAI,UAAU,CAAC,uBAAuB,CAAC,MAAM,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC;EAC3E,GAAG,CAAC,GAAG,CAAC,uBAAuB,EAAE,CAAC,CAAC;EACnC,GAAG,CAAC,GAAG,CAAC,GAAG,EAAE,uBAAuB,CAAC,MAAM,CAAC;EAE5C,IAAI,MAAM,GAAG,CAAC;EACd,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,GAAG,CAAC,EAAE,EAAE,CAAC,EAAE;IACrC,MAAM,IAAI,GAAG,CAAC,CAAC,CAAC;EACpB;EACA,GAAG,CAAC,GAAG,CAAC,MAAM,GAAG,CAAC,CAAC,GAAG,MAAM;EAC5B,MAAM,SAAS,GAAG,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;EAElC,OAAO,SAAS,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC;AAChD;;AAEA;AACA;AACA;AACA;AACA,OAAO,SAAS,iBAAiB,CAAC,WAAmB,EAA2B;EAC5E,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;EAEzD,IAAI,MAAM,GAAG,CAAC;EACd,KAAK,MAAM,CAAC,IAAI,MAAM,EAAE;IACpB,MAAM,IAAI,CAAC;EACf;EACA,IAAI,MAAM,KAAK,CAAC,EAAE;IACd,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;EACvC;EAEA,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,uBAAuB,CAAC,MAAM,EAAE,EAAE,CAAC,EAAE;IACrD,IAAI,MAAM,CAAC,CAAC,CAAC,KAAK,uBAAuB,CAAC,CAAC,CAAC,EAAE;MAC1C,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;IACvC;EACJ;EAEA,IAAI,MAAM,CAAC,MAAM,KAAK,uBAAuB,CAAC,MAAM,GAAG,QAAQ,GAAG,CAAC,EAAE;IACjE,MAAM,IAAI,KAAK,CAAC,kBAAkB,CAAC;EACvC;EAEA,OAAO,UAAU,CAAC,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,uBAAuB,CAAC,MAAM,EAAE,uBAAuB,CAAC,MAAM,GAAG,QAAQ,CAAC,CAAC;AACnH","ignoreList":[]}

View File

@@ -1,5 +1,6 @@
import { type MatrixEvent } from "../models/event.ts";
import { type TypedEventEmitter } from "../models/typed-event-emitter.ts";
/// <reference types="node" />
import { MatrixEvent } from "../models/event";
import { TypedEventEmitter } from "../models/typed-event-emitter";
/**
* An incoming, or outgoing, request to verify a user or a device via cross-signing.
*/
@@ -83,18 +84,31 @@ export interface VerificationRequest extends TypedEventEmitter<VerificationReque
reason?: string;
code?: string;
}): Promise<void>;
/**
* Create a {@link Verifier} to do this verification via a particular method.
*
* If a verifier has already been created for this request, returns that verifier.
*
* This does *not* send the `m.key.verification.start` event - to do so, call {@link Crypto.Verifier#verify} on the
* returned verifier.
*
* If no previous events have been sent, pass in `targetDevice` to set who to direct this request to.
*
* @param method - the name of the verification method to use.
* @param targetDevice - details of where to send the request to.
*
* @returns The verifier which will do the actual verification.
*
* @deprecated Use {@link VerificationRequest#startVerification} instead.
*/
beginKeyVerification(method: string, targetDevice?: {
userId?: string;
deviceId?: string;
}): Verifier;
/**
* Send an `m.key.verification.start` event to start verification via a particular method.
*
* This is used for SAS (emoji) verification: `method` should be set to `m.sas.v1`. It does not start
* QR-code verification, and passing a QR-code method (such as `m.reciprocate.v1`, `m.qr_code.scan.v1`,
* or `m.qr_code.show.v1`) will be rejected with an "Unsupported verification method" error.
*
* For QR-code verification, use {@link VerificationRequest#generateQRCode} to display a QR code to the
* other device, or {@link VerificationRequest#scanQRCode} to consume a QR code scanned from it. This is
* only possible once the `phase` is {@link VerificationPhase.Ready}; when it is, a client can typically
* offer the user any of three options: show a QR code, scan the other party's QR code, or fall back to
* emoji (SAS) verification via this method.
* This is normally used when starting a verification via emojis (ie, `method` is set to `m.sas.v1`).
*
* @param method - the name of the verification method to use.
*
@@ -104,37 +118,35 @@ export interface VerificationRequest extends TypedEventEmitter<VerificationReque
/**
* Start a QR code verification by providing a scanned QR code for this verification flow.
*
* Call this once the user has scanned the QR code displayed by the other device (for example, the bytes
* produced by that device's {@link VerificationRequest#generateQRCode}). Validates the QR code, and if it
* is ok, sends an `m.key.verification.start` event with `method` set to `m.reciprocate.v1`, to tell the
* other side the scan was successful.
* Validates the QR code, and if it is ok, sends an `m.key.verification.start` event with `method` set to
* `m.reciprocate.v1`, to tell the other side the scan was successful.
*
* See also {@link VerificationRequest#startVerification} which can be used to start other verification methods.
*
* @param qrCodeData - the decoded QR code.
* @returns A verifier; call `.verify()` on it to wait for the other side to complete the verification flow.
*/
scanQRCode(qrCodeData: Uint8ClampedArray): Promise<Verifier>;
scanQRCode(qrCodeData: Uint8Array): Promise<Verifier>;
/**
* The verifier which is doing the actual verification, once the method has been established.
* Only defined when the `phase` is Started.
*/
get verifier(): Verifier | undefined;
/**
* Get the data for a QR code allowing the other device to verify this one, if it supports it.
*
* Only set after a .ready if the other party can scan a QR code, otherwise undefined.
*
* @deprecated Not supported in Rust Crypto. Use {@link VerificationRequest#generateQRCode} instead.
*/
getQRCodeBytes(): Buffer | undefined;
/**
* Generate the data for a QR code allowing the other device to verify this one, if it supports it.
*
* Returns the QR code data only when all of the following hold; otherwise it returns `undefined`:
* - `phase` is {@link VerificationPhase.Ready};
* - the other party advertises support for scanning a QR code (ie, `otherPartySupportsMethod("m.qr_code.scan.v1")`
* is true); and
* - this device has its cross-signing keys available locally. A frequent cause of an unexpected `undefined`
* is that cross-signing has not been set up or the keys have not yet been fetched, so the QR code cannot be
* constructed even though the phase and method checks pass.
*
* On success, display the returned bytes as a QR code for the other device to scan; if the other side scans it
* and confirms, there is nothing further to do on this side.
* Only returns data once `phase` is {@link VerificationPhase.Ready} and the other party can scan a QR code;
* otherwise returns `undefined`.
*/
generateQRCode(): Promise<Uint8ClampedArray | undefined>;
generateQRCode(): Promise<Buffer | undefined>;
/**
* If this request has been cancelled, the cancellation code (e.g `m.user`) which is responsible for cancelling
* this verification.
@@ -172,23 +184,11 @@ export declare enum VerificationPhase {
Requested = 2,
/** An `m.key.verification.ready` event has been sent or received, indicating the verification request is accepted. */
Ready = 3,
/**
* The verification is in flight.
*
* This means that an `m.key.verification.start` event has been sent or received, choosing a verification method;
* however the verification has not yet completed or been cancelled.
*/
/** An `m.key.verification.start` event has been sent or received, choosing a verification method */
Started = 4,
/**
* An `m.key.verification.cancel` event has been sent or received at any time before the `done` event, cancelling
* the verification request
*/
/** An `m.key.verification.cancel` event has been sent or received at any time before the `done` event, cancelling the verification request */
Cancelled = 5,
/**
* The verification request is complete.
*
* Normally this means that `m.key.verification.done` events have been sent and received.
*/
/** An `m.key.verification.done` event has been **sent**, completing the verification request. */
Done = 6
}
/**
@@ -223,7 +223,7 @@ export interface Verifier extends TypedEventEmitter<VerifierEvent, VerifierEvent
* Cancel a verification.
*
* We will send an `m.key.verification.cancel` if the verification is still in flight. The verification promise
* will reject, and a {@link crypto-api.VerifierEvent.Cancel | VerifierEvent.Cancel} will be emitted.
* will reject, and a {@link Crypto.VerifierEvent#Cancel} will be emitted.
*
* @param e - the reason for the cancellation.
*/

View File

@@ -1 +1 @@
{"version":3,"file":"verification.d.ts","sourceRoot":"","sources":["../../src/crypto-api/verification.ts"],"names":[],"mappings":"AAgBA,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACtD,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,kCAAkC,CAAC;AAE1E;;GAEG;AACH,MAAM,WAAW,mBAAoB,SAAQ,iBAAiB,CAC1D,wBAAwB,EACxB,kCAAkC,CACrC;IACG;;;;OAIG;IACH,IAAI,aAAa,IAAI,MAAM,GAAG,SAAS,CAAC;IAExC;;;;OAIG;IACH,IAAI,MAAM,IAAI,MAAM,GAAG,SAAS,CAAC;IAEjC;;;;;OAKG;IACH,IAAI,aAAa,IAAI,OAAO,CAAC;IAE7B,qDAAqD;IACrD,IAAI,WAAW,IAAI,MAAM,CAAC;IAE1B,kGAAkG;IAClG,IAAI,aAAa,IAAI,MAAM,GAAG,SAAS,CAAC;IAExC,iFAAiF;IACjF,IAAI,kBAAkB,IAAI,OAAO,CAAC;IAElC,oCAAoC;IACpC,IAAI,KAAK,IAAI,iBAAiB,CAAC;IAE/B;;OAEG;IACH,IAAI,OAAO,IAAI,OAAO,CAAC;IAEvB;;;OAGG;IACH,IAAI,SAAS,IAAI,OAAO,CAAC;IAEzB;;;OAGG;IACH,IAAI,SAAS,IAAI,OAAO,CAAC;IAEzB;;;;OAIG;IACH,IAAI,OAAO,IAAI,MAAM,GAAG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AM,MAAM,uBAAuB,GAAG;IAClC,CAAC,aAAa,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,GAAG,WAAW,KAAK,IAAI,CAAC;IACzD,CAAC,aAAa,CAAC,OAAO,CAAC,EAAE,CAAC,GAAG,EAAE,gBAAgB,KAAK,IAAI,CAAC;IACzD,CAAC,aAAa,CAAC,iBAAiB,CAAC,EAAE,CAAC,EAAE,EAAE,mBAAmB,KAAK,IAAI,CAAC;CACxE,CAAC;AAEF;;;;;GAKG;AACH,MAAM,WAAW,mBAAmB;IAChC,2DAA2D;IAC3D,OAAO,IAAI,IAAI,CAAC;IAEhB,mCAAmC;IACnC,MAAM,IAAI,IAAI,CAAC;CAClB;AAED;;;;GAIG;AACH,MAAM,WAAW,gBAAgB;IAC7B,gDAAgD;IAChD,GAAG,EAAE,YAAY,CAAC;IAElB;;;OAGG;IACH,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;IAEzB;;;;OAIG;IACH,QAAQ,IAAI,IAAI,CAAC;IAEjB,mCAAmC;IACnC,MAAM,IAAI,IAAI,CAAC;CAClB;AAED,sEAAsE;AACtE,MAAM,WAAW,YAAY;IACzB;;;;OAIG;IACH,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IAEnC;;;;OAIG;IACH,KAAK,CAAC,EAAE,YAAY,EAAE,CAAC;CAC1B;AAED;;;GAGG;AACH,MAAM,MAAM,YAAY,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,CAAC;AAEzD;;;GAGG;AACH,wBAAgB,4BAA4B,CAAC,GAAG,EAAE,mBAAmB,GAAG,OAAO,CAE9E"}

View File

@@ -1,3 +1,10 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.VerifierEvent = exports.VerificationRequestEvent = exports.VerificationPhase = void 0;
exports.canAcceptVerificationRequest = canAcceptVerificationRequest;
/*
Copyright 2023 The Matrix.org Foundation C.I.C.
@@ -13,57 +20,30 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/**
* An incoming, or outgoing, request to verify a user or a device via cross-signing.
*/
/** Events emitted by {@link VerificationRequest}. */
export let VerificationRequestEvent = /*#__PURE__*/function (VerificationRequestEvent) {
/**
* Fires whenever the state of the request object has changed.
*
* There is no payload to the event.
*/
let VerificationRequestEvent = /*#__PURE__*/function (VerificationRequestEvent) {
VerificationRequestEvent["Change"] = "change";
return VerificationRequestEvent;
}({});
/**
* Listener type map for {@link VerificationRequestEvent}s.
*
* @internal
*/
exports.VerificationRequestEvent = VerificationRequestEvent;
/** The current phase of a verification request. */
export let VerificationPhase = /*#__PURE__*/function (VerificationPhase) {
/** Initial state: no event yet exchanged */
let VerificationPhase = /*#__PURE__*/function (VerificationPhase) {
VerificationPhase[VerificationPhase["Unsent"] = 1] = "Unsent";
/** An `m.key.verification.request` event has been sent or received */
VerificationPhase[VerificationPhase["Requested"] = 2] = "Requested";
/** An `m.key.verification.ready` event has been sent or received, indicating the verification request is accepted. */
VerificationPhase[VerificationPhase["Ready"] = 3] = "Ready";
/**
* The verification is in flight.
*
* This means that an `m.key.verification.start` event has been sent or received, choosing a verification method;
* however the verification has not yet completed or been cancelled.
*/
VerificationPhase[VerificationPhase["Started"] = 4] = "Started";
/**
* An `m.key.verification.cancel` event has been sent or received at any time before the `done` event, cancelling
* the verification request
*/
VerificationPhase[VerificationPhase["Cancelled"] = 5] = "Cancelled";
/**
* The verification request is complete.
*
* Normally this means that `m.key.verification.done` events have been sent and received.
*/
VerificationPhase[VerificationPhase["Done"] = 6] = "Done";
return VerificationPhase;
}({});
/**
* A `Verifier` is responsible for performing the verification using a particular method, such as via QR code or SAS
* (emojis).
@@ -73,58 +53,37 @@ export let VerificationPhase = /*#__PURE__*/function (VerificationPhase) {
*
* Once a verifier object is created, the verification can be started by calling the {@link Verifier#verify} method.
*/
exports.VerificationPhase = VerificationPhase;
/** Events emitted by {@link Verifier} */
export let VerifierEvent = /*#__PURE__*/function (VerifierEvent) {
/**
* The verification has been cancelled, by us or the other side.
*
* The payload is either an {@link Error}, or an (incoming or outgoing) {@link MatrixEvent}, depending on
* unspecified reasons.
*/
let VerifierEvent = /*#__PURE__*/function (VerifierEvent) {
VerifierEvent["Cancel"] = "cancel";
/**
* SAS data has been exchanged and should be displayed to the user.
*
* The payload is the {@link ShowSasCallbacks} object.
*/
VerifierEvent["ShowSas"] = "show_sas";
/**
* The user should confirm if the other side has scanned our QR code.
*
* The payload is the {@link ShowQrCodeCallbacks} object.
*/
VerifierEvent["ShowReciprocateQr"] = "show_reciprocate_qr";
return VerifierEvent;
}({});
/** Listener type map for {@link VerifierEvent}s. */
/**
* Callbacks for user actions to confirm that the other side has scanned our QR code.
*
* This is exposed as the payload of a `VerifierEvent.ShowReciprocateQr` event, or can be retrieved directly from the
* verifier as `reciprocateQREvent`.
*/
/**
* Callbacks for user actions while a SAS is displayed.
*
* This is exposed as the payload of a `VerifierEvent.ShowSas` event, or directly from the verifier as `sasEvent`.
*/
/** A generated SAS to be shown to the user, in alternative formats */
/**
* An emoji for the generated SAS. A tuple `[emoji, name]` where `emoji` is the emoji itself and `name` is the
* English name.
*/
exports.VerifierEvent = VerifierEvent;
/**
* True if the request is in a state where it can be accepted (ie, that we're in phases {@link VerificationPhase.Unsent}
* or {@link VerificationPhase.Requested}, and that we're not in the process of sending a `ready` or `cancel`).
*/
export function canAcceptVerificationRequest(req) {
function canAcceptVerificationRequest(req) {
return req.phase < VerificationPhase.Ready && !req.accepting && !req.declining;
}
//# sourceMappingURL=verification.js.map

File diff suppressed because one or more lines are too long