]> git.codecow.com Git - libnemo.git/commitdiff
Replace try-catch block with promise functions for consistency.
authorChris Duncan <chris@codecow.com>
Wed, 5 Aug 2026 04:38:54 +0000 (21:38 -0700)
committerChris Duncan <chris@codecow.com>
Wed, 5 Aug 2026 04:38:54 +0000 (21:38 -0700)
src/lib/vault/vault-worker.ts

index e880870bc31e0b82c2344858d93f5d7b3261ddad..d7d78ee09638becd49ae85744fb649215c41086a 100644 (file)
@@ -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