Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export const delegates: any = secrets.map(secret => {
const publicKey = crypto.getKeys(secret).publicKey;
const address = crypto.getAddress(publicKey);
const balance = genesisTransactions.find(
transaction => transaction.recipientId === address && transaction.type === 0,
).amount;
return {
secret,
passphrase: secret, // just an alias for delegate secret
publicKey,
address,
balance,
};
});
async revertBlock (block) {
let delegate = this.getWalletByPublicKey(block.data.generatorPublicKey)
if (!delegate) {
const generator = crypto.getAddress(block.data.generatorPublicKey, config.network.pubKeyHash)
delegate = new Wallet(generator)
delegate.publicKey = block.data.generatorPublicKey
this.reindex(delegate)
}
const revertedTransactions = []
try {
// TODO Use Promise.all or explain why not
// - Promise.each is applied sequentially
// - Promise.all is applied in parallel
await Promise.each(block.transactions, async (transaction) => {
await this.revertTransaction(transaction)
async verifyTransaction(transaction) {
const senderId = crypto.getAddress(
transaction.data.senderPublicKey,
config.network.pubKeyHash,
)
const sender = this.walletManager.findByAddress(senderId) // should exist
if (!sender.publicKey) {
sender.publicKey = transaction.data.senderPublicKey
this.walletManager.reindex(sender)
}
const dbTransaction = await this.getTransaction(transaction.data.id)
return sender.canApply(transaction.data, []) && !dbTransaction
}
public async run(): Promise {
await this.initialize(TransferCommand);
const primaryAddress = crypto.getAddress(
crypto.getKeys(this.config.passphrase).publicKey,
this.config.network.version,
);
let wallets = this.options.wallets;
if (wallets === undefined) {
wallets = this.generateWallets();
}
logger.info(`Sending ${wallets.length} transfer ${pluralize("transaction", wallets.length)}`);
const walletBalance = await this.getWalletBalance(primaryAddress);
if (!this.options.skipValidation) {
logger.info(`Sender starting balance: ${satoshiToArk(walletBalance)}`);
}
module.exports = (quantity = 1, config) => {
let wallets = []
for (let i = 0; i < quantity; i++) {
const passphrase = bip39.generateMnemonic()
const keys = crypto.getKeys(passphrase)
const address = crypto.getAddress(keys.publicKey, config.publicKeyHash)
wallets.push({ address, keys, passphrase })
}
const testWalletsPath = path.resolve(__dirname, '../../test-wallets')
for (const wallet of wallets) {
fs.appendFileSync(testWalletsPath, `${wallet.address}: ${wallet.passphrase}\n`)
}
fs.appendFileSync(testWalletsPath, `${'-'.repeat(80)}\n`)
return wallets
}
const transactions = rows.map(row => {
const transaction = Transaction.deserialize(
row.serialized.toString('hex'),
)
transaction.blockId = row.block_id
transaction.senderId = crypto.getAddress(transaction.senderPublicKey)
return transaction
})
module.exports = model => {
const data = new Transaction(model.serialized.toString('hex'))
return {
id: data.id,
blockid: model.blockId,
type: data.type,
timestamp: model.timestamp || data.timestamp,
amount: +bignumify(data.amount).toFixed(),
fee: +bignumify(data.fee).toFixed(),
recipientId: data.recipientId,
senderId: crypto.getAddress(
data.senderPublicKey,
config.network.pubKeyHash,
),
senderPublicKey: data.senderPublicKey,
vendorField: data.vendorField,
signature: data.signature,
signSignature: data.signSignature,
signatures: data.signatures,
asset: data.asset || {},
confirmations: model.block
? blockchain.getLastBlock().data.height - model.block.height
: 0,
}
}
static generate (pubKeyHash, language) {
const passphrase = bip39.generateMnemonic(null, null, bip39.wordlists[language])
const publicKey = crypto.getKeys(this.normalizePassphrase(passphrase)).publicKey
return {
address: crypto.getAddress(publicKey, pubKeyHash),
passphrase
}
}
static getAddress (passphrase, pubKeyHash) {
const publicKey = crypto.getKeys(this.normalizePassphrase(passphrase)).publicKey
return crypto.getAddress(publicKey, pubKeyHash)
}
async method(params) {
try {
const { keys, wif } = await getBIP38Wallet(params.userId, params.bip38)
return {
publicKey: keys.publicKey,
address: crypto.getAddress(keys.publicKey),
wif,
}
} catch (error) {
const { publicKey, privateKey } = crypto.getKeys(bip39.generateMnemonic())
const encryptedWIF = bip38.encrypt(
Buffer.from(privateKey, 'hex'),
true,
params.bip38 + params.userId,
)
await database.set(
utils.sha256(Buffer.from(params.userId)).toString('hex'),
encryptedWIF,
)
const { wif } = decryptWIF(encryptedWIF, params.userId, params.bip38)