Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
publicKey:
'caff2242b740a733daa3f3f96fc1592303b60c1704a8ac626e2704da039f41ee',
address: '2222471382442610527L',
balance: '0',
},
};
// Decrypt all passwords from delegate genesis and add to accounts array
// eslint-disable-next-line no-restricted-syntax
for (const anAccount of genesisDelegateAccounts) {
const { encryptedPassphrase } = defaultConfig.forging.delegates.find(
aDelegate => aDelegate.publicKey === anAccount.publicKey,
);
const passphrase = decryptPassphraseWithPassword(
parseEncryptedPassphrase(encryptedPassphrase),
defaultConfig.forging.defaultPassword,
);
const keys = getPrivateAndPublicKeyFromPassphrase(passphrase);
const address = getAddressFromPrivateKey(keys.privateKey);
accounts[`${anAccount.username}_delegate`] = {
passphrase,
privateKey: keys.privateKey,
publicKey: keys.publicKey,
address,
balance: '0',
};
}
// Generators
const generateTestCasesValidBlockVotesTx = () => {
const decryptKeypairs = config => {
const encryptedList = config.forging.delegates;
const password = config.forging.defaultPassword;
const keypairs = {};
// eslint-disable-next-line no-restricted-syntax
for (const encryptedItem of encryptedList) {
let passphrase;
try {
passphrase = decryptPassphraseWithPassword(
parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
password,
);
} catch (e) {
throw new Error('Invalid password and public key combination');
}
const {
publicKeyBytes,
privateKeyBytes,
} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
const keypair = {
publicKey: publicKeyBytes,
privateKey: privateKeyBytes,
};
it('should call parseEncryptedPassphrase', () => {
cryptography.decryptPassphrase(input);
return expect(
cryptographyModule.parseEncryptedPassphrase,
).to.be.calledWithExactly(input.encryptedPassphrase);
});
export const decryptPassphrase = ({
encryptedPassphrase,
password,
}: DecryptPassphraseInput) => {
const encryptedPassphraseObject = cryptography.parseEncryptedPassphrase(
encryptedPassphrase,
);
const passphrase = cryptography.decryptPassphraseWithPassword(
encryptedPassphraseObject,
password,
);
return { passphrase };
};
__private.decryptPassphrase = function(encryptedPassphrase, password) {
return decryptPassphraseWithPassword(
parseEncryptedPassphrase(encryptedPassphrase),
password
);
};
!this.config.forging.force ||
!this.config.forging.defaultPassword
) {
return;
}
this.logger.info(
`Loading ${
encryptedList.length
} delegates using encrypted passphrases from config`,
);
for (const encryptedItem of encryptedList) {
let passphrase;
try {
passphrase = decryptPassphraseWithPassword(
parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
this.config.forging.defaultPassword,
);
} catch (error) {
const decryptionError = `Invalid encryptedPassphrase for publicKey: ${
encryptedItem.publicKey
}. ${error.message}`;
this.logger.error(decryptionError);
throw decryptionError;
}
const {
publicKeyBytes,
privateKeyBytes,
} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
const keypair = {
async updateForgingStatus(publicKey, password, forging) {
const encryptedList = this.config.forging.delegates;
const encryptedItem = encryptedList.find(
item => item.publicKey === publicKey,
);
let keypair;
let passphrase;
if (encryptedItem) {
try {
passphrase = decryptPassphraseWithPassword(
parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
password,
);
} catch (e) {
throw new Error('Invalid password and public key combination');
}
const {
publicKeyBytes,
privateKeyBytes,
} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
keypair = {
publicKey: publicKeyBytes,
privateKey: privateKeyBytes,
};
} else {
throw new Error(`Delegate with publicKey: ${publicKey} not found`);
const processInputs = (encryptedPassphrase?: string) => ({
password,
data,
}: InputFromSourceOutput) => {
const encryptedPassphraseTarget =
encryptedPassphrase || getFirstLineFromString(data);
if (!encryptedPassphraseTarget) {
throw new ValidationError('No encrypted passphrase was provided');
}
if (!password) {
throw new ValidationError('No password was provided');
}
const encryptedPassphraseObject = parseEncryptedPassphrase(
encryptedPassphraseTarget,
);
const passphrase = decryptPassphraseWithPassword(
encryptedPassphraseObject,
password,
);
return { passphrase };
};
!encryptedList ||
!encryptedList.length ||
!this.config.forging.force ||
!this.config.forging.defaultPassword
) {
return;
}
this.logger.info(
`Loading ${encryptedList.length} delegates using encrypted passphrases from config`,
);
for (const encryptedItem of encryptedList) {
let passphrase;
try {
passphrase = decryptPassphraseWithPassword(
parseEncryptedPassphrase(encryptedItem.encryptedPassphrase),
this.config.forging.defaultPassword,
);
} catch (error) {
const decryptionError = `Invalid encryptedPassphrase for publicKey: ${encryptedItem.publicKey}. ${error.message}`;
this.logger.error(decryptionError);
throw decryptionError;
}
const {
publicKeyBytes,
privateKeyBytes,
} = getPrivateAndPublicKeyBytesFromPassphrase(passphrase);
const keypair = {
publicKey: publicKeyBytes,
privateKey: privateKeyBytes,