bitagora-booth
Advanced tools
Comparing version 1.0.5 to 1.0.6
40
booth.js
@@ -1,2 +0,2 @@ | ||
const bitagoraVersion = '1.0.5'; | ||
const bitagoraVersion = '1.0.6'; | ||
const CryptoJS = require('crypto-js'); | ||
@@ -31,4 +31,4 @@ const Ecdsa = require('elliptic'); | ||
this.id = CryptoJS.SHA1(idToken).toString(); /* 20 bytes SHA1 hash of ID to guarantee that vote is cast only once */ | ||
this.options = getOptions(ctx.options); /* 6 bytes - if 2 options: "\xaa\xaa\x00\x01\xaa\xaa" */ | ||
this.questions = Bs58.decode(ctx.options.substr(0,4)).toString('hex') + Bs58.decode(ctx.options.substr(10,4)).toString('hex'); /* 6 bytes : 3 bytes option 1, 3 bytes option 2 decoded from Base58 and in hex */ | ||
this.options = getOptions(ctx.options.string); /* 6 bytes - if 2 options: "\xaa\xaa\x00\x01\xaa\xaa" */ | ||
this.questions = Bs58.decode(ctx.options.string.substr(0,4)).toString('hex') + Bs58.decode(ctx.options.string.substr(10,4)).toString('hex'); /* 6 bytes : 3 bytes option 1, 3 bytes option 2 decoded from Base58 and in hex */ | ||
this.ballot = 'ffff' + ballot + 'ffff'; /* 5 bytes with padding "\xFFFF" + "\x00" or "\x01" + "\xFFFF" */ | ||
@@ -122,4 +122,6 @@ this.idPartial = getIdPartial(userId.substr(15,8), ctx.idState); /* 3 bytes: 2 bytes partial ID number to guarantee partial ident and check */ | ||
/* Finally, check that the vote date is not earlier than the startDate or later than the endDate coded on the genesis block */ | ||
console.log("Validating vote"); | ||
console.log("Ballot"); | ||
var options = vote.options.replace(/a/g, '').match(/.{2}/g); | ||
console.log(options); | ||
var included = false; | ||
@@ -129,2 +131,3 @@ for (var i = 0; i < options.length; i++) { | ||
} | ||
console.log(vote.ballot); | ||
if (!included) { | ||
@@ -134,2 +137,4 @@ console.log('Invalid ballot'); | ||
} | ||
console.log("Id partial"); | ||
console.log(vote.idPartial); | ||
if (vote.idPartial == null) { | ||
@@ -139,7 +144,10 @@ console.log('No id partial'); | ||
} | ||
var checksum = CryptoJS.SHA256(CryptoJS.SHA256(vote.id + vote.options + vote.questions + vote.ballot + vote.idPartial + vote.date + vote.certTag + vote.certSig + vote.certKeyLength + vote.certKey ) ).toString().substr(0,6); | ||
console.log("Checksum"); | ||
var voteString = vote.id + vote.options + vote.questions + vote.ballot + vote.idPartial + vote.date + vote.certTag + vote.certSig + vote.certKeyLength + vote.certKey; | ||
var checksum = CryptoJS.SHA256(CryptoJS.SHA256(voteString)).toString().substr(0,6); | ||
if (checksum != vote.checkSum) { | ||
console.log('Invalid checksum'); | ||
return false; | ||
} | ||
} | ||
console.log("Certsig"); | ||
if (!validateCertSig(vote)) { | ||
@@ -149,2 +157,3 @@ console.log('Invalid certifier signature'); | ||
} | ||
console.log("SigVote"); | ||
if (!validateVoterSig(vote)) { | ||
@@ -188,3 +197,3 @@ console.log('Invalid voter signature'); | ||
var newVoteScript = getVoteScript(newVote); | ||
var privkey_hex = Bs58.decode(data.privKeyB58).toString("hex"); | ||
var privkey_hex = Bs58.decode(data.privKey).toString("hex"); | ||
var signature = signScript(newVoteScript, privkey_hex); | ||
@@ -213,4 +222,21 @@ var pubkey = EC.keyFromPrivate(privkey_hex, 'hex').getPublic(true, 'hex'); | ||
} | ||
}, | ||
parse: function(data, context) { | ||
console.log("Starting parse in booth.js"); | ||
// Data should be json object with data.voteHex and data.privKey | ||
console.log(data); | ||
console.log(context); | ||
if (data == null || context == null) return false; | ||
try { | ||
var ctx = new Context(context); | ||
/// Respond with a json object with vote data including : ballot and date of ballot | ||
/// It should also check that the ballot is correct with signatures, checksum, etc. | ||
return true; | ||
} catch(e) { | ||
console.log("Error"); | ||
console.log(e); | ||
return false; | ||
} | ||
} | ||
} | ||
{ | ||
"name": "bitagora-booth", | ||
"version": "1.0.5", | ||
"version": "1.0.6", | ||
"description": "Bitagora booth js functions", | ||
@@ -5,0 +5,0 @@ "main": "booth.js", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9771
217