Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
}
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,
config.forging.secret.forEach(secret => {
console.info('.......');
config.forging.delegates.push({
encryptedPassphrase: stringifyEncryptedPassphrase(
encryptPassphraseWithPassword(secret, password)
),
publicKey: getPrivateAndPublicKeyFromPassphrase(secret).publicKey,
});
});
config.forging.secret.forEach(secret => {
console.info('.......');
config.forging.delegates.push({
encryptedPassphrase: stringifyEncryptedPassphrase(
encryptPassphraseWithPassword(secret, password)
),
publicKey: getPrivateAndPublicKeyFromPassphrase(secret).publicKey,
});
});
const getPacketCredentials = () => {
const passphrase = Mnemonic.generateMnemonic();
const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
passphrase
);
const credentials = {
address: cryptography.getAddressFromPublicKey(keys.publicKey),
passphrase: passphrase,
publicKey: keys.publicKey,
privateKey: keys.privateKey
};
return credentials;
};
const getPacketCredentials = () => {
const passphrase = Mnemonic.generateMnemonic();
const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
passphrase
);
const credentials = {
address: cryptography.getAddressFromPublicKey(keys.publicKey),
passphrase: passphrase,
publicKey: keys.publicKey,
privateKey: keys.privateKey
};
return credentials;
};
export const signRawTransaction = ({
transaction,
passphrase,
secondPassphrase,
timeOffset,
}: SignRawTransactionInput): TransactionJSON => {
const {
publicKey,
address,
} = cryptography.getAddressAndPublicKeyFromPassphrase(passphrase);
const senderSecondPublicKey = secondPassphrase
? cryptography.getPrivateAndPublicKeyFromPassphrase(secondPassphrase)
.publicKey
: undefined;
const propertiesToAdd = {
senderPublicKey: publicKey,
senderSecondPublicKey,
senderId: address,
timestamp: getTimeWithOffset(timeOffset),
};
const transactionWithProperties = {
...transaction,
...propertiesToAdd,
};
return prepareTransaction(
static createAccount() {
const passphrase = Mnemonic.generateMnemonic();
const keys = getPrivateAndPublicKeyFromPassphrase(passphrase);
const address = getAddressFromPrivateKey(keys.privateKey);
return {
passphrase,
privateKey: keys.privateKey,
publicKey: keys.publicKey,
address,
balance: '0',
};
}
}
const getPacketCredentials = () => {
const passphrase = Mnemonic.generateMnemonic();
const keys = cryptography.getPrivateAndPublicKeyFromPassphrase(
passphrase
);
const credentials = {
address: cryptography.getAddressFromPublicKey(keys.publicKey),
passphrase: passphrase,
publicKey: keys.publicKey,
privateKey: keys.privateKey
};
return credentials;
};