Skip to content

Commit

Permalink
fix: remove unrelated changes
Browse files Browse the repository at this point in the history
  • Loading branch information
ieow committed Nov 1, 2024
1 parent eab02d5 commit 0d3e204
Showing 1 changed file with 1 addition and 44 deletions.
45 changes: 1 addition & 44 deletions src/helper/browserStorage.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { TKeyTSS } from "@tkey/tss";
import BN from "bn.js";

import { FIELD_ELEMENT_HEX_LEN } from "../constants";
import { IAsyncStorage, IStorage, TkeyLocalStoreData } from "../interfaces";
import { IAsyncStorage, IStorage } from "../interfaces";
import CoreKitError from "./errors";

export class MemoryStorage implements IStorage {
Expand Down Expand Up @@ -70,42 +66,3 @@ export class AsyncStorage {
await this.storage.setItem(this._storeKey, JSON.stringify(store));
}
}

export class DeviceStorage {
private tKey: TKeyTSS;

private currentStorage: AsyncStorage;

constructor(tkeyInstance: TKeyTSS, currentStorage: AsyncStorage) {
this.tKey = tkeyInstance;
this.currentStorage = currentStorage;
}

// device factor
async setDeviceFactor(factorKey: BN, replace = false): Promise<void> {
if (!replace) {
const existingFactor = await this.getDeviceFactor();
if (existingFactor) {
throw CoreKitError.default("Device factor already exists");
}
}

const metadata = this.tKey.getMetadata();
const tkeyPubX = metadata.pubKey.x.toString(16, FIELD_ELEMENT_HEX_LEN);
await this.currentStorage.set(
tkeyPubX,
JSON.stringify({
factorKey: factorKey.toString("hex").padStart(64, "0"),
} as TkeyLocalStoreData)
);
}

async getDeviceFactor(): Promise<string | undefined> {
const metadata = this.tKey.getMetadata();

const tkeyPubX = metadata.pubKey.x.toString(16, FIELD_ELEMENT_HEX_LEN);
const tKeyLocalStoreString = await this.currentStorage.get<string>(tkeyPubX);
const tKeyLocalStore = JSON.parse(tKeyLocalStoreString || "{}") as TkeyLocalStoreData;
return tKeyLocalStore.factorKey;
}
}

0 comments on commit 0d3e204

Please sign in to comment.