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