forked from hyperledger-archives/aries-framework-go
-
Notifications
You must be signed in to change notification settings - Fork 0
/
did.go
48 lines (36 loc) · 1.09 KB
/
did.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
/*
Copyright SecureKey Technologies Inc. All Rights Reserved.
SPDX-License-Identifier: Apache-2.0
*/
package web
import (
"fmt"
"net/url"
"strings"
"github.com/Universal-Health-Chain/aries-framework-go/pkg/doc/did"
)
const (
defaultPath = "/.well-known/doc.json"
documentPath = "/doc.json"
)
// parseDIDWeb consumes a did:web identifier and returns the URL location of the did Doc.
func parseDIDWeb(id string) (string, string, error) {
var address, host string
parsedDID, err := did.Parse(id)
if err != nil {
return address, host, fmt.Errorf("invalid did, does not conform to generic did standard --> %w", err)
}
pathComponents := strings.Split(parsedDID.MethodSpecificID, ":")
pathComponents[0], err = url.QueryUnescape(pathComponents[0])
if err != nil {
return address, host, fmt.Errorf("error parsing did:web did")
}
host = strings.Split(pathComponents[0], ":")[0]
switch len(pathComponents) {
case 1:
address = "https://" + pathComponents[0] + defaultPath
default:
address = "https://" + strings.Join(pathComponents, "/") + documentPath
}
return address, host, nil
}