diff --git a/src/config/constants.js b/src/config/constants.js index aba2c63..4234b25 100644 --- a/src/config/constants.js +++ b/src/config/constants.js @@ -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, diff --git a/src/core/identity.js b/src/core/identity.js index 0c64857..75594d6 100644 --- a/src/core/identity.js +++ b/src/core/identity.js @@ -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++; } diff --git a/src/core/security.js b/src/core/security.js index 9544583..62eed00 100644 --- a/src/core/security.js +++ b/src/core/security.js @@ -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) => {