-
Notifications
You must be signed in to change notification settings - Fork 6
/
verify_proof.pl
executable file
·41 lines (32 loc) · 1.11 KB
/
verify_proof.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#! /usr/bin/perl
use strict;
use warnings;
use IO::All;
use Digest::SHA qw/sha256/;
use Data::ParseBinary;
use ChronoBit::Bitcoin;
use ChronoBit::ProofFile;
use ChronoBit::Proof;
use ChronoBit::Util;
my $data = io('-')->slurp;
my $proof_file = ChronoBit::ProofFile->struct->parse($data);
# XXX: haxx
my $proof = ChronoBit::Proof->new_from_binary(
ChronoBit::Proof->struct->build($proof_file->{proof})
);
print $proof->explain if $ARGV[0];
printf "proof from %s\n to %s\n", bin2hex($proof->from),
bin2hex($proof->to);
print 'data: <' . $proof_file->{data} . ">\n";
print '(data ' . ((sha256($proof_file->{data}) eq $proof->from) ? 'does' :
'DOES NOT') . " map to proof's start)\n";
print '(data+timestamp ' . ((sha256($proof_file->{data} .
var_int->build($proof_file->{timestamp}) .
ULInt32->build($proof_file->{timestamp_usec}
)) eq $proof->from) ? 'does' : 'DOES NOT') . " map to proof's start)\n";
printf "claims to be made on %s %06d usec GMT\n",
scalar(gmtime($proof_file->{timestamp})),
$proof_file->{timestamp_usec};
my $res = $proof->verify;
print $res ? "proof ok\n" : "PROOF INVALID\n";
exit $res;