-
Notifications
You must be signed in to change notification settings - Fork 13
/
keys.go
67 lines (57 loc) · 1.76 KB
/
keys.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
package resolution
import (
"encoding/json"
"fmt"
"strings"
"embed"
)
// supportedKeys struct of supported keys
type supportedKeys map[string]struct {
DeprecatedKeyName string
Deprecated bool
ValidationRegex string
}
const emailKey = "whois.email.value"
var ipfsKeys = []string{"dweb.ipfs.hash", "ipfs.html.value"}
var redirectUrlKeys = []string{"browser.redirect_url", "ipfs.redirect_domain.value"}
//go:embed uns/resolver-keys.json
var resolverKeysEmbed embed.FS
var supportedKeysJSON, _ = resolverKeysEmbed.ReadFile("uns/resolver-keys.json")
// buildCryptoKey returns raw key for crypto currency which is used to query blockchain
func buildCryptoKey(ticker string) (string, error) {
var key strings.Builder
_, err := fmt.Fprintf(&key, "crypto.%s.address", strings.ToUpper(ticker))
if err != nil {
return "", err
}
return key.String(), nil
}
// buildCryptoKeyVersion returns raw key for multi-chain currency which is used to query blockchain
func buildCryptoKeyVersion(ticker string, version string) (string, error) {
var key strings.Builder
_, err := fmt.Fprintf(&key, "crypto.%s.version.%s.address", strings.ToUpper(ticker), strings.ToUpper(version))
if err != nil {
return "", err
}
return key.String(), nil
}
// returnFirstNonEmpty returns first not empty elements from provided records and keys order
func returnFirstNonEmpty(records map[string]string, keysSequence []string) string {
for _, key := range keysSequence {
if records[key] != "" {
return records[key]
}
}
return ""
}
// newSupportedKeys returns supportedKeys
func newSupportedKeys() (supportedKeys, error) {
var keysObject struct {
Keys supportedKeys
}
err := json.Unmarshal(supportedKeysJSON, &keysObject)
if err != nil {
return nil, err
}
return keysObject.Keys, nil
}