const e = await Entropy.create()\r
return await Bip44Wallet.fromEntropy(passkey as string, e.hex, salt)\r
} catch (err) {\r
- throw new Error(`Error creating new Bip44Wallet: ${err}`)\r
+ throw new Error('Error creating new Bip44Wallet', { cause: err })\r
}\r
}\r
\r
*/\r
static async fromEntropy (key: Uint8Array, entropy: string, salt?: string): Promise<Bip44Wallet>\r
static async fromEntropy (passkey: string | Uint8Array, entropy: string, salt: string = ''): Promise<Bip44Wallet> {\r
+ let wallet: Bip44Wallet\r
try {\r
const id = await Entropy.create(16)\r
const e = await Entropy.import(entropy)\r
const m = await Bip39Mnemonic.fromEntropy(e.hex)\r
const s = await m.toBip39Seed(salt)\r
Bip44Wallet.#isInternal = true\r
- const wallet = new this(id, s, m)\r
+ wallet = new this(id, s, m)\r
+ } catch (err) {\r
+ throw new Error('Error importing Bip44Wallet from entropy', { cause: err })\r
+ }\r
+ try {\r
await wallet.lock(passkey)\r
- return wallet\r
} catch (err) {\r
- throw new Error(`Error importing Bip44Wallet from entropy: ${err}`)\r
+ await wallet.destroy()\r
+ throw new Error('Error locking Bip44Wallet while importing from entropy', { cause: err })\r
}\r
+ return wallet\r
}\r
\r
/**\r
*/\r
static async fromMnemonic (key: Uint8Array, mnemonic: string, salt?: string): Promise<Bip44Wallet>\r
static async fromMnemonic (passkey: string | Uint8Array, mnemonic: string, salt: string = ''): Promise<Bip44Wallet> {\r
+ let wallet: Bip44Wallet\r
try {\r
const id = await Entropy.create(16)\r
const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
const s = await m.toBip39Seed(salt)\r
Bip44Wallet.#isInternal = true\r
- const wallet = new this(id, s, m)\r
+ wallet = new this(id, s, m)\r
+ } catch (err) {\r
+ throw new Error('Error importing Bip44Wallet from mnemonic', { cause: err })\r
+ }\r
+ try {\r
await wallet.lock(passkey)\r
- return wallet\r
} catch (err) {\r
- throw new Error(`Error importing Bip44Wallet from mnemonic: ${err}`)\r
+ await wallet.destroy()\r
+ throw new Error('Error locking Bip44Wallet while importing from mnemonic', { cause: err })\r
}\r
+ return wallet\r
}\r
\r
/**\r
const id = await Entropy.create(16)\r
Bip44Wallet.#isInternal = true\r
const wallet = new this(id, seed)\r
- await wallet.lock(passkey)\r
+ try {\r
+ await wallet.lock(passkey)\r
+ } catch (err) {\r
+ await wallet.destroy()\r
+ throw new Error('Error locking Bip44Wallet while importing from seed', { cause: err })\r
+ }\r
return wallet\r
}\r
\r
const seed = await Entropy.create()\r
return await Blake2bWallet.fromSeed(passkey as string, seed.hex)\r
} catch (err) {\r
- throw new Error(`Error creating new Blake2bWallet: ${err}`)\r
+ throw new Error('Error creating new Blake2bWallet', { cause: err })\r
}\r
}\r
\r
const m = await Bip39Mnemonic.fromEntropy(seed)\r
Blake2bWallet.#isInternal = true\r
const wallet = new this(id, s, m)\r
- await wallet.lock(passkey)\r
+ try {\r
+ await wallet.lock(passkey)\r
+ } catch (err) {\r
+ await wallet.destroy()\r
+ throw new Error('Error locking Blake2bWallet while importing from seed', { cause: err })\r
+ }\r
return wallet\r
}\r
\r
*/\r
static async fromMnemonic (key: Uint8Array, mnemonic: string): Promise<Blake2bWallet>\r
static async fromMnemonic (passkey: string | Uint8Array, mnemonic: string): Promise<Blake2bWallet> {\r
+ let wallet: Blake2bWallet\r
try {\r
const id = await Entropy.create(16)\r
const m = await Bip39Mnemonic.fromPhrase(mnemonic)\r
const s = await m.toBlake2bSeed()\r
Blake2bWallet.#isInternal = true\r
- const wallet = new this(id, s, m)\r
+ wallet = new this(id, s, m)\r
+ } catch (err) {\r
+ throw new Error('Error importing Blake2bWallet from mnemonic', { cause: err })\r
+ }\r
+ try {\r
await wallet.lock(passkey)\r
- return wallet\r
} catch (err) {\r
- throw new Error(`Error importing Blake2bWallet from mnemonic: ${err}`)\r
+ await wallet.destroy()\r
+ throw new Error('Error locking Blake2bWallet while importing from mnemonic', { cause: err })\r
}\r
+ return wallet\r
}\r
\r
/**\r