uploadCrossSigningKeys method
- AuthenticationData? auth,
- MatrixCrossSigningKey? masterKey,
- MatrixCrossSigningKey? selfSigningKey,
- MatrixCrossSigningKey? userSigningKey,
Publishes cross-signing keys for the user.
This API endpoint uses the User-Interactive Authentication API, except when used by an application service.
User-Interactive Authentication MUST be performed for regular clients, except in these cases:
- there is no existing master signing key uploaded to the homeserver, OR
- there is an existing master signing key and it exactly matches the master signing key provided in the request body. If there are any additional keys provided in the request (self-signing key, user-signing key) they MUST also match the existing keys stored on the server. In other words, the request contains no new keys.
This allows clients to freely upload one set of keys, but not modify/overwrite keys if they already exist. Allowing clients to upload the same set of keys more than once makes this endpoint idempotent in the case where the response is lost over the network, which would otherwise cause a UIA challenge upon retry.
NOTE:
When this endpoint requires User-Interactive Authentication,
it uses the m.oauth
authentication type if the access token was obtained
via the OAuth 2.0 API.
auth Additional authentication information for the
user-interactive authentication API.
masterKey Optional. The user's master signing key.
selfSigningKey Optional. The user's self-signing key. Must be signed by
the accompanying master signing key, or by the user's most recently
uploaded master signing key if no master signing key is included in the
request.
userSigningKey Optional. The user's user-signing key. Must be signed by
the accompanying master signing key, or by the user's most recently
uploaded master signing key if no master signing key is included in the
request.
Implementation
Future<void> uploadCrossSigningKeys({
AuthenticationData? auth,
MatrixCrossSigningKey? masterKey,
MatrixCrossSigningKey? selfSigningKey,
MatrixCrossSigningKey? userSigningKey,
}) async {
final requestUri = Uri(
path: '_matrix/client/v3/keys/device_signing/upload',
);
final request = Request('POST', baseUri!.resolveUri(requestUri));
request.headers['authorization'] = 'Bearer ${bearerToken!}';
request.headers['content-type'] = 'application/json';
request.bodyBytes = utf8.encode(
jsonEncode({
if (auth != null) 'auth': auth.toJson(),
if (masterKey != null) 'master_key': masterKey.toJson(),
if (selfSigningKey != null) 'self_signing_key': selfSigningKey.toJson(),
if (userSigningKey != null) 'user_signing_key': userSigningKey.toJson(),
}),
);
final response = await httpClient.send(request);
final responseBody = await response.stream.toBytes();
if (response.statusCode != 200) unexpectedResponse(response, responseBody);
final responseString = utf8.decode(responseBody);
final json = jsonDecode(responseString);
return ignore(json);
}