* three types of wallets are supported: BIP-44, BLAKE2b, and Ledger.\r
*/\r
export class Wallet {\r
- static #isInternal: boolean = false\r
static DB_NAME = 'Wallet'\r
\r
+ /**\r
+ * Retrieves all encrypted wallets from the database.\r
+ *\r
+ * @returns Array of wallets with encrypted secrets and unencrypted metadata\r
+ */\r
+ static async backup (): Promise<NamedData[]> {\r
+ return _backup()\r
+ }\r
+\r
/**\r
* Creates a new HD wallet by using an entropy value generated using a\r
* cryptographically strong pseudorandom number generator.\r
return self\r
}\r
\r
- /**\r
- * Retrieves all encrypted wallets from the database.\r
- *\r
- * @returns Array of wallets with encrypted secrets and unencrypted metadata\r
- */\r
- static async backup (): Promise<NamedData[]> {\r
- return _backup()\r
- }\r
-\r
/**\r
* Imports an existing HD wallet by using an entropy value generated using a\r
* cryptographically strong pseudorandom number generator.NamedD\r
return typeof id === 'string' ? wallets[0] : wallets\r
}\r
\r
- #accounts: AccountList\r
- #lockTimer?: any\r
- #id: string\r
- #mnemonic?: ArrayBuffer\r
- #vault: WorkerQueue\r
- #seed?: ArrayBuffer\r
- #type: WalletType\r
+ constructor (type: WalletType, id?: string)\r
+ constructor (type: unknown, id?: string) {\r
+ if (!Wallet.#isInternal && type !== 'Ledger') {\r
+ throw new Error(`Wallet cannot be instantiated directly. Use 'await Wallet.create()' instead.`)\r
+ }\r
+ if (type !== 'BIP-44' && type !== 'BLAKE2b' && type !== 'Ledger') {\r
+ throw new TypeError('Invalid wallet type', { cause: type })\r
+ }\r
+ Wallet.#isInternal = false\r
+ this.#accounts = new AccountList()\r
+ this.#id = id ?? crypto.randomUUID()\r
+ this.#vault = new WorkerQueue(VaultWorker)\r
+ this.#type = type\r
+ }\r
+\r
+ /**\r
+ * @returns UUID of the wallet.\r
+ */\r
+ get id (): string { return this.#id }\r
\r
- get id () { return this.#id }\r
- get type () { return this.#type }\r
+ /**\r
+ * Method used to create wallet and derive accounts.\r
+ */\r
+ get type (): WalletType { return this.#type }\r
\r
- /** Set when calling `create()` and self-destructs after the first read. */\r
- get mnemonic () {\r
+ /**\r
+ * Set when calling `create()`. Self-destructs after the first read.\r
+ * @returns Mnemonic phrase used to derive the wallet seed.\r
+ */\r
+ get mnemonic (): string | undefined {\r
if (this.#mnemonic == null) return undefined\r
try {\r
const b = new Uint8Array(this.#mnemonic)\r
return undefined\r
}\r
}\r
- /** Set when calling `create()` and self-destructs after the first read. */\r
- get seed () {\r
+\r
+ /**\r
+ * Set when calling `create()`. Self-destructs after the first read.\r
+ * @returns Seed used to derive accounts.\r
+ */\r
+ get seed (): string | undefined {\r
if (this.#seed == null) return undefined\r
try {\r
const b = new Uint8Array(this.#seed)\r
}\r
}\r
\r
- constructor (type: WalletType, id?: string)\r
- constructor (type: unknown, id?: string) {\r
- if (!Wallet.#isInternal && type !== 'Ledger') {\r
- throw new Error(`Wallet cannot be instantiated directly. Use 'await Wallet.create()' instead.`)\r
- }\r
- if (type !== 'BIP-44' && type !== 'BLAKE2b' && type !== 'Ledger') {\r
- throw new TypeError('Invalid wallet type', { cause: type })\r
- }\r
- Wallet.#isInternal = false\r
- this.#accounts = new AccountList()\r
- this.#id = id ?? crypto.randomUUID()\r
- this.#vault = new WorkerQueue(VaultWorker)\r
- this.#type = type\r
- }\r
-\r
/**\r
* Retrieves an account from a wallet using its child key derivation function.\r
* Defaults to the first account at index 0.\r
this.#lockTimer = setTimeout(() => this.lock(), 300000)\r
}\r
}\r
+\r
+ static #isInternal: boolean = false\r
+ #accounts: AccountList\r
+ #lockTimer?: any\r
+ #id: string\r
+ #mnemonic?: ArrayBuffer\r
+ #vault: WorkerQueue\r
+ #seed?: ArrayBuffer\r
+ #type: WalletType\r
}\r