Interactive key verification lets two devices (or users) confirm each other’s cryptographic identity by comparing short authentication strings (SAS / emojis) or scanning a QR code. The flow is modelled by theDocumentation Index
Fetch the complete documentation index at: https://mintlify.com/matrix-org/matrix-js-sdk/llms.txt
Use this file to discover all available pages before exploring further.
VerificationRequest interface.
How to Start Verification
Obtain theCryptoApi instance first:
Verify another user via DM
Verify our own devices (self-verification)
Verify a specific device directly
Handle incoming requests
Listen forCryptoEvent.VerificationRequestReceived on the MatrixClient:
VerificationRequest Interface
AVerificationRequest represents one pending or in-progress verification flow and
extends TypedEventEmitter. Its state is exposed through read-only getters.
Properties
The current phase of the verification request. See
VerificationPhase below.A unique ID for this verification flow. Not assigned until the first message is
sent, so may be
undefined in early phases.For in-room (DM) verifications, the ID of the room used.
undefined for
to-device verifications.The user ID of the other party in this verification.
For to-device verifications, the ID of the other device.
undefined for in-room
verifications.true if the other party is one of the local user’s own devices.true if the local device initiated this verification request.true if the request is still in progress (phases Requested, Ready, or
Started).true if we have started sending an m.key.verification.ready but have not
yet received the remote echo.true if we have started sending an m.key.verification.cancel but have not
yet received the remote echo.Milliseconds remaining before the request times out automatically.
null means
no timeout applies.The verification methods supported by both parties. Only populated after the
request reaches the
Ready or Started phase.The method selected in the
m.key.verification.start event. null before the
Started phase.The active
Verifier object once the Started phase is reached.If the request was cancelled, the cancellation code (e.g.
m.user). Otherwise
null.The user ID that cancelled the request. Only defined in the
Cancelled phase.Methods
accept()
m.key.verification.ready event. Transitions the phase from Requested to
Ready.
cancel(params?)
m.key.verification.cancel to the other party.
The params argument is accepted for compatibility but is ignored by the Rust
crypto backend.
startVerification(method)
m.key.verification.start event for the given method (e.g. "m.sas.v1").
Returns a Verifier to drive the actual verification.
scanQRCode(qrCodeData)
m.key.verification.start with method: m.reciprocate.v1. Returns a Verifier;
call .verify() on it to wait for the other party.
generateQRCode()
Ready phase and the other party indicated support for scanning.
otherPartySupportsMethod(method)
true if the other party advertised support for the given method. Useful
for deciding which UI elements to show (e.g. whether to display a QR code).
VerificationPhase Enum
The state machine of aVerificationRequest:
| Value | Number | Description |
|---|---|---|
VerificationPhase.Unsent | 1 | No event has been exchanged yet. |
VerificationPhase.Requested | 2 | An m.key.verification.request event was sent or received. |
VerificationPhase.Ready | 3 | An m.key.verification.ready event was sent or received; request is accepted. |
VerificationPhase.Started | 4 | An m.key.verification.start event was sent or received; method is chosen. |
VerificationPhase.Cancelled | 5 | An m.key.verification.cancel event was sent or received. |
VerificationPhase.Done | 6 | Verification is complete (m.key.verification.done exchanged). |
Verifier Interface
AVerifier drives the actual cryptographic verification after the method is chosen.
Methods
verify()
cancel(e)
VerifierEvent.Cancel.
getShowSasCallbacks()
ShowSasCallbacks when an SAS comparison is ready to be shown to the
user. Returns null at all other times.
getReciprocateQrCodeCallbacks()
null at all other times.
VerifierEvent Enum
| Value | String | Description |
|---|---|---|
VerifierEvent.Cancel | "cancel" | Verification was cancelled. Payload: Error | MatrixEvent. |
VerifierEvent.ShowSas | "show_sas" | SAS data is ready for display. Payload: ShowSasCallbacks. |
VerifierEvent.ShowReciprocateQr | "show_reciprocate_qr" | User should confirm the other side scanned the QR code. Payload: ShowQrCodeCallbacks. |
VerificationRequestEvent Enum
| Value | String | Description |
|---|---|---|
VerificationRequestEvent.Change | "change" | The state of the VerificationRequest changed. No payload. |