From 5ea852d3696847844b6c043f5a393adec4d8df0d Mon Sep 17 00:00:00 2001 From: Matt Date: Wed, 30 Apr 2014 20:43:43 -0600 Subject: [PATCH] Added client-side mining key generation script for coin-switching port mining --- libs/paymentProcessor.js | 5 +- libs/website.js | 99 +- website/key.html | 2798 +++++++++++++++++++++++++++++++++ website/pages/mining_key.html | 25 + 4 files changed, 2923 insertions(+), 4 deletions(-) create mode 100644 website/key.html create mode 100644 website/pages/mining_key.html diff --git a/libs/paymentProcessor.js b/libs/paymentProcessor.js index 6e05767..638c64d 100644 --- a/libs/paymentProcessor.js +++ b/libs/paymentProcessor.js @@ -502,7 +502,8 @@ function SetupForPool(logger, poolOptions, setupFinished){ } })(); movePendingCommands.push(['smove', coin + '_blocksPending', coin + destinationSet, r.serialized]); - roundsToDelete.push(coin + '_shares:round' + r.height) + if (r.category === 'generate') + roundsToDelete.push(coin + '_shares:round' + r.height) }); var finalRedisCommands = []; @@ -660,7 +661,7 @@ function SetupForPool(logger, poolOptions, setupFinished){ daemon.cmd('sendmany', [processingConfig.feeCollectAccount, withdrawal], function(results){ if (results[0].error){ - logger.debug(logSystem, logComponent, 'Profit withdrawal finished - error with sendmany ' + logger.debug(logSystem, logComponent, 'Profit withdrawal of ' + withdrawalAmount + ' failed - error with sendmany ' + JSON.stringify(results[0].error)); return; } diff --git a/libs/website.js b/libs/website.js index 6ac1962..3af59c5 100644 --- a/libs/website.js +++ b/libs/website.js @@ -3,18 +3,24 @@ var fs = require('fs'); var path = require('path'); var async = require('async'); +var watch = require('node-watch'); +var redis = require('redis'); + var dot = require('dot'); var express = require('express'); var bodyParser = require('body-parser'); var compress = require('compression'); -var watch = require('node-watch'); +var Stratum = require('stratum-pool'); +var util = require('stratum-pool/lib/util.js'); var api = require('./api.js'); module.exports = function(logger){ + dot.templateSettings.strip = false; + var portalConfig = JSON.parse(process.env.portalConfig); var poolConfigs = JSON.parse(process.env.pools); @@ -33,7 +39,8 @@ module.exports = function(logger){ 'stats.html': 'stats', 'tbs.html': 'tbs', 'api.html': 'api', - 'admin.html': 'admin' + 'admin.html': 'admin', + 'mining_key.html': 'mining_key' }; var pageTemplates = {}; @@ -41,6 +48,9 @@ module.exports = function(logger){ var pageProcessed = {}; var indexesProcessed = {}; + var keyScriptTemplate = ''; + var keyScriptProcessed = ''; + var processTemplates = function(){ @@ -113,6 +123,87 @@ module.exports = function(logger){ setInterval(buildUpdatedWebsite, websiteConfig.stats.updateInterval * 1000); + var buildKeyScriptPage = function(){ + async.waterfall([ + function(callback){ + var client = redis.createClient(portalConfig.redis.port, portalConfig.redis.host); + client.hgetall('coinVersionBytes', function(err, coinBytes){ + if (err){ + client.quit(); + return callback('Failed grabbing coin version bytes from redis ' + JSON.stringify(err)); + } + callback(null, client, coinBytes || {}); + }); + }, + function (client, coinBytes, callback){ + var enabledCoins = Object.keys(poolConfigs).map(function(c){return c.toLowerCase()}); + var missingCoins = []; + enabledCoins.forEach(function(c){ + if (!(c in coinBytes)) + missingCoins.push(c); + }); + callback(null, client, coinBytes, missingCoins); + }, + function(client, coinBytes, missingCoins, callback){ + var coinsForRedis = {}; + async.each(missingCoins, function(c, cback){ + var coinInfo = (function(){ + for (var pName in poolConfigs){ + if (pName.toLowerCase() === c) + return { + daemon: poolConfigs[pName].shareProcessing.internal.daemon, + address: poolConfigs[pName].address + } + } + })(); + var daemon = new Stratum.daemon.interface([coinInfo.daemon]); + daemon.cmd('dumpprivkey', [coinInfo.address], function(result){ + if (result[0].error){ + logger.error(logSystem, 'daemon', 'Could not dumpprivkey for ' + c + ' ' + JSON.stringify(result[0].error)); + cback(); + return; + } + + var vBytePub = util.getVersionByte(coinInfo.address)[0]; + var vBytePriv = util.getVersionByte(result[0].response)[0]; + + coinBytes[c] = vBytePub.toString() + ',' + vBytePriv.toString(); + coinsForRedis[c] = coinBytes[c]; + cback(); + }); + }, function(err){ + callback(null, client, coinBytes, coinsForRedis); + }); + }, + function(client, coinBytes, coinsForRedis, callback){ + if (Object.keys(coinsForRedis).length > 0){ + client.hmset('coinVersionBytes', coinsForRedis, function(err){ + if (err) + logger.error(logSystem, 'Init', 'Failed inserting coin byte version into redis ' + JSON.stringify(err)); + client.quit(); + }); + } + else{ + client.quit(); + } + callback(null, coinBytes); + } + ], function(err, coinBytes){ + if (err){ + logger.error(logSystem, 'Init', err); + return; + } + try{ + keyScriptTemplate = dot.template(fs.readFileSync('website/key.html', {encoding: 'utf8'})); + keyScriptProcessed = keyScriptTemplate({coins: coinBytes}); + } + catch(e){ + logger.error(logSystem, 'Init', 'Failed to read key.html file'); + } + }); + + }; + buildKeyScriptPage(); var getPage = function(pageId){ if (pageId in pageProcessed){ @@ -147,6 +238,10 @@ module.exports = function(logger){ next(); }); + app.get('/key.html', function(reg, res, next){ + res.end(keyScriptProcessed); + }); + app.get('/:page', route); app.get('/', route); diff --git a/website/key.html b/website/key.html new file mode 100644 index 0000000..9978e9e --- /dev/null +++ b/website/key.html @@ -0,0 +1,2798 @@ + + + + + + Mining Key Script + + + + + + + + +
+

Mining key generation or input options:

+ +
+
1)
+
Create new private key
+ +
+
- or-
+
+
2)
+
Import existing private key
+ +
+
- or-
+
+
3)
+
Input private key hex
+ + +
Private key must be 64 hexadecimal characters
+
+
+ +
+ + + +
+
NO NOT LOSE THIS PRIVATE KEY. Any coins mined using this public key can + only be controlled with this private key.
+ +
Private key:
+
Key for mining (hashed public key):
+ +

+ An address for any type of coin can be derived from this mining key - and each of those coin address + can only be controlled by this private key. +

+ +
+ +
+
Backup your private key
+ + + + + + + + + +
Step 1) + +
Step 2) + +
+
+ +
+
Coin formatted keys
+ + +
Public address
+ + +
Private key in wallet import format
+ + +
+
How to import your private key for :
+
    +
  1. Open your wallet app
  2. +
  3. Go to Help -> click Debug window -> click Console tab
  4. +
  5. Enter the following command: importprivkey
  6. +
+
+ +
+ + +
+ + + + + + + + + \ No newline at end of file diff --git a/website/pages/mining_key.html b/website/pages/mining_key.html new file mode 100644 index 0000000..d380676 --- /dev/null +++ b/website/pages/mining_key.html @@ -0,0 +1,25 @@ + + +
+ +

+ This script run client-side (in your browser). For maximum security download the script and run it locally and + offline in a modern web browser. +

+ + + +