Skip to content

Commit 9e73f0a

Browse files
Add cmd/gots-verify
Allows verification of created timestamps
1 parent b60e2cd commit 9e73f0a

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

cmd/gots-verify/main.go

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"flag"
5+
"fmt"
6+
"log"
7+
8+
"github.com/BlockchainSource/go-opentimestamps/opentimestamps"
9+
"github.com/BlockchainSource/go-opentimestamps/opentimestamps/client"
10+
"github.com/btcsuite/btcrpcclient"
11+
)
12+
13+
func newBtcConn(host, user, pass string) (*btcrpcclient.Client, error) {
14+
connCfg := &btcrpcclient.ConnConfig{
15+
Host: host,
16+
User: user,
17+
Pass: pass,
18+
HTTPPostMode: true,
19+
DisableTLS: true,
20+
}
21+
return btcrpcclient.New(connCfg, nil)
22+
}
23+
24+
var (
25+
flagBTCHost = flag.String("btc-host", "localhost:8332", "bitcoin-rpc hostname")
26+
flagBTCUser = flag.String("btc-user", "bitcoin", "bitcoin-rpc username")
27+
flagBTCPass = flag.String("btc-pass", "bitcoin", "bitcoin-rpc password")
28+
)
29+
30+
func main() {
31+
flag.Parse()
32+
path := flag.Arg(0)
33+
dts, err := opentimestamps.NewDetachedTimestampFromPath(path)
34+
if err != nil {
35+
log.Fatalf("error reading %s: %v", path, err)
36+
}
37+
38+
btcConn, err := newBtcConn(*flagBTCHost, *flagBTCUser, *flagBTCPass)
39+
if err != nil {
40+
log.Fatalf("error creating btc connection: %v", err)
41+
}
42+
43+
verifier := client.NewBitcoinAttestationVerifier(btcConn)
44+
45+
ts, err := verifier.Verify(dts.Timestamp)
46+
if err != nil {
47+
log.Fatalf("error verifying timestamp: %v", err)
48+
}
49+
if ts == nil {
50+
fmt.Printf("no bitcoin-verifiable timestamps found\n")
51+
}
52+
fmt.Printf("attested time: %v\n", ts)
53+
}

0 commit comments

Comments
 (0)