I can already hear the screams of "Satoshi intended the bitcoin blockchain for bitcoin transfer only" and the like but once again I am merely providing a tool which you may or may not use at your own discretion. There is also no blockchain more secure than that of bitcoin and I am afraid that a blockchain specifically for the purpose of POA may never catch on and never be secure enough against powerful adverseries. Anyhow, I do not see this method being used on a daily basis by many so it would not pose much risk of overloading the network, especially given the need for transaction fees.
Bellow, is a bash script which enables creation and verification of a bitcoin POA.
It requires the original bitcoin client running as a daemon for creation of a POA and Gavin Andresen's dbdump.py (
https://github.com/gavinandresen/bitcointools/tree/45f5c0030ac9a121fff504b0ffd27efc27423bde) for verification.
#!/bin/bash
#bitpoa: Bitcoin blockchain based proof of authenticity
#Author: Wolciph
#Public domain, use at your own risk
set -e
#config:
interactive=1
hashAlgo=sha256
amount=0.00000001
fee=0.0001
keyType=pk
infoFile='info.poa'
bitcoind=~/bitcoind
bitcoinDir=~/.bitcoin/
dbdump=~/bitcointools/dbdump.py
cd "$(dirname "$0")"
. addrgen.so.bash
#. bitpoa.conf
cd - >/dev/null
_tries=5
get_transaction_block() #(txid)
{
#workaround to access block of transaction:
local c=$($bitcoind getblockcount)
local b=$($bitcoind gettransaction $1 |
grep -m1 '"confirmations" :' |
sed -r 's/^.*"confirmations" : ([0-9]*).*$/\1/g';
[[ ${PIPESTATUS[@]} = '0 0 0' ]])
local c2=$($bitcoind getblockcount)
if (( $c2 == $c )); then echo $((c - b + 1))
elif (( _tries > 0 )); then ((_tries--)); get_transaction_block
else
echo "Cannot get stable blockcount. Wait until your blockchain is up\
to date and try again." >&2
return 2
fi
}
get_field() #(field)
{
grep -m1 "^$1:" | sed -r "s/^$1:(.*)$/\1/g"
[[ ${PIPESTATUS[@]} = '0 0' ]]
}
check_pipes() { [[ "${PIPESTATUS[@]}" =~ ^0(\ 0)*$ ]]; }
help="bitpoa Bitcoin blockchain proof of authenticity tool:
Examples:
These tasks require the bitcoin server to be active:
Creation: $0 -cf document.txt -i info.poa -a sha256 -A 0.00000001
Finding the block: $0 -b -i info.poa
This task requires the bitcoin server to be stopped:
Verifying: $0 -vf document.txt -i info.poa
Commands:
-c, --create : create and send _amount_ coins to a new address
-b, --find-block : find the block in which the new transaction is to
complete the info file
-v, --verify : verify a POA
-f, --file= : file from which to create a hash
-i, --info-file= : info file to read or write info for checking the POA
-h, --hash : do not hash the file (to use if it already is a hash)
-a, --algo= : the hashing algorithm; uses openssl
-y, --assume-yes : do not prompt before critical operations, non-interactive
-s, --secret-key : use hash in the private key (NOT IMPLEMENTED)
-A, --amount= : amount of bitcoins to send (WILL BE LOST FOREVER!!!)
-F, --fee= : transaction fee
"
#------------------
OPTS=$(getopt -o cvbf:i:ha:yA:F: \
--long create,verify,find-block,file:,info-file:,hash,algo:,assume-yes,help,amount,fee\
-n "$0" -- "$@")
if [ $? != 0 ]; then echo "Terminating. Use --help for help." >&2; exit 1; fi
eval set -- "$OPTS"
while true; do
case "$1" in
-c|--create) action=create; shift;;
-v|--verify) action=verify; shift;;
-b|--find-block) action=findBlock; shift;;
-f|--file) file="$2"; shift 2;;
-i|--info-file) infoFile="$2"; shift 2;;
-h|--hash) hash=1;; #the file cointains the hash
-a|--algo) hashAlgo="$2"; shift 2;; #first round (followed by ripemd160)
-y|--assume-yes) interactive=0; shift;;
-s|--secret-key) keyType=sk; shift;;
-A|--amount) amount=$2; shift 2;;
-F|--fee) txfee=$2; shift 2;;
--help) printf "%s" "$help" >&2; exit 0;;
--) shift; break;;
*) echo "Invalid argument: $1. Use --help for help." >&2; exit 1;;
esac
done
[ -n "$1" ] && { echo "Unknown extra argument: $1" >&2; exit 1; }
[ -z "$action" ] && { echo 'No action specified (-c|-v|-b)' >&2; exit 1; }
if [[ $action = findBlock ]]; then
txid="$(get_field txid < $infoFile)"
block=$(get_transaction_block $txid)
printf "%s\n" "block:$block" >> $infoFile
exit 0
fi
if [[ "$hash" = '1' ]]; then
hash=$(cat "$file")
else
hash=$(cat "$file" | openssl dgst -$hashAlgo -hex; [[ ${PIPESTATUS[@]} = '0 0' ]];) ||
{ echo "Error while hashing using $hashAlgo. Exiting." >&2; exit 1; }
fi
if [[ $keyType = pk ]]; then
h=$(xxd -p -r <<< "$hash" | openssl dgst -rmd160)
address=$(hash160ToAddress $h)
else
exit 1
#use hash as seed for prng?
fi
if [[ $action = 'create' ]]; then
printf "%s\n%s\n%s\n" "file:$file" "algo:$hashAlgo" "address:$address" > $infoFile
cmd="$bitcoind -paytxfee=$txfee sendtoaddress $address $amount"
if [[ $interactive = '1' ]]; then
echo "Warning: $amount bitcoins will be lost forever." >&2
printf '%s\n%s\n%s\n' "The following command is about to be sent to the bitcoin daemon:"\
"$cmd" "Make sure it is running. Proceed? (y/n)" >&2
read r
[[ "$r" =~ ^y(es?)?$ ]] || exit 0
fi
echo -n 'txid:' >> $infoFile
eval $cmd >> $infoFile
if [[ $interactive = '1' ]]; then
printf "%s%s\n" 'You must now wait for the transaction to be '\
"integrated into a new block before launching $0 -b [...]" >&2
fi
elif [[ $action = 'verify' ]]; then
address2="$(get_field address < $infoFile)"
if [[ "$address2" != "$address" ]]; then
printf "%s\n" "FAILURE: The address is incorrect (should be $address)!" >&2
exit 5
fi
block=$(get_field block < $infoFile)
blockInfo="$($dbdump --block=$block)"
if ! (grep -m1 "pubkey: $address" <<< "$blockInfo"); then
echo "FAILURE: The address is correct but does not appear in the given block!" >&2
exit 6
fi
echo "The address is correct and was published in the blockchain at around:"
grep -m1 '^Time: ' <<< "$blockInfo" | sed -r 's/Time: (.*) Nonce:.*$/\1/'
fi
Usage examples:
These tasks require the bitcoin server to be active:
Creation: ./bitpoa.bash -cf document.txt -i info.poa -a sha256 -A 0.00000001
Finding the block: ./bitpoa.bash -b -i info.poa
(for creation, a second step must be taken to find the block of the transaction in order to speed up verification)
This task requires the bitcoin server to be stopped:
Verifying: ./bitpoa.bash -vf document.txt -i info.poa