Bitcoin Forum
May 07, 2024, 01:48:46 PM *
News: Latest Bitcoin Core release: 27.0 [Torrent]
 
   Home   Help Search Login Register More  
Pages: [1]
  Print  
Author Topic: Timestamping a file into bitcoin's block chain  (Read 3001 times)
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
December 19, 2010, 03:58:47 AM
Last edit: December 19, 2010, 05:22:19 AM by grondilu
 #1

Here is a script to timestamp or search for a timestamp in the block chain.

Code:
#!/bin/bash
#
# timestamp.sh : Bitcoin timestamping script
#
# This script timestamps or search timestamps into bitcoin's block chain

blockexplorer="http://blockexplorer.com"

# reads data sent on stdin and hash it
sha256=$(openssl dgst -sha256)

# converts hash into a valid bitcoin address
address=$(wget -O - $blockexplorer/q/hashtoaddress/${sha256::40})

shopt -s extglob
case "$@" in
    -s|--search)
        # just search the bitcoin address in the block chain
        w3m -dump "$blockexplorer/address/$address" ;;

    0.+([0-9])|"")
        fee=${1:-0.01}
        if bitcoind getinfo > /dev/null
        then bitcoind sendtoaddress $address $fee
        else echo "Please check bitcoind is running"
        fi ;;
    *)
        echo "
        usage :  $0 [-s]  [amount]
        options :
        -s|--search : only search for a timestamp in bitcoin's block chain
        " ;;
esac


The first data I've timestamped using this code is this code itself (or more precisely my signature of it).

You can check it by running :

$ bash ./timestamp.sh -s < ./timestamp.sh.asc

where timestamp.sh.asc is :

-----BEGIN PGP MESSAGE-----
Version: GnuPG v1.4.10 (GNU/Linux)

owFtk7Fv00AUxkMLSD5RRPkLXh1LNIBjlwISroKAgQUQHdiiIJ3tS+7AuTO+c1LU
dmDrgoRUsTFkQDCgMocBBlZ2xMKKBAtsDCw8J3GTILyc7/nd9/3e87tnS4uVheU3
93//3Bye5EcOFmvhCSO6TBvaTeua31l60quueKGQXkg1J1VShdnvEMANYSIl5DQs
ZAd0lInUjNLvcaEn+2mOBpWBZjSL+GxQSKMgHAue0RAmKnoIEadCEjLasK00URnL
GjY3Jg08by5aj1TXJuiZMRpriKmhaCINKAnaxAhJZQwcCwFhiOb0wqXLDWdVpUxq
nUDc0QbccbhWyERK9lhm9ORIAUehRxMRl5BA4zhjWpPJimr9DkOVu+CCMwfnPfIK
GaMmqZ6zPbYKgov+LvpprtLCH9iW6SQqJBHVDGznmo3WBPBx9Y7rjrtWI1YVHuQI
XHaRs3+hoPgrRXimjVZ/vQtunHdTVJ7nO+SavNgbG2Rk69fPrTZ990qrtmPbaNxm
rOFsrwWuX/fXdokl2qVzDFi8kG0FV8GLWc+TeZIQCyHkNKXUBweFiMUSrJJFXIG9
mbCi5Igz5D3Mx/HJcilxrAoiqy1GUGcRZHyKWLmmHYajCI4PTVe3AJq0q3JpWsTC
ngolNQTEmmkfJiuZPC6b18ZppNNBLBr3/ym0bEAGpmlE9m4erSwvVI4fWyguSYVY
p8pr9KteGbz+8eVz/8PXg5f7z1+8v/UnH5rTg8rgKd2Phu8+ffx+/TY5/yp7u7fy
bf0v
=ecN3
-----END PGP MESSAGE-----


