encrypted: new ArrayBuffer(0)
}
if (wallet.type !== 'Ledger') {
- if (typeof password !== 'string') {
- throw new TypeError('Password must be a string')
- }
+ Wallet.zxcvbn(password)
if (mnemonicSalt !== undefined && typeof mnemonicSalt !== 'string') {
throw new TypeError('Mnemonic salt must be a string')
}
//! SPDX-FileCopyrightText: 2025 Chris Duncan <chris@codecow.com>\r
//! SPDX-License-Identifier: GPL-3.0-or-later\r
\r
+import { ZxcvbnFactory } from '@zxcvbn-ts/core'\r
+import * as zxcvbnCommonPackage from '@zxcvbn-ts/language-common'\r
+import * as zxcvbnEnPackage from '@zxcvbn-ts/language-en'\r
import { UUID } from 'crypto'\r
import { Account } from '../account'\r
import { Block } from '../block'\r
*/\r
export class Wallet {\r
static #isInternal: boolean = false\r
+ static #zxcvbn: ZxcvbnFactory = new ZxcvbnFactory({\r
+ translations: zxcvbnEnPackage.translations,\r
+ graphs: zxcvbnCommonPackage.adjacencyGraphs,\r
+ dictionary: {\r
+ ...zxcvbnCommonPackage.dictionary,\r
+ ...zxcvbnEnPackage.dictionary,\r
+ }\r
+ })\r
+ static zxcvbn (password: unknown): asserts password is string {\r
+ if (typeof password !== 'string') {\r
+ throw new TypeError('Password must be a string')\r
+ }\r
+ const passwordCheck = this.#zxcvbn.check(password)\r
+ if (passwordCheck.score < 4) {\r
+ throw new RangeError('Weak password', { cause: passwordCheck })\r
+ }\r
+ }\r
\r
/**\r
* @returns {boolean}\r
throw new Error('Failed to initialize Ledger wallet', { cause: 'Browser is unsupported' })
}
} else {
+ Wallet.zxcvbn(password)
if (wallet.type !== 'BIP-44' && wallet.type !== 'BLAKE2b' && wallet.type !== 'Exodus') {
throw new TypeError('Invalid wallet type', { cause: wallet.type })
}
- if (typeof password !== 'string') {
- throw new TypeError('Password must be a string')
- }
if (typeof secret !== 'string') {
throw new TypeError('Wallet secret must be a string')
}
export async function _update (wallet: Wallet, vault: Vault, password: unknown): Promise<void> {
try {
if (wallet.type !== 'Ledger') {
- if (typeof password !== 'string') {
- throw new TypeError('Password must be a string')
- }
+ Wallet.zxcvbn(password)
const pending = vault.request<ArrayBuffer>({
action: 'update',
password: utf8.toBuffer(password)