-
Notifications
You must be signed in to change notification settings - Fork 388
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e890bfc
commit 20d119b
Showing
13 changed files
with
894 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Dexie from "dexie" | ||
import { normalizeEVMAddress } from "../../lib/utils" | ||
import { HexString } from "../../types" | ||
|
||
export interface TrezorAccount { | ||
trezorId: string | ||
address: HexString | ||
path: string | ||
} | ||
|
||
export class TrezorDatabase extends Dexie { | ||
private trezor!: Dexie.Table<TrezorAccount, number> | ||
|
||
constructor() { | ||
super("tally/trezor") | ||
|
||
this.version(1).stores({ | ||
ledger: "&address,trezorId", | ||
}) | ||
} | ||
|
||
async addAccount(account: TrezorAccount): Promise<void> { | ||
await this.trezor.add(account) | ||
} | ||
|
||
async getAccountByAddress(address: HexString): Promise<TrezorAccount | null> { | ||
return ( | ||
(await this.trezor | ||
.where("address") | ||
.equals(normalizeEVMAddress(address)) | ||
.first()) ?? null | ||
) | ||
} | ||
|
||
async getAllAccountsByTrezorId(trezorId: string): Promise<TrezorAccount[]> { | ||
return this.trezor.where("trezorId").equals(trezorId).toArray() | ||
} | ||
} | ||
|
||
export async function getOrCreateDB(): Promise<TrezorDatabase> { | ||
return new TrezorDatabase() | ||
} |
Oops, something went wrong.