|
1 | | -import { TKeyTSS } from "@tkey/tss"; |
2 | | -import BN from "bn.js"; |
3 | | - |
4 | | -import { FIELD_ELEMENT_HEX_LEN } from "../constants"; |
5 | | -import { IAsyncStorage, IStorage, TkeyLocalStoreData } from "../interfaces"; |
| 1 | +import { IAsyncStorage, IStorage } from "../interfaces"; |
6 | 2 | import CoreKitError from "./errors"; |
7 | 3 |
|
8 | 4 | export class MemoryStorage implements IStorage { |
@@ -70,42 +66,3 @@ export class AsyncStorage { |
70 | 66 | await this.storage.setItem(this._storeKey, JSON.stringify(store)); |
71 | 67 | } |
72 | 68 | } |
73 | | - |
74 | | -export class DeviceStorage { |
75 | | - private tKey: TKeyTSS; |
76 | | - |
77 | | - private currentStorage: AsyncStorage; |
78 | | - |
79 | | - constructor(tkeyInstance: TKeyTSS, currentStorage: AsyncStorage) { |
80 | | - this.tKey = tkeyInstance; |
81 | | - this.currentStorage = currentStorage; |
82 | | - } |
83 | | - |
84 | | - // device factor |
85 | | - async setDeviceFactor(factorKey: BN, replace = false): Promise<void> { |
86 | | - if (!replace) { |
87 | | - const existingFactor = await this.getDeviceFactor(); |
88 | | - if (existingFactor) { |
89 | | - throw CoreKitError.default("Device factor already exists"); |
90 | | - } |
91 | | - } |
92 | | - |
93 | | - const metadata = this.tKey.getMetadata(); |
94 | | - const tkeyPubX = metadata.pubKey.x.toString(16, FIELD_ELEMENT_HEX_LEN); |
95 | | - await this.currentStorage.set( |
96 | | - tkeyPubX, |
97 | | - JSON.stringify({ |
98 | | - factorKey: factorKey.toString("hex").padStart(64, "0"), |
99 | | - } as TkeyLocalStoreData) |
100 | | - ); |
101 | | - } |
102 | | - |
103 | | - async getDeviceFactor(): Promise<string | undefined> { |
104 | | - const metadata = this.tKey.getMetadata(); |
105 | | - |
106 | | - const tkeyPubX = metadata.pubKey.x.toString(16, FIELD_ELEMENT_HEX_LEN); |
107 | | - const tKeyLocalStoreString = await this.currentStorage.get<string>(tkeyPubX); |
108 | | - const tKeyLocalStore = JSON.parse(tKeyLocalStoreString || "{}") as TkeyLocalStoreData; |
109 | | - return tKeyLocalStore.factorKey; |
110 | | - } |
111 | | -} |
0 commit comments