Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
delegateList: string[],
): ReadonlyArray => {
// tslint:disable-next-line no-let
let hashedRound = hash(round, 'utf8');
const list = [...delegateList];
const numberOfDelegates = delegateList.length;
// tslint:disable-next-line
for (let i = 0; i < numberOfDelegates; i++) {
// tslint:disable-next-line
for (let j = 0; j < 4 && i < numberOfDelegates; i++, j++) {
const newIndex = hashedRound[j] % numberOfDelegates;
const temp = list[newIndex];
list[newIndex] = list[i];
list[i] = temp;
}
hashedRound = hash(hashedRound, 'utf8');
}
return list;
};
export const generateDelegateList = (
round: string,
delegateList: string[],
): ReadonlyArray => {
// tslint:disable-next-line no-let
let hashedRound = hash(round, 'utf8');
const list = [...delegateList];
const numberOfDelegates = delegateList.length;
// tslint:disable-next-line
for (let i = 0; i < numberOfDelegates; i++) {
// tslint:disable-next-line
for (let j = 0; j < 4 && i < numberOfDelegates; i++, j++) {
const newIndex = hashedRound[j] % numberOfDelegates;
const temp = list[newIndex];
list[newIndex] = list[i];
list[i] = temp;
}
hashedRound = hash(hashedRound, 'utf8');
}
return list;
};
const createSignatureObject = (txBuffer, account) => ({
// publicKey: account.publicKey,
signature: signData(
hash(Buffer.concat([hexToBuffer(networkIdentifier), txBuffer])),
account.passphrase,
),
});
signature: string,
transaction: TransactionJSON,
isSecondSignature: boolean = false,
): VerifyReturn => {
const {
signature: removedSignature,
signSignature,
...strippedTransaction
} = transaction;
// If transaction includes asset data, include those bytes
const transactionBytes =
transaction.asset && Object.keys(transaction.asset).length
? getTransactionBytes(strippedTransaction as TransactionJSON)
: getBytes(transaction, !isSecondSignature);
const transactionHash = cryptography.hash(transactionBytes);
const verified = cryptography.verifyData(
transactionHash,
signature,
publicKey,
);
return {
verified,
error: !verified
? new TransactionError(
`Failed to verify signature ${signature}`,
transaction.id,
'.signature',
)
: undefined,
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,
};
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,
};
'b92e223981770c716ee54192a0ad028639d28d41221b72e455447bc4767aeb94caff2242b740a733daa3f3f96fc1592303b60c1704a8ac626e2704da039f41ee',
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
}
if (!transaction.id) {
throw new Error('Transaction ID is required to create a signature object.');
}
// tslint:disable-next-line variable-name
const TransactionClass = transactionMap[transaction.type];
const tx = new TransactionClass(transaction) as BaseTransaction;
const validStatus = tx.validate();
if (validStatus.errors.length > 0) {
throw new Error('Invalid transaction.');
}
const { publicKey } = cryptography.getPrivateAndPublicKeyFromPassphrase(
passphrase,
);
// tslint:disable-next-line no-any
(tx as any)._signature = undefined;
// tslint:disable-next-line no-any
(tx as any)._signSignature = undefined;
const multiSignature = cryptography.signData(
cryptography.hash(tx.getBytes()),
passphrase,
);
return {
transactionId: tx.id,
publicKey,
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 chainStateBuilder = new ChainStateBuilder(
genesisBlock,
initialAccountsState,