Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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 };
};
export const writePreviousAuthActions = createActions(ID, ({ encryptedWIF }) => async () => {
if (!wallet.isNEP2(encryptedWIF)) {
throw new Error('Invalid encrypted WIF');
}
const data = { encryptedWIF };
await setStorage(ID, data);
return data;
});
export const determineKey = key => {
if (wallet.isNEP2(key)) return "NEP2";
if (wallet.isWIF(key)) return "WIF";
return false;
};
genWallet () {
if (this.private.value === '') {
this.setState({ error: 'Empty Field!' })
return
}
if (!wallet.isNEP2(this.private.value) && !wallet.isWIF(this.private.value) && !wallet.isPrivateKey(this.private.value)) {
this.setState({ error: 'Wrong Private Key Length!' })
return
}
let newWallet = {}
try {
const acct = new wallet.Account(this.private.value)
if (wallet.isNEP2(this.private.value)) {
if (this.conPassword.value.length > 0) {
newWallet.nep2 = acct.encrypted
acct.decrypt(this.conPassword.value)
} else {
this.setState({error: "Encrypted key provided without password!"})
}
}
newWallet.private = acct.privateKey
newWallet.public = acct.publicKey
newWallet.address = acct.address
} catch (e) {
this.setState({ error: "Invalid Private key!" })
return
}
const done = this.props.addWallet(newWallet)
({ 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,