mirror of
https://github.com/lklynet/hypermind.git
synced 2026-05-03 17:40:29 +00:00
Merge pull request #16 from ricardoboss/feature/pow-upgrade
feat: allow gradual increase of POW
This commit is contained in:
@@ -9,9 +9,12 @@ const TOPIC = crypto.createHash("sha256").update(TOPIC_NAME).digest();
|
||||
*
|
||||
* I ran it that way and I was fairly isolated, with hundreds of failed POW, shame.
|
||||
* adding an extra 0 makes it very expensive on attacker to make it worth the fun for them, so maybe consider it.
|
||||
*
|
||||
* ----
|
||||
* ricardoboss: added a way to get the best of both worlds: newer nodes will use a harder POW, making them compatible
|
||||
* with others who use a harder POW while still being able to accept "old" POWs from clients
|
||||
*/
|
||||
const POW_PREFIX = "0000";
|
||||
const MY_POW_PREFIX = "00000";
|
||||
const VERIFICATION_POW_PREFIX = "0000";
|
||||
|
||||
const MAX_PEERS = parseInt(process.env.MAX_PEERS) || 1000000;
|
||||
const MAX_MESSAGE_SIZE = 2048;
|
||||
@@ -28,7 +31,8 @@ const PORT = process.env.PORT || 3000;
|
||||
module.exports = {
|
||||
TOPIC_NAME,
|
||||
TOPIC,
|
||||
POW_PREFIX,
|
||||
MY_POW_PREFIX,
|
||||
VERIFICATION_POW_PREFIX,
|
||||
MAX_PEERS,
|
||||
MAX_MESSAGE_SIZE,
|
||||
MAX_RELAY_HOPS,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const crypto = require("crypto");
|
||||
const { POW_PREFIX } = require("../config/constants");
|
||||
const { MY_POW_PREFIX } = require("../config/constants");
|
||||
|
||||
const generateIdentity = () => {
|
||||
const { publicKey, privateKey } = crypto.generateKeyPairSync("ed25519");
|
||||
@@ -11,7 +11,7 @@ const generateIdentity = () => {
|
||||
.createHash("sha256")
|
||||
.update(id + nonce)
|
||||
.digest("hex");
|
||||
if (hash.startsWith(POW_PREFIX)) break;
|
||||
if (hash.startsWith(MY_POW_PREFIX)) break;
|
||||
nonce++;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
const crypto = require("crypto");
|
||||
const { POW_PREFIX } = require("../config/constants");
|
||||
const { VERIFICATION_POW_PREFIX } = require("../config/constants");
|
||||
|
||||
const verifyPoW = (id, nonce) => {
|
||||
if (!nonce) return false;
|
||||
@@ -7,7 +7,7 @@ const verifyPoW = (id, nonce) => {
|
||||
.createHash("sha256")
|
||||
.update(id + nonce)
|
||||
.digest("hex");
|
||||
return powHash.startsWith(POW_PREFIX);
|
||||
return powHash.startsWith(VERIFICATION_POW_PREFIX);
|
||||
}
|
||||
|
||||
const signMessage = (message, privateKey) => {
|
||||
|
||||
Reference in New Issue
Block a user