PS.  An other version using rmd160 instead of sha256 (so that we don't have to truncate the hash) :

Code:
#!/bin/bash
#
# timestamp.sh : Bitcoin timestamping script
#
# This script timestamps or search timestamps into bitcoin's block chain

blockexplorer="http://blockexplorer.com"

# reads data sent on stdin, hash it, and converts hash into a valid bitcoin address
address=$(wget -q -O - $blockexplorer/q/hashtoaddress/$(openssl dgst -rmd160))

shopt -s extglob
case "$@" in
    -s|--search)
        # just search the bitcoin address in the block chain
        wget -q -O - "$blockexplorer/address/$address" |
        if grep -q "First seen.*Never used in the network"
        then echo no timestamp found; exit 1
        else echo timestamp found : $blockexplorer/address/$address
        fi ;;

    0.+([0-9])|"")
        # timestamps data by sending a small amount to $address
        fee=${1:-0.01}
        if bitcoind getinfo > /dev/null
        then bitcoind sendtoaddress $address $fee
        else echo "Please check bitcoind is running"
        fi ;;
    *)
        # usage information
        echo "
        usage :  $0 [-s]  [amount]
        options :
        -s|--search : only search for a timestamp in bitcoin's block chain
        " ;;
esac

1715089726
Hero Member
*
Offline Offline

Posts: 1715089726

View Profile Personal Message (Offline)

Ignore
1715089726
Reply with quote  #2

1715089726
Report to moderator
The trust scores you see are subjective; they will change depending on who you have in your trust list.
Advertised sites are not endorsed by the Bitcoin Forum. They may be unsafe, untrustworthy, or illegal in your jurisdiction.
1715089726
Hero Member
*
Offline Offline

Posts: 1715089726

View Profile Personal Message (Offline)

Ignore
1715089726
Reply with quote  #2

1715089726
Report to moderator
1715089726
Hero Member
*
Offline Offline

Posts: 1715089726

View Profile Personal Message (Offline)

Ignore
1715089726
Reply with quote  #2

1715089726
Report to moderator
1715089726
Hero Member
*
Offline Offline

Posts: 1715089726

View Profile Personal Message (Offline)

Ignore
1715089726
Reply with quote  #2

1715089726
Report to moderator
theymos
Administrator
Legendary
*
Offline Offline

Activity: 5194
Merit: 12974


View Profile
December 20, 2010, 02:45:19 AM
 #2

I made a couple of new Real-Time Stats pages for things like this:
http://blockexplorer.com/q/getreceivedbyaddress
http://blockexplorer.com/q/addressfirstseen

If you use /q/addressfirstseen, you'll be able to make a really nice script for distributed timestamping.

1NXYoJ5xU91Jp83XfVMHwwTUyZFK64BoAD
Hal
VIP
Sr. Member
*
expert
Offline Offline

Activity: 314
Merit: 3853



View Profile
December 21, 2010, 12:40:14 AM
 #3

Instead of a file as input, use the hash of a domain name, and you have a quick-n-dirty system for claiming ownership permanently (the name belongs to the key making the payment). Then as suggested in the BitDNS thread, use any common DHT implementation to broadcast the signed DNS records.

Hal Finney
grondilu (OP)
Legendary
*
Offline Offline

Activity: 1288
Merit: 1076


View Profile
January 06, 2011, 06:13:35 PM
 #4

Now that I have implemented base58 code in bash, I don't even need to connect to blockexplorer Smiley


Code:
#!/bin/bash
#
# Timestamping program
# Returns a valid bitcoin address made from stdin
# To timestamp, just send 0.01 BTC to this address
#
# Requires bc, openssl, xxd
#

base58=({1..9} {A..H} {J..N} {P..Z} {a..k} {m..z})

EncodeBase58() {
    # 58 =0x3A
    bc <<<"ibase=16; n=${1^^}; while(n>0) { n%3A ; n/=3A }" |
    tac |
    while read n
    do echo -n ${base58[n]}
    done
}

checksum() {
    xxd -p -r <<<"$1" |
    openssl dgst -sha256 -binary |
    openssl dgst -sha256 -hex |
    cut -d\  -f2 |
    sed -r "s/^((..){4}).*/\1/"
}

Hash160() {
    openssl dgst -sha256 -binary |
    openssl dgst -rmd160 -hex |
    cut -d\  -f2
}

Hash160ToAddress() {
    printf %34s "$(EncodeBase58 "00$1$(checksum "00$1")")" |
    sed "s/ /1/g"
}

Hash160ToAddress $(Hash160)

Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.19 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!