From: Chris Duncan Date: Wed, 5 Aug 2026 04:38:54 +0000 (-0700) Subject: Replace try-catch block with promise functions for consistency. X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=29051ffa3b776e98ad47177da0b1acb8c0006828;p=libnemo.git Replace try-catch block with promise functions for consistency. --- diff --git a/src/lib/vault/vault-worker.ts b/src/lib/vault/vault-worker.ts index e880870..d7d78ee 100644 --- a/src/lib/vault/vault-worker.ts +++ b/src/lib/vault/vault-worker.ts @@ -145,24 +145,22 @@ function create (type?: WalletType, id?: UUID, key?: CryptoKey, keySalt?: ArrayB if (type !== 'BIP-44' && type !== 'BLAKE2b') { throw new TypeError('Unsupported software wallet algorithm', { cause: type }) } - try { - const entropy = crypto.getRandomValues(new Uint8Array(32)) - return Bip39.fromEntropy(entropy) - .then(bip39 => _load(type, id, key, keySalt, bip39.phrase, mnemonicSalt)) - .then(({ iv, salt, encrypted }) => { - entropy.fill(0) - if (_seed == null || _mnemonic == null) { - throw new Error('Failed to generate seed and mnemonic') - } - return { iv, salt, encrypted, seed: _seed.slice(), mnemonic: _mnemonic.slice() } - }) - } catch (err) { - console.error(err) - throw new Error('Failed to create wallet', { cause: err }) - } finally { - lock() + const entropy = crypto.getRandomValues(new Uint8Array(32)) + return Bip39.fromEntropy(entropy) + .then(bip39 => _load(type, id, key, keySalt, bip39.phrase, mnemonicSalt)) + .then(({ iv, salt, encrypted }) => { + entropy.fill(0) + if (_seed == null || _mnemonic == null) { + throw new Error('Failed to generate seed and mnemonic') + } + return { iv, salt, encrypted, seed: _seed.slice(), mnemonic: _mnemonic.slice() } + }) + .catch(err => { + console.error(err) + throw new Error('Failed to create wallet', { cause: err }) + }) + .finally(() => lock()) } -} /** * Derives the private and public keys of a child account from the current