File tree 2 files changed +63
-0
lines changed
2 files changed +63
-0
lines changed Original file line number Diff line number Diff line change
1
+ package main
2
+
3
+ import (
4
+ "flag"
5
+ "log"
6
+ "os"
7
+
8
+ "github.com/BlockchainSource/go-opentimestamps/opentimestamps"
9
+ )
10
+
11
+ const defaultCalendar = "https://alice.btc.calendar.opentimestamps.org"
12
+
13
+ func main () {
14
+ flag .Parse ()
15
+ path := flag .Arg (0 )
16
+
17
+ cal , err := opentimestamps .NewRemoteCalendar (defaultCalendar )
18
+ if err != nil {
19
+ log .Fatalf ("error creating remote calendar: %v" , err )
20
+ }
21
+
22
+ outFile , err := os .Create (path + ".ots" )
23
+ if err != nil {
24
+ log .Fatalf ("error creating output file: %v" , err )
25
+ }
26
+
27
+ dts , err := opentimestamps .CreateDetachedTimestampForFile (path , cal )
28
+ if err != nil {
29
+ log .Fatalf (
30
+ "error creating detached timestamp for %s: %v" ,
31
+ path , err ,
32
+ )
33
+ }
34
+ if err := dts .WriteToStream (outFile ); err != nil {
35
+ log .Fatalf ("error writing detached timestamp: %v" , err )
36
+ }
37
+ }
Original file line number Diff line number Diff line change
1
+ package opentimestamps
2
+
3
+ import (
4
+ "crypto/sha256"
5
+ "io"
6
+ "os"
7
+ )
8
+
9
+ func CreateDetachedTimestampForFile (
10
+ path string , cal * RemoteCalendar ,
11
+ ) (* DetachedTimestamp , error ) {
12
+ f , err := os .Open (path )
13
+ if err != nil {
14
+ return nil , err
15
+ }
16
+ hasher := sha256 .New ()
17
+ if _ , err := io .Copy (hasher , f ); err != nil {
18
+ return nil , err
19
+ }
20
+ digest := hasher .Sum ([]byte {})
21
+ ts , err := cal .Submit (digest )
22
+ if err != nil {
23
+ return nil , err
24
+ }
25
+ return NewDetachedTimestamp (* opSHA256 , digest , ts )
26
+ }
You can’t perform that action at this time.
0 commit comments