This repository has been archived by the owner on Mar 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
service.go
60 lines (47 loc) · 1.67 KB
/
service.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package signatureconfig
import (
"fmt"
"github.com/hyperledger/aries-framework-go-ext/component/vdr/trustbloc/models"
)
type config interface {
GetConsortium(string, string) (*models.ConsortiumFileData, error)
GetStakeholder(string, string) (*models.StakeholderFileData, error)
GetSidetreeConfig(url string) (*models.SidetreeConfig, error)
}
// ConfigService fetches consortium and stakeholder configs over http.
type ConfigService struct {
config config
}
// NewService create new ConfigService.
func NewService(config config) *ConfigService {
configService := &ConfigService{config: config}
return configService
}
// GetConsortium fetches and parses the consortium file at the given domain.
func (cs *ConfigService) GetConsortium(url, domain string) (*models.ConsortiumFileData, error) {
consortiumData, err := cs.config.GetConsortium(url, domain)
if err != nil {
return nil, fmt.Errorf("wrapped config service: %w", err)
}
consortium := consortiumData.Config
if consortium == nil {
return nil, fmt.Errorf("consortium is nil")
}
err = VerifyConsortiumSignatures(consortiumData, consortium)
if err != nil {
return nil, err
}
return consortiumData, nil
}
// GetStakeholder returns the stakeholder config file fetched by the wrapped config service.
func (cs *ConfigService) GetStakeholder(url, domain string) (*models.StakeholderFileData, error) {
return cs.config.GetStakeholder(url, domain)
}
// GetSidetreeConfig get sidetree config.
func (cs *ConfigService) GetSidetreeConfig(url string) (*models.SidetreeConfig, error) {
return cs.config.GetSidetreeConfig(url)
}