refactor: remove uploadKeySignatures (use uploadCrossSigningSignatures)
This commit is contained in:
parent
cb71ca9b26
commit
d16c83f5db
|
|
@ -61,7 +61,6 @@ export 'src/model/room_creation_types.dart';
|
||||||
export 'src/model/room_summary.dart';
|
export 'src/model/room_summary.dart';
|
||||||
export 'src/model/stripped_state_event.dart';
|
export 'src/model/stripped_state_event.dart';
|
||||||
export 'src/model/sync_update.dart';
|
export 'src/model/sync_update.dart';
|
||||||
export 'src/model/upload_key_signatures_response.dart';
|
|
||||||
export 'src/utils/logs.dart';
|
export 'src/utils/logs.dart';
|
||||||
export 'src/utils/map_copy_extension.dart';
|
export 'src/utils/map_copy_extension.dart';
|
||||||
export 'src/utils/try_get_map_extension.dart';
|
export 'src/utils/try_get_map_extension.dart';
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,6 @@ import 'generated/api.dart';
|
||||||
import 'model/matrix_connection_exception.dart';
|
import 'model/matrix_connection_exception.dart';
|
||||||
import 'model/matrix_exception.dart';
|
import 'model/matrix_exception.dart';
|
||||||
import 'model/matrix_keys.dart';
|
import 'model/matrix_keys.dart';
|
||||||
import 'model/upload_key_signatures_response.dart';
|
|
||||||
|
|
||||||
enum RequestType { GET, POST, PUT, DELETE }
|
enum RequestType { GET, POST, PUT, DELETE }
|
||||||
|
|
||||||
|
|
@ -171,37 +170,6 @@ class MatrixApi extends Api {
|
||||||
return Map<String, int>.from(response['one_time_key_counts']);
|
return Map<String, int>.from(response['one_time_key_counts']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Uploads new signatures of keys
|
|
||||||
/// https://github.com/matrix-org/matrix-doc/pull/2536
|
|
||||||
Future<UploadKeySignaturesResponse> uploadKeySignatures(
|
|
||||||
List<MatrixSignableKey> keys) async {
|
|
||||||
final payload = <String, dynamic>{};
|
|
||||||
for (final key in keys) {
|
|
||||||
if (key.identifier == null ||
|
|
||||||
key.signatures == null ||
|
|
||||||
key.signatures!.isEmpty) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (!payload.containsKey(key.userId)) {
|
|
||||||
payload[key.userId] = <String, dynamic>{};
|
|
||||||
}
|
|
||||||
if (payload[key.userId].containsKey(key.identifier)) {
|
|
||||||
// we need to merge signature objects
|
|
||||||
payload[key.userId][key.identifier]['signatures']
|
|
||||||
.addAll(key.signatures);
|
|
||||||
} else {
|
|
||||||
// we can just add signatures
|
|
||||||
payload[key.userId][key.identifier] = key.toJson();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final response = await request(
|
|
||||||
RequestType.POST,
|
|
||||||
'/client/r0/keys/signatures/upload',
|
|
||||||
data: payload,
|
|
||||||
);
|
|
||||||
return UploadKeySignaturesResponse.fromJson(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// This endpoint allows the creation, modification and deletion of pushers
|
/// This endpoint allows the creation, modification and deletion of pushers
|
||||||
/// for this user ID. The behaviour of this endpoint varies depending on the
|
/// for this user ID. The behaviour of this endpoint varies depending on the
|
||||||
/// values in the JSON body.
|
/// values in the JSON body.
|
||||||
|
|
|
||||||
|
|
@ -1,59 +0,0 @@
|
||||||
/* MIT License
|
|
||||||
*
|
|
||||||
* Copyright (C) 2019, 2020, 2021 Famedly GmbH
|
|
||||||
*
|
|
||||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
* of this software and associated documentation files (the "Software"), to deal
|
|
||||||
* in the Software without restriction, including without limitation the rights
|
|
||||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
* copies of the Software, and to permit persons to whom the Software is
|
|
||||||
* furnished to do so, subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
* SOFTWARE.
|
|
||||||
*/
|
|
||||||
|
|
||||||
import 'matrix_exception.dart';
|
|
||||||
|
|
||||||
class UploadKeySignaturesResponse {
|
|
||||||
Map<String, Map<String, MatrixException>>? failures;
|
|
||||||
|
|
||||||
UploadKeySignaturesResponse.fromJson(Map<String, dynamic> json)
|
|
||||||
: failures = json['failures'] != null
|
|
||||||
? (json['failures'] as Map).map(
|
|
||||||
(k, v) => MapEntry(
|
|
||||||
k,
|
|
||||||
(v as Map).map((k, v) => MapEntry(
|
|
||||||
k,
|
|
||||||
MatrixException.fromJson(v),
|
|
||||||
)),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
: null;
|
|
||||||
|
|
||||||
Map<String, dynamic> toJson() {
|
|
||||||
final data = <String, dynamic>{};
|
|
||||||
if (failures != null) {
|
|
||||||
data['failures'] = failures!.map(
|
|
||||||
(k, v) => MapEntry(
|
|
||||||
k,
|
|
||||||
v.map(
|
|
||||||
(k, v) => MapEntry(
|
|
||||||
k,
|
|
||||||
v.raw,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -1187,53 +1187,6 @@ void main() {
|
||||||
selfSigningKey: selfSigningKey,
|
selfSigningKey: selfSigningKey,
|
||||||
userSigningKey: userSigningKey);
|
userSigningKey: userSigningKey);
|
||||||
});
|
});
|
||||||
test('uploadKeySignatures', () async {
|
|
||||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
|
||||||
matrixApi.accessToken = '1234';
|
|
||||||
|
|
||||||
final key1 = MatrixDeviceKeys.fromJson({
|
|
||||||
'user_id': '@alice:example.com',
|
|
||||||
'device_id': 'JLAFKJWSCS',
|
|
||||||
'algorithms': [
|
|
||||||
AlgorithmTypes.olmV1Curve25519AesSha2,
|
|
||||||
AlgorithmTypes.megolmV1AesSha2
|
|
||||||
],
|
|
||||||
'keys': {
|
|
||||||
'curve25519:JLAFKJWSCS':
|
|
||||||
'3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
|
|
||||||
'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI'
|
|
||||||
},
|
|
||||||
'signatures': {
|
|
||||||
'@alice:example.com': {
|
|
||||||
'ed25519:JLAFKJWSCS':
|
|
||||||
'dSO80A01XiigH3uBiDVx/EjzaoycHcjq9lfQX0uWsqxl2giMIiSPR8a4d291W1ihKJL/a+myXS367WT6NAIcBA'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
'unsigned': {'device_display_name': 'Alices mobile phone'},
|
|
||||||
});
|
|
||||||
final key2 = MatrixDeviceKeys.fromJson({
|
|
||||||
'user_id': '@alice:example.com',
|
|
||||||
'device_id': 'JLAFKJWSCS',
|
|
||||||
'algorithms': [
|
|
||||||
AlgorithmTypes.olmV1Curve25519AesSha2,
|
|
||||||
AlgorithmTypes.megolmV1AesSha2
|
|
||||||
],
|
|
||||||
'keys': {
|
|
||||||
'curve25519:JLAFKJWSCS':
|
|
||||||
'3C5BFWi2Y8MaVvjM8M22DBmh24PmgR0nPvJOIArzgyI',
|
|
||||||
'ed25519:JLAFKJWSCS': 'lEuiRJBit0IG6nUf5pUzWTUEsRVVe/HJkoKuEww9ULI'
|
|
||||||
},
|
|
||||||
'signatures': {
|
|
||||||
'@alice:example.com': {'ed25519:OTHERDEVICE': 'OTHERSIG'}
|
|
||||||
},
|
|
||||||
'unsigned': {'device_display_name': 'Alices mobile phone'},
|
|
||||||
});
|
|
||||||
final ret = await matrixApi.uploadKeySignatures([key1, key2]);
|
|
||||||
expect(
|
|
||||||
FakeMatrixApi.api['POST'],
|
|
||||||
ret.toJson(),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
test('requestPushers', () async {
|
test('requestPushers', () async {
|
||||||
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
matrixApi.homeserver = Uri.parse('https://fakeserver.notexisting');
|
||||||
matrixApi.accessToken = '1234';
|
matrixApi.accessToken = '1234';
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue