classic-ui-dev/modules/account/store/actions/recoverAccountFromKey.js
Danil Kovtonyuk 44f31f8b9f
init
2022-04-22 13:14:19 +10:00

24 lines
920 B
JavaScript

import { getEncryptionPublicKey } from 'eth-sig-util'
export function recoverAccountFromKey({ dispatch }, { recoveryKey }) {
try {
dispatch('createMutation', { type: 'SET_DOMAIN_REQUEST', payload: { key: 'recoverAccountFromKey' } })
const publicKey = getEncryptionPublicKey(recoveryKey)
const { address } = this.$provider.web3.eth.accounts.privateKeyToAccount(recoveryKey)
const keyWithOutPrefix = recoveryKey.slice(0, 2) === '0x' ? recoveryKey.replace('0x', '') : recoveryKey
this.$sessionStorage.setItem(address, keyWithOutPrefix)
dispatch('saveAccount', { account: { publicKey, privateKey: '' }, address })
dispatch('createMutation', { type: 'SET_DOMAIN_SUCCESS', payload: { key: 'recoverAccountFromKey' } })
} catch (err) {
dispatch('createMutation', {
type: 'SET_DOMAIN_FAILED',
payload: { key: 'recoverAccountFromKey', errorMessage: err.message }
})
}
}