-
Notifications
You must be signed in to change notification settings - Fork 66
/
format.go
52 lines (43 loc) · 1.34 KB
/
format.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
package btd
import (
"encoding/json"
)
// This is a transport format induced by internal systems. It should be
// irrelevant to third-party implementations.
// { bl_sig_req : b64-encoded request from client }
type BlindTokenRequestWrapper struct {
Request []byte `json:"bl_sig_req"`
Host string `json:"host,omitempty"`
Path string `json:"http,omitempty"`
}
// { type : (Issue|Redeem), contents : list of b64-encoded blinded points }
type BlindTokenRequest struct {
Type ReqType `json:"type"`
Contents [][]byte `json:"contents"`
}
// Contains response to Issue request
// (incl. signed tokens, DLEQ proof and key version)
type IssuedTokenResponse struct {
Sigs [][]byte `json:"sigs"`
Proof []byte `json:"proof"`
Version string `json:"version"`
}
type ReqType string
var (
ISSUE ReqType = "Issue"
REDEEM ReqType = "Redeem"
)
// EncodeByteArrays turns [][]byte into JSON with base64-encoded byte blobs.
func EncodeByteArrays(values [][]byte) ([]byte, error) {
return json.Marshal(values)
}
// DecodeByteArrays decodes JSON of the fromat produced by EncodeByteArrays.
func DecodeByteArrays(encoded []byte) ([][]byte, error) {
var values [][]byte
err := json.Unmarshal(encoded, &values)
return values, err
}
func MarshalRequest(request interface{}) ([]byte, error) {
jsonRequest, err := json.Marshal(request)
return jsonRequest, err
}