Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const generateBlockHeader = ({
delegateName,
height,
maxHeightPreviouslyForged,
maxHeightPrevoted,
delegateMinHeightActive,
}) => {
const delegatePublicKey = getKeys(delegateName).publicKey;
// Generate a deterministic block id from a block height
const blockId = BigNum.fromBuffer(
hash(height.toString(), 'utf8').slice(0, 8),
).toString();
return {
blockId,
height,
maxHeightPreviouslyForged,
delegatePublicKey,
delegateMinHeightActive,
maxHeightPrevoted,
};
};
txMap,
version,
epochTime,
lastBlock,
rewards,
transactions,
passphrase,
}: CreateBlockInput): Block => {
const sortedTransactions = sortTransactions(
transactions as TransactionJSON[],
);
const height = lastBlock.height + 1;
const txs = rawTransactionToInstance(txMap, sortedTransactions);
const reward = calculateRewawrd(rewards, height);
const timestamp = getTimeFromBlockchainEpoch(epochTime);
const { publicKey } = getKeys(passphrase);
const rawBlock = {
version,
height,
previousBlock: lastBlock.id,
timestamp,
reward,
// Calculate tx related property
...calculateTransactionsData(txs),
transactions: sortedTransactions,
generatorPublicKey: publicKey,
};
// Get reward
const block = new Block(rawBlock, txs);
block.sign(passphrase);
return block;
const createAccount = (): AccountInfo => {
const passphrase = createMnemonicPassphrase();
const { privateKey, publicKey } = getKeys(passphrase);
const address = getAddressFromPublicKey(publicKey);
return {
passphrase,
privateKey,
publicKey,
address,
};
};
).balance = parseInt(
new BigNum(senderBalance.toString()).sub(amount).toString(),
10,
);
resultingAccountState.find(
account => account.address === accounts.existingDelegate.address,
).balance = parseInt(
new BigNum(recipientBalance.toString()).plus(amount).toString(),
10,
);
const secondSignature =
'erupt sponsor rude supreme vacant delay salute allow laundry swamp curve brain';
const { publicKey } = getKeys(secondSignature);
const secondPassphraseObject = {
timestamp,
senderPublicKey: accounts.existingDelegate.publicKey,
asset: {
signature: {
publicKey,
},
},
};
const secondPassphraseTx = new SecondSignatureTransaction(
secondPassphraseObject,
);
secondPassphraseTx.sign(accounts.existingDelegate.passphrase);
const blockWithSecondSignatureRegistered = createBlock(
const processInput = ({ passphrase }: { readonly passphrase?: string }) => {
if (!passphrase) {
throw new ValidationError('Passphrase cannot be empty');
}
const { privateKey, publicKey } = getKeys(passphrase);
const address = getAddressFromPublicKey(publicKey);
return {
privateKey,
publicKey,
address,
};
};
if (!password) {
throw new ValidationError('No password was provided');
}
const encryptedPassphraseObject = encryptPassphraseWithPassword(
passphrase,
password,
);
const encryptedPassphrase = stringifyEncryptedPassphrase(
encryptedPassphraseObject,
);
return outputPublicKey
? {
encryptedPassphrase,
publicKey: getKeys(passphrase).publicKey,
}
: { encryptedPassphrase };
};
export const registerSecondPassphrase = (
inputs: SecondPassphraseInputs,
): Partial => {
validateInputs(inputs);
const { passphrase, secondPassphrase, networkIdentifier } = inputs;
const { publicKey } = getKeys(secondPassphrase);
const transaction = {
...createBaseTransaction(inputs),
type: 9,
asset: { publicKey },
networkIdentifier,
};
if (!passphrase) {
return transaction;
}
const secondSignatureTransaction = new SecondSignatureTransaction(
transaction as TransactionJSON,
);
secondSignatureTransaction.sign(passphrase);
export const prepareTransaction = (
partialTransaction: PartialTransaction,
passphrase?: string,
secondPassphrase?: string,
timeOffset?: number,
): TransactionJSON => {
const senderPublicKey = passphrase
? cryptography.getKeys(passphrase).publicKey
: undefined;
const timestamp = getTimeWithOffset(timeOffset);
const transaction = {
amount: '0',
recipientId: '',
senderPublicKey,
timestamp,
...partialTransaction,
};
if (!validTransaction(transaction)) {
throw new Error('Invalid transaction to process');
}
if (!passphrase) {