classic-ui/modules/account/store/actions/recoverAccountFromChain/decryptAccount.js

15 lines
524 B
JavaScript
Raw Permalink Normal View History

2022-04-22 13:05:56 +10:00
import { getEncryptionPublicKey } from 'eth-sig-util'
export async function decryptAccount({ dispatch }, encryptedAccount) {
try {
const privateKey = await dispatch('metamask/ethDecrypt', encryptedAccount, { root: true })
const publicKey = getEncryptionPublicKey(privateKey)
const { address } = await this.$provider.web3.eth.accounts.privateKeyToAccount(privateKey)
return { address, publicKey, privateKey }
} catch (err) {
throw new Error(`Method decryptAccount has error: ${err.message}`)
}
}