-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdid.go
More file actions
102 lines (86 loc) · 3.4 KB
/
Copy pathdid.go
File metadata and controls
102 lines (86 loc) · 3.4 KB
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package document
import (
"time"
"github.com/iden3/go-schema-processor/v2/verifiable"
)
type ErrorCode string
const (
ErrInvalidDID ErrorCode = "invalidDid"
ErrMethodNotSupported ErrorCode = "methodNotSupported"
ErrNotFound ErrorCode = "notFound"
ErrUnknownNetwork ErrorCode = "unknownNetwork"
StateType = "Iden3StateInfo2023"
Iden3ResolutionMetadataType = "Iden3ResolutionMetadata"
EcdsaSecp256k1RecoveryMethod2020Type = "EcdsaSecp256k1RecoveryMethod2020"
)
const (
defaultContext = "https://w3id.org/did-resolution/v1"
defaultDidDocContext = "https://www.w3.org/ns/did/v1"
iden3Context = "https://schema.iden3.io/core/jsonld/auth.jsonld"
defaultContentType = "application/did+ld+json"
iden3ResolutionContext = "https://schema.iden3.io/core/jsonld/resolution.jsonld"
eip712sigContext = "https://w3id.org/security/suites/eip712sig-2021/v1"
)
// DidResolution representation of did resolution.
type DidResolution struct {
Context string `json:"@context,omitempty"`
DidDocument *verifiable.DIDDocument `json:"didDocument"`
// should exist in responses, but can be empty.
// https://www.w3.org/TR/did-core/#did-resolution
DidResolutionMetadata *DidResolutionMetadata `json:"didResolutionMetadata"`
DidDocumentMetadata *DidDocumentMetadata `json:"didDocumentMetadata"`
}
// NewDidResolution create did resolution with default values.
func NewDidResolution() *DidResolution {
return &DidResolution{
Context: defaultContext,
DidDocument: &verifiable.DIDDocument{
Context: []string{defaultDidDocContext, iden3Context},
VerificationMethod: []verifiable.CommonVerificationMethod{},
},
DidResolutionMetadata: &DidResolutionMetadata{
Context: []string{iden3ResolutionContext},
Type: Iden3ResolutionMetadataType,
ContentType: defaultContentType,
Retrieved: time.Now(),
},
DidDocumentMetadata: &DidDocumentMetadata{},
}
}
func DidResolutionMetadataSigContext() []string {
return []string{iden3ResolutionContext, eip712sigContext}
}
func NewDidMethodNotSupportedResolution(msg string) *DidResolution {
return NewDidErrorResolution(ErrMethodNotSupported, msg)
}
func NewDidInvalidResolution(msg string) *DidResolution {
return NewDidErrorResolution(ErrInvalidDID, msg)
}
func NewNetworkNotSupportedForDID(msg string) *DidResolution {
return NewDidErrorResolution(ErrUnknownNetwork, msg)
}
func NewDidNotFoundResolution(msg string) *DidResolution {
return NewDidErrorResolution(ErrNotFound, msg)
}
func NewDidErrorResolution(errCode ErrorCode, errMsg string) *DidResolution {
return &DidResolution{
DidResolutionMetadata: &DidResolutionMetadata{
Error: errCode,
Message: errMsg,
Retrieved: time.Now(),
},
DidDocumentMetadata: &DidDocumentMetadata{},
}
}
// DidResolutionMetadata representation of resolution metadata.
type DidResolutionMetadata struct {
Context interface{} `json:"@context,omitempty"`
Error ErrorCode `json:"error,omitempty"`
Message string `json:"message,omitempty"`
ContentType string `json:"contentType,omitempty"`
Retrieved time.Time `json:"retrieved,omitempty"`
Type string `json:"type,omitempty"`
Proof DidResolutionProofs `json:"proof,omitempty"`
}
// DidDocumentMetadata metadata of did document.
type DidDocumentMetadata struct{}