1
0
mirror of https://github.com/matrix-org/matrix-js-sdk.git synced 2025-11-29 16:43:09 +03:00

Factor crypto stuff out of MatrixClient

Introduce a new Crypto class which encapsulates all of the the crypto-related
gubbins, replacing it with thin wrappers in MatrixClient.
This commit is contained in:
Richard van der Hoff
2016-08-04 09:03:39 +01:00
parent d9867ba458
commit ad6eec329d
4 changed files with 914 additions and 684 deletions

View File

@@ -705,7 +705,7 @@ MatrixBaseApis.prototype.search = function(opts, callback) {
* @param {Object} content body of upload request
*
* @param {Object=} opts
*
* @param {string=} opts.device_id explicit device_id to use for upload
* (default is to use the same as that used during auth).
*
@@ -730,6 +730,56 @@ MatrixBaseApis.prototype.uploadKeysRequest = function(content, opts, callback) {
);
};
/**
* Download device keys
*
* @param {string[]} userIds list of users to get keys for
*
* @param {module:client.callback=} callback
*
* @return {module:client.Promise} Resolves: result object. Rejects: with
* an error response ({@link module:http-api.MatrixError}).
*/
MatrixBaseApis.prototype.downloadKeysForUsers = function(userIds, callback) {
var downloadQuery = {};
for (var i = 0; i < userIds.length; ++i) {
downloadQuery[userIds[i]] = {};
}
var content = {device_keys: downloadQuery};
return this._http.authedRequestWithPrefix(
callback, "POST", "/keys/query", undefined, content,
httpApi.PREFIX_UNSTABLE
);
};
/**
* Claim one-time keys
*
* @param {string[][]} devices a list of [userId, deviceId] pairs
*
* @param {module:client.callback=} callback
*
* @return {module:client.Promise} Resolves: result object. Rejects: with
* an error response ({@link module:http-api.MatrixError}).
*/
MatrixBaseApis.prototype.claimOneTimeKeys = function(devices, callback) {
var queries = {};
for (var i = 0; i < devices.length; ++i) {
var userId = devices[i][0];
var deviceId = devices[i][1];
var query = queries[userId] || {};
queries[userId] = query;
query[deviceId] = "curve25519";
}
var content = {one_time_keys: queries};
return this._http.authedRequestWithPrefix(
callback, "POST", "/keys/claim", undefined, content,
httpApi.PREFIX_UNSTABLE
);
};
// Identity Server Operations
// ==========================