Convert SecretStorage.js to ts

This commit is contained in:
RMidhunSuresh 2021-11-29 17:05:15 +05:30
parent 814c0bed2e
commit b2efcb9515
3 changed files with 11 additions and 5 deletions

View file

@ -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";

View file

@ -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(