You've already forked matrix-js-sdk
mirror of
https://github.com/matrix-org/matrix-js-sdk.git
synced 2025-11-26 17:03:12 +03:00
Rename getPrivateKeys to getCrossSigningKeys
This commit is contained in:
@@ -178,8 +178,8 @@ function keyFromRecoverySession(session, decryptionKey) {
|
|||||||
*
|
*
|
||||||
* @param {object} opts.cryptoCallbacks Optional. Callbacks for crypto and cross-signing.
|
* @param {object} opts.cryptoCallbacks Optional. Callbacks for crypto and cross-signing.
|
||||||
*
|
*
|
||||||
* @param {function} [opts.cryptoCallbacks.getPrivateKey]
|
* @param {function} [opts.cryptoCallbacks.getCrossSigningKey]
|
||||||
* Optional (required for cross-signing). Function to call when a private key is needed.
|
* Optional (required for cross-signing). Function to call when a cross-signing private key is needed.
|
||||||
* Args:
|
* Args:
|
||||||
* {string} type The type of key needed. Will be one of "master",
|
* {string} type The type of key needed. Will be one of "master",
|
||||||
* "self_signing", or "user_signing"
|
* "self_signing", or "user_signing"
|
||||||
@@ -190,7 +190,7 @@ function keyFromRecoverySession(session, decryptionKey) {
|
|||||||
* Should return a promise that resolves with the private key as a
|
* Should return a promise that resolves with the private key as a
|
||||||
* UInt8Array or rejects with an error.
|
* UInt8Array or rejects with an error.
|
||||||
*
|
*
|
||||||
* @param {function} [opts.cryptoCallbacks.savePrivateKeys]
|
* @param {function} [opts.cryptoCallbacks.saveCrossSigningKeys]
|
||||||
* Optional (required for cross-signing). Called when new private keys
|
* Optional (required for cross-signing). Called when new private keys
|
||||||
* for cross-signing need to be saved.
|
* for cross-signing need to be saved.
|
||||||
* Args:
|
* Args:
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
*
|
*
|
||||||
* @param {string} userId the user that the information is about
|
* @param {string} userId the user that the information is about
|
||||||
* @param {object} callbacks Callbacks used to interact with the app
|
* @param {object} callbacks Callbacks used to interact with the app
|
||||||
* Requires getPrivateKey and savePrivateKeys
|
* Requires getCrossSigningKey and saveCrossSigningKeys
|
||||||
*/
|
*/
|
||||||
constructor(userId, callbacks) {
|
constructor(userId, callbacks) {
|
||||||
super();
|
super();
|
||||||
@@ -56,19 +56,19 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
* @param {Uint8Array} expectedPubkey The matching public key or undefined to use
|
* @param {Uint8Array} expectedPubkey The matching public key or undefined to use
|
||||||
* the stored public key for the given key type.
|
* the stored public key for the given key type.
|
||||||
*/
|
*/
|
||||||
async getPrivateKey(type, expectedPubkey) {
|
async getCrossSigningKey(type, expectedPubkey) {
|
||||||
if (!this._callbacks.getPrivateKey) {
|
if (!this._callbacks.getCrossSigningKey) {
|
||||||
throw new Error("No getPrivateKey callback supplied");
|
throw new Error("No getCrossSigningKey callback supplied");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expectedPubkey === undefined) {
|
if (expectedPubkey === undefined) {
|
||||||
expectedPubkey = getPublicKey(this.keys[type])[1];
|
expectedPubkey = getPublicKey(this.keys[type])[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
const privkey = await this._callbacks.getPrivateKey(type, expectedPubkey);
|
const privkey = await this._callbacks.getCrossSigningKey(type, expectedPubkey);
|
||||||
if (!privkey) {
|
if (!privkey) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"getPrivateKey callback for " + type + " returned falsey",
|
"getCrossSigningKey callback for " + type + " returned falsey",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
const signing = new global.Olm.PkSigning();
|
const signing = new global.Olm.PkSigning();
|
||||||
@@ -76,7 +76,7 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
if (gotPubkey !== expectedPubkey) {
|
if (gotPubkey !== expectedPubkey) {
|
||||||
signing.free();
|
signing.free();
|
||||||
throw new Error(
|
throw new Error(
|
||||||
"Key type " + type + " from getPrivateKey callback did not match",
|
"Key type " + type + " from getCrossSigningKey callback did not match",
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
return [gotPubkey, signing];
|
return [gotPubkey, signing];
|
||||||
@@ -113,8 +113,8 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async resetKeys(level) {
|
async resetKeys(level) {
|
||||||
if (!this._callbacks.savePrivateKeys) {
|
if (!this._callbacks.saveCrossSigningKeys) {
|
||||||
throw new Error("No savePrivateKeys callback supplied");
|
throw new Error("No saveCrossSigningKeys callback supplied");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level === undefined || level & 4 || !this.keys.master) {
|
if (level === undefined || level & 4 || !this.keys.master) {
|
||||||
@@ -141,7 +141,7 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
} else {
|
} else {
|
||||||
[masterPub, masterSigning] = await this.getPrivateKey("master");
|
[masterPub, masterSigning] = await this.getCrossSigningyKey("master");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (level & CrossSigningLevel.SELF_SIGNING) {
|
if (level & CrossSigningLevel.SELF_SIGNING) {
|
||||||
@@ -181,7 +181,7 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Object.assign(this.keys, keys);
|
Object.assign(this.keys, keys);
|
||||||
this._callbacks.savePrivateKeys(privateKeys);
|
this._callbacks.saveCrossSigningKeys(privateKeys);
|
||||||
} finally {
|
} finally {
|
||||||
if (masterSigning) {
|
if (masterSigning) {
|
||||||
masterSigning.free();
|
masterSigning.free();
|
||||||
@@ -262,7 +262,7 @@ export class CrossSigningInfo extends EventEmitter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async signObject(data, type) {
|
async signObject(data, type) {
|
||||||
const [pubkey, signing] = await this.getPrivateKey(type);
|
const [pubkey, signing] = await this.getCrossSigningKey(type);
|
||||||
try {
|
try {
|
||||||
pkSign(data, signing, this.userId, pubkey);
|
pkSign(data, signing, this.userId, pubkey);
|
||||||
return data;
|
return data;
|
||||||
|
|||||||
@@ -236,11 +236,11 @@ Crypto.prototype.requestSecret = function(name, devices) {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Checks that a given private key matches a given public key
|
* Checks that a given private key matches a given public key
|
||||||
* This can be used by the getPrivateKey callback to verify that the
|
* This can be used by the getCrossSigningKey callback to verify that the
|
||||||
* private key it is about to supply is the one that was requested.
|
* private key it is about to supply is the one that was requested.
|
||||||
*
|
*
|
||||||
* @param {Uint8Array} privateKey The private key
|
* @param {Uint8Array} privateKey The private key
|
||||||
* @param {Uint8Array} expectedPublicKey The public key supplied by the getPrivateKey callback
|
* @param {Uint8Array} expectedPublicKey The public key supplied by the getCrossSigningKey callback
|
||||||
* @returns {boolean} true if the key matches, otherwise false
|
* @returns {boolean} true if the key matches, otherwise false
|
||||||
*/
|
*/
|
||||||
Crypto.prototype.checkPrivateKey = function(privateKey, expectedPublicKey) {
|
Crypto.prototype.checkPrivateKey = function(privateKey, expectedPublicKey) {
|
||||||
@@ -583,7 +583,7 @@ Crypto.prototype.checkOwnCrossSigningTrust = async function() {
|
|||||||
|
|
||||||
let signing = null;
|
let signing = null;
|
||||||
try {
|
try {
|
||||||
const ret = await this._crossSigningInfo.getPrivateKey(
|
const ret = await this._crossSigningInfo.getCrossSigningKey(
|
||||||
'master', seenPubkey,
|
'master', seenPubkey,
|
||||||
);
|
);
|
||||||
signing = ret[1];
|
signing = ret[1];
|
||||||
|
|||||||
Reference in New Issue
Block a user