From 51231315420ae8321de4eba2e1933e23aa55b5ba Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sun, 27 Jul 2025 01:28:34 -0700 Subject: [PATCH] Start taking only string passwords. --- src/lib/wallets/bip44-wallet.ts | 47 ++++--------------------------- src/lib/wallets/blake2b-wallet.ts | 29 +++---------------- 2 files changed, 10 insertions(+), 66 deletions(-) diff --git a/src/lib/wallets/bip44-wallet.ts b/src/lib/wallets/bip44-wallet.ts index 8490ca7..87ad894 100644 --- a/src/lib/wallets/bip44-wallet.ts +++ b/src/lib/wallets/bip44-wallet.ts @@ -78,19 +78,7 @@ export class Bip44Wallet extends Wallet { * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async fromEntropy (password: string, entropy: string, salt?: string): Promise - /** - * Creates a new HD wallet by using a pregenerated entropy value. The user - * must ensure that it is cryptographically strongly random. - * - * @param {Uint8Array} key - Used to lock and unlock the wallet - * @param {string} entropy - Used when generating the initial mnemonic phrase - * @param {string} [salt=''] - Used when generating the final seed - * @returns {Bip44Wallet} A newly instantiated Bip44Wallet - */ - static async fromEntropy (key: Uint8Array, entropy: string, salt?: string): Promise - static async fromEntropy (passkey: Key, entropy: string, salt: string = ''): Promise { - if (typeof passkey === 'string') passkey = utf8.toBytes(passkey) + static async fromEntropy (password: string, entropy: string, salt: string = ''): Promise { let wallet: Bip44Wallet try { const id = await Entropy.create() @@ -103,7 +91,7 @@ export class Bip44Wallet extends Wallet { throw new Error('Error importing Bip44Wallet from entropy', { cause: err }) } try { - await wallet.lock(passkey) + await wallet.lock(password) } catch (err) { await wallet.destroy() throw new Error('Error locking Bip44Wallet while importing from entropy', { cause: err }) @@ -119,18 +107,7 @@ export class Bip44Wallet extends Wallet { * @param {string} [salt=''] - Used when generating the final seed * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async fromMnemonic (password: string, mnemonic: string, salt?: string): Promise - /** - * Creates a new HD wallet by using a pregenerated mnemonic phrase. - * - * @param {Uint8Array} key - Used to lock and unlock the wallet - * @param {string} mnemonic - Used when generating the final seed - * @param {string} [salt=''] - Used when generating the final seed - * @returns {Bip44Wallet} A newly instantiated Bip44Wallet - */ - static async fromMnemonic (key: Uint8Array, mnemonic: string, salt?: string): Promise - static async fromMnemonic (passkey: Key, mnemonic: string, salt: string = ''): Promise { - if (typeof passkey === 'string') passkey = utf8.toBytes(passkey) + static async fromMnemonic (password: string, mnemonic: string, salt: string = ''): Promise { let wallet: Bip44Wallet try { const id = await Entropy.create() @@ -142,7 +119,7 @@ export class Bip44Wallet extends Wallet { throw new Error('Error importing Bip44Wallet from mnemonic', { cause: err }) } try { - await wallet.lock(passkey) + await wallet.lock(password) } catch (err) { await wallet.destroy() throw new Error('Error locking Bip44Wallet while importing from mnemonic', { cause: err }) @@ -159,19 +136,7 @@ export class Bip44Wallet extends Wallet { * @param {string} seed - Hexadecimal 128-character string used to derive private-public key pairs * @returns {Bip44Wallet} A newly instantiated Bip44Wallet */ - static async fromSeed (password: string, seed: string): Promise - /** - * Creates a new HD wallet by using a pregenerated seed value. This seed cannot - * be used to regenerate any higher level randomness which includes entropy, - * mnemonic phrase, and salt. - * - * @param {Uint8Array} key - Used to lock and unlock the wallet - * @param {string} seed - Hexadecimal 128-character string used to derive private-public key pairs - * @returns {Bip44Wallet} A newly instantiated Bip44Wallet - */ - static async fromSeed (key: Uint8Array, seed: string): Promise - static async fromSeed (passkey: Key, seed: string): Promise { - if (typeof passkey === 'string') passkey = utf8.toBytes(passkey) + static async fromSeed (password: string, seed: string): Promise { if (seed.length !== SEED_LENGTH_BIP44) { throw new Error(`Expected a ${SEED_LENGTH_BIP44}-character seed, but received ${seed.length}-character string.`) } @@ -182,7 +147,7 @@ export class Bip44Wallet extends Wallet { Bip44Wallet.#isInternal = true const wallet = new this(id, hex.toBytes(seed)) try { - await wallet.lock(passkey) + await wallet.lock(password) } catch (err) { await wallet.destroy() throw new Error('Error locking Bip44Wallet while importing from seed', { cause: err }) diff --git a/src/lib/wallets/blake2b-wallet.ts b/src/lib/wallets/blake2b-wallet.ts index 3b465fb..87b906c 100644 --- a/src/lib/wallets/blake2b-wallet.ts +++ b/src/lib/wallets/blake2b-wallet.ts @@ -69,18 +69,7 @@ export class Blake2bWallet extends Wallet { * @param {string} seed - Hexadecimal 64-character string used to derive private-public key pairs * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ - static async fromSeed (password: string, seed: string): Promise - /** - * Creates a new BLAKE2b wallet by using a pregenerated seed. The user must - * ensure that it is cryptographically strongly random. - * - * @param {Uint8Array} key - Used to lock and unlock the wallet - * @param {string} seed - Hexadecimal 64-character string used to derive private-public key pairs - * @returns {Blake2bWallet} A newly instantiated Blake2bWallet - */ - static async fromSeed (key: Uint8Array, seed: string): Promise - static async fromSeed (passkey: Key, seed: string): Promise { - if (typeof passkey === 'string') passkey = utf8.toBytes(passkey) + static async fromSeed (password: string, seed: string): Promise { if (seed.length !== SEED_LENGTH_BLAKE2B) { throw new Error(`Expected a ${SEED_LENGTH_BLAKE2B}-character seed, but received ${seed.length}-character string.`) } @@ -94,7 +83,7 @@ export class Blake2bWallet extends Wallet { Blake2bWallet.#isInternal = true const wallet = new this(id, s, m) try { - await wallet.lock(passkey) + await wallet.lock(password) } catch (err) { await wallet.destroy() throw new Error('Error locking Blake2bWallet while importing from seed', { cause: err }) @@ -109,17 +98,7 @@ export class Blake2bWallet extends Wallet { * @param {string} mnemonic - Used when generating the final seed * @returns {Blake2bWallet} A newly instantiated Blake2bWallet */ - static async fromMnemonic (password: string, mnemonic: string): Promise - /** - * Creates a new BLAKE2b wallet by using a pregenerated mnemonic phrase. - * - * @param {Uint8Array} key - Used to lock and unlock the wallet - * @param {string} mnemonic - Used when generating the final seed - * @returns {Blake2bWallet} A newly instantiated Blake2bWallet - */ - static async fromMnemonic (key: Uint8Array, mnemonic: string): Promise - static async fromMnemonic (passkey: Key, mnemonic: string): Promise { - if (typeof passkey === 'string') passkey = utf8.toBytes(passkey) + static async fromMnemonic (password: string, mnemonic: string): Promise { let wallet: Blake2bWallet try { const id = await Entropy.create() @@ -131,7 +110,7 @@ export class Blake2bWallet extends Wallet { throw new Error('Error importing Blake2bWallet from mnemonic', { cause: err }) } try { - await wallet.lock(passkey) + await wallet.lock(password) } catch (err) { await wallet.destroy() throw new Error('Error locking Blake2bWallet while importing from mnemonic', { cause: err }) -- 2.47.3