Convert SecretStorage.js to ts
This commit is contained in:
parent
814c0bed2e
commit
b2efcb9515
3 changed files with 11 additions and 5 deletions
|
@ -43,7 +43,7 @@ import {
|
||||||
removeKey as ssssRemoveKey,
|
removeKey as ssssRemoveKey,
|
||||||
keyFromDehydratedDeviceKey as createSSSSKeyFromDehydratedDeviceKey
|
keyFromDehydratedDeviceKey as createSSSSKeyFromDehydratedDeviceKey
|
||||||
} from "./ssss/index";
|
} from "./ssss/index";
|
||||||
import {SecretStorage} from "./ssss/SecretStorage.js";
|
import {SecretStorage} from "./ssss/SecretStorage";
|
||||||
import {ObservableValue, RetainedObservableValue} from "../observable/ObservableValue";
|
import {ObservableValue, RetainedObservableValue} from "../observable/ObservableValue";
|
||||||
|
|
||||||
const PICKLE_KEY = "DEFAULT_KEY";
|
const PICKLE_KEY = "DEFAULT_KEY";
|
||||||
|
|
|
@ -13,14 +13,20 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
See the License for the specific language governing permissions and
|
See the License for the specific language governing permissions and
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
import type {Key} from "./common";
|
||||||
|
import type {Platform} from "../../platform/web/Platform.js";
|
||||||
|
import type {Transaction} from "../storage/idb/Transaction";
|
||||||
|
|
||||||
export class SecretStorage {
|
export class SecretStorage {
|
||||||
constructor({key, platform}) {
|
private readonly _key: Key;
|
||||||
|
private readonly _platform: Platform;
|
||||||
|
|
||||||
|
constructor({key, platform}: {key: Key, platform: Platform}) {
|
||||||
this._key = key;
|
this._key = key;
|
||||||
this._platform = platform;
|
this._platform = platform;
|
||||||
}
|
}
|
||||||
|
|
||||||
async readSecret(name, txn) {
|
async readSecret(name: string, txn: Transaction): Promise<string | undefined> {
|
||||||
const accountData = await txn.accountData.get(name);
|
const accountData = await txn.accountData.get(name);
|
||||||
if (!accountData) {
|
if (!accountData) {
|
||||||
return;
|
return;
|
||||||
|
@ -37,7 +43,7 @@ export class SecretStorage {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _decryptAESSecret(type, encryptedData) {
|
async _decryptAESSecret(type: string, encryptedData: any): Promise<string> {
|
||||||
const {base64, utf8} = this._platform.encoding;
|
const {base64, utf8} = this._platform.encoding;
|
||||||
// now derive the aes and mac key from the 4s key
|
// now derive the aes and mac key from the 4s key
|
||||||
const hkdfKey = await this._platform.crypto.derive.hkdf(
|
const hkdfKey = await this._platform.crypto.derive.hkdf(
|
|
@ -22,7 +22,7 @@ import type {Storage} from "../storage/idb/Storage";
|
||||||
import type {Transaction} from "../storage/idb/Transaction";
|
import type {Transaction} from "../storage/idb/Transaction";
|
||||||
import type {IKeyDescription} from "./common";
|
import type {IKeyDescription} from "./common";
|
||||||
import type {Platform} from "../../platform/web/Platform.js";
|
import type {Platform} from "../../platform/web/Platform.js";
|
||||||
import type { Olm } from "./recoveryKey";
|
import type {Olm} from "./recoveryKey";
|
||||||
|
|
||||||
const SSSS_KEY = `${SESSION_E2EE_KEY_PREFIX}ssssKey`;
|
const SSSS_KEY = `${SESSION_E2EE_KEY_PREFIX}ssssKey`;
|
||||||
|
|
||||||
|
|
Reference in a new issue