Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
existingPassphrase,
selectedAccount,
} = this.state
const {
generateNewWalletAccount,
authenticated,
history,
accounts,
} = this.props
if (selectedAccount) {
const accountInStorage = accounts.find(
account => account.label === selectedAccount.value,
)
const key = await wallet.decryptAsync(
accountInStorage.key,
existingPassphrase,
)
generateNewWalletAccount(
passphrase,
passphrase2,
key,
keypart2,
'SPLIT',
history,
walletName,
authenticated,
() => this.setState({ submitButtonDisabled: false }),
)
}
}
toggleStep = (e: SyntheticMouseEvent<*>) => {
if (this.state.step === 1) {
const { existingPassphrase, selectedAccount, keypart2 } = this.state
const { showErrorNotification } = this.props
if (selectedAccount) {
const accountInStorage = this.props.accounts.find(
account => account.label === selectedAccount.value,
)
this.setState({ submitButtonDisabled: true })
e.preventDefault()
wallet
.decryptAsync(accountInStorage.key, existingPassphrase)
.then(() => {
if (keypart2 && !wallet.isWIF(keypart2)) {
showErrorNotification({
message: 'Invalid secondary private key WIF',
})
} else {
this.setState({ step: 2 })
}
})
.catch(err => showErrorNotification({ message: err.message }))
.finally(() => this.setState({ submitButtonDisabled: false }))
}
} else {
this.setState({ step: 1 })
}
const nep2Authenticate = async (passphrase, encryptedWIF) => {
if (!wallet.isNEP2(encryptedWIF)) {
throw new Error('That is not a valid encrypted key.');
}
const wif = await wallet.decryptAsync(encryptedWIF, passphrase);
const account = new wallet.Account(wif);
return { wif: account.WIF, address: account.address };
};
({ passphrase, encryptedWIF }: Nep2LoginProps) => async (): Promise<
AccountType,
> => {
if (!validatePassphraseLength(passphrase)) {
throw new Error('Passphrase too short')
}
if (!wallet.isNEP2(encryptedWIF)) {
throw new Error('Invalid encrypted key entered')
}
const wif = await wallet.decryptAsync(encryptedWIF, passphrase)
const account = new wallet.Account(wif)
await upgradeNEP6AddAddresses(encryptedWIF, wif)
const hasInternetConnectivity = await checkForInternetConnectivity()
return {
wif: account.WIF,
publicKey: account.publicKey,
address: account.address,
isHardwareLogin: false,
hasInternetConnectivity,
}
},
)
submit = async () => {
const {
account,
passphrase,
accounts,
setPassphrase,
addAccount,
showErrorToast,
legacyPassphrase,
currentAccount
} = this.props;
const walletLabel = accounts.filter((acc) => acc.encryptedKey === currentAccount)[0].walletName;
try {
const wif = await wallet.decryptAsync(currentAccount, legacyPassphrase);
const { privateKey } = new wallet.Account(wif);
const options = {
walletLabel,
coinType: NEO,
isHardware: account.isHardware,
isImport: true,
privateKey
};
addAccount({ account, passphrase, options });
setPassphrase('');
} catch (e) {
showErrorToast(`Incorrect legacy passphrase for account ${walletLabel}`);
}
};