-
Notifications
You must be signed in to change notification settings - Fork 19
/
authorities.go
83 lines (68 loc) · 2.3 KB
/
authorities.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
// Copyright 2016 Factom Foundation
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package factom
import (
"encoding/json"
"fmt"
)
// An Authority is an identity on the Factom Blockchain that is responsible for
// signing some part of the Factom Directory Block merkel tree to achieve
// consensus on the network to create a canonical Directory Block.
type Authority struct {
AuthorityChainID string `json:"chainid"`
ManagementChainID string `json:"manageid"`
MatryoshkaHash string `json:"matroyshka"` // [sic]
SigningKey string `json:"signingkey"`
Status string `json:"status"`
AnchorKeys []*AnchorSigningKey `json:"anchorkeys"`
}
func (a *Authority) String() string {
var s string
s += fmt.Sprintln("AuthorityChainID:", a.AuthorityChainID)
s += fmt.Sprintln("ManagementChainID:", a.ManagementChainID)
s += fmt.Sprintln("MatryoshkaHash:", a.MatryoshkaHash)
s += fmt.Sprintln("SigningKey:", a.SigningKey)
s += fmt.Sprintln("Status:", a.Status)
s += fmt.Sprintln("AnchorKeys {")
for _, k := range a.AnchorKeys {
s += fmt.Sprintln(k)
}
s += fmt.Sprintln("}")
return s
}
// AnchorSigningKey is a key for an external blockchain (like Bitcoin or
// Etherium) used to create a Factom Anchor.
type AnchorSigningKey struct {
BlockChain string `json:"blockchain"`
KeyLevel byte `json:"level"`
KeyType byte `json:"keytype"`
SigningKey string `json:"key"` //if bytes, it is hex
}
func (k *AnchorSigningKey) String() string {
var s string
s += fmt.Sprintln("BlockChain:", k.BlockChain)
s += fmt.Sprintln("KeyLevel:", k.KeyLevel)
s += fmt.Sprintln("KeyType:", k.KeyType)
s += fmt.Sprintln("SigningKey:", k.SigningKey)
return s
}
// GetAuthorities retrieves a list of the known athorities from factomd.
func GetAuthorities() ([]*Authority, error) {
req := NewJSON2Request("authorities", APICounter(), nil)
resp, err := factomdRequest(req)
if err != nil {
return nil, err
}
if resp.Error != nil {
return nil, resp.Error
}
// create a temporary type to unmarshal the json object
a := new(struct {
Authorities []*Authority `json:"authorities"`
})
if err := json.Unmarshal(resp.JSONResult(), a); err != nil {
return nil, err
}
return a.Authorities, nil
}