-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for synchronized proof-of-work challenge nonce across n…
…odes (#103) Added support for synchronized proof-of-work challenge nonce across nodes by: - Added a seed for proof-of-work to allow deterministic challenge nonce generation. - Allowed for slight server clock drift. With this PR, the registration endpoint with proof-of-work is now ready to be used in a production environment with many nodes.
- Loading branch information
1 parent
c4a46c0
commit f16e915
Showing
13 changed files
with
155 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,38 @@ | ||
import { expect } from 'chai'; | ||
|
||
import type { DwnServerConfig } from '../src/config.js'; | ||
import { config } from '../src/config.js'; | ||
import { DwnServer } from '../src/dwn-server.js'; | ||
import { randomBytes } from 'crypto'; | ||
|
||
describe('DwnServer', function () { | ||
let dwnServer: DwnServer; | ||
const dwnServerConfig = { ...config }; | ||
|
||
before(async function () { | ||
dwnServer = new DwnServer({ config }); | ||
// NOTE: using SQL to workaround an issue where multiple instances of DwnServer can be started using LevelDB in the same test run, | ||
// and dwn-server.spec.ts already uses LevelDB. | ||
dwnServerConfig.messageStore = 'sqlite://'; | ||
dwnServerConfig.dataStore = 'sqlite://'; | ||
dwnServerConfig.eventLog = 'sqlite://'; | ||
}); | ||
|
||
after(async function () { | ||
dwnServer.stop(() => console.log('server stop')); | ||
}); | ||
|
||
it('should create an instance of DwnServer', function () { | ||
expect(dwnServer).to.be.an.instanceOf(DwnServer); | ||
}); | ||
it('should initialize ProofOfWorkManager with challenge nonce seed if given.', async function () { | ||
const registrationProofOfWorkSeed = randomBytes(32).toString('hex'); | ||
const configWithProofOfWorkSeed: DwnServerConfig = { | ||
...dwnServerConfig, | ||
registrationStoreUrl: 'sqlite://', | ||
registrationProofOfWorkEnabled: true, | ||
registrationProofOfWorkSeed | ||
}; | ||
|
||
it('should start the server and listen on the specified port', async function () { | ||
const dwnServer = new DwnServer({ config: configWithProofOfWorkSeed }); | ||
await dwnServer.start(); | ||
const response = await fetch('http://localhost:3000', { | ||
method: 'GET', | ||
}); | ||
expect(response.status).to.equal(200); | ||
}); | ||
expect(dwnServer.registrationManager['proofOfWorkManager']['challengeSeed']).to.equal(registrationProofOfWorkSeed); | ||
|
||
it('should stop the server', async function () { | ||
dwnServer.stop(() => console.log('server Stop')); | ||
// Add an assertion to check that the server has been stopped | ||
expect(dwnServer.httpServer.listening).to.be.false; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.