Skip to content

Commit

Permalink
add script for private tally
Browse files Browse the repository at this point in the history
  • Loading branch information
dkijania committed Apr 7, 2021
1 parent c927ea6 commit a18a7a1
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 0 deletions.
56 changes: 56 additions & 0 deletions scripts/tally/private.sh
@@ -0,0 +1,56 @@
#!/usr/bin/env bash

set -exuo pipefail

export JORMUNGANDR_RESTAPI_URL=https://dryrun-servicing-station.vit.iohk.io/api

VOTE_PLAN_ID="$(jcli rest v0 vote active plans get --output-format json|jq -r '.[0].id')"

curl $JORMUNGANDR_RESTAPI_URL/v0/block0 > block0.bin

BLOCK0_HASH=$(jcli genesis hash --input block0.bin)
COMMITTEE_KEY=committee_1
MEMBER_SECRET_KEY=member_secret_key.sk

COMMITTEE_ADDR=$(jcli address account "$(jcli key to-public < "$COMMITTEE_KEY")")
COMMITTEE_ADDR_COUNTER=$(jcli rest v0 account get "$COMMITTEE_ADDR" --output-format json|jq -r .counter)

jcli "certificate" "new" "encrypted-vote-tally" "--vote-plan-id" "$VOTE_PLAN_ID" "--output" "encrypted-vote-tally.certificate"
jcli "transaction" "new" "--staging" "transaction.tx"
jcli "transaction" "add-account" "$COMMITTEE_ADDR" "0" "--staging" "transaction.tx"
jcli "transaction" "add-certificate" "$(< encrypted-vote-tally.certificate)" "--staging" "transaction.tx"
jcli "transaction" "finalize" "--staging" "transaction.tx"
jcli "transaction" "data-for-witness" "--staging" "transaction.tx" > encrypted-vote-tally.witness_data

jcli "transaction" "make-witness" "--genesis-block-hash" "$BLOCK0_HASH" "--type" "account" "--account-spending-counter" "$COMMITTEE_ADDR_COUNTER" "$(< encrypted-vote-tally.witness_data)" vote_tally.witness "$COMMITTEE_KEY"
jcli "transaction" "add-witness" "vote_tally.witness" "--staging" "transaction.tx"
jcli "transaction" "seal" "--staging" "transaction.tx"
jcli "transaction" "auth" "--staging" "transaction.tx" "--key" "$COMMITTEE_KEY"
jcli "transaction" "to-message" "--staging" "transaction.tx" > encrypted-vote-tally.fragment
jcli rest v0 message post --file encrypted-vote-tally.fragment

sleep 20

jcli rest v0 vote active plans get --output-format json > active_plans.json
COMMITTEE_ADDR_COUNTER=$(jcli rest v0 account get "$COMMITTEE_ADDR" --output-format json|jq -r .counter)


jcli "votes" "tally" "decryption-shares" "--vote-plan" "active_plans.json" "--vote-plan-id" "$VOTE_PLAN_ID" "--key" "$MEMBER_SECRET_KEY" > decryption_share.json

jcli "votes" "tally" "merge-shares" "decryption_share.json" > shares.json

jcli "votes" "tally" "decrypt-results" "--vote-plan" "active_plans.json" "--vote-plan-id" "$VOTE_PLAN_ID" "--shares" "shares.json" "--threshold" "1" "--output-format" "json" > result.json

jcli "certificate" "new" "vote-tally" "private" "--shares" "shares.json" "--vote-plan" "result.json" "--vote-plan-id" "$VOTE_PLAN_ID" --output "vote-tally.certificate"
jcli "transaction" "new" "--staging" "transaction.tx"
jcli "transaction" "add-account" "$COMMITTEE_ADDR" "0" "--staging" "transaction.tx"
jcli "transaction" "add-certificate" "$(< vote-tally.certificate)" "--staging" "transaction.tx"
jcli "transaction" "finalize" "--staging" "transaction.tx"
jcli "transaction" "data-for-witness" "--staging" "transaction.tx" > vote-tally.witness_data

jcli "transaction" "make-witness" "--genesis-block-hash" "$BLOCK0_HASH" "--type" "account" "--account-spending-counter" "$COMMITTEE_ADDR_COUNTER" "$(< vote-tally.witness_data)" vote_tally.witness "$COMMITTEE_KEY"
jcli "transaction" "add-witness" "vote_tally.witness" "--staging" "transaction.tx"
jcli "transaction" "seal" "--staging" "transaction.tx"
jcli "transaction" "auth" "--staging" "transaction.tx" "--key" "$COMMITTEE_KEY"
jcli "transaction" "to-message" "--staging" "transaction.tx" > vote-tally.fragment
jcli rest v0 message post --file vote-tally.fragment
File renamed without changes.

0 comments on commit a18a7a1

Please sign in to comment.