Skip to content

Commit

Permalink
fix/update equihash implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
lilyannehall committed Nov 18, 2024
1 parent e1b5000 commit d50475f
Show file tree
Hide file tree
Showing 6 changed files with 4,078 additions and 2,430 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
node_modules
proof.log
21 changes: 11 additions & 10 deletions lib/plugin-eclipse.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ class EclipseIdentity extends EventEmitter {
return new Promise((resolve, reject) => {
utils.eqsolve(
utils.hash256(this.pubkey),
constants.IDENTITY_DIFFICULTY
).then(proof => {
this.nonce = proof.nonce;
this.proof = proof.value;
constants.IDENTITY_DIFFICULTY.n,
constants.IDENTITY_DIFFICULTY.k
).then(solution => {
this.nonce = solution.nonce;
this.proof = solution.proof;
this.fingerprint = utils.hash160(this.proof);
resolve(this);
}, reject);
Expand All @@ -55,12 +56,12 @@ class EclipseIdentity extends EventEmitter {
* @returns {boolean}
*/
validate() {
return utils.eqverify(utils.hash256(this.pubkey), {
n: constants.IDENTITY_DIFFICULTY.n,
k: constants.IDENTITY_DIFFICULTY.k,
nonce: this.nonce,
value: this.proof
});
return utils.eqverify(utils.hash256(this.pubkey),
this.proof,
this.nonce,
constants.IDENTITY_DIFFICULTY.n,
constants.IDENTITY_DIFFICULTY.k
);
}

}
Expand Down
11 changes: 3 additions & 8 deletions lib/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const crypto = require('crypto');
const assert = require('assert');
const { randomBytes, createHash } = crypto;
const ms = require('ms');
//const equihash = require('equihash/lib/khovratovich'); // does not build on gcc-11 +
const equihash = require('@tacticalchihuahua/equihash');


/**
Expand Down Expand Up @@ -251,20 +251,15 @@ module.exports.hash256 = function(input) {
* @param {buffer} input - Input hash to solve
* @returns {Promise<EquihashProof>}
*/
module.exports.eqsolve = function() {
return Promise.reject(new Error('Equihash implementation is not functional'));
};
module.exports.eqsolve = equihash.solve;

/**
* Perform an equihash proof verification
* @param {buffer} input - Input hash for proof
* @param {buffer} proof - Equihash proof to verify
* @returns {boolean}
*/
module.exports.eqverify = function(/*input, proof*/) {
throw new Error('Equihash implementation is not functional');
// return equihash.verify(input, proof);
};
module.exports.eqverify = equihash.verify;

/**
* Returns the RMD-160 hash of the input
Expand Down
Loading

0 comments on commit d50475f

Please sign in to comment.