-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
registerdid.go
54 lines (46 loc) · 1.16 KB
/
registerdid.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
package acapy
import (
"bytes"
"encoding/json"
"net/http"
)
type registerDIDRequest struct {
Alias string `json:"alias"`
Seed string `json:"seed"`
Role string `json:"role"`
DID string `json:"did"`
}
type RegisterDIDResponse struct {
DID string `json:"did"`
Seed string `json:"seed"`
Verkey string `json:"verkey"`
}
type DIDRole string
const (
Endorser DIDRole = "ENDORSER"
Steward DIDRole = "STEWARD"
Trustee DIDRole = "TRUSTEE"
NetworkMonitor DIDRole = "NETWORK_MONITOR"
)
func RegisterDID(ledgerURL string, alias string, seed string, role DIDRole) (RegisterDIDResponse, error) {
var request registerDIDRequest
var response RegisterDIDResponse
request = registerDIDRequest{
Alias: alias,
Seed: seed, // Should be random in develop mode
Role: string(role),
}
body, err := json.Marshal(request)
if err != nil {
return RegisterDIDResponse{}, err
}
resp, err := http.Post(ledgerURL+"/register", "application/json", bytes.NewBuffer(body))
if err != nil {
return RegisterDIDResponse{}, err
}
err = json.NewDecoder(resp.Body).Decode(&response)
if err != nil {
return RegisterDIDResponse{}, err
}
return response, nil
}