Socket
Socket
Sign inDemoInstall

bitagora-booth

Package Overview
Dependencies
Maintainers
1
Versions
178
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bitagora-booth - npm Package Compare versions

Comparing version 1.0.15 to 1.0.16

15

booth.js

@@ -1,2 +0,2 @@

const bitagoraBoothVersion = '1.0.14';
const bitagoraBoothVersion = '1.0.12';
const {

@@ -6,10 +6,7 @@ BITAGORA_URL, BITAGORA_PREFIX, BITAGORA_FAMILY, BITAGORA_VERSION

const {
setOptions, setQuestions, getPollAddress, getPrechecksumVote, requestState, getNodeList
setOptions, setQuestions, getPollAddress, getPrechecksumVote, requestState, getNodeList, _hash
} = require('./lib/functions.js');
const { validateVote } = require('./lib/validate.js');
const Ecdsa = require('elliptic');
const EC = Ecdsa.ec('secp256k1');
const BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
const Bs58 = require('base-x')(BASE58);
const crypto = require('crypto');
const { Secp256k1PrivateKey, Secp256k1PublicKey } = require('sawtooth-sdk/signing/secp256k1');

@@ -21,3 +18,2 @@ const { protobuf } = require('sawtooth-sdk');

const today = new Date();
const _hash = (sha, x) => crypto.createHash(sha).update(x).digest('hex').toLowerCase();

@@ -43,4 +39,7 @@ class Vote {

if (!Boolean(data.id)) {
let privkey_hex = Bs58.decode(data.privkey).toString('hex');
data.id = EC.keyFromPrivate(privkey_hex, 'hex').getPublic(true, 'hex');
const privkey_hex = Bs58.decode(data.privkey).toString('hex');
const privateKey = Secp256k1PrivateKey.fromHex(privkey_hex);
const factory = new CryptoFactory(signerContext);
const signer = factory.newSigner(privateKey);
const data.id = signer.getPublicKey().asHex();
}

@@ -47,0 +46,0 @@ if (!Boolean(data.poll) || !Boolean(data.id)) throw 'No data';

@@ -5,10 +5,10 @@ const BITAGORA_FAMILY = 'bitagora-ballots';

const BITAGORA_VERSION = '0.1';
const BITAGORA_URL = 'http://bitagora.cc';
const BITAGORA_URL = 'https://bitagora.cc';
module.exports = {
BITAGORA_FAMILY,
BITAGORA_POLL_FAMILY,
BITAGORA_PREFIX,
BITAGORA_VERSION,
BITAGORA_URL
BITAGORA_FAMILY,
BITAGORA_POLL_FAMILY,
BITAGORA_PREFIX,
BITAGORA_VERSION,
BITAGORA_URL
}

@@ -1,2 +0,4 @@

const { BITAGORA_URL, BITAGORA_PREFIX, BITAGORA_FAMILY, BITAGORA_VERSION } = require('./constants');
const {
BITAGORA_URL, BITAGORA_PREFIX, BITAGORA_FAMILY, BITAGORA_VERSION
} = require('./constants');
const crypto = require('crypto');

@@ -8,5 +10,3 @@ const atob = require('atob');

const _hash = (sha, x) => crypto.createHash(sha).update(x).digest('hex').toLowerCase();
const _hexToB64 = (str) => btoa(String.fromCharCode.apply(null,str.replace(/\r|\n/g, "").replace(/([\da-fA-F]{2}) ?/g, "0x$1 ").replace(/ +$/, "").split(" ")));
const _B64ToHex = (str) => {

@@ -21,3 +21,2 @@ for (var i = 0, bin = atob(str.replace(/[ \r\n]+$/, "")), hex = []; i < bin.length; ++i) {

function getPrechecksumVote(vote) {

@@ -126,48 +125,5 @@ return vote.prefix + vote.id + vote.date + vote.poll + vote.questions + vote.options + emptyBallot();

function requestPolls(cb) {
try {
let api = process.env.API_URL;
if (api === undefined) api = BITAGORA_URL + ":8008";
const request = require('request');
request.get({
url: `${api}/state`,
body: '',
headers: { 'Content-Type': 'application/json'}
},
(err, response) => {
try {
if (err) {
throw 'Error';
} else {
if (!Boolean(response.body)) throw 'No response';
let json = JSON.parse(response.body);
if (!Boolean(json.data)) throw 'No data';
let data = cbor.decode(Buffer.from(json.data, 'base64'));
if (!Boolean(data)) throw 'No data';
let polls = [];
let n = 0;
for (var i; i<data.length;i++) {
if (data[i].substr(0,6) == BITAGORA_PREFIX) {
polls[n] = data[i].substr(10,8);
n = n + 1;
}
}
if (n>0) {
cb({'status': 'FOUND', 'polls': polls });
} else {
cb({'status': 'UNKNOWN' });
}
}
} catch(e) {
cb({ status: 'ERROR' });
}
});
} catch(e) {
cb({ status: 'ERROR' });
}
}
function getNodeList(cb) {
const request = require('request');
let address = BITAGORA_URL + '/nodes/list.json';
const address = BITAGORA_URL + '/nodes/list.json';
request.get({

@@ -182,5 +138,5 @@ url: address,

if (!Boolean(response.body)) throw 'No response';
let nodes = JSON.parse(response.body);
const nodes = JSON.parse(response.body);
if (!Boolean(nodes)) throw 'No data';
let apis = nodes.map(function(api) {
const apis = nodes.map(function(api) {
return 'http://' + api + ':8008';

@@ -255,3 +211,3 @@ });

if (process.env.API_URL !== undefined) apis.unshift(process.env.API_URL);
let address = getPollAddress(pollId);
const address = getPollAddress(pollId);
requestStateFromAPIs(address, apis)

@@ -264,4 +220,2 @@ });

module.exports = {

@@ -278,3 +232,4 @@ getPollAddress,

getPrechecksumVote,
getNodeList
getNodeList,
_hash
}
'use strict'
const { getPollAddress } = require('./functions');
const { getPollAddress, _hash } = require('./functions');
const cbor = require('cbor');
const crypto = require('crypto');
const _hash = (sha, x) => crypto.createHash(sha).update(x).digest('hex').toLowerCase();
class PollState {
constructor (context) {
constructor (context) {
this.context = context

@@ -11,0 +9,0 @@ this.timeout = 500

'use strict';
const { BITAGORA_PREFIX } = require('./constants');
const {
getOptions, setOptions, getQuestions, getPollAddress, getVoteToken, getPollToken, emptyBallot, getPrechecksumVote
_hash, getOptions, setOptions, getQuestions, getPollAddress, getVoteToken, getPollToken, emptyBallot, getPrechecksumVote
} = require('./functions');
const crypto = require('crypto');
const { Secp256k1PublicKey } = require('sawtooth-sdk/signing/secp256k1');
/*
const Ecdsa = require('elliptic');
const EC = Ecdsa.ec('secp256k1');
*/
const today = new Date();
const _hash = (sha, x) => crypto.createHash(sha).update(x).digest('hex').toLowerCase();

@@ -40,2 +41,5 @@ function validatePoll(poll) {

if (!Boolean(certKey)) return false;
console.log("Validating signature with new algorithm");
return Secp256k1PublicKey.verify(self, vote.certsig, certScript, certKey);
/*
var pubPoint = EC.keyFromPublic(certKey, 'hex').getPublic();

@@ -49,2 +53,3 @@ var x = pubPoint.getX().toString('hex');

return key.verify(certScript, vote.certsig);
*/
} catch(e) {

@@ -66,3 +71,2 @@ return false;

if ( parseInt(timestamp) > parseInt(poll.ends)) return false;
console.log("Passed date tests");
if (vote.poll != poll.id) return false;

@@ -69,0 +73,0 @@ /* Check that the ballot corresponds to one of the options in the election and that options and questions are well formed */

{
"name": "bitagora-booth",
"version": "1.0.15",
"version": "1.0.16",
"description": "Bitagora booth",

@@ -25,3 +25,2 @@ "main": "booth.js",

"crypto-js": "^3.1.9-1",
"elliptic": "^6.4.0",
"request": "^2.8.1",

@@ -28,0 +27,0 @@ "async": "^2.6.0",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc