-
Notifications
You must be signed in to change notification settings - Fork 0
/
v1.go
143 lines (115 loc) · 4.34 KB
/
v1.go
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Copyright (c) 2017 The Bitum developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package v1
import (
"regexp"
"github.com/bitum-project/bitumtime/merkle"
)
// XXX add a clamp to all batches
const (
// StatusRoute defines the API route for retrieving
// the server status.
StatusRoute = "/v1/status/"
// TimestampRoute defines the API route for submitting
// both timestamps and digests.
TimestampRoute = "/v1/timestamp/"
// VerifyRoute defines the API route for both timestamp
// and digest verification.
VerifyRoute = "/v1/verify/" // Multi verify ingest
// ResultOK indicates the operation completed successfully.
ResultOK = 0
// ResultExistsError indicates the digest already exists and was
// rejected.
ResultExistsError = 1
// ResultDoesntExistError indiciates the timestamp or digest does not
// exist.
ResultDoesntExistError = 2
// ResultDisabled indicates querying is disabled.
ResultDisabled = 3
// DefaultMainnetTimeHost indicates the default mainnet time host
// server.
DefaultMainnetTimeHost = "time.bitum.io"
// DefaultMainnetTimePort indicates the default mainnet time host
// port.
DefaultMainnetTimePort = "49152"
// DefaultTestnetTimeHost indicates the default testnet time host
// server.
DefaultTestnetTimeHost = "time-testnet.bitum.io"
// DefaultTestnetTimePort indicates the default testnet time host
// port.
DefaultTestnetTimePort = "59152"
)
var (
Result = map[int]string{
ResultOK: "OK",
ResultExistsError: "Exists",
ResultDoesntExistError: "Doesn't exist",
ResultDisabled: "Query disallowed",
}
// RegexpSHA256 is the valid text representation of a sha256 digest.
RegexpSHA256 = regexp.MustCompile("^[A-Fa-f0-9]{64}$")
// RegexpTimestamp is the valid text representation of a timestamp.
RegexpTimestamp = regexp.MustCompile("^[0-9]{10}$")
)
// Status is used to ask the server if everything is running properly.
// ID is user settable and can be used as a unique identifier by the client.
type Status struct {
ID string `json:"id"`
}
// StatusReply is returned by the server if everything is running properly.
type StatusReply struct {
ID string `json:"id"`
}
// Timestamp is used to ask the timestamp server to store a batch of digests.
// ID is user settable and can be used as a unique identifier by the client.
type Timestamp struct {
ID string `json:"id"`
Digests []string `json:"digests"`
}
// TimestampReply is returned by the timestamp server after storing the batch
// of digests. ID is copied from the originating Timestamp call and can be
// used by the client as a unique identifier. The ServerTimestamp indicates
// what collection the Digests belong to. Results contains individual result
// codes for each digest.
type TimestampReply struct {
ID string `json:"id"`
ServerTimestamp int64 `json:"servertimestamp"`
Digests []string `json:"digests"`
Results []int `json:"results"`
}
type Verify struct {
ID string `json:"id"`
Digests []string `json:"digests"`
Timestamps []int64 `json:"timestamps"`
}
type VerifyDigest struct {
Digest string `json:"digest"`
ServerTimestamp int64 `json:"servertimestamp"`
Result int `json:"result"`
ChainInformation ChainInformation `json:"chaininformation"`
}
// VerifyTimestamp is zero if this digest collection is not anchored in the
// blockchain; it is however set to the block timestamp it was anchored in.
type VerifyTimestamp struct {
ServerTimestamp int64 `json:"servertimestamp"`
Result int `json:"result"`
CollectionInformation CollectionInformation `json:"collectioninformation"`
}
type VerifyReply struct {
ID string `json:"id"`
Digests []VerifyDigest `json:"digests"`
Timestamps []VerifyTimestamp `json:"timestamps"`
}
type ChainInformation struct {
ChainTimestamp int64 `json:"chaintimestamp"`
Transaction string `json:"transaction"`
MerkleRoot string `json:"merkleroot"`
MerklePath merkle.Branch `json:"merklepath"`
}
type CollectionInformation struct {
ChainTimestamp int64 `json:"chaintimestamp"`
Transaction string `json:"transaction"`
MerkleRoot string `json:"merkleroot"`
Digests []string `json:"digests"`
}