-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathballot.js
More file actions
39 lines (33 loc) · 1.03 KB
/
ballot.js
File metadata and controls
39 lines (33 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const { generateKeyPairSync, createSign } = require('node:crypto');
const { Vote } = require('./vote.js');
const { Chain } = require('./chain.js');
class Ballot {
publicKey;
privateKey;
constructor(voterName) {
const {
publicKey,
privateKey,
} = generateKeyPairSync('rsa', {
modulusLength: 2048,
publicKeyEncoding: { type: 'spki', format: 'pem' },
privateKeyEncoding: { type: 'pkcs8', format: 'pem' },
});
this.privateKey = privateKey;
this.publicKey = publicKey;
this.voterName = voterName;
}
sendItem(item, voterPublicKey) {
const vote = new Vote(item, this.publicKey, voterPublicKey, this.voterName);
const sign = createSign('sha256');
sign.update(vote.toString()).end();
const signature = sign.sign(this.privateKey);
Chain.instance.addBlock(vote, this.publicKey, signature);
}
getVoterBallot() {
return this
}
}
module.exports = {
Ballot
}