classic-ui/modules/account/store/actions/getEncryptedAccount.js
FreezyEx b32527e057 Revert "minor fixes"
This reverts commit 7f8f7c2aa15c8b8c6a7449d177f46f8a417e2f67.
2022-10-13 16:03:54 +02:00

23 lines
772 B
JavaScript

import { encrypt, getEncryptionPublicKey } from 'eth-sig-util'
export function getEncryptedAccount(_, { privateKey, pubKey }) {
try {
const { address } = this.$provider.web3.eth.accounts.privateKeyToAccount(privateKey)
const keyWithOutPrefix = privateKey.slice(0, 2) === '0x' ? privateKey.replace('0x', '') : privateKey
const publicKey = getEncryptionPublicKey(keyWithOutPrefix)
const encryptedData = encrypt(pubKey, { data: keyWithOutPrefix }, 'x25519-xsalsa20-poly1305')
const hexPrivateKey = Buffer.from(JSON.stringify(encryptedData)).toString('hex')
return {
address,
publicKey,
hexPrivateKey,
encryptedData
}
} catch (err) {
throw new Error(`Method getEncryptedAccount has error: ${err.message}`)
}
}