Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const determineKey = key => {
if (wallet.isNEP2(key)) return "NEP2";
if (wallet.isWIF(key)) return "WIF";
return false;
};
const encryptPrivateKey = (privateKey, passphrase, confirmPassphrase) => {
if (passphrase !== confirmPassphrase) {
throw new Error('Passphrases do not match')
}
if (!validatePassphraseLength(passphrase)) {
throw new Error('Please choose a longer passphrase')
}
if (privateKey && !wallet.isWIF(privateKey)) {
throw new Error('The private key is not valid')
}
return wallet.encrypt(privateKey, passphrase)
}
.then(() => {
if (keypart2 && !wallet.isWIF(keypart2)) {
showErrorNotification({
message: 'Invalid secondary private key WIF',
})
} else {
this.setState({ step: 2 })
}
})
.catch(err => showErrorNotification({ message: err.message }))
export const generateNewEncryptedWIF = (
wif: string,
passphrase: string,
confirmPassphrase: string,
) => {
if (passphrase !== confirmPassphrase) {
throw new Error('Passphrases do not match')
}
if (!validatePassphraseLength(passphrase)) {
throw new Error('Please choose a longer passphrase')
}
if (wif && !wallet.isWIF(wif)) {
throw new Error('The private key is not valid')
}
const encryptedWIF = wallet.encrypt(wif, passphrase)
return {
type: NEW_ENCRYPTED_WIF,
payload: { encryptedWIF },
}
}